Merge pull request #2765 from jgkamat/jay/tab-crashes
Refactor set_tab_pinned to take a tab widget.
This commit is contained in:
commit
45b1285402
@ -280,9 +280,7 @@ class CommandDispatcher:
|
|||||||
return
|
return
|
||||||
|
|
||||||
to_pin = not tab.data.pinned
|
to_pin = not tab.data.pinned
|
||||||
tab_index = self._current_index() if count is None else count - 1
|
self._tabbed_browser.set_tab_pinned(tab, to_pin)
|
||||||
cmdutils.check_overflow(tab_index + 1, 'int')
|
|
||||||
self._tabbed_browser.set_tab_pinned(tab_index, to_pin)
|
|
||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', name='open',
|
@cmdutils.register(instance='command-dispatcher', name='open',
|
||||||
maxsplit=0, scope='window')
|
maxsplit=0, scope='window')
|
||||||
@ -515,7 +513,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, curtab.data.pinned)
|
new_tabbed_browser.set_tab_pinned(newtab, curtab.data.pinned)
|
||||||
return newtab
|
return newtab
|
||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||||
|
@ -342,7 +342,7 @@ class TabbedBrowser(tabwidget.TabWidget):
|
|||||||
newtab = self.tabopen(url, background=False, idx=idx)
|
newtab = self.tabopen(url, background=False, idx=idx)
|
||||||
|
|
||||||
newtab.history.deserialize(history_data)
|
newtab.history.deserialize(history_data)
|
||||||
self.set_tab_pinned(idx, pinned)
|
self.set_tab_pinned(newtab, pinned)
|
||||||
|
|
||||||
@pyqtSlot('QUrl', bool)
|
@pyqtSlot('QUrl', bool)
|
||||||
def openurl(self, url, newtab):
|
def openurl(self, url, newtab):
|
||||||
|
@ -26,7 +26,7 @@ from PyQt5.QtCore import (pyqtSignal, pyqtSlot, Qt, QSize, QRect, QPoint,
|
|||||||
QTimer, QUrl)
|
QTimer, QUrl)
|
||||||
from PyQt5.QtWidgets import (QTabWidget, QTabBar, QSizePolicy, QCommonStyle,
|
from PyQt5.QtWidgets import (QTabWidget, QTabBar, QSizePolicy, QCommonStyle,
|
||||||
QStyle, QStylePainter, QStyleOptionTab,
|
QStyle, QStylePainter, QStyleOptionTab,
|
||||||
QStyleFactory)
|
QStyleFactory, QWidget)
|
||||||
from PyQt5.QtGui import QIcon, QPalette, QColor
|
from PyQt5.QtGui import QIcon, QPalette, QColor
|
||||||
|
|
||||||
from qutebrowser.utils import qtutils, objreg, utils, usertypes, log
|
from qutebrowser.utils import qtutils, objreg, utils, usertypes, log
|
||||||
@ -94,17 +94,18 @@ 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, *, loading=False):
|
def set_tab_pinned(self, tab: QWidget,
|
||||||
|
pinned: bool, *, loading: bool = False) -> None:
|
||||||
"""Set the tab status as pinned.
|
"""Set the tab status as pinned.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
idx: The tab index.
|
tab: The tab to pin
|
||||||
pinned: Pinned tab state to set.
|
pinned: Pinned tab state to set.
|
||||||
loading: Whether to ignore current data state when
|
loading: Whether to ignore current data state when
|
||||||
counting pinned_count.
|
counting pinned_count.
|
||||||
"""
|
"""
|
||||||
bar = self.tabBar()
|
bar = self.tabBar()
|
||||||
tab = self.widget(idx)
|
idx = self.indexOf(tab)
|
||||||
|
|
||||||
# Only modify pinned_count if we had a change
|
# Only modify pinned_count if we had a change
|
||||||
# always modify pinned_count if we are loading
|
# always modify pinned_count if we are loading
|
||||||
|
@ -406,7 +406,7 @@ class SessionManager(QObject):
|
|||||||
tab_to_focus = i
|
tab_to_focus = i
|
||||||
if new_tab.data.pinned:
|
if new_tab.data.pinned:
|
||||||
tabbed_browser.set_tab_pinned(
|
tabbed_browser.set_tab_pinned(
|
||||||
i, new_tab.data.pinned, loading=True)
|
new_tab, 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):
|
||||||
|
@ -1073,6 +1073,16 @@ Feature: Tab management
|
|||||||
- data/numbers/2.txt (pinned)
|
- data/numbers/2.txt (pinned)
|
||||||
- data/numbers/3.txt (active)
|
- data/numbers/3.txt (active)
|
||||||
|
|
||||||
|
Scenario: :tab-pin with an invalid count
|
||||||
|
When I open data/numbers/1.txt
|
||||||
|
And I open data/numbers/2.txt in a new tab
|
||||||
|
And I open data/numbers/3.txt in a new tab
|
||||||
|
And I run :tab-pin with count 23
|
||||||
|
Then the following tabs should be open:
|
||||||
|
- data/numbers/1.txt
|
||||||
|
- data/numbers/2.txt
|
||||||
|
- data/numbers/3.txt (active)
|
||||||
|
|
||||||
Scenario: Pinned :tab-close prompt yes
|
Scenario: Pinned :tab-close prompt yes
|
||||||
When I open data/numbers/1.txt
|
When I open data/numbers/1.txt
|
||||||
And I run :tab-pin
|
And I run :tab-pin
|
||||||
|
Loading…
Reference in New Issue
Block a user