diff --git a/crates/ui-egui/src/panels/properties/appearance_section.rs b/crates/ui-egui/src/panels/properties/appearance_section.rs index b3266b032d..bd0c4d68b2 100644 --- a/crates/ui-egui/src/panels/properties/appearance_section.rs +++ b/crates/ui-egui/src/panels/properties/appearance_section.rs @@ -61,6 +61,7 @@ fn opacity_row(app: &mut VectorcraftApp, ui: &mut Ui, n: &Node) { /// The fx button that opens the effect menu, as the Appearance panel's does, the Delete icon and /// the icon that shows the Appearance panel. fn effects_row(app: &mut VectorcraftApp, ui: &mut Ui, n: &Node) { + let editable = app.session.active().is_some_and(|st| st.selection.symbol_part.is_none()); // The effects of one selected object: the fill's and stroke's as well as its own. let effects: Vec<(Option, usize, &str)> = if panels::selection_len(app) == 1 { let own = n.appearance.effects.iter().enumerate().map(|(k, e)| (None, k, e.id.as_str())); @@ -71,9 +72,11 @@ fn effects_row(app: &mut VectorcraftApp, ui: &mut Ui, n: &Node) { vec![] }; Row::new().show(ui, |ui, _| { - let fx = Button::new("fx").tooltip(tl!("Add New Effect")).show(ui); - Menu::new(tl!("Add New Effect")).opened_by(&fx.response, Trigger::Click).show(ui, |ui, _| appearance::fx_menu(app, ui)); - effect_delete(app, ui, n.id, &effects); + let fx = Button::new("fx").tooltip(tl!("Add New Effect")).enabled(editable).show(ui); + if editable { + Menu::new(tl!("Add New Effect")).opened_by(&fx.response, Trigger::Click).show(ui, |ui, _| appearance::fx_menu(app, ui)); + } + effect_delete(app, ui, n.id, &effects, editable); panel_button("ellipsis", "appearance", tl!("Appearance panel")).show(ui); }); } @@ -82,12 +85,12 @@ fn effects_row(app: &mut VectorcraftApp, ui: &mut Ui, n: &Node) { /// (): /// with one effect applied, its name and an icon that removes it (`effect.remove`); with several, /// the icon shows the Appearance panel to remove them there. Nothing without effects. -fn effect_delete(app: &mut VectorcraftApp, ui: &mut Ui, id: NodeId, effects: &[(Option, usize, &str)]) { +fn effect_delete(app: &mut VectorcraftApp, ui: &mut Ui, id: NodeId, effects: &[(Option, usize, &str)], editable: bool) { match effects { [] => {} [(item, k, effect)] => { Text::new(appearance::shown_effect_label(effect)).elide(Elide::End).show(ui); - if IconButton::new(IconId::new("trash-2")).label(tl!("Remove Effect")).show(ui).clicked() { + if IconButton::new(IconId::new("trash-2")).label(tl!("Remove Effect")).enabled(editable).show(ui).clicked() { app.run("effect.remove", json!({"ids": [id.0], "item": item, "index": k})).ok(); } } diff --git a/crates/ui-egui/src/panels/properties/tests.rs b/crates/ui-egui/src/panels/properties/tests.rs index faeb91c166..bb50b38a58 100644 --- a/crates/ui-egui/src/panels/properties/tests.rs +++ b/crates/ui-egui/src/panels/properties/tests.rs @@ -1300,6 +1300,32 @@ fn one_effect_has_a_delete_icon_in_appearance() { assert!(!panel.shows(&name), "two objects"); } +#[test] +fn properties_remove_effect_requires_the_whole_symbol_instance() { + let mut app = new_app(); + let left = rect(&mut app, 20.0, 20.0, 20.0, 20.0); + let right = rect(&mut app, 60.0, 20.0, 20.0, 20.0); + let instance = app.run("symbol.new", json!({"type": "dynamic", "ids": [left, right]})).unwrap()["id"].clone(); + let node = vectorcraft_doc::NodeId(instance.as_u64().unwrap()); + app.run("effect.apply", json!({"ids": [instance], "effect": "stylize.dropShadow"})).unwrap(); + app.run("symbol.instance.selectPart", json!({"id": instance, "path": [0]})).unwrap(); + let mut panel = Panel::new(app, show); + let effects = |panel: &Panel| panel.app().session.active().unwrap().doc.node(node).unwrap().appearance.effects.len(); + let depth = undo_depth(&panel.app()); + + assert_eq!(effects(&panel), 1); + panel.click("Remove Effect"); + assert_eq!((effects(&panel), undo_depth(&panel.app())), (1, depth), "a part cannot remove the whole instance’s effect"); + assert!(!panel.enabled("Remove Effect")); + assert!(panel.shows("Appearance panel"), "Appearance remains available for inspection"); + + panel.app().run("select.set", json!({"ids": [instance]})).unwrap(); + panel.frame(); + assert!(panel.enabled("Remove Effect")); + panel.click("Remove Effect"); + assert_eq!((effects(&panel), undo_depth(&panel.app())), (0, depth + 1)); +} + /// A rectangle at 100, 100, 100 × 60 pt, selected, with `then` run on it, and the Transform /// panel's reference point on the top-left square. fn reference_setup(then: &[(&str, Value)]) -> VectorcraftApp {