mirror of
https://github.com/ankitects/anki.git
synced 2025-11-06 12:47:11 -05:00
Add RPCs for Fields/Cards dialogs
This commit is contained in:
parent
bdbafb1f6e
commit
7c6fa98063
5 changed files with 43 additions and 11 deletions
|
|
@ -43,6 +43,8 @@ service FrontendService {
|
|||
rpc OpenLink(generic.String) returns (generic.Empty);
|
||||
rpc AskUser(AskUserRequest) returns (generic.Bool);
|
||||
rpc ShowMessageBox(ShowMessageBoxRequest) returns (generic.Empty);
|
||||
rpc OpenFieldsDialog(generic.Empty) returns (generic.Empty);
|
||||
rpc OpenCardsDialog(generic.Empty) returns (generic.Empty);
|
||||
|
||||
// Profile config
|
||||
rpc GetProfileConfigJson(generic.String) returns (generic.Json);
|
||||
|
|
|
|||
|
|
@ -300,9 +300,6 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
|
|||
return checkFocus
|
||||
|
||||
def onFields(self) -> None:
|
||||
self.call_after_note_saved(self._onFields)
|
||||
|
||||
def _onFields(self) -> None:
|
||||
from aqt.fields import FieldDialog
|
||||
|
||||
def on_note_info(note_info: NoteInfo) -> None:
|
||||
|
|
@ -313,9 +310,6 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
|
|||
self.get_note_info(on_note_info)
|
||||
|
||||
def onCardLayout(self) -> None:
|
||||
self.call_after_note_saved(self._onCardLayout)
|
||||
|
||||
def _onCardLayout(self) -> None:
|
||||
from aqt.clayout import CardLayout
|
||||
|
||||
if self.card:
|
||||
|
|
@ -539,8 +533,6 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
|
|||
|
||||
def _init_links(self) -> None:
|
||||
self._links: dict[str, Callable] = dict(
|
||||
fields=NewEditor.onFields,
|
||||
cards=NewEditor.onCardLayout,
|
||||
paste=NewEditor.onPaste,
|
||||
cut=NewEditor.onCut,
|
||||
copy=NewEditor.onCopy,
|
||||
|
|
|
|||
|
|
@ -882,6 +882,32 @@ async def show_message_box() -> bytes:
|
|||
return generic_pb2.Bool(val=answer).SerializeToString()
|
||||
|
||||
|
||||
def open_fields_dialog() -> bytes:
|
||||
def handle_on_main() -> None:
|
||||
from aqt.editor import NewEditor
|
||||
|
||||
window = aqt.mw.app.activeWindow()
|
||||
assert window is not None
|
||||
if hasattr(window, "editor") and isinstance(window.editor, NewEditor):
|
||||
window.editor.onFields()
|
||||
|
||||
aqt.mw.taskman.run_on_main(handle_on_main)
|
||||
return b""
|
||||
|
||||
|
||||
def open_cards_dialog() -> bytes:
|
||||
def handle_on_main() -> None:
|
||||
from aqt.editor import NewEditor
|
||||
|
||||
window = aqt.mw.app.activeWindow()
|
||||
assert window is not None
|
||||
if hasattr(window, "editor") and isinstance(window.editor, NewEditor):
|
||||
window.editor.onCardLayout()
|
||||
|
||||
aqt.mw.taskman.run_on_main(handle_on_main)
|
||||
return b""
|
||||
|
||||
|
||||
def save_custom_colours() -> bytes:
|
||||
colors = [
|
||||
QColorDialog.customColor(i).name(QColor.NameFormat.HexRgb)
|
||||
|
|
@ -919,6 +945,8 @@ post_handler_list = [
|
|||
open_link,
|
||||
ask_user,
|
||||
show_message_box,
|
||||
open_fields_dialog,
|
||||
open_cards_dialog,
|
||||
save_custom_colours,
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
<ButtonToolbar {size} {wrap}>
|
||||
<DynamicallySlottable slotHost={Item} api={toolbar}>
|
||||
<Item id="notetype">
|
||||
<NotetypeButtons {noteEditor} api={notetypeButtons}>
|
||||
<NotetypeButtons {isLegacy} {noteEditor} api={notetypeButtons}>
|
||||
<slot name="notetypeButtons" />
|
||||
</NotetypeButtons>
|
||||
</Item>
|
||||
|
|
|
|||
|
|
@ -17,9 +17,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
import LabelButton from "$lib/components/LabelButton.svelte";
|
||||
import Shortcut from "$lib/components/Shortcut.svelte";
|
||||
import type { NoteEditorAPI } from "../NoteEditor.svelte";
|
||||
import { openFieldsDialog, openCardsDialog } from "@generated/backend";
|
||||
|
||||
export let api = {};
|
||||
export let noteEditor: NoteEditorAPI;
|
||||
export let isLegacy = false;
|
||||
|
||||
const keyCombination = "Control+L";
|
||||
</script>
|
||||
|
|
@ -37,7 +39,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
tooltip={tr.editingCustomizeFields()}
|
||||
on:click={async () => {
|
||||
await noteEditor.saveNow();
|
||||
bridgeCommand("fields");
|
||||
if (isLegacy) {
|
||||
bridgeCommand("fields");
|
||||
} else {
|
||||
await openFieldsDialog({});
|
||||
}
|
||||
}}
|
||||
>
|
||||
{tr.editingFields()}...
|
||||
|
|
@ -51,7 +57,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
)})"
|
||||
on:click={async () => {
|
||||
await noteEditor.saveNow();
|
||||
bridgeCommand("cards");
|
||||
if (isLegacy) {
|
||||
bridgeCommand("cards");
|
||||
} else {
|
||||
await openCardsDialog({});
|
||||
}
|
||||
}}
|
||||
>
|
||||
{tr.editingCards()}...
|
||||
|
|
|
|||
Loading…
Reference in a new issue