From 68c4b10dcd6784e2336f447e2b0f547d97153681 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 9 Feb 2021 10:50:39 +1000 Subject: [PATCH] move update_search into sidebar.py; fix setFilter() No idea why neither mypy nor pylint are not noticing "set_filter_then_search" does not exist. Python tooling. :-( --- qt/aqt/browser.py | 29 +++++------------------------ qt/aqt/sidebar.py | 21 ++++++++++++++++++++- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index e01bb8686..cc0564681 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -674,6 +674,9 @@ class Browser(QMainWindow): self.form.searchEdit.lineEdit().setText(prompt) self.search() + def current_search(self) -> str: + return self.form.searchEdit.lineEdit().text() + def search(self) -> None: """Search triggered programmatically. Caller must have saved note first.""" @@ -979,32 +982,10 @@ QTableView {{ gridline-color: {grid} }} if want_visible: self.sidebar.refresh() - # Sidebar helpers - ###################################################################### - - def update_search(self, *terms: Union[str, SearchTerm]) -> None: - """Modify the current search string based on modified keys, then refresh.""" - try: - search = self.col.build_search_string(*terms) - mods = self.mw.app.keyboardModifiers() - if mods & Qt.AltModifier: - search = self.col.build_search_string(search, negate=True) - cur = str(self.form.searchEdit.lineEdit().text()) - if mods & Qt.ControlModifier and mods & Qt.ShiftModifier: - search = self.col.replace_search_term(cur, search) - elif mods & Qt.ControlModifier: - search = self.col.build_search_string(cur, search) - elif mods & Qt.ShiftModifier: - search = self.col.build_search_string(cur, search, match_any=True) - except InvalidInput as e: - show_invalid_search_error(e) - else: - self.form.searchEdit.lineEdit().setText(search) - self.onSearchActivated() - # legacy + def setFilter(self, *terms: str) -> None: - self.set_filter_then_search(*terms) + self.sidebar.update_search(*terms) # Info ###################################################################### diff --git a/qt/aqt/sidebar.py b/qt/aqt/sidebar.py index ee2a2a00e..7a0606e0a 100644 --- a/qt/aqt/sidebar.py +++ b/qt/aqt/sidebar.py @@ -364,6 +364,25 @@ class SidebarTreeView(QTreeView): if item.is_expanded(searching): self.setExpanded(idx, True) + def update_search(self, *terms: Union[str, SearchTerm]) -> None: + """Modify the current search string based on modified keys, then refresh.""" + try: + search = self.col.build_search_string(*terms) + mods = self.mw.app.keyboardModifiers() + if mods & Qt.AltModifier: + search = self.col.build_search_string(search, negate=True) + current = self.browser.current_search() + if mods & Qt.ControlModifier and mods & Qt.ShiftModifier: + search = self.col.replace_search_term(current, search) + elif mods & Qt.ControlModifier: + search = self.col.build_search_string(current, search) + elif mods & Qt.ShiftModifier: + search = self.col.build_search_string(current, search, match_any=True) + except InvalidInput as e: + show_invalid_search_error(e) + else: + self.browser.search_for(search) + # Qt API ########### @@ -544,7 +563,7 @@ class SidebarTreeView(QTreeView): return top def _filter_func(self, *terms: Union[str, SearchTerm]) -> Callable: - return lambda: self.browser.update_search(self.col.build_search_string(*terms)) + return lambda: self.update_search(self.col.build_search_string(*terms)) # Tree: Saved Searches ###########################