diff --git a/crates/ui-egui/src/chrome/tests.rs b/crates/ui-egui/src/chrome/tests.rs index 618c28baee..d9cf307b52 100644 --- a/crates/ui-egui/src/chrome/tests.rs +++ b/crates/ui-egui/src/chrome/tests.rs @@ -4173,12 +4173,22 @@ fn the_linked_file_and_embedded_labels_open_the_links_panel() { let id = app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 30, "height": 20})).unwrap()["id"].clone(); let linked = app.run("file.place", json!({"path": path, "link": true})).unwrap()["ids"].clone(); let embedded = app.run("file.place", json!({"path": path, "link": false})).unwrap()["ids"].clone(); + // The default layout floats Links: dock it beside Layers so that both passes reach a docked panel. + app.run("window.panel", json!({"panel": links})).unwrap(); + app.run("window.panel.dock", json!({"panel": links, "onto": "layers"})).unwrap(); + // Whether Links floats, and whether its dock column is collapsed to icons. + let placed = |app: &crate::VectorcraftApp| { + let layout = crate::panel_docking::layout_of(&app.ui); + (layout.floating.iter().any(|w| w.panels().any(|p| p == links)), crate::panel_docking::in_iconic_column(&layout, links)) + }; for collapsed in [false, true] { app.run("window.collapseDock", json!({ "collapsed": collapsed })).unwrap(); app.run("select.set", json!({ "ids": linked })).unwrap(); assert!(click(&mut app, "Linked File"), "collapsed {collapsed}, status: {}", app.ui.status); + assert_eq!(placed(&app), (false, collapsed), "Links opened in its dock, collapsed {collapsed}"); app.run("select.set", json!({ "ids": embedded })).unwrap(); assert!(click(&mut app, "Embedded"), "collapsed {collapsed}, status: {}", app.ui.status); + assert_eq!(placed(&app), (false, collapsed), "Links opened in its dock, collapsed {collapsed}"); app.run("select.set", json!({ "ids": [id] })).unwrap(); let name = crate::panels::appearance::object_label(&app); assert!(!click(&mut app, name), "collapsed {collapsed}: a rectangle's label opens nothing"); diff --git a/crates/ui-egui/src/panel_docking.rs b/crates/ui-egui/src/panel_docking.rs index c4269e6190..a62d174267 100644 --- a/crates/ui-egui/src/panel_docking.rs +++ b/crates/ui-egui/src/panel_docking.rs @@ -429,11 +429,27 @@ fn restore_hidden_group(app: &mut VectorcraftApp, panel: &str) -> Result, panel: &str) -> Option { + dock_columns(layout) + .into_iter() + .filter(|column| column.iconic) + .flat_map(|column| &column.groups) + .find(|group| group.panels.iter().any(|p| p == panel)) + .and_then(|group| group.active_panel()) + .map(|front| front.to_string()) +} + /// Show `panel` as `window.panel` does, but leave it be when it can be seen already ([`visible`]): -/// a command that opens a panel to work in (Edit › Color Settings…) never puts it away. In -/// Presentation Mode the panel comes to the front of its group and shows when the mode ends. +/// a command that opens a panel to work in (Edit › Color Settings…) never puts it away. A flyout +/// keeps the name of the icon that opened it after another of its tabs is clicked, so a panel whose +/// flyout is open with another tab in front comes to the front of it. In Presentation Mode the +/// panel comes to the front of its group and shows when the mode ends. pub(crate) fn reveal_panel(app: &mut VectorcraftApp, panel: &str) -> Result { if visible(&app.ui, panel) { + if app.ui.docking.is_some() && flyout_tab(&layout_of(&app.ui), panel).is_some_and(|front| front != panel) { + gesture(app, Action::Activate { panel: panel.to_string() })?; + } return Ok(json!({"open": panel})); } let id = normalize(panel).ok_or_else(|| format!("unknown panel `{panel}`"))?; diff --git a/crates/ui-egui/src/panel_docking/tests.rs b/crates/ui-egui/src/panel_docking/tests.rs index 6c861c0db9..2c90c7cd54 100644 --- a/crates/ui-egui/src/panel_docking/tests.rs +++ b/crates/ui-egui/src/panel_docking/tests.rs @@ -397,6 +397,28 @@ fn a_collapsed_dock_uses_the_flyouts_active_tab_for_thumbnail_work() { assert!(!thumbnail_panel_showing(&h.app.ui, &h.ctx), "a Properties tab under the Layers icon does not need thumbnails"); } +/// Revealing a panel whose flyout is open with another tab of its group in front brings that panel +/// to the front and keeps the flyout open. +#[test] +fn reveal_brings_the_panel_to_the_front_of_its_open_flyout() { + let mut h = Harness::new(); + h.app.run("window.collapseDock", json!({"collapsed": true})).unwrap(); + h.app.ui.docking = Some(layout_of(&h.app.ui)); + h.app.run("window.panel", json!({"panel": "properties"})).unwrap(); + h.frame(vec![]); + gesture(&mut h.app, Action::Activate { panel: "layers".into() }).unwrap(); + h.frame(vec![]); + assert_eq!(h.app.ui.open_panel.as_deref(), Some("properties"), "the flyout is still named for its opening icon"); + assert_eq!(flyout_tab(&layout_of(&h.app.ui), "properties").as_deref(), Some("layers"), "Layers is in front"); + reveal_panel(&mut h.app, "properties").unwrap(); + h.frame(vec![]); + assert_eq!(h.app.ui.open_panel.as_deref(), Some("properties"), "the flyout stays open"); + assert_eq!(flyout_tab(&layout_of(&h.app.ui), "properties").as_deref(), Some("properties"), "Properties is in front"); + // Revealed again while in front, the panel stays as it is. + reveal_panel(&mut h.app, "properties").unwrap(); + assert_eq!(h.app.ui.open_panel.as_deref(), Some("properties")); +} + /// A Character field shortcut with the Character panel in front of its floating window brings /// that window forward and leaves the panel showing. #[test] diff --git a/crates/ui-egui/src/panels/links.rs b/crates/ui-egui/src/panels/links.rs index c2c9fb5ab7..49706b4294 100644 --- a/crates/ui-egui/src/panels/links.rs +++ b/crates/ui-egui/src/panels/links.rs @@ -84,29 +84,18 @@ fn set_options(ctx: &egui::Context, f: impl FnOnce(&mut Options)) { /// Show the Links panel on the selected image (the Control bar's Linked File or Embedded label), /// wherever the panel is docked or floats; a panel that is already shown stays where it is. The -/// Link Info section opens, a Show filter that leaves out the image's row goes back to Show All, -/// and the list scrolls to the row when the panel next draws it. The sort, thumbnail size and DCS -/// option keep their settings. +/// Link Info section opens, and when the panel next draws the list, a Show filter that leaves out +/// the image's row goes back to Show All and the list scrolls to the row ([`show`]). The sort, +/// thumbnail size and DCS option keep their settings. pub(crate) fn show_selected_image(app: &mut VectorcraftApp, ctx: &egui::Context) { - let o = options(ctx); - let listed = |list: Value, id: u64| list["links"].as_array().is_some_and(|rows| rows.iter().any(|r| r["id"].as_u64() == Some(id))); let first = selected_images(app).first().copied(); - let hidden = match first { - Some(id) if o.show != "all" => app.session.execute("links.list", &json!({ "show": o.show, "sort": o.sort })).is_ok_and(|l| !listed(l, id)), - _ => false, - }; set_pstate(ctx, "links-scroll-to", first); // The list drawn next is read after this request, so a row a file change has just brought // into the Show filter is there to scroll to. - let mut c: Cache = pstate(ctx, "links-cache"); - c.at = f64::NEG_INFINITY; + let mut c: std::sync::Arc = pstate(ctx, "links-cache"); + std::sync::Arc::make_mut(&mut c).at = f64::NEG_INFINITY; set_pstate(ctx, "links-cache", c); - set_options(ctx, |o| { - o.info = true; - if hidden { - o.show = "all"; - } - }); + set_options(ctx, |o| o.info = true); if let Err(e) = crate::panel_docking::reveal_panel(app, ID) { app.status(e); } @@ -607,12 +596,22 @@ fn click(app: &mut VectorcraftApp, ctx: &egui::Context, rows: &[Value], id: u64, pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { let t = Tokens::get(ui.ctx()); - let o = options(ui.ctx()); + let mut o = options(ui.ctx()); super::layers::show_thumbs_of(app.session.active().map(|st| st.uid)); - let Some(cache) = cached(app, ui.ctx(), &o) else { + let Some(mut cache) = cached(app, ui.ctx(), &o) else { widgets::dim_label(ui, tl!("No document")); return; }; + // A Show filter that leaves out the row `show_selected_image` asks for goes back to Show All, + // decided from the rows this frame draws and scrolls through. + let scroll_to: Option = pstate(ui.ctx(), "links-scroll-to"); + let listed = |cache: &Cache, id: u64| cache.list["links"].as_array().is_some_and(|rows| rows.iter().any(|r| r["id"].as_u64() == Some(id))); + if scroll_to.filter(|id| o.show != "all" && !listed(&cache, *id)).is_some() { + set_options(ui.ctx(), |o| o.show = "all"); + o = options(ui.ctx()); + let Some(all) = cached(app, ui.ctx(), &o) else { return }; + cache = all; + } let Some(st) = app.session.active() else { return }; let doc = st.doc.clone(); let thumbs = super::layers::ThumbSource::of(app, st, &doc); @@ -632,7 +631,6 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { return; } // The row that `show_selected_image` asks the list to scroll to, once. - let scroll_to: Option = pstate(ui.ctx(), "links-scroll-to"); if scroll_to.is_some() { set_pstate::>(ui.ctx(), "links-scroll-to", None); } diff --git a/crates/ui-egui/src/panels/tests_links.rs b/crates/ui-egui/src/panels/tests_links.rs index 9bb87d1fa2..1fda3486a5 100644 --- a/crates/ui-egui/src/panels/tests_links.rs +++ b/crates/ui-egui/src/panels/tests_links.rs @@ -242,6 +242,30 @@ fn opening_the_panel_on_the_selected_image_reads_the_list_again() { assert_eq!(drawn(&mut app, 2.1), 2, "the missing image's row and its Link Info are drawn"); } +/// The Show filter is set back to Show All from the rows the panel draws, not from the files as +/// they were when the panel was asked to open: a missing image restored before the list is drawn +/// still gets its row. +#[test] +fn opening_the_panel_on_the_selected_image_decides_the_filter_from_the_drawn_rows() { + let dir = Folder::new("show-selected-drawn"); + let (mut app, linked, _) = app(&dir); + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + let drawn = |app: &mut VectorcraftApp, time: f64| { + let raw = egui::RawInput { time: Some(time), ..Default::default() }; + let texts = super::tests_appearance::frame_raw(&ctx, app, raw, super::links::show); + texts.iter().filter(|(t, _)| t == "linked.png").count() + }; + app.run("select.set", json!({"ids": [linked]})).unwrap(); + click_menu_item(&mut app, &ctx, "Show Missing", 1.0); + let bytes = std::fs::read(dir.0.join("linked.png")).unwrap(); + std::fs::remove_file(dir.0.join("linked.png")).unwrap(); + super::links::show_selected_image(&mut app, &ctx); + std::fs::write(dir.0.join("linked.png"), bytes).unwrap(); + assert_eq!(drawn(&mut app, 2.0), 2, "the restored image's row and its Link Info are drawn"); + assert_eq!(super::pstate::>(&ctx, "links-scroll-to"), None, "the scroll request is used on the row"); +} + /// A frame that fetches nothing keeps the stored rows and Link Info as they are, without a copy; the /// two-second recheck, another first selected image and an edit each store a new cache. #[test]