mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 09:19:04 +00:00
Merge main into fix/script-answers-errors-translated
This commit is contained in:
@@ -53,6 +53,7 @@ pub(super) fn script_families(c: char) -> &'static [&'static str] {
|
||||
"Lohit Devanagari",
|
||||
"Mangal",
|
||||
],
|
||||
Script::Gujarati => &["Gujarati Sangam MN", "GujaratiMT", "Nirmala UI", "Shruti", "Noto Sans Gujarati", "Noto Sans Gujarati UI"],
|
||||
_ => &[],
|
||||
}
|
||||
}
|
||||
@@ -164,6 +165,13 @@ mod tests {
|
||||
assert!(script_families('a').is_empty());
|
||||
}
|
||||
|
||||
/// Gujarati takes a font that draws it (macOS Gujarati Sangam MN, Windows Nirmala UI or Shruti).
|
||||
#[test]
|
||||
fn gujarati_prefers_fonts_made_for_it() {
|
||||
assert_eq!(script_families('ગ').first(), Some(&"Gujarati Sangam MN"));
|
||||
assert!(script_families('ગ').contains(&"Nirmala UI"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_name_table_of_many_records_is_cut_short() {
|
||||
let many: Vec<(u16, &str)> = (0..2000).map(|_| (1, "Short")).collect();
|
||||
|
||||
@@ -97,7 +97,7 @@ fn plural_polish(n: u64) -> usize {
|
||||
}
|
||||
|
||||
/// The registry. English first: it is the fallback and the source language.
|
||||
pub static LANGUAGES: [LangInfo; 28] = [
|
||||
pub static LANGUAGES: [LangInfo; 29] = [
|
||||
LangInfo { code: "en", name: "English", source: "", plural: plural_one_other, complete_menus: false, catalog: OnceLock::new() },
|
||||
// Hindi shares the integer zero/one rule with French. Desktop UI fonts are loaded lazily
|
||||
// from installed faces by ui_fonts; the web needs a Devanagari font in its font set.
|
||||
@@ -109,6 +109,18 @@ pub static LANGUAGES: [LangInfo; 28] = [
|
||||
complete_menus: true,
|
||||
catalog: OnceLock::new(),
|
||||
},
|
||||
// Gujarati: menus and dialogs, with partial status/error message coverage and loanwords
|
||||
// transliterated into Gujarati script; zero/one singular plurals. Gujarati text is drawn with an installed system font
|
||||
// (Gujarati Sangam MN, Nirmala UI, Shruti) or a craft-fonts face tagged `Gujr`. Web selection
|
||||
// requires a bundled Gujarati interface face; otherwise `gu-*` locales use the fallback.
|
||||
LangInfo {
|
||||
code: "gu",
|
||||
name: "ગુજરાતી",
|
||||
source: include_str!("i18n/gu.tsv"),
|
||||
plural: plural_french,
|
||||
complete_menus: true,
|
||||
catalog: OnceLock::new(),
|
||||
},
|
||||
// Greek: the whole interface and the status and error messages, keeping the same names in
|
||||
// English as Spanish; every `el-*` locale (including `el-GR` and `el-CY`) resolves here.
|
||||
LangInfo {
|
||||
@@ -355,6 +367,16 @@ pub static LANGUAGES: [LangInfo; 28] = [
|
||||
];
|
||||
|
||||
impl LangInfo {
|
||||
fn available(&self) -> bool {
|
||||
self.available_with_fonts(cfg!(target_arch = "wasm32"), vectorcraft_text::CRAFT_FONTS.iter().any(|f| f.scripts.contains(&"Gujr")))
|
||||
}
|
||||
|
||||
fn available_with_fonts(&self, web: bool, gujarati_font: bool) -> bool {
|
||||
// Browsers cannot use the native installed-font fallback. Do not offer a language
|
||||
// whose text would be missing-glyph boxes, including when restoring a preference.
|
||||
self.code != "gu" || !web || gujarati_font
|
||||
}
|
||||
|
||||
fn catalog(&self) -> &Catalog {
|
||||
self.catalog.get_or_init(|| Catalog::parse(self.source))
|
||||
}
|
||||
@@ -387,7 +409,7 @@ impl Lang {
|
||||
|
||||
/// A language by its exact code.
|
||||
pub fn from_code(code: &str) -> Option<Lang> {
|
||||
LANGUAGES.iter().find(|l| l.code.eq_ignore_ascii_case(code)).map(Lang)
|
||||
LANGUAGES.iter().find(|l| l.code.eq_ignore_ascii_case(code) && l.available()).map(Lang)
|
||||
}
|
||||
|
||||
/// Resolve the `interfaceLanguage` preference: a language code, or `auto` (and anything
|
||||
@@ -396,12 +418,12 @@ impl Lang {
|
||||
Lang::from_code(pref).unwrap_or_else(system_lang)
|
||||
}
|
||||
|
||||
/// Every registered language.
|
||||
/// Every language available in this build.
|
||||
pub fn all() -> impl Iterator<Item = Lang> {
|
||||
LANGUAGES.iter().map(Lang)
|
||||
LANGUAGES.iter().filter(|l| l.available()).map(Lang)
|
||||
}
|
||||
|
||||
/// Every registered language in the order a picker lists them: English first (the source
|
||||
/// Every available language in the order a picker lists them: English first (the source
|
||||
/// language and the fallback), then the rest by their own name with accents folded, so
|
||||
/// Čeština sits under C rather than after Z. Names in other scripts follow the Latin ones in
|
||||
/// code point order: Greek, Cyrillic, Arabic, then the CJK languages.
|
||||
|
||||
@@ -7579,7 +7579,7 @@ breakText Glyphs Glyfy
|
||||
@msg `alignOn` must be a string `alignOn` musí být řetězec
|
||||
@msg `align` is start, center or end `align` je start, center nebo end
|
||||
@msg `align` must be a string `align` musí být řetězec
|
||||
@msg `anchors` must be an array of [subpath, anchor] pairs `anchors` musí být pole dvojic [dílčí cesta, kotevní bod]
|
||||
@msg `anchors` must be an array of [subpath, anchor] pairs `anchors` musí být pole dvojic [subpath, anchor]
|
||||
@msg `anchors` must list anchor indices (0, 1, 2…), not {k} `anchors` musí uvádět indexy kotevních bodů (0, 1, 2…), ne {k}
|
||||
@msg `anchors` must list anchor indices (0, 1, 2…), not {v} `anchors` musí uvádět indexy kotevních bodů (0, 1, 2…), ne {v}
|
||||
@msg `answer` for this {kind} dialog must be one of: {_1} `answer` pro tento dialog {kind} musí být jedna z hodnot: {_1}
|
||||
@@ -7644,7 +7644,7 @@ breakText Glyphs Glyfy
|
||||
@msg `fidelity` must be from {lo} to {hi} pt `fidelity` musí být od {lo} do {hi} pt
|
||||
@msg `files` must be 1 to 1000 paths of font files the last text.findFontFiles search found `files` musí být 1 až 1000 cest k souborům písem, které našlo poslední hledání text.findFontFiles
|
||||
@msg `focal` and `radius` cannot be used together `focal` a `radius` nelze použít společně
|
||||
@msg `focal` must be an array of [subpath, anchor] pairs `focal` musí být pole dvojic [dílčí cesta, kotevní bod]
|
||||
@msg `focal` must be an array of [subpath, anchor] pairs `focal` musí být pole dvojic [subpath, anchor]
|
||||
@msg `focal` names [{si}, {ai}], which is not an anchor of the path `focal` uvádí [{si}, {ai}], což není kotevní bod cesty
|
||||
@msg `folder` must be an absolute folder path `folder` musí být absolutní cesta ke složce
|
||||
@msg `fontAxes` must be an object of axis tags and values, such as {"wght"} `fontAxes` musí být objekt se značkami os a hodnotami, například {"wght"}
|
||||
@@ -8309,7 +8309,7 @@ breakText Glyphs Glyfy
|
||||
@msg instruction {pc} reached with stack depths {seen} and {d} instrukce {pc} byla dosažena s hloubkami zásobníku {seen} a {d}
|
||||
@msg invalid `color` neplatné `color`
|
||||
@msg invalid anchor index {v}: expected a non-negative integer neplatný index kotevního bodu {v}: očekáváno nezáporné celé číslo
|
||||
@msg invalid anchor reference {v}: expected [subpath, anchor] neplatný odkaz na kotevní bod {v}: očekáváno [dílčí cesta, kotevní bod]
|
||||
@msg invalid anchor reference {v}: expected [subpath, anchor] neplatný odkaz na kotevní bod {v}: očekáváno [subpath, anchor]
|
||||
@msg invalid angle neplatný úhel
|
||||
@msg invalid array length neplatná délka pole
|
||||
@msg invalid brush: {e} neplatný štětec: {e}
|
||||
@@ -8418,7 +8418,7 @@ breakText Glyphs Glyfy
|
||||
@msg missing `{k}` chybí `{k}`
|
||||
@msg missing anchor chybí kotevní bod
|
||||
@msg missing anchors chybí kotevní body
|
||||
@msg missing anchors [[subpath, anchor]…] chybí kotevní body [[dílčí cesta, kotevní bod]…]
|
||||
@msg missing anchors [[subpath, anchor]…] chybí kotevní body [[subpath, anchor]…]
|
||||
@msg missing array `{key}` chybí pole `{key}`
|
||||
@msg missing case chybí case
|
||||
@msg missing color chybí barva
|
||||
|
||||
|
Can't render this file because it is too large.
|
File diff suppressed because it is too large
Load Diff
@@ -3,6 +3,20 @@ use super::*;
|
||||
|
||||
const ZH: fn() -> Lang = || Lang::from_code("zh-hant").expect("zh-hant registered");
|
||||
|
||||
#[test]
|
||||
fn gujarati_resolves_locales_and_takes_the_singular_for_zero_and_one() {
|
||||
// The catalog is present even when this web build cannot display it.
|
||||
let gu = Lang(LANGUAGES.iter().find(|l| l.code == "gu").expect("gu registered"));
|
||||
let selectable = gu.0.available().then_some(gu);
|
||||
assert_eq!(Lang::from_code("gu"), selectable);
|
||||
for tag in ["gu", "gu-IN", "gu_IN.UTF-8", "GU-in", "gu-Gujr-IN"] {
|
||||
assert_eq!(lang_from_tag(tag), selectable, "{tag}");
|
||||
}
|
||||
assert_eq!(gu.name(), "ગુજરાતી");
|
||||
assert_eq!([0, 1, 2, 21].map(gu.0.plural), [0, 0, 1, 1]);
|
||||
assert_eq!(tr(gu, "Save"), "સાચવો");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hindi_resolves_locales_and_uses_zero_one_plurals() {
|
||||
let hi = Lang::from_code("hi").expect("hi registered");
|
||||
@@ -209,6 +223,17 @@ fn tags_map_to_languages() {
|
||||
assert_eq!(lang_from_tag("_"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gujarati_web_selection_requires_a_bundled_interface_font() {
|
||||
let gu = LANGUAGES.iter().find(|l| l.code == "gu").expect("Gujarati catalog");
|
||||
assert!(gu.available_with_fonts(false, false), "native installed-font fallback");
|
||||
assert!(!gu.available_with_fonts(true, false), "web must not offer missing glyphs");
|
||||
assert!(gu.available_with_fonts(true, true));
|
||||
assert!(LANGUAGES[0].available_with_fonts(true, false), "English fallback");
|
||||
assert_eq!(Lang::from_code("gu").is_some(), gu.available());
|
||||
assert_eq!(Lang::for_picker().iter().any(|l| l.code() == "gu"), gu.available());
|
||||
}
|
||||
|
||||
/// The Bosnian, Georgian, Ukrainian, Hungarian, Korean, Vietnamese, Swedish and Catalan tags of
|
||||
/// [`tags_map_to_languages`].
|
||||
fn other_tags_map_to_languages() {
|
||||
@@ -823,6 +848,11 @@ fn is_devanagari(c: char) -> bool {
|
||||
matches!(c as u32, 0x0900..=0x097F | 0x1CD0..=0x1CFF | 0xA8E0..=0xA8FF)
|
||||
}
|
||||
|
||||
#[cfg(feature = "interface-fonts")]
|
||||
fn is_gujarati(c: char) -> bool {
|
||||
matches!(c as u32, 0x0A80..=0x0AFF)
|
||||
}
|
||||
|
||||
/// The UI fonts draw every character the catalogs use, in every family the UI draws text with
|
||||
/// (the web build has no system fonts to fall back to). Chinese and Japanese characters come from
|
||||
/// the craft-fonts build input, which is optional: without it they are left to the installed
|
||||
@@ -836,6 +866,7 @@ fn bundled_fonts_cover_the_catalogs() {
|
||||
let japanese_ui_font = vectorcraft_text::CRAFT_FONTS.iter().any(|f| f.is_japanese());
|
||||
let georgian_ui_font = vectorcraft_text::CRAFT_FONTS.iter().any(|f| f.is_georgian());
|
||||
let devanagari_ui_font = vectorcraft_text::CRAFT_FONTS.iter().any(|f| f.scripts.contains(&"Deva"));
|
||||
let gujarati_ui_font = vectorcraft_text::CRAFT_FONTS.iter().any(|f| f.scripts.contains(&"Gujr"));
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
let mut output = ctx.run_ui(egui::RawInput::default(), |_| {});
|
||||
@@ -859,6 +890,7 @@ fn bundled_fonts_cover_the_catalogs() {
|
||||
&& (cjk_checked || !is_cjk(*c))
|
||||
&& (georgian_ui_font || !is_georgian(*c))
|
||||
&& (devanagari_ui_font || !is_devanagari(*c))
|
||||
&& (gujarati_ui_font || !is_gujarati(*c))
|
||||
})
|
||||
.collect();
|
||||
for family in &families {
|
||||
|
||||
+103
-10
@@ -7,20 +7,40 @@ use serde_json::json;
|
||||
use crate::theme::Tokens;
|
||||
use crate::{VectorcraftApp, menus};
|
||||
|
||||
/// Engine commands the palette leaves out, each with the UI command of the same name that runs it
|
||||
/// the way the panels and menus do: (engine id, UI command id). The Layers panel's Delete
|
||||
/// Selection asks before deleting a layer that holds art, and the other UI commands open the
|
||||
/// command's dialog or file chooser. Scripts and the control channel still run the engine ids.
|
||||
const WRAPPED: &[(&str, &str)] = &[
|
||||
("layer.delete", "ui.layerDelete"),
|
||||
("brush.new", "ui.newBrush"),
|
||||
("brush.options", "ui.brushOptions"),
|
||||
("symbol.options", "ui.symbolOptions"),
|
||||
("svgFilter.import", "ui.importSvgFilter"),
|
||||
("text.convertListToText", "type.convertListToText"),
|
||||
];
|
||||
|
||||
/// Everything the palette searches: (label, command id or `tool:<id>`, shortcut).
|
||||
pub fn items() -> Vec<(String, String, String)> {
|
||||
let mut items = vec![];
|
||||
// Aliases kept for older scripts run a command that is listed already.
|
||||
// Aliases kept for older scripts run a command that is listed already, and a wrapped engine
|
||||
// command is listed as its UI command.
|
||||
let plugin_commands = vectorcraft_engine::cmd::plugin::command_specs();
|
||||
for c in vectorcraft_engine::command_specs().iter().filter(|c| !vectorcraft_engine::cmd::is_alias(c.id)).chain(plugin_commands) {
|
||||
let path = c.menu.join(" › ");
|
||||
let label = if path.is_empty() { c.label.to_string() } else { format!("{path} › {}", c.label) };
|
||||
items.push((label, c.id.to_string(), menus::shortcut_of(c.id).unwrap_or("").to_string()));
|
||||
let listed = |id: &str| !vectorcraft_engine::cmd::is_alias(id) && !WRAPPED.iter().any(|(engine, _)| *engine == id);
|
||||
let labeled = |menu: &[&str], label: &str| {
|
||||
let path = menu.join(" › ");
|
||||
if path.is_empty() { label.to_string() } else { format!("{path} › {label}") }
|
||||
};
|
||||
for c in vectorcraft_engine::command_specs().iter().filter(|c| listed(c.id)).chain(plugin_commands) {
|
||||
items.push((labeled(c.menu, c.label), c.id.to_string(), menus::shortcut_of(c.id).unwrap_or("").to_string()));
|
||||
}
|
||||
// `plugin.dialog` runs nothing without an id: [`build`] lists each filter instead. A script of
|
||||
// the Scripts folder runs from File › Scripts, by its path.
|
||||
// the Scripts folder runs from File › Scripts, by its path. A UI command that wraps an engine
|
||||
// command takes that command's menu path, so a search for the path still finds it.
|
||||
for c in menus::UI_COMMANDS.iter().filter(|c| c.0 != "plugin.dialog" && c.0 != crate::scripts_menu::COMMAND) {
|
||||
items.push((c.1.to_string(), c.0.to_string(), menus::shortcut_of(c.0).unwrap_or("").to_string()));
|
||||
let engine = WRAPPED.iter().find(|(_, ui)| *ui == c.0).and_then(|(engine, _)| vectorcraft_engine::find_command(engine));
|
||||
let label = engine.map_or_else(|| c.1.to_string(), |e| labeled(e.menu, c.1));
|
||||
items.push((label, c.0.to_string(), menus::shortcut_of(c.0).unwrap_or("").to_string()));
|
||||
}
|
||||
for tool in vectorcraft_tools::catalog::all_tools() {
|
||||
items.push((tool.label.to_string(), format!("tool:{}", tool.id), crate::shortcut_editor::tool_shortcut(tool.id).unwrap_or("").to_string()));
|
||||
@@ -40,8 +60,9 @@ pub(crate) struct Entry {
|
||||
shortcut: String,
|
||||
/// The label in the UI language.
|
||||
shown: String,
|
||||
/// The English label (what agents document), the shown label and the id, lowercased, one per
|
||||
/// line: a query word (which has no line break) matches within one of them.
|
||||
/// The English label (what agents document), the shown label and the id (and the id of the
|
||||
/// engine command a UI command wraps), lowercased, one per line: a query word (which has no
|
||||
/// line break) matches within one of them.
|
||||
haystack: String,
|
||||
}
|
||||
|
||||
@@ -71,7 +92,12 @@ fn entries(ctx: &egui::Context, lang: crate::i18n::Lang) -> Arc<Vec<Entry>> {
|
||||
/// item (`plugin:<id>`), whose name is not translated.
|
||||
fn build(lang: crate::i18n::Lang) -> Vec<Entry> {
|
||||
let entry = |label: String, shown: String, id: String, shortcut: String| {
|
||||
let haystack = format!("{}\n{}\n{}", label.to_lowercase(), shown.to_lowercase(), id.to_lowercase());
|
||||
let mut haystack = format!("{}\n{}\n{}", label.to_lowercase(), shown.to_lowercase(), id.to_lowercase());
|
||||
// A UI command that wraps an engine command is also found by the engine command's id.
|
||||
if let Some((engine, _)) = WRAPPED.iter().find(|(_, ui)| *ui == id) {
|
||||
haystack.push('\n');
|
||||
haystack.push_str(&engine.to_lowercase());
|
||||
}
|
||||
Entry { id, shortcut, shown, haystack }
|
||||
};
|
||||
let mut out: Vec<Entry> = items()
|
||||
@@ -250,6 +276,73 @@ mod tests {
|
||||
assert_eq!((st.selection.len(), st.selection.key), (2, None), "both objects stay selected, without a key");
|
||||
}
|
||||
|
||||
/// An engine command that a UI command of the same name runs is listed once, as the UI command:
|
||||
/// the Layers panel's Delete Selection, New Brush…, Brush Options…, Symbol Options…, Import SVG
|
||||
/// Filter… and Convert to Text each have one result.
|
||||
#[test]
|
||||
fn a_wrapped_engine_command_is_listed_once_as_its_ui_command() {
|
||||
let items = items();
|
||||
for (engine, ui) in WRAPPED {
|
||||
let spec = vectorcraft_engine::command_specs().iter().find(|c| c.id == *engine).unwrap_or_else(|| panic!("{engine} is a command"));
|
||||
let wrapper = menus::UI_COMMANDS.iter().find(|c| c.0 == *ui).unwrap_or_else(|| panic!("{ui} is a UI command"));
|
||||
assert_eq!(spec.label, wrapper.1, "{engine} and {ui} share a name");
|
||||
assert!(items.iter().all(|(_, id, _)| id != engine), "{engine} is left out");
|
||||
let listed: Vec<&str> = items.iter().filter(|(_, id, _)| id == ui).map(|(label, ..)| label.as_str()).collect();
|
||||
let path: String = spec.menu.iter().map(|m| format!("{m} › ")).collect();
|
||||
assert_eq!(listed, [format!("{path}{}", wrapper.1)], "{ui} is listed once, with {engine}'s menu path");
|
||||
}
|
||||
// A search for Delete Selection, or for its menu path, finds the Layers panel's, and not the
|
||||
// engine command that deletes without asking; the path translates.
|
||||
let entries = build(Lang::EN);
|
||||
for (engine, ui) in WRAPPED {
|
||||
assert!(entries.iter().any(|e| e.id == *ui && e.haystack.contains(&engine.to_lowercase())), "a search for {engine} finds {ui}");
|
||||
}
|
||||
for query in ["delete selection", "layers delete", "layer.delete"] {
|
||||
let found: Vec<&str> =
|
||||
entries.iter().filter(|e| query.split_whitespace().all(|w| e.haystack.contains(w))).map(|e| e.id.as_str()).collect();
|
||||
assert!(found.contains(&"ui.layerDelete") && !found.contains(&"layer.delete"), "{query}: {found:?}");
|
||||
}
|
||||
let zh = Lang::from_code("zh-hant").unwrap();
|
||||
let shown = build(zh).into_iter().find(|e| e.id == "ui.layerDelete").map(|e| e.shown).unwrap();
|
||||
let want = ["Window", "Layers", "Delete Selection"].map(|s| crate::i18n::tr(zh, s)).join(" › ");
|
||||
assert_eq!(shown, want);
|
||||
}
|
||||
|
||||
/// Every result a search for Delete Selection gives asks before deleting a layer that holds art:
|
||||
/// Cancel keeps it, and OK deletes it in one undo step. A script's `layer.delete` still deletes
|
||||
/// at once.
|
||||
#[test]
|
||||
fn a_pick_of_delete_selection_asks_before_deleting_a_layer_with_art() {
|
||||
let query = "delete selection";
|
||||
let picks: Vec<String> =
|
||||
build(Lang::EN).into_iter().filter(|e| query.split_whitespace().all(|w| e.haystack.contains(w))).map(|e| e.id).collect();
|
||||
assert!(!picks.is_empty(), "the search finds Delete Selection");
|
||||
let node = |v: &serde_json::Value| vectorcraft_doc::NodeId(v.as_u64().unwrap());
|
||||
let exists = |app: &VectorcraftApp, v: &serde_json::Value| app.session.active().unwrap().doc.node(node(v)).is_some();
|
||||
let undo = |app: &VectorcraftApp| app.session.active().unwrap().history.undo.len();
|
||||
let asked = |app: &VectorcraftApp| app.ui.dialog.as_ref().is_some_and(|d| d.kind == crate::dialogs::confirm::KIND);
|
||||
for pick in &picks {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
let layer = app.run("layer.new", json!({})).unwrap()["id"].clone();
|
||||
let art = app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap()["id"].clone();
|
||||
app.run("select.none", json!({})).unwrap();
|
||||
let before = undo(&app);
|
||||
run_pick(&mut app, pick);
|
||||
assert!(asked(&app), "{pick} asks first: {}", app.ui.status);
|
||||
assert!(exists(&app, &layer) && exists(&app, &art) && undo(&app) == before, "{pick}: nothing is deleted yet");
|
||||
crate::dialogs::cancel(&mut app);
|
||||
assert!(exists(&app, &layer) && exists(&app, &art) && undo(&app) == before, "{pick}: Cancel keeps the layer");
|
||||
run_pick(&mut app, pick);
|
||||
crate::dialogs::confirm(&mut app).unwrap();
|
||||
assert!(!exists(&app, &layer) && !exists(&app, &art), "{pick}: OK deletes the layer and its art");
|
||||
assert_eq!(undo(&app), before + 1, "{pick}: one undo step");
|
||||
app.run("edit.undo", json!({})).unwrap();
|
||||
app.run("layer.delete", json!({ "ids": [layer] })).unwrap();
|
||||
assert!(app.ui.dialog.is_none() && !exists(&app, &layer), "a script deletes at once");
|
||||
}
|
||||
}
|
||||
|
||||
/// #4864: a pick of an Asset Export command, which the palette runs with no params, opens the
|
||||
/// Asset Export panel instead of failing on the missing params or exporting nowhere.
|
||||
#[test]
|
||||
|
||||
@@ -268,6 +268,66 @@ fn disclosure(ui: &Ui, view: &View, n: &Node, (r, x): (egui::Rect, f32), open: b
|
||||
}
|
||||
}
|
||||
|
||||
/// The row's name label or inline rename field. Returns (name_end, name_rect).
|
||||
fn row_name(ui: &mut Ui, view: &View, item: &Row, r: egui::Rect, x: f32, out: &mut Out) -> (f32, egui::Rect) {
|
||||
let n = &*item.node;
|
||||
let doc = view.doc;
|
||||
let t = &view.t;
|
||||
let xml_id = view.identify_xml_id;
|
||||
let name = if doc.mask_edit.is_some_and(|m| m.layer == n.id) { "<Opacity Mask>".to_string() } else { n.identify_label(xml_id) };
|
||||
let font = egui::FontId::proportional(13.0);
|
||||
let renaming: Option<(u64, String)> = ui.data(|d| d.get_temp(rename_id()));
|
||||
let name_rect = egui::Rect::from_min_max(egui::pos2(x - 2.0, r.center().y - 10.0), egui::pos2(r.right() - 44.0, r.center().y + 10.0));
|
||||
let name_end = match renaming {
|
||||
Some((rid, mut buf)) if rid == n.id.0 => {
|
||||
let field = rename_id().with("field");
|
||||
let kept = crate::widgets::own_field_shift_enter(ui, field, &mut buf, &name);
|
||||
let mut child = ui.new_child(egui::UiBuilder::new().max_rect(name_rect));
|
||||
let te = child
|
||||
.add(egui::TextEdit::singleline(&mut buf).id(field).align(egui::Align2::LEFT_CENTER).desired_width(name_rect.width()).font(font));
|
||||
// Focus the field as it opens. Asking every frame took the focus back from Enter,
|
||||
// Escape or a click elsewhere, so the rename never ended.
|
||||
if !te.has_focus() && !te.lost_focus() {
|
||||
te.request_focus();
|
||||
}
|
||||
if te.lost_focus() {
|
||||
ui.data_mut(|d| d.remove::<(u64, String)>(rename_id()));
|
||||
if child.input(|i| !i.key_pressed(egui::Key::Escape)) && buf != name {
|
||||
out.actions.push(("layer.setProps".into(), json!({"ids": [n.id.0], "name": buf})));
|
||||
}
|
||||
} else {
|
||||
// Shift+Enter renames it and keeps the field open.
|
||||
if kept && buf != name {
|
||||
out.actions.push(("layer.setProps".into(), json!({"ids": [n.id.0], "name": buf.clone()})));
|
||||
}
|
||||
ui.data_mut(|d| d.insert_temp(rename_id(), (n.id.0, buf)));
|
||||
}
|
||||
name_rect.right()
|
||||
}
|
||||
_ => {
|
||||
let painter = ui.painter().with_clip_rect(name_rect);
|
||||
// Generated names ("<Path>", "<Opacity Mask>") are translated where painted; the stored name stays English.
|
||||
// XML IDs stay as ids (not translated).
|
||||
let shown = if doc.mask_edit.is_some_and(|m| m.layer == n.id) {
|
||||
tl!("<Opacity Mask>").to_string()
|
||||
} else if xml_id {
|
||||
name
|
||||
} else {
|
||||
painted_name(n, &n.display_name(), crate::i18n::current())
|
||||
};
|
||||
let text = paint_name(&painter, egui::pos2(x, r.center().y), &shown, font, if item.dim { t.text_dim } else { t.text }, prints_italic(n));
|
||||
// A clipping path's name is underlined, a masked object's with a dashed line.
|
||||
if item.clip_path {
|
||||
painter.line_segment([text.left_bottom(), text.right_bottom()], Stroke::new(1.0, t.text));
|
||||
} else if n.extras().mask.is_some() {
|
||||
painter.extend(egui::Shape::dashed_line(&[text.left_bottom(), text.right_bottom()], Stroke::new(1.0, t.text), 3.0, 2.0));
|
||||
}
|
||||
text.right()
|
||||
}
|
||||
};
|
||||
(name_end, name_rect)
|
||||
}
|
||||
|
||||
/// The widgets of row `item`.
|
||||
pub(super) fn row(ui: &mut Ui, view: &View, item: &Row, out: &mut Out) {
|
||||
if let Some(i) = item.guide {
|
||||
@@ -277,8 +337,7 @@ pub(super) fn row(ui: &mut Ui, view: &View, item: &Row, out: &mut Out) {
|
||||
return spine_row(ui, view, item, out);
|
||||
}
|
||||
let n = &*item.node;
|
||||
let (depth, clip_path, has_children, open, color) = (item.depth, item.clip_path, item.opens, item.open, item.colour);
|
||||
let doc = view.doc;
|
||||
let (depth, has_children, open, color) = (item.depth, item.opens, item.open, item.colour);
|
||||
let t = &view.t;
|
||||
let h = view.h;
|
||||
let (r, resp) = ui.allocate_exact_size(vec2(ui.available_width(), h), Sense::click_and_drag());
|
||||
@@ -309,60 +368,7 @@ pub(super) fn row(ui: &mut Ui, view: &View, item: &Row, out: &mut Out) {
|
||||
th
|
||||
});
|
||||
// Name (Preferences › Units › Identify Objects By: Object Name or XML ID).
|
||||
let xml_id = view.identify_xml_id;
|
||||
let name = if doc.mask_edit.is_some_and(|m| m.layer == n.id) { "<Opacity Mask>".to_string() } else { n.identify_label(xml_id) };
|
||||
let font = egui::FontId::proportional(13.0);
|
||||
let renaming: Option<(u64, String)> = ui.data(|d| d.get_temp(rename_id()));
|
||||
let name_rect = egui::Rect::from_min_max(egui::pos2(x - 2.0, r.center().y - 10.0), egui::pos2(r.right() - 44.0, r.center().y + 10.0));
|
||||
let name_end;
|
||||
match renaming {
|
||||
Some((rid, mut buf)) if rid == n.id.0 => {
|
||||
let field = rename_id().with("field");
|
||||
let kept = crate::widgets::own_field_shift_enter(ui, field, &mut buf, &name);
|
||||
let mut child = ui.new_child(egui::UiBuilder::new().max_rect(name_rect));
|
||||
let te = child.add(
|
||||
egui::TextEdit::singleline(&mut buf).id(field).align(egui::Align2::LEFT_CENTER).desired_width(name_rect.width()).font(font.clone()),
|
||||
);
|
||||
// Focus the field as it opens. Asking every frame took the focus back from Enter,
|
||||
// Escape or a click elsewhere, so the rename never ended.
|
||||
if !te.has_focus() && !te.lost_focus() {
|
||||
te.request_focus();
|
||||
}
|
||||
if te.lost_focus() {
|
||||
ui.data_mut(|d| d.remove::<(u64, String)>(rename_id()));
|
||||
if child.input(|i| !i.key_pressed(egui::Key::Escape)) && buf != name {
|
||||
out.actions.push(("layer.setProps".into(), json!({"ids": [n.id.0], "name": buf})));
|
||||
}
|
||||
} else {
|
||||
// Shift+Enter renames it and keeps the field open.
|
||||
if kept && buf != name {
|
||||
out.actions.push(("layer.setProps".into(), json!({"ids": [n.id.0], "name": buf.clone()})));
|
||||
}
|
||||
ui.data_mut(|d| d.insert_temp(rename_id(), (n.id.0, buf)));
|
||||
}
|
||||
name_end = name_rect.right();
|
||||
}
|
||||
_ => {
|
||||
let painter = ui.painter().with_clip_rect(name_rect);
|
||||
// Generated names ("<Path>", "<Opacity Mask>") are translated where painted; the stored name stays English.
|
||||
// XML IDs stay as ids (not translated).
|
||||
let shown = if doc.mask_edit.is_some_and(|m| m.layer == n.id) {
|
||||
tl!("<Opacity Mask>").to_string()
|
||||
} else if xml_id {
|
||||
name.clone()
|
||||
} else {
|
||||
painted_name(n, &n.display_name(), crate::i18n::current())
|
||||
};
|
||||
let text = paint_name(&painter, egui::pos2(x, r.center().y), &shown, font, if item.dim { t.text_dim } else { t.text }, prints_italic(n));
|
||||
name_end = text.right();
|
||||
// A clipping path's name is underlined, a masked object's with a dashed line.
|
||||
if clip_path {
|
||||
painter.line_segment([text.left_bottom(), text.right_bottom()], Stroke::new(1.0, t.text));
|
||||
} else if n.extras().mask.is_some() {
|
||||
painter.extend(egui::Shape::dashed_line(&[text.left_bottom(), text.right_bottom()], Stroke::new(1.0, t.text), 3.0, 2.0));
|
||||
}
|
||||
}
|
||||
}
|
||||
let (name_end, name_rect) = row_name(ui, view, item, r, x, out);
|
||||
// Target circle and selection square.
|
||||
let col_x = r.right() - 43.5;
|
||||
ui.painter().line_segment([egui::pos2(col_x, r.top()), egui::pos2(col_x, r.bottom())], Stroke::new(1.0, t.input_border));
|
||||
@@ -404,12 +410,18 @@ pub(super) fn row(ui: &mut Ui, view: &View, item: &Row, out: &mut Out) {
|
||||
out.actions.push(("ui.layerOptions".into(), json!({"ids": [n.id.0]})));
|
||||
}
|
||||
}
|
||||
// Row menu: Collect for Export on this row (or every highlighted row when this is one of them).
|
||||
// Row menu: context actions on this row (or every highlighted row when this is one of them).
|
||||
let collect_ids: Vec<u64> = if view.rows.contains(&n.id) { view.rows.iter().map(|id| id.0).collect() } else { vec![n.id.0] };
|
||||
// Right-clicking an unselected row selects it; a highlighted row keeps multiselection.
|
||||
if resp.secondary_clicked() && !view.rows.contains(&n.id) {
|
||||
out.actions.push(("layer.setCurrent".into(), json!({"id": n.id.0})));
|
||||
out.rows_after_click = Some(vec![n.id]);
|
||||
}
|
||||
if resp.secondary_clicked() {
|
||||
crate::panels::set_row_keys(ui.ctx(), ROW_KEYS, true);
|
||||
}
|
||||
resp.context_menu(|ui| {
|
||||
collect_for_export_menu(ui, true, |multiple| {
|
||||
out.actions.push(("assets.add".into(), json!({ "ids": collect_ids.clone(), "multiple": multiple })));
|
||||
});
|
||||
row_context_menu(ui, view, n, &collect_ids, out);
|
||||
});
|
||||
// Dragging rows: the highlighted rows when this is one of them, else this row. Only the primary
|
||||
// button drags; the secondary button opens the row menu, and a drag with it moves nothing.
|
||||
@@ -428,6 +440,114 @@ pub(super) fn row(ui: &mut Ui, view: &View, item: &Row, out: &mut Out) {
|
||||
drop_target(ui, view, n, r, x - 16.0, open, &resp, out);
|
||||
}
|
||||
|
||||
/// The right-click context menu of row `n`.
|
||||
fn row_context_menu(ui: &mut Ui, view: &View, n: &Node, collect_ids: &[u64], out: &mut Out) {
|
||||
let is_multi = collect_ids.len() > 1;
|
||||
// "Layer Options…" / "Options for Selection…" / "Options…"
|
||||
let options_label = if is_multi {
|
||||
"Options for Selection…"
|
||||
} else if n.is_layer() {
|
||||
"Layer Options…"
|
||||
} else {
|
||||
"Options…"
|
||||
};
|
||||
if widgets::menu_item(ui, options_label, true, false) {
|
||||
out.actions.push(("ui.layerOptions".into(), json!({ "ids": collect_ids })));
|
||||
ui.close();
|
||||
}
|
||||
// "Duplicate "<name>"" or "Duplicate Selection"
|
||||
let display = {
|
||||
let raw = painted_name(n, &n.display_name(), crate::i18n::current());
|
||||
if raw.chars().count() > 20 {
|
||||
let truncated: String = raw.chars().take(20).collect();
|
||||
format!("{truncated}…")
|
||||
} else {
|
||||
raw
|
||||
}
|
||||
};
|
||||
let dup_label = if is_multi { tl!("Duplicate Selection").to_string() } else { format!("{} \"{display}\"", tl!("Duplicate")) };
|
||||
if widgets::menu_item_name(ui, &dup_label, true, false) {
|
||||
out.actions.push(("layer.duplicate".into(), json!({ "ids": collect_ids })));
|
||||
ui.close();
|
||||
}
|
||||
// "Delete "<name>"" or "Delete Selection"
|
||||
let del_label = if is_multi { tl!("Delete Selection").to_string() } else { format!("{} \"{display}\"", tl!("Delete")) };
|
||||
let del_enabled = {
|
||||
let listed: std::collections::HashSet<NodeId> = collect_ids.iter().map(|&id| NodeId(id)).collect();
|
||||
!view.doc.layers.iter().all(|l| listed.contains(&l.id))
|
||||
};
|
||||
if widgets::menu_item_name(ui, &del_label, del_enabled, false) {
|
||||
out.actions.push(("layer.delete".into(), json!({ "ids": collect_ids })));
|
||||
ui.close();
|
||||
}
|
||||
ui.separator();
|
||||
// Lock Others / Unlock All Layers
|
||||
{
|
||||
let (lock_cmd, lock_params, lock_enabled) = multi_others_action(view.doc, collect_ids, false);
|
||||
let lock_label = if lock_cmd == "layer.lockOthers" { "Lock Others" } else { "Unlock All Layers" };
|
||||
if widgets::menu_item(ui, lock_label, lock_enabled, false) {
|
||||
out.actions.push((lock_cmd, lock_params));
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
// Hide Others / Show All Layers
|
||||
{
|
||||
let (hide_cmd, hide_params, hide_enabled) = multi_others_action(view.doc, collect_ids, true);
|
||||
let hide_label = if hide_cmd == "layer.hideOthers" { "Hide Others" } else { "Show All Layers" };
|
||||
if widgets::menu_item(ui, hide_label, hide_enabled, false) {
|
||||
out.actions.push((hide_cmd, hide_params));
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
ui.separator();
|
||||
// Locate Object
|
||||
if widgets::menu_item(ui, "Locate Object", true, false) {
|
||||
out.actions.push(("layer.locate".into(), json!({ "id": n.id.0 })));
|
||||
ui.close();
|
||||
}
|
||||
ui.separator();
|
||||
// Collect for Export
|
||||
let ids: Vec<u64> = collect_ids.to_vec();
|
||||
collect_for_export_menu(ui, true, move |multiple| {
|
||||
out.actions.push(("assets.add".into(), json!({ "ids": ids.clone(), "multiple": multiple })));
|
||||
});
|
||||
}
|
||||
|
||||
/// Context menu Others action for `ids`: Lock Others / Unlock All Layers or Hide Others / Show All Layers.
|
||||
/// When any other layer is unlocked (visible), returns `lockOthers` (`hideOthers`) preserving all layers holding
|
||||
/// `ids`. When all other layers are locked (hidden) already, returns `unlockAll` (`showAll`).
|
||||
pub(crate) fn multi_others_action(doc: &Document, ids: &[u64], eye: bool) -> (String, Value, bool) {
|
||||
let own_layers: std::collections::HashSet<NodeId> = ids.iter().filter_map(|&id| doc.layer_of(NodeId(id))).collect();
|
||||
let has_other_active = if eye {
|
||||
doc.layers.iter().any(|l| !own_layers.contains(&l.id) && l.visible)
|
||||
} else {
|
||||
doc.layers.iter().any(|l| !own_layers.contains(&l.id) && !l.locked)
|
||||
};
|
||||
let cmd = match (eye, has_other_active) {
|
||||
(true, true) => "layer.hideOthers",
|
||||
(true, false) => "layer.showAll",
|
||||
(false, true) => "layer.lockOthers",
|
||||
(false, false) => "layer.unlockAll",
|
||||
};
|
||||
let enabled = match (eye, has_other_active) {
|
||||
(true, true) | (false, true) => true,
|
||||
(true, false) => any_layer_state(doc, |n| !n.visible),
|
||||
(false, false) => any_layer_state(doc, |n| n.locked),
|
||||
};
|
||||
let params = if cmd.ends_with("Others") { json!({ "ids": ids }) } else { json!({}) };
|
||||
(cmd.into(), params, enabled)
|
||||
}
|
||||
|
||||
fn any_layer_state(doc: &Document, pred: impl Fn(&Node) -> bool) -> bool {
|
||||
let mut found = false;
|
||||
doc.walk(|n| {
|
||||
if !found && n.is_layer() && pred(n) {
|
||||
found = true;
|
||||
}
|
||||
});
|
||||
found
|
||||
}
|
||||
|
||||
/// Alt-clicking row `n`'s eye (`eye`) or lock: Hide Others or Lock Others, every top-level layer
|
||||
/// but the one holding the row; when they all are hidden (locked) already, Show All Layers (Unlock
|
||||
/// All Layers). Each is one undo step.
|
||||
|
||||
@@ -2440,3 +2440,195 @@ fn guide_rows_list_by_index_whatever_the_node_order() {
|
||||
let indexes: Vec<usize> = rows.iter().filter_map(|r| r.guide).collect();
|
||||
assert_eq!(indexes, [2, 1, 0]);
|
||||
}
|
||||
|
||||
/// Right-clicking a row that is not highlighted selects it.
|
||||
#[test]
|
||||
fn context_menu_right_click_selects_unselected_row() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 200, "height": 200})).unwrap();
|
||||
app.session.execute("layer.new", &json!({})).unwrap();
|
||||
app.session.execute("layer.highlight", &json!({"ids": [], "mode": "set"})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
// Rows top-first: Layer 2, Layer 1. Neither is highlighted.
|
||||
let (circles, _) = frame(&mut app, &ctx, vec![], false);
|
||||
assert_eq!(circles.len(), 2);
|
||||
assert!(rows_of(&app).is_empty());
|
||||
// Secondary-click Layer 1's row (bottom row).
|
||||
let pos = circles[1] - vec2(100.0, 0.0); // name area
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(pos)], false);
|
||||
frame(&mut app, &ctx, vec![button_by(pos, true, egui::PointerButton::Secondary)], false);
|
||||
frame(&mut app, &ctx, vec![button_by(pos, false, egui::PointerButton::Secondary)], false);
|
||||
// The row is now highlighted.
|
||||
let highlighted = rows_of(&app);
|
||||
let layer1 = app.session.active().unwrap().doc.layers[0].id;
|
||||
assert!(highlighted.contains(&layer1), "right-click selected the unselected row");
|
||||
assert!(crate::panels::has_row_keys(&ctx, super::ROW_KEYS), "secondary click claims row keys");
|
||||
}
|
||||
|
||||
/// Right-clicking a row that IS highlighted preserves the multiselection.
|
||||
#[test]
|
||||
fn context_menu_right_click_preserves_multiselection() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 200, "height": 200})).unwrap();
|
||||
app.session.execute("layer.new", &json!({})).unwrap();
|
||||
app.session.execute("layer.new", &json!({})).unwrap();
|
||||
let doc = &app.session.active().unwrap().doc;
|
||||
let ids: Vec<u64> = doc.layers.iter().map(|l| l.id.0).collect();
|
||||
// Highlight all 3 layers.
|
||||
app.session.execute("layer.highlight", &json!({"ids": ids, "mode": "set"})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let (circles, _) = frame(&mut app, &ctx, vec![], false);
|
||||
assert_eq!(circles.len(), 3);
|
||||
// Secondary-click the middle row.
|
||||
let pos = circles[1] - vec2(100.0, 0.0);
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(pos)], false);
|
||||
frame(&mut app, &ctx, vec![button_by(pos, true, egui::PointerButton::Secondary)], false);
|
||||
frame(&mut app, &ctx, vec![button_by(pos, false, egui::PointerButton::Secondary)], false);
|
||||
// All 3 must still be highlighted.
|
||||
assert_eq!(rows_of(&app).len(), 3, "multiselection preserved after right-click on a highlighted row");
|
||||
}
|
||||
|
||||
/// layer.delete removes the specified layer.
|
||||
#[test]
|
||||
fn context_menu_delete_dispatches_layer_delete() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 200, "height": 200})).unwrap();
|
||||
let layer2_id = app.session.execute("layer.new", &json!({})).unwrap()["id"].as_u64().unwrap();
|
||||
let before = app.session.active().unwrap().doc.layers.len();
|
||||
// Dispatch layer.delete with explicit ids (what the context menu item does).
|
||||
app.session.execute("layer.delete", &json!({"ids": [layer2_id]})).unwrap();
|
||||
let after = app.session.active().unwrap().doc.layers.len();
|
||||
assert_eq!(after, before - 1, "layer.delete removes the layer");
|
||||
}
|
||||
|
||||
/// layer.duplicate adds a copy.
|
||||
#[test]
|
||||
fn context_menu_duplicate_dispatches_layer_duplicate() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 200, "height": 200})).unwrap();
|
||||
let layer_id = app.session.active().unwrap().doc.layers[0].id.0;
|
||||
let before_layers = app.session.active().unwrap().doc.layers.len();
|
||||
let before_undo = app.session.active().unwrap().history.undo.len();
|
||||
app.session.execute("layer.duplicate", &json!({"ids": [layer_id]})).unwrap();
|
||||
let after = &app.session.active().unwrap();
|
||||
assert_eq!(after.doc.layers.len(), before_layers + 1, "layer.duplicate adds a layer");
|
||||
assert_eq!(after.history.undo.len(), before_undo + 1, "one undo step");
|
||||
}
|
||||
|
||||
/// layer.locate locates a specified object id without requiring a prior canvas selection.
|
||||
#[test]
|
||||
fn context_menu_locate_object_locates_by_id() {
|
||||
let (mut app, _, [a, _]) = two_rects();
|
||||
app.session.execute("select.none", &json!({})).unwrap();
|
||||
assert!(app.session.active().unwrap().selection.objects.is_empty());
|
||||
// Context menu passes the node's id directly to layer.locate.
|
||||
let result = app.session.execute("layer.locate", &json!({"id": a.0}));
|
||||
assert!(result.is_ok(), "layer.locate with id succeeds without selection: {:?}", result.err());
|
||||
assert_eq!(app.session.active().unwrap().highlighted_rows(), vec![a]);
|
||||
}
|
||||
|
||||
/// In a 1-layer document, the Delete action in the context menu is disabled when targeting that layer.
|
||||
#[test]
|
||||
fn context_menu_delete_disabled_when_every_layer_targeted() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 200, "height": 200})).unwrap();
|
||||
let doc = &app.session.active().unwrap().doc;
|
||||
assert_eq!(doc.layers.len(), 1);
|
||||
let layer_id = doc.layers[0].id;
|
||||
|
||||
// Targeting every layer disables delete.
|
||||
let listed: std::collections::HashSet<NodeId> = [layer_id].into_iter().collect();
|
||||
let del_enabled = !doc.layers.iter().all(|l| listed.contains(&l.id));
|
||||
assert!(!del_enabled, "Delete must be disabled when every layer is targeted");
|
||||
|
||||
// Add a second layer: delete is now enabled for one layer.
|
||||
app.session.execute("layer.new", &json!({})).unwrap();
|
||||
let doc = &app.session.active().unwrap().doc;
|
||||
assert_eq!(doc.layers.len(), 2);
|
||||
let del_enabled = !doc.layers.iter().all(|l| listed.contains(&l.id));
|
||||
assert!(del_enabled, "Delete is enabled when at least one layer remains");
|
||||
}
|
||||
|
||||
/// Others actions (Hide Others / Lock Others) retain all multiselected layers.
|
||||
#[test]
|
||||
fn context_menu_others_actions_preserve_multiselected_layers() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 200, "height": 200})).unwrap();
|
||||
app.session.execute("layer.new", &json!({})).unwrap();
|
||||
app.session.execute("layer.new", &json!({})).unwrap();
|
||||
let doc = &app.session.active().unwrap().doc;
|
||||
assert_eq!(doc.layers.len(), 3);
|
||||
let l1 = doc.layers[0].id.0;
|
||||
let l2 = doc.layers[1].id.0;
|
||||
|
||||
// Hide Others with multiselection [l1, l2] hides only l3.
|
||||
let (hide_cmd, hide_params, hide_enabled) = super::rows::multi_others_action(doc, &[l1, l2], true);
|
||||
assert_eq!(hide_cmd, "layer.hideOthers");
|
||||
assert!(hide_enabled);
|
||||
assert_eq!(hide_params["ids"], json!([l1, l2]));
|
||||
|
||||
// Lock Others with multiselection [l1, l2] locks only l3.
|
||||
let (lock_cmd, lock_params, lock_enabled) = super::rows::multi_others_action(doc, &[l1, l2], false);
|
||||
assert_eq!(lock_cmd, "layer.lockOthers");
|
||||
assert!(lock_enabled);
|
||||
assert_eq!(lock_params["ids"], json!([l1, l2]));
|
||||
}
|
||||
|
||||
/// Context menu Others action resolves an object row to its holding top-level layer.
|
||||
#[test]
|
||||
fn context_menu_others_actions_object_row_resolves_to_holding_layer() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 200, "height": 200})).unwrap();
|
||||
// Layer 1 (current) holding a rectangle.
|
||||
let rect = app.session.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 50, "height": 50})).unwrap();
|
||||
let rect_id = rect["id"].as_u64().unwrap();
|
||||
|
||||
// Create Layer 2 and hide it.
|
||||
let l2 = app.session.execute("layer.new", &json!({})).unwrap()["id"].as_u64().unwrap();
|
||||
app.session.execute("layer.setProps", &json!({"ids": [l2], "visible": false})).unwrap();
|
||||
|
||||
let doc = &app.session.active().unwrap().doc;
|
||||
assert_eq!(doc.layers.len(), 2);
|
||||
|
||||
// Right-clicking the object in Layer 1: Layer 1 is visible, Layer 2 is hidden.
|
||||
// There are no other visible layers, so the action should be Show All Layers, enabled.
|
||||
let (hide_cmd, _hide_params, hide_enabled) = super::rows::multi_others_action(doc, &[rect_id], true);
|
||||
assert_eq!(hide_cmd, "layer.showAll");
|
||||
assert!(hide_enabled, "Show All Layers is enabled because Layer 2 is hidden");
|
||||
|
||||
// Now make Layer 2 visible, but lock it.
|
||||
app.session.execute("layer.setProps", &json!({"ids": [l2], "visible": true, "locked": true})).unwrap();
|
||||
let doc = &app.session.active().unwrap().doc;
|
||||
// Right-clicking the object in Layer 1: Layer 1 is unlocked, Layer 2 is locked.
|
||||
// There are no other unlocked layers, so the action should be Unlock All Layers, enabled.
|
||||
let (lock_cmd, _lock_params, lock_enabled) = super::rows::multi_others_action(doc, &[rect_id], false);
|
||||
assert_eq!(lock_cmd, "layer.unlockAll");
|
||||
assert!(lock_enabled, "Unlock All Layers is enabled because Layer 2 is locked");
|
||||
}
|
||||
|
||||
/// Context menu Show/Unlock All Layers are enabled when sublayers are hidden or locked.
|
||||
#[test]
|
||||
fn context_menu_others_actions_sublayer_state_enables_all_commands() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 200, "height": 200})).unwrap();
|
||||
let doc = &app.session.active().unwrap().doc;
|
||||
assert_eq!(doc.layers.len(), 1);
|
||||
let l1 = doc.layers[0].id.0;
|
||||
|
||||
// Create a sublayer in Layer 1.
|
||||
let sub = app.session.execute("layer.newSublayer", &json!({"parent": l1})).unwrap()["id"].as_u64().unwrap();
|
||||
|
||||
// Case 1: Sublayer is hidden while top layer is visible.
|
||||
app.session.execute("layer.setProps", &json!({"ids": [sub], "visible": false})).unwrap();
|
||||
let doc = &app.session.active().unwrap().doc;
|
||||
let (hide_cmd, _, hide_enabled) = super::rows::multi_others_action(doc, &[l1], true);
|
||||
assert_eq!(hide_cmd, "layer.showAll");
|
||||
assert!(hide_enabled, "hidden sublayer enables Show All Layers");
|
||||
|
||||
// Case 2: Sublayer is visible, but locked while top layer is unlocked.
|
||||
app.session.execute("layer.setProps", &json!({"ids": [sub], "visible": true, "locked": true})).unwrap();
|
||||
let doc = &app.session.active().unwrap().doc;
|
||||
let (lock_cmd, _, lock_enabled) = super::rows::multi_others_action(doc, &[l1], false);
|
||||
assert_eq!(lock_cmd, "layer.unlockAll");
|
||||
assert!(lock_enabled, "locked sublayer enables Unlock All Layers");
|
||||
}
|
||||
|
||||
@@ -571,7 +571,10 @@ pub(crate) fn craft_font_name(f: &vectorcraft_text::CraftFont) -> String {
|
||||
fn add_craft_fonts(fonts: &mut FontDefinitions) {
|
||||
// The name of each face's copy in each family.
|
||||
let mut copies: std::collections::HashMap<(FontFamily, String), String> = std::collections::HashMap::new();
|
||||
for f in vectorcraft_text::CRAFT_FONTS.iter().filter(|f| f.is_japanese() || f.is_georgian() || f.scripts.contains(&"Deva")) {
|
||||
for f in vectorcraft_text::CRAFT_FONTS
|
||||
.iter()
|
||||
.filter(|f| f.is_japanese() || f.is_georgian() || f.scripts.contains(&"Deva") || f.scripts.contains(&"Gujr"))
|
||||
{
|
||||
let name = craft_font_name(f);
|
||||
for (copy, data, families) in crate::ui_fonts::baseline_copies(fonts, &name, &FontData::from_static(f.bytes)) {
|
||||
for family in families {
|
||||
@@ -589,6 +592,7 @@ fn add_craft_fonts(fonts: &mut FontDefinitions) {
|
||||
stack.extend(vectorcraft_text::craft_fonts::japanese_ui_fonts(bold).into_iter().map(copy));
|
||||
stack.extend(vectorcraft_text::craft_fonts::georgian_ui_fonts().into_iter().map(copy));
|
||||
stack.extend(vectorcraft_text::CRAFT_FONTS.iter().filter(|f| f.scripts.contains(&"Deva")).map(copy));
|
||||
stack.extend(vectorcraft_text::CRAFT_FONTS.iter().filter(|f| f.scripts.contains(&"Gujr")).map(copy));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user