Make tab close mouse button configurable
This commit is contained in:
parent
2d3575f6d1
commit
bcbdf9090f
@ -401,9 +401,9 @@ DATA = OrderedDict([
|
||||
SettingValue(types.Bool(), 'true'),
|
||||
"Whether tabs should be movable."),
|
||||
|
||||
('close-on-right-click',
|
||||
SettingValue(types.Bool(), 'false'),
|
||||
"Whether tabs should close when right-clicked."),
|
||||
('close-mouse-button',
|
||||
SettingValue(types.CloseButton(), 'middle'),
|
||||
"On which mouse button to close tabs."),
|
||||
|
||||
('position',
|
||||
SettingValue(types.Position(), 'north'),
|
||||
|
@ -935,3 +935,12 @@ class ForwardUnboundKeys(BaseType):
|
||||
('auto', "Forward unbound non-alphanumeric "
|
||||
"keys."),
|
||||
('none', "Don't forward any keys."))
|
||||
|
||||
|
||||
class CloseButton(BaseType):
|
||||
|
||||
"""Whether to forward unbound keys."""
|
||||
|
||||
valid_values = ValidValues(('right', "Close tabs on right-click."),
|
||||
('middle', "Close tabs on middle-click."),
|
||||
('none', "Don't close tabs using the mouse."))
|
||||
|
@ -126,17 +126,16 @@ class TabBar(QTabBar):
|
||||
self.count())
|
||||
|
||||
def mousePressEvent(self, e):
|
||||
"""Override mousePressEvent to emit tabCloseRequested on rightclick."""
|
||||
if e.button() != Qt.RightButton:
|
||||
super().mousePressEvent(e)
|
||||
return
|
||||
idx = self.tabAt(e.pos())
|
||||
if idx == -1:
|
||||
super().mousePressEvent(e)
|
||||
return
|
||||
e.accept()
|
||||
if config.get('tabbar', 'close-on-right-click'):
|
||||
self.tabCloseRequested.emit(idx)
|
||||
"""Override mousePressEvent to close tabs if configured."""
|
||||
button = config.get('tabbar', 'close-mouse-button')
|
||||
if (e.button() == Qt.RightButton and button == 'right' or
|
||||
e.button() == Qt.MiddleButton and button == 'middle'):
|
||||
idx = self.tabAt(e.pos())
|
||||
if idx != -1:
|
||||
e.accept()
|
||||
self.tabCloseRequested.emit(idx)
|
||||
return
|
||||
super().mousePressEvent(e)
|
||||
|
||||
def minimumTabSizeHint(self, index):
|
||||
"""Override minimumTabSizeHint because we want no hard minimum.
|
||||
|
Loading…
Reference in New Issue
Block a user