Make tab close mouse button configurable

This commit is contained in:
Florian Bruhin 2014-07-15 22:22:10 +02:00
parent 2d3575f6d1
commit bcbdf9090f
3 changed files with 22 additions and 14 deletions

View File

@ -401,9 +401,9 @@ DATA = OrderedDict([
SettingValue(types.Bool(), 'true'), SettingValue(types.Bool(), 'true'),
"Whether tabs should be movable."), "Whether tabs should be movable."),
('close-on-right-click', ('close-mouse-button',
SettingValue(types.Bool(), 'false'), SettingValue(types.CloseButton(), 'middle'),
"Whether tabs should close when right-clicked."), "On which mouse button to close tabs."),
('position', ('position',
SettingValue(types.Position(), 'north'), SettingValue(types.Position(), 'north'),

View File

@ -935,3 +935,12 @@ class ForwardUnboundKeys(BaseType):
('auto', "Forward unbound non-alphanumeric " ('auto', "Forward unbound non-alphanumeric "
"keys."), "keys."),
('none', "Don't forward any 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."))

View File

@ -126,17 +126,16 @@ class TabBar(QTabBar):
self.count()) self.count())
def mousePressEvent(self, e): def mousePressEvent(self, e):
"""Override mousePressEvent to emit tabCloseRequested on rightclick.""" """Override mousePressEvent to close tabs if configured."""
if e.button() != Qt.RightButton: button = config.get('tabbar', 'close-mouse-button')
super().mousePressEvent(e) if (e.button() == Qt.RightButton and button == 'right' or
return e.button() == Qt.MiddleButton and button == 'middle'):
idx = self.tabAt(e.pos()) idx = self.tabAt(e.pos())
if idx == -1: if idx != -1:
super().mousePressEvent(e) e.accept()
return self.tabCloseRequested.emit(idx)
e.accept() return
if config.get('tabbar', 'close-on-right-click'): super().mousePressEvent(e)
self.tabCloseRequested.emit(idx)
def minimumTabSizeHint(self, index): def minimumTabSizeHint(self, index):
"""Override minimumTabSizeHint because we want no hard minimum. """Override minimumTabSizeHint because we want no hard minimum.