feat(app): Save As Command in History, saved commands in the Commands menu, Manage Saved Commands (M6)

This commit is contained in:
Tanish Manku committed 2026-11-14 04:13:01 -07:00
1 parent f167ebe3da
commit 98bb6e98e5
11 files changed
+800 -21

No files matched your search

+1
View File
@@ -57,6 +57,7 @@ pub const PAGES: &[Page] = &[
page!("opening-animate-files.md"),
page!("preferences-shortcuts-accessibility.md"),
page!("plugins.md"),
page!("saved-commands.md"),
page!("working-headless.md"),
page!("troubleshooting-and-faq.md"),
page!("coming-from-animate.md"),
+17 -1
View File
@@ -1,6 +1,6 @@
# Command reference
Everything you can do in AniCraft is a command: the menus, the shortcuts, the command palette (**Ctrl+K**, macOS **⌘K**), `anicraft-cli` and AI assistants over MCP all run the same 352 commands, listed here by menu. The id is what scripts and [working headless](../working-headless.md) use; the parameters are what a command takes as JSON. Commands that change the document are one undo step each. Your own shortcuts (**F1**) replace the defaults shown here; see the [shortcut reference](shortcuts.md).
Everything you can do in AniCraft is a command: the menus, the shortcuts, the command palette (**Ctrl+K**, macOS **⌘K**), `anicraft-cli` and AI assistants over MCP all run the same 360 commands, listed here by menu. The id is what scripts and [working headless](../working-headless.md) use; the parameters are what a command takes as JSON. Commands that change the document are one undo step each. Your own shortcuts (**F1**) replace the defaults shown here; see the [shortcut reference](shortcuts.md).
This page is generated from the command registry, so it always matches the version of AniCraft it came with.
@@ -249,6 +249,10 @@ This page is generated from the command registry, so it always matches the versi
Parameters: `{} lists the installed plug-ins (the app shows them in a window)`
- **Reload Plug-ins** `plugin.reload`
Parameters: `{folder? (makes it the plug-ins folder first)} re-reads every .wasm in the plug-ins folder`
- **Run Command…** `macro.run` · changes the document
Parameters: `{name + folder (a saved command) | path (a saved command's file, or a JSON array of {cmd, params}) | steps: [{cmd, params?, label?}], name? (for steps)} → {name, steps, results}: runs the steps in order as one undo step named after it. At the first step that fails nothing is changed and the error names the step. Steps may call what a plug-in may, never macro.*`
- **Manage Saved Commands…** `macro.list`
Parameters: `{folder} → {commands: [{name, path, steps}], problems: [{file, error}]}: the saved commands in the folder, in their order (the app shows them in a window)`
## Control
@@ -733,3 +737,15 @@ These commands have no menu item: the panels, the stage and the timeline use the
Parameters: ``{text: the script, language?: actionscript3|actionscript1or2|other (default actionscript3)} whether it would run (the ActionScript 3.0 subset, ADR 0013), its problems with line and column, what is ignored, the names it takes from other frames of its timeline (`uses`), and what it compiles to (`steps`, `program`); changes nothing``
- **Set Script Class** `script.set_class` · changes the document
Parameters: `{symbol?: id (default: the document), class: dotted class name ("" clears), base?: the class it extends} sets a symbol's linkage class, or the document class; kept as text, not run`
- **List History Steps** `macro.history`
Parameters: ``{} → {steps: [{index, label, undone, keep, commands?, why?, rewritten?}]}: every undo-history step as Save As Command keeps it: `keep` false says `why` it can't be kept; `rewritten` names params dropped so the step acts on the selection or active layer``
- **Save As Command…** `macro.save`
Parameters: `{folder, name, history: [index, ..] (as macro.history lists them) | steps: [{cmd, params?, label?}], confirm? (to replace a saved command of that name)} → {name, path, steps, rewritten}: keeps the steps as <folder>/<name>.json, last in the list`
- **Rename Saved Command** `macro.rename`
Parameters: `{folder, name, to} → {name, from, path}: renames a saved command (its file); its place in the list stays`
- **Delete Saved Command** `macro.delete`
Parameters: `{folder, name, confirm}: deletes a saved command's file (cannot be undone)`
- **Move Saved Command** `macro.move`
Parameters: `{folder, name, index (its new place in the list, 0-based)}`
- **Add Saved Command from File** `macro.import`
Parameters: `{folder, path (a saved command's file), name? (default: the file's), confirm? (to replace one of that name)} → {name, path, steps}: checks it and copies it in, last in the list`
+68 -4
View File
@@ -579,6 +579,8 @@ pub struct App {
pub thumbs: crate::recent::Thumbs,
/// Templates: their pictures, the user's list and the Save as Template dialog (ADR 0065).
pub templates: crate::templates::Templates,
/// Saved commands (ADR 0097): the folder's list, the History panel's picks, their windows.
pub macros: crate::macros_ui::Macros,
}
/// How often (seconds) the system's contrast and light or dark setting are asked again (ADR 0064).
@@ -797,6 +799,7 @@ impl App {
drop: Default::default(),
thumbs: Default::default(),
templates: Default::default(),
macros: Default::default(),
};
app.apply_prefs(ctx);
app.decode_sounds();
@@ -805,6 +808,7 @@ impl App {
app.status_err(e);
}
crate::plugins_ui::load_at_start(&mut app);
crate::macros_ui::rescan(&mut app);
#[cfg(not(target_arch = "wasm32"))]
crate::desktop_ui::at_start(&mut app);
app
@@ -901,8 +905,7 @@ impl App {
ctx.set_zoom_factor(self.prefs.ui_scale);
theme::apply_palette(ctx, self.prefs.palette(self.system_look));
crate::onion::refresh_colors(self);
self.keymap = keymap::Keymap::new(&self.prefs.shortcuts);
self.shortcuts = self.keymap.table();
self.refresh_keymap();
let wants_system = [&self.prefs.ui_font, &self.prefs.data_font].iter().any(|f| matches!(f, prefs::FontChoice::System(_)));
if wants_system && self.system_fonts.is_none() {
self.scan_system_fonts();
@@ -963,6 +966,12 @@ impl App {
/// Changes preferences: applies them live and saves them.
/// Writes the preferences as they are (a setting changed in place, such as the volume).
/// The shortcut map again, from the preferences and the saved commands listed (ADR 0097).
pub fn refresh_keymap(&mut self) {
self.keymap = keymap::Keymap::new(&self.prefs.shortcuts);
self.shortcuts = self.keymap.table();
}
pub fn save_prefs(&mut self) {
if self.shot.is_none()
&& let Err(e) = self.prefs.save()
@@ -1139,6 +1148,37 @@ impl App {
}
Some("palette") => self.palette = Some(dialogs::Palette { query: "key".into(), selected: 0 }),
Some("shortcuts") => self.show_shortcuts = true,
Some("savecommand") | Some("managecommands") => {
// Saved commands (ADR 0097): three edits on the sample's selection, picked in the
// History panel with Save As Command open; or a few saved commands, managed.
self.tool = Tool::Select;
self.run("edit.select_all", json!({}));
self.run("modify.rotate_cw", json!({}));
self.run("element.set_color_effect", json!({"style": "alpha", "alpha": 60}));
self.run("element.translate", json!({"dx": 24, "dy": -12}));
if !self.panel_visible(crate::dock::Panel::History) {
self.toggle_panel(crate::dock::Panel::History);
}
let n = self.s.history_len();
for i in n.saturating_sub(3)..n {
crate::macros_ui::pick(self, i, true, false);
}
if which == Some("savecommand") {
crate::macros_ui::open_save(self);
if let Some(d) = self.macros.save.as_mut() {
d.name = "Turn, Fade and Nudge".into(); // i18n-exempt: a sample name a user would type
}
} else if let Some(folder) = crate::macros_ui::folder(self) {
let f = folder.display().to_string();
for (name, steps) in [("Turn, Fade and Nudge", json!([n - 3, n - 2, n - 1])), ("Quarter Turn", json!([n - 3])), ("Fade to 60 %", json!([n - 2]))] {
let _ = self.s.execute("macro.save", &json!({"folder": f, "name": name, "history": steps, "confirm": true}));
}
crate::macros_ui::clear_picks(self);
let id = crate::keymap::macro_id("Quarter Turn");
self.prefs.shortcuts.insert(id, vec!["Ctrl+Alt+R".into()]);
crate::macros_ui::open_manage(self);
}
}
Some("lastscene") => {
let last = self.s.doc.scenes.len().saturating_sub(1);
self.run("scene.select", json!({"scene": last}));
@@ -2638,7 +2678,14 @@ impl App {
/// The single entry point for user-initiated commands: asks first when the engine says the
/// command needs confirmation (ADR 0004), otherwise runs it.
pub fn request(&mut self, id: &str, params: Value) {
pub fn request(&mut self, id: &str, mut params: Value) {
// A saved command from a file goes into the user's commands folder (ADR 0097).
if id == "macro.import"
&& params.get("folder").is_none()
&& let (Some(o), Some(f)) = (params.as_object_mut(), crate::macros_ui::folder(self))
{
o.insert("folder".into(), json!(f.display().to_string()));
}
if let Some(c) = self.s.confirmation(id, &params)
&& (c.irreversible || !self.skip_confirm.contains(id))
{
@@ -2843,6 +2890,7 @@ impl App {
});
}
"plugin.run" | "plugin.install" | "plugin.remove" | "plugin.reload" => crate::plugins_ui::status(self, id, v),
id if id.starts_with("macro.") => crate::macros_ui::done(self, id, v),
"timeline.remove_frame" => {
let n = v["removed"].as_u64().unwrap_or(1);
self.status_ok(if n == 1 { tr!("Removed frame — {undo} to undo", undo = self.undo_key()).to_string() } else { trn!("Removed {n} frame — {undo} to undo", "Removed {n} frames — {undo} to undo", n, undo = self.undo_key()) });
@@ -2931,6 +2979,16 @@ impl App {
self.show_plugins = true;
return;
}
if id == "macro.list" {
// Commands › Manage Saved Commands (ADR 0097; headless, the command lists them).
crate::macros_ui::open_manage(self);
return;
}
if id == "macro.save" {
// Save As Command, for the steps picked in the History panel.
crate::macros_ui::open_save(self);
return;
}
if id == "layer.set_properties" {
// Modify › Timeline › Layer Properties: the dialog for the active layer.
crate::layer_props::open(self, None);
@@ -2989,6 +3047,9 @@ impl App {
"file.import_to_library" => Some((tr_noop!("Import to library (WAV, OGG or MP3 sound; PNG or JPEG image)"), "path", "sound.wav".to_string())),
"file.import" => Some((tr_noop!("Import to stage (SVG, PNG or JPEG; WAV, OGG or MP3 onto a new layer)"), "path", "drawing.svg".to_string())),
"plugin.install" => Some((tr_noop!("Install plug-in (.wasm file)"), "path", "plugin.wasm".to_string())),
// Saved commands (ADR 0097): run a file, or copy one into your commands.
"macro.run" => Some((tr_noop!("Run a saved command (a .json file)"), "path", "command.json".to_string())),
"macro.import" => Some((tr_noop!("Add a saved command (a .json file)"), "path", "command.json".to_string())),
// A brush set (ADR 0068): your brushes as a small JSON file.
"brush.preset_export" => Some((tr_noop!("Export your brushes (a brush set file)"), "path", "brushes.json".to_string())),
"brush.preset_import" => Some((tr_noop!("Import brushes (a brush set file)"), "path", "brushes.json".to_string())),
@@ -3001,7 +3062,7 @@ impl App {
_ => None,
};
if let Some((title, key, text)) = prompt {
let is_file = matches!(key, "path" | "dir") && (id.starts_with("file.") || matches!(id, "plugin.install" | "brush.preset_export" | "brush.preset_import" | "filter.preset_export" | "filter.preset_import" | "swatch.export" | "swatch.import"));
let is_file = matches!(key, "path" | "dir") && (id.starts_with("file.") || matches!(id, "plugin.install" | "macro.run" | "macro.import" | "brush.preset_export" | "brush.preset_import" | "filter.preset_export" | "filter.preset_import" | "swatch.export" | "swatch.import"));
if is_file && platform::WEB && platform::reads_file(id) {
// The browser's file picker (ADR 0036). The file arrives on a later frame
// (`open_picked`); a save or export asks for the download's name below.
@@ -3330,6 +3391,8 @@ impl App {
"view.brush_smaller" => crate::brushtool::resize(self, false),
"view.brush_larger" => crate::brushtool::resize(self, true),
id if id.starts_with("tool.") => tool = keymap::tool_for(id).or(tool),
// A saved command's own key (ADR 0097).
id if keymap::macro_name(id).is_some() => crate::macros_ui::run_saved(self, keymap::macro_name(id).unwrap_or("")),
_ => self.invoke(id),
}
}
@@ -3768,6 +3831,7 @@ impl App {
crate::plugin_export_ui::show(self, &ctx);
crate::dock_float::floating(self, &ctx);
crate::workspaces_window::show(self, &ctx);
crate::macros_ui::show(self, &ctx);
crate::find_panel::show(self, &ctx);
crate::brush_panel::show(self, &ctx);
crate::publish_panel::show(self, &ctx);
+14
View File
@@ -834,6 +834,20 @@ fn take_key_press(ctx: &egui::Context) -> Option<(egui::Modifiers, Key)> {
})
}
/// Opens the shortcut editor filtered to `filter` and waiting for a new key for `id` (Manage
/// Saved Commands' Shortcut…, ADR 0097).
pub(crate) fn shortcuts_for(app: &mut App, ctx: &egui::Context, filter: &str, id: &'static str) {
let state_id = egui::Id::new("shortcut_editor");
let mut st: SheetState = ctx.data_mut(|d| d.get_temp(state_id).unwrap_or_default());
st.filter = filter.to_string();
st.notice = None;
st.steal = None;
ctx.data_mut(|d| d.insert_temp(state_id, st));
app.show_shortcuts = true;
let replace = (!app.keymap.keys(id).is_empty()).then_some(0);
app.key_capture = Some(KeyCapture { id, replace });
}
fn shortcut_sheet(app: &mut App, ctx: &egui::Context) {
if !app.show_shortcuts {
app.key_capture = None;
+64 -6
View File
@@ -10,7 +10,8 @@
use crate::app::{Tool, VIEW_SHORTCUTS};
use anicraft_engine::{SHORTCUT_ALIASES, commands};
use egui::{Key, Modifiers};
use std::collections::BTreeMap;
use std::cell::RefCell;
use std::collections::{BTreeMap, BTreeSet};
/// Keys handled before the shortcut map, which the editor will not assign, and what for
/// (English: translated where it is shown).
@@ -94,8 +95,56 @@ fn view_label(id: &str) -> &'static str {
}
}
/// The start of a saved command's action id (ADR 0097): `macro:<its name>`.
pub const MACRO_PREFIX: &str = "macro:";
/// Most distinct saved command names the map ever binds in one run (see [`intern`]).
const MAX_INTERNED: usize = 4096;
thread_local! {
/// The saved commands that can carry a shortcut, as `(action id, name)`, in their order.
static MACROS: RefCell<Vec<(&'static str, &'static str)>> = const { RefCell::new(Vec::new()) };
static INTERNED: RefCell<BTreeSet<&'static str>> = const { RefCell::new(BTreeSet::new()) };
}
/// `s` for the life of the program, each distinct string kept once. An action's id and label
/// are `&'static str` everywhere the map is used; saved commands are the only actions named at
/// run time, and a run meets a handful of their names, so keeping each one is the simple
/// choice. Past [`MAX_INTERNED`] names a new one can't carry a shortcut until the next start.
fn intern(s: &str) -> Option<&'static str> {
INTERNED.with(|set| {
let mut set = set.borrow_mut();
if let Some(kept) = set.get(s) {
return Some(*kept);
}
if set.len() >= MAX_INTERNED {
return None;
}
let kept: &'static str = Box::leak(s.to_string().into_boxed_str());
set.insert(kept);
Some(kept)
})
}
/// A saved command's action id.
pub fn macro_id(name: &str) -> String {
format!("{MACRO_PREFIX}{name}")
}
/// The saved command an action id names.
pub fn macro_name(id: &str) -> Option<&str> {
id.strip_prefix(MACRO_PREFIX)
}
/// The saved commands, in their order, as actions that can carry a shortcut (Manage Saved
/// Commands sets them whenever the list changes; rebuild the [`Keymap`] after).
pub fn set_macros<'a>(names: impl IntoIterator<Item = &'a str>) {
let list: Vec<(&'static str, &'static str)> = names.into_iter().filter_map(|n| Some((intern(&macro_id(n))?, intern(n)?))).collect();
MACROS.with(|m| *m.borrow_mut() = list);
}
/// Every action that can carry a shortcut: the menu commands, any command with a default key,
/// the tools and the view keys.
/// the tools, the view keys and the saved commands.
pub fn actions() -> Vec<Action> {
let mut v: Vec<Action> = commands()
.into_iter()
@@ -120,6 +169,7 @@ pub fn actions() -> Vec<Action> {
group: tr_noop!("View"),
defaults: VIEW_SHORTCUTS.iter().filter(|(_, i)| *i == id).map(|(k, _)| *k).collect(),
}));
MACROS.with(|m| v.extend(m.borrow().iter().map(|&(id, label)| Action { id, label, group: tr_noop!("Commands"), defaults: Vec::new() })));
v
}
@@ -192,11 +242,17 @@ pub struct Keymap {
impl Keymap {
pub fn new(overrides: &BTreeMap<String, Vec<String>>) -> Keymap {
let actions = actions();
// A chord bound twice (a saved command's key in a hand-edited preferences file) stays
// with the action listed first.
let mut taken: BTreeSet<String> = BTreeSet::new();
let keys = actions
.iter()
.map(|a| match overrides.get(a.id) {
Some(user) => user.iter().filter_map(|k| normalize(k)).collect(),
None => a.defaults.iter().filter_map(|k| normalize(k)).collect(),
.map(|a| {
let ks: Vec<String> = match overrides.get(a.id) {
Some(user) => user.iter().filter_map(|k| normalize(k)).collect(),
None => a.defaults.iter().filter_map(|k| normalize(k)).collect(),
};
ks.into_iter().filter(|k| taken.insert(k.clone())).collect()
})
.collect();
Keymap { actions, keys }
@@ -326,7 +382,9 @@ pub fn sanitize(overrides: BTreeMap<String, Vec<String>>) -> BTreeMap<String, Ve
let known = actions();
let mut out: BTreeMap<String, Vec<String>> = BTreeMap::new();
for (id, keys) in overrides.into_iter().take(1_000) {
if !known.iter().any(|a| a.id == id) {
// A saved command's keys are kept while it isn't listed yet (they bind once it is).
let saved = macro_name(&id).is_some_and(|n| !n.is_empty() && n.chars().count() <= 64);
if !saved && !known.iter().any(|a| a.id == id) {
continue;
}
let mut clean: Vec<String> = Vec::new();
+444
View File
@@ -0,0 +1,444 @@
//! Saved commands in the desktop app (ADR 0097): Save As Command from the steps picked in the
//! History panel, the saved commands at the end of the Commands menu with their shortcuts, Run
//! Command… for a file, and Commands › Manage Saved Commands (run, rename, reorder, shortcut,
//! delete, add from a file). The `macro.*` commands do the work; the files live in the settings
//! folder (`platform::commands_dir`).
use crate::a11y::{self, Named};
use crate::app::App;
use crate::keymap;
use crate::theme::{T, Type, text};
use anicraft_engine::cmds_macro::{self, Saved};
use serde_json::{Value, json};
use std::collections::BTreeSet;
use std::path::PathBuf;
/// What the window keeps for saved commands between frames (view state, not saved).
#[derive(Default)]
pub struct Macros {
/// The saved commands, as last read from the folder, in their order.
pub list: Vec<Saved>,
/// Files in the folder that aren't saved commands, with why.
pub problems: Vec<(String, String)>,
/// History steps picked for Save As Command (as `macro.history` numbers them).
pub picked: BTreeSet<usize>,
/// The step picked last (the anchor of a Shift+click range).
anchor: Option<usize>,
/// The history the picks belong to: (steps freed, steps listed).
picked_for: (usize, usize),
/// The Save As Command dialog, while it is open.
pub save: Option<SaveDialog>,
/// Commands › Manage Saved Commands.
pub manage: Manage,
}
/// A picked step as Save As Command keeps it.
#[derive(Clone, Debug)]
pub struct StepView {
pub index: usize,
pub label: String,
/// Why it can't be kept (`None`: it can).
pub refused: Option<String>,
/// What was rewritten so it replays elsewhere ("acts on the selection").
pub note: Option<String>,
}
/// The Save As Command dialog.
pub struct SaveDialog {
pub name: String,
pub steps: Vec<StepView>,
focus: bool,
}
/// The Manage Saved Commands window.
#[derive(Default)]
pub struct Manage {
pub open: bool,
/// The command being renamed and the name typed so far.
renaming: Option<(String, String)>,
focus: bool,
}
/// The folder the saved commands are in. Screenshot runs never touch the real one: they use a
/// temporary folder (unless `ANICRAFT_COMMANDS_DIR` names one). None in a browser.
pub fn folder(app: &App) -> Option<PathBuf> {
if app.shot.is_some() && std::env::var_os("ANICRAFT_COMMANDS_DIR").is_none() && !crate::platform::WEB {
return Some(std::env::temp_dir().join(format!("anicraft-commands-shot-{}", std::process::id())));
}
crate::platform::commands_dir()
}
fn folder_str(app: &App) -> Option<String> {
folder(app).map(|f| f.display().to_string())
}
/// Reads the folder again, and lets the shortcut map bind what is in it.
pub fn rescan(app: &mut App) {
let (list, problems) = folder(app).map(|f| cmds_macro::saved_commands(&f)).unwrap_or_default();
app.macros.list = list;
app.macros.problems = problems;
keymap::set_macros(app.macros.list.iter().map(|c| c.name.as_str()));
app.refresh_keymap();
}
/// Runs the saved command called `name` (from the menu, a shortcut or the Manage window).
pub fn run_saved(app: &mut App, name: &str) {
let Some(folder) = folder_str(app) else { return };
app.playing = false;
app.request("macro.run", json!({"folder": folder, "name": name}));
}
/// Whether the steps picked so far still belong to this history; if not, they are let go.
fn sync_picks(app: &mut App) {
let h = app.s.history();
let now = (h.evicted, h.undo_len() + h.redo_len());
let was = app.macros.picked_for;
// New steps keep the numbers of the old ones; a freed step or a dropped redo moves them.
if now.0 != was.0 || now.1 < was.1 {
app.macros.picked.clear();
app.macros.anchor = None;
}
app.macros.picked_for = now;
}
/// Picks history step `i` for Save As Command: Ctrl toggles it, Shift picks the range from the
/// step picked last.
pub fn pick(app: &mut App, i: usize, toggle: bool, range: bool) {
sync_picks(app);
let m = &mut app.macros;
match (range, m.anchor) {
(true, Some(a)) => {
m.picked.extend(a.min(i)..=a.max(i));
}
_ if toggle && m.picked.contains(&i) => {
m.picked.remove(&i);
}
_ => {
m.picked.insert(i);
}
}
m.anchor = Some(i);
}
/// The picked steps, in order (after letting go of picks the history no longer has).
pub fn picked(app: &mut App) -> Vec<usize> {
sync_picks(app);
app.macros.picked.iter().copied().collect()
}
pub fn clear_picks(app: &mut App) {
app.macros.picked.clear();
app.macros.anchor = None;
}
/// Opens Save As Command for the picked steps.
pub fn open_save(app: &mut App) {
if folder(app).is_none() {
app.status_err(tr!("Saved commands are kept in a folder on your computer: save them in the desktop app."));
return;
}
let picked = picked(app);
if picked.is_empty() {
app.status_err(tr!("Pick the steps to save first: Ctrl+click them in the History panel (Shift+click picks a range)."));
return;
}
let listed = app.s.execute("macro.history", &json!({})).unwrap_or(Value::Null);
let rows = listed["steps"].as_array().cloned().unwrap_or_default();
let steps: Vec<StepView> = picked
.iter()
.filter_map(|&i| rows.get(i))
.map(|r| StepView {
index: r["index"].as_u64().and_then(|n| usize::try_from(n).ok()).unwrap_or(0),
label: r["label"].as_str().unwrap_or("").to_string(),
refused: r["why"].as_str().map(str::to_string),
note: r["rewritten"].as_str().map(str::to_string),
})
.collect();
let n = app.macros.list.len() + 1;
app.macros.save = Some(SaveDialog { name: tr!("Command {n}", n = n), steps, focus: true });
}
/// A step's undo label in the interface language (the engine's English is the key).
fn step_label(label: &str) -> String {
crate::i18n::t_dyn(label).into_owned()
}
fn save_window(app: &mut App, ctx: &egui::Context) {
let Some(d) = &mut app.macros.save else { return };
let mut open = true;
let mut save = false;
let mut cancel = false;
let title = tr!("Save As Command");
let shown = egui::Window::new(title).id(egui::Id::new("save_as_command")).open(&mut open).collapsible(false).resizable(false).pivot(egui::Align2::CENTER_CENTER).default_pos(ctx.content_rect().center()).show(ctx, |ui| {
ui.set_min_width(380.0);
ui.horizontal(|ui| {
ui.label(text(Type::Label, tr!("Name")));
let r = ui.add(egui::TextEdit::singleline(&mut d.name).desired_width(280.0)).named(tr!("Saved command name"));
if d.focus {
r.request_focus();
d.focus = false;
}
if r.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)) {
save = true;
}
});
ui.add_space(6.0);
ui.label(text(Type::Label, trn!("{n} step, run in order as one undo step:", "{n} steps, run in order as one undo step:", d.steps.len())));
egui::ScrollArea::vertical().max_height(220.0).show(ui, |ui| {
for st in &d.steps {
ui.horizontal(|ui| {
ui.label(text(Type::Data, (st.index + 1).to_string()).color(T.text_dim));
ui.label(text(Type::Body, step_label(&st.label)));
match (&st.refused, &st.note) {
(Some(why), _) => {
ui.label(text(Type::Caption, tr!("can't be kept: {why}", why = crate::i18n::t_dyn(why))).color(T.error));
}
(None, Some(note)) => {
ui.label(text(Type::Caption, crate::i18n::t_dyn(note)).color(T.text_dim));
}
(None, None) => {}
}
});
}
});
let refused = d.steps.iter().filter(|s| s.refused.is_some()).count();
ui.add_space(4.0);
if refused > 0 {
ui.label(text(Type::Caption, trn!("Take the step that can't be kept out of the picks (Ctrl+click it) to save the others.", "Take the {n} steps that can't be kept out of the picks (Ctrl+click them) to save the others.", refused)).color(T.error));
} else {
ui.label(text(Type::Caption, tr!("It runs on whatever is selected when you choose it in the Commands menu.")));
}
ui.add_space(6.0);
ui.horizontal(|ui| {
let ok = refused == 0 && !d.name.trim().is_empty();
if ui.add_enabled(ok, egui::Button::new(tr!("Save"))).clicked() {
save = true;
}
if ui.button(tr!("Cancel")).clicked() {
cancel = true;
}
});
});
a11y::name_title_bar(&shown, title);
if ctx.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Escape)) {
cancel = true;
}
if !open || cancel {
app.macros.save = None;
return;
}
let ready = app.macros.save.as_ref().filter(|d| save && !d.name.trim().is_empty() && d.steps.iter().all(|s| s.refused.is_none()));
if let Some(d) = ready {
let history: Vec<usize> = d.steps.iter().map(|s| s.index).collect();
let name = d.name.trim().to_string();
if let Some(folder) = folder_str(app) {
app.request("macro.save", json!({"folder": folder, "name": name, "history": history}));
}
}
}
/// The saved commands at the end of the Commands menu, as Animate lists them.
pub fn menu_items(app: &mut App, ui: &mut egui::Ui) {
if folder(app).is_none() {
return;
}
ui.separator();
if app.macros.list.is_empty() {
ui.label(text(Type::Caption, tr!("No saved commands yet: pick steps in the History panel and Save As Command")));
return;
}
let names: Vec<String> = app.macros.list.iter().map(|c| c.name.clone()).collect();
for name in names {
let key = crate::platform::shortcut_label(app.keymap.primary(&keymap::macro_id(&name)).unwrap_or(""));
if ui.add(egui::Button::new(name.as_str()).shortcut_text(text(Type::Key, key))).clicked() {
ui.input_mut(|i| {
i.consume_key(egui::Modifiers::NONE, egui::Key::Enter);
i.consume_key(egui::Modifiers::NONE, egui::Key::Space);
});
ui.close();
run_saved(app, &name);
}
}
}
/// Commands › Manage Saved Commands…
pub fn open_manage(app: &mut App) {
rescan(app);
app.macros.manage = Manage { open: true, ..Manage::default() };
}
/// Opens the shortcut editor on the saved command `name`, already waiting for its keys.
fn assign_shortcut(app: &mut App, ctx: &egui::Context, name: &str) {
let id = keymap::macro_id(name);
let Some(action) = app.keymap.actions.iter().find(|a| a.id == id).map(|a| a.id) else { return };
crate::dialogs::shortcuts_for(app, ctx, name, action);
}
enum Act {
Run(String),
Move(String, usize),
Rename(String, String),
Delete(String),
Shortcut(String),
}
fn manage_window(app: &mut App, ctx: &egui::Context) {
if !app.macros.manage.open {
return;
}
let Some(dir) = folder(app) else {
app.macros.manage.open = false;
return;
};
let mut open = true;
let mut acts: Vec<Act> = Vec::new();
let title = tr!("Manage Saved Commands");
let shown = egui::Window::new(title).id(egui::Id::new("manage_saved_commands")).open(&mut open).collapsible(false).resizable(false).default_width(760.0).show(ctx, |ui| {
ui.set_min_width(720.0);
let list = app.macros.list.clone();
if list.is_empty() {
ui.label(text(Type::Label, tr!("No saved commands yet. Pick steps in the History panel (Ctrl+click), then Save As Command: they run again on the selection as one undo step.")));
}
let n = list.len();
for (i, c) in list.iter().enumerate() {
ui.horizontal(|ui| {
ui.set_min_height(crate::theme::TARGET);
let mut renaming = app.macros.manage.renaming.take();
if let Some((k, typed)) = &mut renaming
&& *k == c.name
{
let r = ui.add(egui::TextEdit::singleline(typed).desired_width(220.0)).named(&tr!("New name for “{name}”", name = c.name));
if app.macros.manage.focus {
r.request_focus();
app.macros.manage.focus = false;
}
let enter = r.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter));
if ui.button(tr!("Rename")).clicked() || enter {
acts.push(Act::Rename(c.name.clone(), typed.trim().to_string()));
} else if ui.button(tr!("Cancel")).clicked() || ui.input(|i| i.key_pressed(egui::Key::Escape)) {
renaming = None;
}
app.macros.manage.renaming = renaming;
return;
}
app.macros.manage.renaming = renaming;
// Fixed columns, so the buttons line up row under row.
let cell = |ui: &mut egui::Ui, w: f32, add: &mut dyn FnMut(&mut egui::Ui)| {
ui.allocate_ui_with_layout(egui::vec2(w, crate::theme::TARGET), egui::Layout::left_to_right(egui::Align::Center), |ui| {
ui.set_min_width(w);
add(ui);
});
};
cell(ui, 210.0, &mut |ui| {
ui.add(egui::Label::new(text(Type::Body, &c.name)).truncate());
});
cell(ui, 64.0, &mut |ui| {
ui.label(text(Type::DataSmall, trn!("{n} step", "{n} steps", c.steps)).color(T.text_dim));
});
let key = app.keymap.primary(&keymap::macro_id(&c.name)).map(crate::platform::shortcut_label).unwrap_or_default();
cell(ui, 96.0, &mut |ui| {
ui.add(egui::Label::new(text(Type::Key, key.as_str()).color(T.text_dim)).truncate());
});
if ui.button(tr!("Run")).named(&tr!("Run “{name}”", name = c.name)).on_hover_text(tr!("Run it on the selection (one undo step)")).clicked() {
acts.push(Act::Run(c.name.clone()));
}
let gap = crate::theme::TARGET + 4.0;
if i > 0 {
if crate::timeline::icon_button(ui, &tr!("Move “{name}” up", name = c.name), None, crate::icons::Icon::ChevronUp).clicked() {
acts.push(Act::Move(c.name.clone(), i - 1));
}
} else {
ui.allocate_exact_size(egui::vec2(gap, crate::theme::TARGET), egui::Sense::hover());
}
if i + 1 < n {
if crate::timeline::icon_button(ui, &tr!("Move “{name}” down", name = c.name), None, crate::icons::Icon::ChevronDown).clicked() {
acts.push(Act::Move(c.name.clone(), i + 1));
}
} else {
ui.allocate_exact_size(egui::vec2(gap, crate::theme::TARGET), egui::Sense::hover());
}
if ui.button(tr!("Shortcut…")).named(&tr!("Shortcut for “{name}”", name = c.name)).on_hover_text(tr!("Give it a key in Keyboard Shortcuts")).clicked() {
acts.push(Act::Shortcut(c.name.clone()));
}
if ui.button(tr!("Rename…")).named(&tr!("Rename “{name}”", name = c.name)).clicked() {
app.macros.manage.renaming = Some((c.name.clone(), c.name.clone()));
app.macros.manage.focus = true;
}
if ui.button(tr!("Delete…")).named(&tr!("Delete “{name}”", name = c.name)).on_hover_text(tr!("Delete this saved command's file (asks first)")).clicked() {
acts.push(Act::Delete(c.name.clone()));
}
});
}
for (file, why) in &app.macros.problems {
ui.label(text(Type::Caption, tr!("{file} isn't a saved command: {why}", file = file, why = crate::i18n::t_dyn(why))).color(T.error));
}
ui.separator();
ui.horizontal(|ui| {
if ui.button(tr!("Add from File…")).on_hover_text(tr!("Copy a saved command someone shared into your commands")).clicked() {
app.invoke("macro.import");
}
ui.label(text(Type::Path, dir.display().to_string()).color(T.text_faint));
});
ui.label(text(Type::Caption, tr!("Saved commands are small JSON files: share one by sending it; Commands › Run Command… runs a file without adding it.")));
});
a11y::name_title_bar(&shown, title);
let folder = dir.display().to_string();
for act in acts {
match act {
Act::Run(name) => run_saved(app, &name),
Act::Move(name, index) => app.request("macro.move", json!({"folder": folder, "name": name, "index": index})),
Act::Rename(name, to) => app.request("macro.rename", json!({"folder": folder, "name": name, "to": to})),
Act::Delete(name) => app.request("macro.delete", json!({"folder": folder, "name": name})),
Act::Shortcut(name) => assign_shortcut(app, ctx, &name),
}
}
if !open {
app.macros.manage = Manage::default();
}
}
pub fn show(app: &mut App, ctx: &egui::Context) {
save_window(app, ctx);
manage_window(app, ctx);
}
/// Moves (or with `to` None, drops) the shortcut keys kept for the saved command `from`.
fn move_shortcut(app: &mut App, from: &str, to: Option<&str>) {
let Some(keys) = app.prefs.shortcuts.remove(&keymap::macro_id(from)) else { return };
if let Some(to) = to {
app.prefs.shortcuts.insert(keymap::macro_id(to), keys);
}
app.save_prefs();
}
/// After a `macro.*` command ran: the list again, the status line, and a renamed or deleted
/// command's shortcut following it.
pub fn done(app: &mut App, id: &str, v: &Value) {
let name = v["name"].as_str().unwrap_or("").to_string();
match id {
"macro.run" => {
let n = v["steps"].as_u64().unwrap_or(0);
app.status_ok(trn!("Ran “{name}” ({n} step) — {undo} to undo", "Ran “{name}” ({n} steps) — {undo} to undo", n, name = name, undo = app.undo_key()));
return;
}
"macro.save" => {
app.macros.save = None;
clear_picks(app);
app.status_ok(tr!("Saved “{name}”: find it at the end of the Commands menu", name = name));
}
"macro.rename" => {
app.macros.manage.renaming = None;
if let Some(from) = v["from"].as_str() {
move_shortcut(app, from, Some(&name));
}
}
"macro.delete" => {
let gone = v["deleted"].as_str().unwrap_or("").to_string();
move_shortcut(app, &gone, None);
app.status_ok(tr!("Deleted “{name}”", name = gone));
}
"macro.import" => app.status_ok(tr!("Added “{name}” to your commands", name = name)),
_ => {}
}
rescan(app);
}
+115
View File
@@ -0,0 +1,115 @@
//! Saved commands in the desktop app (ADR 0097): picking steps in the History panel, Save As
//! Command, a saved command's shortcut running it, and a rename or delete taking its keys
//! along.
use crate::app::App;
use crate::keymap;
use anicraft_engine::Session;
use anicraft_engine::doc::sample;
use serde_json::json;
/// A test app: a screenshot path, so the saved commands live in a temporary folder.
fn app(ctx: &egui::Context) -> App {
App::with_context(ctx, Session::new(sample::demo()), Some(std::path::PathBuf::from("unused.png")))
}
fn frame(ctx: &egui::Context, app: &mut App, events: Vec<egui::Event>) {
let raw = egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1600.0, 940.0))), events, ..Default::default() };
ctx.run_ui(raw, |ui| app.frame(ui)).textures_delta.clear();
}
#[test]
fn picked_steps_save_as_a_command_and_its_shortcut_runs_it() {
let ctx = egui::Context::default();
let mut app = app(&ctx);
// (The only test here that writes to the folder.)
if let Some(f) = crate::macros_ui::folder(&app) {
let _ = std::fs::remove_dir_all(&f);
}
app.run("edit.select_all", json!({}));
app.run("modify.rotate_cw", json!({}));
app.run("element.set_color_effect", json!({"style": "alpha", "alpha": 50}));
let n = app.s.history_len();
// Ctrl+click the two steps; a plain pick of a third, then Ctrl+click takes it out again.
crate::macros_ui::pick(&mut app, n - 2, true, false);
crate::macros_ui::pick(&mut app, n - 1, true, false);
assert_eq!(crate::macros_ui::picked(&mut app), [n - 2, n - 1]);
crate::macros_ui::open_save(&mut app);
let d = app.macros.save.as_mut().expect("the dialog");
assert_eq!(d.steps.len(), 2);
assert!(d.steps.iter().all(|s| s.refused.is_none()));
d.name = "Spin and Fade".into();
frame(&ctx, &mut app, vec![]);
let folder = crate::macros_ui::folder(&app).expect("a folder").display().to_string();
app.request("macro.save", json!({"folder": folder, "name": "Spin and Fade", "history": [n - 2, n - 1]}));
assert!(app.macros.save.is_none(), "saved, the dialog closes");
assert!(crate::macros_ui::picked(&mut app).is_empty());
assert_eq!(app.macros.list.iter().map(|c| c.name.as_str()).collect::<Vec<_>>(), ["Spin and Fade"]);
// A key of its own, through the shortcut map.
let id = keymap::macro_id("Spin and Fade");
app.prefs.shortcuts = keymap::assign(&app.prefs.shortcuts, &id, None, "Ctrl+Alt+R", false).expect("a free key");
app.refresh_keymap();
assert!(app.shortcuts.iter().any(|(_, k, a)| *k == egui::Key::R && *a == id));
let steps = app.s.history_len();
let before = app.s.selected_elements().first().map(|(_, e)| e.transform);
// (The dialog's name field gives the keyboard back once it is gone.)
for _ in 0..3 {
frame(&ctx, &mut app, vec![]);
}
let key = egui::Event::Key { key: egui::Key::R, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::COMMAND | egui::Modifiers::ALT };
frame(&ctx, &mut app, vec![key]);
assert_eq!(app.s.history_len(), steps + 1, "the key ran it as one step");
assert_eq!(app.s.undo_label(), Some("Spin and Fade"));
assert_ne!(app.s.selected_elements().first().map(|(_, e)| e.transform), before);
// A rename takes its key along; a delete (confirmed) drops it.
app.request("macro.rename", json!({"folder": folder, "name": "Spin and Fade", "to": "Twirl"}));
assert_eq!(app.keymap.keys(&keymap::macro_id("Twirl")), ["Ctrl+Alt+R"]);
assert!(!app.prefs.shortcuts.contains_key(&id));
app.request("macro.delete", json!({"folder": folder, "name": "Twirl"}));
assert!(app.confirm.is_some(), "deleting a file asks first");
app.confirm = None;
app.perform("macro.delete", json!({"folder": folder, "name": "Twirl", "confirm": true}));
assert!(app.macros.list.is_empty());
assert!(app.prefs.shortcuts.keys().all(|k| keymap::macro_name(k).is_none()));
let _ = std::fs::remove_dir_all(&folder);
}
#[test]
fn a_step_that_cant_be_kept_is_named_in_the_dialog() {
let ctx = egui::Context::default();
let mut app = app(&ctx);
app.run("edit.select_all", json!({}));
app.run("edit.copy", json!({}));
app.run("edit.paste", json!({}));
let n = app.s.history_len();
crate::macros_ui::pick(&mut app, n - 1, false, false);
crate::macros_ui::open_save(&mut app);
let d = app.macros.save.as_ref().expect("the dialog");
assert!(d.steps[0].refused.as_deref().is_some_and(|w| w.contains("clipboard")), "{:?}", d.steps);
// The dialog draws, and Save stays off.
frame(&ctx, &mut app, vec![]);
assert!(app.macros.save.is_some());
}
#[test]
fn saved_commands_take_shortcuts_like_any_action() {
keymap::set_macros(["Spin"]);
let none = std::collections::BTreeMap::new();
let o = keymap::assign(&none, "macro:Spin", None, "Ctrl+Alt+R", false).expect("free");
let m = keymap::Keymap::new(&o);
assert_eq!(m.owner("Ctrl+Alt+R").map(|a| a.id), Some("macro:Spin"));
assert!(matches!(keymap::assign(&o, "macro:Spin", None, "Ctrl+Z", false), Err(keymap::Refusal::Taken { id: "edit.undo", .. })));
// Kept while the folder hasn't been read yet, bound once it is.
keymap::set_macros([]);
let kept = keymap::sanitize(o.clone());
assert!(kept.contains_key("macro:Spin"));
assert!(keymap::Keymap::new(&kept).keys("macro:Spin").is_empty());
// A clash from a hand-edited file stays with the action listed first.
keymap::set_macros(["Spin"]);
let bad = std::collections::BTreeMap::from([("macro:Spin".to_string(), vec!["Ctrl+Z".to_string()])]);
let m = keymap::Keymap::new(&bad);
assert_eq!(m.owner("Ctrl+Z").map(|a| a.id), Some("edit.undo"));
assert!(m.keys("macro:Spin").is_empty());
}
+3
View File
@@ -71,6 +71,9 @@ mod plugin_export_ui;
mod plugin_fixture_tests;
#[cfg(test)]
mod plugin_ui_tests;
#[cfg(test)]
mod macros_ui_tests;
mod macros_ui;
mod plugins_ui;
mod prefs;
mod recent;
+56 -8
View File
@@ -576,29 +576,77 @@ pub(crate) fn align_panel(app: &mut App, ui: &mut egui::Ui) {
}
/// Undo history: past steps (click to go back), the current state, and redoable steps (dimmed).
/// Ctrl+click picks steps (Shift+click a range) for Save As Command, which keeps them as a
/// saved command in the Commands menu (ADR 0097); so does each step's context menu.
pub(crate) fn history(app: &mut App, ui: &mut egui::Ui) {
let picked: std::collections::BTreeSet<usize> = crate::macros_ui::picked(app).into_iter().collect();
let hist = app.s.history();
let past: Vec<String> = hist.undo_labels().map(str::to_string).collect();
let future: Vec<String> = hist.redo_labels().map(str::to_string).collect();
let evicted = hist.evicted;
let mut target = None;
egui::ScrollArea::vertical().id_salt("history").max_height(ui.available_height().max(60.0)).auto_shrink([false, false]).stick_to_bottom(true).show(ui, |ui| {
// (step, toggle, range)
let mut pick: Option<(usize, bool, bool)> = None;
let mut save = false;
let footer = crate::theme::TARGET + 8.0;
let tip = tr!("Click to go back to this step · Ctrl+click picks it for Save As Command, Shift+click a range");
egui::ScrollArea::vertical().id_salt("history").max_height((ui.available_height() - footer).max(crate::theme::TARGET)).auto_shrink([false, false]).stick_to_bottom(true).show(ui, |ui| {
let base = if evicted > 0 { tr!("… older steps freed (memory budget)") } else { tr!("Opened document") };
if ui.selectable_label(past.is_empty(), text(Type::Body, base).color(if evicted > 0 { T.text_faint } else { T.text_dim })).clicked() {
if ui.selectable_label(past.is_empty() && picked.is_empty(), text(Type::Body, base).color(if evicted > 0 { T.text_faint } else { T.text_dim })).clicked() {
target = Some(0);
}
for (i, label) in past.iter().enumerate() {
let rows = past.iter().map(|l| (l, false)).chain(future.iter().map(|l| (l, true)));
for (i, (label, undone)) in rows.enumerate() {
let current = i + 1 == past.len();
if ui.selectable_label(current, crate::i18n::t_dyn(label).into_owned()).clicked() {
target = Some(i + 1);
let on = picked.contains(&i);
let shown = crate::i18n::t_dyn(label).into_owned();
// With steps picked, the picks are highlighted and the current step is marked.
let shown = if current && !picked.is_empty() { format!("› {shown}") } else { shown };
let t = if undone { text(Type::Body, shown).color(T.text_faint).italics() } else { text(Type::Body, shown) };
let r = ui.selectable_label(if picked.is_empty() { current } else { on }, t).on_hover_text(tip);
if r.clicked() {
let m = ui.input(|i| i.modifiers);
if m.command || m.shift {
pick = Some((i, m.command, m.shift));
} else {
target = Some(i + 1);
}
}
r.context_menu(|ui| {
if ui.button(if on { tr!("Unpick Step") } else { tr!("Pick for Save As Command") }).clicked() {
pick = Some((i, true, false));
ui.close();
}
if ui.button(tr!("Save As Command…")).clicked() {
if !on {
pick = Some((i, true, false));
}
save = true;
ui.close();
}
});
}
for (i, label) in future.iter().enumerate() {
if ui.selectable_label(false, text(Type::Body, crate::i18n::t_dyn(label)).color(T.text_faint).italics()).clicked() {
target = Some(past.len() + i + 1);
});
ui.horizontal(|ui| {
ui.set_min_height(crate::theme::TARGET);
if picked.is_empty() {
ui.label(text(Type::Caption, tr!("Ctrl+click steps to save them as a command")));
} else {
if ui.button(tr!("Save As Command…")).on_hover_text(tr!("Keep the picked steps as a command in the Commands menu, to run on any selection")).clicked() {
save = true;
}
ui.label(text(Type::Caption, trn!("{n} step picked", "{n} steps picked", picked.len())));
if ui.small_button(tr!("Clear")).on_hover_text(tr!("Unpick every step")).clicked() {
crate::macros_ui::clear_picks(app);
}
}
});
if let Some((i, toggle, range)) = pick {
crate::macros_ui::pick(app, i, toggle, range);
}
if save {
crate::macros_ui::open_save(app);
}
if let Some(t) = target
&& let Err(e) = app.s.travel_to(t)
{
+16 -2
View File
@@ -397,7 +397,7 @@ pub fn places() -> Vec<(&'static str, Option<PathBuf>)> {
return Vec::new();
}
#[cfg_attr(target_arch = "wasm32", allow(unused_mut))]
let mut v = vec![(tr_noop!("Preferences"), config_dir()), (tr_noop!("Autosave"), recovery_dir()), (tr_noop!("Logs"), log_dir()), (tr_noop!("Plug-ins"), plugins_dir()), (tr_noop!("Templates"), templates_dir())];
let mut v = vec![(tr_noop!("Preferences"), config_dir()), (tr_noop!("Autosave"), recovery_dir()), (tr_noop!("Logs"), log_dir()), (tr_noop!("Plug-ins"), plugins_dir()), (tr_noop!("Templates"), templates_dir()), (tr_noop!("Saved commands"), commands_dir())];
#[cfg(not(target_arch = "wasm32"))]
v.push((tr_noop!("User guide"), Some(guide_dir())));
v
@@ -532,6 +532,19 @@ pub fn templates_dir() -> Option<PathBuf> {
}
}
/// Where saved commands live (ADR 0097): `Commands` in the settings folder, one small JSON file
/// each. `ANICRAFT_COMMANDS_DIR` points it elsewhere (tests, screenshots). None in a browser,
/// which has no folders to keep them in.
pub fn commands_dir() -> Option<PathBuf> {
if WEB {
return None;
}
match std::env::var_os("ANICRAFT_COMMANDS_DIR").filter(|v| !v.is_empty()) {
Some(d) => Some(PathBuf::from(d)),
None => config_dir().map(|d| d.join("Commands")), // i18n-exempt: a folder name
}
}
/// Where installed plug-ins live: a `plugins` folder in the settings folder (ADR 0017).
pub fn plugins_dir() -> Option<PathBuf> {
config_dir().map(|d| d.join("plugins"))
@@ -829,6 +842,7 @@ pub fn filters(cmd: &str) -> (&'static str, &'static [&'static str]) {
// Opening also imports .fla archives and .xfl packages.
"file.open" => (tr_noop!("Documents"), &["anicraft", "fla", "xfl"]),
"plugin.install" => (tr_noop!("WebAssembly plug-in"), &["wasm"]),
"macro.run" | "macro.import" => (tr_noop!("Saved command"), &["json"]),
"brush.preset_export" | "brush.preset_import" => (tr_noop!("Brush set"), &["json"]),
"filter.preset_export" | "filter.preset_import" => (tr_noop!("Filter preset file"), &["json"]),
"swatch.export" => (tr_noop!("Swatch file"), &["json"]),
@@ -839,7 +853,7 @@ pub fn filters(cmd: &str) -> (&'static str, &'static [&'static str]) {
/// Commands that read a file the user picks (the others write one, or a folder of them).
pub fn reads_file(cmd: &str) -> bool {
matches!(cmd, "file.open" | "plugin.install" | "file.import" | "file.import_to_library" | "brush.preset_import" | "filter.preset_import" | "swatch.import")
matches!(cmd, "file.open" | "plugin.install" | "file.import" | "file.import_to_library" | "brush.preset_import" | "filter.preset_import" | "swatch.import" | "macro.run" | "macro.import")
}
/// Shows the platform's own dialog (Windows common dialog, macOS panel, Linux XDG portal), with
+2
View File
@@ -141,6 +141,8 @@ pub fn menu(app: &mut App, ui: &mut egui::Ui, cmds: &[CommandSpec], item: impl F
for spec in cmds.iter().filter(|c| c.menu == "Commands") {
item(app, ui, spec);
}
// Saved commands last, as Animate lists them (ADR 0097).
crate::macros_ui::menu_items(app, ui);
}
fn hex_rgb(s: &str) -> [u8; 3] {