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