From 2a961c3951cc7c185e99540f78f95ad31cb2f7a7 Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Sun, 21 May 2017 19:49:10 -0700 Subject: [PATCH] Clean up pinned status to a centralized location - Add support for :tab-clone with pinned tabs Now tabbed_browser.set_tab_pinned can be called independently. --- qutebrowser/browser/commands.py | 8 ++++---- qutebrowser/mainwindow/tabwidget.py | 22 +++++++++++++++------- qutebrowser/misc/sessions.py | 2 +- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index f4591c9d6..532ead3d6 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -268,12 +268,10 @@ class CommandDispatcher: if tab is None: return - tab.data.pinned = not tab.data.pinned - + to_pin = not tab.data.pinned tab_index = self._current_index() if count is None else count - 1 cmdutils.check_overflow(tab_index + 1, 'int') - self._tabbed_browser.set_tab_pinned(tab_index, - tab.data.pinned) + self._tabbed_browser.set_tab_pinned(tab_index, to_pin) @cmdutils.register(instance='command-dispatcher', name='open', maxsplit=0, scope='window') @@ -475,6 +473,7 @@ class CommandDispatcher: """ cmdutils.check_exclusive((bg, window), 'bw') curtab = self._current_widget() + pinned = curtab.data.pinned cur_title = self._tabbed_browser.page_title(self._current_index()) try: history = curtab.history.serialize() @@ -501,6 +500,7 @@ class CommandDispatcher: newtab.data.keep_icon = True newtab.history.deserialize(history) newtab.zoom.set_factor(curtab.zoom.factor()) + new_tabbed_browser.set_tab_pinned(idx, pinned) return newtab @cmdutils.register(instance='command-dispatcher', scope='window') diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py index 6e2f92b9d..3e2b2c9c8 100644 --- a/qutebrowser/mainwindow/tabwidget.py +++ b/qutebrowser/mainwindow/tabwidget.py @@ -94,21 +94,29 @@ class TabWidget(QTabWidget): bar.set_tab_data(idx, 'indicator-color', color) bar.update(bar.tabRect(idx)) - def set_tab_pinned(self, idx, pinned): + def set_tab_pinned(self, idx, pinned, *, loading=False): """Set the tab status as pinned. Args: idx: The tab index. pinned: Pinned tab state to set. + loading: Whether to ignore current data state when + counting pinned_count. """ bar = self.tabBar() - bar.set_tab_data(idx, 'pinned', pinned) - self.update_tab_title(idx) + tab = self.widget(idx) - if pinned: - bar.pinned_count += 1 - else: - bar.pinned_count -= 1 + # Only modify pinned_count if we had a change + # always modify pinned_count if we are loading + if tab.data.pinned != pinned or loading: + if pinned: + bar.pinned_count += 1 + elif not pinned: + bar.pinned_count -= 1 + + bar.set_tab_data(idx, 'pinned', pinned) + tab.data.pinned = pinned + self.update_tab_title(idx) bar.refresh() diff --git a/qutebrowser/misc/sessions.py b/qutebrowser/misc/sessions.py index 94c5855bd..c33dc8045 100644 --- a/qutebrowser/misc/sessions.py +++ b/qutebrowser/misc/sessions.py @@ -396,7 +396,7 @@ class SessionManager(QObject): if tab.get('active', False): tab_to_focus = i if new_tab.data.pinned: - tabbed_browser.set_tab_pinned(i, new_tab.data.pinned) + tabbed_browser.set_tab_pinned(i, new_tab.data.pinned, loading=True) if tab_to_focus is not None: tabbed_browser.setCurrentIndex(tab_to_focus) if win.get('active', False):