diff --git a/crates/ui-egui/src/panels/swatches.rs b/crates/ui-egui/src/panels/swatches.rs index 0e1991154b..a179e07a53 100644 --- a/crates/ui-egui/src/panels/swatches.rs +++ b/crates/ui-egui/src/panels/swatches.rs @@ -219,8 +219,13 @@ fn name_of(key: &SwatchKey) -> &str { /// The swatches and colour groups selected in the panel, in click order, without names that no longer exist /// (deleted, renamed or undone). pub(crate) fn selected(app: &VectorcraftApp) -> Vec { + selected_in(app, &app.ui.swatches_panel) +} + +/// The swatches and colour groups selected in `model`, as [`selected`] reads them from the app's panel. +fn selected_in(app: &VectorcraftApp, model: &Model) -> Vec { let Some(st) = app.session.active() else { return vec![] }; - let mut names = app.ui.swatches_panel.names(); + let mut names = model.names(); names.retain(|n| n == REGISTRATION || st.doc.swatch_name_taken(n)); names } @@ -407,7 +412,7 @@ fn body(app: &mut VectorcraftApp, ui: &mut Ui) { let doc = Arc::clone(&st.doc); let document = st.uid; let reverts = st.reverts; - let foot = Footer::of(app); + let foot = Footer::of(app, &model); let shown_app: &VectorcraftApp = app; let search = model.show_find; let state = &mut model.state; @@ -789,14 +794,14 @@ struct Footer { } impl Footer { - /// The footer's state, read before the swatch browser borrows the app. - fn of(app: &VectorcraftApp) -> Self { - let sel = selected(app); + /// The footer's state for the panel `model`, which is out of the app while the swatch browser borrows it. + fn of(app: &VectorcraftApp, model: &Model) -> Self { + let sel = selected_in(app, model); let del = actions::deletable(app, &sel); let opts = actions::editable(app, &sel); let group = actions::selected_group(app, &sel).filter(|_| opts.is_none()); Footer { - kind: app.ui.swatches_panel.kind, + kind: model.kind, libraries_open: library_panel::any_open::(&app.ui), document: app.session.active().map(|state| state.uid), sel, diff --git a/crates/ui-egui/src/panels/swatches/tests.rs b/crates/ui-egui/src/panels/swatches/tests.rs index e45e0f3132..617fb83a35 100644 --- a/crates/ui-egui/src/panels/swatches/tests.rs +++ b/crates/ui-egui/src/panels/swatches/tests.rs @@ -184,6 +184,22 @@ fn the_footer_menu_buttons_report_that_they_open_a_menu() { } } +/// The footer reads the panel's selection while the browser holds the panel's model: with one swatch selected, Swatch +/// Options and Delete Swatch are enabled. +#[test] +fn the_footer_acts_on_the_panels_selection() { + use crate::tests::panel_harness::Panel; + + let mut app = app(); + select_rows(&mut app, &["Red"]); + let mut panel = Panel::new(app, show); + panel.frame(); + assert_eq!(selected(&panel.app()), vec!["Red".to_string()]); + for name in ["Swatch Options", "Delete Swatch"] { + assert!(panel.enabled(name), "{name}"); + } +} + /// Art `ids` dragged off the canvas. fn art_drag(app: &VectorcraftApp, ids: Vec) -> PanelDrag { let (document, reverts) = app.session.active().map_or((0, 0), |st| (st.uid, st.reverts));