mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Add an action to clear search history as well as disabling the popup
This commit is contained in:
parent
a337fedffb
commit
a32a1e6f79
@ -27,15 +27,17 @@ class PushButton(QPushButton):
|
|||||||
|
|
||||||
class HistoryLineEdit(HistoryLineEdit2):
|
class HistoryLineEdit(HistoryLineEdit2):
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent, clear_msg):
|
||||||
HistoryLineEdit2.__init__(self, parent)
|
HistoryLineEdit2.__init__(self, parent)
|
||||||
self.disable_popup = tprefs['disable_completion_popup_for_search']
|
self.disable_popup = tprefs['disable_completion_popup_for_search']
|
||||||
|
self.clear_msg = clear_msg
|
||||||
|
|
||||||
def contextMenuEvent(self, event):
|
def contextMenuEvent(self, event):
|
||||||
menu = self.createStandardContextMenu()
|
menu = self.createStandardContextMenu()
|
||||||
menu.addSeparator()
|
menu.addSeparator()
|
||||||
menu.addAction((_('Show completion based on search history') if self.disable_popup else _(
|
menu.addAction(self.clear_msg, self.clear_history)
|
||||||
'Hide completion based on search history')), self.toggle_popups)
|
menu.addAction((_('Enable completion based on search history') if self.disable_popup else _(
|
||||||
|
'Disable completion based on search history')), self.toggle_popups)
|
||||||
menu.exec_(event.globalPos())
|
menu.exec_(event.globalPos())
|
||||||
|
|
||||||
def toggle_popups(self):
|
def toggle_popups(self):
|
||||||
@ -63,7 +65,7 @@ class SearchWidget(QWidget):
|
|||||||
|
|
||||||
self.fl = fl = QLabel(_('&Find:'))
|
self.fl = fl = QLabel(_('&Find:'))
|
||||||
fl.setAlignment(Qt.AlignRight | Qt.AlignCenter)
|
fl.setAlignment(Qt.AlignRight | Qt.AlignCenter)
|
||||||
self.find_text = ft = HistoryLineEdit(self)
|
self.find_text = ft = HistoryLineEdit(self, _('Clear search history'))
|
||||||
ft.initialize('tweak_book_find_edit')
|
ft.initialize('tweak_book_find_edit')
|
||||||
ft.returnPressed.connect(lambda : self.search_triggered.emit('find'))
|
ft.returnPressed.connect(lambda : self.search_triggered.emit('find'))
|
||||||
fl.setBuddy(ft)
|
fl.setBuddy(ft)
|
||||||
@ -72,7 +74,7 @@ class SearchWidget(QWidget):
|
|||||||
|
|
||||||
self.rl = rl = QLabel(_('&Replace:'))
|
self.rl = rl = QLabel(_('&Replace:'))
|
||||||
rl.setAlignment(Qt.AlignRight | Qt.AlignCenter)
|
rl.setAlignment(Qt.AlignRight | Qt.AlignCenter)
|
||||||
self.replace_text = rt = HistoryLineEdit(self)
|
self.replace_text = rt = HistoryLineEdit(self, _('Clear replace history'))
|
||||||
rt.initialize('tweak_book_replace_edit')
|
rt.initialize('tweak_book_replace_edit')
|
||||||
rl.setBuddy(rt)
|
rl.setBuddy(rt)
|
||||||
l.addWidget(rl, 1, 0)
|
l.addWidget(rl, 1, 0)
|
||||||
|
@ -34,3 +34,8 @@ class HistoryLineEdit2(LineEdit):
|
|||||||
history.set(self.store_name, self.history)
|
history.set(self.store_name, self.history)
|
||||||
self.update_items_cache(self.history)
|
self.update_items_cache(self.history)
|
||||||
|
|
||||||
|
def clear_history(self):
|
||||||
|
self.history = []
|
||||||
|
history.set(self.store_name, self.history)
|
||||||
|
self.update_items_cache(self.history)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user