' +_( + 'Search for items. If the text begins with equals (=) the search is ' + 'exact match, otherwise it is "contains" finding items containing ' + 'the text anywhere in the item name. Both exact and contains ' + 'searches ignore case. You can limit the search to particular ' + 'categories using syntax similar to search. For example, ' + 'tags:foo will find foo in any tag, but not in authors etc. Entering ' + '*foo will collapse all categories then showing only those categories ' + 'with items containing the text "foo"') + '
= 0: + key = self._parent.library_view.model().db.\ + field_metadata.search_term_to_field_key(txt[:colon]) + if key in self._parent.library_view.model().db.field_metadata: + txt = txt[colon+1:] + else: + key = '' + txt = txt[1:] if colon == 0 else txt + else: + key = None + + # key is None indicates that no colon was found. + # key == '' means either a leading : was found or the key is invalid + + # At this point the txt might have a leading =, in which case do an + # exact match search + + if (gprefs.get('tag_browser_always_autocollapse', False) and + key is None and not txt.startswith('*')): + txt = '*' + txt if txt.startswith('*'): self.tags_view.collapseAll() model.set_categories_filter(txt[1:]) @@ -659,18 +686,14 @@ class TagBrowserWidget(QFrame): # {{{ self.search_button.setFocus(True) self.item_search.lineEdit().blockSignals(False) - key = None - colon = txt.find(':') if len(txt) > 2 else 0 - if colon > 0: - key = self._parent.library_view.model().db.\ - field_metadata.search_term_to_field_key(txt[:colon]) - if key in self._parent.library_view.model().db.field_metadata: - txt = txt[colon+1:] - else: - key = None - + if txt.startswith('='): + equals_match = True + txt = txt[1:] + else: + equals_match = False self.current_find_position = \ - model.find_item_node(key, txt, self.current_find_position) + model.find_item_node(key, txt, self.current_find_position, + equals_match=equals_match) if self.current_find_position: self.tags_view.show_item_at_path(self.current_find_position, box=True)