Show tooltip instead of prompt for removing tags

This commit is contained in:
RumovZ 2021-03-11 09:14:50 +01:00
parent 8e9331e424
commit 186a0202ea
5 changed files with 17 additions and 26 deletions

View File

@ -114,6 +114,11 @@ browsing-note-deleted =
[one] { $count } note deleted. [one] { $count } note deleted.
*[other] { $count } notes 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-window-title = Browse ({ $selected } of { $total } cards selected)
browsing-sidebar-expand = Expand browsing-sidebar-expand = Expand
browsing-sidebar-collapse = Collapse browsing-sidebar-collapse = Collapse
@ -134,5 +139,3 @@ browsing-edited-today = Edited
browsing-sidebar-due-today = Due browsing-sidebar-due-today = Due
browsing-sidebar-untagged = Untagged browsing-sidebar-untagged = Untagged
browsing-sidebar-overdue = Overdue 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?

View File

@ -27,6 +27,7 @@ from aqt.utils import (
show_invalid_search_error, show_invalid_search_error,
showInfo, showInfo,
showWarning, showWarning,
tooltip,
tr, tr,
) )
@ -1146,16 +1147,14 @@ class SidebarTreeView(QTreeView):
def _remove_tags(self, _item: SidebarItem) -> None: def _remove_tags(self, _item: SidebarItem) -> None:
tags = self._selected_tags() tags = self._selected_tags()
if not self.ask_remove_tags(tags):
return
def do_remove() -> None: 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: def on_done(fut: Future) -> None:
self.mw.requireReset(reason=ResetReason.BrowserRemoveTags, context=self) self.mw.requireReset(reason=ResetReason.BrowserRemoveTags, context=self)
self.browser.model.endReset() self.browser.model.endReset()
fut.result() tooltip(tr(TR.BROWSING_NOTES_UPDATED, count=fut.result()), parent=self)
self.refresh() self.refresh()
self.mw.checkpoint(tr(TR.ACTIONS_REMOVE_TAG)) self.mw.checkpoint(tr(TR.ACTIONS_REMOVE_TAG))
@ -1331,19 +1330,3 @@ class SidebarTreeView(QTreeView):
for item in self._selected_items() for item in self._selected_items()
if item.item_type == SidebarItemType.TAG 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))

View File

@ -230,7 +230,7 @@ service BackendService {
rpc ClearUnusedTags(Empty) returns (Empty); rpc ClearUnusedTags(Empty) returns (Empty);
rpc AllTags(Empty) returns (StringList); rpc AllTags(Empty) returns (StringList);
rpc ExpungeTags(String) returns (Empty); rpc ExpungeTags(String) returns (UInt32);
rpc SetTagExpanded(SetTagExpandedIn) returns (Empty); rpc SetTagExpanded(SetTagExpandedIn) returns (Empty);
rpc ClearTag(String) returns (Empty); rpc ClearTag(String) returns (Empty);
rpc TagTree(Empty) returns (TagTreeNode); rpc TagTree(Empty) returns (TagTreeNode);

View File

@ -33,6 +33,12 @@ impl From<u32> for pb::UInt32 {
} }
} }
impl From<usize> for pb::UInt32 {
fn from(val: usize) -> Self {
pb::UInt32 { val: val as u32 }
}
}
impl From<()> for pb::Empty { impl From<()> for pb::Empty {
fn from(_val: ()) -> Self { fn from(_val: ()) -> Self {
pb::Empty {} pb::Empty {}

View File

@ -1217,10 +1217,9 @@ impl BackendService for Backend {
}) })
} }
fn expunge_tags(&self, tags: pb::String) -> BackendResult<pb::Empty> { fn expunge_tags(&self, tags: pb::String) -> BackendResult<pb::UInt32> {
self.with_col(|col| { self.with_col(|col| {
col.expunge_tags(tags.val.as_str())?; col.expunge_tags(tags.val.as_str()).map(Into::into)
Ok(().into())
}) })
} }