mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-18 14:49:18 +00:00
Swatches: a user swatch whose name starts with [ can be deleted and edited
The panel's Delete Swatch and Swatch Options, in the footer and the panel menu, treated every selected name starting with "[" as reserved, so a user swatch such as [Mine] or a color group such as [Team] could not be deleted or edited there, and New Color Group and Save Swatch Library left them out. The checks now use Swatch::is_reserved, as the engine's swatch.delete and swatch.edit and the item context menu already do, so only None and [Registration] stay protected. Selected names the document no longer holds are left out instead of reaching the command as errors.
This commit is contained in:
@@ -2,16 +2,19 @@ use super::dnd::{group_of, selection};
|
||||
use super::libraries::SwatchLibraries;
|
||||
use super::{Kind, LibraryKind, Ui, Value, VectorcraftApp, View, active_paint, json, library_panel, menu_item, pstate, set_pstate, widgets};
|
||||
|
||||
/// The selected swatches and groups that can be deleted (all but None and Registration).
|
||||
pub(super) fn deletable(sel: &[String]) -> Vec<String> {
|
||||
sel.iter().filter(|n| !n.starts_with('[')).cloned().collect()
|
||||
/// The selected swatches and groups that can be deleted: every color group in the document and
|
||||
/// every swatch that `Swatch::is_reserved` does not reserve (None and Registration). Names the
|
||||
/// document does not hold are left out.
|
||||
pub(super) fn deletable(app: &VectorcraftApp, sel: &[String]) -> Vec<String> {
|
||||
let Some(d) = app.session.active().map(|st| &st.doc) else { return vec![] };
|
||||
sel.iter().filter(|n| d.swatch(n).map_or_else(|| d.swatch_groups.iter().any(|g| g.name == **n), |w| !w.is_reserved())).cloned().collect()
|
||||
}
|
||||
|
||||
/// The selected swatch when exactly one swatch with an editor is selected (not None, Registration
|
||||
/// or a group).
|
||||
fn editable(app: &VectorcraftApp, sel: &[String]) -> Option<String> {
|
||||
pub(super) fn editable(app: &VectorcraftApp, sel: &[String]) -> Option<String> {
|
||||
match sel {
|
||||
[n] if !n.starts_with('[') && app.session.active().is_some_and(|st| st.doc.swatch(n).is_some()) => Some(n.clone()),
|
||||
[n] if app.session.active().and_then(|st| st.doc.swatch(n)).is_some_and(|w| !w.is_reserved()) => Some(n.clone()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -77,7 +80,7 @@ pub(super) fn bottom(app: &mut VectorcraftApp, ui: &mut Ui, sel: &[String]) {
|
||||
}
|
||||
ui.add_space((ui.available_width() - 3.0 * 28.0).max(0.0));
|
||||
if widgets::icon_button(ui, "dc-folder", tl!("New Color Group"), false, 24.0).clicked() {
|
||||
app.run("ui.newColorGroup", json!({"swatches": deletable(sel)})).ok();
|
||||
app.run("ui.newColorGroup", json!({"swatches": deletable(app, sel)})).ok();
|
||||
}
|
||||
// Alt-click skips the dialog; Ctrl/Cmd-click makes a spot color, and Ctrl/Cmd+Shift-click
|
||||
// makes a global process color.
|
||||
@@ -85,7 +88,7 @@ pub(super) fn bottom(app: &mut VectorcraftApp, ui: &mut Ui, sel: &[String]) {
|
||||
new_swatch(app, sel, ui.input(|i| i.modifiers));
|
||||
}
|
||||
// Alt-click deletes without asking.
|
||||
let del = deletable(sel);
|
||||
let del = deletable(app, sel);
|
||||
if widgets::icon_button_enabled(ui, "trash-2", tl!("Delete Swatch"), false, !del.is_empty(), 24.0).clicked() {
|
||||
delete(app, del, ui.input(|i| i.modifiers.alt));
|
||||
}
|
||||
@@ -123,7 +126,7 @@ pub(super) fn new_swatch(app: &mut VectorcraftApp, sel: &[String], m: egui::Modi
|
||||
pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
let view = app.ui.swatches_view;
|
||||
let selected = selection(app, ui);
|
||||
let del = deletable(&selected);
|
||||
let del = deletable(app, &selected);
|
||||
let opts = editable(app, &selected);
|
||||
if menu_item(ui, tl!("New Swatch…"), true, false) {
|
||||
new_swatch(app, &selected, egui::Modifiers::NONE);
|
||||
@@ -198,6 +201,6 @@ pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
ui.separator();
|
||||
ui.menu_button(tl!("Open Swatch Library"), |ui| library_panel::library_menu::<SwatchLibraries>(app, ui));
|
||||
if menu_item(ui, tl!("Save Swatch Library…"), true, false) {
|
||||
app.run("ui.saveSwatchLibrary", json!({ "names": deletable(&selected) })).ok();
|
||||
app.run("ui.saveSwatchLibrary", json!({ "names": deletable(app, &selected) })).ok();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ impl LibraryKind for SwatchLibraries {
|
||||
app.status(e);
|
||||
}
|
||||
if menu_item(ui, tl!("Save Swatch Library…"), app.session.active().is_some(), false) {
|
||||
let names = deletable(&selection(app, ui));
|
||||
let names = deletable(app, &selection(app, ui));
|
||||
app.run("ui.saveSwatchLibrary", json!({ "names": names })).ok();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,7 +281,27 @@ fn delete_asks_then_removes_the_selection_and_unlinks_art() {
|
||||
assert!(app.session.doc().unwrap().doc.swatch("Orange").is_some());
|
||||
delete(&mut app, vec!["Orange".into()], true);
|
||||
assert!(app.ui.dialog.is_none() && app.session.doc().unwrap().doc.swatch("Orange").is_none());
|
||||
assert_eq!(deletable(&["[None]".into(), REGISTRATION.into(), "Grays".into()]), ["Grays"]);
|
||||
assert_eq!(deletable(&app, &["[None]".into(), REGISTRATION.into(), "Grays".into()]), ["Grays"]);
|
||||
}
|
||||
|
||||
/// Only None and Registration are reserved: a user swatch or color group whose name starts with
|
||||
/// `[` can be deleted, the swatch can be edited, and names the document does not hold are left out.
|
||||
#[test]
|
||||
fn bracketed_user_swatches_and_groups_can_be_deleted_and_edited() {
|
||||
let mut app = app();
|
||||
app.run("swatch.new", json!({"name": "[Mine]", "color": "#336699"})).unwrap();
|
||||
app.run("swatch.newGroup", json!({"name": "[Team]", "colors": ["#ff0000"]})).unwrap();
|
||||
let names = |v: &[&str]| v.iter().map(|n| n.to_string()).collect::<Vec<String>>();
|
||||
assert_eq!(deletable(&app, &names(&["[None]", REGISTRATION, "[Mine]", "[Team]", "Gone"])), ["[Mine]", "[Team]"]);
|
||||
assert_eq!(actions::editable(&app, &names(&["[Mine]"])).as_deref(), Some("[Mine]"));
|
||||
for name in ["[None]", REGISTRATION, "[Team]", "Gone"] {
|
||||
assert_eq!(actions::editable(&app, &names(&[name])), None, "{name}");
|
||||
}
|
||||
let doomed = deletable(&app, &names(&["[Mine]"]));
|
||||
delete(&mut app, doomed, false);
|
||||
assert_eq!(app.ui.dialog.as_ref().map(|d| d.str("message")).as_deref(), Some("Delete “[Mine]”?"));
|
||||
crate::dialogs::confirm(&mut app).unwrap();
|
||||
assert!(app.session.doc().unwrap().doc.swatch("[Mine]").is_none());
|
||||
}
|
||||
|
||||
/// The prompt for several swatches and groups gives the form the language's plural rule picks for the count.
|
||||
|
||||
@@ -1723,6 +1723,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- **Swatches:** names follow the colour model and are unique; Swatch Options (process/spot, Global, Gray/RGB/HSB/CMYK/Web, live preview); editing a global or spot swatch recolours every linked fill, stroke and text run in one undo step; multi-select and delete with confirmation; New Swatch and New Color Group dialogs (a group from the selected artwork's colours); swatches in colour groups convert, separate and count like any other. The Swatches panel selects ranges and whole groups, has a find field, and drags swatches to reorder, regroup or paint art; Add Used Colors, Select All Unused, Merge, Ungroup and Sort by Kind; a CMYK document keeps applied colours in CMYK. Swatch libraries: nine generated colour libraries, seven gradient libraries (among them Organic Fades, soft perceptually mixed multi-stop fades that thin out to transparent, and Holographic, seven opaque linear foils of narrow pastel and pearl bands and seven radial glows that fade out to a clear edge) and three pattern libraries (Geometric Patterns; Grit Textures with eight seamless grain, speckle, stipple, scratch and fleck tiles; and Optical Effects with eight of VectorCraft's own seamless wave, ring, warped-check, stripe, chevron and lens tiles; their swatches bring their patterns) in a library panel, saved as `.vcswatches`, `.gpl`, swatch exchange (`.ase`) or CSS, and loaded from `.vcswatches`, `.gpl` and `.ase` files (`.ase` both ways: RGB, CMYK, Lab and Gray; global, spot and process; groups) and from color books (`.acb`, read only: the RGB, CMYK or Lab colors of a book such as a Pantone book a user owns, named with its prefix and suffix, spot unless it says process, #831); `swatch.library.copyToUser` copies a loaded library into the User Defined folder without replacing a file, and a file with the same extension and bytes as a User Defined library opens as that library. Tints of global and spot colours ("Name 40%") stay linked and separate as a percentage of their plate. Spot colours can be defined in Lab (Spot Colors options). A built-in [Registration] swatch prints on every plate.
|
||||
Right-clicking a swatch in either list or thumbnail view selects it without applying paint and offers Swatch Options…, Duplicate Swatch and Delete Swatch for that item. None, [Registration] and missing swatches disable these actions. Existing active-item multiselection is retained; actions still target only the clicked item. Evidence: `panels::swatches::tests::context_menu` harness tests cover all five views, selection, dialog dispatch, duplicate/delete and Undo. All 39 Swatches tests pass; the regression fails with the menu hooks removed. Rendered headless list and thumbnail menus were inspected, and a fresh local deep CodeRabbit review reported zero findings. 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. Scores and estimates unchanged.
|
||||
Validation on 2026-11-15: native Windows formatting, workspace Clippy and all 39 focused Swatches tests passed. Windows full CI stopped at unchanged engine tests `tests::package::a_confined_package_names_files_outside_the_read_root_by_name` (slash-sensitive report assertion) and `tests::plugins::plugin_storage_behind_a_link_is_left_alone` (storage-link setup returned AlreadyExists). Both cases pass in the Linux/WSL full CI run, which passed all 13 gates. No engine or CI workflow changes are included.
|
||||
The panel's Delete Swatch and Swatch Options (footer buttons and panel menu), New Color Group and Save Swatch Library treat only None and [Registration] as reserved, so a user swatch or color group whose name starts with `[` can be deleted, edited, grouped and saved; selected names the document no longer holds are left out (`panels::swatches::tests::bracketed_user_swatches_and_groups_can_be_deleted_and_edited`).
|
||||
Editing, renaming, deleting or merging a global swatch also changes the colors linked to it in graph designs, the art of brushes and the tile that pattern editing's Cancel puts back, in the same undo step as the rest of the art; Default Swatches with replace unlinks them there too.
|
||||
A swatch step in `command.batch` (Delete, Swatch Options, Merge, Edit Color Group) changes the fill and stroke for new art as the command run on its own does, so art drawn later in the batch or after it takes the same paint; a batch that fails, and a canceled batch preview, put back the paints it started with, and a canceled Swatch Options preview leaves them as they were. These swatch commands also change the fills and strokes of the appearance new art takes, and Undo and Redo of the command or the batch put the paints for new art back with the swatches. Spot Colors options (`swatch.spotOptions`) and Default Swatches with replace (`swatch.resetDefaults {replace: true}`) as `command.batch` steps also change the fill and stroke for new art as each command run on its own does: a fill or stroke linked to a Lab spot swatch keeps its link and tint and takes the Lab values or their CMYK equivalent, and one linked to a swatch the replace removes keeps its color and loses the link. Evidence: `swatch_steps_in_a_batch_change_the_new_art_paints_as_commands_do`, `spot_colors_options_in_a_batch_change_the_new_art_paints_as_the_command_does`, `default_swatches_replace_in_a_batch_unlinks_the_new_art_paints_as_the_command_does`, `undo_and_redo_of_a_swatch_edit_put_back_the_new_art_paints`, `swatch_edits_reach_the_paints_of_the_new_art_template`, `a_failed_batch_puts_back_the_new_art_paints_a_swatch_step_changed` and `canceling_a_swatch_options_preview_keeps_the_new_art_paints` in `crates/engine/src/tests/swatches.rs`.
|
||||
Add Used Colors (`swatch.addUsedColors`) and Select All Unused (`swatch.unused`) look colors, swatch names, links, tints and gradients up in hash sets instead of searching every swatch and color for each color or linked paint (New Color Group from artwork too), and New Swatch with several colors (`swatch.new`), New Color Group (`swatch.newGroup`) and Edit Color Group (`swatch.editGroup`) name their new swatches from one set of the names already taken. The new swatches keep their names, order and links, and Select All Unused lists the same swatches. Evidence: `add_used_colors_adds_each_new_color_once_with_free_names`, `add_used_colors_global_links_every_paint_of_a_new_color`, `unused_matches_links_tints_colors_gradients_and_patterns_exactly`, `new_swatches_from_colors_are_numbered_after_names_already_taken`, `new_color_group_numbers_its_colors_after_the_group_and_its_moved_swatches`, `new_color_group_from_artwork_lists_each_color_once_with_free_names` and `edit_color_group_numbers_extra_colors_after_the_names_it_keeps` in `crates/engine/src/tests/swatchcmds.rs`; `free_swatch_names_match_naming_each_swatch_as_it_is_added` and `free_swatch_names_match_new_swatch_names_as_swatches_are_added` in `crates/doc/src/swatches.rs`.
|
||||
|
||||
Reference in New Issue
Block a user