mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Move setTagsCollapsed()
This commit is contained in:
parent
51fcb86521
commit
15cbbeea24
7 changed files with 69 additions and 37 deletions
|
@ -34,7 +34,12 @@ service FrontendService {
|
||||||
|
|
||||||
// Profile config
|
// Profile config
|
||||||
rpc GetProfileConfigJson(generic.String) returns (generic.Json);
|
rpc GetProfileConfigJson(generic.String) returns (generic.Json);
|
||||||
rpc SetProfileConfigJson(SetProfileConfigJsonRequest) returns (generic.Empty);
|
rpc SetProfileConfigJson(SetSettingJsonRequest) returns (generic.Empty);
|
||||||
|
|
||||||
|
// Metadata
|
||||||
|
rpc GetMetaJson(generic.String) returns (generic.Json);
|
||||||
|
rpc SetMetaJson(SetSettingJsonRequest) returns (generic.Empty);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
service BackendFrontendService {}
|
service BackendFrontendService {}
|
||||||
|
@ -49,7 +54,7 @@ message SetSchedulingStatesRequest {
|
||||||
scheduler.SchedulingStates states = 2;
|
scheduler.SchedulingStates states = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message SetProfileConfigJsonRequest {
|
message SetSettingJsonRequest {
|
||||||
string key = 1;
|
string key = 1;
|
||||||
bytes value_json = 2;
|
bytes value_json = 2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,13 +181,8 @@ class Editor:
|
||||||
self.outerLayout.addWidget(self.web, 1)
|
self.outerLayout.addWidget(self.web, 1)
|
||||||
|
|
||||||
def setupWeb(self) -> None:
|
def setupWeb(self) -> None:
|
||||||
if self.editorMode == EditorMode.ADD_CARDS:
|
editor_key = self.mw.pm.editor_key(self.editorMode)
|
||||||
mode = "add"
|
self.web.load_sveltekit_page(f"editor/?mode={editor_key}")
|
||||||
elif self.editorMode == EditorMode.BROWSER:
|
|
||||||
mode = "browse"
|
|
||||||
else:
|
|
||||||
mode = "review"
|
|
||||||
self.web.load_sveltekit_page(f"editor/?mode={mode}")
|
|
||||||
|
|
||||||
def _set_ready(self) -> None:
|
def _set_ready(self) -> None:
|
||||||
lefttopbtns: list[str] = []
|
lefttopbtns: list[str] = []
|
||||||
|
@ -460,11 +455,6 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
|
||||||
elif cmd.startswith("saveTags"):
|
elif cmd.startswith("saveTags"):
|
||||||
gui_hooks.editor_did_update_tags(self.note)
|
gui_hooks.editor_did_update_tags(self.note)
|
||||||
|
|
||||||
elif cmd.startswith("setTagsCollapsed"):
|
|
||||||
(type, collapsed_string) = cmd.split(":", 1)
|
|
||||||
collapsed = collapsed_string == "true"
|
|
||||||
self.setTagsCollapsed(collapsed)
|
|
||||||
|
|
||||||
elif cmd.startswith("editorState"):
|
elif cmd.startswith("editorState"):
|
||||||
(_, new_state_id, old_state_id) = cmd.split(":", 2)
|
(_, new_state_id, old_state_id) = cmd.split(":", 2)
|
||||||
self.signal_state_change(
|
self.signal_state_change(
|
||||||
|
|
|
@ -18,6 +18,7 @@ from collections.abc import Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from errno import EPROTOTYPE
|
from errno import EPROTOTYPE
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
import flask
|
import flask
|
||||||
import flask_cors
|
import flask_cors
|
||||||
|
@ -622,23 +623,37 @@ def editor_update_note() -> bytes:
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
def get_profile_config_json() -> bytes:
|
def get_setting_json(getter: Callable[[str], Any]) -> bytes:
|
||||||
key = generic_pb2.String()
|
req = generic_pb2.String()
|
||||||
key.ParseFromString(request.data)
|
req.ParseFromString(request.data)
|
||||||
value = aqt.mw.pm.profile.get(key.val, None)
|
value = getter(req.val)
|
||||||
output = generic_pb2.Json(json=json.dumps(value).encode()).SerializeToString()
|
output = generic_pb2.Json(json=json.dumps(value).encode()).SerializeToString()
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
def set_profile_config_json() -> bytes:
|
def set_setting_json(setter: Callable[[str, Any], Any]) -> bytes:
|
||||||
req = frontend_pb2.SetProfileConfigJsonRequest()
|
req = frontend_pb2.SetSettingJsonRequest()
|
||||||
req.ParseFromString(request.data)
|
req.ParseFromString(request.data)
|
||||||
aqt.mw.pm.profile[req.key] = json.loads(req.value_json)
|
setter(req.key, json.loads(req.value_json))
|
||||||
|
|
||||||
return b""
|
return b""
|
||||||
|
|
||||||
|
|
||||||
|
def get_profile_config_json() -> bytes:
|
||||||
|
return get_setting_json(aqt.mw.pm.profile.get)
|
||||||
|
|
||||||
|
|
||||||
|
def set_profile_config_json() -> bytes:
|
||||||
|
return set_setting_json(aqt.mw.pm.profile.__setitem__)
|
||||||
|
|
||||||
|
|
||||||
|
def get_meta_json() -> bytes:
|
||||||
|
return get_setting_json(aqt.mw.pm.meta.get)
|
||||||
|
|
||||||
|
|
||||||
|
def set_meta_json() -> bytes:
|
||||||
|
return set_setting_json(aqt.mw.pm.meta.__setitem__)
|
||||||
|
|
||||||
|
|
||||||
post_handler_list = [
|
post_handler_list = [
|
||||||
congrats_info,
|
congrats_info,
|
||||||
get_deck_configs_for_update,
|
get_deck_configs_for_update,
|
||||||
|
@ -657,6 +672,8 @@ post_handler_list = [
|
||||||
editor_update_note,
|
editor_update_note,
|
||||||
get_profile_config_json,
|
get_profile_config_json,
|
||||||
set_profile_config_json,
|
set_profile_config_json,
|
||||||
|
get_meta_json,
|
||||||
|
set_meta_json,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,36 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
import { getProfileConfigJson, setProfileConfigJson } from "@generated/backend";
|
import { getMetaJson, getProfileConfigJson, setMetaJson, setProfileConfigJson } from "@generated/backend";
|
||||||
|
|
||||||
export async function getProfileConfig(key: string): Promise<any> {
|
async function getSettingJson(key: string, backendGetter: (key: string) => Promise<any>): Promise<any> {
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
const json = decoder.decode((await getProfileConfigJson({ val: key })).json);
|
const json = decoder.decode((await backendGetter(key)).json);
|
||||||
return JSON.parse(json);
|
return JSON.parse(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setProfileConfig(key: string, value: any): Promise<void> {
|
async function setSettingJson(
|
||||||
|
key: string,
|
||||||
|
value: any,
|
||||||
|
backendSetter: (key: string, value: any) => Promise<any>,
|
||||||
|
): Promise<void> {
|
||||||
const encoder = new TextEncoder();
|
const encoder = new TextEncoder();
|
||||||
const json = JSON.stringify(value);
|
const json = JSON.stringify(value);
|
||||||
await setProfileConfigJson({ key: key, valueJson: encoder.encode(json) });
|
await backendSetter(key, encoder.encode(json));
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getProfileConfig(key: string): Promise<any> {
|
||||||
|
return getSettingJson(key, async (k) => await getProfileConfigJson({ val: k }));
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function setProfileConfig(key: string, value: any): Promise<void> {
|
||||||
|
return await setSettingJson(key, value, async (k, v) => await setProfileConfigJson({ key: k, valueJson: v }));
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getMeta(key: string): Promise<any> {
|
||||||
|
return getSettingJson(key, async (k) => await getMetaJson({ val: k }));
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function setMeta(key: string, value: any): Promise<void> {
|
||||||
|
return await setSettingJson(key, value, async (k, v) => await setMetaJson({ key: k, valueJson: v }));
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,13 +222,15 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
}
|
}
|
||||||
|
|
||||||
const tagsCollapsed = writable<boolean>();
|
const tagsCollapsed = writable<boolean>();
|
||||||
|
$: tagsCollapsedMetaKey = `${mode}TagsCollapsed`;
|
||||||
|
|
||||||
export function setTagsCollapsed(collapsed: boolean): void {
|
export function setTagsCollapsed(collapsed: boolean): void {
|
||||||
$tagsCollapsed = collapsed;
|
$tagsCollapsed = collapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateTagsCollapsed(collapsed: boolean) {
|
async function updateTagsCollapsed(collapsed: boolean) {
|
||||||
$tagsCollapsed = collapsed;
|
$tagsCollapsed = collapsed;
|
||||||
bridgeCommand(`setTagsCollapsed:${$tagsCollapsed}`);
|
await setMeta(tagsCollapsedMetaKey, collapsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
let note: Note | null = null;
|
let note: Note | null = null;
|
||||||
|
@ -446,7 +448,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
decodeIriPaths,
|
decodeIriPaths,
|
||||||
} from "@generated/backend";
|
} from "@generated/backend";
|
||||||
import { wrapInternal } from "@tslib/wrap";
|
import { wrapInternal } from "@tslib/wrap";
|
||||||
import { getProfileConfig } from "@tslib/profile";
|
import { getProfileConfig, getMeta, setMeta } from "@tslib/profile";
|
||||||
import Shortcut from "$lib/components/Shortcut.svelte";
|
import Shortcut from "$lib/components/Shortcut.svelte";
|
||||||
|
|
||||||
import { mathjaxConfig } from "$lib/editable/mathjax-element.svelte";
|
import { mathjaxConfig } from "$lib/editable/mathjax-element.svelte";
|
||||||
|
@ -465,7 +467,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
import ButtonGroupItem from "$lib/components/ButtonGroupItem.svelte";
|
import ButtonGroupItem from "$lib/components/ButtonGroupItem.svelte";
|
||||||
import PreviewButton from "./PreviewButton.svelte";
|
import PreviewButton from "./PreviewButton.svelte";
|
||||||
import type { Note } from "@generated/anki/notes_pb";
|
import type { Note } from "@generated/anki/notes_pb";
|
||||||
import InlineButtons from "./editor-toolbar/InlineButtons.svelte";
|
|
||||||
|
|
||||||
$: isIOImageLoaded = false;
|
$: isIOImageLoaded = false;
|
||||||
$: ioImageLoadedStore.set(isIOImageLoaded);
|
$: ioImageLoadedStore.set(isIOImageLoaded);
|
||||||
|
@ -641,8 +642,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
focusField(focusTo);
|
focusField(focusTo);
|
||||||
toolbar.inlineButtons?.setColorButtons([lastTextColor, lastHighlightColor]);
|
toolbar.inlineButtons?.setColorButtons([lastTextColor, lastHighlightColor]);
|
||||||
setTags(tags);
|
setTags(tags);
|
||||||
// TODO: mw.pm.tags_collapsed()
|
setTagsCollapsed(await getMeta(tagsCollapsedMetaKey));
|
||||||
setTagsCollapsed(false);
|
|
||||||
// TODO: renderMathjax col config
|
// TODO: renderMathjax col config
|
||||||
setMathjaxEnabled(true);
|
setMathjaxEnabled(true);
|
||||||
// TODO: shrinkEditorImages col config
|
// TODO: shrinkEditorImages col config
|
||||||
|
@ -759,7 +759,7 @@ components and functionality for general note editing.
|
||||||
<div class="note-editor" bind:this={noteEditor}>
|
<div class="note-editor" bind:this={noteEditor}>
|
||||||
<EditorToolbar {size} {wrap} api={toolbar}>
|
<EditorToolbar {size} {wrap} api={toolbar}>
|
||||||
<svelte:fragment slot="notetypeButtons">
|
<svelte:fragment slot="notetypeButtons">
|
||||||
{#if mode === "browse"}
|
{#if mode === "browser"}
|
||||||
<ButtonGroupItem>
|
<ButtonGroupItem>
|
||||||
<PreviewButton />
|
<PreviewButton />
|
||||||
</ButtonGroupItem>
|
</ButtonGroupItem>
|
||||||
|
|
|
@ -54,7 +54,7 @@ export const components = {
|
||||||
export { editorToolbar } from "./editor-toolbar";
|
export { editorToolbar } from "./editor-toolbar";
|
||||||
|
|
||||||
export async function setupEditor(mode: EditorMode) {
|
export async function setupEditor(mode: EditorMode) {
|
||||||
if (!["add", "browse", "review"].includes(mode)) {
|
if (!["add", "browser", "current"].includes(mode)) {
|
||||||
alert("unexpected editor type");
|
alert("unexpected editor type");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,4 +28,4 @@ export enum EditorState {
|
||||||
ImageOcclusionFields = 3,
|
ImageOcclusionFields = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EditorMode = "add" | "browse" | "review";
|
export type EditorMode = "add" | "browser" | "current";
|
||||||
|
|
Loading…
Reference in a new issue