mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-29 09:46:19 +01:00
Toolbars: Rename Button… gives a command button a label of its own
A command button on a toolbar made with New Toolbar showed its
command's label only. Its context menu now has Rename Button…, which
opens a dialog with the button's label; OK gives the button the label
typed, and an empty label gives it back its command's label.
- The label loses the spaces at its ends and has at most 64
characters. Control characters and characters that change the
direction of text show as \u{…} escapes on the button.
- The hover text still shows the command's name and shortcut. A
screen reader says the label and then the command's name, or only
the label when it is the command's label or name.
- Labels are saved with the toolbar (`labels`, left out when empty,
so older layouts load unchanged), and Manage Toolbars' copy keeps
them. Remove from Toolbar and `toolbar.reset` drop a button's label
with it, and a move keeps it.
- `toolbar.renameCommand {command, toolbar, label?}` sets the label
(without `label` it opens the dialog), `toolbar.addCommand` takes an
optional `label`, and `window.toolbar.list` reports `labels`. A
longer label, a label that is not text or a button the toolbar does
not have is an error and changes nothing.
Rename Button… and its rules are VectorCraft's own, and so is the
64-character limit.
Docs: docs/control-protocol.md, docs/mcp.md, docs/target-app-parity.md.
This commit is contained in:
1 parent
3f6bd6a0e1
commit
bfae97f9a5
11 files changed
+407
-33
No files matched your search
@@ -617,13 +617,19 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"toolbar.addCommand",
|
||||
"Toolbar: Add Command",
|
||||
"",
|
||||
"{command: id, toolbar: name, at?: n} put a button for `command` (a Command Palette result other than a tool: a command's id, or `plugin:<id>`, `effect:<id>` or `panel:<id>`) on the toolbar made with New Toolbar called `toolbar`, after its tools, moving it if it is there already: at place `at` among its command buttons (0 = the first; omitted: at the end), as Add Command in its Add Tool… menu and Move Up and Move Down in the button's context menu do; a click on the button runs what the command's menu item runs; an unknown command, a tool, a command that needs params a click does not give (such as this one) or an `at` past the end is an error and changes nothing; kept with the workspace; returns the toolbar's commands",
|
||||
"{command: id, toolbar: name, at?: n, label?: text} put a button for `command` (a Command Palette result other than a tool: a command's id, or `plugin:<id>`, `effect:<id>` or `panel:<id>`) on the toolbar made with New Toolbar called `toolbar`, after its tools, moving it if it is there already: at place `at` among its command buttons (0 = the first; omitted: at the end), as Add Command in its Add Tool… menu and Move Up and Move Down in the button's context menu do; with `label`, the button shows that label, as toolbar.renameCommand gives it (an empty `label` gives it the command's own label again); a click on the button runs what the command's menu item runs; an unknown command, a tool, a command that needs params a click does not give (such as this one), an `at` past the end, or a `label` that is not text or is longer than 64 characters is an error and changes nothing; kept with the workspace; returns the toolbar's commands",
|
||||
),
|
||||
(
|
||||
"toolbar.removeCommand",
|
||||
"Toolbar: Remove Command",
|
||||
"",
|
||||
"{command: id, toolbar: name} take the button for `command` off the toolbar made with New Toolbar called `toolbar` (one not on it stays off; a command that is no longer installed can be taken off too), as Remove Command in its Add Tool… menu and Remove from Toolbar in the button's context menu do; returns the toolbar's commands",
|
||||
"{command: id, toolbar: name} take the button for `command` off the toolbar made with New Toolbar called `toolbar`, with its own label (one not on it stays off; a command that is no longer installed can be taken off too), as Remove Command in its Add Tool… menu and Remove from Toolbar in the button's context menu do; returns the toolbar's commands",
|
||||
),
|
||||
(
|
||||
"toolbar.renameCommand",
|
||||
"Toolbar: Rename Button",
|
||||
"",
|
||||
"{command: id, toolbar: name, label?: text} give the button for `command` on the toolbar made with New Toolbar called `toolbar` the label `label` (spaces at its ends dropped, at most 64 characters; empty: the command's own label again), as Rename Button… in the button's context menu does; without `label`, opens the Rename Button dialog and returns null; the hover text still shows the command's name and shortcut, and a screen reader says the label and then the command's name; a button the toolbar does not have, or a label that is not text or is longer, is an error and changes nothing; kept with the workspace; returns {command, label} (`label` null for the command's own)",
|
||||
),
|
||||
(
|
||||
"toolbar.reset",
|
||||
@@ -683,7 +689,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"window.toolbar.list",
|
||||
"List Toolbars",
|
||||
"",
|
||||
"{} the toolbars made with New Toolbar in the current workspace: [{name, shown, double, slots, commands, floating, side, order}], `commands` the Command Palette results of its command buttons, `side` the edge it docks at (while floating, the edge it docked at last) and `order` its place in that edge's stack while docked (else null)",
|
||||
"{} the toolbars made with New Toolbar in the current workspace: [{name, shown, double, slots, commands, labels, floating, side, order}], `commands` the Command Palette results of its command buttons, `labels` the labels given to them with Rename Button… ({command: label}), `side` the edge it docks at (while floating, the edge it docked at last) and `order` its place in that edge's stack while docked (else null)",
|
||||
),
|
||||
("window.taskBar", "Contextual Task Bar", "", "{}"),
|
||||
(
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
//! where a click adds the tool at the end, and whose Remove Tool items take tools out: VectorCraft's
|
||||
//! own way to fill a toolbar without a drag. The same menu's Add Command submenu searches the Command
|
||||
//! Palette's results and adds a command button after the tools, which runs what the command's menu
|
||||
//! item runs (`toolbar.addCommand`, `toolbar.removeCommand`); command buttons are VectorCraft's own.
|
||||
//! item runs (`toolbar.addCommand`, `toolbar.removeCommand`), and whose Rename Button… gives it a
|
||||
//! label of its own (`toolbar.renameCommand`); command buttons are VectorCraft's own.
|
||||
//! Its title bar moves it, its × hides it and its double arrow shows its tools in one column or
|
||||
//! two. Each toolbar is listed under Window › Toolbars, where its item shows or hides it, and is
|
||||
//! kept with the workspace it was made in (`Workspace::toolbars`).
|
||||
@@ -47,6 +48,8 @@ pub(crate) const MAX: usize = 64;
|
||||
const MAX_NAME: usize = 200;
|
||||
/// The most command buttons a toolbar holds.
|
||||
const MAX_COMMANDS: usize = 200;
|
||||
/// The most characters a command button's own label has (Rename Button…).
|
||||
const MAX_LABEL: usize = 64;
|
||||
/// Width of a toolbar of one column of tool buttons, inside its border.
|
||||
const WIDTH: f32 = 44.0;
|
||||
/// Width a second column of tool buttons adds.
|
||||
@@ -135,6 +138,7 @@ pub(crate) fn create(ui: &mut UiState, name: &str) -> Result<String, String> {
|
||||
double: false,
|
||||
floating: vec![],
|
||||
commands: vec![],
|
||||
labels: Default::default(),
|
||||
});
|
||||
show_alone_after_tab(ui, name);
|
||||
Ok(name.to_string())
|
||||
@@ -342,7 +346,9 @@ pub(crate) fn delete(ui: &mut UiState, ctx: Option<&egui::Context>, name: &str)
|
||||
/// torn off them, each group's tool chosen last only when the group holds it, at most
|
||||
/// [`MAX_COMMANDS`] command buttons, each command once and none for a tool, and the docked ones
|
||||
/// numbered 0, 1, 2… at each edge (a hand-edited preferences file or workspace). A command that is
|
||||
/// not known now stays: it may be an uninstalled plug-in's.
|
||||
/// not known now stays: it may be an uninstalled plug-in's. A button's own label loses the spaces
|
||||
/// at its ends, and stays only while the toolbar holds its command and [`check_label`] takes it and
|
||||
/// it is not empty.
|
||||
pub(crate) fn sanitize(bars: &mut Vec<CustomToolbar>) {
|
||||
let mut names = std::collections::BTreeSet::new();
|
||||
bars.retain_mut(|b| {
|
||||
@@ -355,6 +361,11 @@ pub(crate) fn sanitize(bars: &mut Vec<CustomToolbar>) {
|
||||
let mut commands = std::collections::BTreeSet::new();
|
||||
b.commands.retain(|id| !id.trim().is_empty() && !id.starts_with("tool:") && commands.insert(id.clone()));
|
||||
b.commands.truncate(MAX_COMMANDS);
|
||||
let held = &b.commands;
|
||||
b.labels.retain(|id, label| {
|
||||
*label = label.trim().to_string();
|
||||
held.contains(id) && !label.is_empty() && check_label(label).is_ok()
|
||||
});
|
||||
let slots = &b.slots;
|
||||
b.slot_tool.retain(|first, id| slots.iter().any(|s| s.first() == Some(first) && s.contains(id)));
|
||||
crate::state::FloatingFlyout::sanitize(&mut b.floating);
|
||||
@@ -382,8 +393,9 @@ pub(crate) fn keep_strips(bar: &mut CustomToolbar) {
|
||||
});
|
||||
}
|
||||
|
||||
/// The toolbar the `toolbar` param of `toolbar.addCommand` and `toolbar.removeCommand` names,
|
||||
/// which must be one made with New Toolbar: the Tools panel's toolbar holds tools only.
|
||||
/// The toolbar the `toolbar` param of `toolbar.addCommand`, `toolbar.renameCommand` and
|
||||
/// `toolbar.removeCommand` names, which must be one made with New Toolbar: the Tools panel's
|
||||
/// toolbar holds tools only.
|
||||
fn command_target(ui: &UiState, p: &Value) -> Result<usize, String> {
|
||||
let name = target(ui, p)?.ok_or("toolbar (a toolbar's name) is required: only toolbars made with New Toolbar hold commands")?;
|
||||
index(ui, &name)
|
||||
@@ -417,6 +429,49 @@ pub(crate) fn add_command(bar: &mut CustomToolbar, id: &str, at: Option<usize>)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// `label` as a command button keeps it: without leading and trailing spaces, at most
|
||||
/// [`MAX_LABEL`] characters; empty means the command's own label.
|
||||
fn check_label(label: &str) -> Result<&str, String> {
|
||||
let label = label.trim();
|
||||
if label.chars().count() > MAX_LABEL {
|
||||
return Err(format!("a button label has at most {MAX_LABEL} characters"));
|
||||
}
|
||||
Ok(label)
|
||||
}
|
||||
|
||||
/// Give the button for `id` on `bar` the label `label` (Rename Button…); an empty one gives it back
|
||||
/// its command's label.
|
||||
pub(crate) fn set_label(bar: &mut CustomToolbar, id: &str, label: &str) -> Result<(), String> {
|
||||
let label = check_label(label)?;
|
||||
if !bar.commands.iter().any(|c| c == id) {
|
||||
return Err(format!("the toolbar `{}` has no button for `{id}`", bar.name));
|
||||
}
|
||||
if label.is_empty() {
|
||||
bar.labels.remove(id);
|
||||
} else {
|
||||
bar.labels.insert(id.to_string(), label.to_string());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The `label` param of `toolbar.addCommand` and `toolbar.renameCommand`: `None` while it is left
|
||||
/// out.
|
||||
fn label_param(p: &Value) -> Result<Option<&str>, String> {
|
||||
match p.get("label") {
|
||||
None | Some(Value::Null) => Ok(None),
|
||||
Some(Value::String(s)) => check_label(s).map(|_| Some(s.as_str())),
|
||||
Some(v) => Err(format!("label must be a string (got {v})")),
|
||||
}
|
||||
}
|
||||
|
||||
/// A button's own `label` as it is shown: control characters and the characters that change the
|
||||
/// direction text is laid out in are written as `\u{…}` escapes, as other names from outside are.
|
||||
/// The limit leaves room for every character of a label as an escape (at most 10 characters each),
|
||||
/// so the escapes do not cut a label short.
|
||||
fn shown_label(label: &str) -> String {
|
||||
vectorcraft_plugins::permissions::display_text(label, MAX_LABEL * 10)
|
||||
}
|
||||
|
||||
/// The commands of the toolbars made with New Toolbar; `None` for other ids.
|
||||
pub(crate) fn command(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<Result<Value, String>> {
|
||||
Some(match id {
|
||||
@@ -517,14 +572,37 @@ pub(crate) fn command(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<R
|
||||
None | Some(Value::Null) => None,
|
||||
Some(v) => Some(v.as_u64().and_then(|n| usize::try_from(n).ok()).ok_or_else(|| format!("`at` must be 0 or a larger whole number (got {v})"))?),
|
||||
};
|
||||
let label = label_param(p)?;
|
||||
let bar = app.ui.custom_toolbars.get_mut(k).ok_or("no such toolbar")?;
|
||||
add_command(bar, id, at).map(|_| json!(bar.commands))
|
||||
add_command(bar, id, at)?;
|
||||
if let Some(label) = label {
|
||||
set_label(bar, id, label)?;
|
||||
}
|
||||
Ok(json!(bar.commands))
|
||||
})(),
|
||||
"toolbar.renameCommand" => (|| {
|
||||
let k = command_target(&app.ui, p)?;
|
||||
let id = p.get("command").and_then(Value::as_str).ok_or("command (a command's id) is required")?;
|
||||
let label = label_param(p)?;
|
||||
let bar = app.ui.custom_toolbars.get_mut(k).ok_or("no such toolbar")?;
|
||||
let Some(label) = label else {
|
||||
// Without `label`: the Rename Button dialog, with the button's label as it is now.
|
||||
if !bar.commands.iter().any(|c| c == id) {
|
||||
return Err(format!("the toolbar `{}` has no button for `{id}`", bar.name));
|
||||
}
|
||||
let now = bar.labels.get(id).cloned().unwrap_or_default();
|
||||
app.ui.dialog = Some(Dialog::new(RENAME, json!({ "toolbar": bar.name, "command": id, "label": now })));
|
||||
return Ok(Value::Null);
|
||||
};
|
||||
set_label(bar, id, label)?;
|
||||
Ok(json!({ "command": id, "label": bar.labels.get(id) }))
|
||||
})(),
|
||||
"toolbar.removeCommand" => (|| {
|
||||
let k = command_target(&app.ui, p)?;
|
||||
let id = p.get("command").and_then(Value::as_str).ok_or("command (a command's id) is required")?;
|
||||
let bar = app.ui.custom_toolbars.get_mut(k).ok_or("no such toolbar")?;
|
||||
bar.commands.retain(|c| c != id);
|
||||
bar.labels.remove(id);
|
||||
Ok(json!(bar.commands))
|
||||
})(),
|
||||
"window.toolbar.list" => Ok(json!(
|
||||
@@ -533,7 +611,7 @@ pub(crate) fn command(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<R
|
||||
.iter()
|
||||
.map(|b| {
|
||||
let side = if b.dock_right { "right" } else { "left" };
|
||||
json!({"name": b.name, "shown": b.shown, "double": b.double, "slots": b.slots, "commands": b.commands, "floating": b.dock.is_none(), "side": side, "order": b.dock})
|
||||
json!({"name": b.name, "shown": b.shown, "double": b.double, "slots": b.slots, "commands": b.commands, "labels": b.labels, "floating": b.dock.is_none(), "side": side, "order": b.dock})
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
)),
|
||||
@@ -593,6 +671,60 @@ pub(crate) fn show_dialog(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Rename Button's dialog, for a command button (fields `toolbar`, `command` and `label`).
|
||||
pub(crate) const RENAME: &str = "renameToolbarButton";
|
||||
|
||||
/// OK in Rename Button: the typed label becomes the button's (empty: its command's label again).
|
||||
pub(crate) fn confirm_rename(app: &mut VectorcraftApp) -> Result<Value, String> {
|
||||
let Some(d) = app.ui.dialog.clone() else { return Err("no dialog open".into()) };
|
||||
let done = app.run("toolbar.renameCommand", json!({ "toolbar": d.str("toolbar"), "command": d.str("command"), "label": d.str("label") }))?;
|
||||
app.ui.dialog = None;
|
||||
Ok(done)
|
||||
}
|
||||
|
||||
/// The Rename Button dialog: the button's label, empty for its command's own, OK and Cancel.
|
||||
pub(crate) fn show_rename(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
let Some(mut d) = app.ui.dialog.clone() else { return };
|
||||
let t = Tokens::get(ctx);
|
||||
let (mut ok, mut cancel) = (false, false);
|
||||
crate::dialogs::modal::show(ctx, "Rename Button", egui::Id::unique("dialog-rename-toolbar-button"), -40.0, 22, |ui| {
|
||||
ui.set_width(320.0);
|
||||
crate::dialogs::modal::heading(ui, tl!("Rename Button"));
|
||||
ui.add_space(12.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(egui::RichText::new(tl!("Label:")).color(t.text_dim));
|
||||
let mut label = d.str("label");
|
||||
let field = ui.add(egui::TextEdit::singleline(&mut label).desired_width(220.0));
|
||||
if field.changed() {
|
||||
d.fields.insert("label".into(), json!(label));
|
||||
}
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
ui.label(egui::RichText::new(tl!("Leave it empty to show the command's name.")).color(t.text_dim));
|
||||
ui.add_space(16.0);
|
||||
// As wide as the field and as tall as the buttons, as in New Toolbar's dialog.
|
||||
let row = egui::vec2(ui.min_rect().width(), ui.spacing().interact_size.y);
|
||||
ui.allocate_ui_with_layout(row, egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
if widgets::primary_button(ui, tl!("OK")).clicked() {
|
||||
ok = true;
|
||||
}
|
||||
ui.add_space(8.0);
|
||||
if widgets::secondary_button(ui, tl!("Cancel")).clicked() {
|
||||
cancel = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
if ctx.input(|i| i.key_pressed(egui::Key::Enter)) {
|
||||
ok = true;
|
||||
}
|
||||
app.ui.dialog = Some(d);
|
||||
if cancel {
|
||||
app.ui.dialog = None;
|
||||
} else if ok && let Err(e) = confirm_rename(app) {
|
||||
app.status(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// Manage Toolbars' dialog.
|
||||
pub(crate) const MANAGE: &str = "manageToolbars";
|
||||
|
||||
@@ -801,6 +933,8 @@ enum Action {
|
||||
/// A command button moved to another place among the toolbar's command buttons (Move Up and
|
||||
/// Move Down in its context menu).
|
||||
MoveCommand(String, String, usize),
|
||||
/// Rename Button… in a command button's context menu: the toolbar's name and the command.
|
||||
RenameCommand(String, String),
|
||||
/// A command taken out of the toolbar named: Remove Command in Add Tool…'s menu, or Remove
|
||||
/// from Toolbar in the button's context menu.
|
||||
RemoveCommand(String, String),
|
||||
@@ -816,12 +950,36 @@ struct CommandLook {
|
||||
text: Option<crate::palette::ButtonText>,
|
||||
/// Why it can't run now, in English; none while it can.
|
||||
why: Option<String>,
|
||||
/// The label given to it with Rename Button…, as it is shown ([`shown_label`]).
|
||||
own: Option<String>,
|
||||
}
|
||||
|
||||
impl CommandLook {
|
||||
/// The label the button shows: the command's, or its id while the command is gone.
|
||||
/// The label the button shows: its own, else the command's, or its id while the command is gone.
|
||||
fn label(&self) -> &str {
|
||||
self.text.as_ref().map_or(self.id.as_str(), |t| t.label.as_str())
|
||||
self.own.as_deref().unwrap_or_else(|| self.text.as_ref().map_or(self.id.as_str(), |t| t.label.as_str()))
|
||||
}
|
||||
|
||||
/// The name a screen reader says for the button: its label, followed by the command's full name
|
||||
/// when the button has a label of its own that is neither the command's label nor its name.
|
||||
fn said(&self) -> String {
|
||||
match &self.own {
|
||||
Some(own) if own != self.name() && self.text.as_ref().is_none_or(|t| &t.label != own) => format!("{own}, {}", self.name()),
|
||||
_ => self.label().to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Its hover text: the command's full name (never the button's own label), its shortcut, and
|
||||
/// why it can't run now.
|
||||
fn tip(&self) -> String {
|
||||
let mut tip = self.name().to_owned();
|
||||
if let Some(shortcut) = self.text.as_ref().map(|t| t.shortcut.as_str()).filter(|s| !s.is_empty()) {
|
||||
tip = format!("{tip} {shortcut}");
|
||||
}
|
||||
if let Some(why) = &self.why {
|
||||
tip = format!("{tip}\n{}", crate::i18n::msg(why));
|
||||
}
|
||||
tip
|
||||
}
|
||||
|
||||
/// Its full name, with the menu path that tells it apart from a command of the same label, or
|
||||
@@ -905,6 +1063,14 @@ pub(crate) fn asked(ctx: &egui::Context) -> (usize, bool) {
|
||||
ctx.data(|d| d.get_temp::<Known>(known_id())).map_or((0, false), |k| (k.why.len(), k.pending))
|
||||
}
|
||||
|
||||
/// Each command button of the toolbar named `name`: (the label it shows, the name a screen reader
|
||||
/// says, its hover text).
|
||||
#[cfg(test)]
|
||||
pub(crate) fn button_texts(app: &VectorcraftApp, ctx: &egui::Context, name: &str) -> Vec<(String, String, String)> {
|
||||
let Some(bar) = find(&app.ui, name) else { return vec![] };
|
||||
command_looks(app, ctx, bar, &mut None).iter().map(|l| (l.label().to_owned(), l.said(), l.tip())).collect()
|
||||
}
|
||||
|
||||
/// How each command button of `bar` looks now, its answers kept in `known` (read for the current
|
||||
/// state the first time a toolbar with command buttons is drawn in a frame).
|
||||
fn command_looks(app: &VectorcraftApp, ctx: &egui::Context, bar: &CustomToolbar, known: &mut Option<Known>) -> Vec<CommandLook> {
|
||||
@@ -921,7 +1087,7 @@ fn command_looks(app: &VectorcraftApp, ctx: &egui::Context, bar: &CustomToolbar,
|
||||
None => Some(format!("command `{id}` is not available right now")),
|
||||
Some(t) => known.why(app, id, &t.name),
|
||||
};
|
||||
CommandLook { id: id.clone(), text, why }
|
||||
CommandLook { id: id.clone(), text, why, own: bar.labels.get(id).map(|l| shown_label(l)) }
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
@@ -1453,7 +1619,10 @@ pub(crate) fn show(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
app.status(e);
|
||||
}
|
||||
}
|
||||
a @ (Action::RunCommand(_) | Action::AddCommand(..) | Action::MoveCommand(..) | Action::RemoveCommand(..)) => command_action(app, a),
|
||||
a
|
||||
@ (Action::RunCommand(_) | Action::AddCommand(..) | Action::MoveCommand(..) | Action::RenameCommand(..) | Action::RemoveCommand(..)) => {
|
||||
command_action(app, a)
|
||||
}
|
||||
}
|
||||
}
|
||||
end_move();
|
||||
@@ -1592,6 +1761,7 @@ fn command_action(app: &mut VectorcraftApp, a: Action) {
|
||||
Action::AddCommand(name, id) => app.run("toolbar.addCommand", json!({ "command": id, "toolbar": name })),
|
||||
Action::MoveCommand(name, id, at) => app.run("toolbar.addCommand", json!({ "command": id, "toolbar": name, "at": at })),
|
||||
Action::RemoveCommand(name, id) => app.run("toolbar.removeCommand", json!({ "command": id, "toolbar": name })),
|
||||
Action::RenameCommand(name, id) => app.run("toolbar.renameCommand", json!({ "command": id, "toolbar": name })),
|
||||
_ => Ok(Value::Null),
|
||||
};
|
||||
if let Err(e) = done {
|
||||
@@ -1617,11 +1787,12 @@ fn command_buttons(ui: &mut egui::Ui, t: &Tokens, width: f32, middle: f32, bar:
|
||||
/// Height of a command button.
|
||||
const COMMAND_HEIGHT: f32 = 30.0;
|
||||
|
||||
/// A command button `width` points wide on the toolbar named `bar`: the command's label, on up to
|
||||
/// two lines and cut short with … when it is longer; its name and shortcut on hover. A click runs
|
||||
/// A command button `width` points wide on the toolbar named `bar`: its own label or the command's,
|
||||
/// on up to two lines and cut short with … when it is longer; the command's name and shortcut on
|
||||
/// hover ([`CommandLook::tip`]). A click runs
|
||||
/// the command. While the command can't run now, the button is dimmed and its hover says why. Its
|
||||
/// context menu moves it up or down among the toolbar's command buttons (`place`: its place and
|
||||
/// how many there are) and takes it out.
|
||||
/// how many there are), gives it a label of its own (Rename Button…) and takes it out.
|
||||
fn command_button(ui: &mut egui::Ui, t: &Tokens, width: f32, bar: &str, look: &CommandLook, place: (usize, usize), actions: &mut Vec<Action>) {
|
||||
let (rect, resp) = ui.allocate_exact_size(vec2(width, COMMAND_HEIGHT), Sense::click());
|
||||
let on = look.why.is_none();
|
||||
@@ -1635,15 +1806,8 @@ fn command_button(ui: &mut egui::Ui, t: &Tokens, width: f32, bar: &str, look: &C
|
||||
job.halign = egui::Align::Center;
|
||||
let galley = ui.painter().layout_job(job);
|
||||
ui.painter().galley(pos2(rect.center().x, rect.center().y - galley.size().y / 2.0), galley, color);
|
||||
resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, on, look.label()));
|
||||
let mut tip = look.text.as_ref().map_or(look.id.clone(), |t| t.name.clone());
|
||||
if let Some(shortcut) = look.text.as_ref().map(|t| t.shortcut.as_str()).filter(|s| !s.is_empty()) {
|
||||
tip = format!("{tip} {shortcut}");
|
||||
}
|
||||
if let Some(why) = &look.why {
|
||||
tip = format!("{tip}\n{}", crate::i18n::msg(why));
|
||||
}
|
||||
let resp = resp.on_hover_text(tip);
|
||||
resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, on, look.said()));
|
||||
let resp = resp.on_hover_text(look.tip());
|
||||
if resp.clicked() {
|
||||
actions.push(Action::RunCommand(look.id.clone()));
|
||||
}
|
||||
@@ -1657,6 +1821,10 @@ fn command_button(ui: &mut egui::Ui, t: &Tokens, width: f32, bar: &str, look: &C
|
||||
actions.push(Action::MoveCommand(bar.to_string(), look.id.clone(), i + 1));
|
||||
ui.close();
|
||||
}
|
||||
if widgets::menu_item(ui, tl!("Rename Button…"), true, false) {
|
||||
actions.push(Action::RenameCommand(bar.to_string(), look.id.clone()));
|
||||
ui.close();
|
||||
}
|
||||
if widgets::menu_item(ui, tl!("Remove from Toolbar"), true, false) {
|
||||
actions.push(Action::RemoveCommand(bar.to_string(), look.id.clone()));
|
||||
ui.close();
|
||||
@@ -1828,7 +1996,7 @@ mod tests {
|
||||
let names: Vec<&str> = toolbars_menu(&app).into_iter().filter(|(_, id, _)| *id == "window.toolbar.custom").map(|(l, ..)| l).collect();
|
||||
assert_eq!(names, ["Mine", "Toolbar 1"]);
|
||||
let list = app.run("window.toolbar.list", json!({})).unwrap();
|
||||
let blank = |name: &str| json!({"name": name, "shown": true, "double": false, "slots": [], "commands": [], "floating": true, "side": "left", "order": null});
|
||||
let blank = |name: &str| json!({"name": name, "shown": true, "double": false, "slots": [], "commands": [], "labels": {}, "floating": true, "side": "left", "order": null});
|
||||
assert_eq!(list, json!([blank("Mine"), blank("Toolbar 1")]));
|
||||
}
|
||||
|
||||
@@ -2605,6 +2773,7 @@ mod tests {
|
||||
.map(|id| crate::state::FloatingFlyout { tools: vec![id.to_string(), "curvature".into()], pos: [0.0, 0.0] })
|
||||
.collect(),
|
||||
commands: vec![],
|
||||
labels: Default::default(),
|
||||
};
|
||||
let long = "x".repeat(MAX_NAME + 1);
|
||||
let mut bars = vec![
|
||||
|
||||
@@ -346,6 +346,7 @@ registry! {
|
||||
Workspaces: ["newWorkspace", "manageWorkspaces"] => DialogSpec::window(crate::workspaces::show, |app, _| crate::workspaces::confirm(app)),
|
||||
NewToolbar: [crate::custom_toolbars::KIND] => DialogSpec::window(crate::custom_toolbars::show_dialog, |app, _| crate::custom_toolbars::confirm(app)),
|
||||
ManageToolbars: [crate::custom_toolbars::MANAGE] => DialogSpec::window(crate::custom_toolbars::show_manage, |app, _| crate::custom_toolbars::confirm_manage(app)),
|
||||
RenameToolbarButton: [crate::custom_toolbars::RENAME] => DialogSpec::window(crate::custom_toolbars::show_rename, |app, _| crate::custom_toolbars::confirm_rename(app)),
|
||||
FindFont: ["findFont"] => DialogSpec::window(crate::find_font::show, |app, _| crate::find_font::confirm(app)),
|
||||
SwatchOptions: [swatch_options::KIND] => swatch_options::SPEC,
|
||||
Confirm: [confirm::KIND] => confirm::SPEC,
|
||||
|
||||
@@ -308,6 +308,7 @@ pub(crate) fn command(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<R
|
||||
// command buttons too.
|
||||
if let Some(bar) = crate::custom_toolbars::find_mut(&mut app.ui, &name) {
|
||||
bar.commands.clear();
|
||||
bar.labels.clear();
|
||||
}
|
||||
return edit_custom(app, &name, |cats| {
|
||||
cats.clear();
|
||||
|
||||
@@ -668,7 +668,7 @@ fn the_add_tool_menu_fills_a_new_toolbar_without_a_drag() {
|
||||
let list = app.run("window.toolbar.list", json!({})).unwrap();
|
||||
assert_eq!(
|
||||
list,
|
||||
json!([{"name": "Mine", "shown": true, "double": false, "slots": [["lasso"]], "commands": [], "floating": true, "side": "left", "order": null}])
|
||||
json!([{"name": "Mine", "shown": true, "double": false, "slots": [["lasso"]], "commands": [], "labels": {}, "floating": true, "side": "left", "order": null}])
|
||||
);
|
||||
// A second tool goes after the first.
|
||||
let shown = open(&mut app, 19.0);
|
||||
@@ -1129,3 +1129,168 @@ fn command_buttons_ask_whether_they_can_run_a_few_at_a_time() {
|
||||
}
|
||||
assert_eq!(crate::custom_toolbars::asked(&ctx), (ids.len(), false), "every button was asked in the next frames");
|
||||
}
|
||||
|
||||
/// The labels given to the command buttons of the toolbar called Mine.
|
||||
fn mine_labels(app: &VectorcraftApp) -> std::collections::BTreeMap<String, String> {
|
||||
crate::custom_toolbars::find(&app.ui, "Mine").unwrap().labels.clone()
|
||||
}
|
||||
|
||||
/// `toolbar.renameCommand` gives a command button a label of its own, an empty label gives it back
|
||||
/// its command's, and a bad call changes nothing. `toolbar.addCommand` takes the label too. A move
|
||||
/// and Manage Toolbars' copy keep it, Remove and Reset drop it, and the preferences keep it while a
|
||||
/// toolbar saved without labels loads unchanged.
|
||||
#[test]
|
||||
fn a_command_button_takes_a_label_of_its_own() {
|
||||
let mut app = app();
|
||||
app.run("window.toolbar.new", json!({"name": "Mine"})).unwrap();
|
||||
app.run("toolbar.addCommand", json!({"command": "object.group", "toolbar": "Mine"})).unwrap();
|
||||
let done = app.run("toolbar.renameCommand", json!({"command": "object.group", "toolbar": "Mine", "label": " Grp "})).unwrap();
|
||||
assert_eq!(done, json!({"command": "object.group", "label": "Grp"}), "spaces at the ends are dropped");
|
||||
let list = app.run("window.toolbar.list", json!({})).unwrap();
|
||||
assert_eq!(list[0]["labels"], json!({"object.group": "Grp"}), "listed");
|
||||
let long = "x".repeat(65);
|
||||
for (p, why) in [
|
||||
(json!({"command": "object.group", "toolbar": "Mine", "label": long}), "a label past the limit"),
|
||||
(json!({"command": "object.group", "toolbar": "Mine", "label": 3}), "a label that is not text"),
|
||||
(json!({"command": "object.ungroup", "toolbar": "Mine", "label": "U"}), "a button the toolbar does not have"),
|
||||
(json!({"command": "object.group", "label": "G"}), "no toolbar"),
|
||||
(json!({"toolbar": "Mine", "label": "G"}), "no command"),
|
||||
] {
|
||||
assert!(app.run("toolbar.renameCommand", p.clone()).is_err(), "{why}: {p}");
|
||||
assert_eq!(mine_labels(&app).get("object.group").map(String::as_str), Some("Grp"), "{why} changes nothing");
|
||||
}
|
||||
for p in [
|
||||
json!({"command": "object.path.cleanUp", "toolbar": "Mine", "label": "x".repeat(65)}),
|
||||
json!({"command": "object.path.cleanUp", "toolbar": "Mine", "label": false}),
|
||||
] {
|
||||
assert!(app.run("toolbar.addCommand", p.clone()).is_err(), "{p}");
|
||||
assert_eq!(mine_commands(&app), ["object.group"], "a bad label adds nothing: {p}");
|
||||
}
|
||||
app.run("toolbar.addCommand", json!({"command": "object.path.cleanUp", "toolbar": "Mine", "at": 0, "label": "Tidy"})).unwrap();
|
||||
app.run("toolbar.addCommand", json!({"command": "object.group", "toolbar": "Mine", "at": 0})).unwrap();
|
||||
assert_eq!(mine_commands(&app), ["object.group", "object.path.cleanUp"]);
|
||||
let both =
|
||||
std::collections::BTreeMap::from([("object.group".to_string(), "Grp".to_string()), ("object.path.cleanUp".to_string(), "Tidy".to_string())]);
|
||||
assert_eq!(mine_labels(&app), both, "a move keeps the label");
|
||||
app.run("toolbar.addCommand", json!({"command": "object.path.cleanUp", "toolbar": "Mine", "label": "Clear"})).unwrap();
|
||||
app.run("toolbar.addCommand", json!({"command": "object.path.cleanUp", "toolbar": "Mine", "label": ""})).unwrap();
|
||||
assert!(!mine_labels(&app).contains_key("object.path.cleanUp"), "an empty label on addCommand gives back the command's");
|
||||
app.run("toolbar.addCommand", json!({"command": "object.path.cleanUp", "toolbar": "Mine", "label": "Tidy"})).unwrap();
|
||||
assert_eq!(mine_labels(&app), both);
|
||||
// Kept with the preferences; an older toolbar without labels loads with none.
|
||||
let kept = app.ui.custom_toolbars.clone();
|
||||
let prefs: crate::state::UiState = serde_json::from_slice(&serde_json::to_vec(&app.ui).unwrap()).unwrap();
|
||||
assert_eq!(prefs.sanitized().custom_toolbars, kept, "kept with the preferences");
|
||||
let mut old = serde_json::to_value(&kept[0]).unwrap();
|
||||
old.as_object_mut().unwrap().remove("labels");
|
||||
let old: crate::state::CustomToolbar = serde_json::from_value(old).unwrap();
|
||||
assert!(old.labels.is_empty() && old.commands == kept[0].commands, "an older toolbar loads with its buttons and no labels");
|
||||
let copy = app.run("window.toolbar.duplicate", json!({"name": "Mine"})).unwrap();
|
||||
let copy = copy["toolbar"].as_str().unwrap().to_string();
|
||||
assert_eq!(crate::custom_toolbars::find(&app.ui, ©).unwrap().labels, both, "the copy has them");
|
||||
// An empty label gives back the command's own.
|
||||
let done = app.run("toolbar.renameCommand", json!({"command": "object.group", "toolbar": "Mine", "label": " "})).unwrap();
|
||||
assert_eq!(done, json!({"command": "object.group", "label": null}));
|
||||
assert!(!mine_labels(&app).contains_key("object.group"));
|
||||
// Removing the button drops its label, so adding it again shows the command's label.
|
||||
app.run("toolbar.removeCommand", json!({"command": "object.path.cleanUp", "toolbar": "Mine"})).unwrap();
|
||||
app.run("toolbar.addCommand", json!({"command": "object.path.cleanUp", "toolbar": "Mine"})).unwrap();
|
||||
assert!(mine_labels(&app).is_empty(), "removed with its button");
|
||||
app.run("toolbar.renameCommand", json!({"command": "object.group", "toolbar": "Mine", "label": "G"})).unwrap();
|
||||
app.run("toolbar.reset", json!({"toolbar": "Mine"})).unwrap();
|
||||
assert!(mine_labels(&app).is_empty(), "Reset drops the labels");
|
||||
assert_eq!(crate::custom_toolbars::find(&app.ui, ©).unwrap().labels, both, "the copy keeps its own");
|
||||
}
|
||||
|
||||
/// Loading drops the spaces at a label's ends, and drops a label whose button the toolbar does not
|
||||
/// have, one past the limit and an empty one.
|
||||
#[test]
|
||||
fn labels_load_sanitized() {
|
||||
let mut app = app();
|
||||
app.run("window.toolbar.new", json!({"name": "Mine"})).unwrap();
|
||||
app.run("toolbar.addCommand", json!({"command": "object.group", "toolbar": "Mine"})).unwrap();
|
||||
app.run("toolbar.addCommand", json!({"command": "object.ungroup", "toolbar": "Mine"})).unwrap();
|
||||
let bar = crate::custom_toolbars::find_mut(&mut app.ui, "Mine").unwrap();
|
||||
bar.labels.insert("object.group".into(), " Grp ".into());
|
||||
bar.labels.insert("object.ungroup".into(), "x".repeat(65));
|
||||
bar.labels.insert("object.path.cleanUp".into(), "Tidy".into());
|
||||
bar.commands.push("edit.selectAll".into());
|
||||
bar.labels.insert("edit.selectAll".into(), String::new());
|
||||
let loaded = app.ui.clone().sanitized();
|
||||
let bar = loaded.custom_toolbars.iter().find(|b| b.name == "Mine").unwrap();
|
||||
assert_eq!(bar.labels, std::collections::BTreeMap::from([("object.group".to_string(), "Grp".to_string())]));
|
||||
}
|
||||
|
||||
/// A button with a label of its own shows that label, while its hover text still shows the
|
||||
/// command's name and shortcut, and a screen reader says the label and then the command's name.
|
||||
/// Control characters and characters that change the text's direction show as escapes.
|
||||
#[test]
|
||||
fn a_renamed_button_shows_its_label_and_keeps_the_command_name() {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_testkit::fixtures::Fixture::Multi.session(), Default::default());
|
||||
let ctx = ctx();
|
||||
app.run("window.toolbar.new", json!({"name": "Mine"})).unwrap();
|
||||
app.run("toolbar.addCommand", json!({"command": "object.group", "toolbar": "Mine", "label": "Grp"})).unwrap();
|
||||
app.run("toolbar.addCommand", json!({"command": "object.ungroup", "toolbar": "Mine", "label": "a\u{202E}b"})).unwrap();
|
||||
app.run("toolbar.addCommand", json!({"command": "object.path.cleanUp", "toolbar": "Mine"})).unwrap();
|
||||
let group = crate::palette::button_text(&ctx, false, "object.group").expect("Group's result");
|
||||
let texts = crate::custom_toolbars::button_texts(&app, &ctx, "Mine");
|
||||
let (label, said, tip) = &texts[0];
|
||||
assert_eq!(label, "Grp");
|
||||
assert!(said.starts_with("Grp") && said.contains(&group.name), "the screen reader says the label, then the name: {said}");
|
||||
assert!(tip.starts_with(&group.name) && !tip.contains("Grp"), "the hover shows the command's name: {tip}");
|
||||
if !group.shortcut.is_empty() {
|
||||
assert!(tip.contains(&group.shortcut), "and its shortcut: {tip}");
|
||||
}
|
||||
assert!(!texts[1].0.contains('\u{202E}') && texts[1].0.contains("202E"), "escaped: {:?}", texts[1].0);
|
||||
assert_eq!(texts[2].0, crate::palette::button_text(&ctx, false, "object.path.cleanUp").unwrap().label, "no label: the command's");
|
||||
// Drawn on the toolbar, and named so in the screen-reader tree.
|
||||
ctx.enable_accesskit();
|
||||
frame(&mut app, &ctx, 0.0, vec![]);
|
||||
assert!(on_mine(&mut app, &ctx, 0.1, "Grp").is_some(), "the button shows its label");
|
||||
assert!(on_mine(&mut app, &ctx, 0.2, &group.label).is_none(), "and not the command's");
|
||||
let input = RawInput { time: Some(0.3), screen_rect: Some(Rect::from_min_size(Pos2::ZERO, SCREEN)), ..Default::default() };
|
||||
let out = ctx.run_ui(input, |ui| crate::toolbar::show(&mut app, ui));
|
||||
let nodes = out.platform_output.accesskit_update.map(|u| u.nodes).unwrap_or_default();
|
||||
assert!(nodes.iter().any(|(_, n)| n.label() == Some(said.as_str())), "the tree names it {said}");
|
||||
// A label that is the command's own label is said once; escapes do not cut a label short.
|
||||
app.run("toolbar.renameCommand", json!({"command": "object.group", "toolbar": "Mine", "label": group.label.clone()})).unwrap();
|
||||
let escaped = format!("{}{}", "\u{202E}".repeat(20), "y".repeat(44));
|
||||
app.run("toolbar.renameCommand", json!({"command": "object.ungroup", "toolbar": "Mine", "label": escaped})).unwrap();
|
||||
let texts = crate::custom_toolbars::button_texts(&app, &ctx, "Mine");
|
||||
assert_eq!(texts[0].1, group.label, "said once");
|
||||
assert!(texts[1].0.ends_with(&"y".repeat(44)) && !texts[1].0.contains('…'), "not cut: {:?}", texts[1].0);
|
||||
}
|
||||
|
||||
/// Rename Button… in a command button's context menu opens the Rename Button dialog with the
|
||||
/// button's label, and OK gives the button the label typed.
|
||||
#[test]
|
||||
fn rename_button_in_the_context_menu_renames_it() {
|
||||
let mut app = app();
|
||||
let ctx = ctx();
|
||||
app.run("window.toolbar.new", json!({"name": "Mine"})).unwrap();
|
||||
app.run("toolbar.addCommand", json!({"command": "object.group", "toolbar": "Mine"})).unwrap();
|
||||
frame(&mut app, &ctx, 0.0, vec![]);
|
||||
let group = crate::palette::button_text(&ctx, false, "object.group").expect("Group's result").label;
|
||||
let (at, _) = on_mine(&mut app, &ctx, 0.1, &group).expect("the button");
|
||||
let secondary = |pressed| Event::PointerButton { pos: at, button: PointerButton::Secondary, pressed, modifiers: Default::default() };
|
||||
frame(&mut app, &ctx, 1.0, vec![Event::PointerMoved(at), secondary(true)]);
|
||||
frame(&mut app, &ctx, 1.05, vec![secondary(false)]);
|
||||
let shown = frame(&mut app, &ctx, 1.1, vec![]);
|
||||
let item = shown.iter().find(|(s, ..)| s.trim() == "Rename Button…").map(|(_, p, _)| *p).expect("Rename Button… in the context menu");
|
||||
click(&mut app, &ctx, 2.0, item);
|
||||
let d = app.ui.dialog.clone().expect("the dialog opens");
|
||||
assert_eq!(d.kind, crate::custom_toolbars::RENAME);
|
||||
assert_eq!((d.str("toolbar"), d.str("command"), d.str("label")), ("Mine".into(), "object.group".into(), String::new()));
|
||||
app.ui.dialog.as_mut().unwrap().fields.insert("label".into(), json!("Grp"));
|
||||
crate::custom_toolbars::confirm_rename(&mut app).unwrap();
|
||||
assert!(app.ui.dialog.is_none(), "OK closes it");
|
||||
assert_eq!(mine_labels(&app).get("object.group").map(String::as_str), Some("Grp"));
|
||||
// Opened again, it shows the label; a label past the limit is refused and the dialog stays.
|
||||
app.run("toolbar.renameCommand", json!({"command": "object.group", "toolbar": "Mine"})).unwrap();
|
||||
assert_eq!(app.ui.dialog.as_ref().map(|d| d.str("label")).as_deref(), Some("Grp"));
|
||||
app.ui.dialog.as_mut().unwrap().fields.insert("label".into(), json!("x".repeat(65)));
|
||||
assert!(crate::custom_toolbars::confirm_rename(&mut app).is_err());
|
||||
assert!(app.ui.dialog.is_some(), "the dialog stays open");
|
||||
assert_eq!(mine_labels(&app).get("object.group").map(String::as_str), Some("Grp"), "unchanged");
|
||||
assert!(app.run("toolbar.renameCommand", json!({"command": "object.ungroup", "toolbar": "Mine"})).is_err(), "no such button");
|
||||
}
|
||||
@@ -618,13 +618,19 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"toolbar.addCommand",
|
||||
"Toolbar: Add Command",
|
||||
"",
|
||||
"{command: id, toolbar: name, at?: n} put a button for `command` (a Command Palette result other than a tool: a command's id, or `plugin:<id>`, `effect:<id>` or `panel:<id>`) on the toolbar made with New Toolbar called `toolbar`, after its tools, moving it if it is there already: at place `at` among its command buttons (0 = the first; omitted: at the end), as Add Command in its Add Tool… menu and Move Up and Move Down in the button's context menu do; a click on the button runs what the command's menu item runs; an unknown command, a tool, a command that needs params a click does not give (such as this one) or an `at` past the end is an error and changes nothing; kept with the workspace; returns the toolbar's commands",
|
||||
"{command: id, toolbar: name, at?: n, label?: text} put a button for `command` (a Command Palette result other than a tool: a command's id, or `plugin:<id>`, `effect:<id>` or `panel:<id>`) on the toolbar made with New Toolbar called `toolbar`, after its tools, moving it if it is there already: at place `at` among its command buttons (0 = the first; omitted: at the end), as Add Command in its Add Tool… menu and Move Up and Move Down in the button's context menu do; with `label`, the button shows that label, as toolbar.renameCommand gives it (an empty `label` gives it the command's own label again); a click on the button runs what the command's menu item runs; an unknown command, a tool, a command that needs params a click does not give (such as this one), an `at` past the end, or a `label` that is not text or is longer than 64 characters is an error and changes nothing; kept with the workspace; returns the toolbar's commands",
|
||||
),
|
||||
(
|
||||
"toolbar.removeCommand",
|
||||
"Toolbar: Remove Command",
|
||||
"",
|
||||
"{command: id, toolbar: name} take the button for `command` off the toolbar made with New Toolbar called `toolbar` (one not on it stays off; a command that is no longer installed can be taken off too), as Remove Command in its Add Tool… menu and Remove from Toolbar in the button's context menu do; returns the toolbar's commands",
|
||||
"{command: id, toolbar: name} take the button for `command` off the toolbar made with New Toolbar called `toolbar`, with its own label (one not on it stays off; a command that is no longer installed can be taken off too), as Remove Command in its Add Tool… menu and Remove from Toolbar in the button's context menu do; returns the toolbar's commands",
|
||||
),
|
||||
(
|
||||
"toolbar.renameCommand",
|
||||
"Toolbar: Rename Button",
|
||||
"",
|
||||
"{command: id, toolbar: name, label?: text} give the button for `command` on the toolbar made with New Toolbar called `toolbar` the label `label` (spaces at its ends dropped, at most 64 characters; empty: the command's own label again), as Rename Button… in the button's context menu does; without `label`, opens the Rename Button dialog and returns null; the hover text still shows the command's name and shortcut, and a screen reader says the label and then the command's name; a button the toolbar does not have, or a label that is not text or is longer, is an error and changes nothing; kept with the workspace; returns {command, label} (`label` null for the command's own)",
|
||||
),
|
||||
(
|
||||
"toolbar.reset",
|
||||
@@ -684,7 +690,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"window.toolbar.list",
|
||||
"List Toolbars",
|
||||
"",
|
||||
"{} the toolbars made with New Toolbar in the current workspace: [{name, shown, double, slots, commands, floating, side, order}], `commands` the Command Palette results of its command buttons, `side` the edge it docks at (while floating, the edge it docked at last) and `order` its place in that edge's stack while docked (else null)",
|
||||
"{} the toolbars made with New Toolbar in the current workspace: [{name, shown, double, slots, commands, labels, floating, side, order}], `commands` the Command Palette results of its command buttons, `labels` the labels given to them with Rename Button… ({command: label}), `side` the edge it docks at (while floating, the edge it docked at last) and `order` its place in that edge's stack while docked (else null)",
|
||||
),
|
||||
("window.taskBar", "Contextual Task Bar", "", "{}"),
|
||||
(
|
||||
|
||||
@@ -4081,6 +4081,7 @@ mod tests {
|
||||
double: false,
|
||||
floating: vec![],
|
||||
commands: vec![],
|
||||
labels: Default::default(),
|
||||
};
|
||||
// Window › Tools hides the Tools panel while a toolbar made with New Toolbar holds the Pen
|
||||
// Tool: the row names that toolbar.
|
||||
@@ -5367,6 +5368,7 @@ mod tests {
|
||||
double: false,
|
||||
floating: vec![],
|
||||
commands: vec![],
|
||||
labels: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1092,6 +1092,10 @@ pub struct CustomToolbar {
|
||||
/// plug-in's, is kept and shows as unavailable until it comes back.
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub commands: Vec<String>,
|
||||
/// The labels given to its command buttons with Rename Button…, keyed by the command's id. A
|
||||
/// button without one shows its command's label.
|
||||
#[serde(default, skip_serializing_if = "std::collections::BTreeMap::is_empty")]
|
||||
pub labels: std::collections::BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
/// A category of an edited toolbar: its name (one of the Basic toolbar's; none in the Advanced
|
||||
|
||||
@@ -488,9 +488,17 @@ menu, Remove from Toolbar in the context menu). `command` is a palette result's
|
||||
button is dimmed while that item is. An unknown command, a tool, a command that needs params a click does not give
|
||||
(`toolbar.addTool`), a place past the end or a missing `toolbar` is an error and changes nothing. A command that is
|
||||
no longer installed keeps its button, dimmed, and `toolbar.removeCommand` still takes it off.
|
||||
`toolbar.renameCommand {command, toolbar, label?}` (Rename Button… in the button's context menu, which opens a
|
||||
dialog; without `label` the command opens that dialog and returns null) gives a button a label of its own, and
|
||||
`toolbar.addCommand` takes the same optional `label`. The label loses the spaces at its ends and has at most 64
|
||||
characters; an empty one, on either command, gives the button its command's label again. The hover text still shows
|
||||
the command's name and shortcut, and a screen reader says the label and then the command's name. A longer label, a
|
||||
label that is not text or a button the toolbar does not have is an error and changes nothing. `toolbar.removeCommand`
|
||||
and `toolbar.reset` drop a button's label with it.
|
||||
`window.floatTools {tool, toolbar}` floats one of its groups, and a group torn off it shows and hides with it.
|
||||
`window.toolbar.list` returns the toolbars (`ui.custom_toolbars` in `ui.inspect`: name, slots, commands, shown flag,
|
||||
two-column flag, top-left corner, the groups torn off it, and `dock` and `dock_right` while docked or once docked).
|
||||
`window.toolbar.list` returns the toolbars (`ui.custom_toolbars` in `ui.inspect`: name, slots, commands, labels,
|
||||
shown flag, two-column flag, top-left corner, the groups torn off it, and `dock` and `dock_right` while docked or once
|
||||
docked).
|
||||
`window.toolbar.dock {name, side?, order?}` docks a toolbar in the lane along the window's left or right edge, and
|
||||
`window.toolbar.float {name, x?, y?}` floats it again; dropping its title bar on an edge or dragging it out of its
|
||||
lane does the same (see the docking section in `docs/mcp.md`). They are kept with the workspace they were made in:
|
||||
|
||||
+12
@@ -3694,8 +3694,20 @@ installed again or removed. `toolbar.reset {toolbar}` takes the buttons off with
|
||||
the workspace, and toolbars saved before command buttons existed load without any. Command buttons are VectorCraft's
|
||||
own.
|
||||
|
||||
`toolbar.renameCommand {command, toolbar, label?}` (Rename Button… in the button's context menu) gives a button a
|
||||
label of its own, and `toolbar.addCommand` takes the same optional `label`. Spaces at the ends of the label are
|
||||
dropped, and it has at most 64 characters; an empty label, on either command, gives the button its command's label
|
||||
again. Without `label`, `toolbar.renameCommand` opens the Rename Button dialog and answers null. Otherwise it answers
|
||||
`{command, label}`, with `label` null for the command's own, and `window.toolbar.list` reports `labels`
|
||||
({command: label}) for each toolbar. The hover text still shows the command's name and shortcut, and a screen reader
|
||||
says the label and then the command's name, or only the label when it is the command's label or name. Control
|
||||
characters and characters that change the direction of text show as `\u{…}` escapes on the button. A longer label, a
|
||||
label that is not text or a button the toolbar does not have is an error and changes nothing. Labels are kept with the
|
||||
toolbar, Manage Toolbars' copy keeps them, and `toolbar.removeCommand` and `toolbar.reset` drop them with the buttons.
|
||||
|
||||
```json
|
||||
{"name":"invoke_menu","arguments":{"command":"toolbar.addCommand","params":{"command":"object.group","toolbar":"Toolbar 1"}}}
|
||||
{"name":"invoke_menu","arguments":{"command":"toolbar.renameCommand","params":{"command":"object.group","toolbar":"Toolbar 1","label":"Grp"}}}
|
||||
```
|
||||
|
||||
## Help search
|
||||
|
||||
@@ -1132,7 +1132,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- The dock's double arrow collapses Properties, Layers and Libraries to icons at the top of the icon column, popping out like the other icon panels, and expands them again (`window.collapseDock`, kept with the preferences and in saved workspaces). The icon column's own arrow (expanding the icon panels into a full column) is not done.
|
||||
- Window › Toolbars › New Toolbar… and New Toolbar… in the All Tools drawer's menu ask for a name and make a blank toolbar that floats on its own, moved by its title bar and listed under Window › Toolbars, whose item shows or hides it. The title bar's × hides it, and its double arrow shows its tools in one column or two. Its ••• button opens the All Tools drawer beside it, and tools dragged from the drawer fill it. The toolbars are kept with the workspace they were made in: switching workspaces shows that workspace's toolbars, Reset Workspace keeps them, and New Workspace starts the new workspace with a copy of them (<https://helpx.adobe.com/illustrator/using/tools.html>; `window.toolbar.new`, `window.toolbar.custom`, the `toolbar` param of `window.editToolbar` and `toolbar.addTool`/`removeTool`/`reset`; `tools_added_to_a_new_toolbar_survive_a_workspace_reload`).
|
||||
- A toolbar made with New Toolbar has a + button (Add Tool…) above its ••• button. A click on it, or Enter while it has the keyboard focus, opens a menu of every tool under the All Tools drawer's headings, without the drawer: a tool picked there goes at the end of that toolbar, and the tools already in it are dimmed. Under Remove Tool, the menu lists the toolbar's tools, and a click takes one out. This menu is VectorCraft's own way to fill a toolbar without a drag (`toolbar.addTool` and `toolbar.removeTool` with `toolbar`; `the_add_tool_menu_fills_a_new_toolbar_without_a_drag`).
|
||||
- A toolbar made with New Toolbar also holds command buttons, after its tools. The Add Command submenu at the end of its Add Tool… menu searches every Command Palette result other than a tool (menu commands, plug-in commands, effects and panels), and a pick adds a button at the end; Remove Command in the same menu lists the buttons and takes one off. A button shows its command's label without the ellipsis, on up to two lines, and its full name and shortcut on hover. A click runs what the command's menu item runs, so a command whose item ends in … opens its dialog. While that item is dimmed the button is dimmed and runs nothing. The button's context menu has Move Up, Move Down and Remove from Toolbar. The buttons are kept with the toolbar in the workspace, Manage Toolbars' copy keeps them, and a toolbar saved without them loads unchanged. A command that is gone, such as an uninstalled plug-in's, keeps its button, dimmed and labeled with its id, until it comes back or is removed. Not done: dragging a menu item or a Command Palette result onto a toolbar, an Add to Toolbar item in the palette, dragging command buttons to reorder or remove them, and command icons (a button shows its label). Command buttons are VectorCraft's own (`toolbar.addCommand`, `toolbar.removeCommand`; `command_buttons_are_added_moved_and_removed_by_their_commands`, `a_command_button_runs_its_command_and_is_dimmed_while_it_cannot`, `a_missing_command_stays_dimmed_until_it_is_removed`, `a_plugin_command_button_works_again_when_the_plugin_returns`, `a_panel_button_shows_its_panel`, `command_buttons_ask_whether_they_can_run_a_few_at_a_time`, `the_add_tool_menu_adds_and_removes_commands`).
|
||||
- A toolbar made with New Toolbar also holds command buttons, after its tools. The Add Command submenu at the end of its Add Tool… menu searches every Command Palette result other than a tool (menu commands, plug-in commands, effects and panels), and a pick adds a button at the end; Remove Command in the same menu lists the buttons and takes one off. A button shows its command's label without the ellipsis, on up to two lines, and its full name and shortcut on hover. A click runs what the command's menu item runs, so a command whose item ends in … opens its dialog. While that item is dimmed the button is dimmed and runs nothing. The button's context menu has Move Up, Move Down, Rename Button… and Remove from Toolbar. Rename Button… gives the button a label of its own, at most 64 characters (empty: the command's label again), while its hover text keeps the command's name and shortcut and a screen reader says the label and then the command's name (`toolbar.renameCommand`, and `label` on `toolbar.addCommand`; `a_command_button_takes_a_label_of_its_own`, `labels_load_sanitized`, `a_renamed_button_shows_its_label_and_keeps_the_command_name`, `rename_button_in_the_context_menu_renames_it`). The buttons are kept with the toolbar in the workspace, Manage Toolbars' copy keeps them, and a toolbar saved without them loads unchanged. A command that is gone, such as an uninstalled plug-in's, keeps its button, dimmed and labeled with its id, until it comes back or is removed. Not done: dragging a menu item or a Command Palette result onto a toolbar, an Add to Toolbar item in the palette, dragging command buttons to reorder or remove them, and command icons (a button shows its label). Command buttons are VectorCraft's own (`toolbar.addCommand`, `toolbar.removeCommand`; `command_buttons_are_added_moved_and_removed_by_their_commands`, `a_command_button_runs_its_command_and_is_dimmed_while_it_cannot`, `a_missing_command_stays_dimmed_until_it_is_removed`, `a_plugin_command_button_works_again_when_the_plugin_returns`, `a_panel_button_shows_its_panel`, `command_buttons_ask_whether_they_can_run_a_few_at_a_time`, `the_add_tool_menu_adds_and_removes_commands`).
|
||||
- Window › Toolbars › Manage Toolbars… and Manage Toolbars… in the All Tools drawer's menu open a dialog that lists the toolbars made with New Toolbar: a new name typed for the selected toolbar renames it, + copies it with its tools (with none selected, + makes a blank toolbar), and the trash can deletes it. Each change shows under Window › Toolbars and stays in the workspace (<https://helpx.adobe.com/illustrator/using/tools.html>; `window.toolbar.manage`, `window.toolbar.rename`, `window.toolbar.duplicate`, `window.toolbar.delete`; `manage_toolbars_renames_duplicates_and_deletes`).
|
||||
- In the All Tools drawer a tool the toolbar holds is drawn throughout — name, shortcut and icon — in the dim text colour, one step dimmer than a tool not in it, so it still reads as in the toolbar while its name stays readable against the panel; the disabled colour it was drawn in before was about 2.6:1 on the panel, unreadable at the drawer's 12.5 px (#8294; `tools_in_the_toolbar_are_dimmed_in_the_drawer` in `crates/ui-egui/src/edit_toolbar/tests.rs`, which asserts the painted colour's contrast). The dimming is VectorCraft's own (#1018).
|
||||
- A toolbar made with New Toolbar docks in a lane along the window's left or right edge when its title bar is dropped on that edge, or with Dock to Left and Dock to Right in the title bar's context menu. Toolbars docked at one edge stack from the top, each with its share of the lane's height, and the lane is as wide as its widest toolbar; a lane too short for its stack wraps it into more columns, up to half the window's width, and past that the toolbars show only their title bars, which the mouse wheel scrolls through when even they do not fit. Dragging the title bar out of the lane, or Float Toolbar, floats it again, and Escape during the drag puts it back. Hiding and renaming keep its place, and the workspace keeps it. New toolbars still start floating. The lanes and the stacking are VectorCraft's own rules (#1759; `window.toolbar.dock`, `window.toolbar.float`; `toolbars_dock_and_float_by_their_commands`, `docked_toolbars_stack_in_lanes_along_the_window_edges`, `a_title_bar_dropped_on_an_edge_docks_the_toolbar`).
|
||||
|
||||
Reference in new issue
Block a user