From d60ff5ed27c5e775228cbec374b46fff7d86e377 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 28 Jul 2014 02:16:37 +0200 Subject: [PATCH] Add a set-cmd-text command. --- qutebrowser/browser/commands.py | 20 +------------------- qutebrowser/config/configdata.py | 6 +++--- qutebrowser/widgets/statusbar/command.py | 20 +++++++++++++++++++- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index e69f39e43..afd357de2 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -38,7 +38,7 @@ import qutebrowser.browser.quickmarks as quickmarks import qutebrowser.utils.log as log import qutebrowser.utils.url as urlutils from qutebrowser.utils.qt import (check_overflow, check_print_compat, - qt_ensure_valid, QtValueError) + qt_ensure_valid) from qutebrowser.utils.editor import ExternalEditor from qutebrowser.commands.exceptions import CommandError from qutebrowser.commands.userscripts import UserscriptRunner @@ -451,24 +451,6 @@ class CommandDispatcher: raise CommandError(e) self._tabs.tabopen(url, background=True) - @cmdutils.register(instance='mainwindow.tabs.cmd', hide=True) - def open_tab_cur(self): - """Set the statusbar to :tabopen and the current URL.""" - urlstr = self._tabs.current_url().toDisplayString(QUrl.FullyEncoded) - message.set_cmd_text(':open-tab ' + urlstr) - - @cmdutils.register(instance='mainwindow.tabs.cmd', hide=True) - def open_cur(self): - """Set the statusbar to :open and the current URL.""" - urlstr = self._tabs.current_url().toDisplayString(QUrl.FullyEncoded) - message.set_cmd_text(':open ' + urlstr) - - @cmdutils.register(instance='mainwindow.tabs.cmd', hide=True) - def open_tab_bg_cur(self): - """Set the statusbar to :tabopen-bg and the current URL.""" - urlstr = self._tabs.current_url().toDisplayString(QUrl.FullyEncoded) - message.set_cmd_text(':open-tab-bg ' + urlstr) - @cmdutils.register(instance='mainwindow.tabs.cmd') def undo(self): """Re-open a closed tab (optionally skipping [count] tabs).""" diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 58afa4746..fbac47c89 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -598,11 +598,11 @@ DATA = OrderedDict([ ('keybind', sect.ValueList( types.KeyBindingName(), types.KeyBinding(), ('o', 'open'), - ('go', 'open-cur'), + ('go', 'set-cmd-text :open {url}'), ('O', 'open-tab'), - ('gO', 'open-tab-cur'), + ('gO', 'set-cmd-text :open-tab {url}'), ('xo', 'open-tab-bg'), - ('xO', 'open-tab-bg-cur'), + ('xO', 'set-cmd-text :open-tab-bg {url}'), ('ga', 'open-tab about:blank'), ('d', 'tab-close'), ('co', 'tab-only'), diff --git a/qutebrowser/widgets/statusbar/command.py b/qutebrowser/widgets/statusbar/command.py index 53fb8a168..d3ce0801b 100644 --- a/qutebrowser/widgets/statusbar/command.py +++ b/qutebrowser/widgets/statusbar/command.py @@ -31,6 +31,7 @@ from qutebrowser.keyinput.modeparsers import STARTCHARS from qutebrowser.utils.log import completion as logger from qutebrowser.models.cmdhistory import (History, HistoryEmptyError, HistoryEndReachedError) +from qutebrowser.commands.exceptions import CommandError class Command(MinimalLineEdit): @@ -154,7 +155,7 @@ class Command(MinimalLineEdit): """Preset the statusbar to some text. Args: - text: The text to set (string). + text: The text to set as string. Emit: update_completion: Emitted if the text changed. @@ -168,6 +169,23 @@ class Command(MinimalLineEdit): self.setFocus() self.show_cmd.emit() + @cmdutils.register(instance='mainwindow.status.cmd', name='set-cmd-text') + def set_cmd_text_command(self, *strings): + """Preset the statusbar to some text. + + // + + Wrapper for set_cmd_text to check the arguments and allow multiple + strings which will get joined. + + Args: + strings: A list of strings to set. + """ + text = ' '.join(strings) + if not any(text.startswith(c) for c in STARTCHARS): + raise CommandError("Invalid command text '{}'.".format(text)) + self.set_cmd_text(text) + @pyqtSlot(str, bool) def on_change_completed_part(self, newtext, immediate): """Change the part we're currently completing in the commandline.