Merge remote-tracking branch 'origin/pr/3136'

This commit is contained in:
Florian Bruhin 2017-10-24 08:57:28 +02:00
commit 43bca9793e
3 changed files with 36 additions and 1 deletions

View File

@ -1137,6 +1137,17 @@ 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."
- ignore: "Don't do anything."
desc: Behavior when the close mouse button is pressed on the tab bar.
tabs.favicons.scale:
default: 1.0
type:

View File

@ -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.tabopen)
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)
@ -411,6 +412,7 @@ class TabbedBrowser(tabwidget.TabWidget):
@pyqtSlot('QUrl')
@pyqtSlot('QUrl', bool)
@pyqtSlot('QUrl', bool, bool)
def tabopen(self, url=None, background=None, related=True, idx=None, *,
ignore_tabs_are_windows=False):
"""Open a new tab with a given URL.

View File

@ -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, 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)
@ -269,6 +272,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, False, False)
def tab_url(self, idx):
"""Get the URL of the tab at the given index.
@ -298,8 +306,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
@ -432,7 +445,16 @@ 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 == 'ignore':
return
elif 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)