Add KeyParser for normal mode
This commit is contained in:
parent
c674d96cfe
commit
d2dc0b7ac5
@ -57,6 +57,7 @@ import qutebrowser.utils.message as message
|
||||
from qutebrowser.widgets.mainwindow import MainWindow
|
||||
from qutebrowser.widgets.crash import CrashDialog
|
||||
from qutebrowser.keyinput.commandmode import CommandKeyParser
|
||||
from qutebrowser.keyinput.insertmode import InsertKeyParser
|
||||
from qutebrowser.commands.parsers import CommandParser, SearchParser
|
||||
from qutebrowser.browser.hints import HintKeyParser
|
||||
from qutebrowser.utils.appdirs import AppDirs
|
||||
@ -124,16 +125,18 @@ class QuteBrowser(QApplication):
|
||||
self.commandparser = CommandParser()
|
||||
self.searchparser = SearchParser()
|
||||
self._keyparsers = {
|
||||
"normal": CommandKeyParser(self),
|
||||
"hint": HintKeyParser(self),
|
||||
'normal': CommandKeyParser(self),
|
||||
'hint': HintKeyParser(self),
|
||||
'insert': InsertKeyParser(self),
|
||||
}
|
||||
self._init_cmds()
|
||||
self.mainwindow = MainWindow()
|
||||
modes.init(self)
|
||||
modes.manager.register("normal", self._keyparsers["normal"].handle)
|
||||
modes.manager.register("hint", self._keyparsers["hint"].handle)
|
||||
modes.manager.register("insert", None, passthrough=True)
|
||||
modes.manager.register("command", None, passthrough=True)
|
||||
modes.manager.register('normal', self._keyparsers['normal'].handle)
|
||||
modes.manager.register('hint', self._keyparsers['hint'].handle)
|
||||
modes.manager.register('insert', self._keyparsers['insert'].handle,
|
||||
passthrough=True)
|
||||
modes.manager.register('command', None, passthrough=True)
|
||||
self.installEventFilter(modes.manager)
|
||||
self.setQuitOnLastWindowClosed(False)
|
||||
|
||||
|
@ -78,6 +78,13 @@ SECTION_DESC = {
|
||||
"pressed with Shift. For special keys (with <>-signs), you need "
|
||||
"to explicitely add \"Shift-\" to match a key pressed with shift. "
|
||||
"You can bind multiple commands by separating them with \";;\"."),
|
||||
'keybind.insert': (
|
||||
"Keybindings for insert mode.\n"
|
||||
"Since normal keypresses are passed through, only special keys are "
|
||||
"supported in this mode.\n"
|
||||
"In addition to the normal commands, the following special commands "
|
||||
"are defined:\n"
|
||||
" <normal>: Switch back to normal mode."),
|
||||
'aliases': (
|
||||
"Aliases for commands.\n"
|
||||
"By default, no aliases are defined. Example which adds a new command "
|
||||
@ -420,6 +427,12 @@ DATA = OrderedDict([
|
||||
('<Backspace>', 'back'),
|
||||
)),
|
||||
|
||||
('keybind.insert', sect.ValueList(
|
||||
types.KeyBindingName(), types.KeyBinding(['<normal>']),
|
||||
('<Escape>', '<normal>'),
|
||||
('<Ctrl-C>', '<normal>'),
|
||||
)),
|
||||
|
||||
('aliases', sect.ValueList(
|
||||
types.Command(), types.Command(),
|
||||
)),
|
||||
|
@ -538,6 +538,18 @@ class LastClose(String):
|
||||
|
||||
class KeyBinding(Command):
|
||||
|
||||
"""The command of a keybinding."""
|
||||
"""The command of a keybinding.
|
||||
|
||||
pass
|
||||
Attributes:
|
||||
_special_keys: Specially defined keys which are no commands.
|
||||
"""
|
||||
|
||||
def __init__(self, special_keys=None):
|
||||
if special_keys == None:
|
||||
special_keys = []
|
||||
self._special_keys = special_keys
|
||||
|
||||
def validate(self, value):
|
||||
if value in self._special_keys:
|
||||
return
|
||||
super().validate(value)
|
||||
|
37
qutebrowser/keyinput/insertmode.py
Normal file
37
qutebrowser/keyinput/insertmode.py
Normal file
@ -0,0 +1,37 @@
|
||||
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
||||
#
|
||||
# This file is part of qutebrowser.
|
||||
#
|
||||
# qutebrowser is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# qutebrowser is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""KeyParser for "insert" mode."""
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, Qt
|
||||
|
||||
import qutebrowser.keyinput.modes as modes
|
||||
from qutebrowser.keyinput.keyparser import KeyParser
|
||||
|
||||
|
||||
class InsertKeyParser(KeyParser):
|
||||
|
||||
"""KeyParser for insert mode."""
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.read_config('keybind.insert')
|
||||
|
||||
def execute(self, cmdstr, count=None):
|
||||
"""Handle a completed keychain."""
|
||||
if cmdstr == '<normal>':
|
||||
modes.leave("insert")
|
Loading…
Reference in New Issue
Block a user