From 82e056bb5db8c3ca754861621b0fa30f5aedaded Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 2 May 2022 11:58:14 +1000 Subject: [PATCH] Switch import/export legacy toggle to profile setting Shift would have been nice, but the existing shortcuts complicate things. If the user triggers an import with ctrl+shift+i, shift is unlikely to have been released by the time our code runs, meaning the user accidentally triggers the new code. We could potentially wait a while before bringing up the dialog, but then we're forced to guess at how long it will take the user to release the key. One alternative would be to use alt instead of shift, but then we need to trigger our shortcut when that key is pressed as well, and it could potentially cause a conflict with an add-on that already uses that combination. --- qt/aqt/browser/browser.py | 2 +- qt/aqt/main.py | 4 ++-- qt/aqt/profiles.py | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/qt/aqt/browser/browser.py b/qt/aqt/browser/browser.py index 598e62e7a..a38b5bb95 100644 --- a/qt/aqt/browser/browser.py +++ b/qt/aqt/browser/browser.py @@ -793,7 +793,7 @@ class Browser(QMainWindow): @no_arg_trigger @skip_if_selection_is_empty def _on_export_notes(self) -> None: - if KeyboardModifiersPressed().shift: + if self.mw.pm.new_import_export(): nids = self.selected_notes() ExportDialog(self.mw, nids=nids) else: diff --git a/qt/aqt/main.py b/qt/aqt/main.py index afe6e46cf..3d65e7b3e 100644 --- a/qt/aqt/main.py +++ b/qt/aqt/main.py @@ -1182,7 +1182,7 @@ title="{}" {}>{}""".format( def onImport(self) -> None: import aqt.importing - if KeyboardModifiersPressed().shift: + if self.pm.new_import_export(): import_file(self) else: aqt.importing.onImport(self) @@ -1190,7 +1190,7 @@ title="{}" {}>{}""".format( def onExport(self, did: DeckId | None = None) -> None: import aqt.exporting - if KeyboardModifiersPressed().shift: + if self.pm.new_import_export(): ExportDialog(self, did=did) else: aqt.exporting.ExportDialog(self, did=did) diff --git a/qt/aqt/profiles.py b/qt/aqt/profiles.py index 1d8ce51f5..6d00fb6a3 100644 --- a/qt/aqt/profiles.py +++ b/qt/aqt/profiles.py @@ -538,6 +538,12 @@ create table if not exists profiles def dark_mode_widgets(self) -> bool: return self.meta.get("dark_mode_widgets", False) + def new_import_export(self) -> bool: + return self.meta.get("new_import_export", False) + + def set_new_import_export(self, enabled: bool) -> None: + self.meta["new_import_export"] = enabled + # Profile-specific ######################################################################