From 4ab9e6caefeb033ef128ca32a5634251331c94d4 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Thu, 4 Mar 2021 17:22:03 +0100 Subject: [PATCH] Ask for confirmation when overwriting saved search --- ftl/core/browsing.ftl | 1 + qt/aqt/sidebar.py | 30 +++++++++++++++++++----------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/ftl/core/browsing.ftl b/ftl/core/browsing.ftl index 7302321f5..c5a13ad0e 100644 --- a/ftl/core/browsing.ftl +++ b/ftl/core/browsing.ftl @@ -21,6 +21,7 @@ browsing-change-note-type2 = Change Note Type... browsing-change-to = Change { $val } to: browsing-clear-unused = Clear Unused browsing-clear-unused-tags = Clear Unused Tags +browsing-confirm-saved-search-overwrite = A saved search with the name { $name } already exists. Do you want to overwrite it? browsing-confirm-saved-searches-deletion = { $count -> [one] Are you sure you want to delete the selected saved search? diff --git a/qt/aqt/sidebar.py b/qt/aqt/sidebar.py index 69a213312..471ff2664 100644 --- a/qt/aqt/sidebar.py +++ b/qt/aqt/sidebar.py @@ -1279,6 +1279,10 @@ class SidebarTreeView(QTreeView): filt = conf[old_name] except KeyError: return + if new_name in conf and not askUser( + tr(TR.BROWSING_CONFIRM_SAVED_SEARCH_OVERWRITE, name=new_name) + ): + return conf[new_name] = filt del conf[old_name] self._set_saved_searches(conf) @@ -1294,17 +1298,21 @@ class SidebarTreeView(QTreeView): ) except InvalidInput as e: show_invalid_search_error(e) - else: - name = getOnlyText(tr(TR.BROWSING_PLEASE_GIVE_YOUR_FILTER_A_NAME)) - if not name: - return - conf = self._get_saved_searches() - conf[name] = filt - self._set_saved_searches(conf) - self.refresh( - lambda item: item.item_type == SidebarItemType.SAVED_SEARCH - and item.name == name - ) + return + name = getOnlyText(tr(TR.BROWSING_PLEASE_GIVE_YOUR_FILTER_A_NAME)) + if not name: + return + conf = self._get_saved_searches() + if name in conf and not askUser( + tr(TR.BROWSING_CONFIRM_SAVED_SEARCH_OVERWRITE, name=name) + ): + return + conf[name] = filt + self._set_saved_searches(conf) + self.refresh( + lambda item: item.item_type == SidebarItemType.SAVED_SEARCH + and item.name == name + ) def manage_notetype(self, item: SidebarItem) -> None: Models(