diff --git a/src/calibre/gui2/tweak_book/function_replace.py b/src/calibre/gui2/tweak_book/function_replace.py index 1cc9cb6177..cde1ca0388 100644 --- a/src/calibre/gui2/tweak_book/function_replace.py +++ b/src/calibre/gui2/tweak_book/function_replace.py @@ -8,6 +8,8 @@ __copyright__ = '2014, Kovid Goyal ' import re, io +from PyQt5.Qt import pyqtSignal + from calibre.gui2.complete2 import EditWithComplete from calibre.gui2.tweak_book import dictionaries from calibre.utils.config import JSONConfig @@ -93,14 +95,26 @@ def functions(refresh=False): class FunctionBox(EditWithComplete): - def __init__(self, parent=None): + save_search = pyqtSignal() + show_saved_searches = pyqtSignal() + + def __init__(self, parent=None, show_saved_search_actions=False): EditWithComplete.__init__(self, parent) self.set_separator(None) + self.show_saved_search_actions = show_saved_search_actions self.refresh() def refresh(self): self.update_items_cache(set(functions())) + def contextMenuEvent(self, event): + menu = self.lineEdit().createStandardContextMenu() + if self.show_saved_search_actions: + menu.addSeparator() + menu.addAction(_('Save current search'), self.save_search.emit) + menu.addAction(_('Show saved searches'), self.show_saved_searches.emit) + menu.exec_(event.globalPos()) + # Builtin functions ########################################################## from calibre.ebooks.oeb.polish.utils import apply_func_to_match_groups diff --git a/src/calibre/gui2/tweak_book/search.py b/src/calibre/gui2/tweak_book/search.py index 59305baa96..0765b6e768 100644 --- a/src/calibre/gui2/tweak_book/search.py +++ b/src/calibre/gui2/tweak_book/search.py @@ -224,7 +224,9 @@ class SearchWidget(QWidget): self.rl2 = rl2 = QLabel(_('F&unction:')) rl2.setAlignment(Qt.AlignRight | Qt.AlignCenter) - self.functions = fb = FunctionBox(self) + self.functions = fb = FunctionBox(self, show_saved_search_actions=True) + fb.show_saved_searches.connect(self.show_saved_searches) + fb.save_search.connect(self.save_search) rl2.setBuddy(fb) rs1.addWidget(rl2) self.functions_container = w = QWidget(self)