Use enum for keyboard modes.
This commit is contained in:
parent
860ef75abc
commit
7c8f9bec0f
@ -61,7 +61,7 @@ from qutebrowser.browser.downloads import DownloadManager
|
||||
from qutebrowser.utils.misc import get_standard_dir, actute_warning
|
||||
from qutebrowser.utils.qt import get_qt_args
|
||||
from qutebrowser.utils.readline import ReadlineBridge
|
||||
from qutebrowser.utils.usertypes import Timer
|
||||
from qutebrowser.utils.usertypes import Timer, KeyMode
|
||||
|
||||
|
||||
class Application(QApplication):
|
||||
@ -154,7 +154,7 @@ class Application(QApplication):
|
||||
|
||||
log.init.debug("Connecting signals...")
|
||||
self._connect_signals()
|
||||
self.modeman.enter('normal', 'init')
|
||||
self.modeman.enter(KeyMode.normal, 'init')
|
||||
|
||||
log.init.debug("Showing mainwindow...")
|
||||
self.mainwindow.show()
|
||||
@ -202,27 +202,40 @@ class Application(QApplication):
|
||||
def _init_modes(self):
|
||||
"""Inizialize the mode manager and the keyparsers."""
|
||||
self._keyparsers = {
|
||||
'normal': NormalKeyParser(self),
|
||||
'hint': HintKeyParser(self),
|
||||
'insert': PassthroughKeyParser('keybind.insert', self),
|
||||
'passthrough': PassthroughKeyParser('keybind.passthrough', self),
|
||||
'command': PassthroughKeyParser('keybind.command', self),
|
||||
'prompt': PassthroughKeyParser('keybind.prompt', self, warn=False),
|
||||
'yesno': PromptKeyParser(self),
|
||||
KeyMode.normal:
|
||||
NormalKeyParser(self),
|
||||
KeyMode.hint:
|
||||
HintKeyParser(self),
|
||||
KeyMode.insert:
|
||||
PassthroughKeyParser('keybind.insert', self),
|
||||
KeyMode.passthrough:
|
||||
PassthroughKeyParser('keybind.passthrough', self),
|
||||
KeyMode.command:
|
||||
PassthroughKeyParser('keybind.command', self),
|
||||
KeyMode.prompt:
|
||||
PassthroughKeyParser('keybind.prompt', self, warn=False),
|
||||
KeyMode.yesno:
|
||||
PromptKeyParser(self),
|
||||
}
|
||||
self.modeman = ModeManager(self)
|
||||
self.modeman.register('normal', self._keyparsers['normal'].handle)
|
||||
self.modeman.register('hint', self._keyparsers['hint'].handle)
|
||||
self.modeman.register('insert', self._keyparsers['insert'].handle,
|
||||
self.modeman.register(KeyMode.normal,
|
||||
self._keyparsers[KeyMode.normal].handle)
|
||||
self.modeman.register(KeyMode.hint,
|
||||
self._keyparsers[KeyMode.hint].handle)
|
||||
self.modeman.register(KeyMode.insert,
|
||||
self._keyparsers[KeyMode.insert].handle,
|
||||
passthrough=True)
|
||||
self.modeman.register('passthrough',
|
||||
self._keyparsers['passthrough'].handle,
|
||||
self.modeman.register(KeyMode.passthrough,
|
||||
self._keyparsers[KeyMode.passthrough].handle,
|
||||
passthrough=True)
|
||||
self.modeman.register('command', self._keyparsers['command'].handle,
|
||||
self.modeman.register(KeyMode.command,
|
||||
self._keyparsers[KeyMode.command].handle,
|
||||
passthrough=True)
|
||||
self.modeman.register('prompt', self._keyparsers['prompt'].handle,
|
||||
self.modeman.register(KeyMode.prompt,
|
||||
self._keyparsers[KeyMode.prompt].handle,
|
||||
passthrough=True)
|
||||
self.modeman.register('yesno', self._keyparsers['yesno'].handle)
|
||||
self.modeman.register(KeyMode.yesno,
|
||||
self._keyparsers[KeyMode.yesno].handle)
|
||||
|
||||
def _init_misc(self):
|
||||
"""Initialize misc things."""
|
||||
@ -366,14 +379,15 @@ class Application(QApplication):
|
||||
cmd.got_search_rev.connect(self.searchmanager.search_rev)
|
||||
cmd.returnPressed.connect(tabs.setFocus)
|
||||
self.searchmanager.do_search.connect(tabs.search)
|
||||
kp['normal'].keystring_updated.connect(status.keystring.setText)
|
||||
kp[KeyMode.normal].keystring_updated.connect(status.keystring.setText)
|
||||
tabs.got_cmd.connect(self.commandmanager.run_safely)
|
||||
|
||||
# hints
|
||||
kp['hint'].fire_hint.connect(tabs.fire_hint)
|
||||
kp['hint'].filter_hints.connect(tabs.filter_hints)
|
||||
kp['hint'].keystring_updated.connect(tabs.handle_hint_key)
|
||||
tabs.hint_strings_updated.connect(kp['hint'].on_hint_strings_updated)
|
||||
kp[KeyMode.hint].fire_hint.connect(tabs.fire_hint)
|
||||
kp[KeyMode.hint].filter_hints.connect(tabs.filter_hints)
|
||||
kp[KeyMode.hint].keystring_updated.connect(tabs.handle_hint_key)
|
||||
tabs.hint_strings_updated.connect(
|
||||
kp[KeyMode.hint].on_hint_strings_updated)
|
||||
|
||||
# messages
|
||||
self.messagebridge.s_error.connect(status.disp_error)
|
||||
@ -386,7 +400,7 @@ class Application(QApplication):
|
||||
# config
|
||||
self.config.style_changed.connect(style.invalidate_caches)
|
||||
for obj in (tabs, completion, self.mainwindow, self.cmd_history,
|
||||
websettings, kp['normal'], self.modeman, status,
|
||||
websettings, kp[KeyMode.normal], self.modeman, status,
|
||||
status.txt):
|
||||
self.config.changed.connect(obj.on_config_changed)
|
||||
|
||||
|
@ -41,6 +41,7 @@ from qutebrowser.utils.qt import check_overflow, check_print_compat
|
||||
from qutebrowser.utils.editor import ExternalEditor
|
||||
from qutebrowser.commands.exceptions import CommandError
|
||||
from qutebrowser.commands.userscripts import UserscriptRunner
|
||||
from qutebrowser.utils.usertypes import KeyMode
|
||||
|
||||
|
||||
class CommandDispatcher:
|
||||
@ -664,7 +665,7 @@ class CommandDispatcher:
|
||||
page = self._tabs.currentWidget().page()
|
||||
self._tabs.download_get.emit(self._tabs.current_url(), page)
|
||||
|
||||
@cmdutils.register(instance='mainwindow.tabs.cmd', modes=['insert'],
|
||||
@cmdutils.register(instance='mainwindow.tabs.cmd', modes=[KeyMode.insert],
|
||||
hide=True)
|
||||
def open_editor(self):
|
||||
"""Open an external editor with the current form field.
|
||||
|
@ -31,7 +31,7 @@ import qutebrowser.keyinput.modeman as modeman
|
||||
import qutebrowser.utils.message as message
|
||||
import qutebrowser.utils.webelem as webelem
|
||||
from qutebrowser.commands.exceptions import CommandError
|
||||
from qutebrowser.utils.usertypes import enum
|
||||
from qutebrowser.utils.usertypes import enum, KeyMode
|
||||
from qutebrowser.utils.log import hints as logger
|
||||
from qutebrowser.utils.qt import qt_ensure_valid
|
||||
|
||||
@ -458,7 +458,7 @@ class HintManager(QObject):
|
||||
self._context = ctx
|
||||
self._connect_frame_signals()
|
||||
self.hint_strings_updated.emit(strings)
|
||||
modeman.enter('hint', 'HintManager.start')
|
||||
modeman.enter(KeyMode.hint, 'HintManager.start')
|
||||
|
||||
def handle_partial_key(self, keystr):
|
||||
"""Handle a new partial keypress."""
|
||||
@ -500,7 +500,7 @@ class HintManager(QObject):
|
||||
visible[k] = e
|
||||
if not visible:
|
||||
# Whoops, filtered all hints
|
||||
modeman.leave('hint', 'all filtered')
|
||||
modeman.leave(KeyMode.hint, 'all filtered')
|
||||
elif len(visible) == 1 and config.get('hints', 'auto-follow'):
|
||||
# unpacking gets us the first (and only) key in the dict.
|
||||
self.fire(*visible)
|
||||
@ -546,7 +546,7 @@ class HintManager(QObject):
|
||||
else:
|
||||
raise ValueError("No suitable handler found!")
|
||||
if self._context.target != Target.rapid:
|
||||
modeman.maybe_leave('hint', 'followed')
|
||||
modeman.maybe_leave(KeyMode.hint, 'followed')
|
||||
|
||||
def follow_hint(self):
|
||||
"""Follow the currently selected hint."""
|
||||
@ -567,16 +567,16 @@ class HintManager(QObject):
|
||||
css = self._get_hint_css(elems.elem, elems.label)
|
||||
elems.label.setAttribute('style', css)
|
||||
|
||||
@pyqtSlot(str)
|
||||
@pyqtSlot(KeyMode)
|
||||
def on_mode_entered(self, mode):
|
||||
"""Stop hinting when insert mode was entered."""
|
||||
if mode == 'insert':
|
||||
modeman.maybe_leave('hint', 'insert mode')
|
||||
if mode == KeyMode.insert:
|
||||
modeman.maybe_leave(KeyMode.hint, 'insert mode')
|
||||
|
||||
@pyqtSlot(str)
|
||||
@pyqtSlot(KeyMode)
|
||||
def on_mode_left(self, mode):
|
||||
"""Stop hinting when hinting mode was left."""
|
||||
if mode != 'hint' or self._context is None:
|
||||
if mode != KeyMode.hint or self._context is None:
|
||||
# We have one HintManager per tab, so when this gets called,
|
||||
# self._context might be None, because the current tab is not
|
||||
# hinting.
|
||||
|
@ -30,6 +30,8 @@ from PyQt5.QtWidgets import QApplication
|
||||
import qutebrowser.config.config as config
|
||||
import qutebrowser.commands.utils as cmdutils
|
||||
from qutebrowser.utils.log import modes as logger
|
||||
from qutebrowser.utils.usertypes import KeyMode
|
||||
from qutebrowser.commands.exceptions import CommandError
|
||||
|
||||
|
||||
def instance():
|
||||
@ -73,13 +75,13 @@ class ModeManager(QObject):
|
||||
|
||||
Signals:
|
||||
entered: Emitted when a mode is entered.
|
||||
arg: Name of the entered mode.
|
||||
arg: The mode which has been entered.
|
||||
left: Emitted when a mode is left.
|
||||
arg: Name of the left mode.
|
||||
arg: The mode which has been left.
|
||||
"""
|
||||
|
||||
entered = pyqtSignal(str)
|
||||
left = pyqtSignal(str)
|
||||
entered = pyqtSignal(KeyMode)
|
||||
left = pyqtSignal(KeyMode)
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
@ -123,7 +125,7 @@ class ModeManager(QObject):
|
||||
True if event should be filtered, False otherwise.
|
||||
"""
|
||||
handler = self._handlers[self.mode]
|
||||
if self.mode != 'insert':
|
||||
if self.mode != KeyMode.insert:
|
||||
logger.debug("got keypress in mode {} - calling handler {}".format(
|
||||
self.mode, handler.__qualname__))
|
||||
handled = handler(event) if handler is not None else False
|
||||
@ -142,7 +144,7 @@ class ModeManager(QObject):
|
||||
if not filter_this:
|
||||
self._releaseevents_to_pass.append(event)
|
||||
|
||||
if self.mode != 'insert':
|
||||
if self.mode != KeyMode.insert:
|
||||
logger.debug("handled: {}, forward-unbound-keys: {}, passthrough: "
|
||||
"{}, is_non_alnum: {} --> filter: {}".format(
|
||||
handled, self._forward_unbound_keys,
|
||||
@ -167,7 +169,7 @@ class ModeManager(QObject):
|
||||
filter_this = False
|
||||
else:
|
||||
filter_this = True
|
||||
if self.mode != 'insert':
|
||||
if self.mode != KeyMode.insert:
|
||||
logger.debug("filter: {}".format(filter_this))
|
||||
return filter_this
|
||||
|
||||
@ -184,12 +186,11 @@ class ModeManager(QObject):
|
||||
if passthrough:
|
||||
self.passthrough.append(mode)
|
||||
|
||||
@cmdutils.register(instance='modeman', name='enter-mode', hide=True)
|
||||
def enter(self, mode, reason=None):
|
||||
"""Enter a new mode.
|
||||
|
||||
Args:
|
||||
mode: The name of the mode to enter.
|
||||
mode: The mode to enter as a KeyMode member.
|
||||
reason: Why the mode was entered.
|
||||
|
||||
Emit:
|
||||
@ -206,6 +207,19 @@ class ModeManager(QObject):
|
||||
logger.debug("New mode stack: {}".format(self._mode_stack))
|
||||
self.entered.emit(mode)
|
||||
|
||||
@cmdutils.register(instance='modeman', hide=True)
|
||||
def enter_mode(self, mode):
|
||||
"""Enter mode as a command.
|
||||
|
||||
Args:
|
||||
mode: The mode to enter as a string.
|
||||
"""
|
||||
try:
|
||||
m = KeyMode[mode]
|
||||
except KeyError:
|
||||
raise CommandError("Mode {} does not exist!".format(mode))
|
||||
self.enter(m, 'command')
|
||||
|
||||
def leave(self, mode, reason=None):
|
||||
"""Leave a mode.
|
||||
|
||||
@ -226,10 +240,10 @@ class ModeManager(QObject):
|
||||
self.left.emit(mode)
|
||||
|
||||
@cmdutils.register(instance='modeman', name='leave-mode',
|
||||
not_modes=['normal'], hide=True)
|
||||
not_modes=[KeyMode.normal], hide=True)
|
||||
def leave_current_mode(self):
|
||||
"""Leave the mode we're currently in."""
|
||||
if self.mode == 'normal':
|
||||
if self.mode == KeyMode.normal:
|
||||
raise ValueError("Can't leave normal mode!")
|
||||
self.leave(self.mode, 'leave current')
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
from PyQt5.QtWidgets import QApplication, QLineEdit
|
||||
|
||||
import qutebrowser.commands.utils as cmd
|
||||
from qutebrowser.utils.usertypes import KeyMode
|
||||
|
||||
|
||||
class ReadlineBridge:
|
||||
@ -44,49 +45,56 @@ class ReadlineBridge:
|
||||
else:
|
||||
return None
|
||||
|
||||
@cmd.register(instance='rl_bridge', hide=True, modes=['command', 'prompt'])
|
||||
@cmd.register(instance='rl_bridge', hide=True,
|
||||
modes=[KeyMode.command, KeyMode.prompt])
|
||||
def rl_backward_char(self):
|
||||
"""Readline: Move back a character."""
|
||||
if self.widget is None:
|
||||
return
|
||||
self.widget.cursorBackward(False)
|
||||
|
||||
@cmd.register(instance='rl_bridge', hide=True, modes=['command', 'prompt'])
|
||||
@cmd.register(instance='rl_bridge', hide=True,
|
||||
modes=[KeyMode.command, KeyMode.prompt])
|
||||
def rl_forward_char(self):
|
||||
"""Readline: Move forward a character."""
|
||||
if self.widget is None:
|
||||
return
|
||||
self.widget.cursorForward(False)
|
||||
|
||||
@cmd.register(instance='rl_bridge', hide=True, modes=['command', 'prompt'])
|
||||
@cmd.register(instance='rl_bridge', hide=True,
|
||||
modes=[KeyMode.command, KeyMode.prompt])
|
||||
def rl_backward_word(self):
|
||||
"""Readline: Move back to the start of the current or previous word."""
|
||||
if self.widget is None:
|
||||
return
|
||||
self.widget.cursorWordBackward(False)
|
||||
|
||||
@cmd.register(instance='rl_bridge', hide=True, modes=['command', 'prompt'])
|
||||
@cmd.register(instance='rl_bridge', hide=True,
|
||||
modes=[KeyMode.command, KeyMode.prompt])
|
||||
def rl_forward_word(self):
|
||||
"""Readline: Move forward to the end of the next word."""
|
||||
if self.widget is None:
|
||||
return
|
||||
self.widget.cursorWordForward(False)
|
||||
|
||||
@cmd.register(instance='rl_bridge', hide=True, modes=['command', 'prompt'])
|
||||
@cmd.register(instance='rl_bridge', hide=True,
|
||||
modes=[KeyMode.command, KeyMode.prompt])
|
||||
def rl_beginning_of_line(self):
|
||||
"""Readline: Move to the start of the current line."""
|
||||
if self.widget is None:
|
||||
return
|
||||
self.widget.home(False)
|
||||
|
||||
@cmd.register(instance='rl_bridge', hide=True, modes=['command', 'prompt'])
|
||||
@cmd.register(instance='rl_bridge', hide=True,
|
||||
modes=[KeyMode.command, KeyMode.prompt])
|
||||
def rl_end_of_line(self):
|
||||
"""Readline: Move to the end of the line."""
|
||||
if self.widget is None:
|
||||
return
|
||||
self.widget.end(False)
|
||||
|
||||
@cmd.register(instance='rl_bridge', hide=True, modes=['command', 'prompt'])
|
||||
@cmd.register(instance='rl_bridge', hide=True,
|
||||
modes=[KeyMode.command, KeyMode.prompt])
|
||||
def rl_unix_line_discard(self):
|
||||
"""Readline: Kill backward from cursor to the beginning of the line."""
|
||||
if self.widget is None:
|
||||
@ -95,7 +103,8 @@ class ReadlineBridge:
|
||||
self.deleted[self.widget] = self.widget.selectedText()
|
||||
self.widget.del_()
|
||||
|
||||
@cmd.register(instance='rl_bridge', hide=True, modes=['command', 'prompt'])
|
||||
@cmd.register(instance='rl_bridge', hide=True,
|
||||
modes=[KeyMode.command, KeyMode.prompt])
|
||||
def rl_kill_line(self):
|
||||
"""Readline: Kill the text from point to the end of the line."""
|
||||
if self.widget is None:
|
||||
@ -104,7 +113,8 @@ class ReadlineBridge:
|
||||
self.deleted[self.widget] = self.widget.selectedText()
|
||||
self.widget.del_()
|
||||
|
||||
@cmd.register(instance='rl_bridge', hide=True, modes=['command', 'prompt'])
|
||||
@cmd.register(instance='rl_bridge', hide=True,
|
||||
modes=[KeyMode.command, KeyMode.prompt])
|
||||
def rl_unix_word_rubout(self):
|
||||
"""Readline: Kill the word behind point."""
|
||||
if self.widget is None:
|
||||
@ -113,7 +123,8 @@ class ReadlineBridge:
|
||||
self.deleted[self.widget] = self.widget.selectedText()
|
||||
self.widget.del_()
|
||||
|
||||
@cmd.register(instance='rl_bridge', hide=True, modes=['command', 'prompt'])
|
||||
@cmd.register(instance='rl_bridge', hide=True,
|
||||
modes=[KeyMode.command, KeyMode.prompt])
|
||||
def rl_kill_word(self):
|
||||
"""Readline: Kill from point to the end of the current word."""
|
||||
if self.widget is None:
|
||||
@ -122,21 +133,24 @@ class ReadlineBridge:
|
||||
self.deleted[self.widget] = self.widget.selectedText()
|
||||
self.widget.del_()
|
||||
|
||||
@cmd.register(instance='rl_bridge', hide=True, modes=['command', 'prompt'])
|
||||
@cmd.register(instance='rl_bridge', hide=True,
|
||||
modes=[KeyMode.command, KeyMode.prompt])
|
||||
def rl_yank(self):
|
||||
"""Readline: Yank the top of the kill ring into the buffer at point."""
|
||||
if self.widget is None or self.widget not in self.deleted:
|
||||
return
|
||||
self.widget.insert(self.deleted[self.widget])
|
||||
|
||||
@cmd.register(instance='rl_bridge', hide=True, modes=['command', 'prompt'])
|
||||
@cmd.register(instance='rl_bridge', hide=True,
|
||||
modes=[KeyMode.command, KeyMode.prompt])
|
||||
def rl_delete_char(self):
|
||||
"""Readline: Delete the character at point."""
|
||||
if self.widget is None:
|
||||
return
|
||||
self.widget.del_()
|
||||
|
||||
@cmd.register(instance='rl_bridge', hide=True, modes=['command', 'prompt'])
|
||||
@cmd.register(instance='rl_bridge', hide=True,
|
||||
modes=[KeyMode.command, KeyMode.prompt])
|
||||
def rl_backward_delete_char(self):
|
||||
"""Readline: Delete the character behind the cursor."""
|
||||
if self.widget is None:
|
||||
|
@ -235,10 +235,16 @@ class NeighborList(collections.abc.Sequence):
|
||||
# The mode of a Question.
|
||||
PromptMode = enum('PromptMode', 'yesno', 'text', 'user_pwd', 'alert')
|
||||
|
||||
|
||||
# Where to open a clicked link.
|
||||
ClickTarget = enum('ClickTarget', 'normal', 'tab', 'tab_bg')
|
||||
|
||||
|
||||
# Key input modes
|
||||
KeyMode = enum('KeyMode', 'normal', 'hint', 'command', 'yesno', 'prompt',
|
||||
'insert', 'passthrough')
|
||||
|
||||
|
||||
class Question(QObject):
|
||||
|
||||
"""A question asked to the user, e.g. via the status bar.
|
||||
|
@ -32,6 +32,7 @@ from qutebrowser.widgets.completiondelegate import CompletionItemDelegate
|
||||
from qutebrowser.config.style import set_register_stylesheet
|
||||
from qutebrowser.utils.completer import Completer
|
||||
from qutebrowser.utils.qt import qt_ensure_valid
|
||||
from qutebrowser.utils.usertypes import KeyMode
|
||||
|
||||
|
||||
class CompletionView(QTreeView):
|
||||
@ -211,13 +212,13 @@ class CompletionView(QTreeView):
|
||||
selmod.clearCurrentIndex()
|
||||
|
||||
@cmdutils.register(instance='mainwindow.completion', hide=True,
|
||||
modes=['command'])
|
||||
modes=[KeyMode.command])
|
||||
def completion_item_prev(self):
|
||||
"""Select the previous completion item."""
|
||||
self._next_prev_item(prev=True)
|
||||
|
||||
@cmdutils.register(instance='mainwindow.completion', hide=True,
|
||||
modes=['command'])
|
||||
modes=[KeyMode.command])
|
||||
def completion_item_next(self):
|
||||
"""Select the next completion item."""
|
||||
self._next_prev_item(prev=False)
|
||||
|
@ -36,7 +36,7 @@ from qutebrowser.widgets.statusbar.percentage import Percentage
|
||||
from qutebrowser.widgets.statusbar.url import UrlText
|
||||
from qutebrowser.widgets.statusbar.prompt import Prompt
|
||||
from qutebrowser.config.style import set_register_stylesheet, get_stylesheet
|
||||
from qutebrowser.utils.usertypes import Timer
|
||||
from qutebrowser.utils.usertypes import Timer, KeyMode
|
||||
|
||||
|
||||
class StatusBar(QWidget):
|
||||
@ -353,20 +353,20 @@ class StatusBar(QWidget):
|
||||
"""Set a normal (persistent) text in the status bar."""
|
||||
self.txt.normaltext = val
|
||||
|
||||
@pyqtSlot(str)
|
||||
@pyqtSlot(KeyMode)
|
||||
def on_mode_entered(self, mode):
|
||||
"""Mark certain modes in the commandline."""
|
||||
if mode in modeman.instance().passthrough:
|
||||
self.txt.normaltext = "-- {} MODE --".format(mode.upper())
|
||||
if mode == 'insert':
|
||||
self.txt.normaltext = "-- {} MODE --".format(mode.name.upper())
|
||||
if mode == KeyMode.insert:
|
||||
self.insert_active = True
|
||||
|
||||
@pyqtSlot(str)
|
||||
@pyqtSlot(KeyMode)
|
||||
def on_mode_left(self, mode):
|
||||
"""Clear marked mode."""
|
||||
if mode in modeman.instance().passthrough:
|
||||
self.txt.normaltext = ""
|
||||
if mode == 'insert':
|
||||
if mode == KeyMode.insert:
|
||||
self.insert_active = False
|
||||
|
||||
@pyqtSlot(str, str)
|
||||
|
@ -32,6 +32,7 @@ from qutebrowser.utils.log import completion as logger
|
||||
from qutebrowser.models.cmdhistory import (History, HistoryEmptyError,
|
||||
HistoryEndReachedError)
|
||||
from qutebrowser.commands.exceptions import CommandError
|
||||
from qutebrowser.utils.usertypes import KeyMode
|
||||
|
||||
|
||||
class Command(MinimalLineEdit):
|
||||
@ -218,7 +219,7 @@ class Command(MinimalLineEdit):
|
||||
self.show_cmd.emit()
|
||||
|
||||
@cmdutils.register(instance='mainwindow.status.cmd', hide=True,
|
||||
modes=['command'])
|
||||
modes=[KeyMode.command])
|
||||
def command_history_prev(self):
|
||||
"""Handle Up presses (go back in history)."""
|
||||
try:
|
||||
@ -232,7 +233,7 @@ class Command(MinimalLineEdit):
|
||||
self.set_cmd_text(item)
|
||||
|
||||
@cmdutils.register(instance='mainwindow.status.cmd', hide=True,
|
||||
modes=['command'])
|
||||
modes=[KeyMode.command])
|
||||
def command_history_next(self):
|
||||
"""Handle Down presses (go forward in history)."""
|
||||
if not self.history.browsing:
|
||||
@ -245,7 +246,7 @@ class Command(MinimalLineEdit):
|
||||
self.set_cmd_text(item)
|
||||
|
||||
@cmdutils.register(instance='mainwindow.status.cmd', hide=True,
|
||||
modes=['command'])
|
||||
modes=[KeyMode.command])
|
||||
def command_accept(self):
|
||||
"""Handle the command in the status bar.
|
||||
|
||||
@ -261,7 +262,7 @@ class Command(MinimalLineEdit):
|
||||
}
|
||||
text = self.text()
|
||||
self.history.append(text)
|
||||
modeman.leave('command', 'cmd accept')
|
||||
modeman.leave(KeyMode.command, 'cmd accept')
|
||||
if text[0] in signals:
|
||||
signals[text[0]].emit(text.lstrip(text[0]))
|
||||
|
||||
@ -274,6 +275,7 @@ class Command(MinimalLineEdit):
|
||||
# here, but that's already done for us by cursorPositionChanged
|
||||
# anyways, so we don't need to do it twice.
|
||||
|
||||
@pyqtSlot(KeyMode)
|
||||
def on_mode_left(self, mode):
|
||||
"""Clear up when ommand mode was left.
|
||||
|
||||
@ -288,7 +290,7 @@ class Command(MinimalLineEdit):
|
||||
clear_completion_selection: Always emitted.
|
||||
hide_completion: Always emitted so the completion is hidden.
|
||||
"""
|
||||
if mode == "command":
|
||||
if mode == KeyMode.command:
|
||||
self.setText('')
|
||||
self.history.stop()
|
||||
self.hide_cmd.emit()
|
||||
@ -297,7 +299,7 @@ class Command(MinimalLineEdit):
|
||||
|
||||
def focusInEvent(self, e):
|
||||
"""Extend focusInEvent to enter command mode."""
|
||||
modeman.enter('command', 'cmd focus')
|
||||
modeman.enter(KeyMode.command, 'cmd focus')
|
||||
super().focusInEvent(e)
|
||||
|
||||
|
||||
|
@ -26,7 +26,7 @@ from PyQt5.QtWidgets import QLineEdit
|
||||
|
||||
import qutebrowser.keyinput.modeman as modeman
|
||||
import qutebrowser.commands.utils as cmdutils
|
||||
from qutebrowser.utils.usertypes import PromptMode, Question
|
||||
from qutebrowser.utils.usertypes import PromptMode, Question, KeyMode
|
||||
from qutebrowser.utils.qt import EventLoop
|
||||
from qutebrowser.utils.log import statusbar as logger
|
||||
|
||||
@ -133,23 +133,23 @@ class Prompter:
|
||||
suffix = " (no)"
|
||||
self._prompt.txt.setText(self.question.text + suffix)
|
||||
self._prompt.lineedit.hide()
|
||||
mode = 'yesno'
|
||||
mode = KeyMode.yesno
|
||||
elif self.question.mode == PromptMode.text:
|
||||
self._prompt.txt.setText(self.question.text)
|
||||
if self.question.default:
|
||||
self._prompt.lineedit.setText(self.question.default)
|
||||
self._prompt.lineedit.show()
|
||||
mode = 'prompt'
|
||||
mode = KeyMode.prompt
|
||||
elif self.question.mode == PromptMode.user_pwd:
|
||||
self._prompt.txt.setText(self.question.text)
|
||||
if self.question.default:
|
||||
self._prompt.lineedit.setText(self.question.default)
|
||||
self._prompt.lineedit.show()
|
||||
mode = 'prompt'
|
||||
mode = KeyMode.prompt
|
||||
elif self.question.mode == PromptMode.alert:
|
||||
self._prompt.txt.setText(self.question.text + ' (ok)')
|
||||
self._prompt.lineedit.hide()
|
||||
mode = 'prompt'
|
||||
mode = KeyMode.prompt
|
||||
else:
|
||||
raise ValueError("Invalid prompt mode!")
|
||||
self._prompt.lineedit.setFocus()
|
||||
@ -157,9 +157,10 @@ class Prompter:
|
||||
self._busy = True
|
||||
return mode
|
||||
|
||||
@pyqtSlot(KeyMode)
|
||||
def on_mode_left(self, mode):
|
||||
"""Clear and reset input when the mode was left."""
|
||||
if mode in ('prompt', 'yesno'):
|
||||
if mode in (KeyMode.prompt, KeyMode.yesno):
|
||||
self._prompt.txt.setText('')
|
||||
self._prompt.lineedit.clear()
|
||||
self._prompt.lineedit.setEchoMode(QLineEdit.Normal)
|
||||
@ -169,7 +170,7 @@ class Prompter:
|
||||
self.question.cancel()
|
||||
|
||||
@cmdutils.register(instance='mainwindow.status.prompt.prompter', hide=True,
|
||||
modes=['prompt'])
|
||||
modes=[KeyMode.prompt])
|
||||
def prompt_accept(self):
|
||||
"""Accept the current prompt.
|
||||
|
||||
@ -189,46 +190,46 @@ class Prompter:
|
||||
# User just entered a password
|
||||
password = self._prompt.lineedit.text()
|
||||
self.question.answer = (self.question.user, password)
|
||||
modeman.leave('prompt', 'prompt accept')
|
||||
modeman.leave(KeyMode.prompt, 'prompt accept')
|
||||
self.question.done()
|
||||
elif self.question.mode == PromptMode.text:
|
||||
# User just entered text.
|
||||
self.question.answer = self._prompt.lineedit.text()
|
||||
modeman.leave('prompt', 'prompt accept')
|
||||
modeman.leave(KeyMode.prompt, 'prompt accept')
|
||||
self.question.done()
|
||||
elif self.question.mode == PromptMode.yesno:
|
||||
# User wants to accept the default of a yes/no question.
|
||||
self.question.answer = self.question.default
|
||||
modeman.leave('yesno', 'yesno accept')
|
||||
modeman.leave(KeyMode.yesno, 'yesno accept')
|
||||
self.question.done()
|
||||
elif self.question.mode == PromptMode.alert:
|
||||
# User acknowledged an alert
|
||||
self.question.answer = None
|
||||
modeman.leave('prompt', 'alert accept')
|
||||
modeman.leave(KeyMode.prompt, 'alert accept')
|
||||
self.question.done()
|
||||
else:
|
||||
raise ValueError("Invalid question mode!")
|
||||
|
||||
@cmdutils.register(instance='mainwindow.status.prompt.prompter', hide=True,
|
||||
modes=['yesno'])
|
||||
modes=[KeyMode.yesno])
|
||||
def prompt_yes(self):
|
||||
"""Answer yes to a yes/no prompt."""
|
||||
if self.question.mode != PromptMode.yesno:
|
||||
# We just ignore this if we don't have a yes/no question.
|
||||
return
|
||||
self.question.answer = True
|
||||
modeman.leave('yesno', 'yesno accept')
|
||||
modeman.leave(KeyMode.yesno, 'yesno accept')
|
||||
self.question.done()
|
||||
|
||||
@cmdutils.register(instance='mainwindow.status.prompt.prompter', hide=True,
|
||||
modes=['yesno'])
|
||||
modes=[KeyMode.yesno])
|
||||
def prompt_no(self):
|
||||
"""Answer no to a yes/no prompt."""
|
||||
if self.question.mode != PromptMode.yesno:
|
||||
# We just ignore this if we don't have a yes/no question.
|
||||
return
|
||||
self.question.answer = False
|
||||
modeman.leave('yesno', 'prompt accept')
|
||||
modeman.leave(KeyMode.yesno, 'prompt accept')
|
||||
self.question.done()
|
||||
|
||||
@pyqtSlot(Question, bool)
|
||||
|
@ -36,6 +36,7 @@ from qutebrowser.browser.signalfilter import SignalFilter
|
||||
from qutebrowser.browser.commands import CommandDispatcher
|
||||
from qutebrowser.utils.qt import qt_ensure_valid, QtValueError
|
||||
from qutebrowser.commands.exceptions import CommandError
|
||||
from qutebrowser.utils.usertypes import KeyMode
|
||||
|
||||
|
||||
class TabbedBrowser(TabWidget):
|
||||
@ -391,8 +392,8 @@ class TabbedBrowser(TabWidget):
|
||||
@pyqtSlot()
|
||||
def on_cur_load_started(self):
|
||||
"""Leave insert/hint mode when loading started."""
|
||||
modeman.maybe_leave('insert', 'load started')
|
||||
modeman.maybe_leave('hint', 'load started')
|
||||
modeman.maybe_leave(KeyMode.insert, 'load started')
|
||||
modeman.maybe_leave(KeyMode.hint, 'load started')
|
||||
|
||||
@pyqtSlot(WebView, str)
|
||||
def on_title_changed(self, tab, text):
|
||||
@ -451,10 +452,10 @@ class TabbedBrowser(TabWidget):
|
||||
return
|
||||
self.setTabIcon(idx, tab.icon())
|
||||
|
||||
@pyqtSlot(str)
|
||||
@pyqtSlot(KeyMode)
|
||||
def on_mode_left(self, mode):
|
||||
"""Give focus to current tab if command mode was left."""
|
||||
if mode == "command":
|
||||
if mode == KeyMode.command:
|
||||
self.currentWidget().setFocus()
|
||||
|
||||
@pyqtSlot(int)
|
||||
@ -462,7 +463,7 @@ class TabbedBrowser(TabWidget):
|
||||
"""Set last_focused and leave hinting mode when focus changed."""
|
||||
tab = self.widget(idx)
|
||||
tab.setFocus()
|
||||
modeman.maybe_leave('hint', 'tab changed')
|
||||
modeman.maybe_leave(KeyMode.hint, 'tab changed')
|
||||
self.last_focused = self.now_focused
|
||||
self.now_focused = tab
|
||||
self.current_tab_changed.emit(tab)
|
||||
|
@ -35,7 +35,8 @@ from qutebrowser.utils.misc import elide
|
||||
from qutebrowser.utils.qt import qt_ensure_valid
|
||||
from qutebrowser.browser.webpage import BrowserPage
|
||||
from qutebrowser.browser.hints import HintManager
|
||||
from qutebrowser.utils.usertypes import NeighborList, ClickTarget, enum
|
||||
from qutebrowser.utils.usertypes import (NeighborList, ClickTarget, KeyMode,
|
||||
enum)
|
||||
from qutebrowser.commands.exceptions import CommandError
|
||||
|
||||
|
||||
@ -231,11 +232,11 @@ class WebView(QWebView):
|
||||
elif ((hitresult.isContentEditable() and webelem.is_writable(elem)) or
|
||||
webelem.is_editable(elem)):
|
||||
log.mouse.debug("Clicked editable element!")
|
||||
modeman.enter('insert', 'click')
|
||||
modeman.enter(KeyMode.insert, 'click')
|
||||
else:
|
||||
log.mouse.debug("Clicked non-editable element!")
|
||||
if config.get('input', 'auto-leave-insert-mode'):
|
||||
modeman.maybe_leave('insert', 'click')
|
||||
modeman.maybe_leave(KeyMode.insert, 'click')
|
||||
|
||||
def mouserelease_insertmode(self):
|
||||
"""If we have an insertmode check scheduled, handle it."""
|
||||
@ -245,11 +246,11 @@ class WebView(QWebView):
|
||||
elem = webelem.focus_elem(self.page().currentFrame())
|
||||
if webelem.is_editable(elem):
|
||||
log.mouse.debug("Clicked editable element (delayed)!")
|
||||
modeman.enter('insert', 'click-delayed')
|
||||
modeman.enter(KeyMode.insert, 'click-delayed')
|
||||
else:
|
||||
log.mouse.debug("Clicked non-editable element (delayed)!")
|
||||
if config.get('input', 'auto-leave-insert-mode'):
|
||||
modeman.maybe_leave('insert', 'click-delayed')
|
||||
modeman.maybe_leave(KeyMode.insert, 'click-delayed')
|
||||
|
||||
def _mousepress_opentarget(self, e):
|
||||
"""Set the open target when something was clicked.
|
||||
@ -410,7 +411,7 @@ class WebView(QWebView):
|
||||
self.load_status = LoadStatus.error
|
||||
if not config.get('input', 'auto-insert-mode'):
|
||||
return
|
||||
if modeman.instance().mode == 'insert' or not ok:
|
||||
if modeman.instance().mode == KeyMode.insert or not ok:
|
||||
return
|
||||
frame = self.page().currentFrame()
|
||||
elem = frame.findFirstElement(':focus')
|
||||
@ -418,7 +419,7 @@ class WebView(QWebView):
|
||||
if elem.isNull():
|
||||
log.webview.debug("Focused element is null!")
|
||||
elif webelem.is_editable(elem):
|
||||
modeman.enter('insert', 'load finished')
|
||||
modeman.enter(KeyMode.insert, 'load finished')
|
||||
|
||||
@pyqtSlot(str)
|
||||
def set_force_open_target(self, target):
|
||||
|
Loading…
Reference in New Issue
Block a user