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.
This commit is contained in:
parent
5e3c68530a
commit
2a961c3951
@ -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')
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user