Allow other chars than : to be used for commandline

This commit is contained in:
Florian Bruhin 2014-01-29 20:25:41 +01:00
parent 891fa581fd
commit c0f01d9219
3 changed files with 17 additions and 12 deletions

View File

@ -61,7 +61,7 @@ class QuteBrowser(QApplication):
self.mainwindow.tabs.keypress.connect(self.keyparser.handle) self.mainwindow.tabs.keypress.connect(self.keyparser.handle)
self.keyparser.set_cmd_text.connect(self.mainwindow.status.cmd.set_cmd) self.keyparser.set_cmd_text.connect(self.mainwindow.status.cmd.set_cmd)
self.mainwindow.status.cmd.got_cmd.connect(self.commandparser.run) self.mainwindow.status.cmd.got_cmd.connect(self.commandparser.run)
self.mainwindow.status.cmd.got_cmd.connect( self.mainwindow.status.cmd.returnPressed.connect(
self.mainwindow.tabs.setFocus) self.mainwindow.tabs.setFocus)
self.commandparser.error.connect(self.mainwindow.status.disp_error) self.commandparser.error.connect(self.mainwindow.status.disp_error)
self.keyparser.commandparser.error.connect( self.keyparser.commandparser.error.connect(

View File

@ -9,6 +9,9 @@ from PyQt5.QtCore import QObject, pyqtSignal
from qutebrowser.commands.utils import (CommandParser, ArgumentCountError, from qutebrowser.commands.utils import (CommandParser, ArgumentCountError,
NoSuchCommandError) NoSuchCommandError)
# Possible chars for starting a commandline input
startchars = ":/?"
class KeyParser(QObject): class KeyParser(QObject):
"""Parser for vim-like key sequences.""" """Parser for vim-like key sequences."""
@ -61,8 +64,8 @@ class KeyParser(QObject):
self.keystring += txt self.keystring += txt
if self.keystring == ':': if any(self.keystring == c for c in startchars):
self.set_cmd_text.emit('') self.set_cmd_text.emit(self.keystring)
self.keystring = '' self.keystring = ''
return return
@ -102,7 +105,7 @@ class KeyParser(QObject):
except ArgumentCountError: except ArgumentCountError:
logging.debug('Filling statusbar with partial command {}'.format( logging.debug('Filling statusbar with partial command {}'.format(
cmdstr_hay)) cmdstr_hay))
self.set_cmd_text.emit(cmdstr_hay + ' ') self.set_cmd_text.emit(':{} '.format(cmdstr_hay))
return return
def _match_key(self, cmdstr_needle): def _match_key(self, cmdstr_needle):

View File

@ -5,6 +5,8 @@ from PyQt5.QtWidgets import QLineEdit, QShortcut
from PyQt5.QtCore import pyqtSignal, Qt from PyQt5.QtCore import pyqtSignal, Qt
from PyQt5.QtGui import QValidator, QKeySequence from PyQt5.QtGui import QValidator, QKeySequence
import qutebrowser.commands.keys as keys
class Command(QLineEdit): class Command(QLineEdit):
"""The commandline part of the statusbar.""" """The commandline part of the statusbar."""
@ -28,7 +30,7 @@ class Command(QLineEdit):
self.statusbar = statusbar self.statusbar = statusbar
self.setStyleSheet("border: 0px; padding-left: 1px") self.setStyleSheet("border: 0px; padding-left: 1px")
self.setValidator(Validator()) self.setValidator(Validator())
self.returnPressed.connect(self.process_cmd) self.returnPressed.connect(self.process_cmdline)
self.textEdited.connect(self._histbrowse_stop) self.textEdited.connect(self._histbrowse_stop)
for (key, handler) in [ for (key, handler) in [
@ -43,18 +45,19 @@ class Command(QLineEdit):
sc.setContext(Qt.WidgetWithChildrenShortcut) sc.setContext(Qt.WidgetWithChildrenShortcut)
sc.activated.connect(handler) sc.activated.connect(handler)
def process_cmd(self): def process_cmdline(self):
"""Handle the command in the status bar.""" """Handle the command in the status bar."""
self._histbrowse_stop() self._histbrowse_stop()
text = self.text().lstrip(':') text = self.text()
if not self.history or text != self.history[-1]: if not self.history or text != self.history[-1]:
self.history.append(text) self.history.append(text)
self.setText('') self.setText('')
self.got_cmd.emit(text) if text[0] == ':':
self.got_cmd.emit(text.lstrip(':'))
def set_cmd(self, text): def set_cmd(self, text):
"""Preset the statusbar to some text.""" """Preset the statusbar to some text."""
self.setText(':' + text) self.setText(text)
self.setFocus() self.setFocus()
def append_cmd(self, text): def append_cmd(self, text):
@ -85,7 +88,7 @@ class Command(QLineEdit):
history already. history already.
""" """
pre = self.text().strip().lstrip(':') pre = self.text().strip()
logging.debug('Preset text: "{}"'.format(pre)) logging.debug('Preset text: "{}"'.format(pre))
if pre: if pre:
self._tmphist = [e for e in self.history if e.startswith(pre)] self._tmphist = [e for e in self.history if e.startswith(pre)]
@ -138,8 +141,7 @@ class Validator(QValidator):
Returns a tuple (status, string, pos) as a QValidator should.\ Returns a tuple (status, string, pos) as a QValidator should.\
""" """
if any(string.startswith(c) for c in keys.startchars):
if string.startswith(':'):
return (QValidator.Acceptable, string, pos) return (QValidator.Acceptable, string, pos)
else: else:
return (QValidator.Invalid, string, pos) return (QValidator.Invalid, string, pos)