Enable setting of PreviewButton and hiding of cloze button again
This commit is contained in:
parent
862905c58a
commit
e80f43e8fc
@ -383,23 +383,11 @@ class Browser(QMainWindow):
|
|||||||
|
|
||||||
editor._links["preview"] = lambda _editor: self.onTogglePreview()
|
editor._links["preview"] = lambda _editor: self.onTogglePreview()
|
||||||
editor.web.eval(
|
editor.web.eval(
|
||||||
f"""
|
f"$editorToolbar.then(({{ notetypeButtons }}) => notetypeButtons.appendButton({{ component: editorToolbar.PreviewButton }}, -1));"
|
||||||
$editorToolbar.then(({{ addButton }}) => addButton(editorToolbar.labelButton({{
|
|
||||||
label: `{tr.actions_preview()}`,
|
|
||||||
tooltip: `{tr.browsing_preview_selected_card(val=shortcut(preview_shortcut))}`,
|
|
||||||
onClick: () => bridgeCommand("preview"),
|
|
||||||
disables: false,
|
|
||||||
}}), "notetype", -1));
|
|
||||||
"""
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def add_preview_shortcut(cuts: List[Tuple], editor: Editor) -> None:
|
|
||||||
cuts.append(("Ctrl+Shift+P", self.onTogglePreview, True))
|
|
||||||
|
|
||||||
gui_hooks.editor_did_init.append(add_preview_button)
|
gui_hooks.editor_did_init.append(add_preview_button)
|
||||||
gui_hooks.editor_did_init_shortcuts.append(add_preview_shortcut)
|
|
||||||
self.editor = aqt.editor.Editor(self.mw, self.form.fieldsArea, self)
|
self.editor = aqt.editor.Editor(self.mw, self.form.fieldsArea, self)
|
||||||
gui_hooks.editor_did_init_shortcuts.remove(add_preview_shortcut)
|
|
||||||
gui_hooks.editor_did_init.remove(add_preview_button)
|
gui_hooks.editor_did_init.remove(add_preview_button)
|
||||||
|
|
||||||
@ensure_editor_saved
|
@ensure_editor_saved
|
||||||
|
@ -145,7 +145,7 @@ class Editor:
|
|||||||
gui_hooks.editor_did_init_left_buttons(lefttopbtns, self)
|
gui_hooks.editor_did_init_left_buttons(lefttopbtns, self)
|
||||||
|
|
||||||
lefttopbtns_defs = [
|
lefttopbtns_defs = [
|
||||||
f"$editorToolbar.then(({{ addButton }}) => addButton(editorToolbar.rawButton({{ html: `{button}` }}), 'notetype', -1));"
|
f"$editorToolbar.then(({{ notetypeButtons }}) => notetypeButtons.addButton({{ component: editorToolbar.Raw, props: {{ html: `{button}` }} }}, -1));"
|
||||||
for button in lefttopbtns
|
for button in lefttopbtns
|
||||||
]
|
]
|
||||||
lefttopbtns_js = "\n".join(lefttopbtns_defs)
|
lefttopbtns_js = "\n".join(lefttopbtns_defs)
|
||||||
@ -156,10 +156,7 @@ class Editor:
|
|||||||
righttopbtns = runFilter("setupEditorButtons", righttopbtns, self)
|
righttopbtns = runFilter("setupEditorButtons", righttopbtns, self)
|
||||||
|
|
||||||
righttopbtns_defs = "\n".join(
|
righttopbtns_defs = "\n".join(
|
||||||
[
|
[f"editorToolbar.Raw({{ html: `{button}` }})," for button in righttopbtns]
|
||||||
f"editorToolbar.rawButton({{ html: `{button}` }}),"
|
|
||||||
for button in righttopbtns
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
righttopbtns_js = (
|
righttopbtns_js = (
|
||||||
f"""
|
f"""
|
||||||
@ -172,7 +169,7 @@ $editorToolbar.then(({{ addButton }}) => addButton(editorToolbar.buttonGroup({{
|
|||||||
else ""
|
else ""
|
||||||
)
|
)
|
||||||
|
|
||||||
self.web.eval(f"{lefttopbtns_js} {righttopbtns_js}")
|
self.web.eval(f"{lefttopbtns_js}")
|
||||||
|
|
||||||
# Top buttons
|
# Top buttons
|
||||||
######################################################################
|
######################################################################
|
||||||
@ -1268,11 +1265,11 @@ gui_hooks.editor_will_munge_html.append(reverse_url_quoting)
|
|||||||
def set_cloze_button(editor: Editor) -> None:
|
def set_cloze_button(editor: Editor) -> None:
|
||||||
if editor.note.model()["type"] == MODEL_CLOZE:
|
if editor.note.model()["type"] == MODEL_CLOZE:
|
||||||
editor.web.eval(
|
editor.web.eval(
|
||||||
'$editorToolbar.then(({ showButton }) => showButton("template", "cloze")); '
|
'$editorToolbar.then(({ templateButtons }) => templateButtons.showButton("cloze")); '
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
editor.web.eval(
|
editor.web.eval(
|
||||||
'$editorToolbar.then(({ hideButton }) => hideButton("template", "cloze")); '
|
'$editorToolbar.then(({ templateButtons }) => templateButtons.hideButton("cloze")); '
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,11 +51,17 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
return registration;
|
return registration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface SvelteComponent {
|
||||||
|
id: string | undefined;
|
||||||
|
component: SvelteComponentTyped;
|
||||||
|
props: Record<string, unknown>;
|
||||||
|
}
|
||||||
|
|
||||||
const dynamicItems: ButtonRegistration[] = [];
|
const dynamicItems: ButtonRegistration[] = [];
|
||||||
let dynamic: SvelteComponentTyped[] = [];
|
let dynamic: SvelteComponent[] = [];
|
||||||
|
|
||||||
function addButton(
|
function addButton(
|
||||||
button: SvelteComponentTyped,
|
button: SvelteComponent,
|
||||||
add: (added: Element, parent: Element) => number
|
add: (added: Element, parent: Element) => number
|
||||||
): void {
|
): void {
|
||||||
const registration = makeRegistration();
|
const registration = makeRegistration();
|
||||||
@ -86,10 +92,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
dynamic = [...dynamic, button];
|
dynamic = [...dynamic, button];
|
||||||
}
|
}
|
||||||
|
|
||||||
const insertButton = (button: SvelteComponentTyped, id: Identifier = 0) =>
|
const insertButton = (button: SvelteComponent, position: Identifier = 0) =>
|
||||||
addButton(button, (added, parent) => insert(added, parent, id));
|
addButton(button, (added, parent) => insert(added, parent, position));
|
||||||
const appendButton = (button: SvelteComponentTyped, id: Identifier = -1) =>
|
const appendButton = (button: SvelteComponent, position: Identifier = -1) =>
|
||||||
addButton(button, (added, parent) => add(added, parent, id));
|
addButton(button, (added, parent) => add(added, parent, position));
|
||||||
|
|
||||||
function updateRegistration(
|
function updateRegistration(
|
||||||
f: (registration: ButtonRegistration) => void,
|
f: (registration: ButtonRegistration) => void,
|
||||||
@ -137,9 +143,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
|
|
||||||
<div bind:this={buttonGroupRef} {id} class={className} dir="ltr">
|
<div bind:this={buttonGroupRef} {id} class={className} dir="ltr">
|
||||||
<slot />
|
<slot />
|
||||||
{#each dynamic as component, i}
|
{#each dynamic as item, i}
|
||||||
<ButtonGroupItem registration={dynamicItems[i]}>
|
<ButtonGroupItem id={item.id} registration={dynamicItems[i]}>
|
||||||
<svelte:component this={component} />
|
<svelte:component this={item.component} {...item.props} />
|
||||||
</ButtonGroupItem>
|
</ButtonGroupItem>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
@ -12,6 +12,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
import { getContext, hasContext } from "svelte";
|
import { getContext, hasContext } from "svelte";
|
||||||
import { buttonGroupKey } from "./contextKeys";
|
import { buttonGroupKey } from "./contextKeys";
|
||||||
|
|
||||||
|
export let id: string | undefined = undefined;
|
||||||
export let registration: ButtonRegistration | undefined = undefined;
|
export let registration: ButtonRegistration | undefined = undefined;
|
||||||
|
|
||||||
let detach_: boolean;
|
let detach_: boolean;
|
||||||
@ -53,7 +54,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- div in WithTheming is necessary to preserve item position -->
|
<!-- div in WithTheming is necessary to preserve item position -->
|
||||||
<WithTheming {style}>
|
<WithTheming {id} {style}>
|
||||||
<Detachable detach={detach_}>
|
<Detachable detach={detach_}>
|
||||||
<slot />
|
<slot />
|
||||||
</Detachable>
|
</Detachable>
|
||||||
|
@ -3,12 +3,7 @@ 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
|
||||||
-->
|
-->
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
import { onMount, createEventDispatcher } from "svelte";
|
|
||||||
|
|
||||||
export let html: string;
|
export let html: string;
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
|
||||||
onMount(() => dispatch("mount", { button: null }));
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{@html html}
|
{@html html}
|
@ -3,6 +3,7 @@ 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
|
||||||
-->
|
-->
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
|
export let id: string | undefined = undefined;
|
||||||
export let style: string;
|
export let style: string;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -12,6 +13,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div {style}>
|
<div {id} {style}>
|
||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
|
@ -16,6 +16,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
|
|
||||||
import "./color.css";
|
import "./color.css";
|
||||||
|
|
||||||
|
export let api = {};
|
||||||
|
|
||||||
const foregroundColorKeyword = "--foreground-color";
|
const foregroundColorKeyword = "--foreground-color";
|
||||||
let color = "black";
|
let color = "black";
|
||||||
|
|
||||||
@ -32,7 +34,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ButtonGroup id="color">
|
<ButtonGroup id="color" {api}>
|
||||||
<ButtonGroupItem>
|
<ButtonGroupItem>
|
||||||
<WithShortcut shortcut="F7" let:createShortcut let:shortcutLabel>
|
<WithShortcut shortcut="F7" let:createShortcut let:shortcutLabel>
|
||||||
<IconButton
|
<IconButton
|
||||||
|
@ -28,10 +28,17 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Export components */
|
/* Export components */
|
||||||
|
import PreviewButton from "./PreviewButton.svelte";
|
||||||
import LabelButton from "components/LabelButton.svelte";
|
import LabelButton from "components/LabelButton.svelte";
|
||||||
import IconButton from "components/IconButton.svelte";
|
import IconButton from "components/IconButton.svelte";
|
||||||
|
import Raw from "components/Raw.svelte";
|
||||||
|
|
||||||
export const editorToolbar = { LabelButton, IconButton };
|
export const editorToolbar = {
|
||||||
|
PreviewButton,
|
||||||
|
LabelButton,
|
||||||
|
IconButton,
|
||||||
|
Raw,
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
@ -48,6 +55,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
import TemplateButtons from "./TemplateButtons.svelte";
|
import TemplateButtons from "./TemplateButtons.svelte";
|
||||||
|
|
||||||
export const notetypeButtons = {};
|
export const notetypeButtons = {};
|
||||||
|
export const formatInlineButtons = {};
|
||||||
|
export const formatBlockButtons = {};
|
||||||
|
export const colorButtons = {};
|
||||||
|
export const templateButtons = {};
|
||||||
|
|
||||||
export let nightMode: boolean;
|
export let nightMode: boolean;
|
||||||
|
|
||||||
@ -65,9 +76,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
<WithTheming {style}>
|
<WithTheming {style}>
|
||||||
<StickyBar>
|
<StickyBar>
|
||||||
<NoteTypeButtons api={notetypeButtons} />
|
<NoteTypeButtons api={notetypeButtons} />
|
||||||
<FormatInlineButtons />
|
<FormatInlineButtons api={formatInlineButtons} />
|
||||||
<FormatBlockButtons />
|
<FormatBlockButtons api={formatBlockButtons} />
|
||||||
<ColorButtons />
|
<ColorButtons api={colorButtons} />
|
||||||
<TemplateButtons />
|
<TemplateButtons api={templateButtons} />
|
||||||
</StickyBar>
|
</StickyBar>
|
||||||
</WithTheming>
|
</WithTheming>
|
||||||
|
23
ts/editor/PreviewButton.svelte
Normal file
23
ts/editor/PreviewButton.svelte
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<!--
|
||||||
|
Copyright: Ankitects Pty Ltd and contributors
|
||||||
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
-->
|
||||||
|
<script lang="typescript">
|
||||||
|
import { bridgeCommand } from "lib/bridgecommand";
|
||||||
|
import * as tr from "lib/i18n";
|
||||||
|
|
||||||
|
import WithShortcut from "components/WithShortcut.svelte";
|
||||||
|
import LabelButton from "components/LabelButton.svelte";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<WithShortcut shortcut="Control+Shift+KeyP" let:createShortcut let:shortcutLabel>
|
||||||
|
<LabelButton
|
||||||
|
tooltip="{`${tr.browsingPreviewSelectedCard({
|
||||||
|
val: 'test',
|
||||||
|
})} (${shortcutLabel})`},"
|
||||||
|
disables={false}
|
||||||
|
on:click={() => bridgeCommand('preview')}
|
||||||
|
on:mount={createShortcut}>
|
||||||
|
{tr.actionsPreview()}
|
||||||
|
</LabelButton>
|
||||||
|
</WithShortcut>
|
@ -19,6 +19,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
import { appendInParentheses } from "./helpers";
|
import { appendInParentheses } from "./helpers";
|
||||||
import { paperclipIcon, micIcon, functionIcon, xmlIcon } from "./icons";
|
import { paperclipIcon, micIcon, functionIcon, xmlIcon } from "./icons";
|
||||||
|
|
||||||
|
export let api = {};
|
||||||
|
|
||||||
function onAttachment(): void {
|
function onAttachment(): void {
|
||||||
bridgeCommand("attach");
|
bridgeCommand("attach");
|
||||||
}
|
}
|
||||||
@ -32,7 +34,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ButtonGroup id="template">
|
<ButtonGroup id="template" {api}>
|
||||||
<ButtonGroupItem>
|
<ButtonGroupItem>
|
||||||
<WithShortcut shortcut="F3" let:createShortcut let:shortcutLabel>
|
<WithShortcut shortcut="F3" let:createShortcut let:shortcutLabel>
|
||||||
<IconButton
|
<IconButton
|
||||||
@ -55,7 +57,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
</WithShortcut>
|
</WithShortcut>
|
||||||
</ButtonGroupItem>
|
</ButtonGroupItem>
|
||||||
|
|
||||||
<ButtonGroupItem>
|
<ButtonGroupItem id="cloze">
|
||||||
<ClozeButton />
|
<ClozeButton />
|
||||||
</ButtonGroupItem>
|
</ButtonGroupItem>
|
||||||
|
|
||||||
|
@ -166,7 +166,9 @@ export function setFormat(cmd: string, arg?: any, nosave: boolean = false): void
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const i18n = setupI18n({ modules: [ModuleName.EDITING, ModuleName.KEYBOARD] });
|
const i18n = setupI18n({
|
||||||
|
modules: [ModuleName.EDITING, ModuleName.KEYBOARD, ModuleName.ACTIONS, ModuleName.BROWSING],
|
||||||
|
});
|
||||||
|
|
||||||
import type EditorToolbar from "./EditorToolbar.svelte";
|
import type EditorToolbar from "./EditorToolbar.svelte";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user