Add different hinting modes (yank, backtab, rapid)

This commit is contained in:
Florian Bruhin 2014-04-21 23:33:36 +02:00
parent 05e3fb8650
commit ba7f56f5e9
4 changed files with 33 additions and 37 deletions

18
TODO
View File

@ -185,27 +185,9 @@ Lock tab [n]. Locking a tab will lock this tab to the current uri, its not po
wf wf
Show hints, open link in a new tab. (command hints_win, aliases: winhints, whi). Show hints, open link in a new tab. (command hints_win, aliases: winhints, whi).
;o
Set hints url in commandline (command hints_url, aliases: uhints, uhi).
;O
Set hints url in commandline, open in a new tab (command hints_url_tab, aliases: utabhints, uthi).
.o
Set hints url in commandline, open in a background tab (command hints_url_background, aliases: ubackhints).
;d ;d
Download via hints (command hints_download, aliases: dhints). Download via hints (command hints_download, aliases: dhints).
;y
Save link location to clipboard (command hints_clipboard, aliases: chints, chi).
;Y
Save link location to primary selection (command hints_primary, aliases: phints, phi).
;r
Rapid hint mode, each matching hint opens a new tab in background. (command hints_rapid, aliases: rhints, rhi).
;R ;R
Rapid hint mode, each matching hint opens a new window. (command hints_rapid_win, aliases: wrhints, wrhi). Rapid hint mode, each matching hint opens a new window. (command hints_rapid_win, aliases: wrhints, wrhi).

View File

@ -22,7 +22,8 @@ import math
from collections import namedtuple from collections import namedtuple
from PyQt5.QtCore import pyqtSignal, QObject, QEvent, Qt from PyQt5.QtCore import pyqtSignal, QObject, QEvent, Qt
from PyQt5.QtGui import QMouseEvent from PyQt5.QtGui import QMouseEvent, QClipboard
from PyQt5.QtWidgets import QApplication
import qutebrowser.config.config as config import qutebrowser.config.config as config
import qutebrowser.utils.message as message import qutebrowser.utils.message as message
@ -90,6 +91,10 @@ class HintManager(QObject):
_frame: The QWebFrame to use. _frame: The QWebFrame to use.
_elems: A mapping from keystrings to (elem, label) namedtuples. _elems: A mapping from keystrings to (elem, label) namedtuples.
_target: What to do with the opened links. _target: What to do with the opened links.
"normal"/"tab"/"bgtab": Get passed to BrowserTab.
"yank"/"yank_primary": Yank to clipboard/primary selection
"cmd"/"cmd_tab"/"cmd_bgtab": Enter link to commandline
"rapid": Rapid mode with background tabs
Signals: Signals:
hint_strings_updated: Emitted when the possible hint strings changed. hint_strings_updated: Emitted when the possible hint strings changed.
@ -102,6 +107,7 @@ class HintManager(QObject):
arg 0: URL to open as a string. arg 0: URL to open as a string.
arg 1: true if it should be opened in a new tab, else false. arg 1: true if it should be opened in a new tab, else false.
set_open_target: Set a new target to open the links in. set_open_target: Set a new target to open the links in.
set_cmd_text: Emitted when the commandline text should be set.
""" """
SELECTORS = { SELECTORS = {
@ -133,6 +139,7 @@ class HintManager(QObject):
set_mode = pyqtSignal(str) set_mode = pyqtSignal(str)
mouse_event = pyqtSignal('QMouseEvent') mouse_event = pyqtSignal('QMouseEvent')
set_open_target = pyqtSignal(str) set_open_target = pyqtSignal(str)
set_cmd_text = pyqtSignal(str)
def __init__(self, frame): def __init__(self, frame):
"""Constructor. """Constructor.
@ -375,21 +382,21 @@ class HintManager(QObject):
def fire(self, keystr): def fire(self, keystr):
"""Fire a completed hint.""" """Fire a completed hint."""
elem = self._elems[keystr].elem elem = self._elems[keystr].elem
self.set_open_target.emit(self._target) target = self._target
self.stop() if target != 'rapid':
point = elem.geometry().topLeft() self.stop()
scrollpos = self._frame.scrollPosition()
logging.debug("Clicking on \"{}\" at {}/{} - {}/{}".format( if target in ['normal', 'tab', 'bgtab']:
elem.toPlainText(), point.x(), point.y(), scrollpos.x(), self._click(elem, target)
scrollpos.y())) elif target == 'rapid':
point -= scrollpos self._click(elem, 'bgtab')
events = [ elif target in ['yank', 'yank_primary']:
QMouseEvent(QEvent.MouseMove, point, Qt.NoButton, Qt.NoButton, sel = target == 'yank_primary'
Qt.NoModifier), self._yank(elem, sel)
QMouseEvent(QEvent.MouseButtonPress, point, Qt.LeftButton, elif target in ['cmd', 'cmd_tab', 'cmd_bgtab']:
Qt.NoButton, Qt.NoModifier), commands = {
QMouseEvent(QEvent.MouseButtonRelease, point, Qt.LeftButton, 'cmd': 'open',
Qt.NoButton, Qt.NoModifier), 'cmd_tab': 'tabopen',
] 'cmd_bgtab': 'backtabopen',
for evt in events: }
self.mouse_event.emit(evt) self._set_cmd_text(elem, commands[target])

View File

@ -356,6 +356,12 @@ DATA = OrderedDict([
(';I', 'hint images tab'), (';I', 'hint images tab'),
('.i', 'hint images bgtab'), ('.i', 'hint images bgtab'),
(';e', 'hint editable'), (';e', 'hint editable'),
(';o', 'hint links cmd'),
(';O', 'hint links cmd_tab'),
('.o', 'hint links cmd_bgtab'),
(';y', 'hint links yank'),
(';Y', 'hint links yank_primary'),
(';r', 'hint links rapid'),
('h', 'scroll -50 0'), ('h', 'scroll -50 0'),
('j', 'scroll 0 50'), ('j', 'scroll 0 50'),
('k', 'scroll 0 -50'), ('k', 'scroll 0 -50'),

View File

@ -247,6 +247,7 @@ class TabbedBrowser(TabWidget):
tab.titleChanged.connect(self._titleChanged_handler) tab.titleChanged.connect(self._titleChanged_handler)
tab.hintmanager.hint_strings_updated.connect(self.hint_strings_updated) tab.hintmanager.hint_strings_updated.connect(self.hint_strings_updated)
tab.hintmanager.set_mode.connect(self.set_mode) tab.hintmanager.set_mode.connect(self.set_mode)
tab.hintmanager.set_cmd_text.connect(self.set_cmd_text)
# FIXME sometimes this doesn't load # FIXME sometimes this doesn't load
tab.show() tab.show()
tab.open_tab.connect(self.tabopen) tab.open_tab.connect(self.tabopen)