mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add a popup options menu to the save-a-search button.
This commit is contained in:
parent
5374b839ce
commit
3941dbac13
@ -214,7 +214,6 @@ class SearchBar(QWidget): # {{{
|
|||||||
x.setIcon(QIcon(I("search_add_saved.png")))
|
x.setIcon(QIcon(I("search_add_saved.png")))
|
||||||
x.setObjectName("save_search_button")
|
x.setObjectName("save_search_button")
|
||||||
l.addWidget(x)
|
l.addWidget(x)
|
||||||
x.setToolTip(_("Save current search under the name shown in the box"))
|
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
@ -7,12 +7,15 @@ __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
|
|
||||||
from PyQt4.Qt import QComboBox, Qt, QLineEdit, QStringList, pyqtSlot, QDialog, \
|
from PyQt4.Qt import QComboBox, Qt, QLineEdit, QStringList, pyqtSlot, QDialog, \
|
||||||
pyqtSignal, QCompleter, QAction, QKeySequence, QTimer, \
|
pyqtSignal, QCompleter, QAction, QKeySequence, QTimer, \
|
||||||
QString, QIcon
|
QString, QIcon, QMenu
|
||||||
|
|
||||||
from calibre.gui2 import config
|
from calibre.gui2 import config, error_dialog
|
||||||
|
from calibre.gui2.dialogs.confirm_delete import confirm
|
||||||
from calibre.gui2.dialogs.saved_search_editor import SavedSearchEditor
|
from calibre.gui2.dialogs.saved_search_editor import SavedSearchEditor
|
||||||
from calibre.gui2.dialogs.search import SearchDialog
|
from calibre.gui2.dialogs.search import SearchDialog
|
||||||
from calibre.utils.search_query_parser import saved_searches
|
from calibre.utils.search_query_parser import saved_searches
|
||||||
@ -330,6 +333,24 @@ class SavedSearchBox(QComboBox): # {{{
|
|||||||
self.saved_search_selected (name)
|
self.saved_search_selected (name)
|
||||||
self.changed.emit()
|
self.changed.emit()
|
||||||
|
|
||||||
|
def delete_current_search(self):
|
||||||
|
idx = self.currentIndex()
|
||||||
|
if idx <= 0:
|
||||||
|
error_dialog(self, _('Delete current search'),
|
||||||
|
_('No search is selected'), show=True)
|
||||||
|
return
|
||||||
|
if not confirm('<p>'+_('The selected search will be '
|
||||||
|
'<b>permanently deleted</b>. Are you sure?')
|
||||||
|
+'</p>', 'saved_search_delete', self):
|
||||||
|
return
|
||||||
|
ss = saved_searches().lookup(unicode(self.currentText()))
|
||||||
|
if ss is None:
|
||||||
|
return
|
||||||
|
saved_searches().delete(unicode(self.currentText()))
|
||||||
|
self.clear()
|
||||||
|
self.search_box.clear()
|
||||||
|
self.changed.emit()
|
||||||
|
|
||||||
# SIGNALed from the main UI
|
# SIGNALed from the main UI
|
||||||
def copy_search_button_clicked (self):
|
def copy_search_button_clicked (self):
|
||||||
idx = self.currentIndex();
|
idx = self.currentIndex();
|
||||||
@ -428,6 +449,22 @@ class SavedSearchBoxMixin(object): # {{{
|
|||||||
for x in ('copy', 'save'):
|
for x in ('copy', 'save'):
|
||||||
b = getattr(self, x+'_search_button')
|
b = getattr(self, x+'_search_button')
|
||||||
b.setStatusTip(b.toolTip())
|
b.setStatusTip(b.toolTip())
|
||||||
|
self.save_search_button.setToolTip('<p>' +
|
||||||
|
_("Save current search under the name shown in the box. "
|
||||||
|
"Press and hold for a pop-up options menu.") + '</p>')
|
||||||
|
self.save_search_button.setMenu(QMenu())
|
||||||
|
self.save_search_button.menu().addAction(
|
||||||
|
QIcon(I('plus.png')),
|
||||||
|
_('Create saved search'),
|
||||||
|
self.saved_search.save_search_button_clicked)
|
||||||
|
self.save_search_button.menu().addAction(
|
||||||
|
QIcon(I('trash.png')),
|
||||||
|
_('Delete saved search'),
|
||||||
|
self.saved_search.delete_current_search)
|
||||||
|
self.save_search_button.menu().addAction(
|
||||||
|
QIcon(I('search.png')),
|
||||||
|
_('Manage saved searches'),
|
||||||
|
partial(self.do_saved_search_edit, None))
|
||||||
|
|
||||||
def saved_searches_changed(self, set_restriction=None, recount=True):
|
def saved_searches_changed(self, set_restriction=None, recount=True):
|
||||||
p = sorted(saved_searches().names(), key=sort_key)
|
p = sorted(saved_searches().names(), key=sort_key)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user