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. :-(
This commit is contained in:
Damien Elmes 2021-02-09 10:50:39 +10:00
parent 09dfbfe2b9
commit 68c4b10dcd
2 changed files with 25 additions and 25 deletions

View File

@ -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
######################################################################

View File

@ -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
###########################