Connect icons to sticky fields values
This commit is contained in:
parent
d1bca9e4d9
commit
8593ab3c4c
@ -29,6 +29,7 @@ from anki.utils import checksum, isLin, isWin, namedtmp
|
|||||||
from aqt import AnkiQt, colors, gui_hooks
|
from aqt import AnkiQt, colors, gui_hooks
|
||||||
from aqt.main import ResetReason
|
from aqt.main import ResetReason
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
|
from aqt.schema_change_tracker import ChangeTracker
|
||||||
from aqt.sound import av_player
|
from aqt.sound import av_player
|
||||||
from aqt.theme import theme_manager
|
from aqt.theme import theme_manager
|
||||||
from aqt.utils import (
|
from aqt.utils import (
|
||||||
@ -180,7 +181,7 @@ class Editor:
|
|||||||
tr(TR.EDITING_SET_FOREGROUND_COLOUR_F7),
|
tr(TR.EDITING_SET_FOREGROUND_COLOUR_F7),
|
||||||
"""
|
"""
|
||||||
<span id="forecolor" class="topbut topbut--rounded" style="background: #000"></span>
|
<span id="forecolor" class="topbut topbut--rounded" style="background: #000"></span>
|
||||||
"""
|
""",
|
||||||
),
|
),
|
||||||
self._addButton(
|
self._addButton(
|
||||||
None,
|
None,
|
||||||
@ -188,7 +189,7 @@ class Editor:
|
|||||||
tr(TR.EDITING_CHANGE_COLOUR_F8),
|
tr(TR.EDITING_CHANGE_COLOUR_F8),
|
||||||
"""
|
"""
|
||||||
<span class="topbut topbut--rounded rainbow"></span>
|
<span class="topbut topbut--rounded rainbow"></span>
|
||||||
"""
|
""",
|
||||||
),
|
),
|
||||||
self._addButton(
|
self._addButton(
|
||||||
"text_cloze", "cloze", tr(TR.EDITING_CLOZE_DELETION_CTRLANDSHIFTANDC)
|
"text_cloze", "cloze", tr(TR.EDITING_CLOZE_DELETION_CTRLANDSHIFTANDC)
|
||||||
@ -472,6 +473,16 @@ class Editor:
|
|||||||
else:
|
else:
|
||||||
print("uncaught cmd", cmd)
|
print("uncaught cmd", cmd)
|
||||||
|
|
||||||
|
if cmd.startswith("toggleSticky"):
|
||||||
|
(type, num) = cmd.split(":", 1)
|
||||||
|
ord = int(num)
|
||||||
|
|
||||||
|
fld = self.note.model()["flds"][ord]
|
||||||
|
fld["sticky"] = not fld["sticky"]
|
||||||
|
|
||||||
|
change_tracker = ChangeTracker(self.mw)
|
||||||
|
change_tracker.mark_basic()
|
||||||
|
|
||||||
def mungeHTML(self, txt: str) -> str:
|
def mungeHTML(self, txt: str) -> str:
|
||||||
return gui_hooks.editor_will_munge_html(txt, self)
|
return gui_hooks.editor_will_munge_html(txt, self)
|
||||||
|
|
||||||
@ -520,6 +531,11 @@ class Editor:
|
|||||||
json.dumps(focusTo),
|
json.dumps(focusTo),
|
||||||
json.dumps(self.note.id),
|
json.dumps(self.note.id),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if self.addMode:
|
||||||
|
sticky = [field["sticky"] for field in self.note.model()["flds"]]
|
||||||
|
js += " setSticky(%s);" % json.dumps(sticky)
|
||||||
|
|
||||||
js = gui_hooks.editor_will_load_note(js, self.note, self)
|
js = gui_hooks.editor_will_load_note(js, self.note, self)
|
||||||
self.web.evalWithCallback(js, oncallback)
|
self.web.evalWithCallback(js, oncallback)
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
* 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 */
|
||||||
|
|
||||||
body {
|
body {
|
||||||
|
color: var(--text-fg);
|
||||||
background-color: var(--bg-color);
|
background-color: var(--bg-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +62,7 @@ body {
|
|||||||
width: 16px;
|
width: 16px;
|
||||||
height: 16px;
|
height: 16px;
|
||||||
margin-top: 4px;
|
margin-top: 4px;
|
||||||
vertical-align: -.125em;
|
vertical-align: -0.125em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.topbut--rounded {
|
.topbut--rounded {
|
||||||
|
@ -212,8 +212,8 @@ export class EditingArea extends HTMLDivElement {
|
|||||||
customElements.define("anki-editing-area", EditingArea, { extends: "div" });
|
customElements.define("anki-editing-area", EditingArea, { extends: "div" });
|
||||||
|
|
||||||
export class LabelContainer extends HTMLDivElement {
|
export class LabelContainer extends HTMLDivElement {
|
||||||
sticky: HTMLSpanElement
|
sticky: HTMLSpanElement;
|
||||||
label: HTMLSpanElement
|
label: HTMLSpanElement;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@ -221,6 +221,7 @@ export class LabelContainer extends HTMLDivElement {
|
|||||||
|
|
||||||
this.sticky = document.createElement("span");
|
this.sticky = document.createElement("span");
|
||||||
this.sticky.className = "bi bi-pin-angle-fill me-1 sticky-icon";
|
this.sticky.className = "bi bi-pin-angle-fill me-1 sticky-icon";
|
||||||
|
this.sticky.hidden = true;
|
||||||
this.appendChild(this.sticky);
|
this.appendChild(this.sticky);
|
||||||
|
|
||||||
this.label = document.createElement("span");
|
this.label = document.createElement("span");
|
||||||
@ -242,8 +243,15 @@ export class LabelContainer extends HTMLDivElement {
|
|||||||
this.label.innerText = labelName;
|
this.label.innerText = labelName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
activateSticky(initialState: boolean): void {
|
||||||
|
this.sticky.classList.toggle("is-active", initialState);
|
||||||
|
this.sticky.hidden = false;
|
||||||
|
}
|
||||||
|
|
||||||
toggleSticky(): void {
|
toggleSticky(): void {
|
||||||
this.sticky.classList.toggle('is-active');
|
bridgeCommand(`toggleSticky:${this.getAttribute("ord")}`, () => {
|
||||||
|
this.sticky.classList.toggle("is-active");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,6 +286,7 @@ export class EditorField extends HTMLDivElement {
|
|||||||
switch (name) {
|
switch (name) {
|
||||||
case "ord":
|
case "ord":
|
||||||
this.editingArea.setAttribute("ord", newValue);
|
this.editingArea.setAttribute("ord", newValue);
|
||||||
|
this.labelContainer.setAttribute("ord", newValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,6 +362,12 @@ export function setFonts(fonts: [string, number, boolean][]): void {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setSticky(stickies: boolean[]): void {
|
||||||
|
forEditorField(stickies, (field, isSticky) => {
|
||||||
|
field.labelContainer.activateSticky(isSticky);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function setFormat(cmd: string, arg?: any, nosave: boolean = false): void {
|
export function setFormat(cmd: string, arg?: any, nosave: boolean = false): void {
|
||||||
document.execCommand(cmd, false, arg);
|
document.execCommand(cmd, false, arg);
|
||||||
if (!nosave) {
|
if (!nosave) {
|
||||||
|
@ -35,9 +35,11 @@ $fusion-button-base-bg: #454545;
|
|||||||
color: var(--text-fg);
|
color: var(--text-fg);
|
||||||
|
|
||||||
/* match the fusion button gradient */
|
/* match the fusion button gradient */
|
||||||
background: linear-gradient(0deg,
|
background: linear-gradient(
|
||||||
|
0deg,
|
||||||
$fusion-button-gradient-start 0%,
|
$fusion-button-gradient-start 0%,
|
||||||
$fusion-button-gradient-end 100%);
|
$fusion-button-gradient-end 100%
|
||||||
|
);
|
||||||
box-shadow: 0 0 3px $fusion-button-outline;
|
box-shadow: 0 0 3px $fusion-button-outline;
|
||||||
border: 1px solid $fusion-button-border;
|
border: 1px solid $fusion-button-border;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user