mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add an action to the context menu for the search bar to paste and instantly execute the search. Fixes #1541286 [[Enhancement] Search Bar - PASTE & GO](https://bugs.launchpad.net/calibre/+bug/1541286)
This commit is contained in:
parent
f8c2b77812
commit
8c7d5e99a4
@ -10,9 +10,10 @@ import re, time
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
|
|
||||||
from PyQt5.Qt import QComboBox, Qt, QLineEdit, pyqtSlot, QDialog, \
|
from PyQt5.Qt import (
|
||||||
pyqtSignal, QCompleter, QAction, QKeySequence, QTimer, \
|
QComboBox, Qt, QLineEdit, pyqtSlot, QDialog,
|
||||||
QIcon, QMenu
|
pyqtSignal, QCompleter, QAction, QKeySequence, QTimer,
|
||||||
|
QIcon, QMenu, QApplication, QKeyEvent)
|
||||||
|
|
||||||
from calibre.gui2 import config, error_dialog, question_dialog, gprefs
|
from calibre.gui2 import config, error_dialog, question_dialog, gprefs
|
||||||
from calibre.gui2.dialogs.confirm_delete import confirm
|
from calibre.gui2.dialogs.confirm_delete import confirm
|
||||||
@ -40,7 +41,22 @@ class SearchLineEdit(QLineEdit): # {{{
|
|||||||
|
|
||||||
def contextMenuEvent(self, ev):
|
def contextMenuEvent(self, ev):
|
||||||
self.parent().normalize_state()
|
self.parent().normalize_state()
|
||||||
return QLineEdit.contextMenuEvent(self, ev)
|
menu = self.createStandardContextMenu()
|
||||||
|
menu.setAttribute(Qt.WA_DeleteOnClose)
|
||||||
|
for action in menu.actions():
|
||||||
|
if action.text().startswith(_('&Paste') + '\t'):
|
||||||
|
break
|
||||||
|
ac = menu.addAction(_('Paste and &search'))
|
||||||
|
ac.setEnabled(bool(QApplication.clipboard().text()))
|
||||||
|
ac.setIcon(QIcon(I('search.png')))
|
||||||
|
ac.triggered.connect(self.paste_and_search)
|
||||||
|
menu.insertAction(action, ac)
|
||||||
|
menu.exec_(ev.globalPos())
|
||||||
|
|
||||||
|
def paste_and_search(self):
|
||||||
|
self.paste()
|
||||||
|
ev = QKeyEvent(QKeyEvent.KeyPress, Qt.Key_Enter, Qt.NoModifier)
|
||||||
|
self.keyPressEvent(ev)
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def paste(self, *args):
|
def paste(self, *args):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user