From 186a0202ea68332c022b96fdc01b7ff014190870 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Thu, 11 Mar 2021 09:14:50 +0100 Subject: [PATCH] Show tooltip instead of prompt for removing tags --- ftl/core/browsing.ftl | 7 +++++-- qt/aqt/sidebar.py | 23 +++-------------------- rslib/backend.proto | 2 +- rslib/src/backend/generic.rs | 6 ++++++ rslib/src/backend/mod.rs | 5 ++--- 5 files changed, 17 insertions(+), 26 deletions(-) diff --git a/ftl/core/browsing.ftl b/ftl/core/browsing.ftl index 222843473..f20030b11 100644 --- a/ftl/core/browsing.ftl +++ b/ftl/core/browsing.ftl @@ -114,6 +114,11 @@ browsing-note-deleted = [one] { $count } note deleted. *[other] { $count } notes deleted. } +browsing-notes-updated = + { $count -> + [one] { $count } note updated. + *[other] { $count } notes updated. + } browsing-window-title = Browse ({ $selected } of { $total } cards selected) browsing-sidebar-expand = Expand browsing-sidebar-collapse = Collapse @@ -134,5 +139,3 @@ browsing-edited-today = Edited browsing-sidebar-due-today = Due browsing-sidebar-untagged = Untagged browsing-sidebar-overdue = Overdue -browsing-sidebar-remove-tag = Are you sure you want to delete the tag “{ $name }” from { $count } notes? -browsing-sidebar-remove-tags = Are you sure you want to delete all selected tags from { $count } notes? diff --git a/qt/aqt/sidebar.py b/qt/aqt/sidebar.py index 46f561798..e590a1eea 100644 --- a/qt/aqt/sidebar.py +++ b/qt/aqt/sidebar.py @@ -27,6 +27,7 @@ from aqt.utils import ( show_invalid_search_error, showInfo, showWarning, + tooltip, tr, ) @@ -1146,16 +1147,14 @@ class SidebarTreeView(QTreeView): def _remove_tags(self, _item: SidebarItem) -> None: tags = self._selected_tags() - if not self.ask_remove_tags(tags): - return def do_remove() -> None: - self.col._backend.expunge_tags(" ".join(tags)) + return self.col._backend.expunge_tags(" ".join(tags)) def on_done(fut: Future) -> None: self.mw.requireReset(reason=ResetReason.BrowserRemoveTags, context=self) self.browser.model.endReset() - fut.result() + tooltip(tr(TR.BROWSING_NOTES_UPDATED, count=fut.result()), parent=self) self.refresh() self.mw.checkpoint(tr(TR.ACTIONS_REMOVE_TAG)) @@ -1331,19 +1330,3 @@ class SidebarTreeView(QTreeView): for item in self._selected_items() if item.item_type == SidebarItemType.TAG ] - - def ask_remove_tags(self, tags: List[str]) -> bool: - count = len( - self.col.find_notes( - self.col.build_search_string( - *(SearchNode(tag=tag) for tag in tags), joiner="OR" - ) - ) - ) - if not count: - return True - if len(tags) == 1: - return askUser( - tr(TR.BROWSING_SIDEBAR_REMOVE_TAG, name=tags[0], count=count) - ) - return askUser(tr(TR.BROWSING_SIDEBAR_REMOVE_TAGS, count=count)) diff --git a/rslib/backend.proto b/rslib/backend.proto index 751c14116..db6ab7d8c 100644 --- a/rslib/backend.proto +++ b/rslib/backend.proto @@ -230,7 +230,7 @@ service BackendService { rpc ClearUnusedTags(Empty) returns (Empty); rpc AllTags(Empty) returns (StringList); - rpc ExpungeTags(String) returns (Empty); + rpc ExpungeTags(String) returns (UInt32); rpc SetTagExpanded(SetTagExpandedIn) returns (Empty); rpc ClearTag(String) returns (Empty); rpc TagTree(Empty) returns (TagTreeNode); diff --git a/rslib/src/backend/generic.rs b/rslib/src/backend/generic.rs index e554761f4..68664954f 100644 --- a/rslib/src/backend/generic.rs +++ b/rslib/src/backend/generic.rs @@ -33,6 +33,12 @@ impl From for pb::UInt32 { } } +impl From for pb::UInt32 { + fn from(val: usize) -> Self { + pb::UInt32 { val: val as u32 } + } +} + impl From<()> for pb::Empty { fn from(_val: ()) -> Self { pb::Empty {} diff --git a/rslib/src/backend/mod.rs b/rslib/src/backend/mod.rs index fa399529a..b42f9b179 100644 --- a/rslib/src/backend/mod.rs +++ b/rslib/src/backend/mod.rs @@ -1217,10 +1217,9 @@ impl BackendService for Backend { }) } - fn expunge_tags(&self, tags: pb::String) -> BackendResult { + fn expunge_tags(&self, tags: pb::String) -> BackendResult { self.with_col(|col| { - col.expunge_tags(tags.val.as_str())?; - Ok(().into()) + col.expunge_tags(tags.val.as_str()).map(Into::into) }) }