mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
Add context action 'Update with Current Search'
This commit is contained in:
parent
5d67265658
commit
76b4b7f6b1
2 changed files with 36 additions and 16 deletions
|
@ -98,6 +98,7 @@ browsing-target-field = Target field:
|
||||||
browsing-toggle-mark = Toggle Mark
|
browsing-toggle-mark = Toggle Mark
|
||||||
browsing-toggle-suspend = Toggle Suspend
|
browsing-toggle-suspend = Toggle Suspend
|
||||||
browsing-treat-input-as-regular-expression = Treat input as regular expression
|
browsing-treat-input-as-regular-expression = Treat input as regular expression
|
||||||
|
browsing-update-saved-search = Update with Current Search
|
||||||
browsing-whole-collection = Whole Collection
|
browsing-whole-collection = Whole Collection
|
||||||
browsing-you-must-have-at-least-one = You must have at least one column.
|
browsing-you-must-have-at-least-one = You must have at least one column.
|
||||||
browsing-group =
|
browsing-group =
|
||||||
|
|
|
@ -1080,6 +1080,11 @@ class SidebarTreeView(QTreeView):
|
||||||
menu.addAction(
|
menu.addAction(
|
||||||
tr(TR.BROWSING_SIDEBAR_SAVE_CURRENT_SEARCH), self.save_current_search
|
tr(TR.BROWSING_SIDEBAR_SAVE_CURRENT_SEARCH), self.save_current_search
|
||||||
)
|
)
|
||||||
|
elif item.item_type == SidebarItemType.SAVED_SEARCH:
|
||||||
|
menu.addAction(
|
||||||
|
tr(TR.BROWSING_UPDATE_SAVED_SEARCH),
|
||||||
|
lambda: self.update_saved_search(item),
|
||||||
|
)
|
||||||
|
|
||||||
def _maybe_add_delete_action(
|
def _maybe_add_delete_action(
|
||||||
self, menu: QMenu, item: SidebarItem, index: QModelIndex
|
self, menu: QMenu, item: SidebarItem, index: QModelIndex
|
||||||
|
@ -1218,6 +1223,30 @@ class SidebarTreeView(QTreeView):
|
||||||
def _set_saved_searches(self, searches: Dict[str, str]) -> None:
|
def _set_saved_searches(self, searches: Dict[str, str]) -> None:
|
||||||
self.col.set_config(self._saved_searches_key, searches)
|
self.col.set_config(self._saved_searches_key, searches)
|
||||||
|
|
||||||
|
def _get_current_search(self) -> Optional[str]:
|
||||||
|
try:
|
||||||
|
return self.col.build_search_string(
|
||||||
|
self.browser.form.searchEdit.lineEdit().text()
|
||||||
|
)
|
||||||
|
except InvalidInput as e:
|
||||||
|
show_invalid_search_error(e)
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _save_search(self, name: str, search: str, update: bool = False) -> None:
|
||||||
|
conf = self._get_saved_searches()
|
||||||
|
if (
|
||||||
|
not update
|
||||||
|
and name in conf
|
||||||
|
and not askUser(tr(TR.BROWSING_CONFIRM_SAVED_SEARCH_OVERWRITE, name=name))
|
||||||
|
):
|
||||||
|
return
|
||||||
|
conf[name] = search
|
||||||
|
self._set_saved_searches(conf)
|
||||||
|
self.refresh(
|
||||||
|
lambda item: item.item_type == SidebarItemType.SAVED_SEARCH
|
||||||
|
and item.name == name
|
||||||
|
)
|
||||||
|
|
||||||
def remove_saved_searches(self, _item: SidebarItem) -> None:
|
def remove_saved_searches(self, _item: SidebarItem) -> None:
|
||||||
selected = self._selected_saved_searches()
|
selected = self._selected_saved_searches()
|
||||||
conf = self._get_saved_searches()
|
conf = self._get_saved_searches()
|
||||||
|
@ -1246,27 +1275,17 @@ class SidebarTreeView(QTreeView):
|
||||||
)
|
)
|
||||||
|
|
||||||
def save_current_search(self) -> None:
|
def save_current_search(self) -> None:
|
||||||
try:
|
if (search := self._get_current_search()) is None:
|
||||||
filt = self.col.build_search_string(
|
|
||||||
self.browser.form.searchEdit.lineEdit().text()
|
|
||||||
)
|
|
||||||
except InvalidInput as e:
|
|
||||||
show_invalid_search_error(e)
|
|
||||||
return
|
return
|
||||||
name = getOnlyText(tr(TR.BROWSING_PLEASE_GIVE_YOUR_FILTER_A_NAME))
|
name = getOnlyText(tr(TR.BROWSING_PLEASE_GIVE_YOUR_FILTER_A_NAME))
|
||||||
if not name:
|
if not name:
|
||||||
return
|
return
|
||||||
conf = self._get_saved_searches()
|
self._save_search(name, search)
|
||||||
if name in conf and not askUser(
|
|
||||||
tr(TR.BROWSING_CONFIRM_SAVED_SEARCH_OVERWRITE, name=name)
|
def update_saved_search(self, item: SidebarItem) -> None:
|
||||||
):
|
if (search := self._get_current_search()) is None:
|
||||||
return
|
return
|
||||||
conf[name] = filt
|
self._save_search(item.name, search, update=True)
|
||||||
self._set_saved_searches(conf)
|
|
||||||
self.refresh(
|
|
||||||
lambda item: item.item_type == SidebarItemType.SAVED_SEARCH
|
|
||||||
and item.name == name
|
|
||||||
)
|
|
||||||
|
|
||||||
# Notetypes and templates
|
# Notetypes and templates
|
||||||
####################################
|
####################################
|
||||||
|
|
Loading…
Reference in a new issue