Split some functions into smaller ones.

This commit is contained in:
Florian Bruhin 2014-11-23 21:26:59 +01:00
parent 655115858c
commit 0a1bdd79da
2 changed files with 44 additions and 18 deletions

View File

@ -512,15 +512,17 @@ class Application(QApplication):
"""Quit qutebrowser."""
QApplication.closeAllWindows()
@cmdutils.register(instance='app', ignore_args=True)
def restart(self, shutdown=True, pages=None):
"""Restart qutebrowser while keeping existing tabs open."""
if pages is None:
pages = self._recover_pages()
log.destroy.debug("sys.executable: {}".format(sys.executable))
log.destroy.debug("sys.path: {}".format(sys.path))
log.destroy.debug("sys.argv: {}".format(sys.argv))
log.destroy.debug("frozen: {}".format(hasattr(sys, 'frozen')))
def _get_restart_args(self, pages):
"""Get the current working directory and args to relaunch qutebrowser.
Args:
pages: The pages to re-open.
Return:
An (args, cwd) tuple.
args: The commandline as a list of strings.
cwd: The current working directory as a string.
"""
if os.path.basename(sys.argv[0]) == 'qutebrowser':
# Launched via launcher script
args = [sys.argv[0]]
@ -545,6 +547,18 @@ class Application(QApplication):
args.extend(page_args[:-1])
log.destroy.debug("args: {}".format(args))
log.destroy.debug("cwd: {}".format(cwd))
return args, cwd
@cmdutils.register(instance='app', ignore_args=True)
def restart(self, shutdown=True, pages=None):
"""Restart qutebrowser while keeping existing tabs open."""
if pages is None:
pages = self._recover_pages()
log.destroy.debug("sys.executable: {}".format(sys.executable))
log.destroy.debug("sys.path: {}".format(sys.path))
log.destroy.debug("sys.argv: {}".format(sys.argv))
log.destroy.debug("frozen: {}".format(hasattr(sys, 'frozen')))
args, cwd = self._get_restart_args(pages)
# Open a new process and immediately shutdown the existing one
try:
if cwd is None:

View File

@ -328,6 +328,26 @@ class TabbedBrowser(tabwidget.TabWidget):
return tabbed_browser.tabopen(url, background, explicit)
tab = webview.WebView(self._win_id, self)
self._connect_tab_signals(tab)
idx = self._get_new_tab_idx(explicit)
self.insertTab(idx, tab, "")
if url is not None:
tab.openurl(url)
if background is None:
background = config.get('tabs', 'background-tabs')
if not background:
self.setCurrentWidget(tab)
tab.show()
return tab
def _get_new_tab_idx(self, explicit):
"""Get the index of a tab to insert.
Args:
explicit: Whether the tab was opened explicitely.
Return:
The index of the new tab.
"""
if explicit:
pos = config.get('tabs', 'new-tab-position-explicit')
else:
@ -352,15 +372,7 @@ class TabbedBrowser(tabwidget.TabWidget):
"next left: {} / right: {}".format(
pos, idx, self._tab_insert_idx_left,
self._tab_insert_idx_right))
self.insertTab(idx, tab, "")
if url is not None:
tab.openurl(url)
if background is None:
background = config.get('tabs', 'background-tabs')
if not background:
self.setCurrentWidget(tab)
tab.show()
return tab
return idx
@pyqtSlot(str, int)
def search(self, text, flags):