diff --git a/TODO b/TODO index 53e665c5f..97aee9119 100644 --- a/TODO +++ b/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 =================== diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 16bd0bda7..6809da11a 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -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] diff --git a/qutebrowser/commands/__init__.py b/qutebrowser/commands/__init__.py index 730a75f6d..cbece168f 100644 --- a/qutebrowser/commands/__init__.py +++ b/qutebrowser/commands/__init__.py @@ -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 = '?' diff --git a/qutebrowser/utils/__init__.py b/qutebrowser/utils/__init__.py index eff65a055..ad90b39d6 100644 --- a/qutebrowser/utils/__init__.py +++ b/qutebrowser/utils/__init__.py @@ -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) diff --git a/qutebrowser/utils/config.py b/qutebrowser/utils/config.py index 7afbc4b73..0d12efb88 100644 --- a/qutebrowser/utils/config.py +++ b/qutebrowser/utils/config.py @@ -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', diff --git a/qutebrowser/widgets/browser.py b/qutebrowser/widgets/browser.py index 52d1710c1..33aec462d 100644 --- a/qutebrowser/widgets/browser.py +++ b/qutebrowser/widgets/browser.py @@ -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)