From 94b261f1ef7daa32567a46ca7f8874e3ceb7f385 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Sun, 19 Sep 2021 18:33:36 +0200 Subject: [PATCH 1/3] Simplify sidebar context menu separators Qt can collapse consecutive menu separators, so no need to check if a subroutine has actually added any actions to the menu. --- qt/aqt/browser/sidebar/tree.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/qt/aqt/browser/sidebar/tree.py b/qt/aqt/browser/sidebar/tree.py index 4911e36e9..8f8e0398c 100644 --- a/qt/aqt/browser/sidebar/tree.py +++ b/qt/aqt/browser/sidebar/tree.py @@ -867,10 +867,13 @@ class SidebarTreeView(QTreeView): def show_context_menu(self, item: SidebarItem, index: QModelIndex) -> None: menu = QMenu() self._maybe_add_type_specific_actions(menu, item) + menu.addSeparator() self._maybe_add_delete_action(menu, item, index) self._maybe_add_rename_actions(menu, item, index) self._maybe_add_find_and_replace_action(menu, item, index) + menu.addSeparator() self._maybe_add_search_actions(menu) + menu.addSeparator() self._maybe_add_tree_actions(menu) gui_hooks.browser_sidebar_will_show_context_menu(self, menu, item, index) if menu.children(): @@ -932,7 +935,6 @@ class SidebarTreeView(QTreeView): ] if not nodes: return - menu.addSeparator() if len(nodes) == 1: menu.addAction(tr.actions_search(), lambda: self.update_search(*nodes)) return @@ -963,7 +965,6 @@ class SidebarTreeView(QTreeView): if not any(item.children for item in selected_items): return - menu.addSeparator() if any(not item.expanded for item in selected_items if item.children): menu.addAction(tr.browsing_sidebar_expand(), lambda: set_expanded(True)) if any(item.expanded for item in selected_items if item.children): From 75f210a66cd3342fac84965024daf832f4ed0d38 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Tue, 21 Sep 2021 11:48:43 +0200 Subject: [PATCH 2/3] Enable adding/removing tags from the sidebar ... ... to selected notes. --- ftl/core/browsing.ftl | 2 ++ qt/aqt/browser/sidebar/tree.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/ftl/core/browsing.ftl b/ftl/core/browsing.ftl index 0c6349fcd..96867379b 100644 --- a/ftl/core/browsing.ftl +++ b/ftl/core/browsing.ftl @@ -1,6 +1,8 @@ browsing-add-notes = Add Notes... browsing-add-tags = Add Tags browsing-add-tags2 = Add Tags... +browsing-add-to-selected-notes = Add to selected Notes +browsing-remove-from-selected-notes = Remove from selected Notes browsing-addon = Add-on browsing-all-card-types = All Card Types browsing-all-fields = All Fields diff --git a/qt/aqt/browser/sidebar/tree.py b/qt/aqt/browser/sidebar/tree.py index 8f8e0398c..0c68c3d98 100644 --- a/qt/aqt/browser/sidebar/tree.py +++ b/qt/aqt/browser/sidebar/tree.py @@ -897,6 +897,15 @@ class SidebarTreeView(QTreeView): tr.browsing_update_saved_search(), lambda: self.update_saved_search(item), ) + elif item.item_type == SidebarItemType.TAG: + if all(s.item_type == item.item_type for s in self._selected_items()): + menu.addAction( + tr.browsing_add_to_selected_notes(), self.add_tags_to_selected_notes + ) + menu.addAction( + tr.browsing_remove_from_selected_notes(), + self.remove_tags_from_selected_notes, + ) def _maybe_add_delete_action( self, menu: QMenu, item: SidebarItem, index: QModelIndex @@ -1090,6 +1099,14 @@ class SidebarTreeView(QTreeView): new_name=new_full_name, ).success(success).run_in_background() + def add_tags_to_selected_notes(self) -> None: + tags = " ".join(item.full_name for item in self._selected_items()) + self.browser.add_tags_to_selected_notes(tags) + + def remove_tags_from_selected_notes(self) -> None: + tags = " ".join(item.full_name for item in self._selected_items()) + self.browser.remove_tags_from_selected_notes(tags) + # Saved searches #################################### From b89913a2c0bdc7fe537098b1371c93c78447d497 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Wed, 22 Sep 2021 16:59:05 +0200 Subject: [PATCH 3/3] Apply suggestions from code review Capitalise "selected" Co-authored-by: Damien Elmes --- ftl/core/browsing.ftl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ftl/core/browsing.ftl b/ftl/core/browsing.ftl index 96867379b..f1cf22d24 100644 --- a/ftl/core/browsing.ftl +++ b/ftl/core/browsing.ftl @@ -1,8 +1,8 @@ browsing-add-notes = Add Notes... browsing-add-tags = Add Tags browsing-add-tags2 = Add Tags... -browsing-add-to-selected-notes = Add to selected Notes -browsing-remove-from-selected-notes = Remove from selected Notes +browsing-add-to-selected-notes = Add to Selected Notes +browsing-remove-from-selected-notes = Remove from Selected Notes browsing-addon = Add-on browsing-all-card-types = All Card Types browsing-all-fields = All Fields