mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-28 21:49:49 +00:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1a9fa89fb2 | ||
|
|
8b293b64ad | ||
|
|
d1c9c8c034 | ||
|
|
06499e39aa |
@@ -10,7 +10,7 @@ use wordcraft_geom::Rect;
|
||||
|
||||
use crate::boxes::BoxContext;
|
||||
use crate::para::{CellText, ClKind, ParaLayout};
|
||||
use crate::{BoxInput, BoxLayout, Ctx, Placed, ViewMode, layout_box};
|
||||
use crate::{BoxInput, BoxLayout, Ctx, Placed, layout_box};
|
||||
|
||||
/// Largest preferred table width, as a share of the text column, that a file can ask for.
|
||||
const MAX_WIDTH_SHARE: f32 = 10.0;
|
||||
@@ -431,12 +431,6 @@ fn table_frame(ctx: &mut Ctx, t: &Table, avail: f32, depth: usize, style: Option
|
||||
grid.iter_mut().for_each(|w| *w *= k);
|
||||
total = avail;
|
||||
}
|
||||
// The reading view reflows to its column, so even a table with its own width fits it (#7988).
|
||||
if ctx.opts.view == ViewMode::Read && total > avail && avail > 0.0 {
|
||||
let k = avail / total;
|
||||
grid.iter_mut().for_each(|w| *w *= k);
|
||||
total = avail;
|
||||
}
|
||||
if !t.props.fixed {
|
||||
// Measuring lays paragraphs out once more; it mustn't count their equations twice.
|
||||
let eq_count = ctx.eq_count;
|
||||
@@ -483,14 +477,6 @@ fn table_frame(ctx: &mut Ctx, t: &Table, avail: f32, depth: usize, style: Option
|
||||
} else {
|
||||
indent - first_cell_left_margin_in(t, margins_def)
|
||||
};
|
||||
// The reading view fits the table into what the start offset leaves of the column, mirrored or not (#7988).
|
||||
let room = (avail - start_offset.max(0.0)).max(1.0);
|
||||
if ctx.opts.view == ViewMode::Read && acc > room && !matches!(t.props.align, Some(Align::Center | Align::Right)) {
|
||||
let k = room / acc;
|
||||
colx.iter_mut().for_each(|c| *c *= k);
|
||||
acc = room;
|
||||
total = room;
|
||||
}
|
||||
let x = match (t.props.align, rtl) {
|
||||
(Some(Align::Center), _) => (avail - total) / 2.0,
|
||||
// End alignment: the right margin, or the left one in a right-to-left table.
|
||||
|
||||
@@ -660,31 +660,6 @@ fn reading_layout_reflows_into_viewport_height_pages_without_changing_print_layo
|
||||
assert!(invalid.pages.iter().all(|p| p.w.is_finite() && p.h.is_finite()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reading_layout_fits_a_wide_table_to_the_column() {
|
||||
crate::test_fonts();
|
||||
// #7988: a 468 pt table is wider than a reading column but must not run past its edge, however it is indented or mirrored.
|
||||
let cases = [(0.0, false, None), (36.0, false, None), (36.0, true, None)];
|
||||
let aligned = [None, Some(Align::Left), Some(Align::Center), Some(Align::Right)].map(|a| (36.0, false, a));
|
||||
let aligned_rtl = [Some(Align::Left), Some(Align::Right)].map(|a| (36.0, true, a));
|
||||
for (indent, rtl, align) in cases.into_iter().chain(aligned).chain(aligned_rtl) {
|
||||
let mut d = Document::from_text("Before.");
|
||||
let mut t = Table::new(2, 4, 468.0);
|
||||
t.props.indent = Some(indent);
|
||||
t.props.bidi_visual = rtl;
|
||||
t.props.align = align;
|
||||
d.insert_block(StoryRef::Body, &Path::top(1), wordcraft_doc::Block::Table(t)).unwrap();
|
||||
let opts = LayoutOptions { view: ViewMode::Read, web_width: 360.0, read_height: 600.0, ..Default::default() };
|
||||
let l = layout(&d, &mut LayoutCache::new(), &opts);
|
||||
let p = &l.pages[0];
|
||||
let cells: Vec<_> = p.items.iter().filter_map(|i| if let Placed::Cell { rect, .. } = i { Some(*rect) } else { None }).collect();
|
||||
let (left, right) = cells.iter().fold((f32::MAX, 0.0f32), |(l, r), c| (l.min(c.x), r.max(c.x + c.w)));
|
||||
assert!(right > left, "cells placed");
|
||||
assert!(right <= p.body.x + p.body.w + 0.5, "indent {indent} rtl {rtl} {align:?}: right {right} vs column {}", p.body.x + p.body.w);
|
||||
assert!(left >= p.body.x - 0.5, "indent {indent} rtl {rtl} {align:?}: left {left} vs column {}", p.body.x);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hit_and_caret_agree() {
|
||||
crate::test_fonts();
|
||||
|
||||
@@ -3,18 +3,21 @@
|
||||
//! `styles.copyFrom`, `styles.delete`, `styles.rename`), so agents get the same result without
|
||||
//! the dialogs.
|
||||
|
||||
use craft::behavior::{EditEvent, Selection, SelectionChange, item_source::keyed};
|
||||
use craft::behavior::{ColumnWidth, EditEvent, Selection, SelectionChange, item_source::keyed};
|
||||
use craft::host::PickRequest;
|
||||
use craft::ui::choice::Checkbox;
|
||||
use craft::ui::contract::{Bind, CollectionEvent, Props as _, SelectMode, Show as _, ShowCollection as _, ShowContainer as _};
|
||||
use craft::ui::contract::{Bind, CollectionEvent, Props as _, SelectMode, Show as _, ShowCollection as _, ShowContainer as _, request_rename};
|
||||
use craft::ui::dialog::{Dialog, DialogId, DialogResult, DialogStack, StackDialog, dialog_id};
|
||||
use craft::ui::display::Text;
|
||||
use craft::ui::form::Field;
|
||||
use craft::ui::layout_components::Row;
|
||||
use craft::ui::layout::CellAlign;
|
||||
use craft::ui::layout_components::{Grid, Stack};
|
||||
use craft::ui::list::{List, ListRow};
|
||||
use craft::ui::notices::Notice;
|
||||
use craft::ui::patterns::form_dialogs::{FormCx, PathRow};
|
||||
use craft::ui::runtime::env::{Env, Label};
|
||||
use craft::ui::sections::{DialogRole, FooterButton};
|
||||
use craft::ui::style::SurfaceKind;
|
||||
use egui::{Context, Ui};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Value, json};
|
||||
@@ -24,6 +27,15 @@ use super::styles::{action, label};
|
||||
use crate::WordApp;
|
||||
|
||||
const ORGANIZER_KEY: &str = "organizer";
|
||||
/// The Organizer's columns: each takes what it holds, and a list holds at least `LIST_WIDTH` (a fill column takes no more
|
||||
/// than its content in a dialog that sizes to its content, so an empty list was a few pixels wide).
|
||||
const COLUMNS: [ColumnWidth; 3] = [ColumnWidth::Content; 3];
|
||||
/// The least width of a list, in points.
|
||||
const LIST_WIDTH: f32 = 200.0;
|
||||
/// The rows each list shows before it scrolls.
|
||||
const LIST_ROWS: u16 = 12;
|
||||
/// The other file's list has its name above it, so it shows one row fewer to end level with the first.
|
||||
const OTHER_ROWS: u16 = LIST_ROWS - 1;
|
||||
|
||||
/// The Templates and Add-ins dialog's fields.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||
@@ -236,50 +248,69 @@ impl OrganizerDialog {
|
||||
|
||||
fn body(&mut self, ui: &mut Ui) {
|
||||
let reason = browse_reason(ui);
|
||||
Row::new().show(ui, |ui, _| {
|
||||
let mut selection = Selection::single(self.left.clone());
|
||||
let mine = &self.mine;
|
||||
let source = keyed(mine, |st| text_of(st, "id"));
|
||||
let out = List::new(label(tl!("Document")))
|
||||
.select(SelectMode::Single)
|
||||
.selection(Bind::bound(&mut selection))
|
||||
.rename(true)
|
||||
.can_rename(|key: &String| {
|
||||
mine.iter().find(|x| text_of(x, "id") == *key).is_some_and(|x| !x.get("builtIn").and_then(Value::as_bool).unwrap_or(true))
|
||||
})
|
||||
.id_salt("mine")
|
||||
.show_items(ui, &source, &mut |_, icx| {
|
||||
let Some(st) = mine.get(icx.at) else { return ListRow::spacer() };
|
||||
ListRow::new(label(text_of(st, "name"))).lead_text(label(glyph(&text_of(st, "type"))), label("¶"))
|
||||
});
|
||||
for event in out.events {
|
||||
match event {
|
||||
CollectionEvent::Selection { change: SelectionChange::Set(keys), .. } => {
|
||||
if let Some(key) = keys.last() {
|
||||
self.left = key.clone();
|
||||
let mine_id = ui.scope_id().with("organizer_mine");
|
||||
// Three columns as the old dialog had: this document's styles, Copy / Delete / Rename, the other file's styles.
|
||||
Grid::new(&COLUMNS).cells(CellAlign::Top).show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
ui.set_min_width(LIST_WIDTH);
|
||||
let mut selection = Selection::single(self.left.clone());
|
||||
let mine = &self.mine;
|
||||
let source = keyed(mine, |st| text_of(st, "id"));
|
||||
let out = List::new(label(tl!("Document")))
|
||||
.surface(SurfaceKind::Frame)
|
||||
.select(SelectMode::Single)
|
||||
.selection(Bind::bound(&mut selection))
|
||||
.rename(true)
|
||||
.can_rename(|key: &String| {
|
||||
mine.iter().find(|x| text_of(x, "id") == *key).is_some_and(|x| !x.get("builtIn").and_then(Value::as_bool).unwrap_or(true))
|
||||
})
|
||||
.id(mine_id)
|
||||
.min_rows(LIST_ROWS)
|
||||
.max_rows(LIST_ROWS)
|
||||
.show_items(ui, &source, &mut |_, icx| {
|
||||
let Some(st) = mine.get(icx.at) else { return ListRow::spacer() };
|
||||
ListRow::new(label(text_of(st, "name"))).lead_text(label(glyph(&text_of(st, "type"))), label("¶"))
|
||||
});
|
||||
for event in out.events {
|
||||
match event {
|
||||
CollectionEvent::Selection { change: SelectionChange::Set(keys), .. } => {
|
||||
if let Some(key) = keys.last() {
|
||||
self.left = key.clone();
|
||||
}
|
||||
}
|
||||
CollectionEvent::Rename(EditEvent::Commit { after, .. }) => {
|
||||
self.requests.push(Request::Rename { style: after.key, name: after.name });
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
CollectionEvent::Rename(EditEvent::Commit { after, .. }) => {
|
||||
self.requests.push(Request::Rename { style: after.key, name: after.name });
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
if action(ui, "copy", label(tl!("Copy")), !self.right.is_empty(), None) {
|
||||
self.requests.push(Request::Copy);
|
||||
}
|
||||
if action(ui, "delete", label(tl!("Delete")), !self.left_builtin(), None) {
|
||||
self.requests.push(Request::Delete(self.left.clone()));
|
||||
}
|
||||
let name = std::path::Path::new(&self.file).file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_else(|| "—".into());
|
||||
Field::new(label(name)).show(ui, |ui, _| {
|
||||
});
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
if action(ui, "copy", label(tl!("Copy")), !self.right.is_empty(), None) {
|
||||
self.requests.push(Request::Copy);
|
||||
}
|
||||
if action(ui, "delete", label(tl!("Delete")), !self.left_builtin(), None) {
|
||||
self.requests.push(Request::Delete(self.left.clone()));
|
||||
}
|
||||
// The list's own rename field takes the name in place.
|
||||
if action(ui, "rename", label(tl!("Rename…")), !self.left_builtin(), None) {
|
||||
request_rename(ui.ctx(), mine_id, &self.left);
|
||||
}
|
||||
});
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
ui.set_min_width(LIST_WIDTH);
|
||||
let name = std::path::Path::new(&self.file).file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_else(|| "—".into());
|
||||
Text::new(label(name)).show(ui);
|
||||
let mut selection = Selection::single(self.right.clone());
|
||||
let other = &self.other;
|
||||
let source = keyed(other, |(n, _)| n.clone());
|
||||
let out = List::new(label(tl!("Template")))
|
||||
.surface(SurfaceKind::Frame)
|
||||
.select(SelectMode::Single)
|
||||
.selection(Bind::bound(&mut selection))
|
||||
.id_salt("other")
|
||||
.min_rows(OTHER_ROWS)
|
||||
.max_rows(OTHER_ROWS)
|
||||
.show_items(ui, &source, &mut |_, icx| {
|
||||
let Some((n, ty)) = other.get(icx.at) else { return ListRow::spacer() };
|
||||
ListRow::new(label(n)).lead_text(label(glyph(ty)), label("¶"))
|
||||
@@ -291,12 +322,13 @@ impl OrganizerDialog {
|
||||
self.right = key.clone();
|
||||
}
|
||||
}
|
||||
let picked = template_row(label(tl!("Template")), Bind::bound(&mut self.file), reason.clone()).show(ui).picked;
|
||||
if let Some(path) = picked {
|
||||
self.requests.push(Request::Load(path));
|
||||
}
|
||||
});
|
||||
});
|
||||
// The other file's path and Browse stand under both lists, at the dialog's full width.
|
||||
let picked = template_row(label(tl!("Template")), Bind::bound(&mut self.file), reason.clone()).show(ui).picked;
|
||||
if let Some(path) = picked {
|
||||
self.requests.push(Request::Load(path));
|
||||
}
|
||||
if !self.message.is_empty() {
|
||||
Notice::new(craft::theme::variant::Tone::Bad, label(&self.message)).show(ui);
|
||||
}
|
||||
|
||||
@@ -191,11 +191,11 @@ const MARGIN_SIDES: [(&str, &str); 4] = [("top", "Top"), ("left", "Left"), ("bot
|
||||
fn open_cell_margins(app: &mut WordApp, ctx: &Context, parent: Option<DialogId>) -> Option<DialogId> {
|
||||
let margins = cell_margins_pt(app)?;
|
||||
let fields = DialogFields::from_pairs(MARGIN_SIDES.iter().zip(margins).map(|((key, _), v)| (*key, v)));
|
||||
let kind = crate::options::unit_kind(app.session.units());
|
||||
let units = crate::options::lengths(app.session.units());
|
||||
let dialog = HostedParamDialog::new(ctx, "tableCellMargins", fields, move |fields| {
|
||||
let params: Vec<Param> = MARGIN_SIDES
|
||||
.iter()
|
||||
.map(|(key, label)| Param::number(*key, tl!(label).to_string(), 0.0, 1.0, 2).bounds(Some(0.0), Some(144.0)).unit(kind))
|
||||
.map(|(key, label)| Param::number(*key, tl!(label).to_string(), 0.0, units.shown.step(), 2).bounds(Some(0.0), Some(144.0)).length(units))
|
||||
.collect();
|
||||
ParamDialog::command("tableCellMargins", tl!("Cell Margins").to_string(), params).values(Bind::bound(fields)).alt_resets(false)
|
||||
});
|
||||
|
||||
@@ -2283,3 +2283,109 @@ fn modal_dialog_with_open_popup_does_not_shake_on_inside_click_but_shakes_on_out
|
||||
let key2 = chrome::nudge_id(&h.ctx, id2);
|
||||
assert!(h.ctx.data(|d| d.get_temp::<f64>(key2)).is_none(), "reopened dialog starts still");
|
||||
}
|
||||
|
||||
/// #7970: Cell Margins shows the table's points in the interface unit (0.19 cm, not 5.4 cm), and OK without
|
||||
/// an edit leaves the table's margins as they were.
|
||||
#[test]
|
||||
fn cell_margins_dialog_shows_points_in_the_interface_unit_and_ok_changes_nothing() {
|
||||
let mut app = app_with("");
|
||||
let _ = app.run("insert.table", json!({"rows": 1, "cols": 1}));
|
||||
app.session.prefs.units = Some(wordcraft_geom::Unit::Centimeters);
|
||||
let mut h = app_harness(app);
|
||||
h.run_steps(2);
|
||||
let (tp, _, _) = h.state().session.sel.focus.path.cell().unwrap();
|
||||
let margins =
|
||||
|h: &egui_kittest::Harness<'_, WordApp>| h.state().session.doc.table(h.state().session.sel.focus.story, &tp).unwrap().props.cell_margins;
|
||||
let before = margins(&h);
|
||||
let _ = h.state_mut().run("ui.dialog", json!({"name": "tableCellMargins"}));
|
||||
h.run_steps(3);
|
||||
let left = h.get_by_role_and_label(egui::accesskit::Role::SpinButton, "Left").value().unwrap_or_default();
|
||||
let shown: f64 = left.trim_end_matches(|c: char| !c.is_ascii_digit()).replace(',', ".").parse().unwrap_or(f64::NAN);
|
||||
assert!(shown < 1.0, "5.4 pt is about 0.19 cm, not the point count: {left:?}");
|
||||
let id = id_of(h.state(), "tableCellMargins");
|
||||
let ctx = h.ctx.clone();
|
||||
let _ = h.state_mut().dialog_host.confirm_by_id(&ctx, id);
|
||||
h.run_steps(4);
|
||||
assert_eq!(margins(&h), before, "OK without an edit writes no margins");
|
||||
}
|
||||
|
||||
/// #7970: a width typed into Cell Margins in the interface unit reaches the table in points (1 cm is about 28 pt).
|
||||
#[test]
|
||||
fn cell_margins_dialog_converts_a_typed_length_back_to_points() {
|
||||
let mut app = app_with("");
|
||||
let _ = app.run("insert.table", json!({"rows": 1, "cols": 1}));
|
||||
app.session.prefs.units = Some(wordcraft_geom::Unit::Centimeters);
|
||||
let mut h = app_harness(app);
|
||||
h.run_steps(2);
|
||||
let (tp, _, _) = h.state().session.sel.focus.path.cell().unwrap();
|
||||
let _ = h.state_mut().run("ui.dialog", json!({"name": "tableCellMargins"}));
|
||||
h.run_steps(3);
|
||||
h.get_by_role_and_label(egui::accesskit::Role::SpinButton, "Left").click();
|
||||
h.run_steps(3);
|
||||
h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A);
|
||||
h.event(egui::Event::Paste("1".into()));
|
||||
h.run_steps(3);
|
||||
h.key_press(egui::Key::Tab);
|
||||
h.run_steps(3);
|
||||
let id = id_of(h.state(), "tableCellMargins");
|
||||
let ctx = h.ctx.clone();
|
||||
let _ = h.state_mut().dialog_host.confirm_by_id(&ctx, id);
|
||||
h.run_steps(4);
|
||||
let left = h.state().session.doc.table(h.state().session.sel.focus.story, &tp).unwrap().props.cell_margins.map(|m| m[1]);
|
||||
assert!(left.is_some_and(|l| (l - 28.35).abs() < 0.5), "1 cm is about 28.35 pt: {left:?}");
|
||||
}
|
||||
|
||||
/// #7980: the Organizer shows this document's styles and the other file's side by side, with Copy, Delete and
|
||||
/// Rename between them, all inside the dialog.
|
||||
#[test]
|
||||
fn organizer_shows_both_lists_and_its_buttons() {
|
||||
use egui::accesskit::Role;
|
||||
let mut h = app_harness(app_with(""));
|
||||
h.run_steps(2);
|
||||
let _ = h.state_mut().run("ui.dialog", json!({"name": "organizer"}));
|
||||
h.run_steps(4);
|
||||
let rect = |h: &egui_kittest::Harness<'_, WordApp>, role, name: &str| h.get_by_role_and_label(role, name).rect();
|
||||
let mine = rect(&h, Role::List, "Document");
|
||||
let other = rect(&h, Role::List, "Template");
|
||||
assert!(mine.is_positive() && other.is_positive() && mine.right() <= other.left(), "the lists stand side by side: {mine:?} {other:?}");
|
||||
// Each list is wider than the button column between them, empty (no other file) or not.
|
||||
let rename = rect(&h, Role::Button, "Rename…");
|
||||
assert!(mine.width() > rename.width() && other.width() > rename.width(), "the lists are wider than the buttons: {mine:?} {other:?} {rename:?}");
|
||||
// The ribbon has its own Copy: the one that counts stands between the lists.
|
||||
for name in ["Copy", "Delete", "Rename…"] {
|
||||
let between = h
|
||||
.query_all(egui_kittest::kittest::By::new().role(Role::Button).label(name))
|
||||
.any(|b| b.rect().left() >= mine.right() - 1.0 && b.rect().right() <= other.left() + 1.0);
|
||||
assert!(between, "{name} stands between the lists {mine:?} {other:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Part of #7980: the Organizer's two lists have a visible frame, as before the port; without it an empty list is a
|
||||
/// blank patch.
|
||||
#[test]
|
||||
fn the_organizer_lists_are_framed() {
|
||||
use egui::accesskit::Role;
|
||||
fn rects<'a>(shape: &'a egui::Shape, out: &mut Vec<&'a egui::epaint::RectShape>) {
|
||||
match shape {
|
||||
egui::Shape::Vec(inner) => inner.iter().for_each(|s| rects(s, out)),
|
||||
egui::Shape::Rect(r) => out.push(r),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let mut h = app_harness(app_with(""));
|
||||
h.run_steps(2);
|
||||
let _ = h.state_mut().run("ui.dialog", json!({"name": "organizer"}));
|
||||
h.run_steps(4);
|
||||
let mut seen = Vec::new();
|
||||
h.output().shapes.iter().for_each(|c| rects(&c.shape, &mut seen));
|
||||
for label in ["Document", "Template"] {
|
||||
let list = h.get_by_role_and_label(Role::List, label).rect();
|
||||
assert!(
|
||||
seen.iter().any(|r| r.stroke.width > 0.0
|
||||
&& r.stroke.color.a() > 0
|
||||
&& r.rect.contains_rect(list.shrink(2.0))
|
||||
&& list.expand(2.0).contains_rect(r.rect)),
|
||||
"the list {label:?} {list:?} has a border"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ use craft::behavior::{EditEvent, MotionMode, keyed};
|
||||
use craft::ui::buttons::Button;
|
||||
use craft::ui::contract::{Bind, Entry, Props as _, Show, ShowCollection, ShowContainer};
|
||||
use craft::ui::display::{Elide, Shade, Text};
|
||||
use craft::ui::form::{SliderField, SliderFieldLayout};
|
||||
use craft::ui::layout_components::Row;
|
||||
use craft::ui::list::{List, ListRow};
|
||||
use craft::ui::patterns::preferences::{GroupSpec, PageSpec, PrefValue, PreferencesModel, PreferencesPage, RowKind, RowSpec};
|
||||
@@ -303,6 +302,7 @@ impl PreferencesModel for OptionsModel<'_> {
|
||||
use crate::StatusCount;
|
||||
use crate::scroll::ScrollSpeed;
|
||||
use crate::theme::{Animations, Appearance};
|
||||
use wordcraft_engine::speech::{MAX_RATE, MIN_RATE};
|
||||
let app = &*self.app;
|
||||
let s = &self.strings;
|
||||
let prefs = &app.session.prefs;
|
||||
@@ -375,8 +375,7 @@ impl PreferencesModel for OptionsModel<'_> {
|
||||
b("display.spaces", tl!("Spaces"), marks.spaces),
|
||||
b("display.paragraphs", tl!("Paragraph marks"), marks.paragraphs),
|
||||
b("display.hidden", tl!("Hidden text"), marks.hidden),
|
||||
b("display.allMarks", tl!("Show all formatting marks"), app.session.view.marks)
|
||||
.help(tl!("These marks show even when Show/Hide ¶ is off.")),
|
||||
b("display.allMarks", tl!("Show all formatting marks"), app.session.view.marks),
|
||||
],
|
||||
),
|
||||
GroupSpec::new(
|
||||
@@ -405,7 +404,8 @@ impl PreferencesModel for OptionsModel<'_> {
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
)
|
||||
.footnote(tl!("These marks show even when Show/Hide ¶ is off."));
|
||||
|
||||
let proofing = page_of(
|
||||
"proofing",
|
||||
@@ -445,11 +445,7 @@ impl PreferencesModel for OptionsModel<'_> {
|
||||
GroupSpec::new(Some(tl!("Save documents")), {
|
||||
// The browser can't write to the user's files, so AutoSave can't be turned on there (#176).
|
||||
let row = b("save.autosave", tl!("AutoSave documents you have saved in WordCraft"), app.autosave && !browser).enabled(!browser);
|
||||
vec![row.help(if browser {
|
||||
&s.autosave_reason
|
||||
} else {
|
||||
tl!("AutoSave writes your changes to the file a moment after you stop typing.")
|
||||
})]
|
||||
vec![if browser { row.help(&s.autosave_reason) } else { row }]
|
||||
}),
|
||||
// The open document's `file.privacyOptions` (#1062): saved with it, honoured when it is saved.
|
||||
GroupSpec::new(
|
||||
@@ -464,12 +460,12 @@ impl PreferencesModel for OptionsModel<'_> {
|
||||
"save.removeDateTime",
|
||||
tl!("Leave out the date and time of comments and tracked changes when saving"),
|
||||
settings.remove_date_time,
|
||||
)
|
||||
.help(tl!("The document you are editing keeps the names and dates; only the saved file leaves them out.")),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
)
|
||||
.footnote(tl!("AutoSave writes your changes to the file a moment after you stop typing."));
|
||||
|
||||
let language = page_of(
|
||||
"language",
|
||||
@@ -490,7 +486,11 @@ impl PreferencesModel for OptionsModel<'_> {
|
||||
GroupSpec::new(
|
||||
Some(tl!("Dictionaries")),
|
||||
vec![
|
||||
RowSpec::new("language.dictionariesFolder", tl!("Dictionaries folder:"), RowKind::Custom)
|
||||
RowSpec::new(
|
||||
"language.dictionariesFolder",
|
||||
tl!("Dictionaries folder:"),
|
||||
RowKind::Text(prefs.dictionaries_folder.as_deref().unwrap_or("")),
|
||||
)
|
||||
.help(tl!("Hunspell .aff and .dic files here (pl_PL, pt_BR, it_IT, hr_HR, tr_TR) are used before the system's.\nAn installed Language pack is used after this folder.")),
|
||||
custom("language.dictionaryFiles", tl!("Dictionary files")),
|
||||
],
|
||||
@@ -523,7 +523,12 @@ impl PreferencesModel for OptionsModel<'_> {
|
||||
GroupSpec::new(
|
||||
Some(tl!("Read Aloud")),
|
||||
vec![
|
||||
RowSpec::new("accessibility.readAloudSpeed", tl!("Speed"), RowKind::Custom),
|
||||
RowSpec::new(
|
||||
"accessibility.readAloudSpeed",
|
||||
tl!("Speed"),
|
||||
RowKind::float(app.session.read_aloud.rate() as f64, (MIN_RATE as f64)..=(MAX_RATE as f64), 2),
|
||||
)
|
||||
.step(0.05),
|
||||
b("accessibility.skipCitations", tl!("Skip citations & bibliography"), app.session.read_aloud.skip_citations),
|
||||
],
|
||||
),
|
||||
@@ -581,8 +586,12 @@ impl PreferencesModel for OptionsModel<'_> {
|
||||
groups.push(GroupSpec::new(
|
||||
Some(tl!("File locations")),
|
||||
vec![
|
||||
RowSpec::new("advanced.templatesFolder", tl!("User templates:"), RowKind::Custom)
|
||||
.help(tl!("File › New lists the .dotx and .dotm templates here under Personal; Save as Word Template starts here.")),
|
||||
RowSpec::new(
|
||||
"advanced.templatesFolder",
|
||||
tl!("User templates:"),
|
||||
RowKind::Text(prefs.user_templates_folder.as_deref().unwrap_or("")),
|
||||
)
|
||||
.help(tl!("File › New lists the .dotx and .dotm templates here under Personal; Save as Word Template starts here.")),
|
||||
],
|
||||
));
|
||||
}
|
||||
@@ -701,15 +710,6 @@ impl PreferencesModel for OptionsModel<'_> {
|
||||
"general.defaultApp" => default_app_row(self.app, ui),
|
||||
"proofing.autoCorrect" => self.command_button(ui, tl!("AutoCorrect Options"), "tools.autocorrect"),
|
||||
"proofing.customDictionaryFile" => self.custom_dictionary_file(ui),
|
||||
"language.dictionariesFolder" => {
|
||||
let saved = self.app.session.prefs.dictionaries_folder.clone().unwrap_or_default();
|
||||
self.folder_row(ui, key, tl!("Dictionaries folder:"), saved, tl!("Not set: the system's usual places").to_string())
|
||||
}
|
||||
"advanced.templatesFolder" => {
|
||||
let saved = self.app.session.prefs.user_templates_folder.clone().unwrap_or_default();
|
||||
let default = self.app.services.templates_dir.as_ref().map(|d| d.to_string_lossy().into_owned());
|
||||
self.folder_row(ui, key, tl!("User templates:"), saved, default.unwrap_or_else(|| tl!("Not set").to_string()))
|
||||
}
|
||||
"proofing.customDictionary" => self.custom_dictionary(ui),
|
||||
"language.proofingLanguage" => {
|
||||
Text::new(self.strings.proofing_language.clone()).role(TypeRole::Caption).shade(Shade::Faint).show(ui);
|
||||
@@ -724,7 +724,6 @@ impl PreferencesModel for OptionsModel<'_> {
|
||||
dictionary_files(ui);
|
||||
false
|
||||
}
|
||||
"accessibility.readAloudSpeed" => self.read_aloud_speed(ui),
|
||||
"advanced.customizeKeyboard" => self.command_button(ui, tl!("Customize…"), "tools.customizeKeyboard"),
|
||||
"advanced.customizeRibbon" => self.command_button(ui, tl!("Customize…"), "tools.customizeRibbon"),
|
||||
_ => false,
|
||||
@@ -733,6 +732,7 @@ impl PreferencesModel for OptionsModel<'_> {
|
||||
|
||||
fn custom_page(&mut self, ui: &mut Ui, page: &str) -> bool {
|
||||
if page == "agents" {
|
||||
Text::new(tl!("Agents")).role(TypeRole::Heading).show(ui);
|
||||
Text::new(tl!("Every command is available to scripts and AI agents: run `wordcraft-cli mcp` for an MCP server, or start the app with `--control <port>` for the JSON control channel."))
|
||||
.show(ui);
|
||||
}
|
||||
@@ -769,56 +769,6 @@ impl OptionsModel<'_> {
|
||||
clicked
|
||||
}
|
||||
|
||||
/// The Read Aloud speed: a slider with its number, as the player's.
|
||||
fn read_aloud_speed(&mut self, ui: &mut Ui) -> bool {
|
||||
use wordcraft_engine::speech::{MAX_RATE, MIN_RATE};
|
||||
let rate = f64::from(self.app.session.read_aloud.rate());
|
||||
let out = SliderField::new(tl!("Speed"), Bind::given(rate), f64::from(MIN_RATE)..=f64::from(MAX_RATE))
|
||||
.step(0.05)
|
||||
.layout(SliderFieldLayout::Inline)
|
||||
.short(true)
|
||||
.unit(tl!("×"))
|
||||
.show(ui);
|
||||
// Committed, not live, so a drag doesn't restart the sentence on every frame.
|
||||
let committed = out.edit.events.committed().copied();
|
||||
if let Some(v) = committed {
|
||||
self.set("accessibility.readAloudSpeed", PrefValue::Float(v));
|
||||
}
|
||||
committed.is_some()
|
||||
}
|
||||
|
||||
/// A folder setting (v0.19.1's): the saved path or a placeholder, Apply (or Enter) saves the typed path,
|
||||
/// Clear returns to the default. The draft follows the saved path whenever that changes.
|
||||
fn folder_row(&mut self, ui: &mut Ui, key: &str, label: &'static str, saved: String, placeholder: String) -> bool {
|
||||
#[derive(Clone, Default)]
|
||||
struct Draft {
|
||||
text: String,
|
||||
seen: Option<String>,
|
||||
}
|
||||
let mut changed = false;
|
||||
Row::new().id_salt(key).show(ui, |ui, cx| {
|
||||
let draft = &mut cx.keep::<Draft>();
|
||||
if draft.seen.as_deref() != Some(saved.as_str()) {
|
||||
draft.text = saved.clone();
|
||||
draft.seen = Some(saved.clone());
|
||||
}
|
||||
let out = TextField::new(label, Bind::bound(&mut draft.text)).limit(None).placeholder(placeholder.clone()).submits().show(ui);
|
||||
let typed = draft.text.trim().to_string();
|
||||
let differs = typed != saved;
|
||||
let apply = Button::new(tl!("Apply")).enabled(differs).show(ui).clicked() || (out.submitted && differs);
|
||||
let clear = Button::new(tl!("Clear")).enabled(!saved.is_empty()).show(ui).clicked();
|
||||
if apply {
|
||||
self.set(key, PrefValue::Text(typed));
|
||||
changed = true;
|
||||
} else if clear {
|
||||
self.set(key, PrefValue::Text(String::new()));
|
||||
draft.text.clear();
|
||||
changed = true;
|
||||
}
|
||||
});
|
||||
changed
|
||||
}
|
||||
|
||||
fn custom_dictionary_file(&mut self, ui: &mut Ui) -> bool {
|
||||
let saved = self.app.session.prefs.custom_dictionary.clone().unwrap_or_default();
|
||||
let out = TextField::new(tl!("Dictionary file:"), Bind::given(saved)).limit(None).show(ui);
|
||||
|
||||
@@ -454,88 +454,3 @@ fn escape_does_not_commit_the_custom_dictionary_path() {
|
||||
assert_eq!(dictionary_field_text(&h), "", "the field shows the saved (empty) path");
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// #7987: the Read Aloud speed is a slider, not only a number box.
|
||||
#[test]
|
||||
fn read_aloud_speed_is_a_slider() {
|
||||
use egui_kittest::kittest::Queryable;
|
||||
let h = options_harness(app(), system_reducing_motion(false));
|
||||
let _ = h.get_by_role_and_label(egui::accesskit::Role::Slider, "Speed");
|
||||
}
|
||||
|
||||
/// #7987: the Agents page names itself once.
|
||||
#[test]
|
||||
fn agents_page_has_one_heading() {
|
||||
use egui_kittest::kittest::Queryable;
|
||||
let mut a = app();
|
||||
a.run("ui.backstage", json!({"value": true, "page": "options", "pane": "agents"})).unwrap();
|
||||
let mut h = crate::test_harness::builder().build_ui_state(
|
||||
|ui, app: &mut WordApp| {
|
||||
let ctx = ui.ctx().clone();
|
||||
app.logic(&ctx);
|
||||
app.ui(ui);
|
||||
},
|
||||
a,
|
||||
);
|
||||
options_frames(&mut h, 3);
|
||||
use egui_kittest::kittest::NodeT;
|
||||
// The nav entry is a list item; every other node that carries the name is a title.
|
||||
let titles = h.query_all_by_label("Agents").filter(|n| n.accesskit_node().role() != egui::accesskit::Role::ListItem).count();
|
||||
assert_eq!(titles, 2, "the page's group and its title, no second heading");
|
||||
}
|
||||
|
||||
/// #7987: a hint sits under the setting it explains, not in a page footnote at the bottom.
|
||||
#[test]
|
||||
fn display_and_save_hints_sit_under_their_rows() {
|
||||
let mut a = app();
|
||||
let (display, save, privacy) = with_model(&mut a, true, |m| {
|
||||
let pages = m.pages();
|
||||
let help_of = |page: &str, key: &str| {
|
||||
let p = pages.iter().find(|p| p.id == page).expect("page");
|
||||
let r = p.groups.iter().flat_map(|g| g.rows.iter()).find(|r| r.key == key).expect("row");
|
||||
(p.footnote.is_none(), r.help.is_some())
|
||||
};
|
||||
(help_of("display", "display.allMarks"), help_of("save", "save.autosave"), help_of("save", "save.removeDateTime"))
|
||||
});
|
||||
assert_eq!(display, (true, true));
|
||||
assert_eq!(save, (true, true));
|
||||
assert_eq!(privacy, (true, true), "the Privacy hint under its row");
|
||||
}
|
||||
|
||||
/// #7987: a folder setting has Apply and Clear. Typing alone saves nothing, Apply saves the typed path, and Clear
|
||||
/// returns to the default.
|
||||
#[test]
|
||||
fn folder_settings_have_apply_and_clear() {
|
||||
use egui_kittest::kittest::Queryable;
|
||||
let dir = std::env::temp_dir().join(format!("wc-ui-folder-row-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let path = dir.to_string_lossy().into_owned();
|
||||
for (pane, label, saved) in [
|
||||
("advanced", "User templates:", (|a: &WordApp| a.session.prefs.user_templates_folder.clone()) as fn(&WordApp) -> Option<String>),
|
||||
("language", "Dictionaries folder:", |a: &WordApp| a.session.prefs.dictionaries_folder.clone()),
|
||||
] {
|
||||
let mut a = app();
|
||||
a.run("ui.backstage", json!({"value": true, "page": "options", "pane": pane})).unwrap();
|
||||
let mut h = crate::test_harness::builder().build_ui_state(
|
||||
|ui, app: &mut WordApp| {
|
||||
let ctx = ui.ctx().clone();
|
||||
app.logic(&ctx);
|
||||
app.ui(ui);
|
||||
},
|
||||
a,
|
||||
);
|
||||
options_frames(&mut h, 3);
|
||||
h.get_by_role_and_label(egui::accesskit::Role::TextInput, label).focus();
|
||||
options_frames(&mut h, 2);
|
||||
h.get_by_role_and_label(egui::accesskit::Role::TextInput, label).type_text(&path);
|
||||
options_frames(&mut h, 3);
|
||||
assert_eq!(saved(h.state()), None, "{label} typing alone saved");
|
||||
h.get_by_label("Apply").click();
|
||||
options_frames(&mut h, 3);
|
||||
assert_eq!(saved(h.state()).as_deref(), Some(path.as_str()), "{label} Apply");
|
||||
h.get_by_label("Clear").click();
|
||||
options_frames(&mut h, 3);
|
||||
assert_eq!(saved(h.state()), None, "{label} Clear");
|
||||
}
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user