Keep symbol instance effects from its part selection

This commit is contained in:
dotCooCoo committed 2026-11-26 22:09:51 -08:00
1 parent 97da102592
commit ee446c8dcf
2 files changed
+34 -5

No files matched your search

@@ -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>, 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) {
/// (<https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/properties-panel-overview.html>):
/// 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>, usize, &str)]) {
fn effect_delete(app: &mut VectorcraftApp, ui: &mut Ui, id: NodeId, effects: &[(Option<usize>, 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();
}
}
@@ -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 {