Merge pull request #10482 from ruchirguitar/feat/resource-library-item-menus

Add item context menus to resource library panels
This commit is contained in:
BFlat authored and GitHub committed 2026-12-02 11:47:18 +07:00
commit 5ed86c0c45
3 files changed
+48 -3

No files matched your search

+11 -3
View File
@@ -24,7 +24,7 @@ use std::rc::Rc;
use craft::behavior::{IconId, Selection, SelectionModel};
use craft::host::PickRequest;
use craft::theme::variant::Tone;
use craft::ui::contract::{Bind, MemoKey, MemoProps, SelectMode, Show as _, ShowContainer as _, Trigger};
use craft::ui::contract::{Bind, Entry, MemoKey, MemoProps, SelectMode, Show as _, ShowContainer as _, Trigger};
use craft::ui::menu::{Menu, MenuItem, PanelRow};
use craft::ui::notices::{Notice, NoticeAction, NoticeLayout};
use craft::ui::patterns::presets::{PresetBrowser, PresetEvent, PresetFns, PresetRow, PresetRowMenu, PresetSource, PresetState, PresetView};
@@ -729,7 +729,8 @@ fn body<K: LibraryKind>(app: &mut VectorcraftApp, ui: &mut Ui, id: &str) {
let title = library_name(id, &name).to_string();
// The footer stays under the browser, which scrolls in the room left above it.
let footer_out = RefCell::new(None);
let any = !selection.items.is_empty() && can_add(app, K::KIND);
let can_add = can_add(app, K::KIND);
let any = !selection.items.is_empty() && can_add;
let mut shown = Panel::new(title.clone())
.collection_body()
.footer(|ui, _| *footer_out.borrow_mut() = Some(footer_bar::<K>(any).show_footer(ui)))
@@ -740,7 +741,9 @@ fn body<K: LibraryKind>(app: &mut VectorcraftApp, ui: &mut Ui, id: &str) {
.select(SelectMode::Multi)
.selection(Bind::given(selection.clone()))
.empty(tl!("This library is empty."))
.row_menu(PresetRowMenu::Off)
.row_menu(PresetRowMenu::Host)
.row_items(move |_: &LibraryKey| vec![Entry::new("ui.libraryPanel.add".to_owned(), K::ADD).enabled(can_add)])
.host_version(u64::from(can_add))
.drags(K::drags())
.show(ui)
});
@@ -750,6 +753,11 @@ fn body<K: LibraryKind>(app: &mut VectorcraftApp, ui: &mut Ui, id: &str) {
for event in events {
match event {
PresetEvent::Selection(change) => chosen.apply(change),
PresetEvent::Menu { target, command, .. } if command == "ui.libraryPanel.add" && can_add => {
let names =
if chosen.items.contains(&target) { chosen.items.iter().map(|key| key.name.clone()).collect() } else { vec![target.name] };
K::add(app, id, names);
}
// A plain click on an item also adds and applies it; folders and modifier clicks only select.
PresetEvent::Select { key, mods, .. } if !key.folder && !mods.shift && !mods.cmd => clicked = Some(key.name),
_ => {}
@@ -182,6 +182,42 @@ fn modifier_clicks_select_and_add_to_swatches_adds_the_selection() {
assert!(selected_names(&app, "library:swatches:brights").is_empty());
}
#[test]
fn library_item_menu_adds_the_target_or_its_selection_without_applying_paint() {
for view in ["smallList", "smallThumb"] {
for target in ["Clay 1", "Clay 3"] {
let mut app = app();
let ctx = context();
app.run("window.swatchLibrary", json!({"library": "earth-tones"})).unwrap();
let panel = shown(&app);
app.run("ui.libraryPanel", json!({"panel": panel, "view": view})).unwrap();
click(&mut app, &ctx, "Clay 1", Modifiers::COMMAND, 0.0);
click(&mut app, &ctx, "Clay 2", Modifiers::COMMAND, 1.0);
let paint = app.session.paint.fill.clone();
let undo = undo_len(&app);
let draw = |app: &mut VectorcraftApp, ui: &mut Ui| show(app, ui, &panel);
let (_, at) = control(&mut app, &ctx, &draw, target);
let button = |pressed| Event::PointerButton { pos: at, button: PointerButton::Secondary, pressed, modifiers: Modifiers::NONE };
draw_frame(&mut app, &ctx, &draw, vec![Event::PointerMoved(at)]);
draw_frame(&mut app, &ctx, &draw, vec![button(true)]);
draw_frame(&mut app, &ctx, &draw, vec![button(false)]);
draw_frame(&mut app, &ctx, &draw, vec![]);
let out = draw_frame(&mut app, &ctx, &draw, vec![]);
let nodes = &out.platform_output.accesskit_update.as_ref().unwrap().nodes;
let (_, row) = nodes.iter().find(|(_, n)| n.role() == egui::accesskit::Role::MenuItem && n.label() == Some("Add to Swatches")).unwrap();
let bounds = row.bounds().unwrap();
assert_eq!(undo_len(&app), undo, "opening the item menu must not edit the drawing");
let expected = if target == "Clay 1" { vec!["Clay 1", "Clay 2"] } else { vec!["Clay 3"] };
assert_eq!(selected_names(&app, &panel), expected);
click_at(&mut app, &ctx, &draw, Pos2::new((bounds.x0 + bounds.x1) as f32 * 0.5, (bounds.y0 + bounds.y1) as f32 * 0.5));
for name in ["Clay 1", "Clay 2", "Clay 3"] {
assert_eq!(app.session.doc().unwrap().doc.swatch(name).is_some(), expected.contains(&name), "{view}: {target}: {name}");
}
assert_eq!(app.session.paint.fill, paint);
}
}
}
#[test]
fn adding_selected_library_items_requires_an_open_drawing() {
let mut app = app();
+1
View File
@@ -528,6 +528,7 @@ next unit in the order a right-click on a ruler lists them, from Feet back to Po
| Make Compound Path on a group (such as outlined type) keeps its backmost path's paint; compound paths joined into one keep their holes | done | #1537 |
| Symbol libraries: Window › Symbol Libraries (Basic Shapes, UI Frames, Map Markers, Inventory Icons, Skill Icons, User Defined, Other Library…, Save Symbols…) and the Symbols panel's Symbol Libraries Menu button and its menu's Open Symbol Library / Save Symbol Library…; a click on a library symbol adds it to the document's Symbols (one undo step, it becomes the current symbol), Shift/Cmd-clicks select for Add to Symbols, and a symbol dragged onto the canvas is added and placed where it is dropped | done | [public source](https://helpx.adobe.com/illustrator/desktop/manage-objects/traces-mockups-symbols/create-or-import-symbol-libraries.html), [Symbols panel options](https://helpx.adobe.com/illustrator/desktop/manage-objects/traces-mockups-symbols/symbols-panel-options.html), [placing from a library](https://helpx.adobe.com/illustrator/desktop/manage-objects/traces-mockups-symbols/create-and-place-symbols.html); `window.symbolLibrary`, `window.symbolLibrary.other`, `ui.saveSymbolLibrary` (dialog `saveSymbolLibrary`), `window.userSymbolLibrary1`…`10`; `panels::tests_symbol_libraries`; five built-in libraries (Basic Shapes, UI Frames with default 9-slice, Map Markers, Inventory Icons, Skill Icons; original, generated in code) |
| Brush libraries: Window › Brush Libraries (Art Ribbons, Ink and Wash, Calligraphic Nibs, Pressure Sensitive, Bristle Brushes, Pattern Borders, Decorative, Scatter Shapes, Stipple, Game Trails, Energy Beams, Dry Media, Tech Circuit, Engraving, Arrows, User Defined, Other Library…, Save Brushes…) and the Brushes panel's Brush Libraries Menu button and its menu's Open Brush Library / Save Brush Library…; a click on a library brush adds it to the document's Brushes (one undo step, it becomes the current brush, and selected paths take it in the same step), Shift/Cmd-clicks select for Add to Brushes, a brush dragged onto a path is added and applied to it and one dragged onto the Brushes panel is added; thumbnails render with the library's patterns and symbols | done | [public source](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/apply-and-edit-strokes/create-new-brush-libraries.html), [import brushes](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/apply-and-edit-strokes/import-brushes-from-brush-libraries-or-other-files.html), [Brushes panel overview](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/apply-and-edit-strokes/brushes-panel-overview.html); `window.brushLibrary`, `window.brushLibrary.other`, `ui.saveBrushLibrary` (dialog `saveBrushLibrary`), `window.userBrushLibrary1`…`10`; `panels::tests_brush_libraries`; fifteen built-in libraries (original, generated in code) |
| Swatch, Brush, Symbol and Graphic Style Library item menus | done | In list and thumbnail views, the item menu offers the same Add to action as the footer. It adds the current selection when the target is selected or the target alone otherwise. The action requires an open drawing. |
| Brushes panel menu › Options of Selected Object…: changes the selected brushed paths' brush settings on those paths only, leaving the brush and its other strokes as they are; the brush type's options dialog opens without the Name row (and without an art brush's scale and direction options or a pattern brush's tiles), and OK sends only the values changed in it | done | [Modify brushes](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/apply-and-edit-strokes/modify-brushes.html), [Brushes panel overview](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/apply-and-edit-strokes/brushes-panel-overview.html); `brush.objectOptions`, `ui.brushObjectOptions`; which fields a path can set is VectorCraft's own choice (calligraphic, scatter, art and pattern brushes; not bristle); `options_of_selected_object_*` tests in `crates/engine/src/tests/brushsym.rs` and `crates/ui-egui/src/dialogs/brush_options/tests.rs`, brush tests in `crates/brush/src/tests.rs` |
| Symbols panel: New Symbol opens Symbol Options (Name) before making the symbol; Alt-click skips it | partial | #1560 (#1566); Registration 9-point grid in Symbol Options (`symbol.new` / `symbol.place`); Export Type (Graphic / Movie Clip) and Enable Guides for 9-Slice Scaling (scaled instances keep their corners; in symbol editing mode the guides are drawn over the art and the Selection tool drags them); Symbol Type (Dynamic Symbol / Static Symbol, new symbols dynamic; #4938); Align to Pixel Grid (`alignToPixelGrid` on `symbol.new` / `symbol.options`: the art snaps at the symbol's natural size and instances at that size stay on whole points; [Aligning symbols to pixel grid](https://web.archive.org/web/20220911143322/https://helpx.adobe.com/pdf/cs6/illustrator_reference.pdf#page=28)) |
| Dynamic symbols: an instance changes the fill, stroke, opacity and blend of objects in its symbol's art and stays linked; Reset in the Properties panel's Quick Actions and the Symbols panel menu (Reset Symbol Instance) | partial | #4938; `symbol.instance.setAppearance` (by child-index path) and `symbol.instance.reset`; redefining keeps the changes, Break Link bakes them; Direct Selection of a path, compound path or type object inside an instance, with the Fill/Stroke controls setting its fill or stroke (solid, gradient or pattern) and the Transparency panel setting its opacity and blend, is on canvas (#6308); `.ai` editing data keeps dynamic symbols and their instance changes when VectorCraft writes and reads it (#8747); on-canvas editing beyond fill, stroke, opacity and blend, and reading other apps' dynamic symbol records, remain |