commands: Move tab opening to _open functions.
This commit is contained in:
parent
207bb00c50
commit
d5a294ae55
@ -72,6 +72,24 @@ class CommandDispatcher:
|
|||||||
raise cmdexc.CommandError("No WebView available yet!")
|
raise cmdexc.CommandError("No WebView available yet!")
|
||||||
return widget
|
return widget
|
||||||
|
|
||||||
|
def _open(self, url, tab, background):
|
||||||
|
"""Helper function to open a page.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
url: The URL to open as QUrl.
|
||||||
|
tab: Whether to open in a new tab.
|
||||||
|
background: Whether to open in the background.
|
||||||
|
"""
|
||||||
|
if tab and background:
|
||||||
|
raise cmdexc.CommandError("Only one of -t/-b can be given!")
|
||||||
|
elif tab:
|
||||||
|
self._tabs.tabopen(url, background=False, explicit=True)
|
||||||
|
elif background:
|
||||||
|
self._tabs.tabopen(url, background=True, explicit=True)
|
||||||
|
else:
|
||||||
|
widget = self._current_widget()
|
||||||
|
widget.openurl(url)
|
||||||
|
|
||||||
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).
|
||||||
|
|
||||||
@ -338,10 +356,7 @@ class CommandDispatcher:
|
|||||||
raise cmdexc.CommandError("Can't go up!")
|
raise cmdexc.CommandError("Can't go up!")
|
||||||
new_path = posixpath.join(path, posixpath.pardir)
|
new_path = posixpath.join(path, posixpath.pardir)
|
||||||
url.setPath(new_path)
|
url.setPath(new_path)
|
||||||
if tab:
|
self._open(url, tab, background=False)
|
||||||
self._tabs.tabopen(url, background=False, explicit=True)
|
|
||||||
else:
|
|
||||||
widget.openurl(url)
|
|
||||||
elif where in ('decrement', 'increment'):
|
elif where in ('decrement', 'increment'):
|
||||||
encoded = bytes(url.toEncoded()).decode('ascii')
|
encoded = bytes(url.toEncoded()).decode('ascii')
|
||||||
# Get the last number in a string
|
# Get the last number in a string
|
||||||
@ -365,10 +380,7 @@ class CommandDispatcher:
|
|||||||
val += 1
|
val += 1
|
||||||
urlstr = ''.join([pre, str(val), post]).encode('ascii')
|
urlstr = ''.join([pre, str(val), post]).encode('ascii')
|
||||||
new_url = QUrl.fromEncoded(urlstr)
|
new_url = QUrl.fromEncoded(urlstr)
|
||||||
if tab:
|
self._open(new_url, tab, background=False)
|
||||||
self._tabs.tabopen(new_url, background=False, explicit=True)
|
|
||||||
else:
|
|
||||||
widget.openurl(new_url)
|
|
||||||
else:
|
else:
|
||||||
raise ValueError("Got called with invalid value {} for "
|
raise ValueError("Got called with invalid value {} for "
|
||||||
"`where'.".format(where))
|
"`where'.".format(where))
|
||||||
@ -554,13 +566,7 @@ class CommandDispatcher:
|
|||||||
url = urlutils.fuzzy_url(text)
|
url = urlutils.fuzzy_url(text)
|
||||||
except urlutils.FuzzyUrlError as e:
|
except urlutils.FuzzyUrlError as e:
|
||||||
raise cmdexc.CommandError(e)
|
raise cmdexc.CommandError(e)
|
||||||
if tab:
|
self._open(url, tab, bg)
|
||||||
self._tabs.tabopen(url, background=False, explicit=True)
|
|
||||||
elif bg:
|
|
||||||
self._tabs.tabopen(url, background=True, explicit=True)
|
|
||||||
else:
|
|
||||||
widget = self._current_widget()
|
|
||||||
widget.openurl(url)
|
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
||||||
def tab_focus(self, index: (int, 'last')=None, count=None):
|
def tab_focus(self, index: (int, 'last')=None, count=None):
|
||||||
@ -677,12 +683,7 @@ class CommandDispatcher:
|
|||||||
if not url.isValid():
|
if not url.isValid():
|
||||||
raise cmdexc.CommandError("Invalid URL {} ({})".format(
|
raise cmdexc.CommandError("Invalid URL {} ({})".format(
|
||||||
urlstr, url.errorString()))
|
urlstr, url.errorString()))
|
||||||
if tab:
|
self._open(url, tab, bg)
|
||||||
self._tabs.tabopen(url, background=False, explicit=True)
|
|
||||||
elif bg:
|
|
||||||
self._tabs.tabopen(url, background=True, explicit=True)
|
|
||||||
else:
|
|
||||||
self._current_widget().openurl(url)
|
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd', name='inspector')
|
@cmdutils.register(instance='mainwindow.tabs.cmd', name='inspector')
|
||||||
def toggle_inspector(self):
|
def toggle_inspector(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user