mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add saved searches context menu items to the functions box
This commit is contained in:
parent
c70b89e099
commit
d8cef2d192
@ -8,6 +8,8 @@ __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
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
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user