Move cntwidget to commands.
This commit is contained in:
parent
fd9c4b860a
commit
5e8144fafa
@ -92,6 +92,26 @@ class CommandDispatcher:
|
|||||||
widget = self._current_widget()
|
widget = self._current_widget()
|
||||||
widget.openurl(url)
|
widget.openurl(url)
|
||||||
|
|
||||||
|
def _cntwidget(self, count=None):
|
||||||
|
"""Return a widget based on a count/idx.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
count: The tab index, or None.
|
||||||
|
|
||||||
|
Return:
|
||||||
|
The current widget if count is None.
|
||||||
|
The widget with the given tab ID if count is given.
|
||||||
|
None if no widget was found.
|
||||||
|
"""
|
||||||
|
if count is None:
|
||||||
|
return self._tabs.currentWidget()
|
||||||
|
elif 1 <= count <= self._tabs.count():
|
||||||
|
cmdutils.check_overflow(count + 1, 'int')
|
||||||
|
return self._tabs.widget(count - 1)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _scroll_percent(self, perc=None, count=None, orientation=None):
|
def _scroll_percent(self, perc=None, count=None, orientation=None):
|
||||||
"""Inner logic for scroll_percent_(x|y).
|
"""Inner logic for scroll_percent_(x|y).
|
||||||
|
|
||||||
@ -170,7 +190,7 @@ class CommandDispatcher:
|
|||||||
quit: If last tab was closed and last-close in config is set to
|
quit: If last tab was closed and last-close in config is set to
|
||||||
quit.
|
quit.
|
||||||
"""
|
"""
|
||||||
tab = self._tabs.cntwidget(count)
|
tab = self._cntwidget(count)
|
||||||
if tab is None:
|
if tab is None:
|
||||||
return
|
return
|
||||||
self._tabs.close_tab(tab)
|
self._tabs.close_tab(tab)
|
||||||
@ -195,7 +215,7 @@ class CommandDispatcher:
|
|||||||
elif bg:
|
elif bg:
|
||||||
self._tabs.tabopen(url, background=True, explicit=True)
|
self._tabs.tabopen(url, background=True, explicit=True)
|
||||||
else:
|
else:
|
||||||
curtab = self._tabs.cntwidget(count)
|
curtab = self._cntwidget(count)
|
||||||
if curtab is None:
|
if curtab is None:
|
||||||
if count is None:
|
if count is None:
|
||||||
# We want to open a URL in the current tab, but none exists
|
# We want to open a URL in the current tab, but none exists
|
||||||
@ -214,7 +234,7 @@ class CommandDispatcher:
|
|||||||
Args:
|
Args:
|
||||||
count: The tab index to reload, or None.
|
count: The tab index to reload, or None.
|
||||||
"""
|
"""
|
||||||
tab = self._tabs.cntwidget(count)
|
tab = self._cntwidget(count)
|
||||||
if tab is not None:
|
if tab is not None:
|
||||||
tab.reload()
|
tab.reload()
|
||||||
|
|
||||||
@ -225,7 +245,7 @@ class CommandDispatcher:
|
|||||||
Args:
|
Args:
|
||||||
count: The tab index to stop, or None.
|
count: The tab index to stop, or None.
|
||||||
"""
|
"""
|
||||||
tab = self._tabs.cntwidget(count)
|
tab = self._cntwidget(count)
|
||||||
if tab is not None:
|
if tab is not None:
|
||||||
tab.stop()
|
tab.stop()
|
||||||
|
|
||||||
@ -241,7 +261,7 @@ class CommandDispatcher:
|
|||||||
# WORKAROUND (remove this when we bump the requirements to 5.3.0)
|
# WORKAROUND (remove this when we bump the requirements to 5.3.0)
|
||||||
raise cmdexc.CommandError(
|
raise cmdexc.CommandError(
|
||||||
"Printing on Qt < 5.3.0 on Windows is broken, please upgrade!")
|
"Printing on Qt < 5.3.0 on Windows is broken, please upgrade!")
|
||||||
tab = self._tabs.cntwidget(count)
|
tab = self._cntwidget(count)
|
||||||
if tab is not None:
|
if tab is not None:
|
||||||
if preview:
|
if preview:
|
||||||
diag = QPrintPreviewDialog()
|
diag = QPrintPreviewDialog()
|
||||||
|
@ -174,25 +174,6 @@ class TabbedBrowser(tabwidget.TabWidget):
|
|||||||
page.windowCloseRequested.connect(
|
page.windowCloseRequested.connect(
|
||||||
functools.partial(self.on_window_close_requested, tab))
|
functools.partial(self.on_window_close_requested, tab))
|
||||||
|
|
||||||
def cntwidget(self, count=None):
|
|
||||||
"""Return a widget based on a count/idx.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
count: The tab index, or None.
|
|
||||||
|
|
||||||
Return:
|
|
||||||
The current widget if count is None.
|
|
||||||
The widget with the given tab ID if count is given.
|
|
||||||
None if no widget was found.
|
|
||||||
"""
|
|
||||||
if count is None:
|
|
||||||
return self.currentWidget()
|
|
||||||
elif 1 <= count <= self.count():
|
|
||||||
cmdutils.check_overflow(count + 1, 'int')
|
|
||||||
return self.widget(count - 1)
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def current_url(self):
|
def current_url(self):
|
||||||
"""Get the URL of the current tab.
|
"""Get the URL of the current tab.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user