Small search API change to let someone add, then set, a search restriction

This commit is contained in:
Kovid Goyal 2011-03-08 11:51:38 -07:00
commit 6386aff7c4
2 changed files with 8 additions and 8 deletions

View File

@ -436,17 +436,18 @@ class SavedSearchBoxMixin(object): # {{{
b = getattr(self, x+'_search_button') b = getattr(self, x+'_search_button')
b.setStatusTip(b.toolTip()) b.setStatusTip(b.toolTip())
def saved_searches_changed(self): def saved_searches_changed(self, set_restriction=None):
p = sorted(saved_searches().names(), key=sort_key) p = sorted(saved_searches().names(), key=sort_key)
t = unicode(self.search_restriction.currentText()) if set_restriction is None:
set_restriction = unicode(self.search_restriction.currentText())
# rebuild the restrictions combobox using current saved searches # rebuild the restrictions combobox using current saved searches
self.search_restriction.clear() self.search_restriction.clear()
self.search_restriction.addItem('') self.search_restriction.addItem('')
self.tags_view.recount() self.tags_view.recount()
for s in p: for s in p:
self.search_restriction.addItem(s) self.search_restriction.addItem(s)
if t: # redo the search restriction if there was one if set_restriction: # redo the search restriction if there was one
self.apply_named_search_restriction(t) self.apply_named_search_restriction(set_restriction)
def do_saved_search_edit(self, search): def do_saved_search_edit(self, search):
d = SavedSearchEditor(self, search) d = SavedSearchEditor(self, search)

View File

@ -6,7 +6,7 @@ __license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>' __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
import re, itertools, time, traceback import re, itertools, time, traceback, copy
from itertools import repeat, izip from itertools import repeat, izip
from datetime import timedelta from datetime import timedelta
from threading import Thread from threading import Thread
@ -788,10 +788,9 @@ class ResultCache(SearchQueryParser): # {{{
''' '''
if not hasattr(id_dict, 'items'): if not hasattr(id_dict, 'items'):
# Simple list. Make it a dict of string 'true' # Simple list. Make it a dict of string 'true'
self.marked_ids_dict = dict(izip(id_dict, repeat(u'true', self.marked_ids_dict = dict(izip(id_dict, repeat(u'true')))
len(id_dict))))
else: else:
self.marked_ids_dict = dict(**id_dict) self.marked_ids_dict = copy.copy(id_dict)
# Ensure that all the items in the dict are text # Ensure that all the items in the dict are text
for id_,val in self.marked_ids_dict.iteritems(): for id_,val in self.marked_ids_dict.iteritems():
self.marked_ids_dict[id_] = unicode(val) self.marked_ids_dict[id_] = unicode(val)