Implement yank/paste
This commit is contained in:
parent
24255a3a93
commit
58103fa7e4
2
TODO
2
TODO
@ -33,6 +33,8 @@ pasting
|
||||
open with preset url (go)
|
||||
show infos in statusline, temporary/longer
|
||||
set settings/colors/bindings via commandline
|
||||
sane default config handling (default always loaded, userconfig overrides, provide unbind)
|
||||
write default config with comments
|
||||
|
||||
Minor features/bugs
|
||||
===================
|
||||
|
@ -185,6 +185,10 @@ class QuteBrowser(QApplication):
|
||||
'undo': self.mainwindow.tabs.undo_close,
|
||||
'pyeval': self.pyeval,
|
||||
'nextsearch': self.searchparser.nextsearch,
|
||||
'yank': self.mainwindow.tabs.cur_yank,
|
||||
'yanktitle': self.mainwindow.tabs.cur_yank_title,
|
||||
'paste': self.mainwindow.tabs.paste,
|
||||
'tabpaste': self.mainwindow.tabs.tabpaste,
|
||||
}
|
||||
|
||||
handler = handlers[cmd]
|
||||
|
@ -152,3 +152,39 @@ class NextSearch(Command):
|
||||
|
||||
nargs = 0
|
||||
hide = True
|
||||
|
||||
|
||||
class Yank(Command):
|
||||
"""Yank the URL of the current tab to the clipboard.
|
||||
|
||||
optional arg: If 'sel', yank to the primary selection.
|
||||
"""
|
||||
|
||||
nargs = '?'
|
||||
|
||||
|
||||
class YankTitle(Command):
|
||||
"""Yank the title of the current tab to the clipboard.
|
||||
|
||||
optional arg: If 'sel', yank to the primary selection.
|
||||
"""
|
||||
|
||||
nargs = '?'
|
||||
|
||||
|
||||
class Paste(Command):
|
||||
"""Open an URL from the clipboard.
|
||||
|
||||
optional arg: If 'sel', paste from the primary selection.
|
||||
"""
|
||||
|
||||
nargs = '?'
|
||||
|
||||
|
||||
class TabPaste(Command):
|
||||
"""Open an URL from the clipboard in a new tab.
|
||||
|
||||
optional arg: If 'sel', paste from the primary selection.
|
||||
"""
|
||||
|
||||
nargs = '?'
|
||||
|
@ -1,5 +1,7 @@
|
||||
"""Utility functions"""
|
||||
|
||||
import re
|
||||
|
||||
from PyQt5.QtCore import QUrl
|
||||
|
||||
|
||||
@ -7,6 +9,6 @@ def qurl(url):
|
||||
"""Get a QUrl from an url string."""
|
||||
if isinstance(url, QUrl):
|
||||
return url
|
||||
if not url.startswith('http://'):
|
||||
if not re.match(r'^\w+://', url):
|
||||
url = 'http://' + url
|
||||
return QUrl(url)
|
||||
|
@ -37,6 +37,14 @@ default_config = {
|
||||
'gg': 'scroll_perc_y 0',
|
||||
'G': 'scroll_perc_y',
|
||||
'n': 'nextsearch',
|
||||
'yy': 'yank',
|
||||
'yY': 'yank sel',
|
||||
'yt': 'yanktitle',
|
||||
'yT': 'yanktitle sel',
|
||||
'pp': 'paste',
|
||||
'pP': 'paste sel',
|
||||
'Pp': 'tabpaste',
|
||||
'PP': 'tabpaste sel',
|
||||
},
|
||||
'colors': {
|
||||
'completion.fg': '#333333',
|
||||
|
@ -7,8 +7,9 @@ containing BrowserTabs).
|
||||
|
||||
import logging
|
||||
|
||||
from PyQt5.QtWidgets import QShortcut
|
||||
from PyQt5.QtWidgets import QShortcut, QApplication
|
||||
from PyQt5.QtCore import QUrl, pyqtSignal, Qt, QEvent
|
||||
from PyQt5.QtGui import QClipboard
|
||||
from PyQt5.QtPrintSupport import QPrintPreviewDialog
|
||||
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
|
||||
|
||||
@ -229,6 +230,52 @@ class TabbedBrowser(TabWidget):
|
||||
amount = 200
|
||||
self.cur_scroll(0, amount)
|
||||
|
||||
def cur_yank(self, sel=False):
|
||||
"""Yank the current url to the clipboard or primary selection.
|
||||
|
||||
Command handler for :yank.
|
||||
"""
|
||||
clip = QApplication.clipboard()
|
||||
url = self.currentWidget().url().toString()
|
||||
mode = QClipboard.Selection if sel else QClipboard.Clipboard
|
||||
clip.setText(url, mode)
|
||||
# FIXME provide visual feedback
|
||||
|
||||
def cur_yank_title(self, sel=False):
|
||||
"""Yank the current title to the clipboard or primary selection.
|
||||
|
||||
Command handler for :yanktitle.
|
||||
"""
|
||||
clip = QApplication.clipboard()
|
||||
title = self.tabText(self.currentIndex())
|
||||
mode = QClipboard.Selection if sel else QClipboard.Clipboard
|
||||
clip.setText(title, mode)
|
||||
# FIXME provide visual feedbac
|
||||
|
||||
def paste(self, sel=False):
|
||||
"""Open a page from the clipboard.
|
||||
|
||||
Command handler for :paste.
|
||||
"""
|
||||
# FIXME what happens for invalid URLs?
|
||||
clip = QApplication.clipboard()
|
||||
mode = QClipboard.Selection if sel else QClipboard.Clipboard
|
||||
url = clip.text(mode)
|
||||
logging.debug("Clipboard contained: '{}'".format(url))
|
||||
self.openurl(url)
|
||||
|
||||
def tabpaste(self, sel=False):
|
||||
"""Open a page from the clipboard in a new tab.
|
||||
|
||||
Command handler for :paste.
|
||||
"""
|
||||
# FIXME what happens for invalid URLs?
|
||||
clip = QApplication.clipboard()
|
||||
mode = QClipboard.Selection if sel else QClipboard.Clipboard
|
||||
url = clip.text(mode)
|
||||
logging.debug("Clipboard contained: '{}'".format(url))
|
||||
self.tabopen(url)
|
||||
|
||||
def keyPressEvent(self, e):
|
||||
"""Extend TabWidget (QWidget)'s keyPressEvent to emit a signal."""
|
||||
self.keypress.emit(e)
|
||||
|
Loading…
Reference in New Issue
Block a user