Skip to content

Commit

Permalink
Migrate export dialog to web
Browse files Browse the repository at this point in the history
  • Loading branch information
RumovZ committed May 1, 2024
1 parent 4a05fab commit 6a6ae4a
Show file tree
Hide file tree
Showing 23 changed files with 1,012 additions and 373 deletions.
31 changes: 31 additions & 0 deletions ftl/core/exporting.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,24 @@ exporting-export = Export...
exporting-export-format = <b>Export format</b>:
exporting-include = <b>Include</b>:
exporting-include-html-and-media-references = Include HTML and media references
exporting-include-html-and-media-references-help =
If enabled, markup and media information will be kept. Suitable if the file is intended to be reimported by Anki
or another app that can render HTML.
exporting-include-media = Include media
exporting-include-media-help = If enabled, referenced media files will be bundled.
exporting-include-scheduling-information = Include scheduling information
exporting-include-scheduling-information-help =
If enabled, study data like your review history and card intervals will be exported.
Unsuitable for sharing decks with others.
exporting-include-deck-configs = Include deck presets
exporting-include-deck-configs-help =
If enabled, your deck option prests will be exported. However, the default preset is *never* shared.
exporting-include-tags = Include tags
exporting-include-tags-help = If enabled, an additional column with note tags will be included.
exporting-support-older-anki-versions = Support older Anki versions (slower/larger files)
exporting-support-older-anki-versions-help =
If enabled, the resulting file may also be imported by some outdated Anki clients, but it will
be larger, and importing and exporting will take longer.
exporting-notes-in-plain-text = Notes in Plain Text
exporting-selected-notes = Selected Notes
exporting-card-exported =
Expand All @@ -40,5 +53,23 @@ exporting-processed-media-files =
*[other] Processed { $count } media files...
}
exporting-include-deck = Include deck name
exporting-include-deck-help =
If enabled, an additional column with deck names will be included. This will allow
the importer to sort cards into the intended decks.
exporting-include-notetype = Include notetype name
exporting-include-notetype-help =
If enabled, an additional column with notetype names will be included. This will allow
the importer to assign notes the intended notetypes.
exporting-include-guid = Include unique identifier
exporting-include-guid-help =
If enabled, an additional column with unique notetype identifiers will be included.
This allows to identify and update the exact orignal notes when the file is later reimported.
exporting-format = Format
exporting-content = Content
exporting-format-help =
Anki supports multiple file formats for differing use cases:
- `{ exporting-anki-collection-package }`: Contains your entire collection. Useful for back-ups or moving between devices.
- `{ exporting-anki-deck-package }`: Lets you control exactly which notes and what data to include. Ideal for sharing decks with other users.
- `{ exporting-notes-in-plain-text }`: Converts notes into the universal CSV format, readable by many third-party tools like text editors or spreadsheet apps.
- `{ exporting-cards-in-plain-text }`: Converts the rendered front and back sides of cards into CSV format.
20 changes: 20 additions & 0 deletions proto/anki/frontend.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ package anki.frontend;
import "anki/scheduler.proto";
import "anki/generic.proto";
import "anki/search.proto";
import "anki/notes.proto";
import "anki/import_export.proto";

service FrontendService {
// Returns values from the reviewer
Expand All @@ -22,6 +24,18 @@ service FrontendService {
rpc ImportDone(generic.Empty) returns (generic.Empty);

rpc SearchInBrowser(search.SearchNode) returns (generic.Empty);

// Get an export location chosen by the user
rpc GetExportFilePath(ExportFilePathRequest) returns (generic.String);

// Retrieve note ids to include in export file
rpc GetNotesToExport(generic.Empty) returns (notes.NoteIds);

// Show a tooltip in the main window
rpc ShowTooltip(generic.String) returns (generic.Empty);

rpc TemporarilyCloseAndExportCollectionPackage(
import_export.ExportCollectionPackageRequest) returns (generic.Empty);
}

service BackendFrontendService {}
Expand All @@ -35,3 +49,9 @@ message SetSchedulingStatesRequest {
string key = 1;
scheduler.SchedulingStates states = 2;
}

message ExportFilePathRequest {
string exporter = 1;
string extension = 2;
string filename = 3;
}
14 changes: 11 additions & 3 deletions pylib/anki/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
card_rendering_pb2,
collection_pb2,
config_pb2,
frontend_pb2,
generic_pb2,
image_occlusion_pb2,
import_export_pb2,
Expand Down Expand Up @@ -57,6 +58,10 @@
MediaSyncStatus = sync_pb2.MediaSyncStatusResponse
FsrsItem = scheduler_pb2.FsrsItem
FsrsReview = scheduler_pb2.FsrsReview
NoteIds = notes_pb2.NoteIds
String = generic_pb2.String
ExportFilePathRequest = frontend_pb2.ExportFilePathRequest
ExportCollectionPackageRequest = import_export_pb2.ExportCollectionPackageRequest

import os
import sys
Expand Down Expand Up @@ -352,9 +357,12 @@ def export_collection_package(
self, out_path: str, include_media: bool, legacy: bool
) -> None:
self.close_for_full_sync()
self._backend.export_collection_package(
out_path=out_path, include_media=include_media, legacy=legacy
)
try:
self._backend.export_collection_package(
out_path=out_path, include_media=include_media, legacy=legacy
)
finally:
self.reopen()

def import_anki_package(
self, request: ImportAnkiPackageRequest
Expand Down
Loading

0 comments on commit 6a6ae4a

Please sign in to comment.