mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Default input setting in fields dialog (#1987)
* Introduce field setting to use plain text editor by default * Remove leftover function from #1476 * Use boolean instead of string * Simplify clear_other_field_duplicates * Convert plain text key to camelCase * Move HTML item below the existing checkbox, instead of to the right (dae) Showing it on the right is more space efficient, but feels a bit cluttered IMHO.
This commit is contained in:
parent
75723d7c9c
commit
d1cbb86178
10 changed files with 84 additions and 51 deletions
|
@ -10,6 +10,7 @@ fields-font = Font:
|
||||||
fields-new-position-1 = New position (1...{ $val }):
|
fields-new-position-1 = New position (1...{ $val }):
|
||||||
fields-notes-require-at-least-one-field = Notes require at least one field.
|
fields-notes-require-at-least-one-field = Notes require at least one field.
|
||||||
fields-reverse-text-direction-rtl = Reverse text direction (RTL)
|
fields-reverse-text-direction-rtl = Reverse text direction (RTL)
|
||||||
|
fields-html-by-default = Use HTML editor by default
|
||||||
fields-size = Size:
|
fields-size = Size:
|
||||||
fields-sort-by-this-field-in-the = Sort by this field in the browser
|
fields-sort-by-this-field-in-the = Sort by this field in the browser
|
||||||
fields-that-field-name-is-already-used = That field name is already used.
|
fields-that-field-name-is-already-used = That field name is already used.
|
||||||
|
|
|
@ -72,6 +72,7 @@ message Notetype {
|
||||||
string font_name = 3;
|
string font_name = 3;
|
||||||
uint32 font_size = 4;
|
uint32 font_size = 4;
|
||||||
string description = 5;
|
string description = 5;
|
||||||
|
bool plain_text = 6;
|
||||||
|
|
||||||
bytes other = 255;
|
bytes other = 255;
|
||||||
}
|
}
|
||||||
|
|
|
@ -501,6 +501,7 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
|
||||||
]
|
]
|
||||||
|
|
||||||
flds = self.note.note_type()["flds"]
|
flds = self.note.note_type()["flds"]
|
||||||
|
plain_texts = [fld.get("plainText", False) for fld in flds]
|
||||||
descriptions = [fld.get("description", "") for fld in flds]
|
descriptions = [fld.get("description", "") for fld in flds]
|
||||||
|
|
||||||
self.widget.show()
|
self.widget.show()
|
||||||
|
@ -521,8 +522,19 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
|
||||||
text_color = self.mw.pm.profile.get("lastTextColor", "#00f")
|
text_color = self.mw.pm.profile.get("lastTextColor", "#00f")
|
||||||
highlight_color = self.mw.pm.profile.get("lastHighlightColor", "#00f")
|
highlight_color = self.mw.pm.profile.get("lastHighlightColor", "#00f")
|
||||||
|
|
||||||
js = "setFields({}); setDescriptions({}); setFonts({}); focusField({}); setNoteId({}); setColorButtons({}); setTags({}); setMathjaxEnabled({});".format(
|
js = """
|
||||||
|
setFields({});
|
||||||
|
setPlainTexts({});
|
||||||
|
setDescriptions({});
|
||||||
|
setFonts({});
|
||||||
|
focusField({});
|
||||||
|
setNoteId({});
|
||||||
|
setColorButtons({});
|
||||||
|
setTags({});
|
||||||
|
setMathjaxEnabled({});
|
||||||
|
""".format(
|
||||||
json.dumps(data),
|
json.dumps(data),
|
||||||
|
json.dumps(plain_texts),
|
||||||
json.dumps(descriptions),
|
json.dumps(descriptions),
|
||||||
json.dumps(self.fonts()),
|
json.dumps(self.fonts()),
|
||||||
json.dumps(focusTo),
|
json.dumps(focusTo),
|
||||||
|
|
|
@ -243,6 +243,7 @@ class FieldDialog(QDialog):
|
||||||
f.fontSize.setValue(fld["size"])
|
f.fontSize.setValue(fld["size"])
|
||||||
f.sortField.setChecked(self.model["sortf"] == fld["ord"])
|
f.sortField.setChecked(self.model["sortf"] == fld["ord"])
|
||||||
f.rtl.setChecked(fld["rtl"])
|
f.rtl.setChecked(fld["rtl"])
|
||||||
|
f.plainTextByDefault.setChecked(fld["plainText"])
|
||||||
f.fieldDescription.setText(fld.get("description", ""))
|
f.fieldDescription.setText(fld.get("description", ""))
|
||||||
|
|
||||||
def saveField(self) -> None:
|
def saveField(self) -> None:
|
||||||
|
@ -264,6 +265,10 @@ class FieldDialog(QDialog):
|
||||||
if fld["rtl"] != rtl:
|
if fld["rtl"] != rtl:
|
||||||
fld["rtl"] = rtl
|
fld["rtl"] = rtl
|
||||||
self.change_tracker.mark_basic()
|
self.change_tracker.mark_basic()
|
||||||
|
plain_text = f.plainTextByDefault.isChecked()
|
||||||
|
if fld["plainText"] != plain_text:
|
||||||
|
fld["plainText"] = plain_text
|
||||||
|
self.change_tracker.mark_basic()
|
||||||
desc = f.fieldDescription.text()
|
desc = f.fieldDescription.text()
|
||||||
if fld.get("description", "") != desc:
|
if fld.get("description", "") != desc:
|
||||||
fld["description"] = desc
|
fld["description"] = desc
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>586</width>
|
<width>598</width>
|
||||||
<height>376</height>
|
<height>378</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -84,13 +84,6 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QGridLayout" name="_2">
|
<layout class="QGridLayout" name="_2">
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QLabel" name="label_font">
|
|
||||||
<property name="text">
|
|
||||||
<string>fields_editing_font</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="1">
|
<item row="3" column="1">
|
||||||
<widget class="QCheckBox" name="rtl">
|
<widget class="QCheckBox" name="rtl">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -98,13 +91,27 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="2">
|
<item row="1" column="1">
|
||||||
<widget class="QSpinBox" name="fontSize">
|
<widget class="QFontComboBox" name="fontFamily">
|
||||||
<property name="minimum">
|
<property name="minimumSize">
|
||||||
<number>5</number>
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>25</height>
|
||||||
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="maximum">
|
</widget>
|
||||||
<number>300</number>
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="label_font">
|
||||||
|
<property name="text">
|
||||||
|
<string>fields_editing_font</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1" colspan="2">
|
||||||
|
<widget class="QLineEdit" name="fieldDescription">
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>fields_description_placeholder</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -115,13 +122,6 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
|
||||||
<widget class="QRadioButton" name="sortField">
|
|
||||||
<property name="text">
|
|
||||||
<string>fields_sort_by_this_field_in_the</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label_description">
|
<widget class="QLabel" name="label_description">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -135,20 +135,30 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="2">
|
||||||
<widget class="QFontComboBox" name="fontFamily">
|
<widget class="QSpinBox" name="fontSize">
|
||||||
<property name="minimumSize">
|
<property name="minimum">
|
||||||
<size>
|
<number>5</number>
|
||||||
<width>0</width>
|
</property>
|
||||||
<height>25</height>
|
<property name="maximum">
|
||||||
</size>
|
<number>300</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1" colspan="2">
|
<item row="2" column="1">
|
||||||
<widget class="QLineEdit" name="fieldDescription">
|
<widget class="QRadioButton" name="sortField">
|
||||||
<property name="placeholderText">
|
<property name="text">
|
||||||
<string>fields_description_placeholder</string>
|
<string>fields_sort_by_this_field_in_the</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="1">
|
||||||
|
<widget class="QCheckBox" name="plainTextByDefault">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>fields_html_by_default</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
@ -42,6 +42,7 @@ impl NoteField {
|
||||||
config: NoteFieldConfig {
|
config: NoteFieldConfig {
|
||||||
sticky: false,
|
sticky: false,
|
||||||
rtl: false,
|
rtl: false,
|
||||||
|
plain_text: false,
|
||||||
font_name: "Arial".into(),
|
font_name: "Arial".into(),
|
||||||
font_size: 20,
|
font_size: 20,
|
||||||
description: "".into(),
|
description: "".into(),
|
||||||
|
|
|
@ -161,7 +161,7 @@ impl From<Notetype> for NotetypeSchema11 {
|
||||||
|
|
||||||
/// See [crate::deckconfig::schema11::clear_other_duplicates()].
|
/// See [crate::deckconfig::schema11::clear_other_duplicates()].
|
||||||
fn clear_other_field_duplicates(other: &mut HashMap<String, Value>) {
|
fn clear_other_field_duplicates(other: &mut HashMap<String, Value>) {
|
||||||
for key in &["description"] {
|
for key in &["description", "plainText"] {
|
||||||
other.remove(*key);
|
other.remove(*key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -195,6 +195,7 @@ impl From<CardRequirement> for CardRequirementSchema11 {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct NoteFieldSchema11 {
|
pub struct NoteFieldSchema11 {
|
||||||
pub(crate) name: String,
|
pub(crate) name: String,
|
||||||
pub(crate) ord: Option<u16>,
|
pub(crate) ord: Option<u16>,
|
||||||
|
@ -211,6 +212,9 @@ pub struct NoteFieldSchema11 {
|
||||||
#[serde(default, deserialize_with = "default_on_invalid")]
|
#[serde(default, deserialize_with = "default_on_invalid")]
|
||||||
pub(crate) description: String,
|
pub(crate) description: String,
|
||||||
|
|
||||||
|
#[serde(default, deserialize_with = "default_on_invalid")]
|
||||||
|
pub(crate) plain_text: bool,
|
||||||
|
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub(crate) other: HashMap<String, Value>,
|
pub(crate) other: HashMap<String, Value>,
|
||||||
}
|
}
|
||||||
|
@ -222,6 +226,7 @@ impl Default for NoteFieldSchema11 {
|
||||||
ord: None,
|
ord: None,
|
||||||
sticky: false,
|
sticky: false,
|
||||||
rtl: false,
|
rtl: false,
|
||||||
|
plain_text: false,
|
||||||
font: "Arial".to_string(),
|
font: "Arial".to_string(),
|
||||||
size: 20,
|
size: 20,
|
||||||
description: String::new(),
|
description: String::new(),
|
||||||
|
@ -238,6 +243,7 @@ impl From<NoteFieldSchema11> for NoteField {
|
||||||
config: NoteFieldConfig {
|
config: NoteFieldConfig {
|
||||||
sticky: f.sticky,
|
sticky: f.sticky,
|
||||||
rtl: f.rtl,
|
rtl: f.rtl,
|
||||||
|
plain_text: f.plain_text,
|
||||||
font_name: f.font,
|
font_name: f.font,
|
||||||
font_size: f.size as u32,
|
font_size: f.size as u32,
|
||||||
description: f.description,
|
description: f.description,
|
||||||
|
@ -259,6 +265,7 @@ impl From<NoteField> for NoteFieldSchema11 {
|
||||||
ord: p.ord.map(|o| o as u16),
|
ord: p.ord.map(|o| o as u16),
|
||||||
sticky: conf.sticky,
|
sticky: conf.sticky,
|
||||||
rtl: conf.rtl,
|
rtl: conf.rtl,
|
||||||
|
plain_text: conf.plain_text,
|
||||||
font: conf.font_name,
|
font: conf.font_name,
|
||||||
size: conf.font_size as u16,
|
size: conf.font_size as u16,
|
||||||
description: conf.description,
|
description: conf.description,
|
||||||
|
|
|
@ -38,17 +38,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
onDestroy(() => tooltipObject?.dispose());
|
onDestroy(() => tooltipObject?.dispose());
|
||||||
|
|
||||||
// hack to update field description tooltips
|
|
||||||
let previousTooltip: string = tooltip;
|
|
||||||
$: if (tooltip !== previousTooltip) {
|
|
||||||
previousTooltip = tooltip;
|
|
||||||
if (tooltipObject !== undefined) {
|
|
||||||
const element: HTMLElement = tooltipObject["_element"];
|
|
||||||
tooltipObject.dispose();
|
|
||||||
createTooltip(element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<slot {createTooltip} {tooltipObject} />
|
<slot {createTooltip} {tooltipObject} />
|
||||||
|
|
|
@ -12,6 +12,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
fontFamily: string;
|
fontFamily: string;
|
||||||
fontSize: number;
|
fontSize: number;
|
||||||
direction: "ltr" | "rtl";
|
direction: "ltr" | "rtl";
|
||||||
|
plainText: boolean;
|
||||||
description: string;
|
description: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -109,6 +109,15 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
fieldNames = newFieldNames;
|
fieldNames = newFieldNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let plainTexts: boolean[] = [];
|
||||||
|
let richTextsHidden: boolean[] = [];
|
||||||
|
let plainTextsHidden: boolean[] = [];
|
||||||
|
|
||||||
|
export function setPlainTexts(fs: boolean[]): void {
|
||||||
|
richTextsHidden = plainTexts = fs;
|
||||||
|
plainTextsHidden = Array.from(fs, (v) => !v);
|
||||||
|
}
|
||||||
|
|
||||||
function setMathjaxEnabled(enabled: boolean): void {
|
function setMathjaxEnabled(enabled: boolean): void {
|
||||||
mathjaxConfig.enabled = enabled;
|
mathjaxConfig.enabled = enabled;
|
||||||
}
|
}
|
||||||
|
@ -119,15 +128,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
}
|
}
|
||||||
|
|
||||||
let fonts: [string, number, boolean][] = [];
|
let fonts: [string, number, boolean][] = [];
|
||||||
let richTextsHidden: boolean[] = [];
|
|
||||||
let plainTextsHidden: boolean[] = [];
|
|
||||||
const fields = clearableArray<EditorFieldAPI>();
|
const fields = clearableArray<EditorFieldAPI>();
|
||||||
|
|
||||||
export function setFonts(fs: [string, number, boolean][]): void {
|
export function setFonts(fs: [string, number, boolean][]): void {
|
||||||
fonts = fs;
|
fonts = fs;
|
||||||
|
|
||||||
richTextsHidden = fonts.map((_, index) => richTextsHidden[index] ?? false);
|
|
||||||
plainTextsHidden = fonts.map((_, index) => plainTextsHidden[index] ?? true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function focusField(index: number | null): void {
|
export function focusField(index: number | null): void {
|
||||||
|
@ -175,6 +179,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
$: fieldsData = fieldNames.map((name, index) => ({
|
$: fieldsData = fieldNames.map((name, index) => ({
|
||||||
name,
|
name,
|
||||||
|
plainText: plainTexts[index],
|
||||||
description: fieldDescriptions[index],
|
description: fieldDescriptions[index],
|
||||||
fontFamily: quoteFontFamily(fonts[index][0]),
|
fontFamily: quoteFontFamily(fonts[index][0]),
|
||||||
fontSize: fonts[index][1],
|
fontSize: fonts[index][1],
|
||||||
|
@ -244,6 +249,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
Object.assign(globalThis, {
|
Object.assign(globalThis, {
|
||||||
setFields,
|
setFields,
|
||||||
|
setPlainTexts,
|
||||||
setDescriptions,
|
setDescriptions,
|
||||||
setFonts,
|
setFonts,
|
||||||
focusField,
|
focusField,
|
||||||
|
|
Loading…
Reference in a new issue