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.
This commit is contained in:
Damien Elmes 2022-05-02 11:58:14 +10:00
parent 8c5311e8ae
commit 82e056bb5d
3 changed files with 9 additions and 3 deletions

View file

@ -793,7 +793,7 @@ class Browser(QMainWindow):
@no_arg_trigger @no_arg_trigger
@skip_if_selection_is_empty @skip_if_selection_is_empty
def _on_export_notes(self) -> None: def _on_export_notes(self) -> None:
if KeyboardModifiersPressed().shift: if self.mw.pm.new_import_export():
nids = self.selected_notes() nids = self.selected_notes()
ExportDialog(self.mw, nids=nids) ExportDialog(self.mw, nids=nids)
else: else:

View file

@ -1182,7 +1182,7 @@ title="{}" {}>{}</button>""".format(
def onImport(self) -> None: def onImport(self) -> None:
import aqt.importing import aqt.importing
if KeyboardModifiersPressed().shift: if self.pm.new_import_export():
import_file(self) import_file(self)
else: else:
aqt.importing.onImport(self) aqt.importing.onImport(self)
@ -1190,7 +1190,7 @@ title="{}" {}>{}</button>""".format(
def onExport(self, did: DeckId | None = None) -> None: def onExport(self, did: DeckId | None = None) -> None:
import aqt.exporting import aqt.exporting
if KeyboardModifiersPressed().shift: if self.pm.new_import_export():
ExportDialog(self, did=did) ExportDialog(self, did=did)
else: else:
aqt.exporting.ExportDialog(self, did=did) aqt.exporting.ExportDialog(self, did=did)

View file

@ -538,6 +538,12 @@ create table if not exists profiles
def dark_mode_widgets(self) -> bool: def dark_mode_widgets(self) -> bool:
return self.meta.get("dark_mode_widgets", False) 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 # Profile-specific
###################################################################### ######################################################################