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:
|
if tab is None:
|
||||||
return
|
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
|
tab_index = self._current_index() if count is None else count - 1
|
||||||
cmdutils.check_overflow(tab_index + 1, 'int')
|
cmdutils.check_overflow(tab_index + 1, 'int')
|
||||||
self._tabbed_browser.set_tab_pinned(tab_index,
|
self._tabbed_browser.set_tab_pinned(tab_index, to_pin)
|
||||||
tab.data.pinned)
|
|
||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', name='open',
|
@cmdutils.register(instance='command-dispatcher', name='open',
|
||||||
maxsplit=0, scope='window')
|
maxsplit=0, scope='window')
|
||||||
@ -475,6 +473,7 @@ class CommandDispatcher:
|
|||||||
"""
|
"""
|
||||||
cmdutils.check_exclusive((bg, window), 'bw')
|
cmdutils.check_exclusive((bg, window), 'bw')
|
||||||
curtab = self._current_widget()
|
curtab = self._current_widget()
|
||||||
|
pinned = curtab.data.pinned
|
||||||
cur_title = self._tabbed_browser.page_title(self._current_index())
|
cur_title = self._tabbed_browser.page_title(self._current_index())
|
||||||
try:
|
try:
|
||||||
history = curtab.history.serialize()
|
history = curtab.history.serialize()
|
||||||
@ -501,6 +500,7 @@ class CommandDispatcher:
|
|||||||
newtab.data.keep_icon = True
|
newtab.data.keep_icon = True
|
||||||
newtab.history.deserialize(history)
|
newtab.history.deserialize(history)
|
||||||
newtab.zoom.set_factor(curtab.zoom.factor())
|
newtab.zoom.set_factor(curtab.zoom.factor())
|
||||||
|
new_tabbed_browser.set_tab_pinned(idx, pinned)
|
||||||
return newtab
|
return newtab
|
||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||||
|
@ -94,22 +94,30 @@ class TabWidget(QTabWidget):
|
|||||||
bar.set_tab_data(idx, 'indicator-color', color)
|
bar.set_tab_data(idx, 'indicator-color', color)
|
||||||
bar.update(bar.tabRect(idx))
|
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.
|
"""Set the tab status as pinned.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
idx: The tab index.
|
idx: The tab index.
|
||||||
pinned: Pinned tab state to set.
|
pinned: Pinned tab state to set.
|
||||||
|
loading: Whether to ignore current data state when
|
||||||
|
counting pinned_count.
|
||||||
"""
|
"""
|
||||||
bar = self.tabBar()
|
bar = self.tabBar()
|
||||||
bar.set_tab_data(idx, 'pinned', pinned)
|
tab = self.widget(idx)
|
||||||
self.update_tab_title(idx)
|
|
||||||
|
|
||||||
|
# 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:
|
if pinned:
|
||||||
bar.pinned_count += 1
|
bar.pinned_count += 1
|
||||||
else:
|
elif not pinned:
|
||||||
bar.pinned_count -= 1
|
bar.pinned_count -= 1
|
||||||
|
|
||||||
|
bar.set_tab_data(idx, 'pinned', pinned)
|
||||||
|
tab.data.pinned = pinned
|
||||||
|
self.update_tab_title(idx)
|
||||||
|
|
||||||
bar.refresh()
|
bar.refresh()
|
||||||
|
|
||||||
def tab_indicator_color(self, idx):
|
def tab_indicator_color(self, idx):
|
||||||
|
@ -396,7 +396,7 @@ class SessionManager(QObject):
|
|||||||
if tab.get('active', False):
|
if tab.get('active', False):
|
||||||
tab_to_focus = i
|
tab_to_focus = i
|
||||||
if new_tab.data.pinned:
|
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:
|
if tab_to_focus is not None:
|
||||||
tabbed_browser.setCurrentIndex(tab_to_focus)
|
tabbed_browser.setCurrentIndex(tab_to_focus)
|
||||||
if win.get('active', False):
|
if win.get('active', False):
|
||||||
|
Loading…
Reference in New Issue
Block a user