1) Add a preference to disable base chars find accented chars in search.

2) Removed matches from the candidate set in search when recursing
3) Add the ID to the string when using context-menu Copy in the tweaks preference dialog.
This commit is contained in:
Charles Haley 2012-07-06 14:52:49 +02:00
parent e534a1e527
commit 81bda46d1b
5 changed files with 39 additions and 8 deletions

View File

@ -26,6 +26,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
r('search_as_you_type', config)
r('highlight_search_matches', config)
r('limit_search_columns', prefs)
r('use_primary_find_in_search', prefs)
r('limit_search_columns_to', prefs, setting=CommaSeparatedList)
fl = db.field_metadata.get_search_terms()
self.opt_limit_search_columns_to.update_items_cache(fl)

View File

@ -29,6 +29,18 @@
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="opt_use_primary_find_in_search">
<property name="text">
<string>Base characters match accented characters</string>
</property>
<property name="toolTip">
<string>Characters typed in the search box will match their
accented versions, using language rules. For example, in
English, searching for e will match &#233; and &#232;.</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>What to search by default</string>
@ -77,7 +89,7 @@
</layout>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QPushButton" name="clear_history_button">
<property name="toolTip">
<string>Clear search histories from all over calibre. Including the book list, e-book viewer, fetch news dialog, etc.</string>
@ -87,7 +99,7 @@
</property>
</widget>
</item>
<item row="4" column="0">
<item row="5" column="0">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Grouped Search Terms</string>

View File

@ -343,7 +343,9 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.context_menu.addAction(self.copy_icon,
_('Copy to clipboard'),
partial(self.copy_item_to_clipboard,
val=tweak.name))
val=u"%s (%s: %s)"%(tweak.name,
_('ID'),
tweak.var_names[0])))
self.context_menu.popup(self.mapToGlobal(point))
return True

View File

@ -119,6 +119,8 @@ class MetadataBackup(Thread): # {{{
# }}}
pref_use_primary_find_in_search = False
### Global utility function for get_match here and in gui2/library.py
CONTAINS_MATCH = 0
EQUALS_MATCH = 1
@ -151,7 +153,10 @@ def _match(query, value, matchkind):
elif matchkind == REGEXP_MATCH:
return re.search(query, t, re.I|re.UNICODE)
elif matchkind == CONTAINS_MATCH:
if pref_use_primary_find_in_search:
return primary_find(query, t)[0] != -1
else:
return query in t
except re.error:
pass
return False
@ -613,6 +618,9 @@ class ResultCache(SearchQueryParser): # {{{
def get_matches(self, location, query, candidates=None,
allow_recursion=True):
global pref_use_primary_find_in_search
pref_use_primary_find_in_search = prefs['use_primary_find_in_search']
matches = set([])
if candidates is None:
candidates = self.universal_set()
@ -639,8 +647,10 @@ class ResultCache(SearchQueryParser): # {{{
else:
invert = False
for loc in location:
matches |= self.get_matches(loc, query,
m = self.get_matches(loc, query,
candidates=candidates, allow_recursion=False)
matches |= m
candidates -= m
if invert:
matches = self.universal_set() - matches
return matches
@ -657,8 +667,10 @@ class ResultCache(SearchQueryParser): # {{{
if terms:
for l in terms:
try:
matches |= self.get_matches(l, query,
m = self.get_matches(l, query,
candidates=candidates, allow_recursion=allow_recursion)
matches |= m
candidates -= m
except:
pass
return matches

View File

@ -422,6 +422,10 @@ def _prefs():
'title:Red. Enter a list of search/lookup names '
'separated by commas. Only takes effect if you set the option '
'to limit search columns above.'))
c.add_opt('use_primary_find_in_search', default=True,
help=_('Characters typed in the search box will match their '
'accented versions, using language rules. For example, in '
' English, searching for e will match é and è.'))
c.add_opt('migrated', default=False, help='For Internal use. Don\'t modify.')
return c