From 612f965679fafae87a7a89b87a750ff57bbe36a5 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 17 Nov 2026 18:53:36 -0800 Subject: [PATCH 1/4] Control bar: the Linked File or Embedded label opens the Links panel With one image selected, the Control bar's object label, Linked File or Embedded, is an underlined link. A click on it shows the Links panel wherever it is docked or floats, scrolls the list to the image's row and shows the image's details in Link Info. The help page (https://helpx.adobe.com/illustrator/using/links-info.html) describes clicking this label for a selected linked object as a way to open the Links panel. VectorCraft's own rules: the Embedded label opens the panel too; the click opens Link Info when it was closed; and a Show filter that leaves out the image's row goes back to Show All. The panel's sort, thumbnail size and DCS option keep their settings, and a panel that is already shown stays where it is. The label of any other object stays plain text. --- crates/ui-egui/src/chrome/control_bar.rs | 39 ++++++----- crates/ui-egui/src/chrome/tests.rs | 42 ++++++++++++ crates/ui-egui/src/panels/links.rs | 33 ++++++++++ crates/ui-egui/src/panels/tests_links.rs | 83 ++++++++++++++++++++++++ docs/target-app-parity.md | 1 + 5 files changed, 181 insertions(+), 17 deletions(-) diff --git a/crates/ui-egui/src/chrome/control_bar.rs b/crates/ui-egui/src/chrome/control_bar.rs index 71b737dbfc..534c4ed516 100644 --- a/crates/ui-egui/src/chrome/control_bar.rs +++ b/crates/ui-egui/src/chrome/control_bar.rs @@ -922,6 +922,19 @@ pub fn control_bar(app: &mut VectorcraftApp, ui: &mut Ui) { } } +/// The Control bar's object label, `label`, while the bar has room for it. For one selected image +/// (`image`: Linked File or Embedded) it is an underlined link, and a click opens the Links panel on +/// the image with its Link Info. +fn object_label(app: &mut VectorcraftApp, ui: &mut Ui, label: egui::RichText, image: bool) { + if ui.available_width() < widgets::text_width(ui, label.clone()) { + left_out(ui); + } else if !image { + ui.label(label); + } else if ui.link(label.underline()).clicked() { + crate::panels::links::show_selected_image(app, ui.ctx()); + } +} + /// The Control bar's gripper, controls and panel menu, in the bar `bar`. A `floating` bar clips its /// controls to the room left of the panel menu button, and always shows the button. fn contents(app: &mut VectorcraftApp, ui: &mut Ui, t: &Tokens, bar: egui::Rect, dock_room: egui::Rect, floating: bool) { @@ -954,30 +967,22 @@ fn contents(app: &mut VectorcraftApp, ui: &mut Ui, t: &Tokens, bar: egui::Rect, let units = app.session.general_unit(); let first = sel.first().and_then(|id| st.doc.node(*id)); let anchors = anchor_controls(app); - let label = match first { - _ if app.session.tool_id() == "artboard" => tl!("Artboard"), - Some(_) if sel.len() == 1 && anchors != AnchorControls::None => { - tl!("Anchor Point") - } + // The label, and whether it names one selected image. + let (label, image) = match first { + _ if app.session.tool_id() == "artboard" => (tl!("Artboard"), false), + Some(_) if sel.len() == 1 && anchors != AnchorControls::None => (tl!("Anchor Point"), false), Some(vectorcraft_doc::Node { kind: NodeKind::Image(im), .. }) if sel.len() == 1 => { if im.link.is_some() { - tl!("Linked File") + (tl!("Linked File"), true) } else { - tl!("Embedded") + (tl!("Embedded"), true) } } - Some(n) if sel.len() == 1 && crate::panels::image_trace::is_trace(n) => { - tl!("Image Tracing") - } - _ => tl!(crate::panels::appearance::object_label(app)), + Some(n) if sel.len() == 1 && crate::panels::image_trace::is_trace(n) => (tl!("Image Tracing"), false), + _ => (tl!(crate::panels::appearance::object_label(app)), false), }; let has_first = first.is_some(); - let label = egui::RichText::new(label).font(theme::semibold(12.0)).color(t.text); - if ui.available_width() >= widgets::text_width(ui, label.clone()) { - ui.label(label); - } else { - left_out(ui); - } + object_label(app, ui, egui::RichText::new(label).font(theme::semibold(12.0)).color(t.text), image); // With the Artboard tool in use, the bar shows the active artboard's controls in place // of the object controls. let (artboard_options, transform) = (group_on(app, "artboardOptions"), group_on(app, "transform")); diff --git a/crates/ui-egui/src/chrome/tests.rs b/crates/ui-egui/src/chrome/tests.rs index 61c67e6a70..64798ece36 100644 --- a/crates/ui-egui/src/chrome/tests.rs +++ b/crates/ui-egui/src/chrome/tests.rs @@ -4049,6 +4049,48 @@ fn select_similar_stays_out_while_an_image_control_is_left_out() { assert!(seen, "a wide bar shows the button after the image's controls"); } +/// A click on the Control bar's Linked File or Embedded label shows the Links panel, in an expanded +/// dock and in one collapsed to icons; the label of any other object stays plain text. +#[test] +fn the_linked_file_and_embedded_labels_open_the_links_panel() { + crate::i18n::set_current(crate::i18n::Lang::EN); + let mut app = crate::VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 400, "height": 200})).unwrap(); + let img = image::RgbaImage::from_pixel(20, 20, image::Rgba([0, 0, 0, 255])); + let mut png = vec![]; + img.write_to(&mut std::io::Cursor::new(&mut png), image::ImageFormat::Png).unwrap(); + let dir = vectorcraft_testkit::temp_dir("control-bar-image-label"); + std::fs::create_dir_all(&dir).unwrap(); + let path = dir.join("square.png"); + std::fs::write(&path, &png).unwrap(); + use crate::tests_removeanchors::{at, click_control, control_frame}; + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + let links = crate::panels::links::ID; + // Closes the Links panel, clicks `name` on the bar and answers whether the panel shows. + let click = |app: &mut crate::VectorcraftApp, name: &str| { + app.run("window.panel.close", json!({"panel": links})).ok(); + app.ui.open_panel = None; + assert!(!crate::panel_docking::visible(&app.ui, links), "{name}: the panel is closed first"); + let pos = at(&control_frame(app, &ctx, vec![]), name); + click_control(app, &ctx, pos); + crate::panel_docking::visible(&app.ui, links) + }; + 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(); + 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); + app.run("select.set", json!({ "ids": embedded })).unwrap(); + assert!(click(&mut app, "Embedded"), "collapsed {collapsed}, status: {}", app.ui.status); + 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"); + } +} + /// The Anchor Points group holds Convert and Anchors for direct-selected anchors; off, the bar keeps /// its Anchor Point label. #[test] diff --git a/crates/ui-egui/src/panels/links.rs b/crates/ui-egui/src/panels/links.rs index 611c9e472a..7eaf6da8c2 100644 --- a/crates/ui-egui/src/panels/links.rs +++ b/crates/ui-egui/src/panels/links.rs @@ -82,6 +82,31 @@ fn set_options(ctx: &egui::Context, f: impl FnOnce(&mut Options)) { set_pstate(ctx, "links-options", o); } +/// 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. +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); + set_options(ctx, |o| { + o.info = true; + if hidden { + o.show = "all"; + } + }); + if let Err(e) = crate::panel_docking::reveal_panel(app, ID) { + app.status(e); + } +} + /// The rows to show (cached per document revision, the files looked at again every [`RECHECK`] /// seconds) and the Link Info of the first selected image when the section is open. fn cached(app: &mut VectorcraftApp, ctx: &egui::Context, o: &Options) -> Option { @@ -566,11 +591,19 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { super::empty_state(ui, "link", tl!("No images"), detail); 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); + } egui::ScrollArea::vertical().max_height(260.0).auto_shrink([false, true]).show(ui, |ui| { let h = o.thumb.max(16.0) + 6.0; for r in rows { let Some(id) = r["id"].as_u64() else { continue }; let (rect, resp) = ui.allocate_exact_size(vec2(ui.available_width(), h), Sense::click()); + if scroll_to == Some(id) { + ui.scroll_to_rect(rect, Some(egui::Align::Center)); + } if !ui.is_rect_visible(rect) { continue; } diff --git a/crates/ui-egui/src/panels/tests_links.rs b/crates/ui-egui/src/panels/tests_links.rs index 781c4f5840..fbee40fbc7 100644 --- a/crates/ui-egui/src/panels/tests_links.rs +++ b/crates/ui-egui/src/panels/tests_links.rs @@ -136,6 +136,89 @@ fn the_panel_lists_the_images_with_link_info_for_the_selected_one() { } } +/// Click the flyout item `name`, checked or not (frames at `time` and just after). +fn click_menu_item(app: &mut VectorcraftApp, ctx: &egui::Context, name: &str, time: f64) { + let frame = |app: &mut VectorcraftApp, events: Vec, time: f64| { + super::tests_appearance::frame_raw(ctx, app, egui::RawInput { events, time: Some(time), ..Default::default() }, super::links::menu) + }; + let texts = frame(app, vec![], time); + let item = texts.iter().find(|(t, _)| t.trim_start_matches('✓').trim() == name); + let at = item.unwrap_or_else(|| panic!("`{name}` not drawn: {texts:?}")).1.center(); + let button = |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }; + for (i, e) in [egui::Event::PointerMoved(at), button(true), button(false)].into_iter().enumerate() { + frame(app, vec![e], time + 0.01 * (i + 1) as f64); + } +} + +/// Opening the panel on the selected image (the Control bar's Linked File or Embedded label) opens +/// Link Info when it was closed, and sets a Show filter that leaves out the image's row back to +/// Show All; a filter that lists the row stays. +#[test] +fn opening_the_panel_on_the_selected_image_shows_its_row_and_link_info() { + let dir = Folder::new("show-selected"); + let (mut app, linked, embedded) = app(&dir); + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + let text = |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.into_iter().map(|(t, _)| t).collect::>().join("\n") + }; + app.run("select.set", json!({"ids": [linked]})).unwrap(); + click_menu_item(&mut app, &ctx, "Show Link Info", 1.0); + click_menu_item(&mut app, &ctx, "Show Embedded", 2.0); + let before = text(&mut app, 3.0); + assert!(!before.contains("linked.png") && !before.contains("Location"), "the filter hides the row, Link Info is closed: {before}"); + app.run("window.panel.close", json!({"panel": super::links::ID})).ok(); + super::links::show_selected_image(&mut app, &ctx); + assert!(crate::panel_docking::visible(&app.ui, super::links::ID), "status: {}", app.ui.status); + let after = text(&mut app, 4.0); + assert!(after.contains("linked.png") && after.contains("embedded.png"), "Show All lists every row: {after}"); + assert!(after.contains("Location") && after.contains("300 × 200 px"), "Link Info shows the linked image: {after}"); + // An embedded image under Show Embedded keeps the filter. + app.run("select.set", json!({"ids": [embedded]})).unwrap(); + click_menu_item(&mut app, &ctx, "Show Link Info", 5.0); + click_menu_item(&mut app, &ctx, "Show Embedded", 6.0); + super::links::show_selected_image(&mut app, &ctx); + assert!(crate::panel_docking::visible(&app.ui, super::links::ID), "an open panel stays open"); + let embedded_only = text(&mut app, 7.0); + assert!(embedded_only.contains("embedded.png") && !embedded_only.contains("linked.png"), "Show Embedded stays: {embedded_only}"); + assert!(embedded_only.contains("Effective PPI"), "Link Info shows the embedded image: {embedded_only}"); +} + +/// Opening the panel on the selected image scrolls the list to the image's row when it is out of +/// view. +#[test] +fn opening_the_panel_on_the_selected_image_scrolls_to_its_row() { + let dir = Folder::new("show-selected-scroll"); + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 400, "height": 300})).unwrap(); + // The panel lists the image placed first last, below the list's view. + let mut first = None; + for i in 0..20 { + let path = dir.file(&format!("img{i:02}.png"), &png(10, 10)); + let id = app.run("file.place", json!({"path": path, "at": [10 + 15 * i, 100]})).unwrap()["ids"][0].as_u64().unwrap(); + first.get_or_insert(id); + } + app.run("select.set", json!({"ids": [first]})).unwrap(); + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + // How many times the first image's name is drawn: its row while in view, and Link Info. + 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 == "img00.png").count() + }; + let before = drawn(&mut app, 1.0); + assert_eq!(drawn(&mut app, 2.0), before, "the list stays at the top"); + super::links::show_selected_image(&mut app, &ctx); + // The list scrolls over the frames after the one that asks. + for time in [3.0, 4.0, 5.0] { + drawn(&mut app, time); + } + assert_eq!(drawn(&mut app, 6.0), before + 1, "the row scrolled into view"); +} + /// Copy Info copies the file names of the selected links, or of `ids` in the order given, one per /// line; it is off with nothing selected, and a bad `ids` leaves the clipboard as it was. #[test] diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index ef83de54ad..6fdd63b890 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -2133,6 +2133,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - Missing linked files can be looked for in a folder and its subfolders: Find in Folder… in the Linked File Not Found dialog and in the Links panel menu lists the files with each one's name, those with the size and contents saved with the link first, and relinks the files chosen, copying an image's file into the document's folder when asked, without replacing a file there (`links.findFiles`, `links.relink {copy}`). In the Links panel it looks for the selected linked files when any are selected. - The Links panel's Relink… opens a Relink dialog whose Replace menu picks which links take the new file: Selected Instances (the selected images, as before), All Instances (every image linked to the same file), Missing Links from This Folder (then every other missing link whose file name is in the new file's folder) and Each Link Separately (a file for each selected link in turn). Each relinks as one undo step (`links.relink {scope}`, `ui.relinkDialog`). Relink to Folder… stays as it is. - The Links panel menu's Copy Info ([Links panel](https://helpx.adobe.com/illustrator/desktop/add-and-import-files/import-from-other-apps/links-panel-in-illustrator.html)) copies the selected link's file name to the clipboard (`links.copyInfo`). VectorCraft's own rules: with several rows selected it copies one name per line in the order the panel shows them, an embedded image gives the name its row shows, and the item is off with no row selected. + - With one image selected, the Control bar's object label, Linked File or Embedded, is an underlined link, and a click on it opens the Links panel wherever it is docked, scrolls the list to the image's row, which shows selected, and shows the image's details in Link Info. The help page () describes clicking this label for a selected linked object as a way to open the Links panel. VectorCraft's own rules: the Embedded label opens the panel too, the click opens Link Info when it was closed and scrolls the list to the row, and a Show filter that leaves out the image's row goes back to Show All; the panel's sort, thumbnail size and other options stay as they were (`the_linked_file_and_embedded_labels_open_the_links_panel`, `opening_the_panel_on_the_selected_image_shows_its_row_and_link_info`, `opening_the_panel_on_the_selected_image_scrolls_to_its_row`). - Linked files inside symbols, graph designs, patterns and opacity masks are saved with their paths relative to the document, as linked files in the layers are, so they are found after the document and its files move to another folder together; on open each of those links takes the path where its file was found. Update Links, and opening with Update Links: Automatically, read a modified file again for that art too, and saving a document refreshes its placed copies inside symbols and patterns of the other open documents. Evidence: `links_outside_the_layers_find_their_files_after_the_folder_moves`, `update_links_reads_files_again_inside_symbols_patterns_and_masks`, `saving_a_document_refreshes_its_placed_copies_inside_symbols_and_patterns`. - A linked file that is missing when a moved document is saved keeps the folder its relative path names, instead of a relative path worked out from the out-of-date absolute path, also for a `.ai` file another app wrote (such as `src/`), so the file is found once it is back in that folder. Evidence: `a_missing_link_keeps_its_relative_path_when_the_moved_document_is_saved`, `links_of_an_imported_file_are_found_by_their_relative_folder`, `a_missing_link_of_a_moved_document_keeps_its_relative_place`. - On Windows, a document opened from a mapped network drive finds its links stored with the share's own path (`\\server\share\…`), as the same document opened from the share does; links on other computers stay missing. From 4b04d3e905e77e42e300c01a2cb050a26f2b5538 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 17 Nov 2026 19:42:04 -0800 Subject: [PATCH 2/4] Links: the panel opened from the Control bar label reads its list again The panel keeps its list for two seconds before it looks at the files again. When an image's file changed in that time, for example a deleted file under Show Missing, the label opened the panel on the old list, which lacked the image's row, and the list did not scroll to it. Opening the panel from the label now reads the list again. --- crates/ui-egui/src/panels/links.rs | 5 +++++ crates/ui-egui/src/panels/tests_links.rs | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/crates/ui-egui/src/panels/links.rs b/crates/ui-egui/src/panels/links.rs index 7eaf6da8c2..7951595ba0 100644 --- a/crates/ui-egui/src/panels/links.rs +++ b/crates/ui-egui/src/panels/links.rs @@ -96,6 +96,11 @@ pub(crate) fn show_selected_image(app: &mut VectorcraftApp, ctx: &egui::Context) _ => 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; + set_pstate(ctx, "links-cache", c); set_options(ctx, |o| { o.info = true; if hidden { diff --git a/crates/ui-egui/src/panels/tests_links.rs b/crates/ui-egui/src/panels/tests_links.rs index fbee40fbc7..f7e067aeed 100644 --- a/crates/ui-egui/src/panels/tests_links.rs +++ b/crates/ui-egui/src/panels/tests_links.rs @@ -219,6 +219,29 @@ fn opening_the_panel_on_the_selected_image_scrolls_to_its_row() { assert_eq!(drawn(&mut app, 6.0), before + 1, "the row scrolled into view"); } +/// Opening the panel on the selected image draws a list read after the request, so a row that a +/// file change brought into the Show filter since the list was last read is there to scroll to. +#[test] +fn opening_the_panel_on_the_selected_image_reads_the_list_again() { + let dir = Folder::new("show-selected-fresh"); + let (mut app, linked, _) = app(&dir); + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + // How many times the linked image's name is drawn: its row, and Link Info. + 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); + assert_eq!(drawn(&mut app, 2.0), 1, "Link Info only: nothing is missing yet"); + std::fs::remove_file(dir.0.join("linked.png")).unwrap(); + // Within the time the panel keeps its list before it looks at the files again. + super::links::show_selected_image(&mut app, &ctx); + assert_eq!(drawn(&mut app, 2.1), 2, "the missing image's row and its Link Info are drawn"); +} + /// Copy Info copies the file names of the selected links, or of `ids` in the order given, one per /// line; it is off with nothing selected, and a bad `ids` leaves the clipboard as it was. #[test] From 779cbae110121b3dfbf8f266a291fa35df405807 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 17:02:31 -0800 Subject: [PATCH 3/4] Links: the label resets the list the panel reads and decides the filter from the drawn rows - show_selected_image resets the Arc entry that cached() reads, so the next draw reads the list again. It wrote a plain Cache under the same key before, which cached() never saw. - The Show filter goes back to Show All when the rows the panel draws leave out the selected image, instead of from a separate query made when the label was clicked. - reveal_panel brings a panel to the front of its open flyout when another tab of the group is in front. - The Control bar test docks Links beside Layers and checks where it opens, so both passes reach a docked panel. --- crates/ui-egui/src/chrome/tests.rs | 10 ++++++ crates/ui-egui/src/panel_docking.rs | 20 ++++++++++-- crates/ui-egui/src/panel_docking/tests.rs | 22 +++++++++++++ crates/ui-egui/src/panels/links.rs | 38 +++++++++++------------ crates/ui-egui/src/panels/tests_links.rs | 24 ++++++++++++++ 5 files changed, 92 insertions(+), 22 deletions(-) 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] From 2b1aa98c6f766f3456bc953577d0096e6c6f1c45 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 19 Nov 2026 05:12:15 -0800 Subject: [PATCH 4/4] Links: the request to show the selected image applies only in its own document The Control bar label's request to scroll the Links panel to the selected image now carries the document it was made in. A draw of another document drops it and leaves the Show filter as it is, and every draw that reads the request clears it, including one with an empty list. --- crates/ui-egui/src/panels/links.rs | 19 +++++++++++-------- crates/ui-egui/src/panels/tests_links.rs | 24 +++++++++++++++++++++++- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/panels/links.rs b/crates/ui-egui/src/panels/links.rs index 49706b4294..14794de987 100644 --- a/crates/ui-egui/src/panels/links.rs +++ b/crates/ui-egui/src/panels/links.rs @@ -89,7 +89,8 @@ fn set_options(ctx: &egui::Context, f: impl FnOnce(&mut Options)) { /// thumbnail size and DCS option keep their settings. pub(crate) fn show_selected_image(app: &mut VectorcraftApp, ctx: &egui::Context) { let first = selected_images(app).first().copied(); - set_pstate(ctx, "links-scroll-to", first); + let request = app.session.active().map(|st| st.uid).zip(first); + set_pstate(ctx, "links-scroll-to", request); // 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: std::sync::Arc = pstate(ctx, "links-cache"); @@ -602,9 +603,15 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { 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"); + // The row that `show_selected_image` asks for, used by this draw only and only in the document + // it was asked in. A Show filter that leaves the row out goes back to Show All, decided from the + // rows this frame draws and scrolls through. + let request: Option<(u64, u64)> = pstate(ui.ctx(), "links-scroll-to"); + if request.is_some() { + set_pstate::>(ui.ctx(), "links-scroll-to", None); + } + let uid = app.session.active().map(|st| st.uid); + let scroll_to = request.filter(|(doc, _)| Some(*doc) == uid).map(|(_, id)| id); 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"); @@ -630,10 +637,6 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { super::empty_state(ui, "link", tl!("No images"), detail); return; } - // The row that `show_selected_image` asks the list to scroll to, once. - if scroll_to.is_some() { - set_pstate::>(ui.ctx(), "links-scroll-to", None); - } egui::ScrollArea::vertical().max_height(260.0).auto_shrink([false, true]).show(ui, |ui| { let h = o.thumb.max(16.0) + 6.0; for r in rows { diff --git a/crates/ui-egui/src/panels/tests_links.rs b/crates/ui-egui/src/panels/tests_links.rs index 03d333dc10..12a0c293b1 100644 --- a/crates/ui-egui/src/panels/tests_links.rs +++ b/crates/ui-egui/src/panels/tests_links.rs @@ -263,7 +263,29 @@ fn opening_the_panel_on_the_selected_image_decides_the_filter_from_the_drawn_row 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"); + assert_eq!(super::pstate::>(&ctx, "links-scroll-to"), None, "the scroll request is used on the row"); +} + +/// A request to show the selected image applies only in the document it was made in: drawn for +/// another document, the panel keeps its Show filter and drops the request. +#[test] +fn opening_the_panel_on_the_selected_image_leaves_another_document_alone() { + let dir = Folder::new("show-selected-other-doc"); + let (mut app, linked, _) = app(&dir); + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + let text = |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.into_iter().map(|(t, _)| t).collect::>().join("\n") + }; + app.run("select.set", json!({"ids": [linked]})).unwrap(); + click_menu_item(&mut app, &ctx, "Show Missing", 1.0); + super::links::show_selected_image(&mut app, &ctx); + app.run("file.new", json!({"width": 400, "height": 300})).unwrap(); + let other = text(&mut app, 2.0); + assert!(other.contains("Nothing matches the Show filter."), "the other document keeps Show Missing: {other}"); + assert_eq!(super::pstate::>(&ctx, "links-scroll-to"), None, "the request is dropped"); } /// A frame that fetches nothing keeps the stored rows and Link Info as they are, without a copy; the