Graphic Styles panel: add item right-click context menu (Options, Duplicate, Delete, Redefine, Break Link)

This commit is contained in:
ruchirguitar
2026-11-19 23:17:37 +05:30
parent bedbbad72f
commit 83aacb0946
3 changed files with 262 additions and 9 deletions
+256 -8
View File
@@ -24,7 +24,10 @@ use serde_json::{Value, json};
use vectorcraft_color::{BlendMode, Color, Paint};
use vectorcraft_doc::style_libs::STYLE_LIBRARIES;
use vectorcraft_doc::text::{CharStyle, TextObject};
use vectorcraft_doc::{Appearance, AppearanceItem, Document, FillLayer, GraphicStyle, Node, NodeId, NodeKind, PatternDef, StrokeLayer, StyleLibrary};
use vectorcraft_doc::{
Appearance, AppearanceItem, DEFAULT_GRAPHIC_STYLE, Document, FillLayer, GraphicStyle, Node, NodeId, NodeKind,
PatternDef, StrokeLayer, StyleLibrary,
};
use vectorcraft_engine::cmd::stylelib;
use vectorcraft_engine::cmd::swatchlib::LibraryInfo;
use vectorcraft_geom::{Affine, Point, shapes};
@@ -484,21 +487,88 @@ fn zone_input(ui: &Ui, zone: &Response, d: &Document, ev: &mut Events) {
}
}
/// An item's right-click context menu in the Graphic Styles panel.
fn item_context_menu(app: &mut VectorcraftApp, ui: &mut Ui, name: &str, sel: &[String]) {
let is_default = name == DEFAULT_GRAPHIC_STYLE;
let is_multi = sel.len() > 1 && sel.contains(&name.to_string());
let targets: Vec<String> = if is_multi {
let doc = app.session.active().map(|st| st.doc.clone());
if let Some(d) = &doc {
d.graphic_styles.iter().filter(|g| sel.contains(&g.name)).map(|g| g.name.clone()).collect()
} else {
sel.to_vec()
}
} else {
vec![name.to_string()]
};
let doomed: Vec<String> = targets.iter().filter(|s| *s != DEFAULT_GRAPHIC_STYLE).cloned().collect();
let can_options = !is_default && !is_multi;
if menu_item(ui, tl!("Graphic Style Options…"), can_options, false) {
if let Err(e) = app.run("ui.graphicStyleOptions", json!({ "name": name })) {
app.status(e);
}
ui.close();
}
let duplicate_label = if is_multi { tl!("Duplicate Graphic Styles") } else { tl!("Duplicate Graphic Style") };
if menu_item(ui, duplicate_label, true, false) {
duplicate(app, ui.ctx(), &targets);
ui.close();
}
let delete_label = if is_multi { tl!("Delete Graphic Styles") } else { tl!("Delete Graphic Style") };
let can_delete = !is_default && !doomed.is_empty();
if menu_item(ui, delete_label, can_delete, false) {
let res = if doomed.len() == 1 {
app.run("graphicStyle.delete", json!({ "name": doomed[0] }))
} else {
app.run("graphicStyle.delete", json!({ "names": doomed }))
};
if res.is_ok() {
set_pstate(ui.ctx(), "gs-sel", Vec::<String>::new());
}
ui.close();
}
ui.separator();
let has_art_sel = selection_len(app) > 0;
if menu_item(ui, tl!("Redefine Graphic Style"), has_art_sel, false) {
if let Err(e) = app.run("graphicStyle.redefine", json!({ "name": name })) {
app.status(e);
}
ui.close();
}
let is_linked = app.session.selection_graphic_style().is_some_and(|(g, _)| g.name == name);
if menu_item(ui, tl!("Break Link to Graphic Style"), is_linked, false) {
if let Err(e) = app.run("graphicStyle.breakLink", json!({})) {
app.status(e);
}
ui.close();
}
}
/// The thumbnail grid (Thumbnail View and the Control bar's picker), `sel` outlined.
fn tiles(app: &VectorcraftApp, ui: &mut Ui, s: &Shown, sel: &[String], ev: &mut Events) {
fn tiles(app: &mut VectorcraftApp, ui: &mut Ui, s: &Shown, sel: &mut Vec<String>, ev: &mut Events, in_panel: bool) {
ui.horizontal_wrapped(|ui| {
ui.spacing_mut().item_spacing = vec2(3.0, 3.0);
for (i, g) in s.d.graphic_styles.iter().enumerate() {
let (r, resp) = ui.allocate_exact_size(vec2(TILE, TILE), Sense::click_and_drag());
s.paint(app, ui, r, i);
outline(ui, r, sel.contains(&g.name), resp.hovered());
cell_input(ui, &resp.on_hover_text(&g.name), s.d, i, false, ev);
let resp = resp.on_hover_text(&g.name);
cell_input(ui, &resp, s.d, i, false, ev);
if in_panel {
if resp.secondary_clicked() && !sel.contains(&g.name) {
*sel = vec![g.name.clone()];
set_pstate(ui.ctx(), "gs-anchor", g.name.clone());
set_pstate(ui.ctx(), "gs-sel", sel.clone());
}
resp.context_menu(|ui| item_context_menu(app, ui, &g.name, sel));
}
}
});
}
/// The list views' rows (`row`: height and thumbnail side), `sel` highlighted.
fn rows(app: &VectorcraftApp, ui: &mut Ui, s: &Shown, sel: &[String], row: (f32, f32), ev: &mut Events) {
fn rows(app: &mut VectorcraftApp, ui: &mut Ui, s: &Shown, sel: &mut Vec<String>, row: (f32, f32), ev: &mut Events) {
let t = Tokens::get(ui.ctx());
let (h, side) = row;
for (i, g) in s.d.graphic_styles.iter().enumerate() {
@@ -512,7 +582,14 @@ fn rows(app: &VectorcraftApp, ui: &mut Ui, s: &Shown, sel: &[String], row: (f32,
s.paint(app, ui, th, i);
ui.painter().rect_stroke(th, 0.0, Stroke::new(1.0, t.border), StrokeKind::Outside);
ui.painter().text(pos2(th.right() + 8.0, r.center().y), egui::Align2::LEFT_CENTER, &g.name, egui::FontId::proportional(12.0), t.text);
let resp = resp.on_hover_text(&g.name);
cell_input(ui, &resp, s.d, i, true, ev);
if resp.secondary_clicked() && !sel.contains(&g.name) {
*sel = vec![g.name.clone()];
set_pstate(ui.ctx(), "gs-anchor", g.name.clone());
set_pstate(ui.ctx(), "gs-sel", sel.clone());
}
resp.context_menu(|ui| item_context_menu(app, ui, &g.name, sel));
}
}
@@ -581,7 +658,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
};
let looks = look_hashes(ui.ctx(), app);
let shown = Shown { d: &doc, looks: &looks, preview: pstate(ui.ctx(), "gs-preview") };
let sel = selected(ui.ctx(), &doc);
let mut sel = selected(ui.ctx(), &doc);
let view = app.ui.graphic_styles_view;
let mut ev = Events::default();
// In a sized panel the list fills the space above the footer (#2992), as the Artboards list
@@ -602,8 +679,8 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
return;
}
match view.row() {
Some(row) => rows(app, ui, &shown, &sel, row, &mut ev),
None => tiles(app, ui, &shown, &sel, &mut ev),
Some(row) => rows(app, ui, &shown, &mut sel, row, &mut ev),
None => tiles(app, ui, &shown, &mut sel, &mut ev, true),
}
});
// The drop zone is the part of the list on screen: when the list shrinks to its rows,
@@ -667,8 +744,9 @@ pub(crate) fn picker(app: &mut VectorcraftApp, ui: &mut Ui) {
let looks = look_hashes(ui.ctx(), app);
let shown = Shown { d: &doc, looks: &looks, preview: pstate(ui.ctx(), "gs-preview") };
let mut ev = Events::default();
let mut sel = Vec::new();
ui.set_max_width(6.0 * (TILE + 3.0));
tiles(app, ui, &shown, &[], &mut ev);
tiles(app, ui, &shown, &mut sel, &mut ev, false);
act(app, ui, &shown, ev, true);
}
@@ -1740,4 +1818,174 @@ mod tests {
frame_with(&ctx, click(false), |ui| picker(&mut app, ui));
assert_eq!(app.session.selection_graphic_style().map(|(g, linked)| (g.name.clone(), linked)), Some((name, true)));
}
#[test]
fn right_click_context_menu_in_graphic_styles_panel() {
use egui_kittest::kittest::{NodeT, Queryable};
let mut app = app();
app.run("graphicStyle.new", json!({"name": "Style A"})).unwrap();
app.run("graphicStyle.new", json!({"name": "Style B"})).unwrap();
let mut h = egui_kittest::Harness::builder()
.with_size(vec2(260.0, 400.0))
.with_accessibility_check(false)
.build_ui_state(
|ui, app: &mut VectorcraftApp| {
show(app, ui);
},
app,
);
h.run_steps(2);
// Initially "Style B" was added last; "Style A" is unselected.
let pos_a = h.get_by_label("Style A").rect().center();
// 1. Right-click unselected "Style A"
h.event(egui::Event::PointerMoved(pos_a));
h.event(egui::Event::PointerButton { pos: pos_a, button: egui::PointerButton::Secondary, pressed: true, modifiers: Default::default() });
h.event(egui::Event::PointerButton { pos: pos_a, button: egui::PointerButton::Secondary, pressed: false, modifiers: Default::default() });
h.run_steps(2);
// Right-clicking unselected "Style A" selects it.
let doc = h.state().session.active().unwrap().doc.clone();
assert_eq!(selected(&h.ctx, &doc), vec!["Style A"]);
// Context menu items are displayed
let options = h.get_by_label(" Graphic Style Options…");
let duplicate = h.get_by_label(" Duplicate Graphic Style");
let delete = h.get_by_label(" Delete Graphic Style");
let redefine = h.get_by_label(" Redefine Graphic Style");
let break_link = h.get_by_label(" Break Link to Graphic Style");
assert!(!options.accesskit_node().is_disabled());
assert!(!duplicate.accesskit_node().is_disabled());
assert!(!delete.accesskit_node().is_disabled());
assert!(!redefine.accesskit_node().is_disabled()); // Art is selected
assert!(break_link.accesskit_node().is_disabled()); // Art not linked to Style A
// 2. Click "Duplicate Graphic Style"
duplicate.click();
h.run_steps(3);
let doc = h.state().session.active().unwrap().doc.clone();
assert!(doc.graphic_style("Style A copy").is_some());
assert_eq!(selected(&h.ctx, &doc), vec!["Style A copy"]);
// 3. Apply Style A to the active art and verify Break Link
h.state_mut().run("graphicStyle.apply", json!({"name": "Style A"})).unwrap();
h.run_steps(2);
let pos_a = h.get_by_label("Style A").rect().center();
h.event(egui::Event::PointerMoved(pos_a));
h.event(egui::Event::PointerButton { pos: pos_a, button: egui::PointerButton::Secondary, pressed: true, modifiers: Default::default() });
h.event(egui::Event::PointerButton { pos: pos_a, button: egui::PointerButton::Secondary, pressed: false, modifiers: Default::default() });
h.run_steps(2);
let break_link = h.get_by_label(" Break Link to Graphic Style");
assert!(!break_link.accesskit_node().is_disabled());
break_link.click();
h.run_steps(3);
assert!(h.state().session.selection_graphic_style().is_none());
// 4. Right-click Style A and click "Delete Graphic Style"
let pos_a = h.get_by_label("Style A").rect().center();
h.event(egui::Event::PointerMoved(pos_a));
h.event(egui::Event::PointerButton { pos: pos_a, button: egui::PointerButton::Secondary, pressed: true, modifiers: Default::default() });
h.event(egui::Event::PointerButton { pos: pos_a, button: egui::PointerButton::Secondary, pressed: false, modifiers: Default::default() });
h.run_steps(2);
let delete = h.get_by_label(" Delete Graphic Style");
assert!(!delete.accesskit_node().is_disabled());
delete.click();
h.run_steps(3);
let doc = h.state().session.active().unwrap().doc.clone();
assert!(doc.graphic_style("Style A").is_none());
// Verify one undo step restores it
h.state_mut().run("edit.undo", json!({})).unwrap();
let doc = h.state().session.active().unwrap().doc.clone();
assert!(doc.graphic_style("Style A").is_some());
}
#[test]
fn right_click_context_menu_default_style_disables_options_and_delete() {
use egui_kittest::kittest::{NodeT, Queryable};
let app = app();
let mut h = egui_kittest::Harness::builder()
.with_size(vec2(260.0, 400.0))
.with_accessibility_check(false)
.build_ui_state(
|ui, app: &mut VectorcraftApp| {
show(app, ui);
},
app,
);
h.run_steps(2);
let pos_def = h.get_by_label(DEFAULT_GRAPHIC_STYLE).rect().center();
h.event(egui::Event::PointerMoved(pos_def));
h.event(egui::Event::PointerButton { pos: pos_def, button: egui::PointerButton::Secondary, pressed: true, modifiers: Default::default() });
h.event(egui::Event::PointerButton { pos: pos_def, button: egui::PointerButton::Secondary, pressed: false, modifiers: Default::default() });
h.run_steps(2);
let options = h.get_by_label(" Graphic Style Options…");
let duplicate = h.get_by_label(" Duplicate Graphic Style");
let delete = h.get_by_label(" Delete Graphic Style");
assert!(options.accesskit_node().is_disabled(), "Options disabled on Default Graphic Style");
assert!(!duplicate.accesskit_node().is_disabled(), "Duplicate enabled on Default Graphic Style");
assert!(delete.accesskit_node().is_disabled(), "Delete disabled on Default Graphic Style");
}
#[test]
fn right_click_context_menu_preserves_multiselection_and_works_in_list_view() {
use egui_kittest::kittest::{NodeT, Queryable};
let mut app = app();
app.ui.graphic_styles_view = View::SmallList;
app.run("graphicStyle.new", json!({"name": "Style 1"})).unwrap();
app.run("graphicStyle.new", json!({"name": "Style 2"})).unwrap();
let mut h = egui_kittest::Harness::builder()
.with_size(vec2(260.0, 400.0))
.with_accessibility_check(false)
.build_ui_state(
|ui, app: &mut VectorcraftApp| {
show(app, ui);
},
app,
);
h.run_steps(2);
set_pstate(&h.ctx, "gs-sel", vec!["Style 1".to_string(), "Style 2".to_string()]);
h.run_steps(1);
let pos_2 = h.get_by_label("Style 2").rect().center();
h.event(egui::Event::PointerMoved(pos_2));
h.event(egui::Event::PointerButton { pos: pos_2, button: egui::PointerButton::Secondary, pressed: true, modifiers: Default::default() });
h.event(egui::Event::PointerButton { pos: pos_2, button: egui::PointerButton::Secondary, pressed: false, modifiers: Default::default() });
h.run_steps(2);
let doc = h.state().session.active().unwrap().doc.clone();
assert_eq!(selected(&h.ctx, &doc), vec!["Style 1", "Style 2"]);
let options = h.get_by_label(" Graphic Style Options…");
let duplicate = h.get_by_label(" Duplicate Graphic Styles");
let delete = h.get_by_label(" Delete Graphic Styles");
assert!(options.accesskit_node().is_disabled(), "Options disabled on multi-selection");
assert!(!duplicate.accesskit_node().is_disabled());
assert!(!delete.accesskit_node().is_disabled());
duplicate.click();
h.run_steps(3);
let doc = h.state().session.active().unwrap().doc.clone();
assert!(doc.graphic_style("Style 1 copy").is_some());
assert!(doc.graphic_style("Style 2 copy").is_some());
}
}
+4
View File
@@ -50,6 +50,7 @@ Artboard Options forwards the active Artboard tool's Scale Artwork with Artboard
| Date | Change | Summary |
|---|---|---|
| 2026-11-19 | minor | G12: Graphic Styles panel item context menus (Options…, Duplicate, Delete, Redefine, Break Link); regression tests in crates/ui-egui/src/panels/graphic_styles.rs; scores and estimates unchanged. |
| 2026-11-19 | minor | G12: Place: show progress window with Cancel for slow placed files exceeding 0.4 s (part of #5930, `file.cancelPlace`); indeterminate moving bar, Cancel (Esc) leaves the document unmodified without undo steps; scores and estimates unchanged. |
| 2026-11-18 | minor | G11: SVG export writes physical unit suffixes on the root <svg width="..." height="..."> for documents with physical units (mm, cm, in, pc), preventing drawings from scaling to 75% in external tools and preserving units across round-trips (#864; general unit preference on restart remains open under #864). Estimate 8–15 → 6–13 h. |
| 2026-11-18 | minor | G5: Media Controls joins Basic Shapes, UI Frames, Map Markers, Inventory Icons, Skill Icons and Weather Icons as a seventh built-in symbol library (Play, Pause, Stop, Skip Next, Shuffle, Repeat; original procedural vector symbols generated in code, no default 9-slice); estimate decremented (3–13 → 2–12 h). |
@@ -507,6 +508,8 @@ macOS cursor delivery (#2292) is narrowed to a native host adapter using the exi
## G12 Preferences and panels that don't act yet
- **Implemented and tested (2026-11-19):** Graphic Styles panel thumbnail and list views have item context menus with Graphic Style Options…, Duplicate Graphic Style, Delete Graphic Style, Redefine Graphic Style, and Break Link to Graphic Style. Right-click on an unselected style selects it first; existing multi-selections are preserved and offer plural commands ("Duplicate Graphic Styles", "Delete Graphic Styles"). Default Graphic Style disables Options and Delete; large preview remains accessible when holding the secondary button. Regression tests in `crates/ui-egui/src/panels/graphic_styles.rs` verify right-click selection, command dispatch, and one-step undo. Scores and estimates unchanged.
- **Production workflow addition (2026-11-18):** Window > Production Preflight brings existing output-aware font/overflow checks, linked-file probes and effective image resolution into one panel. Findings select and zoom to affected art, and results recheck after edits, Undo/Redo and external link changes. Resource-art resolution is explicitly not checked. This does not close the remaining G12 gaps or change estimates.
- **Implemented and tested (2026-11-15):** Swatches list rows and thumbnail cells have item context menus with Swatch Options…, Duplicate Swatch and Delete Swatch. Right-click selects the target without painting art; actions use that item's name and are disabled for reserved or missing swatches. All 39 Swatches tests pass, covering all five views, command dispatch, selection and Undo; the regression fails with the menu hooks removed. Rendered list and thumbnail menus were 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. Other panels without context menus remain in G12; estimate unchanged.
@@ -956,6 +959,7 @@ trap, and the defaults (0.25 pt, 100%, 40%) are VectorCraft's own, the pages giv
| Date | Change | Summary |
|---|---|---|
| 2026-11-19 | minor | G12: Graphic Styles panel item context menus (Options…, Duplicate, Delete, Redefine, Break Link); regression tests in crates/ui-egui/src/panels/graphic_styles.rs; scores and estimates unchanged. |
| 2026-11-18 | minor | G12: Layers panel context menu on guide rows (Release Guide, Duplicate, Delete Guide, Lock/Unlock, Hide/Show); regression tests in `crates/ui-egui/src/panels/layers/tests.rs`; scores and estimates unchanged. |
| 2026-11-18 | minor | G4 type: Retype phase 1 (#4934), `type.retype` for outlined text that exactly matches an available font; near matches, the ranked font list and images remain. Scores and estimates unchanged |
| 2026-11-18 | minor | Production Preflight: output-aware fonts, text overflow, linked files and effective image resolution, clickable findings and automatic rechecking; scores and estimates unchanged. See [production-preflight.md](production-preflight.md) for scope and limits. |
File diff suppressed because one or more lines are too long