Configurable behavior of close mouse button on bar
This commit is contained in:
parent
e89fda189a
commit
674269724f
@ -1127,6 +1127,16 @@ tabs.close_mouse_button:
|
||||
- none: "Don't close tabs using the mouse."
|
||||
desc: On which mouse button to close tabs.
|
||||
|
||||
tabs.close_mouse_button_on_bar:
|
||||
default: new-tab
|
||||
type:
|
||||
name: String
|
||||
valid_values:
|
||||
- new-tab: "Open a new tab."
|
||||
- close-current: "Close the current tab."
|
||||
- close-last: "Close the last tab."
|
||||
desc: Behavior when the close mouse button is pressed on the tab bar.
|
||||
|
||||
tabs.favicons.scale:
|
||||
default: 1.0
|
||||
type:
|
||||
|
@ -116,6 +116,7 @@ class TabbedBrowser(tabwidget.TabWidget):
|
||||
self._tab_insert_idx_right = -1
|
||||
self.shutting_down = False
|
||||
self.tabCloseRequested.connect(self.on_tab_close_requested)
|
||||
self.new_tab_requested.connect(self.openurl)
|
||||
self.currentChanged.connect(self.on_current_changed)
|
||||
self.cur_load_started.connect(self.on_cur_load_started)
|
||||
self.cur_fullscreen_requested.connect(self.tabBar().maybe_hide)
|
||||
|
@ -46,9 +46,11 @@ class TabWidget(QTabWidget):
|
||||
tab_index_changed: Emitted when the current tab was changed.
|
||||
arg 0: The index of the tab which is now focused.
|
||||
arg 1: The total count of tabs.
|
||||
new_tab_requested: Emitted when a new tab is requested.
|
||||
"""
|
||||
|
||||
tab_index_changed = pyqtSignal(int, int)
|
||||
new_tab_requested = pyqtSignal('QUrl', bool)
|
||||
|
||||
def __init__(self, win_id, parent=None):
|
||||
super().__init__(parent)
|
||||
@ -59,6 +61,7 @@ class TabWidget(QTabWidget):
|
||||
bar.tabMoved.connect(functools.partial(
|
||||
QTimer.singleShot, 0, self._update_tab_titles))
|
||||
bar.currentChanged.connect(self._on_current_changed)
|
||||
bar.new_tab_requested.connect(self._on_new_tab_requested)
|
||||
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
|
||||
self.setDocumentMode(True)
|
||||
self.setElideMode(Qt.ElideRight)
|
||||
@ -261,6 +264,11 @@ class TabWidget(QTabWidget):
|
||||
self.tabBar().on_current_changed()
|
||||
self.tab_index_changed.emit(index, self.count())
|
||||
|
||||
@pyqtSlot()
|
||||
def _on_new_tab_requested(self):
|
||||
"""Open a new tab."""
|
||||
self.new_tab_requested.emit(config.val.url.default_page, True)
|
||||
|
||||
def tab_url(self, idx):
|
||||
"""Get the URL of the tab at the given index.
|
||||
|
||||
@ -290,8 +298,13 @@ class TabBar(QTabBar):
|
||||
Attributes:
|
||||
vertical: When the tab bar is currently vertical.
|
||||
win_id: The window ID this TabBar belongs to.
|
||||
|
||||
Signals:
|
||||
new_tab_requested: Emitted when a new tab is requested.
|
||||
"""
|
||||
|
||||
new_tab_requested = pyqtSignal()
|
||||
|
||||
def __init__(self, win_id, parent=None):
|
||||
super().__init__(parent)
|
||||
self._win_id = win_id
|
||||
@ -424,7 +437,14 @@ class TabBar(QTabBar):
|
||||
e.accept()
|
||||
idx = self.tabAt(e.pos())
|
||||
if idx == -1:
|
||||
idx = self.currentIndex()
|
||||
action = config.val.tabs.close_mouse_button_on_bar
|
||||
if action == 'new-tab':
|
||||
self.new_tab_requested.emit()
|
||||
return
|
||||
elif action == 'close-current':
|
||||
idx = self.currentIndex()
|
||||
elif action == 'close-last':
|
||||
idx = self.count() - 1
|
||||
self.tabCloseRequested.emit(idx)
|
||||
return
|
||||
super().mousePressEvent(e)
|
||||
|
Loading…
Reference in New Issue
Block a user