diff --git a/crates/ui-egui/src/dialogs/action_batch.rs b/crates/ui-egui/src/dialogs/action_batch.rs index 61ef75c5e1..3bf7d2efd0 100644 --- a/crates/ui-egui/src/dialogs/action_batch.rs +++ b/crates/ui-egui/src/dialogs/action_batch.rs @@ -23,14 +23,24 @@ pub fn open(app: &mut VectorcraftApp, set: usize, action: usize) -> Result Result<(), String> { + if crate::panels::actions::has_stop(commands) { + return Err("Batch cannot play an action with a stop".into()); + } + if commands.iter().any(crate::panels::actions::is_ui_step) { + return Err("Batch cannot play an action with a View menu step".into()); + } + Ok(()) +} + fn initial_fields(set: usize, action: usize, name: &str) -> Value { json!({ "set": set, @@ -119,9 +129,7 @@ fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result { if commands.is_empty() { return Err("the action has no included steps".into()); } - if crate::panels::actions::has_stop(&commands) { - return Err("Batch cannot play an action with a stop".into()); - } + refuse_steps(&commands)?; let source = d.str("source"); if source == "folder" && d.str("folder").trim().is_empty() { return Err("choose a source folder".into()); diff --git a/crates/ui-egui/src/dialogs/action_insert_menu_item.rs b/crates/ui-egui/src/dialogs/action_insert_menu_item.rs index 2cf0ab6127..0b4bd8dc7d 100644 --- a/crates/ui-egui/src/dialogs/action_insert_menu_item.rs +++ b/crates/ui-egui/src/dialogs/action_insert_menu_item.rs @@ -207,43 +207,86 @@ mod tests { assert_eq!((d.str("note"), d.str("command")), ("none".to_string(), "object.ungroup".to_string()), "a failed Find keeps the pick"); } - /// The list holds the menu items that run an engine command without asking for values first, - /// outside the application, File, Window and Help menus, and leaves out Undo, Redo, the Pastes, - /// Object › Align, Image Trace's Make and Make and Expand, Pattern's Make and Edit Pattern and the - /// saved-selection, saved-view and recent-font items. + /// The list holds the menu items that run an engine command, and the View menu items that the + /// app runs itself, without asking for values first, outside the application, File, Window and + /// Help menus, and leaves out Undo, Redo, the Pastes, Image Trace's Make and Make and Expand, + /// Pattern's Make and Edit Pattern and the saved-selection, saved-view and recent-font items. #[test] fn the_list_holds_only_menu_items_that_can_be_steps() { let items = menus::insertable_items(true); assert!(items.len() > 100, "only {} items", items.len()); for item in &items { - assert!(vectorcraft_engine::find_command(item.command).is_some(), "{item:?}"); + let in_app = menus::plays_in_app(item.command); + assert!(vectorcraft_engine::find_command(item.command).is_some() != in_app, "{item:?}"); + assert!(!in_app || item.path[0] == "View", "{item:?}"); assert!(!item.label.ends_with('…'), "{item:?}"); assert!(!["VectorCraft", "File", "Window", "Help"].contains(&item.path[0]), "{item:?}"); assert!(item.params.is_object(), "{item:?}"); } let has = |command: &str| items.iter().any(|i| i.command == command); - for command in ["object.group", "object.ungroup", "object.arrange.bringToFront"] { + for command in [ + "object.group", + "object.ungroup", + "object.arrange.bringToFront", + "object.align", + "view.outline", + "view.zoomIn", + "view.fitArtboard", + "view.rotate", + "view.rulers", + "view.snapToGrid", + "view.guides.lock", + ] { assert!(has(command), "{command}"); } + let aligns = items.iter().filter(|i| i.command == "object.align").count(); + assert_eq!(aligns, 7, "each Object › Align item, by its params"); for command in [ "edit.undo", "edit.redo", "edit.paste", "edit.pasteInFront", "object.move", - "object.align", "imageTrace.make", "imageTrace.makeAndExpand", "object.pattern.make", "object.pattern.edit", "file.save", - "view.zoomIn", + "window.panel", + "view.goto1", + "view.saved.new", "select.recall1", ] { assert!(!has(command), "{command}"); } } + /// Every View menu item that the app runs itself is listed, apart from the saved-view slots, the + /// Perspective Grid presets (`ui.` commands, whose items follow the presets in the preferences) + /// and the items that ask for values first. + #[test] + fn every_view_item_the_app_runs_is_listed() { + let items = menus::insertable_items(true); + let view = menus::menu_tree_named(true).into_iter().find(|(title, _)| *title == "View").map(|(_, items)| items).unwrap(); + fn walk(items: &[menus::Item], out: &mut Vec<(&'static str, &'static str)>) { + for it in items { + match it { + menus::Item::Cmd(label, id, _) => out.push((label, id)), + menus::Item::Sub(_, children) => walk(children, out), + _ => {} + } + } + } + let mut all = vec![]; + walk(&view, &mut all); + for (label, id) in all { + let ui = vectorcraft_engine::find_command(id).is_none() && menus::UI_COMMANDS.iter().any(|c| c.0 == id); + if ui && !label.ends_with('…') && !id.starts_with("view.goto") && !id.starts_with("ui.") { + assert!(items.iter().any(|i| i.command == id), "{label} ({id})"); + } + } + } + /// Rows show their menu path in the UI language, and Find matches the English path, the shown /// one and the command id. #[test] diff --git a/crates/ui-egui/src/i18n/bg.tsv b/crates/ui-egui/src/i18n/bg.tsv index 3828d9ba2d..6923892939 100644 --- a/crates/ui-egui/src/i18n/bg.tsv +++ b/crates/ui-egui/src/i18n/bg.tsv @@ -5995,6 +5995,7 @@ axis Y Axis Y ос @msg message must be text message трябва да бъде текст @msg allowContinue must be true or false allowContinue трябва да бъде true или false @msg Batch cannot play an action with a stop Пакет не може да изпълни действие със спиране +@msg Batch cannot play an action with a View menu step Пакет не може да изпълни действие със стъпка от менюто Изглед Insert Menu Item… Вмъкване на елемент от меню… Insert Menu Item Вмъкване на елемент от меню Insert Select Path Вмъкване на избор на път diff --git a/crates/ui-egui/src/i18n/bs.tsv b/crates/ui-egui/src/i18n/bs.tsv index 81fee3a079..67e7f3422a 100644 --- a/crates/ui-egui/src/i18n/bs.tsv +++ b/crates/ui-egui/src/i18n/bs.tsv @@ -6037,6 +6037,7 @@ axis Y Axis Y osa @msg message must be text message mora biti tekst @msg allowContinue must be true or false allowContinue mora biti true ili false @msg Batch cannot play an action with a stop Paketna obrada ne može reprodukovati akciju sa zaustavljanjem +@msg Batch cannot play an action with a View menu step Paketna obrada ne može reprodukovati akciju s korakom iz menija Prikaz Insert Menu Item… Umetni stavku menija… Insert Menu Item Umetni stavku menija Insert Select Path Umetni odabir putanje diff --git a/crates/ui-egui/src/i18n/ca.tsv b/crates/ui-egui/src/i18n/ca.tsv index 02ae0f4a09..06e11e4eea 100644 --- a/crates/ui-egui/src/i18n/ca.tsv +++ b/crates/ui-egui/src/i18n/ca.tsv @@ -4049,6 +4049,7 @@ digits Malayalam Malaiàlam @msg message must be text message ha de ser text @msg allowContinue must be true or false allowContinue ha de ser true o false @msg Batch cannot play an action with a stop Lot no pot reproduir una acció amb una aturada +@msg Batch cannot play an action with a View menu step Lot no pot reproduir una acció amb un pas del menú Visualitza Insert Menu Item… Insereix un element de menú… Insert Menu Item Insereix un element de menú Insert Select Path Insereix una selecció de traçat diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv index 7e3794e8a1..4c53c0a420 100644 --- a/crates/ui-egui/src/i18n/cs.tsv +++ b/crates/ui-egui/src/i18n/cs.tsv @@ -6530,6 +6530,7 @@ axis Y Axis osa Y @msg message must be text message musí být text @msg allowContinue must be true or false allowContinue musí být true nebo false @msg Batch cannot play an action with a stop Dávka nemůže přehrát akci se zastavením +@msg Batch cannot play an action with a View menu step Dávka nemůže přehrát akci s krokem z nabídky Zobrazení Insert Menu Item… Vložit položku nabídky… Insert Menu Item Vložit položku nabídky Insert Select Path Vložit výběr cesty diff --git a/crates/ui-egui/src/i18n/da.tsv b/crates/ui-egui/src/i18n/da.tsv index f7011e23bf..b96fe18ef9 100644 --- a/crates/ui-egui/src/i18n/da.tsv +++ b/crates/ui-egui/src/i18n/da.tsv @@ -6012,6 +6012,7 @@ axis Y Axis Y-akse @msg message must be text message skal være tekst @msg allowContinue must be true or false allowContinue skal være true eller false @msg Batch cannot play an action with a stop Batch kan ikke afspille en handling med et stop +@msg Batch cannot play an action with a View menu step Batch kan ikke afspille en handling med et trin fra menuen Vis Insert Menu Item… Indsæt menupunkt… Insert Menu Item Indsæt menupunkt Insert Select Path Indsæt kurvemarkering diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv index 4174537f87..2f34a07a7d 100644 --- a/crates/ui-egui/src/i18n/de.tsv +++ b/crates/ui-egui/src/i18n/de.tsv @@ -6121,6 +6121,7 @@ axis Y Axis Y-Achse @msg message must be text message muss Text sein @msg allowContinue must be true or false allowContinue muss true oder false sein @msg Batch cannot play an action with a stop Die Stapelverarbeitung kann keine Aktion mit einem Stopp abspielen +@msg Batch cannot play an action with a View menu step Die Stapelverarbeitung kann keine Aktion mit einem Schritt aus dem Menü Ansicht abspielen Insert Menu Item… Menübefehl einfügen… Insert Menu Item Menübefehl einfügen Insert Select Path Pfadauswahl einfügen diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv index bde2fbee78..00c259c6ee 100644 --- a/crates/ui-egui/src/i18n/el.tsv +++ b/crates/ui-egui/src/i18n/el.tsv @@ -6481,6 +6481,7 @@ axis Y Axis Άξονας Y @msg message must be text Το message πρέπει να είναι κείμενο @msg allowContinue must be true or false Το allowContinue πρέπει να είναι true ή false @msg Batch cannot play an action with a stop Η μαζική επεξεργασία δεν μπορεί να αναπαράγει ενέργεια με διακοπή +@msg Batch cannot play an action with a View menu step Η μαζική επεξεργασία δεν μπορεί να αναπαράγει ενέργεια με βήμα από το μενού Προβολή Insert Menu Item… Εισαγωγή στοιχείου μενού… Insert Menu Item Εισαγωγή στοιχείου μενού Insert Select Path Εισαγωγή επιλογής διαδρομής diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv index ff28d9dfc5..84b3c1b402 100644 --- a/crates/ui-egui/src/i18n/es.tsv +++ b/crates/ui-egui/src/i18n/es.tsv @@ -6472,6 +6472,7 @@ axis Y Axis Eje Y @msg message must be text message debe ser texto @msg allowContinue must be true or false allowContinue debe ser true o false @msg Batch cannot play an action with a stop Lote no puede reproducir una acción con una parada +@msg Batch cannot play an action with a View menu step Lote no puede reproducir una acción con un paso del menú Ver Insert Menu Item… Insertar elemento de menú… Insert Menu Item Insertar elemento de menú Insert Select Path Insertar selección de trazado diff --git a/crates/ui-egui/src/i18n/fi.tsv b/crates/ui-egui/src/i18n/fi.tsv index bb74188ed8..0bee1219f9 100644 --- a/crates/ui-egui/src/i18n/fi.tsv +++ b/crates/ui-egui/src/i18n/fi.tsv @@ -6560,6 +6560,7 @@ axis Y Axis Y-akseli @msg message must be text message on oltava tekstiä @msg allowContinue must be true or false allowContinue on oltava true tai false @msg Batch cannot play an action with a stop Erä ei voi toistaa toimintoa, jossa on pysäytys +@msg Batch cannot play an action with a View menu step Erä ei voi toistaa toimintoa, jossa on Näytä-valikon vaihe Insert Menu Item… Lisää valikkokohta… Insert Menu Item Lisää valikkokohta Insert Select Path Lisää polun valinta diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv index 09c9c35b0d..e74a8144b2 100644 --- a/crates/ui-egui/src/i18n/fr.tsv +++ b/crates/ui-egui/src/i18n/fr.tsv @@ -6525,6 +6525,7 @@ axis Y Axis Axe Y @msg message must be text message doit être du texte @msg allowContinue must be true or false allowContinue doit valoir true ou false @msg Batch cannot play an action with a stop Le traitement par lots ne peut pas exécuter un script comportant un arrêt +@msg Batch cannot play an action with a View menu step Le traitement par lots ne peut pas exécuter un script comportant une étape du menu Affichage Insert Menu Item… Insérer une commande de menu… Insert Menu Item Insérer une commande de menu Insert Select Path Insérer une sélection de tracé diff --git a/crates/ui-egui/src/i18n/hi.tsv b/crates/ui-egui/src/i18n/hi.tsv index 9aa4bd7b99..8ce396dffc 100644 --- a/crates/ui-egui/src/i18n/hi.tsv +++ b/crates/ui-egui/src/i18n/hi.tsv @@ -3478,6 +3478,7 @@ antiAlias Sharp शार्प @msg message must be text message टेक्स्ट होना चाहिए @msg allowContinue must be true or false allowContinue true या false होना चाहिए @msg Batch cannot play an action with a stop बैच स्टॉप वाला एक्शन नहीं चला सकता +@msg Batch cannot play an action with a View menu step बैच व्यू मेनू के चरण वाला एक्शन नहीं चला सकता Insert Menu Item… मेनू आइटम जोड़ें… Insert Menu Item मेनू आइटम जोड़ें Insert Select Path सिलेक्ट पाथ जोड़ें diff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsv index af6f586880..5c507dc7df 100644 --- a/crates/ui-egui/src/i18n/hu.tsv +++ b/crates/ui-egui/src/i18n/hu.tsv @@ -6513,6 +6513,7 @@ axis Y Axis Y tengely @msg message must be text message: szöveg kell @msg allowContinue must be true or false allowContinue: true vagy false kell @msg Batch cannot play an action with a stop A kötegelt feldolgozás nem játszhat le megállást tartalmazó műveletet +@msg Batch cannot play an action with a View menu step A kötegelt feldolgozás nem játszhat le Nézet menübeli lépést tartalmazó műveletet Insert Menu Item… Menüelem beszúrása… Insert Menu Item Menüelem beszúrása Insert Select Path Útvonal kijelölésének beszúrása diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv index e0ba31ecd5..9a50c48251 100644 --- a/crates/ui-egui/src/i18n/id.tsv +++ b/crates/ui-egui/src/i18n/id.tsv @@ -6012,6 +6012,7 @@ axis Y Axis Sumbu Y @msg message must be text message harus berupa teks @msg allowContinue must be true or false allowContinue harus true atau false @msg Batch cannot play an action with a stop Batch tidak dapat memutar tindakan dengan titik henti +@msg Batch cannot play an action with a View menu step Batch tidak dapat memutar tindakan dengan langkah menu Tampilan Insert Menu Item… Sisipkan item menu… Insert Menu Item Sisipkan item menu Insert Select Path Sisipkan pemilihan jalur diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv index ce0bc58ce5..9973763b74 100644 --- a/crates/ui-egui/src/i18n/it.tsv +++ b/crates/ui-egui/src/i18n/it.tsv @@ -6155,6 +6155,7 @@ axis Y Axis Asse Y @msg message must be text message deve essere testo @msg allowContinue must be true or false allowContinue deve essere true o false @msg Batch cannot play an action with a stop L'elaborazione batch non può eseguire un'azione con un'interruzione +@msg Batch cannot play an action with a View menu step L'elaborazione batch non può eseguire un'azione con un passaggio del menu Visualizza Insert Menu Item… Inserisci voce di menu… Insert Menu Item Inserisci voce di menu Insert Select Path Inserisci selezione tracciato diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv index 1ecce4618a..92734972c1 100644 --- a/crates/ui-egui/src/i18n/ja.tsv +++ b/crates/ui-egui/src/i18n/ja.tsv @@ -6220,6 +6220,7 @@ axis Y Axis Y 軸 @msg message must be text message にはテキストを指定してください @msg allowContinue must be true or false allowContinue には true または false を指定してください @msg Batch cannot play an action with a stop バッチでは停止を含むアクションを再生できません +@msg Batch cannot play an action with a View menu step バッチでは表示メニューのステップを含むアクションを再生できません Insert Menu Item… メニュー項目を挿入… Insert Menu Item メニュー項目を挿入 Insert Select Path パスの選択を挿入 diff --git a/crates/ui-egui/src/i18n/ka.tsv b/crates/ui-egui/src/i18n/ka.tsv index 3d6425c373..69d2769ab2 100644 --- a/crates/ui-egui/src/i18n/ka.tsv +++ b/crates/ui-egui/src/i18n/ka.tsv @@ -6481,6 +6481,7 @@ axis Y Axis Y ღერძი @msg message must be text message უნდა იყოს ტექსტი @msg allowContinue must be true or false allowContinue უნდა იყოს true ან false @msg Batch cannot play an action with a stop პაკეტურ დამუშავებას არ შეუძლია გაჩერების მქონე მოქმედების შესრულება +@msg Batch cannot play an action with a View menu step პაკეტურ დამუშავებას არ შეუძლია ხედის მენიუს ნაბიჯის მქონე მოქმედების შესრულება Insert Menu Item… მენიუს ელემენტის ჩასმა… Insert Menu Item მენიუს ელემენტის ჩასმა Insert Select Path ტრაექტორიის მონიშვნის ჩასმა diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv index fb87488d64..d77c2ce633 100644 --- a/crates/ui-egui/src/i18n/ko.tsv +++ b/crates/ui-egui/src/i18n/ko.tsv @@ -6116,6 +6116,7 @@ axis Y Axis Y축 @msg message must be text message의 값은 텍스트여야 합니다 @msg allowContinue must be true or false allowContinue의 값은 true 또는 false여야 합니다 @msg Batch cannot play an action with a stop 일괄 처리에서는 중지가 있는 액션을 재생할 수 없습니다 +@msg Batch cannot play an action with a View menu step 일괄 처리에서는 보기 메뉴 단계가 있는 액션을 재생할 수 없습니다 Insert Menu Item… 메뉴 항목 삽입… Insert Menu Item 메뉴 항목 삽입 Insert Select Path 패스 선택 삽입 diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv index b3388fa82a..c813d29720 100644 --- a/crates/ui-egui/src/i18n/nl.tsv +++ b/crates/ui-egui/src/i18n/nl.tsv @@ -6063,6 +6063,7 @@ axis Y Axis Y-as @msg message must be text message moet tekst zijn @msg allowContinue must be true or false allowContinue moet true of false zijn @msg Batch cannot play an action with a stop Batch kan geen actie met een stop afspelen +@msg Batch cannot play an action with a View menu step Batch kan geen actie met een stap uit het menu Beeld afspelen Insert Menu Item… Menu-item invoegen… Insert Menu Item Menu-item invoegen Insert Select Path Pad selecteren invoegen diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv index 0729e35c79..ad825516fa 100644 --- a/crates/ui-egui/src/i18n/pl.tsv +++ b/crates/ui-egui/src/i18n/pl.tsv @@ -6384,6 +6384,7 @@ axis Y Axis Oś Y @msg message must be text message musi być tekstem @msg allowContinue must be true or false allowContinue musi mieć wartość true lub false @msg Batch cannot play an action with a stop Przetwarzanie wsadowe nie może odtworzyć operacji z zatrzymaniem +@msg Batch cannot play an action with a View menu step Przetwarzanie wsadowe nie może odtworzyć operacji z krokiem z menu Widok Insert Menu Item… Wstaw polecenie menu… Insert Menu Item Wstaw polecenie menu Insert Select Path Wstaw zaznaczenie ścieżki diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv index 36f778dbd5..22f371a8fd 100644 --- a/crates/ui-egui/src/i18n/pt-br.tsv +++ b/crates/ui-egui/src/i18n/pt-br.tsv @@ -6445,6 +6445,7 @@ axis Y Axis Eixo Y @msg message must be text message deve ser texto @msg allowContinue must be true or false allowContinue deve ser true ou false @msg Batch cannot play an action with a stop Lote não pode reproduzir uma ação com uma parada +@msg Batch cannot play an action with a View menu step Lote não pode reproduzir uma ação com uma etapa do menu Exibir Insert Menu Item… Inserir Item de Menu… Insert Menu Item Inserir Item de Menu Insert Select Path Inserir Seleção de Caminho diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv index 442a9612d4..a3a361b4c3 100644 --- a/crates/ui-egui/src/i18n/ru.tsv +++ b/crates/ui-egui/src/i18n/ru.tsv @@ -6141,6 +6141,7 @@ axis Y Axis Ось Y @msg message must be text message должно быть текстом @msg allowContinue must be true or false allowContinue должно быть true или false @msg Batch cannot play an action with a stop Пакет не может воспроизвести действие с остановкой +@msg Batch cannot play an action with a View menu step Пакет не может воспроизвести действие с шагом из меню Просмотр Insert Menu Item… Вставить пункт меню… Insert Menu Item Вставить пункт меню Insert Select Path Вставить выделение контура diff --git a/crates/ui-egui/src/i18n/sv.tsv b/crates/ui-egui/src/i18n/sv.tsv index 8a8f8453b6..3e2d4b9990 100644 --- a/crates/ui-egui/src/i18n/sv.tsv +++ b/crates/ui-egui/src/i18n/sv.tsv @@ -6511,6 +6511,7 @@ axis Y Axis Y-axel @msg message must be text message måste vara text @msg allowContinue must be true or false allowContinue måste vara true eller false @msg Batch cannot play an action with a stop Batch kan inte spela upp en åtgärd med ett stopp +@msg Batch cannot play an action with a View menu step Batch kan inte spela upp en åtgärd med ett steg från menyn Visa Insert Menu Item… Infoga menyalternativ… Insert Menu Item Infoga menyalternativ Insert Select Path Infoga markering av bana diff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsv index ef8773c31b..d4edfbbc5b 100644 --- a/crates/ui-egui/src/i18n/tr.tsv +++ b/crates/ui-egui/src/i18n/tr.tsv @@ -6486,6 +6486,7 @@ axis Y Axis Y ekseni @msg message must be text "message" metin olmalıdır @msg allowContinue must be true or false "allowContinue" true veya false olmalıdır @msg Batch cannot play an action with a stop Toplu işlem durak içeren bir eylemi oynatamaz +@msg Batch cannot play an action with a View menu step Toplu işlem Görünüm menüsü adımı içeren bir eylemi oynatamaz Insert Menu Item… Menü Öğesi Ekle… Insert Menu Item Menü Öğesi Ekle Insert Select Path Yol Seçimi Ekle diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv index 0bccbd8cb6..6fd22c7d02 100644 --- a/crates/ui-egui/src/i18n/uk.tsv +++ b/crates/ui-egui/src/i18n/uk.tsv @@ -6135,6 +6135,7 @@ axis Y Axis Вісь Y @msg message must be text message має бути текстом @msg allowContinue must be true or false allowContinue має бути true або false @msg Batch cannot play an action with a stop Пакет не може відтворити дію із зупинкою +@msg Batch cannot play an action with a View menu step Пакет не може відтворити дію з кроком із меню Перегляд Insert Menu Item… Вставити пункт меню… Insert Menu Item Вставити пункт меню Insert Select Path Вставити виділення контуру diff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsv index 4f084029db..295e645ad2 100644 --- a/crates/ui-egui/src/i18n/vi.tsv +++ b/crates/ui-egui/src/i18n/vi.tsv @@ -6136,6 +6136,7 @@ axis Y Axis Trục Y @msg message must be text message phải là văn bản @msg allowContinue must be true or false allowContinue phải là true hoặc false @msg Batch cannot play an action with a stop Hàng loạt không thể phát hành động có điểm dừng +@msg Batch cannot play an action with a View menu step Hàng loạt không thể phát hành động có bước của menu Hiển thị Insert Menu Item… Chèn mục menu… Insert Menu Item Chèn mục menu Insert Select Path Chèn chọn đường dẫn diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv index b04e65a65b..07059f8caf 100644 --- a/crates/ui-egui/src/i18n/zh-hans.tsv +++ b/crates/ui-egui/src/i18n/zh-hans.tsv @@ -6368,6 +6368,7 @@ axis Y Axis Y 轴 @msg message must be text message 必须是文本 @msg allowContinue must be true or false allowContinue 必须是 true 或 false @msg Batch cannot play an action with a stop 批处理无法播放含有停止的动作 +@msg Batch cannot play an action with a View menu step 批处理无法播放含有视图菜单步骤的动作 Insert Menu Item… 插入菜单项… Insert Menu Item 插入菜单项 Insert Select Path 插入选择路径 diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv index be62fde8a7..c03f36991f 100644 --- a/crates/ui-egui/src/i18n/zh-hant.tsv +++ b/crates/ui-egui/src/i18n/zh-hant.tsv @@ -6173,6 +6173,7 @@ axis Y Axis Y 軸 @msg message must be text message 必須是文字 @msg allowContinue must be true or false allowContinue 必須是 true 或 false @msg Batch cannot play an action with a stop 批次無法播放含有停止的動作 +@msg Batch cannot play an action with a View menu step 批次無法播放含有檢視選單步驟的動作 Insert Menu Item… 插入選單項目… Insert Menu Item 插入選單項目 Insert Select Path 插入選取路徑 diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs index 26dd765d29..4e2d80bb45 100644 --- a/crates/ui-egui/src/menus.rs +++ b/crates/ui-egui/src/menus.rs @@ -65,7 +65,7 @@ pub(crate) use bar::{home_key, home_showing}; use bar::{menu_body, pointer_reaches_title}; pub use context::{context_items, context_menu_body, ruler_menu_body, ruler_unit_items}; pub use entries::{ - InsertableItem, MenuEntry, Row, context_entries, entry, insertable, insertable_items, menu_entries, pretty_shortcut, shown_shortcut, + InsertableItem, MenuEntry, Row, context_entries, entry, insertable, insertable_items, menu_entries, plays_in_app, pretty_shortcut, shown_shortcut, }; pub(crate) use invoke::graph_dialog; #[cfg(test)] diff --git a/crates/ui-egui/src/menus/entries.rs b/crates/ui-egui/src/menus/entries.rs index 42ad7b6555..953b5b58f4 100644 --- a/crates/ui-egui/src/menus/entries.rs +++ b/crates/ui-egui/src/menus/entries.rs @@ -150,20 +150,65 @@ const NOT_INSERTED_MENUS: [&str; 4] = ["VectorCraft", "File", "Window", "Help"]; /// Options panel. const MENU_ONLY_COMMANDS: [&str; 4] = ["imageTrace.make", "imageTrace.makeAndExpand", "object.pattern.make", "object.pattern.edit"]; +/// The View menu commands that the app runs itself, not the engine, and that can be steps of an +/// action ([`plays_in_app`]): Outline, Pixel Preview, Trim View, Presentation Mode and Screen Mode, +/// the zoom, fit and rotate view items, and the items that show or hide or turn snapping on or off. +/// The saved-view slots are not among them. +const UI_STEP_COMMANDS: [&str; 30] = [ + "view.outline", + "view.pixelPreview", + "view.trimView", + "view.presentation", + "view.screenMode", + "view.zoomIn", + "view.zoomOut", + "view.fitArtboard", + "view.fitAll", + "view.actualSize", + "view.rotate", + "view.rotateToSelection", + "view.rotateReset", + "view.edges", + "view.artboards", + "view.template", + "view.rulers", + "view.videoRulers", + "view.boundingBox", + "view.textThreads", + "view.gradientAnnotator", + "view.cornerWidget", + "view.livePaintGaps", + "view.guides", + "view.smartGuides", + "view.grid", + "view.snapToGrid", + "view.snapToPixel", + "view.snapToPoint", + "view.snapToGlyph", +]; + +/// Whether a step that runs command `id` is a View menu command that the app runs itself +/// ([`UI_STEP_COMMANDS`]). Action playback runs such a step on its own, as its menu item runs it, +/// and not inside `command.batch`. +pub fn plays_in_app(id: &str) -> bool { + UI_STEP_COMMANDS.contains(&id) +} + /// Whether the item labeled `label` in menu `title`, which runs command `id` with `p`, can be a step /// of an action. It can when it runs an engine command, which action playback runs as the menu -/// does; its label does not end with "…", the mark of an item that asks for values first; it is not -/// in a menu of [`NOT_INSERTED_MENUS`]; and it is not Undo, Redo, a Paste, an item that stands for a -/// saved selection, a saved view or a recent font, a plug-in's item or an action's own command. Nor -/// is it Object › Align, whose menu items add the Align To choice and the selection's key to their -/// params when clicked ([`crate::panels::align::with_align_to`]), which playback does not, or another -/// item of [`MENU_ONLY_COMMANDS`]. +/// does, or is a View menu item that the app runs itself ([`plays_in_app`]); its label does not end +/// with "…", the mark of an item that asks for values first; it is not in a menu of +/// [`NOT_INSERTED_MENUS`]; and it is not Undo, Redo, a Paste, an item that stands for a saved +/// selection, a saved view or a recent font, a plug-in's item, an action's own command or another +/// item of [`MENU_ONLY_COMMANDS`]. An Object › Align item can be a step: inserting it adds the Align +/// To choice of that moment to its params, as clicking it does +/// ([`crate::panels::align::with_align_to`]). pub fn insertable(title: &str, label: &str, id: &str, p: &Value) -> bool { use super::slots::{RECENT_FONT_IDS, SAVED_SELECTION_IDS, SAVED_VIEW_IDS}; - vectorcraft_engine::find_command(id).is_some() + (vectorcraft_engine::find_command(id).is_some() || (title == "View" && plays_in_app(id))) && !label.ends_with('…') && !NOT_INSERTED_MENUS.contains(&title) - && !matches!(id, "edit.undo" | "edit.redo" | "command.batch" | "object.align") + && !matches!(id, "edit.undo" | "edit.redo" | "command.batch") && !MENU_ONLY_COMMANDS.contains(&id) && !id.starts_with("edit.paste") && !id.starts_with("prefs.") diff --git a/crates/ui-egui/src/menus/invoke.rs b/crates/ui-egui/src/menus/invoke.rs index 9d30b2a5b6..262e346c2c 100644 --- a/crates/ui-egui/src/menus/invoke.rs +++ b/crates/ui-egui/src/menus/invoke.rs @@ -178,10 +178,7 @@ pub fn invoke(app: &mut VectorcraftApp, id: &str, p: Value) { // Object → Align aligns to what the align buttons align to, unless the call names `to`. With // anchors selected (Direct Selection) it sends its params unchanged, and the points align to // their own bounds. - let follows_align_to = id == "object.align" - && p.as_object().is_some_and(|o| !o.contains_key("to")) - && app.session.active().is_some_and(|st| st.selection.anchors.is_empty()); - let p = if follows_align_to { crate::panels::align::with_align_to(app, p) } else { p }; + let p = if id == "object.align" { crate::panels::align::menu_align_params(app, p) } else { p }; // Image Trace traces off the UI thread, with its progress (#3098). if matches!(id, "imageTrace.make" | "imageTrace.makeAndExpand") { if let Err(e) = crate::trace_runs::start(app, id, p, false) { diff --git a/crates/ui-egui/src/panels/actions.rs b/crates/ui-egui/src/panels/actions.rs index 8196ad27c2..a357e2cc3a 100644 --- a/crates/ui-egui/src/panels/actions.rs +++ b/crates/ui-egui/src/panels/actions.rs @@ -220,13 +220,17 @@ pub fn default_sets() -> Vec { /// Plays an action at the speed [`UiState::action_playback`](crate::UiState::action_playback) sets. /// Accelerated runs every included step at once as a single undoable batch → what `command.batch` -/// returns. Step by Step and Pause For run the first step now, each as its own undo step, and leave -/// the rest to [`tick_playback`] → {results: [the first step's result], pending: the steps left}. -/// While a paced playback is in progress, another action does not play. +/// returns, {results}. Step by Step and Pause For run the first step now, each as its own undo step, +/// and leave the rest to [`tick_playback`] → {results: [the first step's result], pending: the steps +/// left}. While a paced playback is in progress, another action does not play. /// /// An action with an included stop ([`STOP_STEP`]) plays up to the stop and waits there at any speed /// ([`continue_playback`]). At Accelerated, the steps between two stops are one undo step. → {results: /// [the results of the steps run], pending: the steps left, stops included, atStop: true when it waits} +/// +/// A View menu step ([`is_ui_step`]) runs on its own at every speed, in its place among the steps, and +/// adds no undo step ([`run_steps`]). At Accelerated the steps before it and the steps after it are +/// then one undo step each. pub fn play(app: &mut VectorcraftApp, set: usize, idx: usize) -> Result { let Some(a) = app.ui.action_sets.get(set).and_then(|s| s.actions.get(idx)).cloned() else { return Err("no such action".into()) }; let commands = a.included_commands(); @@ -241,7 +245,7 @@ pub fn play(app: &mut VectorcraftApp, set: usize, idx: usize) -> Result = commands.into(); let Some(first) = steps.pop_front() else { return Err("the action has no included steps".into()) }; @@ -259,10 +263,59 @@ pub fn play(app: &mut VectorcraftApp, set: usize, idx: usize) -> Result Result { - let r = app.replay("command.batch", json!({"label": label, "commands": [step]}))?; - Ok(r.get("results").and_then(|r| r.get(0)).cloned().unwrap_or(Value::Null)) + Ok(run_steps(app, label, vec![step])?.into_iter().next().unwrap_or(Value::Null)) +} + +/// Whether a step as [`Action::included_commands`] gives it is a View menu command that the app runs +/// itself ([`crate::menus::plays_in_app`]), which `command.batch` does not run. +pub(crate) fn is_ui_step(step: &Value) -> bool { + step.get("command").and_then(Value::as_str).is_some_and(crate::menus::plays_in_app) +} + +/// Runs `steps` in order, as saved steps ([`VectorcraftApp::replay`]) → their results. The steps +/// between two View menu steps ([`is_ui_step`]) run as one `command.batch` named `label`, which is one +/// undo step; a View menu step runs on its own ([`play_ui_step`]). A step that fails ends the run with +/// its error: the batch it is in changes nothing, and the steps before that batch stay done. +fn run_steps(app: &mut VectorcraftApp, label: &str, steps: Vec) -> Result, String> { + fn batch(app: &mut VectorcraftApp, label: &str, run: Vec, results: &mut Vec) -> Result<(), String> { + if run.is_empty() { + return Ok(()); + } + let r = app.replay("command.batch", json!({"label": label, "commands": run}))?; + results.extend(r.get("results").and_then(Value::as_array).cloned().unwrap_or_default()); + Ok(()) + } + let mut results = Vec::with_capacity(steps.len()); + let mut run = vec![]; + for step in steps { + if is_ui_step(&step) { + batch(app, label, std::mem::take(&mut run), &mut results)?; + results.push(play_ui_step(app, &step)?); + } else { + run.push(step); + } + } + batch(app, label, run, &mut results)?; + Ok(results) +} + +/// Runs a View menu step as its menu item runs it, which adds no undo step → its result. While an +/// action records, the step goes into the recording too, as a stop does, unless it does not fit in +/// the action ([`recording_room`]): then the status bar shows the reason. +fn play_ui_step(app: &mut VectorcraftApp, step: &Value) -> Result { + let command = step.get("command").and_then(Value::as_str).unwrap_or_default().to_string(); + let params = step.get("params").filter(|p| !p.is_null()).cloned().unwrap_or_else(|| json!({})); + let r = app.replay(&command, params.clone())?; + if app.ui.recording.is_some() { + match recording_room(app, &command, ¶ms) { + Ok(()) => app.session.journal.push((command, params)), + Err(e) => app.status(e), + } + } + Ok(r) } /// [`play`] for an action with a stop: runs what comes before the first stop, or at Step by Step and @@ -271,18 +324,12 @@ fn play_with_stops(app: &mut VectorcraftApp, label: String, commands: Vec let mut steps: std::collections::VecDeque = commands.into(); let run = next_run(&mut steps, options.speed); let ran = !run.is_empty(); - let results = if ran { play_steps(app, &label, run)? } else { vec![] }; + let results = if ran { run_steps(app, &label, run)? } else { vec![] }; app.ui.action_playing = Some(Playing { label, steps, options, next_at: None, hold: false, doc: None, played_in: None, stop: None }); after_run(app, ran); Ok(playback_result(app, results)) } -/// Runs steps of a playback as one undo step, named `label` → the steps' results. -fn play_steps(app: &mut VectorcraftApp, label: &str, steps: Vec) -> Result, String> { - let r = app.run("command.batch", json!({"label": label, "commands": steps}))?; - Ok(r.get("results").and_then(Value::as_array).cloned().unwrap_or_default()) -} - /// Takes the steps that run next as one undo step off the front of `steps`: at Accelerated all of /// them up to the next stop, at the other speeds one. None when a stop comes next. fn next_run(steps: &mut std::collections::VecDeque, speed: PlaybackSpeed) -> Vec { @@ -429,7 +476,7 @@ pub fn continue_playback(app: &mut VectorcraftApp, _: &Value) -> Result Result { if !p.is_object() { return Err("`params` must be an object".into()); @@ -945,6 +997,7 @@ pub fn insert_menu_item(app: &mut VectorcraftApp, p: &Value) -> Result (VectorcraftApp, impl Fn(&VectorcraftApp) -> f64) { + let (mut app, x) = app_with_three_moves(); + let doc = app.session.active().unwrap().doc.clone(); + let r = app.run(INSERT_MENU_ITEM, json!({"set": 0, "action": 0, "step": 0, "command": "view.outline"})).unwrap(); + assert_eq!(r, json!({"set": 0, "action": 0, "step": 1})); + assert!(!app.outline_view(), "inserting runs nothing"); + assert!(std::sync::Arc::ptr_eq(&app.session.active().unwrap().doc, &doc)); + assert_eq!(app.ui.action_sets[0].actions[0].steps[1], ("view.outline".to_string(), json!({}))); + (app, x) + } + + /// At Accelerated a View menu step plays in its place: the steps before it are one undo step, + /// the View step adds none, and the steps after it are one more. + #[test] + fn an_inserted_view_item_plays_in_its_place_at_accelerated() { + let (mut app, x) = app_with_a_view_step(); + let before = undo_steps(&app); + let r = play(&mut app, 0, 0).unwrap(); + assert_eq!(r["results"].as_array().map(Vec::len), Some(4), "{r}"); + assert_eq!(r["results"][1], json!(true), "Outline turned on: {r}"); + assert!(app.outline_view()); + assert_eq!(x(&app), 7.0); + assert_eq!(undo_steps(&app), before + 2, "the moves on each side of Outline are one undo step each"); + app.run("edit.undo", json!({})).unwrap(); + assert_eq!(x(&app), 1.0, "Undo takes back the moves after Outline"); + assert!(app.outline_view(), "and leaves the view as it is"); + } + + /// A step that fails after a View menu step ends the playback: the steps before it stay done and + /// the batch it is in changes nothing. + #[test] + fn a_failing_step_after_a_view_item_keeps_what_played_before_it() { + let (mut app, x) = app_with_a_view_step(); + app.ui.action_sets[0].actions[0].steps.insert(3, ("object.align".into(), json!({}))); + assert!(play(&mut app, 0, 0).is_err()); + assert!(app.outline_view(), "Outline played"); + assert_eq!(x(&app), 1.0, "the move before Outline stays, and the move of 2 in the failing batch is taken back"); + } + + /// At Step by Step and Pause For a View menu step is one step of the playback and adds no undo + /// step. + #[test] + fn an_inserted_view_item_plays_step_by_step_and_with_pauses() { + for speed in ["step", "pause"] { + let (mut app, x) = app_with_a_view_step(); + app.run(PLAYBACK_OPTIONS, json!({"speed": speed})).unwrap(); + let before = undo_steps(&app); + let r = play(&mut app, 0, 0).unwrap(); + assert_eq!(r["pending"], json!(3), "{speed}: {r}"); + assert!(!app.outline_view(), "{speed}: Outline waits its turn"); + let mut now = 0.0; + for _ in 0..40 { + if app.ui.action_playing.is_none() { + break; + } + now += 2.0; + frame(&mut app, now); + } + assert!(app.ui.action_playing.is_none(), "{speed}: the playback ended"); + assert!(app.outline_view(), "{speed}"); + assert_eq!(x(&app), 7.0, "{speed}"); + assert_eq!(undo_steps(&app), before + 3, "{speed}: each move its own undo step, Outline none"); + } + } + + /// A View menu step before a stop plays before the playback waits there, and the steps after the + /// stop play on Continue. + #[test] + fn an_inserted_view_item_plays_up_to_a_stop() { + let (mut app, x) = app_with_a_view_step(); + app.run(INSERT_STOP, json!({"set": 0, "action": 0, "step": 1})).unwrap(); + let r = play(&mut app, 0, 0).unwrap(); + assert_eq!(r["atStop"], json!(true), "{r}"); + assert!(app.outline_view()); + assert_eq!(x(&app), 1.0); + app.run(CONTINUE_PLAYBACK, json!({})).unwrap(); + assert_eq!(x(&app), 7.0); + assert!(app.outline_view(), "Outline did not play again"); + } + + /// Playing an action with a View menu step while another records keeps the View step in the + /// recording, between the batches of the steps around it. + #[test] + fn a_view_step_played_while_recording_is_recorded() { + let (mut app, _) = app_with_a_view_step(); + app.run(START_RECORDING, json!({})).unwrap(); + play(&mut app, 0, 0).unwrap(); + app.run(STOP_RECORDING, json!({})).unwrap(); + let recorded = &app.ui.action_sets[0].actions.last().unwrap().steps; + let ids: Vec<&str> = recorded.iter().map(|(c, _)| c.as_str()).collect(); + assert_eq!(ids, ["command.batch", "view.outline", "command.batch"]); + assert_eq!(recorded[1].1, json!({})); + } + + /// Batch… refuses an action with an included View menu step, which acts on a document window, + /// and plays one whose View menu step is excluded. + #[test] + fn batch_refuses_an_action_with_a_view_step() { + let (mut app, _) = app_with_a_view_step(); + assert_eq!(crate::dialogs::action_batch::open(&mut app, 0, 0).unwrap_err(), "Batch cannot play an action with a View menu step"); + assert!(app.ui.dialog.is_none()); + app.ui.action_sets[0].actions[0].excluded_steps.insert(1); + crate::dialogs::action_batch::open(&mut app, 0, 0).unwrap(); + } + + /// An action set with a View menu step saves as version 6 and loads back with the step; one whose + /// View menu step has params that are not an object is not an action set file. + #[test] + fn a_saved_view_step_survives_as_version_6() { + let (app, _) = app_with_a_view_step(); + let saved = files::write_set(&app.ui.action_sets[0]); + let file: Value = serde_json::from_str(&saved).unwrap(); + assert_eq!(file["version"], json!(6), "older builds must refuse a View menu step"); + let loaded = files::read_set(&saved, "Test").unwrap(); + assert_eq!(loaded.actions[0].steps, app.ui.action_sets[0].actions[0].steps); + for params in [json!(5), json!([1]), json!(null)] { + let step = json!({"command": "view.zoomIn", "params": params}); + let bad = json!({"format": "vcactions", "version": 6, "name": "Bad", "actions": [{"name": "A", "steps": [step]}]}); + assert_eq!(files::read_set(&bad.to_string(), "Test").unwrap_err(), "not an action set file", "{params}"); + } + } + + /// At Accelerated, the steps up to a stop play as saved steps, as they do without a stop: a key + /// their command no longer reads, recorded by an older version, is taken. + #[test] + fn steps_before_a_stop_play_with_a_key_no_longer_read() { + let (mut app, _) = app_with_three_moves(); + let old = json!({"x": 10, "y": 50, "width": 20, "height": 20, "cornerStyle": "round"}); + assert!(app.run("shape.rectangle", old.clone()).is_err()); + let stop = (STOP_STEP.to_string(), json!({"message": "", "allowContinue": false})); + app.ui.action_sets[0].actions[0].steps = vec![("shape.rectangle".into(), old), stop]; + let shapes = app.session.active().unwrap().doc.layers[0].children().unwrap().len(); + let r = play(&mut app, 0, 0).unwrap(); + assert_eq!(r["atStop"], json!(true), "{r}"); + assert_eq!(app.session.active().unwrap().doc.layers[0].children().unwrap().len(), shapes + 1); + assert!(!app.session.replaying()); + } + #[test] fn insert_menu_item_refuses_what_no_menu_item_runs_and_changes_nothing() { let (mut app, _) = app_with_three_moves(); @@ -4515,11 +4708,15 @@ mod tests { (place(json!({"command": "file.save"})), none), (place(json!({"command": "object.move"})), none), (place(json!({"command": "object.move", "params": {"dx": 1, "dy": 0}})), none), - (place(json!({"command": "view.zoomIn"})), none), (place(json!({"command": INSERT_MENU_ITEM})), none), (place(json!({"command": "edit.paste"})), none), - // Align, whose menu items add the Align To choice when clicked. - (place(json!({"command": "object.align", "params": {"horizontal": "left"}})), none), + // The app's own commands outside the View menu, a saved-view slot and the View menu's New + // View…, which asks for a name first. + (place(json!({"command": "window.panel", "params": {"panel": "layers", "toggle": true}})), none), + (place(json!({"command": "view.goto1"})), none), + (place(json!({"command": "view.saved.new"})), none), + // Align To is the step's own: only the menu item's params are taken. + (place(json!({"command": "object.align", "params": {"horizontal": "left", "to": "selection"}})), none), // Image Trace, whose menu items trace off the UI thread with progress and Cancel. (place(json!({"command": "imageTrace.make", "params": {"preset": "Default"}})), none), (place(json!({"command": "imageTrace.makeAndExpand", "params": {"preset": "Default"}})), none), @@ -4547,19 +4744,74 @@ mod tests { } /// A listed menu item runs from the menu what its step runs in playback: the click opens no - /// dialog, and it journals the item's own command with the item's own params. + /// dialog, and it journals the item's own command with the params its step holds. An Object › + /// Align item's step holds the Align To choice that the click sends, and the app adds the active + /// artboard to both. #[test] fn every_listed_menu_item_runs_from_the_menu_what_its_step_holds() { for item in crate::menus::insertable_items(false) { let (mut app, _) = app_with_three_moves(); + app.run(INSERT_MENU_ITEM, json!({"set": 0, "action": 0, "command": item.command, "params": item.params})).unwrap(); + let held = app.ui.action_sets[0].actions[0].steps[3].1.clone(); let start = app.session.journal.len(); crate::menus::invoke(&mut app, item.command, item.params.clone()); assert!(app.ui.dialog.is_none(), "{item:?} opens a dialog"); let ran = app.session.journal_for_action(start); - assert!(ran.iter().all(|(c, p)| c != item.command || *p == item.params), "{item:?} ran {ran:?}"); + let without_artboard = |p: &Value| { + let mut p = p.clone(); + if let Some(o) = p.as_object_mut() { + o.remove("artboard"); + } + p + }; + assert!(ran.iter().all(|(c, p)| c != item.command || without_artboard(p) == held), "{item:?} ran {ran:?}, its step holds {held}"); } } + /// Object › Align items can be inserted, and the step keeps the Align To that the click sends at + /// insertion: a later Align To choice does not change it. + #[test] + fn an_inserted_align_item_keeps_the_align_to_of_its_insertion() { + let (mut app, _, ids) = app_with_two_rectangles(); + app.run("select.set", json!({ "ids": ids })).unwrap(); + app.ui.align_to = super::super::align::AlignTo::Artboard; + app.run(INSERT_MENU_ITEM, json!({"set": 0, "action": 0, "command": "object.align", "params": {"horizontal": "left"}})).unwrap(); + app.ui.align_to = super::super::align::AlignTo::Selection; + app.run(INSERT_MENU_ITEM, json!({"set": 0, "action": 0, "command": "object.align", "params": {"horizontal": "left"}})).unwrap(); + let steps = &app.ui.action_sets[0].actions[0].steps; + assert_eq!(steps[3], ("object.align".to_string(), json!({"horizontal": "left", "to": "artboard"}))); + assert_eq!(steps[4], ("object.align".to_string(), json!({"horizontal": "left", "to": "selection"}))); + } + + /// With anchor points selected, an Object › Align item sends its params unchanged, and the points + /// align to their own bounds: its step holds the same params, without the Align To choice. + #[test] + fn an_inserted_align_item_with_anchors_selected_keeps_the_menu_params() { + let (mut app, _, [first, _]) = app_with_two_rectangles(); + app.ui.align_to = super::super::align::AlignTo::Artboard; + app.run("select.anchors", json!({"id": first, "anchors": [[0, 0], [0, 1]]})).unwrap(); + assert!(!app.session.active().unwrap().selection.anchors.is_empty()); + app.run(INSERT_MENU_ITEM, json!({"set": 0, "action": 0, "command": "object.align", "params": {"horizontal": "left"}})).unwrap(); + assert_eq!(app.ui.action_sets[0].actions[0].steps[3], ("object.align".to_string(), json!({"horizontal": "left"}))); + } + + /// A step that aligns to the key object fails in playback when the selection has no key then: + /// it does not align to the selection or the artboard instead, and the steps after it do not run. + #[test] + fn an_align_step_to_the_key_object_fails_without_a_key() { + let (mut app, _, [first, second]) = app_with_two_rectangles(); + app.run("select.set", json!({"ids": [first, second]})).unwrap(); + app.run("select.key", json!({"id": second})).unwrap(); + app.ui.action_sets[0].actions[0].steps.clear(); + app.run(INSERT_MENU_ITEM, json!({"set": 0, "action": 0, "command": "object.align", "params": {"horizontal": "left"}})).unwrap(); + assert_eq!(app.ui.action_sets[0].actions[0].steps[0].1["to"], json!("key")); + app.ui.action_sets[0].actions[0].steps.push(("object.move".into(), json!({"dx": 5, "dy": 0}))); + app.run("select.set", json!({"ids": [first, second]})).unwrap(); + let before = (left_of(&app, first), left_of(&app, second)); + assert!(play(&mut app, 0, 0).unwrap_err().contains("no key object")); + assert_eq!((left_of(&app, first), left_of(&app, second)), before, "nothing moved"); + } + #[test] fn insert_menu_item_goes_into_the_recording() { let (mut app, _) = app_with_three_moves(); @@ -5789,7 +6041,7 @@ mod tests { json!({"format": "vcactions", "version": version, "name": "Old", "actions": [{"name": "A", "steps": [{"command": "object.move"}]}]}); assert_eq!(files::read_set(&old.to_string(), "Test").unwrap().actions[0].steps.len(), 1, "version {version}"); } - let later = json!({"format": "vcactions", "version": 6, "name": "New", "actions": []}); + let later = json!({"format": "vcactions", "version": 7, "name": "New", "actions": []}); assert_eq!(files::read_set(&later.to_string(), "Test").unwrap_err(), "the action set file needs a later version of VectorCraft"); for params in [json!({"message": 5}), json!({"allowContinue": "yes"}), json!(42)] { let stop = json!({"command": "action.stop", "params": params}); diff --git a/crates/ui-egui/src/panels/actions/files.rs b/crates/ui-egui/src/panels/actions/files.rs index 6aa8b95df4..911e6ae41b 100644 --- a/crates/ui-egui/src/panels/actions/files.rs +++ b/crates/ui-egui/src/panels/actions/files.rs @@ -1,6 +1,6 @@ //! Action set files: the Actions panel menu's Save Actions… and Load Actions…. //! -//! An action set file (`.vcactions`) is JSON: `{"format": "vcactions", "version": 1 to 5, "name", +//! An action set file (`.vcactions`) is JSON: `{"format": "vcactions", "version": 1 to 6, "name", //! "actions": [{"name", "steps": [{"command", "params", "excluded"?}], "key"?, "color"?}]}`. Each step is a //! command id and its params, as `command.batch` takes them, or a stop: the command `action.stop` //! with `{"message", "allowContinue"}`. A Select Object step is the command `select.byNote` with @@ -10,9 +10,10 @@ //! or with a value that is not one, has none. `excluded: true` keeps a step but skips it during //! playback. Sets with exclusions use version 2 so older builds refuse them rather than replay //! excluded steps, sets with stops use version 3 so older builds refuse them rather than fail at a -//! stop, sets with Select Object steps use version 4 and sets with Select Path steps use version 5 so -//! older builds refuse them rather than fail at that step. Other sets use version 1, and earlier -//! version 1 to 4 files still work. +//! stop, sets with Select Object steps use version 4, sets with Select Path steps use version 5 and +//! sets with View menu steps ([`crate::menus::plays_in_app`]), whose params are an object, use +//! version 6 so older builds refuse them rather than fail at that step. Other sets use version 1, and +//! earlier version 1 to 5 files still work. //! Load Actions… also reads the action sets another app saves as text (`.aia`, through //! `actionSet.read`). @@ -173,7 +174,9 @@ pub fn write_set(set: &ActionSet) -> String { let has_select_object = steps().any(|(command, params)| !select_objects_in(command, params).is_empty()); let has_select_path = steps().any(|(command, params)| !select_paths_in(command, params).is_empty()); let has_stop = steps().any(|(command, params)| !stops_in(command, params).is_empty()); + let has_ui_step = steps().any(|(command, _)| crate::menus::plays_in_app(command)); let version = match (has_select_path, has_select_object, has_stop, set.actions.iter().any(|a| !a.excluded_steps.is_empty())) { + _ if has_ui_step => 6, (true, ..) => 5, (false, true, ..) => 4, (false, false, true, _) => 3, @@ -193,7 +196,7 @@ pub fn read_set(text: &str, name: &str) -> Result { if f.format != ACTIONS_EXT { return Err("not an action set file".into()); } - if !matches!(f.version, 1..=5) { + if !matches!(f.version, 1..=6) { return Err("the action set file needs a later version of VectorCraft".into()); } if f.actions.len() > MAX_SET_ACTIONS { @@ -214,6 +217,10 @@ pub fn read_set(text: &str, name: &str) -> Result { if select_objects.any(|p| super::select_object_params(p).is_err()) { return Err("not an action set file".into()); } + let mut ui_steps = f.actions.iter().flat_map(|a| &a.steps).filter(|s| crate::menus::plays_in_app(&s.command)); + if ui_steps.any(|s| !s.params.is_object()) { + return Err("not an action set file".into()); + } let actions = f .actions .into_iter() diff --git a/crates/ui-egui/src/panels/align.rs b/crates/ui-egui/src/panels/align.rs index 417468f642..02c7969be2 100644 --- a/crates/ui-egui/src/panels/align.rs +++ b/crates/ui-egui/src/panels/align.rs @@ -60,6 +60,13 @@ pub fn with_align_to(app: &VectorcraftApp, base: Value) -> Value { align_params(base, align_to(app), objects_aligned(app)) } +/// The params that an Object → Align menu item with params `p` sends: [`with_align_to`] unless `p` +/// names `to` or anchor points are selected (Direct Selection), when `p` goes unchanged and the +/// points align to their own bounds. Insert Menu Item stores the same params as the item's step. +pub fn menu_align_params(app: &VectorcraftApp, p: Value) -> Value { + if p.as_object().is_some_and(|o| !o.contains_key("to")) && !has_anchors(app) { with_align_to(app, p) } else { p } +} + /// The selected objects that Align aligns as objects: none while anchor points are selected /// (Direct Selection), since the points align and a single path's points must not go to the /// artboard as a single object does (#1636). diff --git a/docs/mcp.md b/docs/mcp.md index 274db05a34..9aad4adf71 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -3016,15 +3016,18 @@ already walks Image Trace. Short agent entry points: the file at `path`, else a picked one, or the file's text `data`, adds its set after the other sets and returns `{set, name, actions}`. A set named like one already in the panel gets the next free number (`Print 2`), and the other sets and the current set stay as they are. An action set file (`.vcactions`) is JSON: - `{"format": "vcactions", "version": 1 to 5, "name", "actions": [{"name", "steps": [{"command", "params", "excluded"?}]}]}`, each step + `{"format": "vcactions", "version": 1 to 6, "name", "actions": [{"name", "steps": [{"command", "params", "excluded"?}]}]}`, each step a command id and its params as `command.batch` takes them, or a stop: the command `action.stop` with `{message, allowContinue}`. A Select Object step is the command `select.byNote` with `{note, caseSensitive, - wholeWord}`, and a Select Path step is the command `select.storedPath` with `{id, fingerprint}`. `excluded: true` preserves a step but omits it from playback; - an absent or false flag includes the step. Files with Select Path steps use version 5, files with Select Object steps - and no Select Path step use version 4, files with stops and neither use version 3, and files with excluded steps and - none of these use version 2, so older builds refuse them instead of playing the excluded steps or failing at a stop, a - Select Object step or a Select Path step; other files use version 1, and version 1 to 4 files still load. A file with another `format` or a `version` other than - 1 to 5, a stop whose message is not text or whose `allowContinue` is not true or false, a Select Object step whose params `ui.action.insertSelectObject` would refuse, a file larger than 8 MiB, one with more than 1,000 actions and one with an action of more than 10,000 steps are + wholeWord}`, and a Select Path step is the command `select.storedPath` with `{id, fingerprint}`. A View menu step is + the id of a View menu command that the app runs itself (`view.outline`, `view.zoomIn`, `view.rotate` and the others + `ui.action.insertMenuItem` lists) with the item's params. `excluded: true` preserves a step but omits it from playback; + an absent or false flag includes the step. Files with View menu steps use version 6, files with Select Path steps and + no View menu step use version 5, files with Select Object steps and neither use version 4, files with stops and none + of these use version 3, and files with excluded steps and none of these use version 2, so older builds refuse them + instead of playing the excluded steps or failing at a stop, a Select Object step, a Select Path step or a View menu + step; other files use version 1, and version 1 to 5 files still load. A file with another `format` or a `version` other than + 1 to 6, a stop whose message is not text or whose `allowContinue` is not true or false, a Select Object step whose params `ui.action.insertSelectObject` would refuse, a View menu step whose params are not an object, a file larger than 8 MiB, one with more than 1,000 actions and one with an action of more than 10,000 steps are refused, and no set is added. So is a file whose set `ui.actionSet.save` would write larger than 8 MiB (a file with less white space, a set name that gets a number, or an `.aia` set), with the error `the action set would be larger than 8 MiB`. The Actions panel menu's Save Actions… and Load Actions… run these; Load Actions… is @@ -3089,7 +3092,12 @@ already walks Image Trace. Short agent entry points: here and in Batch…. An action with an included stop plays up to the stop at any speed and then waits, with its message box open, until `ui.action.continue` or `ui.action.stop`. At Accelerated the steps between two stops are one undoable batch each. The result is then `{results, pending, atStop?}`, with `atStop: true` when the action already - waits. Batch… refuses an action with an included stop, and a stop that is excluded does not hold playback. + waits. Batch… refuses an action with an included stop, and a stop that is excluded does not hold playback. A View + menu step (`ui.action.insertMenuItem`) plays at every speed in its place among the steps, as its menu item runs, and + adds no undo step. At Accelerated the steps before it and the steps after it are one undoable batch each, and the + result is `{results}` with every step's result in order. A step that fails ends the playback with its error: the + batch it is in changes nothing, and the steps before that batch stay done. While another action records, the View + menu step is recorded too. Batch… refuses an action with an included View menu step. - Actions: `ui.action.insertStop {set?, action?, step?, message?, allowContinue?}` inserts a stop. With `set` and `action`, the stop goes into that action, after step `step`, else after its last step, and the command returns `{set, action, step}`. Without them it goes into the recording in progress, after the steps recorded so far, and @@ -3103,11 +3111,17 @@ already walks Image Trace. Short agent entry points: (`message`, `allowContinue`, `set`, `action`, `step`), whose OK runs this. - Actions: `ui.action.insertMenuItem {set?, action?, step?, command, params?}` inserts a menu item's command as a step without running it. `command` and `params` (default: `{}`) must be those of an item in the menus that can be a step: - an item that runs a document command without opening a dialog first, outside the File, Window and Help menus, and - not Undo, Redo, a Paste command, Object › Align (its items add the Align To choice when clicked), Object › Image + an item that runs a document command, or a View menu item that the app runs itself (Outline, Pixel Preview, Trim + View, Presentation Mode, Screen Mode, the zoom, fit and Rotate View items, and the show, hide and snap items), without + opening a dialog first, outside the File, Window and Help menus, and not Undo, Redo, a Paste command, Object › Image Trace › Make or Make and Expand (the menu traces off the UI thread, with progress and Cancel), Object › Pattern › Make or Edit Pattern (the menu also opens the Pattern Options panel), a preference - toggle, an Actions command or a recent-font, saved-selection or saved-view slot. Disabled items are listed, and playback checks the step when it runs. With `set` and `action`, the + toggle, an Actions command, a Perspective Grid preset of the preferences or a recent-font, saved-selection or saved-view slot. Disabled items are listed, and playback checks the step when it runs. An Object › Align item's step + keeps the `to` its click sends at insertion (`key` while the selection has a key object or key guide, `artboard` for one selected + object or with Align to Artboard, else `selection`), so a later Align To choice does not change it, and a step that + aligns to the key object fails in playback when the selection has no key then. With anchor points selected the click + sends no `to`, and neither does the step. These are VectorCraft's own rules. A + View menu step plays as `ui.action.play` describes. With `set` and `action`, the step goes into that action, after step `step`, else after its last step, becomes the panel's selected step, and the command returns `{set, action, step}`. Without them it goes into the recording in progress and returns `{recording: true}`. A command no such item runs, params that are not an object, an index past the last set, action diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index f04ee3c910..65ba4db3a2 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -747,7 +747,8 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - Actions panel: an action keeps to the limits that Load Actions… reads while it records and while its steps are excluded: at most 10,000 steps in an action and 8 MiB in its set's file, which are VectorCraft's own rules. Commands add steps to a recording until it stops ([the help page](https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/automate-actions/record-actions.html)); a command whose step would pass a limit does not run, its document stays as it was, and the recording goes on. A command whose step passes a limit only as it runs, from values it adds to its step, keeps its edit; the status bar names the limit, later recorded commands do not run, and Stop Playing/Recording leaves its step out. A stop that playback reaches is not recorded then, and the status bar shows the reason. Clearing a checkmark keeps the step in the action and skips it in playback ([the help page](https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/automate-actions/exclude-commands-from-actions.html)); an exclusion that would make the set's file larger than 8 MiB changes no checkmark, and one that makes the file smaller always works. Stop Playing/Recording leaves out any recorded steps still past a limit and names the limit in the status bar. Begin Recording, Duplicate, New Action, renaming an action, Action Options…, Set Options…, New Set… and Load Actions… (`.aia` sets included) also refuse a change that would give a set more than 1,000 actions or a file larger than 8 MiB, and change nothing then. Tests `panels::actions::tests::{recorded_commands_keep_an_action_at_10_000_steps, recorded_commands_keep_an_action_set_file_within_8_mib, a_recorded_command_whose_noted_values_do_not_fit_is_left_out, a_stop_reached_while_recording_a_full_action_is_left_out, stop_leaves_out_recorded_steps_past_the_limits, excluding_steps_keeps_an_action_set_file_within_8_mib, a_recorded_batch_that_edits_another_document_is_left_out_when_it_grows, a_set_renamed_while_it_records_is_measured_again, steps_recorded_after_an_exclusion_past_the_last_step_are_included, duplicate_keeps_action_set_files_within_their_limits, new_action_keeps_an_action_set_file_within_its_limits, renaming_keeps_an_action_set_file_within_8_mib, load_actions_refuses_a_set_that_would_save_larger_than_8_mib}`. - Actions panel: the panel menu's Playback Options… sets how actions play: Accelerated (the default) plays every step at once, Step by Step plays one step at a time with the canvas drawn after each, and Pause For waits the given number of seconds between steps ([Specify playback speed](https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/automate-actions/specify-playback-speed.html); `ui.action.playbackOptions`). VectorCraft's own rules, which the page does not cover: the pause is a whole number of seconds from 1 to 60, the setting is kept with the UI preferences, a paced playback ends at Stop Playing/Recording or when a step comes due while another document is active, each step of a paced playback is its own undo step, and Batch… plays at full speed. - Actions panel: the panel menu's Insert Stop… opens Record Stop, with a Message box and Allow Continue, and adds a stop to the recording in progress, after the selected command, or at the end of the selected action ([Insert stops in actions](https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/automate-actions/insert-stops-in-actions.html); `ui.action.insertStop`). A playing action waits at the stop and shows the message so the user can do a manual task, and Play Current Selection plays the rest ([Illustrator CS5 help](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=459); `ui.action.continue`). With Allow Continue, the message box also has Continue. VectorCraft's own rules, which the pages do not cover: an empty message still waits, Stop Playing/Recording ends the playback and keeps the steps already played, the rest plays on the document active then, a stop waits at every playback speed, at Accelerated the steps between two stops are one undo step, Batch… refuses an action with an included stop, and Delete Selection on a selected step deletes that step, a stop or a command, without asking (`ui.action.deleteStep`). - - Actions panel: the panel menu's Insert Menu Item… adds a menu command to the recording in progress, after the selected step, or at the end of the selected action, without running it, and playback runs it as the menu does ([Insert non-recordable tasks into actions](https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/automate-actions/insert-non-recordable-tasks-into-actions.html); `ui.action.insertMenuItem`). The dialog's Find box picks the one item that matches the words typed, and a click on a listed item picks it. VectorCraft's own rules, which the page does not cover: items that open a dialog, the Object › Align items, Image Trace's Make and Make and Expand, Pattern's Make and Edit Pattern, and the File, Window and Help menu items are not listed, and an action holds at most 10,000 steps and its set file at most 8 MiB, for stops too. + - Actions panel: the panel menu's Insert Menu Item… adds a menu command to the recording in progress, after the selected step, or at the end of the selected action, without running it, and playback runs it as the menu does ([Insert non-recordable tasks into actions](https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/automate-actions/insert-non-recordable-tasks-into-actions.html); `ui.action.insertMenuItem`). The dialog's Find box picks the one item that matches the words typed, and a click on a listed item picks it. VectorCraft's own rules, which the page does not cover: items that open a dialog, Image Trace's Make and Make and Expand, Pattern's Make and Edit Pattern, and the File, Window and Help menu items are not listed, and an action holds at most 10,000 steps and its set file at most 8 MiB, for stops too. + - Actions panel: Insert Menu Item… also lists the Object › Align items and the View menu commands that act on the window rather than the document (Outline, Pixel Preview, Trim View, Presentation Mode, Screen Mode, zoom, fit, Rotate View, and the show, hide and snap items), which the help page names among the commands that cannot be recorded ([Insert non-recordable tasks into actions](https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/automate-actions/insert-non-recordable-tasks-into-actions.html); [Align and distribute objects](https://helpx.adobe.com/illustrator/desktop/manage-objects/arrange-objects/align-and-distribute-objects.html); `ui.action.insertMenuItem`, `ui.action.play`). VectorCraft's own rules, which the pages do not cover: an Align step keeps the Align To choice of its insertion, and one that aligns to the key object stops the playback when there is no key; a View menu step plays in its place at every speed and adds no undo step, so at Accelerated the steps on each side of it are one undo step each; Batch… refuses an action with one; and a set file with one is version 6. Tests `panels::actions::tests::{an_inserted_view_item_plays_in_its_place_at_accelerated, an_inserted_view_item_plays_step_by_step_and_with_pauses, an_inserted_view_item_plays_up_to_a_stop, a_view_step_played_while_recording_is_recorded, a_saved_view_step_survives_as_version_6, an_inserted_align_item_keeps_the_align_to_of_its_insertion, an_align_step_to_the_key_object_fails_without_a_key}`. - Actions panel: with a path selected, the panel menu's Insert Select Path adds a step that selects that path to the recording in progress, after the selected step, or at the end of the selected action, without changing the selection ([Insert non-recordable tasks into actions](https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/automate-actions/insert-non-recordable-tasks-into-actions.html); `ui.action.insertSelectPath`, `select.storedPath`). VectorCraft's own rules, which the page does not cover: the selection must be one whole path or compound path that can be selected, the step stores the path's id and a fingerprint of its anchors, and playback selects the path only while it is still there unchanged and can be selected, else the step is an error and the selection stays; the row reads Select Path, and a set file with the step is version 5. - Actions panel: the panel menu's Select Object… opens Set Selection, where the note typed names the objects to select, and adds a step to the recording in progress, after the selected step, or at the end of the selected action; playback selects the objects whose Attributes note matches it, and the steps after it act on them ([Insert non-recordable tasks into actions](https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/automate-actions/insert-non-recordable-tasks-into-actions.html); `ui.action.insertSelectObject`, `select.byNote`). VectorCraft's own rules, which the page does not cover: the note matches anywhere and in any letter case unless Case Sensitive or Whole Word is checked, hidden and locked objects are left out, the objects found replace the selection, a step that finds none stops the playback with an error, and the note is at most 1,024 bytes. Action sets with the step save as version 4. - Actions panel: Delete Selection deletes the selected action set with its actions and keeps the other sets ([Actions panel overview](https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/automate-actions/actions-panel-overview.html); `ui.actionSet.delete`). VectorCraft's own rules, which the overview does not cover: deleting a set asks first, Shift-click on a set's name selects a range of sets to delete together, the panel menu's Delete does the same, and Default Actions and the last set can be deleted. Undo does not bring a deleted set back.