mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-29 01:34:29 +01:00
Toolbars: a toolbar made with New Toolbar holds menu command buttons
A toolbar made with Window > Toolbars > New Toolbar held tools only. Its
Add Tool... menu now ends in an Add Command submenu that searches every
Command Palette result other than a tool (menu commands, plug-in
commands, effects and panels); a pick adds a button after the tools, and
Remove Command in the same menu lists the buttons by their full names
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 an ellipsis
opens its dialog; while the item is dimmed, the button is dimmed and a
click runs nothing and the status line says why.
- Each command is asked whether it can run once per app state, at most
12 in a frame, and again on a click or a key press.
- The button's context menu has Move Up, Move Down and Remove from
Toolbar.
- The buttons are saved with the toolbar (`commands`, left out when
empty, so older layouts load unchanged), and Manage Toolbars' copy keeps
them. 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.
- `toolbar.addCommand {command, toolbar, at?}` adds or moves a button,
`toolbar.removeCommand {command, toolbar}` takes one off, and
`window.toolbar.list` reports `commands`. `toolbar.reset` with
`toolbar` clears them along with the tools. A UI command that fails
without params, such as `toolbar.addTool`, is not listed and cannot be
added.
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. Command buttons are
VectorCraft's own.
Docs: docs/control-protocol.md, docs/mcp.md, docs/target-app-parity.md.
This commit is contained in:
1 parent
db9acab4da
commit
add7c0f48b
12 files changed
+748
-21
No files matched your search
@@ -613,6 +613,18 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"",
|
||||
"{tool: id, group?: bool, toolbar?: name} take `tool` (with `group`, its whole group) out of the current toolbar (with `toolbar`, out of that toolbar made with New Toolbar; one not in it stays out), as dragging it into the Edit Toolbar drawer does; returns the toolbar's slots",
|
||||
),
|
||||
(
|
||||
"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",
|
||||
),
|
||||
(
|
||||
"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",
|
||||
),
|
||||
(
|
||||
"toolbar.reset",
|
||||
"Toolbar: Reset",
|
||||
@@ -671,7 +683,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, floating, side, order}], `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, 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)",
|
||||
),
|
||||
("window.taskBar", "Contextual Task Bar", "", "{}"),
|
||||
(
|
||||
|
||||
@@ -3,9 +3,12 @@
|
||||
//! All Tools drawer beside it, and tools dragged from the drawer fill it (`edit_toolbar`, with the
|
||||
//! `toolbar` param of its commands). The + button above it opens Add Tool…, a menu of every tool
|
||||
//! 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. 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`).
|
||||
//! 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.
|
||||
//! 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`).
|
||||
//! Window › Toolbars › Manage Toolbars (also in the drawer's menu) renames, copies and deletes them.
|
||||
//!
|
||||
//! A toolbar docks in a lane along the window's left or right edge (on the left, right of the Tools
|
||||
@@ -42,6 +45,8 @@ use crate::{VectorcraftApp, icons, widgets};
|
||||
pub(crate) const MAX: usize = 64;
|
||||
/// The most characters a toolbar's name has.
|
||||
const MAX_NAME: usize = 200;
|
||||
/// The most command buttons a toolbar holds.
|
||||
const MAX_COMMANDS: usize = 200;
|
||||
/// 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.
|
||||
@@ -129,6 +134,7 @@ pub(crate) fn create(ui: &mut UiState, name: &str) -> Result<String, String> {
|
||||
slot_tool: Default::default(),
|
||||
double: false,
|
||||
floating: vec![],
|
||||
commands: vec![],
|
||||
});
|
||||
show_alone_after_tab(ui, name);
|
||||
Ok(name.to_string())
|
||||
@@ -333,8 +339,10 @@ pub(crate) fn delete(ui: &mut UiState, ctx: Option<&egui::Context>, name: &str)
|
||||
|
||||
/// Keep named toolbars, each name once whatever its case and at most [`MAX_NAME`] characters, of
|
||||
/// known tools, each once in its toolbar, at a position that is a number, with one strip per group
|
||||
/// torn off them, each group's tool chosen last only when the group holds it, and the docked ones
|
||||
/// numbered 0, 1, 2… at each edge (a hand-edited preferences file or workspace).
|
||||
/// 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.
|
||||
pub(crate) fn sanitize(bars: &mut Vec<CustomToolbar>) {
|
||||
let mut names = std::collections::BTreeSet::new();
|
||||
bars.retain_mut(|b| {
|
||||
@@ -344,6 +352,9 @@ pub(crate) fn sanitize(bars: &mut Vec<CustomToolbar>) {
|
||||
s.retain(|id| tool_info(id).is_some() && seen.insert(id.clone()));
|
||||
}
|
||||
b.slots.retain(|s| !s.is_empty());
|
||||
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 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);
|
||||
@@ -371,6 +382,41 @@ 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.
|
||||
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)
|
||||
}
|
||||
|
||||
/// Put the command button for the Command Palette result `id` in `bar`, moving it if it is there
|
||||
/// already: at place `at` among its command buttons (0 = the first; none: at the end). A command
|
||||
/// that is gone (an uninstalled plug-in's) can still move, but not be added. A tool, and a UI
|
||||
/// command that fails without params, can't be added.
|
||||
pub(crate) fn add_command(bar: &mut CustomToolbar, id: &str, at: Option<usize>) -> Result<(), String> {
|
||||
if id.starts_with("tool:") {
|
||||
return Err(format!("`{id}` is a tool: toolbar.addTool adds tools"));
|
||||
}
|
||||
if crate::shortcut_editor::ui_command_needs_params(id) {
|
||||
return Err(format!("`{id}` needs params, which a click on a button does not give"));
|
||||
}
|
||||
if !bar.commands.iter().any(|c| c == id) && !crate::palette::is_command(id) {
|
||||
return Err(format!("unknown command `{id}`"));
|
||||
}
|
||||
let mut list: Vec<String> = bar.commands.iter().filter(|c| *c != id).cloned().collect();
|
||||
if list.len() >= MAX_COMMANDS {
|
||||
return Err(format!("a toolbar holds at most {MAX_COMMANDS} commands"));
|
||||
}
|
||||
let at = match at {
|
||||
None => list.len(),
|
||||
Some(n) if n <= list.len() => n,
|
||||
Some(n) => return Err(format!("`at` must be a whole number from 0 to {} (got {n})", list.len())),
|
||||
};
|
||||
list.insert(at, id.to_string());
|
||||
bar.commands = list;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
@@ -464,13 +510,30 @@ pub(crate) fn command(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<R
|
||||
renumber(&mut app.ui.custom_toolbars);
|
||||
app.ui.custom_toolbars.get(k).map(placement).ok_or_else(|| format!("no toolbar named `{name}`"))
|
||||
})(),
|
||||
"toolbar.addCommand" => (|| {
|
||||
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 at = match p.get("at") {
|
||||
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 bar = app.ui.custom_toolbars.get_mut(k).ok_or("no such toolbar")?;
|
||||
add_command(bar, id, at).map(|_| json!(bar.commands))
|
||||
})(),
|
||||
"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);
|
||||
Ok(json!(bar.commands))
|
||||
})(),
|
||||
"window.toolbar.list" => Ok(json!(
|
||||
app.ui
|
||||
.custom_toolbars
|
||||
.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, "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, "floating": b.dock.is_none(), "side": side, "order": b.dock})
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
)),
|
||||
@@ -730,6 +793,130 @@ enum Action {
|
||||
Dock(String, bool),
|
||||
/// Float Toolbar in the title bar's context menu.
|
||||
Float(String),
|
||||
/// A click on a command button: the Command Palette result it runs.
|
||||
RunCommand(String),
|
||||
/// A command picked in the Add Command submenu of Add Tool…'s menu, added at the end of the
|
||||
/// toolbar named.
|
||||
AddCommand(String, String),
|
||||
/// 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),
|
||||
/// 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),
|
||||
}
|
||||
|
||||
/// What a command button shows, worked out before its toolbar is drawn.
|
||||
#[derive(Clone, Debug)]
|
||||
struct CommandLook {
|
||||
/// The Command Palette result it runs.
|
||||
id: String,
|
||||
/// Its label, name and shortcut; none while the palette lists no result with its id (an
|
||||
/// uninstalled plug-in's command).
|
||||
text: Option<crate::palette::ButtonText>,
|
||||
/// Why it can't run now, in English; none while it can.
|
||||
why: Option<String>,
|
||||
}
|
||||
|
||||
impl CommandLook {
|
||||
/// The label the button shows: 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())
|
||||
}
|
||||
|
||||
/// Its full name, with the menu path that tells it apart from a command of the same label, or
|
||||
/// its id while the command is gone.
|
||||
fn name(&self) -> &str {
|
||||
self.text.as_ref().map_or(self.id.as_str(), |t| t.name.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
/// The most commands the toolbars ask in one frame whether they can run. An engine check can take
|
||||
/// tens of milliseconds on a large selection, and during a drag the state changes on every frame.
|
||||
const ASKS_PER_FRAME: usize = 12;
|
||||
|
||||
/// The command buttons' [`crate::palette::unavailable`] answers for the state `key` they were read
|
||||
/// in ([`crate::palette::availability_key`]): each command is asked once per state, and at most
|
||||
/// [`ASKS_PER_FRAME`] are asked in a frame. A command not asked yet in this state shows its answer
|
||||
/// from an earlier state (`stale`), or is dimmed when it has none, and is asked in a later frame.
|
||||
#[derive(Clone, Default)]
|
||||
struct Known {
|
||||
key: u64,
|
||||
why: std::collections::HashMap<String, Option<String>>,
|
||||
stale: std::collections::HashMap<String, Option<String>>,
|
||||
/// How many more commands this frame may ask.
|
||||
budget: usize,
|
||||
/// Is a command still waiting to be asked in this state?
|
||||
pending: bool,
|
||||
}
|
||||
|
||||
impl Known {
|
||||
/// The answers for the state now. The state leaves out a panel shown and a tool chosen, so a
|
||||
/// frame with a pointer button release or a key press asks every command again, as the Command
|
||||
/// Palette asks its results again on a click.
|
||||
fn load(app: &VectorcraftApp, ctx: &egui::Context) -> Known {
|
||||
let key = crate::palette::availability_key(app);
|
||||
let mut known = ctx.data(|d| d.get_temp::<Known>(known_id())).unwrap_or_default();
|
||||
let again = ctx.input(|i| {
|
||||
i.events.iter().any(|e| matches!(e, egui::Event::PointerButton { pressed: false, .. } | egui::Event::Key { pressed: true, .. }))
|
||||
});
|
||||
if known.key != key || again {
|
||||
let old = std::mem::take(&mut known.why);
|
||||
known.stale.extend(old);
|
||||
known.key = key;
|
||||
}
|
||||
known.budget = ASKS_PER_FRAME;
|
||||
known.pending = false;
|
||||
known
|
||||
}
|
||||
|
||||
/// Why the result `id`, shown as `name`, can't run now, in English, or `None` while it can.
|
||||
fn why(&mut self, app: &VectorcraftApp, id: &str, name: &str) -> Option<String> {
|
||||
if let Some(why) = self.why.get(id) {
|
||||
return why.clone();
|
||||
}
|
||||
if self.budget == 0 {
|
||||
// Dimmed until it is asked, unless an earlier state's answer is known.
|
||||
self.pending = true;
|
||||
return self.stale.get(id).cloned().unwrap_or_else(|| Some(format!("checking whether `{id}` can run")));
|
||||
}
|
||||
self.budget -= 1;
|
||||
let why = crate::palette::unavailable(app, id, name);
|
||||
self.stale.remove(id);
|
||||
self.why.insert(id.to_string(), why.clone());
|
||||
why
|
||||
}
|
||||
}
|
||||
|
||||
fn known_id() -> egui::Id {
|
||||
egui::Id::unique("custom-toolbar-command-availability")
|
||||
}
|
||||
|
||||
/// How many commands have their answer for the state now, and is one still waiting to be asked?
|
||||
#[cfg(test)]
|
||||
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))
|
||||
}
|
||||
|
||||
/// 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> {
|
||||
if bar.commands.is_empty() {
|
||||
return vec![];
|
||||
}
|
||||
let known = known.get_or_insert_with(|| Known::load(app, ctx));
|
||||
let native = app.services.native_menu.is_some();
|
||||
bar.commands
|
||||
.iter()
|
||||
.map(|id| {
|
||||
let text = crate::palette::is_command(id).then(|| crate::palette::button_text(ctx, native, id)).flatten();
|
||||
let why = match &text {
|
||||
None => Some(format!("command `{id}` is not available right now")),
|
||||
Some(t) => known.why(app, id, &t.name),
|
||||
};
|
||||
CommandLook { id: id.clone(), text, why }
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The lane along the window's right edge (true) or left edge where docked toolbars show, as last
|
||||
@@ -1001,9 +1188,14 @@ pub(crate) fn show(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
// Where the drawer opens (the toolbar's bounds and its ••• button): beside the toolbar it
|
||||
// edits, or beside the one whose ••• button was just clicked.
|
||||
let (mut anchor, mut clicked_anchor) = (None, None);
|
||||
let mut known = None;
|
||||
let native = app.services.native_menu.is_some();
|
||||
for k in 0..app.ui.custom_toolbars.len() {
|
||||
let Some(bar) = app.ui.custom_toolbars.get(k).filter(|b| b.shown).cloned() else { continue };
|
||||
let id = area_id(&bar.name);
|
||||
let looks = command_looks(app, ctx, &bar, &mut known);
|
||||
// Add Tool…'s menu lists them under Remove Command and searches the commands it can add.
|
||||
ctx.data_mut(|d| d.insert_temp(add_menu_id(&bar.name).with("commands"), (native, looks.clone())));
|
||||
let cols = if bar.double { 2 } else { 1 };
|
||||
let width = WIDTH + BUTTON * (cols - 1) as f32;
|
||||
// Docked: where its lane puts it, its tools scrolling in its share of the lane, or only its
|
||||
@@ -1137,6 +1329,8 @@ pub(crate) fn show(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
}
|
||||
});
|
||||
}
|
||||
// The command buttons, after its tools.
|
||||
command_buttons(ui, &t, width - 6.0, middle, &bar.name, &looks, &mut actions);
|
||||
ui.add_space(4.0);
|
||||
// Add Tool…: a menu of the tools, which adds one to this toolbar or takes one out.
|
||||
let add = ui.vertical_centered(|ui| widgets::icon_button(ui, "plus", "Add Tool…", false, 26.0)).inner;
|
||||
@@ -1182,6 +1376,13 @@ pub(crate) fn show(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(known) = known {
|
||||
// The commands not asked yet are asked in the next frames.
|
||||
if known.pending {
|
||||
ctx.request_repaint();
|
||||
}
|
||||
ctx.data_mut(|d| d.insert_temp(known_id(), known));
|
||||
}
|
||||
if let Some((bounds, button)) = clicked_anchor.or(anchor) {
|
||||
ctx.data_mut(|d| {
|
||||
d.insert_temp(crate::edit_toolbar::toolbar_id(), bounds);
|
||||
@@ -1245,6 +1446,7 @@ 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),
|
||||
}
|
||||
}
|
||||
end_move();
|
||||
@@ -1369,6 +1571,143 @@ pub(crate) fn shown_tool(bar: &CustomToolbar, active: &'static str, tools: &[&'s
|
||||
Some(bar.slot_tool.get(first).and_then(|id| tools.iter().copied().find(|t| t == id)).unwrap_or(first))
|
||||
}
|
||||
|
||||
/// What a press on a command button, its context menu or Add Tool…'s command rows did.
|
||||
fn command_action(app: &mut VectorcraftApp, a: Action) {
|
||||
let done = match a {
|
||||
// It runs what the command's menu item runs, as a pick in the Command Palette does: a
|
||||
// command whose item ends in … opens its dialog, and a dimmed one runs nothing and the
|
||||
// status line says why.
|
||||
Action::RunCommand(id) if crate::palette::is_command(&id) => {
|
||||
crate::palette::run_pick(app, &id);
|
||||
Ok(Value::Null)
|
||||
}
|
||||
Action::RunCommand(id) => Err(format!("command `{id}` is not available right now")),
|
||||
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 })),
|
||||
_ => Ok(Value::Null),
|
||||
};
|
||||
if let Err(e) = done {
|
||||
app.status(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// The command buttons of the toolbar named `bar` (`looks`), one per row across its `width`, with
|
||||
/// `middle` the toolbar's middle: [`command_button`].
|
||||
fn command_buttons(ui: &mut egui::Ui, t: &Tokens, width: f32, middle: f32, bar: &str, looks: &[CommandLook], actions: &mut Vec<Action>) {
|
||||
if looks.is_empty() {
|
||||
return;
|
||||
}
|
||||
ui.add_space(4.0);
|
||||
for (i, look) in looks.iter().enumerate() {
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space((middle - width / 2.0 - ui.cursor().min.x).max(0.0));
|
||||
command_button(ui, t, width, bar, look, (i, looks.len()), actions);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// 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
|
||||
/// 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.
|
||||
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();
|
||||
if resp.hovered() || resp.has_focus() {
|
||||
ui.painter().rect_filled(rect.shrink(1.0), CornerRadius::same(4), t.hover);
|
||||
}
|
||||
let color = if on { t.text } else { t.text_disabled };
|
||||
let font = egui::FontId::proportional(10.0);
|
||||
let mut job = egui::text::LayoutJob::simple(look.label().to_owned(), font, color, rect.width() - 4.0);
|
||||
job.wrap = egui::text::TextWrapping { max_width: rect.width() - 4.0, max_rows: 2, break_anywhere: false, overflow_character: Some('…') };
|
||||
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);
|
||||
if resp.clicked() {
|
||||
actions.push(Action::RunCommand(look.id.clone()));
|
||||
}
|
||||
let (i, n) = place;
|
||||
resp.context_menu(|ui| {
|
||||
if widgets::menu_item(ui, tl!("Move Up"), i > 0, false) {
|
||||
actions.push(Action::MoveCommand(bar.to_string(), look.id.clone(), i.saturating_sub(1)));
|
||||
ui.close();
|
||||
}
|
||||
if widgets::menu_item(ui, tl!("Move Down"), i + 1 < n, false) {
|
||||
actions.push(Action::MoveCommand(bar.to_string(), look.id.clone(), i + 1));
|
||||
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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// The most commands Add Tool…'s menu lists for a search.
|
||||
const COMMAND_RESULTS: usize = 30;
|
||||
|
||||
/// Add Tool…'s command rows, for the toolbar named `bar`: under Remove Command the toolbar's
|
||||
/// command buttons by their full names, which a click takes out, then the Add Command submenu
|
||||
/// ([`command_search`]).
|
||||
fn command_section(ui: &mut egui::Ui, t: &Tokens, bar: &str, actions: &mut Vec<Action>) {
|
||||
let Some((native, looks)) = ui.data(|d| d.get_temp::<(bool, Vec<CommandLook>)>(add_menu_id(bar).with("commands"))) else { return };
|
||||
ui.separator();
|
||||
if !looks.is_empty() {
|
||||
ui.label(egui::RichText::new(crate::i18n::colon(tl!("Remove Command"))).size(12.0).color(t.text_strong));
|
||||
for look in &looks {
|
||||
if widgets::menu_item_name(ui, look.name(), true, false) {
|
||||
actions.push(Action::RemoveCommand(bar.to_string(), look.id.clone()));
|
||||
}
|
||||
}
|
||||
ui.separator();
|
||||
}
|
||||
// A click in the search field leaves the submenu open; a pick closes the whole menu.
|
||||
let config = egui::containers::menu::MenuConfig::new().close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside);
|
||||
egui::containers::menu::SubMenuButton::new(tl!("Add Command")).config(config).ui(ui, |ui| command_search(ui, t, bar, native, &looks, actions));
|
||||
}
|
||||
|
||||
/// The Add Command submenu: a search field over the Command Palette's results other than tools
|
||||
/// (`native`: with the native menu bar), whose first [`COMMAND_RESULTS`] matches a click adds at
|
||||
/// the end of the toolbar named `bar` (dimmed: one of its command buttons, `looks`, already).
|
||||
fn command_search(ui: &mut egui::Ui, t: &Tokens, bar: &str, native: bool, looks: &[CommandLook], actions: &mut Vec<Action>) {
|
||||
widgets::menu_min_width(ui, 260.0);
|
||||
let q = widgets::search_field(ui, command_query_id(bar), tl!("Search Commands"));
|
||||
if q.trim().is_empty() {
|
||||
ui.label(egui::RichText::new(tl!("Type to find a command")).color(t.text_dim));
|
||||
return;
|
||||
}
|
||||
let found = crate::palette::command_matches(ui.ctx(), native, &q, COMMAND_RESULTS);
|
||||
if found.is_empty() {
|
||||
ui.label(egui::RichText::new(tl!("No matching commands")).color(t.text_dim));
|
||||
}
|
||||
for (id, name) in found {
|
||||
let held = looks.iter().any(|l| l.id == id);
|
||||
if widgets::menu_item_name(ui, &name, !held, false) {
|
||||
actions.push(Action::AddCommand(bar.to_string(), id));
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Where Add Tool…'s menu on the toolbar named `name` keeps the text of its command search field.
|
||||
pub(crate) fn command_query_id(name: &str) -> egui::Id {
|
||||
add_menu_id(name).with("query")
|
||||
}
|
||||
|
||||
/// The area of Add Tool…'s menu on the toolbar named `name`.
|
||||
pub(crate) fn add_menu_id(name: &str) -> egui::Id {
|
||||
egui::Id::unique(("custom-toolbar-add", key(name)))
|
||||
@@ -1376,8 +1715,9 @@ pub(crate) fn add_menu_id(name: &str) -> egui::Id {
|
||||
|
||||
/// Add Tool…'s menu, which the + button on the toolbar `bar` opens: under Remove Tool the tools in
|
||||
/// the toolbar, where a click takes one out; then every tool under the All Tools drawer's headings,
|
||||
/// where a click adds one at the end (dimmed: in the toolbar already). It scrolls past the window's
|
||||
/// bottom bars, as other long menus do ([`widgets::menu_scroll`]).
|
||||
/// where a click adds one at the end (dimmed: in the toolbar already); then its command rows
|
||||
/// ([`command_section`]). It scrolls past the window's bottom bars, as other long menus do
|
||||
/// ([`widgets::menu_scroll`]).
|
||||
fn add_menu(button: &egui::Response, t: &Tokens, bar: &CustomToolbar, actions: &mut Vec<Action>) {
|
||||
egui::Popup::menu(button).id(add_menu_id(&bar.name)).show(|ui| {
|
||||
widgets::menu_min_width(ui, 200.0);
|
||||
@@ -1401,6 +1741,7 @@ fn add_menu(button: &egui::Response, t: &Tokens, bar: &CustomToolbar, actions: &
|
||||
}
|
||||
}
|
||||
}
|
||||
command_section(ui, t, &bar.name, actions);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1480,7 +1821,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": [], "floating": true, "side": "left", "order": null});
|
||||
let blank = |name: &str| json!({"name": name, "shown": true, "double": false, "slots": [], "commands": [], "floating": true, "side": "left", "order": null});
|
||||
assert_eq!(list, json!([blank("Mine"), blank("Toolbar 1")]));
|
||||
}
|
||||
|
||||
@@ -1579,7 +1920,10 @@ mod tests {
|
||||
assert!(app.run("toolbar.addTool", json!({"tool": "pen", "toolbar": "Nope"})).is_err());
|
||||
let r = app.run("toolbar.removeTool", json!({"tool": "artboard", "toolbar": "Mine"})).unwrap();
|
||||
assert_eq!(r, json!([["pen", "curvature"]]));
|
||||
// Its command buttons go with it.
|
||||
app.run("toolbar.addCommand", json!({"command": "object.group", "toolbar": "Mine"})).unwrap();
|
||||
let mine = find(&app.ui, "Mine").cloned().unwrap();
|
||||
assert_eq!(mine.commands, ["object.group"]);
|
||||
// Another workspace has its own toolbars (none); coming back brings Mine back.
|
||||
app.run("window.workspace", json!({"name": "Essentials"})).unwrap();
|
||||
assert!(app.ui.custom_toolbars.is_empty());
|
||||
@@ -2253,6 +2597,7 @@ mod tests {
|
||||
.iter()
|
||||
.map(|id| crate::state::FloatingFlyout { tools: vec![id.to_string(), "curvature".into()], pos: [0.0, 0.0] })
|
||||
.collect(),
|
||||
commands: vec![],
|
||||
};
|
||||
let long = "x".repeat(MAX_NAME + 1);
|
||||
let mut bars = vec![
|
||||
|
||||
@@ -304,7 +304,11 @@ pub(crate) fn command(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<R
|
||||
})(),
|
||||
"toolbar.reset" => (|| {
|
||||
if let Some(name) = crate::custom_toolbars::target(&app.ui, p)? {
|
||||
// A toolbar made with New Toolbar goes back to blank, as it was made.
|
||||
// A toolbar made with New Toolbar goes back to blank, as it was made, without its
|
||||
// command buttons too.
|
||||
if let Some(bar) = crate::custom_toolbars::find_mut(&mut app.ui, &name) {
|
||||
bar.commands.clear();
|
||||
}
|
||||
return edit_custom(app, &name, |cats| {
|
||||
cats.clear();
|
||||
Ok(())
|
||||
|
||||
@@ -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"]], "floating": true, "side": "left", "order": null}])
|
||||
json!([{"name": "Mine", "shown": true, "double": false, "slots": [["lasso"]], "commands": [], "floating": true, "side": "left", "order": null}])
|
||||
);
|
||||
// A second tool goes after the first.
|
||||
let shown = open(&mut app, 19.0);
|
||||
@@ -891,3 +891,241 @@ fn addon_tools_are_in_the_drawer_not_the_toolbars() {
|
||||
assert!(slot_of(&app, tool).is_some(), "{tool}");
|
||||
}
|
||||
}
|
||||
|
||||
/// The command buttons of the toolbar made with New Toolbar called Mine.
|
||||
fn mine_commands(app: &VectorcraftApp) -> Vec<String> {
|
||||
crate::custom_toolbars::find(&app.ui, "Mine").unwrap().commands.clone()
|
||||
}
|
||||
|
||||
/// `toolbar.addCommand` puts command buttons on a toolbar made with New Toolbar and moves them,
|
||||
/// `toolbar.removeCommand` takes them off, and a bad call changes nothing. Manage Toolbars' copy
|
||||
/// keeps them, and `toolbar.reset` takes them off with the tools.
|
||||
#[test]
|
||||
fn command_buttons_are_added_moved_and_removed_by_their_commands() {
|
||||
let mut app = app();
|
||||
app.run("window.toolbar.new", json!({"name": "Mine"})).unwrap();
|
||||
let added = app.run("toolbar.addCommand", json!({"command": "object.group", "toolbar": "Mine"})).unwrap();
|
||||
assert_eq!(added, json!(["object.group"]));
|
||||
app.run("toolbar.addCommand", json!({"command": "object.path.cleanUp", "toolbar": "Mine"})).unwrap();
|
||||
app.run("toolbar.addCommand", json!({"command": "object.path.cleanUp", "toolbar": "Mine", "at": 0})).unwrap();
|
||||
assert_eq!(mine_commands(&app), ["object.path.cleanUp", "object.group"], "moved, not added twice");
|
||||
for (p, why) in [
|
||||
(json!({"command": "no.such", "toolbar": "Mine"}), "an unknown command"),
|
||||
(json!({"command": "tool:pen", "toolbar": "Mine"}), "a tool"),
|
||||
(json!({"command": "object.group", "toolbar": "Mine", "at": 2}), "a place past the end"),
|
||||
(json!({"command": "object.group", "toolbar": "Mine", "at": -1}), "a negative place"),
|
||||
(json!({"command": "toolbar.addTool", "toolbar": "Mine"}), "a command that needs params"),
|
||||
(json!({"command": "object.group"}), "no toolbar"),
|
||||
(json!({"toolbar": "Mine"}), "no command"),
|
||||
] {
|
||||
assert!(app.run("toolbar.addCommand", p.clone()).is_err(), "{why}: {p}");
|
||||
assert_eq!(mine_commands(&app), ["object.path.cleanUp", "object.group"], "{why} changes nothing");
|
||||
}
|
||||
assert!(app.run("toolbar.removeCommand", json!({"command": "object.group"})).is_err(), "no toolbar");
|
||||
let list = app.run("window.toolbar.list", json!({})).unwrap();
|
||||
assert_eq!(list[0]["commands"], json!(["object.path.cleanUp", "object.group"]));
|
||||
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().commands, mine_commands(&app), "the copy has them");
|
||||
let left = app.run("toolbar.removeCommand", json!({"command": "object.group", "toolbar": "Mine"})).unwrap();
|
||||
assert_eq!(left, json!(["object.path.cleanUp"]));
|
||||
app.run("toolbar.addTool", json!({"tool": "pen", "toolbar": "Mine"})).unwrap();
|
||||
app.run("toolbar.reset", json!({"toolbar": "Mine"})).unwrap();
|
||||
assert!(mine_commands(&app).is_empty(), "Reset makes the toolbar blank");
|
||||
assert_eq!(crate::custom_toolbars::find(&app.ui, ©).unwrap().commands.len(), 2, "the copy keeps its own");
|
||||
}
|
||||
|
||||
/// The text painted inside the toolbar called Mine that starts with `text`: a point inside it and
|
||||
/// its color.
|
||||
fn on_mine(app: &mut VectorcraftApp, ctx: &egui::Context, time: f64, text: &str) -> Option<(Pos2, Color32)> {
|
||||
let shown = frame(app, ctx, time, vec![]);
|
||||
let bar = ctx.memory(|m| m.area_rect(crate::custom_toolbars::area_id("Mine")))?;
|
||||
shown.into_iter().find(|(s, p, _)| s.starts_with(text) && bar.contains(*p)).map(|(_, p, c)| (p, c))
|
||||
}
|
||||
|
||||
/// A command button shows its command's label, without the ellipsis, and a click runs what the
|
||||
/// command's menu item runs. While that item would be dimmed, the button is dimmed too and a click
|
||||
/// runs nothing. A command whose item ends in … opens its dialog.
|
||||
#[test]
|
||||
fn a_command_button_runs_its_command_and_is_dimmed_while_it_cannot() {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_testkit::fixtures::Fixture::Multi.session(), Default::default());
|
||||
let ctx = ctx();
|
||||
let t = Tokens::get(&ctx);
|
||||
app.run("window.toolbar.new", json!({"name": "Mine"})).unwrap();
|
||||
for c in ["object.group", "object.path.cleanUp"] {
|
||||
app.run("toolbar.addCommand", json!({"command": c, "toolbar": "Mine"})).unwrap();
|
||||
}
|
||||
let undo = |app: &VectorcraftApp| app.session.active().map_or(0, |d| d.history.undo.len());
|
||||
app.run("select.set", json!({"ids": []})).unwrap();
|
||||
frame(&mut app, &ctx, 0.0, vec![]);
|
||||
let (at, color) = on_mine(&mut app, &ctx, 0.1, "Group").expect("the button shows Group");
|
||||
assert_eq!(color, t.text_disabled, "dimmed with nothing selected");
|
||||
let before = undo(&app);
|
||||
app.ui.status.clear();
|
||||
click(&mut app, &ctx, 1.0, at);
|
||||
assert_eq!(undo(&app), before, "a dimmed button runs nothing");
|
||||
assert!(!app.ui.status.is_empty(), "the status line says why");
|
||||
app.run("select.all", json!({})).unwrap();
|
||||
let (at, color) = on_mine(&mut app, &ctx, 2.0, "Group").expect("the button shows Group");
|
||||
assert_eq!(color, t.text, "not dimmed with objects selected");
|
||||
click(&mut app, &ctx, 3.0, at);
|
||||
assert!(undo(&app) > before, "Group ran");
|
||||
let (at, _) = on_mine(&mut app, &ctx, 4.0, "Clean Up").expect("the button shows Clean Up");
|
||||
assert!(on_mine(&mut app, &ctx, 4.1, "Clean Up…").is_none(), "without the ellipsis");
|
||||
assert!(app.ui.dialog.is_none());
|
||||
click(&mut app, &ctx, 5.0, at);
|
||||
assert!(app.ui.dialog.is_some(), "Clean Up… opens its dialog");
|
||||
}
|
||||
|
||||
/// Command buttons are kept with the preferences, and a toolbar saved before toolbars held commands
|
||||
/// loads with none. A command that is gone, such as an uninstalled plug-in's, stays: its button is
|
||||
/// dimmed and shows its id, a click runs nothing and says so, and Remove Command takes it off.
|
||||
#[test]
|
||||
fn a_missing_command_stays_dimmed_until_it_is_removed() {
|
||||
let mut app = app();
|
||||
let ctx = ctx();
|
||||
let t = Tokens::get(&ctx);
|
||||
app.run("window.toolbar.new", json!({"name": "Mine"})).unwrap();
|
||||
app.run("toolbar.addCommand", json!({"command": "object.group", "toolbar": "Mine"})).unwrap();
|
||||
crate::custom_toolbars::find_mut(&mut app.ui, "Mine").unwrap().commands.push("plugin:x".into());
|
||||
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, the missing command too");
|
||||
let mut old = serde_json::to_value(&kept[0]).unwrap();
|
||||
old.as_object_mut().unwrap().remove("commands");
|
||||
let old: crate::state::CustomToolbar = serde_json::from_value(old).unwrap();
|
||||
assert!(old.commands.is_empty(), "an older toolbar loads without commands");
|
||||
frame(&mut app, &ctx, 0.0, vec![]);
|
||||
let (at, color) = on_mine(&mut app, &ctx, 0.1, "plug").expect("the button shows the command's id");
|
||||
assert_eq!(color, t.text_disabled);
|
||||
app.ui.status.clear();
|
||||
click(&mut app, &ctx, 1.0, at);
|
||||
assert!(app.ui.status.contains("plugin:x"), "the status line names it: {}", app.ui.status);
|
||||
let left = app.run("toolbar.removeCommand", json!({"command": "plugin:x", "toolbar": "Mine"})).unwrap();
|
||||
assert_eq!(left, json!(["object.group"]));
|
||||
}
|
||||
|
||||
/// Add Tool…'s menu lists a toolbar's command buttons under Remove Command, where a click takes one
|
||||
/// off, and its Add Command submenu searches the menu commands: a click on a match adds its button
|
||||
/// at the end of the toolbar.
|
||||
#[test]
|
||||
fn the_add_tool_menu_adds_and_removes_commands() {
|
||||
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![]);
|
||||
frame(&mut app, &ctx, 0.1, vec![]);
|
||||
// The + button, which moves down as command buttons are added above it.
|
||||
let plus = || {
|
||||
let bar = ctx.memory(|m| m.area_rect(crate::custom_toolbars::area_id("Mine"))).expect("the toolbar is shown");
|
||||
crate::toolbar::tests::widget_rects(&ctx, vec2(26.0, 26.0)).into_iter().find(|r| bar.contains(r.center())).expect("the + button")
|
||||
};
|
||||
// The menu's text named `name`, opened with a click on the + button unless it is open.
|
||||
let menu_text = |app: &mut VectorcraftApp, time: f64, name: &str| {
|
||||
let mut shown = frame(app, &ctx, time, vec![]);
|
||||
if !shown.iter().any(|(s, ..)| s == "Select:") {
|
||||
click(app, &ctx, time + 0.2, plus().center());
|
||||
frame(app, &ctx, time + 0.5, vec![]);
|
||||
shown = frame(app, &ctx, time + 0.6, vec![]);
|
||||
}
|
||||
let menu = ctx.memory(|m| m.area_rect(crate::custom_toolbars::add_menu_id("Mine")))?;
|
||||
shown.into_iter().find(|(s, p, _)| s.trim() == name && menu.contains(*p)).map(|(_, p, _)| p)
|
||||
};
|
||||
assert!(menu_text(&mut app, 1.0, "Remove Command:").is_some(), "a heading over the toolbar's commands");
|
||||
// The Add Command submenu opens under the pointer and searches as text is typed.
|
||||
let row = menu_text(&mut app, 2.0, "Add Command").expect("the Add Command row");
|
||||
frame(&mut app, &ctx, 3.0, vec![Event::PointerMoved(row)]);
|
||||
frame(&mut app, &ctx, 3.5, vec![Event::PointerMoved(row)]);
|
||||
let field = crate::custom_toolbars::command_query_id("Mine").with("edit");
|
||||
ctx.memory_mut(|m| m.request_focus(field));
|
||||
frame(&mut app, &ctx, 4.0, vec![]);
|
||||
frame(&mut app, &ctx, 4.1, vec![Event::Text("clean up".into())]);
|
||||
frame(&mut app, &ctx, 4.2, vec![]);
|
||||
let shown = frame(&mut app, &ctx, 4.3, vec![]);
|
||||
let at = shown.iter().find(|(s, ..)| s.trim().ends_with("Clean Up…")).map(|(_, p, _)| *p).expect("Clean Up… is found");
|
||||
click(&mut app, &ctx, 5.0, at);
|
||||
assert_eq!(mine_commands(&app), ["object.group", "object.path.cleanUp"], "added at the end");
|
||||
let pen = crate::palette::command_matches(&ctx, false, "pen", 30);
|
||||
assert!(!pen.is_empty() && pen.iter().all(|(id, _)| !id.starts_with("tool:")), "tools are not listed among the commands: {pen:?}");
|
||||
let toolbar = crate::palette::command_matches(&ctx, false, "toolbar add", 30);
|
||||
assert!(toolbar.iter().all(|(id, _)| id != "toolbar.addTool" && id != "toolbar.addCommand"), "commands that need params: {toolbar:?}");
|
||||
// Under Remove Command, Group is listed by its full name, and a click takes it off.
|
||||
let name = crate::palette::button_text(&ctx, false, "object.group").expect("Group's result").name;
|
||||
let group = menu_text(&mut app, 10.0, &name).unwrap_or_else(|| panic!("{name} under Remove Command"));
|
||||
click(&mut app, &ctx, 11.0, group);
|
||||
assert_eq!(mine_commands(&app), ["object.path.cleanUp"]);
|
||||
}
|
||||
|
||||
/// A button for a panel shows the panel, as the panel's Command Palette result does.
|
||||
#[test]
|
||||
fn a_panel_button_shows_its_panel() {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_testkit::fixtures::Fixture::Multi.session(), Default::default());
|
||||
let ctx = ctx();
|
||||
let panel = crate::state::all_panels()
|
||||
.map(|(id, _)| id)
|
||||
.find(|id| !crate::panel_docking::visible(&app.ui, id) && crate::palette::is_command(&format!("panel:{id}")))
|
||||
.expect("a hidden panel");
|
||||
let id = format!("panel:{panel}");
|
||||
app.run("window.toolbar.new", json!({"name": "Mine"})).unwrap();
|
||||
app.run("toolbar.addCommand", json!({"command": id, "toolbar": "Mine"})).unwrap();
|
||||
frame(&mut app, &ctx, 0.0, vec![]);
|
||||
let label = crate::palette::button_text(&ctx, false, &id).expect("the panel's result").label;
|
||||
let start: String = label.chars().take(3).collect();
|
||||
let (at, _) = on_mine(&mut app, &ctx, 0.1, &start).unwrap_or_else(|| panic!("the button shows {label}"));
|
||||
click(&mut app, &ctx, 1.0, at);
|
||||
frame(&mut app, &ctx, 1.5, vec![]);
|
||||
assert!(crate::panel_docking::visible(&app.ui, panel), "{panel} is shown");
|
||||
}
|
||||
|
||||
/// A button for a plug-in's command that is not installed is dimmed and shows the command's id;
|
||||
/// once the plug-in is installed it shows the plug-in's name and can run, and when the plug-in is
|
||||
/// removed again it is dimmed again.
|
||||
#[test]
|
||||
fn a_plugin_command_button_works_again_when_the_plugin_returns() {
|
||||
use vectorcraft_plugins::wat as tpl;
|
||||
let mut app = VectorcraftApp::new(vectorcraft_testkit::fixtures::Fixture::Multi.session(), Default::default());
|
||||
let ctx = ctx();
|
||||
let t = Tokens::get(&ctx);
|
||||
// A name no other test gives a plug-in.
|
||||
let filter = "test.UI.toolbar_command-probe";
|
||||
let id = format!("plugin:{filter}");
|
||||
app.run("window.toolbar.new", json!({"name": "Mine"})).unwrap();
|
||||
crate::custom_toolbars::find_mut(&mut app.ui, "Mine").unwrap().commands.push(id.clone());
|
||||
app.run("select.all", json!({})).unwrap();
|
||||
frame(&mut app, &ctx, 0.0, vec![]);
|
||||
let gone = on_mine(&mut app, &ctx, 0.1, "plugin:").map(|(_, c)| c);
|
||||
let manifest = format!(r#"{{"id":"{filter}","name":"Toolbar Probe","version":"1","kind":"filter","params":{{}}}}"#);
|
||||
vectorcraft_plugins::registry::install_bytes(&wat::parse_str(tpl::returning(&manifest, r#"{"objects":[]}"#)).unwrap()).unwrap();
|
||||
frame(&mut app, &ctx, 1.0, vec![]);
|
||||
let back = on_mine(&mut app, &ctx, 1.1, "Toolbar").map(|(_, c)| c);
|
||||
let added = app.run("toolbar.addCommand", json!({"command": id, "toolbar": "Mine", "at": 0}));
|
||||
vectorcraft_plugins::registry::remove(filter);
|
||||
frame(&mut app, &ctx, 2.0, vec![]);
|
||||
let gone_again = on_mine(&mut app, &ctx, 2.1, "plugin:").map(|(_, c)| c);
|
||||
assert_eq!(gone, Some(t.text_disabled), "dimmed, with its id, while it is not installed");
|
||||
assert_eq!(back, Some(t.text), "its name, and it can run, once it is installed");
|
||||
assert!(added.is_ok(), "an installed plug-in's command can be added: {added:?}");
|
||||
assert_eq!(gone_again, Some(t.text_disabled), "dimmed again once it is removed");
|
||||
}
|
||||
|
||||
/// The toolbars ask only a few command buttons in a frame whether they can run, and the others in
|
||||
/// the next frames.
|
||||
#[test]
|
||||
fn command_buttons_ask_whether_they_can_run_a_few_at_a_time() {
|
||||
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();
|
||||
let ids: Vec<String> = crate::palette::command_matches(&ctx, false, "object", 40).into_iter().map(|(id, _)| id).take(20).collect();
|
||||
assert_eq!(ids.len(), 20);
|
||||
for id in &ids {
|
||||
app.run("toolbar.addCommand", json!({"command": id, "toolbar": "Mine"})).unwrap();
|
||||
}
|
||||
frame(&mut app, &ctx, 0.0, vec![]);
|
||||
let (first, waiting) = crate::custom_toolbars::asked(&ctx);
|
||||
assert!(first < ids.len() && waiting, "{first} asked in the first frame");
|
||||
for k in 1..5 {
|
||||
frame(&mut app, &ctx, f64::from(k), vec![]);
|
||||
}
|
||||
assert_eq!(crate::custom_toolbars::asked(&ctx), (ids.len(), false), "every button was asked in the next frames");
|
||||
}
|
||||
@@ -614,6 +614,18 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"",
|
||||
"{tool: id, group?: bool, toolbar?: name} take `tool` (with `group`, its whole group) out of the current toolbar (with `toolbar`, out of that toolbar made with New Toolbar; one not in it stays out), as dragging it into the Edit Toolbar drawer does; returns the toolbar's slots",
|
||||
),
|
||||
(
|
||||
"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",
|
||||
),
|
||||
(
|
||||
"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",
|
||||
),
|
||||
(
|
||||
"toolbar.reset",
|
||||
"Toolbar: Reset",
|
||||
@@ -672,7 +684,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, floating, side, order}], `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, 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)",
|
||||
),
|
||||
("window.taskBar", "Contextual Task Bar", "", "{}"),
|
||||
(
|
||||
|
||||
@@ -327,6 +327,8 @@ pub(crate) struct Catalog {
|
||||
list: Vec<Entry>,
|
||||
index: search::Index,
|
||||
ranked: std::sync::Mutex<Option<Ranked>>,
|
||||
/// Where each id is in `list`.
|
||||
by_id: std::collections::HashMap<String, usize>,
|
||||
}
|
||||
|
||||
impl std::ops::Deref for Catalog {
|
||||
@@ -375,7 +377,69 @@ fn catalog(lang: crate::i18n::Lang, native: bool) -> Catalog {
|
||||
// A group's row in the `search` context gives its words in `lang`; a plain row is not read.
|
||||
let search_row = |key: &str| crate::i18n::tr_ctx_row(lang, words::CONTEXT, key).map(str::to_string);
|
||||
let index = search::Index::build(&list, &shown_homes, ¶ms_texts(&list), search_row);
|
||||
Catalog { list, index, ranked: std::sync::Mutex::new(None) }
|
||||
let by_id = list.iter().enumerate().map(|(i, e)| (e.id.clone(), i)).collect();
|
||||
Catalog { list, index, ranked: std::sync::Mutex::new(None), by_id }
|
||||
}
|
||||
|
||||
/// What a command button on a toolbar made with New Toolbar shows for the result `id`
|
||||
/// ([`button_text`]).
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub(crate) struct ButtonText {
|
||||
/// The result's label in the interface language, without the menu path in front of it and
|
||||
/// without a closing ellipsis.
|
||||
pub label: String,
|
||||
/// The result's full name in the interface language, as the palette lists it.
|
||||
pub name: String,
|
||||
/// The shortcut as the menus show it, or empty.
|
||||
pub shortcut: String,
|
||||
}
|
||||
|
||||
/// The label and shortcut of the palette result `id` in the interface language, from the entries
|
||||
/// built once per language, plug-in set and shortcut set (`native`: with the native menu bar); none
|
||||
/// when the palette lists no result with that id now (an uninstalled plug-in's command).
|
||||
pub(crate) fn button_text(ctx: &egui::Context, native: bool, id: &str) -> Option<ButtonText> {
|
||||
let entries = entries_in(ctx, crate::i18n::current(), native);
|
||||
let e = entries.by_id.get(id).and_then(|&i| entries.list.get(i))?;
|
||||
let label = label_of(e).trim_end();
|
||||
let label = label.strip_suffix('…').or_else(|| label.strip_suffix("...")).unwrap_or(label).trim_end();
|
||||
Some(ButtonText { label: label.to_string(), name: e.shown.clone(), shortcut: menus::shown_shortcut(&e.shortcut) })
|
||||
}
|
||||
|
||||
/// The results a toolbar made with New Toolbar can hold as command buttons that the query `q`
|
||||
/// matches, best first, at most `most`: the results [`is_command`] allows. Each is its id and its
|
||||
/// name in the interface language (`native`: as [`button_text`]).
|
||||
pub(crate) fn command_matches(ctx: &egui::Context, native: bool, q: &str, most: usize) -> Vec<(String, String)> {
|
||||
let entries = entries_in(ctx, crate::i18n::current(), native);
|
||||
matching(&entries, q, &[], &CommandUses::default())
|
||||
.into_iter()
|
||||
.filter(|e| is_command(&e.id))
|
||||
.take(most)
|
||||
.map(|e| (e.id.clone(), e.shown.clone()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Can a toolbar made with New Toolbar hold the result `id` as a command button now: is it a
|
||||
/// palette result other than a tool, and not a UI command that fails without params a click does
|
||||
/// not give ([`crate::shortcut_editor::ui_command_needs_params`]: `toolbar.addTool` needs a
|
||||
/// `tool`)? The ids are listed again when the plug-ins or the shortcuts change, not on every call.
|
||||
pub(crate) fn is_command(id: &str) -> bool {
|
||||
type Ids = ((u64, u64), Arc<std::collections::HashSet<String>>);
|
||||
static IDS: std::sync::Mutex<Option<Ids>> = std::sync::Mutex::new(None);
|
||||
if id.starts_with("tool:") {
|
||||
return false;
|
||||
}
|
||||
let key = (menus::plugin_revision(), crate::shortcut_editor::GENERATION.load(std::sync::atomic::Ordering::Relaxed));
|
||||
let kept = IDS.lock().ok().and_then(|ids| ids.as_ref().filter(|(k, _)| *k == key).map(|(_, v)| v.clone()));
|
||||
let ids = kept.unwrap_or_else(|| {
|
||||
let filters: Vec<String> = crate::shortcut_editor::filter_items().iter().map(|f| format!("plugin:{}", f.id)).collect();
|
||||
let ids = drafts().into_iter().map(|d| d.id).filter(|id| !id.starts_with("tool:") && !crate::shortcut_editor::ui_command_needs_params(id));
|
||||
let ids: Arc<std::collections::HashSet<String>> = Arc::new(ids.chain(filters).collect());
|
||||
if let Ok(mut kept) = IDS.lock() {
|
||||
*kept = Some((key, ids.clone()));
|
||||
}
|
||||
ids
|
||||
});
|
||||
ids.contains(id)
|
||||
}
|
||||
|
||||
/// The params text of each entry's command, which the index reads a description from
|
||||
@@ -531,7 +595,7 @@ pub(crate) enum Picked {
|
||||
/// ([`crate::shortcut_editor::dimmed`]), with the engine's reason when it gives one and `name` in
|
||||
/// place of the command's id. A panel can't be shown in Presentation Mode, a tool can always be
|
||||
/// chosen, and every other result asks about the command its pick runs.
|
||||
fn unavailable(app: &VectorcraftApp, id: &str, name: &str) -> Option<String> {
|
||||
pub(crate) fn unavailable(app: &VectorcraftApp, id: &str, name: &str) -> Option<String> {
|
||||
if id.starts_with("tool:") {
|
||||
return None;
|
||||
}
|
||||
@@ -585,7 +649,7 @@ impl Availability {
|
||||
/// mode, an open dialog, and the background saves and exports, file reads, plug-in runs and traces
|
||||
/// that run or show their progress. A click asks again for what it leaves out (a panel shown, a
|
||||
/// tool chosen) without changing it ([`show`]); typing in the search field does not.
|
||||
fn availability_key(app: &VectorcraftApp) -> u64 {
|
||||
pub(crate) fn availability_key(app: &VectorcraftApp) -> u64 {
|
||||
use std::hash::{Hash, Hasher};
|
||||
let mut h = std::collections::hash_map::DefaultHasher::new();
|
||||
crate::native_menu::state_hash(app, None).hash(&mut h);
|
||||
@@ -4016,6 +4080,7 @@ mod tests {
|
||||
slot_tool: Default::default(),
|
||||
double: false,
|
||||
floating: vec![],
|
||||
commands: vec![],
|
||||
};
|
||||
// Window › Tools hides the Tools panel while a toolbar made with New Toolbar holds the Pen
|
||||
// Tool: the row names that toolbar.
|
||||
@@ -5301,6 +5366,7 @@ mod tests {
|
||||
slot_tool: Default::default(),
|
||||
double: false,
|
||||
floating: vec![],
|
||||
commands: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1004,7 +1004,7 @@ mod tests {
|
||||
/// `entries` with their index, the params text of each in `params`.
|
||||
fn described(entries: Vec<Entry>, params: &[&str]) -> Catalog {
|
||||
let index = Index::build(&entries, &[], params, |_| None);
|
||||
Catalog { list: entries, index, ranked: std::sync::Mutex::new(None) }
|
||||
Catalog { list: entries, index, ranked: std::sync::Mutex::new(None), by_id: Default::default() }
|
||||
}
|
||||
|
||||
/// Where `id` is among the results of `query`.
|
||||
@@ -1464,7 +1464,7 @@ mod tests {
|
||||
#[test]
|
||||
fn without_an_index_only_the_substring_rule_matches() {
|
||||
let entries = vec![entry("Remove Background…", "a.one"), entry("Zz Group", "b.two")];
|
||||
let c = Catalog { list: entries, index: Index::default(), ranked: std::sync::Mutex::new(None) };
|
||||
let c = Catalog { list: entries, index: Index::default(), ranked: std::sync::Mutex::new(None), by_id: Default::default() };
|
||||
assert!(ranked(&c, "mov.nd").is_empty(), "{:?}", ranked(&c, "mov.nd"));
|
||||
assert_eq!(ranked(&c, "background mov"), ["a.one"]);
|
||||
}
|
||||
@@ -1519,7 +1519,12 @@ mod tests {
|
||||
fn a_catalog_row_adds_words_to_a_group() {
|
||||
let entries = || vec![entry("Zz Delete", "a.one")];
|
||||
let row = |key: &str| (key == "remove, delete, erase, clear").then(|| "Entfernen, ganz weg, text".to_string());
|
||||
let with = Catalog { list: entries(), index: Index::build(&entries(), &[], &[], row), ranked: std::sync::Mutex::new(None) };
|
||||
let with = Catalog {
|
||||
list: entries(),
|
||||
index: Index::build(&entries(), &[], &[], row),
|
||||
ranked: std::sync::Mutex::new(None),
|
||||
by_id: Default::default(),
|
||||
};
|
||||
assert_eq!(ranked(&with, "entfernen"), ["a.one"]);
|
||||
assert!(ranked(&with, "ganz weg").is_empty(), "two words are left out");
|
||||
assert!(ranked(&with, "text").is_empty(), "text stays in its own group");
|
||||
|
||||
@@ -991,6 +991,16 @@ fn a_menu_bar_item_runs(id: &str, params: &str) -> bool {
|
||||
|| menu_target(id).is_some_and(|(target, _)| target != id || !names_a_required_field(params))
|
||||
}
|
||||
|
||||
/// Is `id` a UI command that fails when it runs with no params: its params doc names a field a call
|
||||
/// must give, no item of the menu bar runs it ([`a_menu_bar_item_runs`]), and a key press does not
|
||||
/// run it on its own ([`ui_listed_on_its_own`])? `toolbar.addTool` needs a `tool`.
|
||||
pub(crate) fn ui_command_needs_params(id: &str) -> bool {
|
||||
crate::menus::UI_COMMANDS
|
||||
.iter()
|
||||
.find(|c| c.0 == id)
|
||||
.is_some_and(|c| names_a_required_field(c.3) && !a_menu_bar_item_runs(c.0, c.3) && !ui_listed_on_its_own(c.0, c.2, c.3))
|
||||
}
|
||||
|
||||
/// Is engine command `c` listed in Edit › Keyboard Shortcuts whether or not an item of the menu bar
|
||||
/// runs it? A command with a menu path of its own is. One without (a panel menu item) is when a key
|
||||
/// alone can run it: it has a default key, or it is an undoable command, not an alias, whose params
|
||||
|
||||
@@ -1087,6 +1087,11 @@ pub struct CustomToolbar {
|
||||
/// The groups torn off it, each floating as its own strip; they show while it does.
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub floating: Vec<FloatingFlyout>,
|
||||
/// Its command buttons, after its tools: Command Palette result ids (a command's id, or
|
||||
/// `plugin:`, `effect:` or `panel:` and an id). A command that is gone, such as an uninstalled
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
/// A category of an edited toolbar: its name (one of the Basic toolbar's; none in the Advanced
|
||||
|
||||
@@ -479,8 +479,17 @@ toolbars Tab hid are turned off. A toolbar's ••• button
|
||||
button (Add Tool…) opens a menu of every tool under the drawer's headings: a click on a tool runs `toolbar.addTool
|
||||
{tool, toolbar}`, which puts it at the end, and the tools under its Remove Tool heading run `toolbar.removeTool
|
||||
{tool, toolbar}`; the tools already in the toolbar are dimmed under their headings. The drawer has no Show section
|
||||
there. `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, shown flag,
|
||||
there. The same menu's Add Command submenu searches the Command Palette's results other than tools, and a pick runs
|
||||
`toolbar.addCommand {command, toolbar}`, which puts a command button at the end of the toolbar, after its tools;
|
||||
`toolbar.addCommand {command, toolbar, at}` moves one to place `at` among the command buttons (Move Up and Move Down
|
||||
in the button's context menu), and `toolbar.removeCommand {command, toolbar}` takes one off (Remove Command in the
|
||||
menu, Remove from Toolbar in the context menu). `command` is a palette result's id: a command's id, or
|
||||
`plugin:<id>`, `effect:<id>` or `panel:<id>`. A click on the button runs what the command's menu item runs, and the
|
||||
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.
|
||||
`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.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
|
||||
|
||||
+20
@@ -3678,6 +3678,26 @@ own layout rules.
|
||||
{"name":"invoke_menu","arguments":{"command":"window.toolbar.dock","params":{"name":"Toolbar 1","side":"left","order":0}}}
|
||||
```
|
||||
|
||||
## Command buttons on toolbars made with New Toolbar
|
||||
|
||||
A toolbar made with New Toolbar holds command buttons after its tools. `toolbar.addCommand {command, toolbar, at?}`
|
||||
(Add Command in the toolbar's Add Tool… menu, remote mode, `invoke_menu`) puts a button for `command` on the toolbar
|
||||
named `toolbar`, or moves the button when the toolbar has it already: at place `at` among its command buttons, 0 for
|
||||
the first, or at the end without `at`. `command` is a Command Palette result's id: a command's id, or
|
||||
`plugin:<id>`, `effect:<id>` or `panel:<id>`. `toolbar.removeCommand {command, toolbar}` takes a button off. Both
|
||||
answer with the toolbar's command buttons, and `window.toolbar.list` reports `commands` for each toolbar. An unknown
|
||||
command, a tool, a command that needs params a click does not give (`toolbar.addTool`), an `at` past the end or a
|
||||
missing `toolbar` is an error and changes nothing. A click on a button runs what the command's menu item runs, so a
|
||||
command whose item ends in … opens its dialog, and the button is dimmed while that item is. A command that is no
|
||||
longer installed, such as an uninstalled plug-in's, keeps its button, dimmed and labeled with its id, until it is
|
||||
installed again or removed. `toolbar.reset {toolbar}` takes the buttons off with the tools. The buttons are kept with
|
||||
the workspace, and toolbars saved before command buttons existed load without any. Command buttons are VectorCraft's
|
||||
own.
|
||||
|
||||
```json
|
||||
{"name":"invoke_menu","arguments":{"command":"toolbar.addCommand","params":{"command":"object.group","toolbar":"Toolbar 1"}}}
|
||||
```
|
||||
|
||||
## Help search
|
||||
|
||||
Help › VectorCraft Help… and F1 show the Help panel. `help.discover {query?}` opens it without
|
||||
|
||||
@@ -1132,6 +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`).
|
||||
- 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