mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-29 01:34:29 +01:00
Swatches: the footer reads the panel's selection and kind filter
The panel model is out of the app while the swatch browser draws, so the footer read an empty selection and the default kind filter: Swatch Options and Delete Swatch stayed disabled with a swatch selected, and Show Swatch Kinds never showed as pressed. The footer now takes its state from the model the browser holds.
This commit is contained in:
1 parent
aaa036511c
commit
24b5930cc8
2 files changed
+27
-6
No files matched your search
@@ -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<String> {
|
||||
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<String> {
|
||||
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::<SwatchLibraries>(&app.ui),
|
||||
document: app.session.active().map(|state| state.uid),
|
||||
sel,
|
||||
|
||||
@@ -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<vectorcraft_doc::NodeId>) -> PanelDrag {
|
||||
let (document, reverts) = app.session.active().map_or((0, 0), |st| (st.uid, st.reverts));
|
||||
|
||||
Reference in new issue
Block a user