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('search_as_you_type', config)
r('highlight_search_matches', config) r('highlight_search_matches', config)
r('limit_search_columns', prefs) r('limit_search_columns', prefs)
r('use_primary_find_in_search', prefs)
r('limit_search_columns_to', prefs, setting=CommaSeparatedList) r('limit_search_columns_to', prefs, setting=CommaSeparatedList)
fl = db.field_metadata.get_search_terms() fl = db.field_metadata.get_search_terms()
self.opt_limit_search_columns_to.update_items_cache(fl) self.opt_limit_search_columns_to.update_items_cache(fl)

View File

@ -29,6 +29,18 @@
</widget> </widget>
</item> </item>
<item row="2" column="0"> <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"> <widget class="QGroupBox" name="groupBox">
<property name="title"> <property name="title">
<string>What to search by default</string> <string>What to search by default</string>
@ -77,7 +89,7 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item row="4" column="0">
<widget class="QPushButton" name="clear_history_button"> <widget class="QPushButton" name="clear_history_button">
<property name="toolTip"> <property name="toolTip">
<string>Clear search histories from all over calibre. Including the book list, e-book viewer, fetch news dialog, etc.</string> <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> </property>
</widget> </widget>
</item> </item>
<item row="4" column="0"> <item row="5" column="0">
<widget class="QGroupBox" name="groupBox_2"> <widget class="QGroupBox" name="groupBox_2">
<property name="title"> <property name="title">
<string>Grouped Search Terms</string> <string>Grouped Search Terms</string>

View File

@ -341,9 +341,11 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
tweak = self.tweaks.data(idx, Qt.UserRole) tweak = self.tweaks.data(idx, Qt.UserRole)
self.context_menu = QMenu(self) self.context_menu = QMenu(self)
self.context_menu.addAction(self.copy_icon, self.context_menu.addAction(self.copy_icon,
_('Copy to clipboard'), _('Copy to clipboard'),
partial(self.copy_item_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)) self.context_menu.popup(self.mapToGlobal(point))
return True 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 ### Global utility function for get_match here and in gui2/library.py
CONTAINS_MATCH = 0 CONTAINS_MATCH = 0
EQUALS_MATCH = 1 EQUALS_MATCH = 1
@ -151,7 +153,10 @@ def _match(query, value, matchkind):
elif matchkind == REGEXP_MATCH: elif matchkind == REGEXP_MATCH:
return re.search(query, t, re.I|re.UNICODE) return re.search(query, t, re.I|re.UNICODE)
elif matchkind == CONTAINS_MATCH: elif matchkind == CONTAINS_MATCH:
return primary_find(query, t)[0] != -1 if pref_use_primary_find_in_search:
return primary_find(query, t)[0] != -1
else:
return query in t
except re.error: except re.error:
pass pass
return False return False
@ -613,6 +618,9 @@ class ResultCache(SearchQueryParser): # {{{
def get_matches(self, location, query, candidates=None, def get_matches(self, location, query, candidates=None,
allow_recursion=True): allow_recursion=True):
global pref_use_primary_find_in_search
pref_use_primary_find_in_search = prefs['use_primary_find_in_search']
matches = set([]) matches = set([])
if candidates is None: if candidates is None:
candidates = self.universal_set() candidates = self.universal_set()
@ -639,8 +647,10 @@ class ResultCache(SearchQueryParser): # {{{
else: else:
invert = False invert = False
for loc in location: for loc in location:
matches |= self.get_matches(loc, query, m = self.get_matches(loc, query,
candidates=candidates, allow_recursion=False) candidates=candidates, allow_recursion=False)
matches |= m
candidates -= m
if invert: if invert:
matches = self.universal_set() - matches matches = self.universal_set() - matches
return matches return matches
@ -657,8 +667,10 @@ class ResultCache(SearchQueryParser): # {{{
if terms: if terms:
for l in terms: for l in terms:
try: try:
matches |= self.get_matches(l, query, m = self.get_matches(l, query,
candidates=candidates, allow_recursion=allow_recursion) candidates=candidates, allow_recursion=allow_recursion)
matches |= m
candidates -= m
except: except:
pass pass
return matches return matches

View File

@ -422,6 +422,10 @@ def _prefs():
'title:Red. Enter a list of search/lookup names ' 'title:Red. Enter a list of search/lookup names '
'separated by commas. Only takes effect if you set the option ' 'separated by commas. Only takes effect if you set the option '
'to limit search columns above.')) '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.') c.add_opt('migrated', default=False, help='For Internal use. Don\'t modify.')
return c return c