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-notes-require-at-least-one-field = Notes require at least one field.
|
||||
fields-reverse-text-direction-rtl = Reverse text direction (RTL)
|
||||
fields-html-by-default = Use HTML editor by default
|
||||
fields-size = Size:
|
||||
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.
|
||||
|
|
|
@ -72,6 +72,7 @@ message Notetype {
|
|||
string font_name = 3;
|
||||
uint32 font_size = 4;
|
||||
string description = 5;
|
||||
bool plain_text = 6;
|
||||
|
||||
bytes other = 255;
|
||||
}
|
||||
|
|
|
@ -501,6 +501,7 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
|
|||
]
|
||||
|
||||
flds = self.note.note_type()["flds"]
|
||||
plain_texts = [fld.get("plainText", False) for fld in flds]
|
||||
descriptions = [fld.get("description", "") for fld in flds]
|
||||
|
||||
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")
|
||||
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(plain_texts),
|
||||
json.dumps(descriptions),
|
||||
json.dumps(self.fonts()),
|
||||
json.dumps(focusTo),
|
||||
|
|
|
@ -243,6 +243,7 @@ class FieldDialog(QDialog):
|
|||
f.fontSize.setValue(fld["size"])
|
||||
f.sortField.setChecked(self.model["sortf"] == fld["ord"])
|
||||
f.rtl.setChecked(fld["rtl"])
|
||||
f.plainTextByDefault.setChecked(fld["plainText"])
|
||||
f.fieldDescription.setText(fld.get("description", ""))
|
||||
|
||||
def saveField(self) -> None:
|
||||
|
@ -264,6 +265,10 @@ class FieldDialog(QDialog):
|
|||
if fld["rtl"] != rtl:
|
||||
fld["rtl"] = rtl
|
||||
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()
|
||||
if fld.get("description", "") != desc:
|
||||
fld["description"] = desc
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>586</width>
|
||||
<height>376</height>
|
||||
<width>598</width>
|
||||
<height>378</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -84,13 +84,6 @@
|
|||
</item>
|
||||
<item>
|
||||
<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">
|
||||
<widget class="QCheckBox" name="rtl">
|
||||
<property name="text">
|
||||
|
@ -98,13 +91,27 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QSpinBox" name="fontSize">
|
||||
<property name="minimum">
|
||||
<number>5</number>
|
||||
<item row="1" column="1">
|
||||
<widget class="QFontComboBox" name="fontFamily">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>25</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>300</number>
|
||||
</widget>
|
||||
</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>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -115,13 +122,6 @@
|
|||
</property>
|
||||
</widget>
|
||||
</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">
|
||||
<widget class="QLabel" name="label_description">
|
||||
<property name="sizePolicy">
|
||||
|
@ -135,20 +135,30 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QFontComboBox" name="fontFamily">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>25</height>
|
||||
</size>
|
||||
<item row="1" column="2">
|
||||
<widget class="QSpinBox" name="fontSize">
|
||||
<property name="minimum">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>300</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" colspan="2">
|
||||
<widget class="QLineEdit" name="fieldDescription">
|
||||
<property name="placeholderText">
|
||||
<string>fields_description_placeholder</string>
|
||||
<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="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>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -42,6 +42,7 @@ impl NoteField {
|
|||
config: NoteFieldConfig {
|
||||
sticky: false,
|
||||
rtl: false,
|
||||
plain_text: false,
|
||||
font_name: "Arial".into(),
|
||||
font_size: 20,
|
||||
description: "".into(),
|
||||
|
|
|
@ -161,7 +161,7 @@ impl From<Notetype> for NotetypeSchema11 {
|
|||
|
||||
/// See [crate::deckconfig::schema11::clear_other_duplicates()].
|
||||
fn clear_other_field_duplicates(other: &mut HashMap<String, Value>) {
|
||||
for key in &["description"] {
|
||||
for key in &["description", "plainText"] {
|
||||
other.remove(*key);
|
||||
}
|
||||
}
|
||||
|
@ -195,6 +195,7 @@ impl From<CardRequirement> for CardRequirementSchema11 {
|
|||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct NoteFieldSchema11 {
|
||||
pub(crate) name: String,
|
||||
pub(crate) ord: Option<u16>,
|
||||
|
@ -211,6 +212,9 @@ pub struct NoteFieldSchema11 {
|
|||
#[serde(default, deserialize_with = "default_on_invalid")]
|
||||
pub(crate) description: String,
|
||||
|
||||
#[serde(default, deserialize_with = "default_on_invalid")]
|
||||
pub(crate) plain_text: bool,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub(crate) other: HashMap<String, Value>,
|
||||
}
|
||||
|
@ -222,6 +226,7 @@ impl Default for NoteFieldSchema11 {
|
|||
ord: None,
|
||||
sticky: false,
|
||||
rtl: false,
|
||||
plain_text: false,
|
||||
font: "Arial".to_string(),
|
||||
size: 20,
|
||||
description: String::new(),
|
||||
|
@ -238,6 +243,7 @@ impl From<NoteFieldSchema11> for NoteField {
|
|||
config: NoteFieldConfig {
|
||||
sticky: f.sticky,
|
||||
rtl: f.rtl,
|
||||
plain_text: f.plain_text,
|
||||
font_name: f.font,
|
||||
font_size: f.size as u32,
|
||||
description: f.description,
|
||||
|
@ -259,6 +265,7 @@ impl From<NoteField> for NoteFieldSchema11 {
|
|||
ord: p.ord.map(|o| o as u16),
|
||||
sticky: conf.sticky,
|
||||
rtl: conf.rtl,
|
||||
plain_text: conf.plain_text,
|
||||
font: conf.font_name,
|
||||
size: conf.font_size as u16,
|
||||
description: conf.description,
|
||||
|
|
|
@ -38,17 +38,6 @@
|
|||
}
|
||||
|
||||
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>
|
||||
|
||||
<slot {createTooltip} {tooltipObject} />
|
||||
|
|
|
@ -12,6 +12,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
fontFamily: string;
|
||||
fontSize: number;
|
||||
direction: "ltr" | "rtl";
|
||||
plainText: boolean;
|
||||
description: string;
|
||||
}
|
||||
|
||||
|
|
|
@ -109,6 +109,15 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
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 {
|
||||
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 richTextsHidden: boolean[] = [];
|
||||
let plainTextsHidden: boolean[] = [];
|
||||
const fields = clearableArray<EditorFieldAPI>();
|
||||
|
||||
export function setFonts(fs: [string, number, boolean][]): void {
|
||||
fonts = fs;
|
||||
|
||||
richTextsHidden = fonts.map((_, index) => richTextsHidden[index] ?? false);
|
||||
plainTextsHidden = fonts.map((_, index) => plainTextsHidden[index] ?? true);
|
||||
}
|
||||
|
||||
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) => ({
|
||||
name,
|
||||
plainText: plainTexts[index],
|
||||
description: fieldDescriptions[index],
|
||||
fontFamily: quoteFontFamily(fonts[index][0]),
|
||||
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, {
|
||||
setFields,
|
||||
setPlainTexts,
|
||||
setDescriptions,
|
||||
setFonts,
|
||||
focusField,
|
||||
|
|
Loading…
Reference in a new issue