diff --git a/qt/aqt/import_export/exporting.py b/qt/aqt/import_export/exporting.py index 8b26ee599..f770552e5 100644 --- a/qt/aqt/import_export/exporting.py +++ b/qt/aqt/import_export/exporting.py @@ -220,8 +220,11 @@ class ColpkgExporter(Exporter): @staticmethod def export(mw: aqt.main.AnkiQt, options: Options) -> None: + gui_hooks.exporter_will_export(ExportFormat.COLPKG, options) + def on_success(_: None) -> None: mw.reopen() + gui_hooks.exporter_did_export(ExportFormat.COLPKG, options) tooltip(tr.exporting_collection_exported(), parent=mw) def on_failure(exception: Exception) -> None: @@ -255,6 +258,12 @@ class ApkgExporter(Exporter): @staticmethod def export(mw: aqt.main.AnkiQt, options: Options) -> None: + gui_hooks.exporter_will_export(ExportFormat.APKG, options) + + def on_success(count: int) -> None: + gui_hooks.exporter_did_export(ExportFormat.APKG, options) + tooltip(tr.exporting_note_exported(count=count), parent=mw) + QueryOp( parent=mw, op=lambda col: col.export_anki_package( @@ -264,9 +273,7 @@ class ApkgExporter(Exporter): with_media=options.include_media, legacy_support=options.legacy_support, ), - success=lambda count: tooltip( - tr.exporting_note_exported(count=count), parent=mw - ), + success=on_success, ).with_backend_progress(export_progress_update).run_in_background() @@ -285,6 +292,12 @@ class NoteCsvExporter(Exporter): @staticmethod def export(mw: aqt.main.AnkiQt, options: Options) -> None: + gui_hooks.exporter_will_export(ExportFormat.CSV_NOTES, options) + + def on_success(count: int) -> None: + gui_hooks.exporter_did_export(ExportFormat.CSV_NOTES, options) + tooltip(tr.exporting_note_exported(count=count), parent=mw) + QueryOp( parent=mw, op=lambda col: col.export_note_csv( @@ -296,9 +309,7 @@ class NoteCsvExporter(Exporter): with_notetype=options.include_notetype, with_guid=options.include_guid, ), - success=lambda count: tooltip( - tr.exporting_note_exported(count=count), parent=mw - ), + success=on_success, ).with_backend_progress(export_progress_update).run_in_background() @@ -313,6 +324,12 @@ class CardCsvExporter(Exporter): @staticmethod def export(mw: aqt.main.AnkiQt, options: Options) -> None: + gui_hooks.exporter_will_export(ExportFormat.CSV_CARDS, options) + + def on_success(count: int) -> None: + gui_hooks.exporter_did_export(ExportFormat.CSV_CARDS, options) + tooltip(tr.exporting_card_exported(count=count), parent=mw) + QueryOp( parent=mw, op=lambda col: col.export_card_csv( @@ -320,9 +337,7 @@ class CardCsvExporter(Exporter): limit=options.limit, with_html=options.include_html, ), - success=lambda count: tooltip( - tr.exporting_card_exported(count=count), parent=mw - ), + success=on_success, ).with_backend_progress(export_progress_update).run_in_background() diff --git a/qt/tools/genhooks_gui.py b/qt/tools/genhooks_gui.py index 6efe0125f..11994e182 100644 --- a/qt/tools/genhooks_gui.py +++ b/qt/tools/genhooks_gui.py @@ -816,6 +816,22 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest) `output` provides access to the unused/missing file lists and the text output that will be shown in the Check Media screen.""", ), + Hook( + name="exporter_will_export", + args=[ + "export_format: aqt.import_export.exporting.ExportFormat", + "options: aqt.import_export.exporting.Options", + ], + doc="""Called before collection and deck exports.""", + ), + Hook( + name="exporter_did_export", + args=[ + "export_format: aqt.import_export.exporting.ExportFormat", + "options: aqt.import_export.exporting.Options", + ], + doc="""Called after collection and deck exports.""", + ), # Dialog Manager ################### Hook(