mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-30 18:25:34 +01:00
Toolbars: Rename Button's Label field takes the focus, and a workspace switch closes the dialog
- The Label field takes the keyboard focus with its text selected when the dialog opens, so typing right away goes into it. - Switching workspaces closes Rename Button, so OK cannot rename a button of the same name on a toolbar of the same name in the other workspace. - The params text and docs say a screen reader reads only the label when it is the command's label or name, and that a null `label` opens the dialog.
This commit is contained in:
1 parent
bfae97f9a5
commit
b6d24816a8
9 files changed
+91
-9
No files matched your search
@@ -629,7 +629,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"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)",
|
||||
"{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` (or with null), 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, or only the label when it is the command's label or 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",
|
||||
|
||||
@@ -682,11 +682,18 @@ pub(crate) fn confirm_rename(app: &mut VectorcraftApp) -> Result<Value, String>
|
||||
Ok(done)
|
||||
}
|
||||
|
||||
/// The Rename Button dialog: the button's label, empty for its command's own, OK and Cancel.
|
||||
/// The Label field of the Rename Button dialog.
|
||||
pub(crate) fn rename_label_id() -> egui::Id {
|
||||
egui::Id::unique("rename-toolbar-button-label")
|
||||
}
|
||||
|
||||
/// The Rename Button dialog: the button's label, empty for its command's own, OK and Cancel. Just
|
||||
/// opened, its Label field takes the keyboard focus with its text selected.
|
||||
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);
|
||||
let focus = crate::dialogs::window_focus_pending(ctx);
|
||||
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"));
|
||||
@@ -694,10 +701,15 @@ pub(crate) fn show_rename(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
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));
|
||||
let field = ui.add(egui::TextEdit::singleline(&mut label).id(rename_label_id()).desired_width(220.0));
|
||||
if field.changed() {
|
||||
d.fields.insert("label".into(), json!(label));
|
||||
}
|
||||
// A new window's first frame only measures it: the field takes the focus on the next.
|
||||
if focus && !ui.is_sizing_pass() {
|
||||
widgets::focus_field(ui, rename_label_id(), &label);
|
||||
crate::dialogs::window_focus_taken(ctx);
|
||||
}
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
ui.label(egui::RichText::new(tl!("Leave it empty to show the command's name.")).color(t.text_dim));
|
||||
|
||||
@@ -894,6 +894,23 @@ pub(crate) fn opened_by_panel(app: &mut VectorcraftApp) {
|
||||
}
|
||||
}
|
||||
|
||||
/// The key under which [`show`] marks a dialog that has just opened: its first field is to take the
|
||||
/// keyboard focus, until a field takes it.
|
||||
fn focus_pending_id() -> egui::Id {
|
||||
egui::Id::unique("dialog-focus-pending")
|
||||
}
|
||||
|
||||
/// Whether a dialog drawn by its own window (`DialogSpec::window`) has just opened and its field
|
||||
/// is to take the keyboard focus this frame: not in the frame of a click, as in [`show`].
|
||||
pub(crate) fn window_focus_pending(ctx: &egui::Context) -> bool {
|
||||
!ctx.input(|i| i.pointer.any_click()) && ctx.data(|m| m.get_temp::<bool>(focus_pending_id())).unwrap_or(false)
|
||||
}
|
||||
|
||||
/// The field of a dialog drawn by its own window has taken the keyboard focus.
|
||||
pub(crate) fn window_focus_taken(ctx: &egui::Context) {
|
||||
ctx.data_mut(|m| m.remove::<bool>(focus_pending_id()));
|
||||
}
|
||||
|
||||
/// Draws the active dialog and handles shared initial focus, keyboard shortcuts and actions.
|
||||
/// Inline actions and footer buttons use the same confirmation and preview rollback paths.
|
||||
pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
@@ -904,7 +921,7 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
confirm::show_waiting(app);
|
||||
// The kind of dialog shown last frame: a different one (or none) means this one just opened, and
|
||||
// its first field is to take the keyboard focus (`focus_id`, until a field takes it).
|
||||
let (shown_id, focus_id) = (egui::Id::unique("dialog-shown"), egui::Id::unique("dialog-focus-pending"));
|
||||
let (shown_id, focus_id) = (egui::Id::unique("dialog-shown"), focus_pending_id());
|
||||
let Some(mut d) = app.ui.dialog.clone() else {
|
||||
revolve_gizmo::clear(ctx);
|
||||
app.ui.dialog_file = None;
|
||||
|
||||
@@ -1281,7 +1281,17 @@ fn rename_button_in_the_context_menu_renames_it() {
|
||||
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"));
|
||||
// The Label field has the keyboard focus: typing right away goes into it.
|
||||
let dialog_frame = |app: &mut VectorcraftApp, time: f64, events: Vec<Event>| {
|
||||
let input = RawInput { time: Some(time), events, screen_rect: Some(Rect::from_min_size(Pos2::ZERO, SCREEN)), ..Default::default() };
|
||||
ctx.run_ui(input, |ui| crate::dialogs::show(app, ui.ctx())).textures_delta.clear();
|
||||
};
|
||||
for k in 0..3 {
|
||||
dialog_frame(&mut app, 3.0 + 0.1 * f64::from(k), vec![]);
|
||||
}
|
||||
assert_eq!(ctx.memory(|m| m.focused()), Some(crate::custom_toolbars::rename_label_id()), "the Label field has the focus");
|
||||
dialog_frame(&mut app, 3.5, vec![Event::Text("Grp".into())]);
|
||||
assert_eq!(app.ui.dialog.as_ref().map(|d| d.str("label")).as_deref(), Some("Grp"), "typed into the Label field");
|
||||
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"));
|
||||
@@ -1294,3 +1304,32 @@ fn rename_button_in_the_context_menu_renames_it() {
|
||||
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");
|
||||
}
|
||||
|
||||
/// Switching workspaces closes the Rename Button dialog, so OK cannot rename a button of the same
|
||||
/// name on a toolbar of the same name in the workspace switched to. Reset Workspace keeps the
|
||||
/// toolbars, and the dialog stays open. New Workspace closes it like a switch.
|
||||
#[test]
|
||||
fn switching_workspaces_closes_rename_button() {
|
||||
let mut app = app();
|
||||
app.run("window.toolbar.new", json!({"name": "Mine"})).unwrap();
|
||||
app.run("toolbar.addCommand", json!({"command": "object.group", "toolbar": "Mine"})).unwrap();
|
||||
// Drawing starts with a copy of Mine, so both workspaces have Mine with a Group button.
|
||||
app.run("window.workspace.new", json!({"name": "Drawing"})).unwrap();
|
||||
app.run("toolbar.renameCommand", json!({"command": "object.group", "toolbar": "Mine"})).unwrap();
|
||||
app.ui.dialog.as_mut().unwrap().fields.insert("label".into(), json!("Grp"));
|
||||
app.run("window.workspace.reset", json!({})).unwrap();
|
||||
assert_eq!(app.ui.dialog.as_ref().map(|d| d.str("label")).as_deref(), Some("Grp"), "Reset Workspace keeps the dialog open");
|
||||
app.run("window.workspace", json!({"name": "Essentials"})).unwrap();
|
||||
assert!(app.ui.dialog.is_none(), "the dialog closes");
|
||||
assert!(crate::custom_toolbars::confirm_rename(&mut app).is_err());
|
||||
assert!(mine_labels(&app).is_empty(), "Essentials' Mine keeps its command's label");
|
||||
app.run("window.workspace", json!({"name": "Drawing"})).unwrap();
|
||||
assert!(mine_labels(&app).is_empty(), "and so does Drawing's");
|
||||
// New Workspace leaves the workspace as well, and its copy of Mine keeps its command's label.
|
||||
app.run("toolbar.renameCommand", json!({"command": "object.group", "toolbar": "Mine"})).unwrap();
|
||||
app.ui.dialog.as_mut().unwrap().fields.insert("label".into(), json!("Grp"));
|
||||
app.run("window.workspace.new", json!({"name": "Inking"})).unwrap();
|
||||
assert!(app.ui.dialog.is_none(), "New Workspace closes the dialog");
|
||||
assert!(crate::custom_toolbars::confirm_rename(&mut app).is_err());
|
||||
assert!(mine_labels(&app).is_empty(), "Inking's Mine keeps its command's label");
|
||||
}
|
||||
@@ -630,7 +630,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"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)",
|
||||
"{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` (or with null), 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, or only the label when it is the command's label or 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",
|
||||
|
||||
@@ -276,10 +276,21 @@ pub fn apply(ui: &mut UiState, w: &Workspace) {
|
||||
if ui.drawer_toolbar.take().is_some() {
|
||||
ui.tools_drawer = false;
|
||||
}
|
||||
// Reset Workspace stays in the same workspace and keeps its toolbars, so Rename Button stays open.
|
||||
if !ui.workspace.eq_ignore_ascii_case(&w.name) {
|
||||
close_rename_button(ui);
|
||||
}
|
||||
ui.flyout = None;
|
||||
ui.workspace = w.name.clone();
|
||||
}
|
||||
|
||||
/// Closes the Rename Button dialog, which names a button on a toolbar of the workspace being left.
|
||||
fn close_rename_button(ui: &mut UiState) {
|
||||
if ui.dialog.as_ref().is_some_and(|d| d.kind == crate::custom_toolbars::RENAME) {
|
||||
ui.dialog = None;
|
||||
}
|
||||
}
|
||||
|
||||
/// Keep the layout of the current workspace as it is now, so switching back brings it back.
|
||||
fn remember(ui: &mut UiState) {
|
||||
// Kept under the saved workspace's spelling, which `find_saved` matches whatever the case.
|
||||
@@ -358,6 +369,7 @@ pub fn save_as(ui: &mut UiState, name: &str) -> Result<(), String> {
|
||||
// saved starts with a copy of.
|
||||
if !ui.workspace.eq_ignore_ascii_case(name) {
|
||||
keep_toolbars(ui);
|
||||
close_rename_button(ui);
|
||||
}
|
||||
// A user workspace of that name in another case is replaced, as `find_saved` would find it.
|
||||
let w = capture(ui, name);
|
||||
|
||||
@@ -492,7 +492,8 @@ no longer installed keeps its button, dimmed, and `toolbar.removeCommand` still
|
||||
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
|
||||
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. 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.
|
||||
|
||||
+2
-1
@@ -3697,7 +3697,8 @@ 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
|
||||
again. Without `label`, or with a null one, `toolbar.renameCommand` opens the Rename Button dialog and answers null.
|
||||
The dialog's Label field takes the keyboard focus, and switching workspaces or New Workspace closes the dialog. 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
|
||||
|
||||
@@ -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, 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`).
|
||||
- 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, or only the label when it is the command's label or full 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`, `switching_workspaces_closes_rename_button`). 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