mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Merge pull request #9149 from dotCooCoo/fix/reset-preferences-interface-settings
Preferences: Reset Preferences resets Smart Guides, Snap to Grid and the Contextual Task Bar
This commit is contained in:
13 files changed
+495
-9
No files matched your search
@@ -710,6 +710,12 @@ impl Prefs {
|
||||
}
|
||||
|
||||
impl Session {
|
||||
/// Take the categories `prefs.reset` reset since the last call, each once, with `None` for a
|
||||
/// reset of every category. A frontend resets the settings it keeps itself in them.
|
||||
pub fn take_prefs_resets(&mut self) -> Vec<Option<&'static str>> {
|
||||
std::mem::take(&mut self.prefs_resets)
|
||||
}
|
||||
|
||||
/// Replace the preferences and push the ones with engine-side consumers into open documents
|
||||
/// and the renderer (grid, history depth, render threads).
|
||||
pub fn apply_prefs(&mut self, mut p: Prefs) {
|
||||
@@ -817,7 +823,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
always,
|
||||
set
|
||||
),
|
||||
cmd!(query "prefs.reset", "Reset Preferences", [], None, "{category?} reset one category (or everything) to defaults", always, reset),
|
||||
cmd!(query "prefs.reset", "Reset Preferences", [], None, "{category?: string} reset one category (or everything, with category left out or null) to defaults; an unknown category or one that is not a string is an error", always, reset),
|
||||
cmd!(query "prefs.list", "List Preferences", [], None, "{} → [{key, category, section, label, kind, value, …}] every preference; under automation read roots a folder preference's value outside them is null", always, list),
|
||||
cmd!(
|
||||
query "prefs.export",
|
||||
@@ -1000,15 +1006,17 @@ fn set(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
|
||||
fn reset(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let cat = str_param(p, "category");
|
||||
if let Some(c) = cat
|
||||
&& !PREF_CATEGORIES.iter().any(|x| x.eq_ignore_ascii_case(c))
|
||||
{
|
||||
return Err(bad("prefs.reset", format!("unknown category `{c}`")));
|
||||
}
|
||||
let cat = text_param(p, "category", "prefs.reset")?;
|
||||
let known = |c: &str| {
|
||||
PREF_CATEGORIES.iter().copied().find(|x| x.eq_ignore_ascii_case(c)).ok_or_else(|| bad("prefs.reset", format!("unknown category `{c}`")))
|
||||
};
|
||||
let category = cat.map(known).transpose()?;
|
||||
let mut next = s.prefs.clone();
|
||||
next.reset(cat);
|
||||
s.apply_prefs(next);
|
||||
if !s.prefs_resets.contains(&category) {
|
||||
s.prefs_resets.push(category);
|
||||
}
|
||||
Ok(json!({ "prefs": shown_prefs(&s.prefs) }))
|
||||
}
|
||||
|
||||
|
||||
@@ -136,6 +136,8 @@ pub struct Session {
|
||||
/// Set when a command that draws a shape was journaled outside saved steps
|
||||
/// ([`Session::take_shape_drawn`]).
|
||||
shape_drawn: bool,
|
||||
/// The categories `prefs.reset` reset, `None` for every one ([`Session::take_prefs_resets`]).
|
||||
prefs_resets: Vec<Option<&'static str>>,
|
||||
/// Set when the active tool panicked (see [`guard`]); reported by the next tool event.
|
||||
tool_panic: Option<EngineError>,
|
||||
/// How many times switching or closing documents, or replacing the active one, has started the
|
||||
|
||||
@@ -78,6 +78,7 @@ impl Session {
|
||||
depth: 0,
|
||||
replaying: false,
|
||||
shape_drawn: false,
|
||||
prefs_resets: Vec::new(),
|
||||
tool_panic: None,
|
||||
tool_resets: 0,
|
||||
tool_set_since_reset: false,
|
||||
|
||||
@@ -216,6 +216,24 @@ fn reset_category_and_all() {
|
||||
assert!(s.execute("prefs.reset", &json!({"category": "Bogus"})).is_err());
|
||||
}
|
||||
|
||||
/// `prefs.reset` records each category it reset once, `None` for every category, and a failed
|
||||
/// reset records nothing.
|
||||
#[test]
|
||||
fn prefs_reset_records_the_categories_it_reset() {
|
||||
let mut s = Session::new();
|
||||
assert!(s.take_prefs_resets().is_empty());
|
||||
s.execute("prefs.reset", &json!({"category": "general"})).unwrap();
|
||||
s.execute("prefs.reset", &json!({"category": "General"})).unwrap();
|
||||
assert_eq!(s.take_prefs_resets(), vec![Some("General")]);
|
||||
assert!(s.take_prefs_resets().is_empty(), "taking clears the list");
|
||||
assert!(s.execute("prefs.reset", &json!({"category": "Bogus"})).is_err());
|
||||
assert!(s.execute("prefs.reset", &json!({"category": 5})).is_err());
|
||||
assert!(s.take_prefs_resets().is_empty(), "a failed reset records nothing");
|
||||
s.execute("prefs.reset", &json!({})).unwrap();
|
||||
s.execute("prefs.reset", &json!({"category": "Type"})).unwrap();
|
||||
assert_eq!(s.take_prefs_resets(), vec![None, Some("Type")]);
|
||||
}
|
||||
|
||||
/// A rectangle made into a guide path; nothing is selected after.
|
||||
fn guide_path(s: &mut Session, x: f64) -> NodeId {
|
||||
let id = square(s, x, 0.0);
|
||||
|
||||
@@ -544,6 +544,9 @@ impl VectorcraftApp {
|
||||
if let Some(wait) = crate::panels::actions::tick_playback(self, now) {
|
||||
ctx.request_repaint_after(std::time::Duration::from_secs_f64(wait));
|
||||
}
|
||||
// A `prefs.reset` run in this frame outside `Self::run` (a script's, say): the pass that follows draws the
|
||||
// reset rows.
|
||||
prefs_dialog::apply_prefs_resets(self);
|
||||
}
|
||||
|
||||
/// The canvas panel's body: the document tabs, then the canvas (a pane for each document while
|
||||
|
||||
@@ -77,7 +77,10 @@ impl VectorcraftApp {
|
||||
pub fn run(&mut self, id: &str, params: Value) -> Result<Value, String> {
|
||||
self.beacon.command(id);
|
||||
let touch_workspace = self.session.prefs.touch_workspace;
|
||||
// A `prefs.reset` that ran straight on the session applies before this command can switch workspaces.
|
||||
crate::prefs_dialog::apply_prefs_resets(self);
|
||||
let result = self.run_now(id, params);
|
||||
crate::prefs_dialog::apply_prefs_resets(self);
|
||||
if id == "prefs.import" && result.is_ok() {
|
||||
crate::prefs_dialog::imported(self, touch_workspace);
|
||||
}
|
||||
|
||||
@@ -54,6 +54,12 @@ pub(crate) fn reset(app: &mut VectorcraftApp) {
|
||||
app.original_editor.choice = Choice::default();
|
||||
}
|
||||
|
||||
/// `prefs.reset`: the saved choice goes back to the default, and the next Preferences shows it.
|
||||
pub(crate) fn reset_saved(app: &mut VectorcraftApp) {
|
||||
app.ui.original_editor = Choice::default();
|
||||
reset(app);
|
||||
}
|
||||
|
||||
pub(crate) fn cancel(app: &mut VectorcraftApp) {
|
||||
open(app);
|
||||
}
|
||||
@@ -262,6 +268,32 @@ mod tests {
|
||||
assert!(app.ui.original_editor.path.is_none());
|
||||
}
|
||||
|
||||
/// `prefs.reset` of every category or of File Handling, alone or as a batch step, resets the
|
||||
/// saved choice; a reset of another category keeps it.
|
||||
#[test]
|
||||
fn prefs_reset_resets_the_saved_choice_with_file_handling() {
|
||||
let (mut app, picker) = app();
|
||||
prefs_dialog::cancel(&mut app);
|
||||
let mine = editor("prefs-reset");
|
||||
let chosen = |app: &mut VectorcraftApp| {
|
||||
prefs_dialog::open(app, Some("File Handling"));
|
||||
choose(app, &picker, Some(&mine)).unwrap();
|
||||
prefs_dialog::confirm(app).unwrap();
|
||||
assert!(app.ui.original_editor.path.is_some());
|
||||
};
|
||||
chosen(&mut app);
|
||||
app.run("prefs.reset", json!({"category": "General"})).unwrap();
|
||||
assert!(app.ui.original_editor.path.is_some(), "General keeps the choice");
|
||||
app.run("prefs.reset", json!({"category": "File Handling"})).unwrap();
|
||||
assert!(app.ui.original_editor.path.is_none(), "File Handling resets it");
|
||||
chosen(&mut app);
|
||||
app.run("file.new", json!({"width": 100, "height": 100})).unwrap();
|
||||
app.run("command.batch", json!({"commands": [{"command": "prefs.reset", "params": {}}]})).unwrap();
|
||||
assert!(app.ui.original_editor.path.is_none(), "every category, as a batch step");
|
||||
prefs_dialog::open(&mut app, Some("File Handling"));
|
||||
assert!(app.original_editor.choice.path.is_none(), "Preferences shows the default");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn original_editor_routing_and_errors() {
|
||||
|
||||
@@ -324,5 +324,69 @@ pub(crate) fn imported(app: &mut VectorcraftApp, touch_workspace: bool) {
|
||||
}
|
||||
}
|
||||
|
||||
/// The default of each UI-only row ([`UI_FIELDS`]), by key. Enable Contextual Task Bar takes the value the current
|
||||
/// workspace was saved with, so a reset leaves the workspace as it was saved.
|
||||
fn default_ui_fields(ui: &crate::UiState) -> [(&'static str, bool); 3] {
|
||||
let first = crate::UiState::default();
|
||||
let task_bar = crate::workspaces::saved_task_bar(ui);
|
||||
[("__smartGuides", first.view.smart_guides), ("__snapToGrid", first.view.snap_to_grid), ("__taskBar", task_bar)]
|
||||
}
|
||||
|
||||
/// After `prefs.reset`, alone or as a batch step, of every category or of one: the UI-only rows ([`UI_FIELDS`]) and
|
||||
/// the Edit Original app of the categories it reset take their defaults too, and an open Preferences window shows
|
||||
/// the reset values. Returns whether any reset was pending.
|
||||
pub(crate) fn apply_prefs_resets(app: &mut VectorcraftApp) -> bool {
|
||||
let mut w = app.prefs.take();
|
||||
let any = apply_prefs_resets_to(app, w.as_deref_mut());
|
||||
if app.prefs.is_none() {
|
||||
app.prefs = w;
|
||||
}
|
||||
any
|
||||
}
|
||||
|
||||
/// [`apply_prefs_resets`] with the open window `w`, which is out of `app` while it draws or applies.
|
||||
fn apply_prefs_resets_to(app: &mut VectorcraftApp, mut w: Option<&mut PrefsWindow>) -> bool {
|
||||
let resets = app.session.take_prefs_resets();
|
||||
if resets.is_empty() {
|
||||
return false;
|
||||
}
|
||||
let in_reset = |category: &str| resets.iter().any(|r| r.is_none_or(|c| c == category));
|
||||
for (key, value) in default_ui_fields(&app.ui) {
|
||||
if !UI_FIELDS.iter().any(|&(k, c, _)| k == key && in_reset(c)) {
|
||||
continue;
|
||||
}
|
||||
match key {
|
||||
"__smartGuides" => app.ui.view.smart_guides = value,
|
||||
"__snapToGrid" => app.ui.view.snap_to_grid = value,
|
||||
_ => app.ui.task_bar = value,
|
||||
}
|
||||
// The window shows the reset row, so OK keeps it.
|
||||
if let Some(w) = w.as_deref_mut() {
|
||||
w.draft.set(key, &value);
|
||||
}
|
||||
}
|
||||
// And the reset preferences, the groups with a reset of every category; Units ▸ General then leaves the open
|
||||
// document's units alone on OK.
|
||||
if let Some(w) = w {
|
||||
let every = resets.contains(&None);
|
||||
let prefs = app.session.prefs.to_json();
|
||||
for (k, v) in prefs.as_object().into_iter().flatten() {
|
||||
let reset = spec(k).map_or(every && PREF_GROUPS.contains(&k.as_str()), |s| in_reset(s.category));
|
||||
if reset && w.draft.get::<Value>(k).is_some() {
|
||||
w.draft.set(k, v);
|
||||
if k == "unitsGeneral" {
|
||||
w.reset_units = v.as_str().map(str::to_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
w.sync_strings();
|
||||
}
|
||||
// The Edit Original row shows the app's Edit Original choice.
|
||||
if spec("editOriginalSystemDefaults").is_some_and(|s| in_reset(s.category)) {
|
||||
crate::original_editor::reset_saved(app);
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@@ -269,14 +269,25 @@ impl Live<'_> {
|
||||
page
|
||||
}
|
||||
|
||||
/// Sets every key of the draft to its default, as the answered Reset question does.
|
||||
/// Sets every key of the draft to its default, the UI-only rows ([`UI_FIELDS`]) included, as the answered
|
||||
/// Reset question does.
|
||||
fn reset_all(&mut self) {
|
||||
let keys: Vec<String> =
|
||||
Prefs::default().to_json().as_object().into_iter().flatten().map(|(k, _)| k.clone()).filter(|k| super::is_known(k)).collect();
|
||||
self.w.reset_keys(keys.iter().map(String::as_str));
|
||||
self.reset_ui_rows(|_| true);
|
||||
crate::original_editor::reset(self.app);
|
||||
}
|
||||
|
||||
/// Sets the UI-only rows of the categories `reset` names to their defaults.
|
||||
fn reset_ui_rows(&mut self, reset: impl Fn(&str) -> bool) {
|
||||
for (key, value) in super::default_ui_fields(&self.app.ui) {
|
||||
if UI_FIELDS.iter().any(|&(k, c, _)| k == key && reset(c)) {
|
||||
self.w.draft.set(key, &value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The answers of the dialogs the window opened: the Reset question and the colour picker.
|
||||
pub(super) fn take_answers(&mut self) {
|
||||
if let Some(id) = self.w.reset_asked
|
||||
@@ -388,6 +399,11 @@ impl PreferencesModel for Live<'_> {
|
||||
fn reset_page(&mut self, page: &str) {
|
||||
let keys: Vec<&str> = PREF_SPECS.iter().filter(|s| s.category == page).map(|s| s.key).collect();
|
||||
self.w.reset_keys(keys);
|
||||
self.reset_ui_rows(|c| c == page);
|
||||
// The Edit Original row of its page.
|
||||
if spec("editOriginalSystemDefaults").is_some_and(|s| s.category == page) {
|
||||
crate::original_editor::reset(self.app);
|
||||
}
|
||||
}
|
||||
|
||||
fn nested(&mut self, ui: &mut egui::Ui) {
|
||||
@@ -406,20 +422,33 @@ impl PreferencesDraft for Live<'_> {
|
||||
}
|
||||
|
||||
fn apply(&mut self) -> Result<(), String> {
|
||||
// A `prefs.reset` run since the last frame shows in the draft before OK reads it.
|
||||
super::apply_prefs_resets_to(self.app, Some(&mut *self.w));
|
||||
let values: Map<String, Value> =
|
||||
self.w.draft.to::<Map<String, Value>>().unwrap_or_default().into_iter().filter(|(k, _)| !k.starts_with("__")).collect();
|
||||
let touch_ws = values.get("touchWorkspace").and_then(Value::as_bool);
|
||||
let document_units = self.w.reset_units.as_deref().is_none_or(|u| values.get("unitsGeneral").and_then(Value::as_str) != Some(u));
|
||||
// A refused folder, typed or picked, comes back here as the engine's message.
|
||||
self.app.run("prefs.set", json!({ "values": values, "documentUnits": document_units }))?;
|
||||
// When OK enters the Touch workspace, the task bar is set before the switch, so it goes to the workspace being
|
||||
// left; otherwise after it, so a return from Touch gives it to the workspace returned to.
|
||||
let before_switch = touch_ws.is_some() && crate::workspaces::enters_touch(self.app, self.app.touch_screen);
|
||||
if before_switch && let Some(on) = self.w.draft.get::<bool>("__taskBar") {
|
||||
self.app.ui.task_bar = on;
|
||||
}
|
||||
let was_touch = crate::workspaces::is_current(&self.app.ui, crate::workspaces::TOUCH);
|
||||
if touch_ws.is_some() {
|
||||
crate::workspaces::sync_touch_workspace(self.app, self.app.touch_screen);
|
||||
}
|
||||
// When OK leaves Touch, the workspace returned to takes the row only when it changed since the window opened or
|
||||
// last applied; otherwise it keeps its own.
|
||||
let left_touch = was_touch && !crate::workspaces::is_current(&self.app.ui, crate::workspaces::TOUCH);
|
||||
let task_bar_row = self.w.draft.get::<bool>("__taskBar").filter(|on| !left_touch || self.w.opened.get::<bool>("__taskBar") != Some(*on));
|
||||
let flag = |key: &str, now: bool| self.w.draft.get::<bool>(key).unwrap_or(now);
|
||||
let (smart_guides, snap_to_grid, task_bar) = (
|
||||
flag("__smartGuides", self.app.ui.view.smart_guides),
|
||||
flag("__snapToGrid", self.app.ui.view.snap_to_grid),
|
||||
flag("__taskBar", self.app.ui.task_bar),
|
||||
if before_switch { self.app.ui.task_bar } else { task_bar_row.unwrap_or(self.app.ui.task_bar) },
|
||||
);
|
||||
self.app.ui.view.smart_guides = smart_guides;
|
||||
self.app.ui.view.snap_to_grid = snap_to_grid;
|
||||
@@ -427,6 +456,9 @@ impl PreferencesDraft for Live<'_> {
|
||||
crate::original_editor::commit(self.app);
|
||||
super::snapshot(self.app);
|
||||
self.app.prefs_changed = true;
|
||||
// The row shows the task bar in use: after OK enters Touch, that is Touch's, not the value the workspace left
|
||||
// took, so a later Apply does not give the workspace left's value to Touch.
|
||||
self.w.draft.set("__taskBar", &self.app.ui.task_bar);
|
||||
self.w.opened = self.w.draft.clone();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -298,6 +298,291 @@ fn reset_preferences_keeps_an_edit_of_general_units() {
|
||||
assert_eq!(b.session.prefs.units_general, Prefs::default().units_general);
|
||||
}
|
||||
|
||||
/// Smart Guides, Snap to Grid and Enable Contextual Task Bar, the UI-only rows.
|
||||
fn ui_rows(a: &VectorcraftApp) -> (bool, bool, bool) {
|
||||
(a.ui.view.smart_guides, a.ui.view.snap_to_grid, a.ui.task_bar)
|
||||
}
|
||||
|
||||
fn set_ui_rows(a: &mut VectorcraftApp, rows: (bool, bool, bool)) {
|
||||
(a.ui.view.smart_guides, a.ui.view.snap_to_grid, a.ui.task_bar) = rows;
|
||||
}
|
||||
|
||||
/// The Contextual Task Bar workspace `name` was left with.
|
||||
fn left_task_bar(a: &VectorcraftApp, name: &str) -> bool {
|
||||
let id = &crate::workspaces::find(&a.ui, name).expect("a workspace").id;
|
||||
a.ui.workspaces.edited.get(id).expect("left").task_bar
|
||||
}
|
||||
|
||||
/// Reset Preferences returns every UI-only row (Smart Guides, Snap to Grid, Enable Contextual Task Bar) to its
|
||||
/// default in the draft, the value a new app shows. OK applies them; Cancel keeps the values in use.
|
||||
#[test]
|
||||
fn reset_preferences_resets_the_ui_only_rows() {
|
||||
let default = ui_rows(&app());
|
||||
let changed = (!default.0, !default.1, !default.2);
|
||||
let reset_changed = |a: &mut VectorcraftApp| {
|
||||
set_ui_rows(a, changed);
|
||||
open(a, Some("General"));
|
||||
reset_preferences(a, PromptChoice::Proceed);
|
||||
};
|
||||
let mut a = app();
|
||||
reset_changed(&mut a);
|
||||
assert_eq!(
|
||||
(field(&a, "__smartGuides"), field(&a, "__snapToGrid"), field(&a, "__taskBar")),
|
||||
(json!(default.0), json!(default.1), json!(default.2))
|
||||
);
|
||||
assert_eq!(ui_rows(&a), changed, "nothing applied before OK");
|
||||
confirm(&mut a).unwrap();
|
||||
assert_eq!(ui_rows(&a), default, "OK applies the defaults");
|
||||
|
||||
let mut b = app();
|
||||
reset_changed(&mut b);
|
||||
cancel(&mut b);
|
||||
assert!(!is_open(&b));
|
||||
assert_eq!(ui_rows(&b), changed, "Cancel keeps the values in use");
|
||||
}
|
||||
|
||||
/// A page's own reset also resets the UI-only row of that page, and only that one.
|
||||
#[test]
|
||||
fn a_page_reset_resets_the_ui_only_row_of_the_page() {
|
||||
let mut a = app();
|
||||
let default = ui_rows(&a);
|
||||
set_ui_rows(&mut a, (!default.0, !default.1, !default.2));
|
||||
// The saved Edit Original choice has no setter outside its module; the UI state's saved form sets it.
|
||||
let chosen = json!({"path": "editor"});
|
||||
let editor = |a: &VectorcraftApp| serde_json::to_value(&a.ui.original_editor).unwrap_or_default();
|
||||
a.ui.original_editor = serde_json::from_value(chosen.clone()).unwrap();
|
||||
let reset_page = |a: &mut VectorcraftApp, page: &str| {
|
||||
open(a, Some(page));
|
||||
let mut w = a.prefs.take().expect("Preferences is open");
|
||||
model::Live { app: &mut *a, w: &mut w }.reset_page(page);
|
||||
a.prefs = Some(w);
|
||||
};
|
||||
reset_page(&mut a, "General");
|
||||
assert_eq!(field(&a, "__taskBar"), json!(default.2), "General: Enable Contextual Task Bar");
|
||||
assert_eq!((field(&a, "__smartGuides"), field(&a, "__snapToGrid")), (json!(!default.0), json!(!default.1)), "the other pages' rows");
|
||||
confirm(&mut a).unwrap();
|
||||
assert_eq!(editor(&a), chosen, "General keeps the Edit Original choice");
|
||||
reset_page(&mut a, "File Handling");
|
||||
confirm(&mut a).unwrap();
|
||||
assert_eq!(editor(&a)["path"], Value::Null, "File Handling resets the Edit Original choice");
|
||||
}
|
||||
|
||||
/// `prefs.reset` (the Command Palette's Reset Preferences) also returns the UI-only rows to their defaults, as a
|
||||
/// batch step too; with a category, only that category's rows; with an unknown or malformed category, none.
|
||||
#[test]
|
||||
fn prefs_reset_resets_the_ui_only_rows_of_its_category() {
|
||||
let default = ui_rows(&app());
|
||||
let changed = (!default.0, !default.1, !default.2);
|
||||
let mut a = app();
|
||||
a.run("file.new", json!({"width": 400, "height": 400})).unwrap();
|
||||
set_ui_rows(&mut a, changed);
|
||||
a.run("prefs.set", json!({"key": "keyboardIncrement", "value": 7})).unwrap();
|
||||
for bad in [json!("Nowhere"), json!(["General"]), json!(5)] {
|
||||
assert!(a.run("prefs.reset", json!({"category": bad})).is_err(), "{bad}");
|
||||
assert_eq!(ui_rows(&a), changed, "{bad}: an unknown or malformed category resets nothing");
|
||||
assert_eq!(a.session.prefs.keyboard_increment, 7.0, "{bad}: the preferences are kept");
|
||||
}
|
||||
a.run("prefs.reset", json!({"category": "general"})).unwrap();
|
||||
assert_eq!(ui_rows(&a), (changed.0, changed.1, default.2), "General: Enable Contextual Task Bar only");
|
||||
a.run("command.batch", json!({"commands": [{"command": "prefs.reset", "params": {"category": "Guides & Grid"}}]})).unwrap();
|
||||
assert_eq!(ui_rows(&a), (changed.0, default.1, default.2), "Guides & Grid, as a batch step: Snap to Grid only");
|
||||
a.run("prefs.reset", json!({"category": "Smart Guides"})).unwrap();
|
||||
assert_eq!(ui_rows(&a), default, "Smart Guides: Smart Guides");
|
||||
set_ui_rows(&mut a, changed);
|
||||
a.run("prefs.reset", json!({})).unwrap();
|
||||
assert_eq!(ui_rows(&a), default, "every category");
|
||||
}
|
||||
|
||||
/// A `prefs.reset` run while Preferences is open shows the reset values in the draft, for the categories it reset,
|
||||
/// so OK keeps the reset; rows of other categories keep the draft's values.
|
||||
#[test]
|
||||
fn prefs_reset_while_preferences_is_open_shows_the_reset_values() {
|
||||
let fresh = app();
|
||||
let default = ui_rows(&fresh);
|
||||
let mut a = app();
|
||||
set_ui_rows(&mut a, (!default.0, !default.1, !default.2));
|
||||
a.run("prefs.set", json!({"key": "keyboardIncrement", "value": 7})).unwrap();
|
||||
open(&mut a, Some("General"));
|
||||
a.run("prefs.reset", json!({"category": "General"})).unwrap();
|
||||
assert_eq!(field(&a, "__taskBar"), json!(default.2), "the window shows the reset row");
|
||||
assert_eq!(field(&a, "__smartGuides"), json!(!default.0), "a row of another category keeps its value");
|
||||
confirm(&mut a).unwrap();
|
||||
assert_eq!(ui_rows(&a), (!default.0, !default.1, default.2), "OK keeps the reset");
|
||||
assert_eq!(a.session.prefs.keyboard_increment, fresh.session.prefs.keyboard_increment, "OK keeps the reset preference");
|
||||
|
||||
// Every category, the preference groups included.
|
||||
let group = fresh.session.prefs.to_json()["pixelSnap"].clone();
|
||||
let mut changed = group.clone();
|
||||
let flag = changed.as_object_mut().and_then(|o| o.values_mut().find(|v| v.is_boolean())).expect("a pixelSnap option is a boolean");
|
||||
*flag = json!(!flag.as_bool().unwrap_or_default());
|
||||
a.run("prefs.set", json!({"key": "keyboardIncrement", "value": 7})).unwrap();
|
||||
a.run("prefs.set", json!({"key": "pixelSnap", "value": changed})).unwrap();
|
||||
open(&mut a, Some("General"));
|
||||
assert_eq!(field(&a, "pixelSnap"), changed);
|
||||
a.run("prefs.reset", json!({})).unwrap();
|
||||
confirm(&mut a).unwrap();
|
||||
assert_eq!(ui_rows(&a), default, "every category");
|
||||
assert_eq!(a.session.prefs.keyboard_increment, fresh.session.prefs.keyboard_increment);
|
||||
assert_eq!(a.session.prefs.to_json()["pixelSnap"], group, "OK keeps the reset group");
|
||||
|
||||
// Run straight on the session, with OK before the next frame.
|
||||
a.run("prefs.set", json!({"key": "keyboardIncrement", "value": 7})).unwrap();
|
||||
open(&mut a, Some("General"));
|
||||
a.session.execute("prefs.reset", &json!({"category": "General"})).unwrap();
|
||||
confirm(&mut a).unwrap();
|
||||
assert_eq!(a.session.prefs.keyboard_increment, fresh.session.prefs.keyboard_increment, "OK keeps a reset outside run");
|
||||
}
|
||||
|
||||
/// Reset Preferences and `prefs.reset` give Enable Contextual Task Bar the value the current workspace was saved
|
||||
/// with, which for a workspace saved with the bar off differs from the default.
|
||||
#[test]
|
||||
fn reset_preferences_gives_the_task_bar_the_workspaces_value() {
|
||||
let off = crate::workspaces::builtins().into_iter().find(|w| !w.record.task_bar).expect("a workspace saved with the bar off");
|
||||
let in_workspace = |a: &mut VectorcraftApp| {
|
||||
crate::workspaces::switch(a, off.name).unwrap();
|
||||
assert!(!a.ui.task_bar, "{} starts with the bar off", off.name);
|
||||
a.ui.task_bar = true;
|
||||
};
|
||||
let mut a = app();
|
||||
in_workspace(&mut a);
|
||||
open(&mut a, Some("General"));
|
||||
reset_preferences(&mut a, PromptChoice::Proceed);
|
||||
assert_eq!(field(&a, "__taskBar"), json!(false), "the draft shows the workspace's value");
|
||||
confirm(&mut a).unwrap();
|
||||
assert!(!a.ui.task_bar, "OK applies the workspace's value");
|
||||
|
||||
let mut b = app();
|
||||
in_workspace(&mut b);
|
||||
b.run("prefs.reset", json!({"category": "General"})).unwrap();
|
||||
assert!(!b.ui.task_bar, "prefs.reset gives the workspace's value");
|
||||
let mut c = app();
|
||||
assert!(c.ui.task_bar, "the default workspace starts with the bar on");
|
||||
c.ui.task_bar = false;
|
||||
c.run("prefs.reset", json!({})).unwrap();
|
||||
assert!(c.ui.task_bar, "the default workspace's value");
|
||||
}
|
||||
|
||||
/// On a touch screen, OK after Reset Preferences turns Enable Touch Workspace back on: the reset task bar goes to
|
||||
/// the workspace left, and Touch keeps its own. With Touch entered automatically while Preferences was open,
|
||||
/// clearing Enable Touch Workspace gives the row to the workspace returned to.
|
||||
#[test]
|
||||
fn ok_sets_the_task_bar_in_the_workspace_outside_touch() {
|
||||
use crate::workspaces::{TOUCH, is_current, switch, sync_touch_workspace};
|
||||
let mut a = app();
|
||||
a.touch_screen = true;
|
||||
a.run("prefs.set", json!({"key": "touchWorkspace", "value": false})).unwrap();
|
||||
switch(&mut a, "Essentials Classic").unwrap();
|
||||
a.ui.task_bar = true;
|
||||
open(&mut a, Some("General"));
|
||||
reset_preferences(&mut a, PromptChoice::Proceed);
|
||||
assert_eq!(field(&a, "touchWorkspace"), json!(true), "the reset turns it on");
|
||||
confirm(&mut a).unwrap();
|
||||
assert!(is_current(&a.ui, TOUCH));
|
||||
assert!(a.ui.task_bar, "Touch keeps its own task bar");
|
||||
assert!(!left_task_bar(&a, "Essentials Classic"), "the workspace left takes the reset value");
|
||||
|
||||
let mut b = app();
|
||||
b.run("prefs.set", json!({"key": "touchWorkspace", "value": true})).unwrap();
|
||||
switch(&mut b, "Essentials Classic").unwrap();
|
||||
open(&mut b, Some("General"));
|
||||
b.touch_screen = true;
|
||||
sync_touch_workspace(&mut b, true);
|
||||
assert!(is_current(&b.ui, TOUCH));
|
||||
set_field(&mut b, "touchWorkspace", json!(false)).unwrap();
|
||||
confirm(&mut b).unwrap();
|
||||
assert!(is_current(&b.ui, "Essentials Classic"));
|
||||
assert!(!b.ui.task_bar, "the workspace returned to takes the row");
|
||||
assert!(left_task_bar(&b, TOUCH), "Touch keeps its own task bar");
|
||||
}
|
||||
|
||||
/// After an Apply that enters Touch, the task bar row shows Touch's task bar: a later Apply that leaves the row
|
||||
/// unedited keeps it, and an edit or a reset of the row reaches it. Leaving Touch with the row unedited gives the
|
||||
/// workspace returned to the value it left with.
|
||||
#[test]
|
||||
fn apply_after_entering_touch_keeps_touchs_task_bar() {
|
||||
use crate::workspaces::{TOUCH, is_current, switch};
|
||||
use craft::ui::patterns::preferences::PreferencesDraft as _;
|
||||
let apply = |a: &mut VectorcraftApp| {
|
||||
let mut w = a.prefs.take().expect("Preferences is open");
|
||||
let r = model::Live { app: &mut *a, w: &mut w }.apply();
|
||||
a.prefs = Some(w);
|
||||
r.unwrap();
|
||||
};
|
||||
let mut a = app();
|
||||
a.touch_screen = true;
|
||||
a.run("prefs.set", json!({"key": "touchWorkspace", "value": false})).unwrap();
|
||||
switch(&mut a, "Essentials Classic").unwrap();
|
||||
a.ui.task_bar = true;
|
||||
open(&mut a, Some("General"));
|
||||
reset_preferences(&mut a, PromptChoice::Proceed);
|
||||
assert_eq!(field(&a, "__taskBar"), json!(false), "the reset row differs from Touch's task bar");
|
||||
apply(&mut a);
|
||||
assert!(is_current(&a.ui, TOUCH));
|
||||
assert!(a.ui.task_bar, "Touch keeps its own task bar");
|
||||
set_field(&mut a, "keyboardIncrement", json!(9)).unwrap();
|
||||
apply(&mut a);
|
||||
assert!(is_current(&a.ui, TOUCH));
|
||||
assert!(a.ui.task_bar, "an Apply without a task bar edit keeps Touch's task bar");
|
||||
assert_eq!(field(&a, "__taskBar"), json!(true), "the row shows Touch's task bar");
|
||||
set_field(&mut a, "__taskBar", json!(false)).unwrap();
|
||||
apply(&mut a);
|
||||
assert!(!a.ui.task_bar, "an edit to the row reaches Touch");
|
||||
|
||||
// Reset Preferences in Touch gives Touch its saved value, the value the row showed before the edit.
|
||||
reset_preferences(&mut a, PromptChoice::Proceed);
|
||||
apply(&mut a);
|
||||
assert!(is_current(&a.ui, TOUCH));
|
||||
assert!(a.ui.task_bar, "the reset reaches Touch");
|
||||
|
||||
// Leaving Touch with the row unedited: the workspace returned to keeps the value it left with.
|
||||
set_field(&mut a, "touchWorkspace", json!(false)).unwrap();
|
||||
apply(&mut a);
|
||||
assert!(is_current(&a.ui, "Essentials Classic"));
|
||||
assert!(!a.ui.task_bar, "the workspace returned to keeps its reset value");
|
||||
}
|
||||
|
||||
/// A Touch return marker left over from an earlier automatic switch (Window › Workspace does not clear it) does not
|
||||
/// change where OK puts the task bar: OK enters Touch from the workspace it leaves, so that workspace takes the row
|
||||
/// and Touch keeps its own.
|
||||
#[test]
|
||||
fn ok_sets_the_task_bar_in_the_workspace_left_with_a_stale_touch_marker() {
|
||||
use crate::workspaces::{TOUCH, is_current, switch};
|
||||
let mut a = app();
|
||||
a.touch_screen = true;
|
||||
a.run("prefs.set", json!({"key": "touchWorkspace", "value": false})).unwrap();
|
||||
a.ui.touch_workspace_restore = Some("Typography".into());
|
||||
switch(&mut a, "Essentials Classic").unwrap();
|
||||
a.ui.task_bar = true;
|
||||
open(&mut a, Some("General"));
|
||||
reset_preferences(&mut a, PromptChoice::Proceed);
|
||||
confirm(&mut a).unwrap();
|
||||
assert!(is_current(&a.ui, TOUCH));
|
||||
assert!(a.ui.task_bar, "Touch keeps its own task bar");
|
||||
assert!(!left_task_bar(&a, "Essentials Classic"), "the workspace left takes the reset value");
|
||||
}
|
||||
|
||||
/// A `prefs.reset` run straight on the session, outside `VectorcraftApp::run`, resets the UI-only rows in the next
|
||||
/// frame, and before the next command switches workspaces.
|
||||
#[test]
|
||||
fn prefs_reset_outside_run_resets_the_ui_only_rows_in_the_next_frame() {
|
||||
let mut a = app();
|
||||
let default = ui_rows(&a);
|
||||
set_ui_rows(&mut a, (!default.0, !default.1, !default.2));
|
||||
a.session.execute("prefs.reset", &json!({})).unwrap();
|
||||
let ctx = a.ui_ctx.clone().expect("a window context");
|
||||
crate::testing::app_frame(&mut a, &ctx, egui::RawInput::default());
|
||||
assert_eq!(ui_rows(&a), default);
|
||||
|
||||
// Before the next command switches workspaces: the workspace left keeps the reset value.
|
||||
let mut b = app();
|
||||
crate::workspaces::switch(&mut b, "Essentials Classic").unwrap();
|
||||
b.ui.task_bar = true;
|
||||
b.session.execute("prefs.reset", &json!({"category": "General"})).unwrap();
|
||||
b.run("window.workspace", json!({"name": crate::workspaces::ESSENTIALS})).unwrap();
|
||||
assert!(b.ui.task_bar, "Essentials keeps its own task bar");
|
||||
assert!(!left_task_bar(&b, "Essentials Classic"), "the workspace left keeps the reset value");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn old_pref_files_keep_their_brightness() {
|
||||
let mut a = app();
|
||||
@@ -527,6 +812,23 @@ fn prefs_import_of_touch_workspace_switches_the_workspace() {
|
||||
assert!(crate::workspaces::is_current(&a.ui, "Typography"));
|
||||
}
|
||||
|
||||
/// A `prefs.reset` run straight on the session, then a touch screen that switches to Touch: the workspace left keeps
|
||||
/// the reset value.
|
||||
#[test]
|
||||
fn a_pending_prefs_reset_applies_before_a_touch_switch() {
|
||||
use crate::workspaces::{TOUCH, is_current, switch, sync_touch_workspace};
|
||||
let mut a = app();
|
||||
a.run("prefs.set", json!({"key": "touchWorkspace", "value": false})).unwrap();
|
||||
switch(&mut a, "Essentials Classic").unwrap();
|
||||
a.ui.task_bar = true;
|
||||
a.session.execute("prefs.reset", &json!({})).unwrap();
|
||||
assert!(a.session.prefs.touch_workspace, "the reset turns Enable Touch Workspace on");
|
||||
sync_touch_workspace(&mut a, true);
|
||||
assert!(is_current(&a.ui, TOUCH));
|
||||
assert!(a.ui.task_bar, "Touch keeps its own task bar");
|
||||
assert!(!left_task_bar(&a, "Essentials Classic"), "the workspace left keeps the reset value");
|
||||
}
|
||||
|
||||
/// A folder that no folder can be created in, or that is not there, is refused on OK with the
|
||||
/// engine's message, and the draft keeps its value.
|
||||
#[test]
|
||||
|
||||
@@ -304,11 +304,23 @@ fn chrome_of(record: &WorkspaceRecord) -> WorkspaceChrome {
|
||||
chrome
|
||||
}
|
||||
|
||||
/// Whether [`sync_touch_workspace`] with `touch_screen` switches to the Touch workspace.
|
||||
pub fn enters_touch(app: &VectorcraftApp, touch_screen: bool) -> bool {
|
||||
app.session.prefs.touch_workspace && touch_screen && !is_current(&app.ui, TOUCH)
|
||||
}
|
||||
|
||||
/// Whether the current workspace was saved with the Contextual Task Bar on.
|
||||
pub(crate) fn saved_task_bar(ui: &UiState) -> bool {
|
||||
saved_record(&ui.workspaces, &ui.workspaces.set.current).task_bar
|
||||
}
|
||||
|
||||
/// Preferences › Devices › Enable Touch Workspace (#394): on, a touch screen switches to the Touch
|
||||
/// workspace; off, or when no touch screen is reported, the workspace before that switch is
|
||||
/// restored if Touch was entered automatically. Each switch keeps the layout it leaves and brings
|
||||
/// back the one it returns to as it was left, as Window › Workspace does.
|
||||
pub fn sync_touch_workspace(app: &mut VectorcraftApp, touch_screen: bool) {
|
||||
// A pending `prefs.reset` applies to the workspace it was run in.
|
||||
crate::prefs_dialog::apply_prefs_resets(app);
|
||||
let auto = app.session.prefs.touch_workspace && touch_screen;
|
||||
if auto {
|
||||
if !is_current(&app.ui, TOUCH) {
|
||||
|
||||
@@ -9341,6 +9341,14 @@ Preferences. `prefs.reset` resets the preferences at once, without the question.
|
||||
{"name":"run_command","arguments":{"command":"prefs.set","params":{"key":"unitsGeneral","value":"millimeters"}}}
|
||||
```
|
||||
|
||||
Reset Preferences also sets the dialog's `__smartGuides`, `__snapToGrid` and `__taskBar` fields to their defaults
|
||||
(`__taskBar` takes the value the current workspace was saved with). A category's own reset sets the field of that
|
||||
category (Smart Guides, Guides & Grid or General), and File Handling's also resets the app chosen for Edit Original.
|
||||
`prefs.reset` run while Preferences is open shows the values it reset in the dialog. In the app, `prefs.reset` also resets Smart Guides,
|
||||
Snap to Grid and Enable Contextual Task Bar when it resets every category or their category (Smart Guides, Guides &
|
||||
Grid and General), and the app chosen for Edit Original when it resets every category or File Handling. A `category`
|
||||
left out or `null` resets every category, and one that is not a string is an error.
|
||||
|
||||
`prefs.export {path?}` writes the preferences as a JSON file, `{"format": "vectorcraft-preferences", "version": 1,
|
||||
"prefs": {…}}`, and replies `{path, count}`; without `path` it replies `{data, count}` with the file's text. The file
|
||||
holds every preference `prefs.list` lists and the `eyedropper`, `perspectiveWidget`, `pathfinder`, `glyphSnap` and
|
||||
|
||||
@@ -901,6 +901,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- **Preferences › User Interface › Open Documents As Tabs (G7, #394):** checked by default, documents open under tabs in one document window ([public source](https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/workspace-overview.html)). With the box cleared, each document opened or created afterwards opens in a floating window of its own, at the next cascade place, as Float in Window floats it; documents already open stay where they are, and checking the box again leaves floating documents in their windows. Tests: `crates/ui-egui/src/doc_windows/tests.rs`.
|
||||
- **Preferences search:** a Search Preferences field above the category list has the keyboard focus when the dialog opens, and Cmd/Ctrl+F gives it back; typing lists the settings it finds, and choosing one shows its category, as the [help page](https://helpx.adobe.com/illustrator/desktop/get-started/preferences-and-settings/set-app-preferences.html) describes. VectorCraft's own rules: the field matches a setting's label, section or category, ignoring case, in the interface language or in English; the list replaces the categories while the field has text and shows every match, or "No settings found"; the chosen setting's row is highlighted and scrolled into view; Escape in the field with text clears it, and Escape in the empty field closes the dialog. The dialog's `__search` field (`ui.dialog.set`) holds the text. Tests: `crates/ui-egui/src/prefs_dialog/tests.rs`.
|
||||
- **Reset Preferences asks first (#6435):** the Preferences dialog's Reset Preferences button opens a question over the dialog (`resetPreferences`). Cancel or Escape goes back to Preferences unchanged, with its category, search and edits kept; OK goes back with every preference at its default value, which OK in Preferences applies and Cancel there discards. The question and its wording are VectorCraft's own. Tests: `crates/ui-egui/src/prefs_dialog/tests.rs`.
|
||||
- **Reset Preferences resets every setting the dialog shows:** Smart Guides and Snap to Grid also return to their defaults (on and off) when Reset Preferences is confirmed, and General's Enable Contextual Task Bar takes the value the current workspace was saved with. OK in Preferences applies them with the other defaults, and Cancel keeps the values in use. A category's own reset resets the row of that category, and File Handling's also resets the app chosen for Edit Original. `prefs.reset` (the Command Palette's Reset Preferences) resets them too, each only when it resets every category or the setting's own, and with every category or File Handling it also clears the app chosen for Edit Original. The rule is VectorCraft's own. Tests: `crates/ui-egui/src/prefs_dialog/tests.rs`, `crates/ui-egui/src/original_editor.rs`.
|
||||
- **Preferences › General describes its settings:** the line under the Preferences fields shows a sentence for each of the 32 General settings, Enable Contextual Task Bar included, when the pointer is over the setting's row or its control has the keyboard focus, and a screen reader gets the same sentence. The sentences are VectorCraft's own and state what the app does with each setting. Sentences: `crates/ui-egui/src/prefs_dialog/descriptions.rs`. Tests: `crates/ui-egui/src/prefs_dialog/tests.rs`.
|
||||
- **Preferences › Selection & Anchor Display describes its settings:** the line under the Preferences fields shows a sentence for each of the 14 Selection & Anchor Display settings, from Tolerance to the Curvature Tool rubber band, on hover and on keyboard focus, and a screen reader gets the same sentence. The Snap to Point sentence states that the Smart Guides Snapping Tolerance applies while Smart Guides is on. Sentences: `crates/ui-egui/src/prefs_dialog/descriptions.rs`. Tests: `crates/ui-egui/src/prefs_dialog/tests.rs`.
|
||||
- **Preferences › Guides & Grid describes its settings:** the line under the Preferences fields shows a sentence for each of the 12 Guides & Grid settings, from Snap to Grid to Pattern Editing's Tile Edge Color, on hover and on keyboard focus, and a screen reader gets the same sentence. The Show Pixel Grid sentence states that the pixel grid shows from 600% zoom. Sentences: `crates/ui-egui/src/prefs_dialog/descriptions.rs`. Tests: `crates/ui-egui/src/prefs_dialog/tests.rs`.
|
||||
|
||||
Reference in new issue
Block a user