mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-24 18:32:23 +00:00
Links panel: add row context menu (Relink, Go to Link, Edit Original, Show in Folder)
This commit is contained in:
@@ -586,7 +586,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
let Some(st) = app.session.active() else { return };
|
||||
let doc = st.doc.clone();
|
||||
let thumbs = super::layers::ThumbSource::of(app, st, &doc);
|
||||
let selected = selected_links(app, ui.ctx());
|
||||
let mut selected = selected_links(app, ui.ctx());
|
||||
let rows: &[Value] = cache.list["links"].as_array().map_or(&[], Vec::as_slice);
|
||||
let mut clicked: Option<(u64, egui::Modifiers, bool)> = None;
|
||||
widgets::list_box(ui, |ui| {
|
||||
@@ -659,6 +659,14 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
.and_then(|m| doc.node(NodeId(m)).or_else(|| cache.nested_node(m).map(|n| &**n)))
|
||||
.map(|n| super::layers::shown_name(app, n, crate::i18n::current()));
|
||||
let resp = resp.on_hover_text(status_tip(r, mask));
|
||||
resp.widget_info(|| egui::WidgetInfo::selected(egui::Role::ListItem, ui.is_enabled(), selected.contains(&id), name));
|
||||
if resp.secondary_clicked() && !selected.contains(&id) {
|
||||
click(app, ui.ctx(), rows, id, egui::Modifiers::NONE);
|
||||
selected = selected_links(app, ui.ctx());
|
||||
}
|
||||
resp.context_menu(|ui| {
|
||||
row_context_menu(app, ui, r, id, &cache.list);
|
||||
});
|
||||
if resp.double_clicked() {
|
||||
clicked = Some((id, egui::Modifiers::NONE, true));
|
||||
} else if resp.clicked() {
|
||||
@@ -728,6 +736,78 @@ fn break_link(app: &mut VectorcraftApp, ids: Vec<u64>) {
|
||||
});
|
||||
}
|
||||
|
||||
/// Embed images `ids` (`links.embed`).
|
||||
fn embed_images(app: &mut VectorcraftApp, ids: Vec<u64>) {
|
||||
let r = app.run("links.embed", json!({ "ids": ids }));
|
||||
report(app, r, |v| {
|
||||
let missing = v["missing"].as_array().map_or(0, Vec::len);
|
||||
let n = v["embedded"].as_array().map_or(0, Vec::len);
|
||||
if missing == 0 {
|
||||
crate::i18n::msg_n(n as u64, "Embedded {n} image", "Embedded {n} images", &[])
|
||||
} else {
|
||||
crate::i18n::msg_n(
|
||||
n as u64,
|
||||
"Embedded {n} image; {missing} missing: relink them first",
|
||||
"Embedded {n} images; {missing} missing: relink them first",
|
||||
&[("missing", &missing.to_string())],
|
||||
)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// An item's right-click context menu in the Links panel.
|
||||
fn row_context_menu(app: &mut VectorcraftApp, ui: &mut Ui, r: &Value, id: u64, list: &Value) {
|
||||
let selected = selected_links(app, ui.ctx());
|
||||
let sel = selected_rows(list, &selected);
|
||||
let linked = ids(&sel, |r| r["linked"] == true);
|
||||
let embedded: Vec<&Value> = sel.iter().copied().filter(|r| status_is(r, "embedded")).collect();
|
||||
let modified = ids(&sel, |r| status_is(r, "modified") || (r["preview"] == true && !status_is(r, "missing")));
|
||||
let can_edit = sel.iter().any(|r| r["linked"] == true && !status_is(r, "missing"));
|
||||
let in_canvas = app.session.active().is_some_and(|st| st.doc.node(NodeId(id)).is_some()) && !nested_row(r);
|
||||
|
||||
if menu_item(ui, tl!("Relink…"), !sel.is_empty() && can_pick(app), false) {
|
||||
crate::menus::invoke(app, "ui.relinkDialog", json!({ "ids": ids(&sel, |_| true) }));
|
||||
ui.close();
|
||||
}
|
||||
if menu_item(ui, tl!("Go To Link"), in_canvas, false) {
|
||||
go_to(app, id);
|
||||
ui.close();
|
||||
}
|
||||
if menu_item(ui, tl!("Update Link"), !modified.is_empty(), false) {
|
||||
let r = app.run("links.update", json!({ "ids": modified }));
|
||||
report(app, r, |v| updated_status(v["updated"].as_array().map_or(0, Vec::len)));
|
||||
ui.close();
|
||||
}
|
||||
if menu_item(ui, tl!("Edit Original"), can_edit, false) {
|
||||
let file_arg = if r["linked"] == true && !status_is(r, "missing") { json!({ "id": id }) } else { file_row(&sel) };
|
||||
crate::menus::invoke(app, "links.editOriginal", file_arg);
|
||||
ui.close();
|
||||
}
|
||||
if menu_item(ui, tl!("Show in Folder"), can_edit, false) {
|
||||
let file_arg = if r["linked"] == true && !status_is(r, "missing") { json!({ "id": id }) } else { file_row(&sel) };
|
||||
crate::menus::invoke(app, "links.reveal", file_arg);
|
||||
ui.close();
|
||||
}
|
||||
ui.separator();
|
||||
if status_is(r, "embedded") {
|
||||
if menu_item(ui, tl!("Unembed…"), can_unembed(app, embedded.len()), false) {
|
||||
match &embedded[..] {
|
||||
[r] => {
|
||||
if let Some(id) = r["id"].as_u64() {
|
||||
let name = r["name"].as_str().unwrap_or("Image").to_string();
|
||||
unembed(app, id, &name);
|
||||
}
|
||||
}
|
||||
rows => unembed_several(app, rows.iter().filter_map(|r| r["id"].as_u64()).collect()),
|
||||
}
|
||||
ui.close();
|
||||
}
|
||||
} else if menu_item(ui, tl!("Embed Image"), !linked.is_empty(), false) {
|
||||
embed_images(app, linked);
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
|
||||
/// The params of Edit Original and Show in Folder for the selected rows `sel`: the first linked
|
||||
/// row whose file is there (rows outside the layer tree included), else none (the selection's).
|
||||
fn file_row(sel: &[&Value]) -> Value {
|
||||
@@ -854,21 +934,7 @@ pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
}
|
||||
ui.separator();
|
||||
if menu_item(ui, tl!("Embed Image(s)"), !linked.is_empty(), false) {
|
||||
let r = app.run("links.embed", json!({ "ids": linked }));
|
||||
report(app, r, |v| {
|
||||
let missing = v["missing"].as_array().map_or(0, Vec::len);
|
||||
let n = v["embedded"].as_array().map_or(0, Vec::len);
|
||||
if missing == 0 {
|
||||
crate::i18n::msg_n(n as u64, "Embedded {n} image", "Embedded {n} images", &[])
|
||||
} else {
|
||||
crate::i18n::msg_n(
|
||||
n as u64,
|
||||
"Embedded {n} image; {missing} missing: relink them first",
|
||||
"Embedded {n} images; {missing} missing: relink them first",
|
||||
&[("missing", &missing.to_string())],
|
||||
)
|
||||
}
|
||||
});
|
||||
embed_images(app, linked);
|
||||
}
|
||||
if menu_item(ui, tl!("Unembed…"), can_unembed(app, embedded.len()), false) {
|
||||
match &embedded[..] {
|
||||
|
||||
@@ -584,3 +584,93 @@ fn the_links_menu_items_run_commands() {
|
||||
assert!(ids("Edit").contains("links.editOriginal"));
|
||||
assert!(ids("Window").contains(super::links::ID));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn right_click_context_menu_in_links_panel() {
|
||||
use egui::vec2;
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
|
||||
let dir = Folder::new("context-menu");
|
||||
let (mut app, linked, embedded) = app(&dir);
|
||||
|
||||
let revealed: Rc<RefCell<Vec<String>>> = Rc::default();
|
||||
let rev = revealed.clone();
|
||||
app.services.reveal = Some(Box::new(move |p: &str| {
|
||||
rev.borrow_mut().push(p.to_string());
|
||||
Ok(())
|
||||
}));
|
||||
|
||||
// Initially embedded is selected, linked is unselected
|
||||
assert_eq!(selected(&app), vec![embedded]);
|
||||
|
||||
let mut h = Harness::builder().with_size(vec2(280.0, 500.0)).with_accessibility_check(false).build_ui_state(
|
||||
|ui, app: &mut VectorcraftApp| {
|
||||
super::links::show(app, ui);
|
||||
},
|
||||
app,
|
||||
);
|
||||
h.run_steps(2);
|
||||
|
||||
let right_click = |h: &mut Harness<'static, VectorcraftApp>, label: &str| {
|
||||
let node = h.get_all_by_label(label).find(|n| n.accesskit_node().role() == egui::accesskit::Role::ListItem).unwrap();
|
||||
let pos = node.rect().center();
|
||||
h.event(egui::Event::PointerMoved(pos));
|
||||
h.event(egui::Event::PointerButton { pos, button: egui::PointerButton::Secondary, pressed: true, modifiers: Default::default() });
|
||||
h.event(egui::Event::PointerButton { pos, button: egui::PointerButton::Secondary, pressed: false, modifiers: Default::default() });
|
||||
h.run_steps(2);
|
||||
};
|
||||
|
||||
// 1. Right-click unselected "linked.png": selects it and opens context menu
|
||||
right_click(&mut h, "linked.png");
|
||||
assert_eq!(selected(h.state()), vec![linked], "right-clicking unselected row selects that row first");
|
||||
|
||||
let relink = h.get_by_label(" Relink…");
|
||||
let go_to = h.get_by_label(" Go To Link");
|
||||
let update = h.get_by_label(" Update Link");
|
||||
let edit_orig = h.get_by_label(" Edit Original");
|
||||
let show_folder = h.get_by_label(" Show in Folder");
|
||||
let embed_img = h.get_by_label(" Embed Image");
|
||||
|
||||
// "Relink…" is disabled because app has no pick_open service by default
|
||||
assert!(relink.accesskit_node().is_disabled());
|
||||
// "Go To Link" is enabled because linked node is in canvas document
|
||||
assert!(!go_to.accesskit_node().is_disabled());
|
||||
// "Update Link" is disabled because linked file is not modified
|
||||
assert!(update.accesskit_node().is_disabled());
|
||||
// "Edit Original" and "Show in Folder" are enabled because linked file exists
|
||||
assert!(!edit_orig.accesskit_node().is_disabled());
|
||||
assert!(!show_folder.accesskit_node().is_disabled());
|
||||
// "Embed Image" is enabled because it is a linked image
|
||||
assert!(!embed_img.accesskit_node().is_disabled());
|
||||
|
||||
// 2. Click "Show in Folder" dispatches links.reveal
|
||||
show_folder.click();
|
||||
h.run_steps(2);
|
||||
assert_eq!(revealed.borrow().len(), 1);
|
||||
assert!(revealed.borrow()[0].ends_with("linked.png"));
|
||||
|
||||
// 3. Multi-selection: select both linked and embedded
|
||||
h.state_mut().run("select.set", json!({"ids": [linked, embedded]})).unwrap();
|
||||
assert_eq!(selected(h.state()), vec![linked, embedded]);
|
||||
|
||||
// Right-click "linked.png" while already selected in multi-selection: preserves selection
|
||||
right_click(&mut h, "linked.png");
|
||||
assert_eq!(selected(h.state()), vec![linked, embedded], "right-clicking selected row preserves multi-selection");
|
||||
|
||||
// 4. Click "Go To Link" focuses the art on canvas via go_to
|
||||
let go_to_btn = h.get_by_label(" Go To Link");
|
||||
assert!(!go_to_btn.accesskit_node().is_disabled());
|
||||
go_to_btn.click();
|
||||
h.run_steps(2);
|
||||
assert_eq!(selected(h.state()), vec![linked]);
|
||||
assert!(h.state().view().unwrap().fitted);
|
||||
|
||||
// 5. Right-click embedded image: displays "Unembed…" while "Edit Original" and "Show in Folder" are disabled
|
||||
right_click(&mut h, "embedded.png");
|
||||
assert_eq!(selected(h.state()), vec![embedded]);
|
||||
let unembed_btn = h.get_by_label(" Unembed…");
|
||||
assert!(!unembed_btn.accesskit_node().is_disabled());
|
||||
assert!(h.get_by_label(" Edit Original").accesskit_node().is_disabled());
|
||||
assert!(h.get_by_label(" Show in Folder").accesskit_node().is_disabled());
|
||||
}
|
||||
|
||||
+3
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -503,6 +503,7 @@ next unit in the order a right-click on a ruler lists them, from Feet back to Po
|
||||
| Canvas context menu | done | Right-clicking type opens the canvas menu, with Bullets and Numbering and Spelling. Right-clicking a path offers Object › Path › Simplify… and Smooth…, each opening what its menu item opens (#8344). Artboard rows, library groups and items, the rulers and floating toolbar grips have menus too. Gaps: other panels have none |
|
||||
| Layers panel row context menu | done | Right-clicking a layer/group/object row shows a context menu with Options…, Duplicate, Delete, Lock/Hide Others, Locate Object, and Collect for Export; right-clicking a ruler guide row shows Hide/Show, Lock/Unlock, Release Guides, Delete and Locate Object; right-clicking a blend spine row shows Select, Blend Options…, Reverse Spine, Reverse Front to Back, Expand, Release and Locate Object (#8592). |
|
||||
| Swatches item context menu (G12) | done | List and thumbnail items offer Swatch Options…, Duplicate Swatch and Delete Swatch for the clicked item. Right-click selects without applying paint; reserved/missing items disable actions. All 39 Swatches tests pass, including all five views and Undo; the regression fails with the menu hooks removed. Rendered headless menus inspected. Full workspace CI passed on Linux/WSL on the merged branch (all 13 gates), including the test-helper correction for the upstream compile error tracked in #7727; native Windows full CI has two unchanged engine-test failures. |
|
||||
| Links panel row context menu (G12) | done | Right-clicking a link row presents an item context menu offering Relink…, Go To Link, Update Link, Edit Original, Show in Folder, and Embed Image / Unembed…; right-clicking an unselected row selects it first, preserving selection if already part of a multi-selection. Tests: `panels::tests_links::right_click_context_menu_in_links_panel`. |
|
||||
| SVG Interactivity panel: JavaScript for each object's events and the document's linked JavaScript files, written to SVG and read back as text | done | `svgInteractivity.*`, `ui.javascriptFilesDialog` |
|
||||
| Retype panel | partial | Window › Retype lists the fonts whose glyphs exactly match at least one selected outlined shape, ranked by how many shapes each matches, ten and then five more, with samples in three sizes and the user's own text; a click sets the font on selected live type (`retype.find`, `type.retypeFonts`). Opening it from the Type menu, the context menu and the Properties panel, filtering by font source and favorites, near matches, installed fonts not yet loaded and text in images are missing (#4934) |
|
||||
| Comments, Version History panels | missing | cloud features (out of scope) |
|
||||
|
||||
Reference in New Issue
Block a user