mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-30 10:14:46 +01:00
Merge pull request #9771 from dotCooCoo/fix/layer-options-unchanged-b-verify
Keep unchanged Layer and Object Options out of Undo
This commit is contained in:
5 files changed
+210
-9
No files matched your search
@@ -1256,7 +1256,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"ui.layerOptions",
|
||||
"Options for Selection…",
|
||||
"",
|
||||
"{ids?|id?} open Layer Options for Layers panel rows (default: the highlighted rows, else the current layer), filled in from the first: dialog `layerOptions`, fields name, color (a preset name such as \"Light Blue\" or #rrggbb), template, locked, visible, printable, preview, dimImages (bool), dimPercent (0–100); an object's row has name, visible and locked. OK runs layer.setProps (one undo step); for several rows it sends only the fields set in the dialog",
|
||||
"{ids?|id?} open Layer Options for Layers panel rows (default: the highlighted rows, else the current layer), filled in from the first: dialog `layerOptions`, fields name, color (a preset name such as \"Light Blue\" or #rrggbb), template, locked, visible, printable, preview, dimImages (bool), dimPercent (0–100); an object's row has name, visible and locked. Unchanged OK adds no undo step; edits run layer.setProps in one undo step. Existing names are preserved unless Name is edited or explicitly set; for several rows it sends only the fields set in the dialog",
|
||||
),
|
||||
(
|
||||
"ui.layerDelete",
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
//! `#rrggbb`), `template`, `locked`, `visible`, `printable`, `preview`, `dimImages` and
|
||||
//! `dimPercent`. OK runs `layer.setProps`, `layer.new` or `layer.newSublayer`. For several rows
|
||||
//! the dialog shows the first row's settings, and OK sends only the ones set in the dialog.
|
||||
//! Existing rows keep their stored names unless Name is edited; unchanged approval adds no Undo step.
|
||||
|
||||
use std::cell::RefCell;
|
||||
|
||||
@@ -327,7 +328,9 @@ fn flag_row(ui: &mut egui::Ui, v: &mut LayerOptionsValue, key: &'static str, tex
|
||||
fn body(ui: &mut egui::Ui, v: &mut LayerOptionsValue, requested: &RefCell<Option<ColorRequest>>) {
|
||||
if v.shows("name") {
|
||||
Field::new(tl!("Name:")).id_salt("name").show(ui, |ui, _| {
|
||||
TextField::new(tl!("Name:"), Bind::bound(&mut v.name)).show(ui);
|
||||
if TextField::new(tl!("Name:"), Bind::bound(&mut v.name)).show(ui).value().is_some() {
|
||||
v.mark("name");
|
||||
}
|
||||
});
|
||||
}
|
||||
if v.layer {
|
||||
@@ -379,7 +382,7 @@ fn body(ui: &mut egui::Ui, v: &mut LayerOptionsValue, requested: &RefCell<Option
|
||||
/// so each row keeps its own values for the rest.
|
||||
pub(crate) fn params(v: &LayerOptionsValue) -> (&'static str, Value) {
|
||||
let mut p = serde_json::Map::new();
|
||||
if !v.many {
|
||||
if !v.many && (v.mode != "edit" || v.is_set("name")) {
|
||||
p.insert("name".into(), json!(v.name));
|
||||
}
|
||||
p.insert("visible".into(), json!(v.visible));
|
||||
@@ -415,6 +418,8 @@ pub(crate) struct LayerOptionsDialog {
|
||||
reverts: u64,
|
||||
open: bool,
|
||||
value: LayerOptionsValue,
|
||||
/// Unchanged approval is not an edit, even though the engine command records one.
|
||||
opening_params: Value,
|
||||
held: HeldAnswer<LayerOptionsValue>,
|
||||
/// The value the held OK was refused for: the reason shows until it changes.
|
||||
refused_at: Option<LayerOptionsValue>,
|
||||
@@ -425,12 +430,14 @@ pub(crate) struct LayerOptionsDialog {
|
||||
impl LayerOptionsDialog {
|
||||
/// The dialog over `value`.
|
||||
fn new(document: u64, reverts: u64, value: LayerOptionsValue) -> Self {
|
||||
let opening_params = params(&value).1;
|
||||
LayerOptionsDialog {
|
||||
id: dialog_id(KEY),
|
||||
document,
|
||||
reverts,
|
||||
open: true,
|
||||
value,
|
||||
opening_params,
|
||||
held: HeldAnswer::new(),
|
||||
refused_at: None,
|
||||
color_request: None,
|
||||
@@ -553,7 +560,10 @@ impl StackDialog for LayerOptionsDialog {
|
||||
}
|
||||
let rejects = || FieldRefusal::Rejects(&value).message(field);
|
||||
match key {
|
||||
"name" => v.name = value.as_str().ok_or_else(rejects)?.to_owned(),
|
||||
"name" => {
|
||||
v.name = value.as_str().ok_or_else(rejects)?.to_owned();
|
||||
v.mark("name");
|
||||
}
|
||||
"color" => v.set_color_text(value.as_str().ok_or_else(rejects)?).ok_or_else(rejects)?,
|
||||
"dimPercent" => {
|
||||
v.dim_percent = value.as_f64().filter(|p| p.is_finite()).ok_or_else(rejects)?;
|
||||
@@ -583,9 +593,9 @@ pub(crate) fn pump(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
let Some(dialogs) = app.dialogs() else { return };
|
||||
// The closed dialog's answer was run when OK was filed.
|
||||
let _ = dialogs.with(|host| host.take::<LayerOptionsDialog>());
|
||||
let Some((document, reverts, value)) = dialogs.with(|host| {
|
||||
let Some((document, reverts, value, opening_params)) = dialogs.with(|host| {
|
||||
let dialog = host.get_mut::<LayerOptionsDialog>()?;
|
||||
Some((dialog.document, dialog.reverts, dialog.take_filed()?))
|
||||
Some((dialog.document, dialog.reverts, dialog.take_filed()?, dialog.opening_params.clone()))
|
||||
}) else {
|
||||
return;
|
||||
};
|
||||
@@ -603,7 +613,10 @@ pub(crate) fn pump(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
Err(Label::from("exit isolation mode first"))
|
||||
}
|
||||
_ => {
|
||||
if let Err(e) = app.run(cmd, p) {
|
||||
let targets_exist = app.session.active().is_some_and(|st| value.ids.iter().all(|id| st.doc.node(NodeId(*id)).is_some()));
|
||||
if (cmd != "layer.setProps" || p != opening_params || !value.set.is_empty() || !targets_exist)
|
||||
&& let Err(e) = app.run(cmd, p)
|
||||
{
|
||||
app.status(e);
|
||||
}
|
||||
Ok(())
|
||||
@@ -664,6 +677,191 @@ mod tests {
|
||||
dialogs.with(|host| host.confirm_by_id(&ctx, id));
|
||||
}
|
||||
|
||||
/// Accepting displayed labels must not turn generated object names into stored names, or
|
||||
/// add an edit when the user accepts an existing layer's unchanged options.
|
||||
#[test]
|
||||
fn normal_unchanged_ok_preserves_names_document_and_history() {
|
||||
use crate::tests::panel_harness::Panel;
|
||||
use craft::ui::contract::Role;
|
||||
for xml_id in [false, true] {
|
||||
for kind in ["text", "path", "layer"] {
|
||||
let mut app = app();
|
||||
if xml_id {
|
||||
app.session.prefs.identify_objects_by = "xmlId".into();
|
||||
}
|
||||
let id = match kind {
|
||||
"text" => app.run("text.create", json!({"x": 10, "y": 30, "text": "Opening words"})).unwrap()["id"].as_u64().unwrap(),
|
||||
"path" => app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap()["id"].as_u64().unwrap(),
|
||||
_ => app.session.active().unwrap().doc.layers[0].id.0,
|
||||
};
|
||||
let before = app.session.active().unwrap().doc.clone();
|
||||
let revision = app.session.active().unwrap().revision;
|
||||
let undo = app.session.active().unwrap().history.undo.len();
|
||||
if kind != "layer" {
|
||||
assert_eq!(before.node(NodeId(id)).unwrap().name, None);
|
||||
}
|
||||
let mut panel = Panel::new(app, crate::tests::picks::dialogs);
|
||||
panel.room(egui::vec2(800.0, 900.0));
|
||||
panel.app().run("ui.layerOptions", json!({"id": id})).unwrap();
|
||||
panel.frame();
|
||||
panel.click_role("Name:", Role::TEXT_INPUT);
|
||||
panel.click("OK");
|
||||
panel.frame();
|
||||
panel.frame();
|
||||
{
|
||||
let app = panel.app();
|
||||
assert!(!app.any_dialog_open());
|
||||
let st = app.session.active().unwrap();
|
||||
assert_eq!(st.doc, before, "{kind}, XML ID: {xml_id}");
|
||||
assert_eq!(st.revision, revision);
|
||||
assert_eq!(st.history.undo.len(), undo);
|
||||
}
|
||||
if kind == "text" {
|
||||
panel.app().run("text.setText", json!({"id": id, "text": "Later words"})).unwrap();
|
||||
let app = panel.app();
|
||||
let node = app.session.active().unwrap().doc.node(NodeId(id)).unwrap();
|
||||
assert_eq!(node.name, None);
|
||||
assert_eq!(node.display_name(), "Later words", "the Layers label still follows the text");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A deliberate Name edit may assign even the generated caption; clearing it still means
|
||||
/// removing the explicit name. Cancel and changes to other options preserve the name.
|
||||
#[test]
|
||||
fn normal_name_edits_other_options_and_cancel_keep_their_intended_effects() {
|
||||
use crate::tests::panel_harness::Panel;
|
||||
use craft::ui::contract::Role;
|
||||
use egui::{Key, Modifiers};
|
||||
for cancel in [false, true] {
|
||||
let mut app = app();
|
||||
let id = app.run("text.create", json!({"x": 10, "y": 30, "text": "Opening words"})).unwrap()["id"].as_u64().unwrap();
|
||||
let original = app.session.active().unwrap().doc.clone();
|
||||
let undo = app.session.active().unwrap().history.undo.len();
|
||||
let mut panel = Panel::new(app, crate::tests::picks::dialogs);
|
||||
panel.room(egui::vec2(800.0, 900.0));
|
||||
panel.app().run("ui.layerOptions", json!({"id": id})).unwrap();
|
||||
panel.frame();
|
||||
panel.click_role("Name:", Role::TEXT_INPUT);
|
||||
panel.key(Key::A, Modifiers::COMMAND);
|
||||
panel.key(Key::Backspace, Modifiers::NONE);
|
||||
panel.type_text("Opening words");
|
||||
panel.click(if cancel { "Cancel" } else { "OK" });
|
||||
panel.frame();
|
||||
panel.frame();
|
||||
{
|
||||
let app = panel.app();
|
||||
let st = app.session.active().unwrap();
|
||||
assert!(!app.any_dialog_open());
|
||||
assert_eq!(st.history.undo.len(), undo + usize::from(!cancel));
|
||||
if cancel {
|
||||
assert_eq!(st.doc, original);
|
||||
} else {
|
||||
assert_eq!(st.doc.node(NodeId(id)).unwrap().name.as_deref(), Some("Opening words"));
|
||||
}
|
||||
}
|
||||
if !cancel {
|
||||
panel.app().run("edit.undo", json!({})).unwrap();
|
||||
assert_eq!(panel.app().session.active().unwrap().doc, original);
|
||||
}
|
||||
panel.app().run("ui.layerOptions", json!({"id": id})).unwrap();
|
||||
panel.frame();
|
||||
panel.click("Lock");
|
||||
panel.click("OK");
|
||||
panel.frame();
|
||||
panel.frame();
|
||||
let app = panel.app();
|
||||
let st = app.session.active().unwrap();
|
||||
let node = st.doc.node(NodeId(id)).unwrap();
|
||||
assert!(node.locked);
|
||||
assert_eq!(node.name, None, "a different option does not store the generated caption");
|
||||
assert_eq!(st.history.undo.len(), undo + 1);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_automation_can_name_the_generated_caption_or_clear_a_name() {
|
||||
let mut app = app();
|
||||
let id = app.run("text.create", json!({"x": 10, "y": 30, "text": "Opening words"})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("ui.layerOptions", json!({"id": id})).unwrap();
|
||||
set(&mut app, "name", json!("Opening words"));
|
||||
ok(&mut app);
|
||||
assert_eq!(app.session.active().unwrap().doc.node(NodeId(id)).unwrap().name.as_deref(), Some("Opening words"));
|
||||
app.run("ui.layerOptions", json!({"id": id})).unwrap();
|
||||
set(&mut app, "name", json!(""));
|
||||
ok(&mut app);
|
||||
assert_eq!(app.session.active().unwrap().doc.node(NodeId(id)).unwrap().name, None);
|
||||
app.run("ui.layerOptions", json!({"id": id})).unwrap();
|
||||
app.run("layer.setProps", json!({"ids": [id], "name": "Newer name"})).unwrap();
|
||||
let undo = app.session.active().unwrap().history.undo.len();
|
||||
ok(&mut app);
|
||||
assert_eq!(app.session.active().unwrap().doc.node(NodeId(id)).unwrap().name.as_deref(), Some("Newer name"));
|
||||
assert_eq!(app.session.active().unwrap().history.undo.len(), undo, "unchanged approval keeps an external rename");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normal_multi_row_approval_preserves_mixed_names_and_options() {
|
||||
use crate::tests::panel_harness::Panel;
|
||||
let mut app = app();
|
||||
let a = app.run("text.create", json!({"x": 10, "y": 30, "text": "Opening words"})).unwrap()["id"].as_u64().unwrap();
|
||||
let b = app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("layer.setProps", json!({"ids": [b], "name": "Named path", "locked": true})).unwrap();
|
||||
let before = app.session.active().unwrap().doc.clone();
|
||||
let revision = app.session.active().unwrap().revision;
|
||||
let undo = app.session.active().unwrap().history.undo.len();
|
||||
let mut panel = Panel::new(app, crate::tests::picks::dialogs);
|
||||
panel.room(egui::vec2(800.0, 900.0));
|
||||
panel.app().run("ui.layerOptions", json!({"ids": [a, b]})).unwrap();
|
||||
panel.frame();
|
||||
panel.click("OK");
|
||||
panel.frame();
|
||||
panel.frame();
|
||||
let app = panel.app();
|
||||
assert!(!app.any_dialog_open());
|
||||
let st = app.session.active().unwrap();
|
||||
assert_eq!(st.doc, before);
|
||||
assert_eq!(st.revision, revision);
|
||||
assert_eq!(st.history.undo.len(), undo);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_settings_still_override_changes_made_while_options_are_open() {
|
||||
let mut app = app();
|
||||
let id = app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("ui.layerOptions", json!({"id": id})).unwrap();
|
||||
app.run("layer.setProps", json!({"ids": [id], "locked": true})).unwrap();
|
||||
let undo = app.session.active().unwrap().history.undo.len();
|
||||
set(&mut app, "locked", json!(false));
|
||||
ok(&mut app);
|
||||
let st = app.session.active().unwrap();
|
||||
assert!(!st.doc.node(NodeId(id)).unwrap().locked);
|
||||
assert_eq!(st.history.undo.len(), undo + 1);
|
||||
app.run("edit.undo", json!({})).unwrap();
|
||||
assert!(app.session.active().unwrap().doc.node(NodeId(id)).unwrap().locked);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unchanged_approval_of_a_deleted_row_still_reports_the_command_error() {
|
||||
let mut app = app();
|
||||
let id = app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("ui.layerOptions", json!({"id": id})).unwrap();
|
||||
app.run("edit.clear", json!({"ids": [id]})).unwrap();
|
||||
assert!(app.session.active().unwrap().doc.node(NodeId(id)).is_none());
|
||||
let before = app.session.active().unwrap().doc.clone();
|
||||
let revision = app.session.active().unwrap().revision;
|
||||
let undo = app.session.active().unwrap().history.undo.len();
|
||||
let expected = app.session.execute("layer.setProps", &json!({"ids": [id]})).unwrap_err().to_string();
|
||||
app.ui.status.clear();
|
||||
ok(&mut app);
|
||||
assert!(!app.any_dialog_open());
|
||||
assert_eq!(app.ui.status, expected);
|
||||
let st = app.session.active().unwrap();
|
||||
assert_eq!(st.doc, before);
|
||||
assert_eq!(st.revision, revision);
|
||||
assert_eq!(st.history.undo.len(), undo);
|
||||
}
|
||||
|
||||
/// Explicit object ids must not silently disappear or fall back to the highlighted row.
|
||||
#[test]
|
||||
fn invalid_layer_options_targets_do_not_open_a_partial_dialog() {
|
||||
|
||||
@@ -1257,7 +1257,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"ui.layerOptions",
|
||||
"Options for Selection…",
|
||||
"",
|
||||
"{ids?|id?} open Layer Options for Layers panel rows (default: the highlighted rows, else the current layer), filled in from the first: dialog `layerOptions`, fields name, color (a preset name such as \"Light Blue\" or #rrggbb), template, locked, visible, printable, preview, dimImages (bool), dimPercent (0–100); an object's row has name, visible and locked. OK runs layer.setProps (one undo step); for several rows it sends only the fields set in the dialog",
|
||||
"{ids?|id?} open Layer Options for Layers panel rows (default: the highlighted rows, else the current layer), filled in from the first: dialog `layerOptions`, fields name, color (a preset name such as \"Light Blue\" or #rrggbb), template, locked, visible, printable, preview, dimImages (bool), dimPercent (0–100); an object's row has name, visible and locked. Unchanged OK adds no undo step; edits run layer.setProps in one undo step. Existing names are preserved unless Name is edited or explicitly set; for several rows it sends only the fields set in the dialog",
|
||||
),
|
||||
(
|
||||
"ui.layerDelete",
|
||||
|
||||
+3
-1
@@ -7010,7 +7010,9 @@ and `layerRows`, the rows highlighted in the panel.
|
||||
path pasted directly into the group under either name loses its name.
|
||||
- **Dialogs and panel state** (control channel and the app's MCP): `ui.layerOptions {ids?}` and `ui.newLayer
|
||||
{sublayer?}` open Layer Options (dialog `layerOptions`: name, color, template, locked, visible, printable, preview,
|
||||
dimImages, dimPercent; OK is one undo step; `ui.dialog.set` of `template` also sets `locked` and `dimImages`, as the
|
||||
dimImages, dimPercent; for existing rows, unchanged approval adds no undo step; an edit is one undo step.
|
||||
Existing rows keep their stored names unless Name is edited or explicitly set through `ui.dialog.set`, so generated labels remain automatic.
|
||||
`ui.dialog.set` of `template` also sets `locked` and `dimImages`, as the
|
||||
checkbox does, except a Dim Images set before it; for several `ids` the dialog shows the first row's settings, and OK sends only the fields set with a
|
||||
control or `ui.dialog.set`; Cmd/Ctrl+Alt+L runs `ui.newLayer` for a new layer; in isolation mode `ui.newLayer` for a
|
||||
layer that would be outside the isolated art is an error, OK in the dialog checks again and returns the same error,
|
||||
|
||||
@@ -223,6 +223,7 @@ tools, never checked side by side) isn't captured row by row.
|
||||
| Swatches list fills a taller panel (#1638) | done | Docked, floating or in a resized flyout, the swatch list takes the height above the panel's footer, as the Artboards list does; outside a sized panel it stays 150 pt (200 pt for large thumbnails); `the_list_fills_a_tall_panel_above_its_footer` in `panels/swatches/tests.rs` |
|
||||
| Layers panel lists a blend's spine (#4820) | done | an open blend shows a `<Path>` row below its key objects, where Release leaves the spine; a click selects the blend (Shift/Cmd toggles it) so Direct Selection edits the spine; a locked blend's row selects nothing; no row while searching or filtering (`a_blends_spine_is_a_row_below_its_keys_that_selects_the_blend`) |
|
||||
| Layers panel: a layer whose Layer Options › Print is off shows its name italic (#5739) | done | the panel row and its drag ghost; a printing layer stays upright, and Print on again restores it; `panels::layers` test `a_layer_that_does_not_print_has_its_name_italic` |
|
||||
| Layer/Object Options preserve automatic names and skip unchanged approval | done | Leaving Name untouched preserves the automatic name, including when another option changes. Approving without edits preserves the document revision and Undo history. |
|
||||
| Layers panel: Alt-drag shows the copy cursor (#8217) | done | rows and the selected-art square dragged over the list show the copy cursor while Alt is held and the grabbing hand otherwise, following Alt mid-drag; on Windows and X11 the copy cursor is the white arrow with a plus (the panels' add cursor, #8241); over the trash and New Layer, which ignore Alt, the hand stays; guide rows keep theirs; `alt_shows_the_copy_cursor_while_rows_are_dragged`, `drag_cursor_shows_a_copy_only_where_the_drop_copies` |
|
||||
| Gradient panel: add-stop cursor under the ramp (#8241) | done | the white arrow with a plus (the Group Selection glyph) over the strip under the ramp, handed to the OS on Windows and X11 (winit shows the plain arrow for the system copy cursor there), the system copy cursor elsewhere; over the ramp itself the arrow stays; `panels::gradient` test `the_strip_under_the_ramp_shows_the_add_cursor` |
|
||||
| Layers panel: Alt-drag copies a row beside itself (#8237) | done | with Alt, rows held over one of their own rows copy above or below it, and the bottom layer dropped in the empty space under the list copies below itself, so the top layer dragged up, the bottom one dragged down and a document's only layer are copied; a move onto its own place, or a copy inside itself, still does nothing; `panels::layers` tests `alt_dragging_the_top_layer_up_or_the_bottom_layer_down_copies_it`, `a_lone_layer_alt_dragged_up_or_down_is_copied`; engine test `a_copy_goes_above_or_below_a_row_it_copies` |
|
||||
|
||||
Reference in new issue
Block a user