Expand description
ShortcutSettings: the user-facing panel for browsing and rebinding an application’s shortcuts.
It lists every shortcut in the tree’s
ShortcutRegistry, grouped
by category, one row per command:
[ Search commands or keys ] [⌨] [ ] Modified only [Reset all…]
File
New project [Ctrl] [N] +
Open… [Ctrl] [O] +
● Save [Ctrl] [Shift] [S] [Ctrl] [S] ↺
Format
Bold ( Press keys… ) +
Press the new shortcut. Esc cancels, Del removes it.- The chord is the control. Each chord is drawn as key caps; click
it (or focus it and press Enter or Space) to record a new one. The
first column is the shortcut, the second its alternative (
+adds one). Delete or Backspace on a focused chord removes it. - Recording shows “Press keys…” in a field the width of its column, so the list never reflows. Escape or Tab cancels; Delete or Backspace removes the chord; leaving the field cancels too. A key that cannot be a shortcut is refused with the reason, and recording goes on: a printable key needs Ctrl, Alt or ⌘ (Shift alone types a capital), and chords the system keeps (Alt+F4, Alt+Tab, ⌘Tab, ⌘Space, …) and Ctrl+Tab (the way out of a control that keeps Tab) are reserved.
- Conflicts are confirmed. A chord another command already uses
is not taken from it until the user presses “Reassign” on the line
that appears under the row.
confirm_conflicts(false)reassigns at once instead; either wayon_conflictis told. - Changed rows are marked with a dot and get a reset button, which puts that command’s declared defaults back. “Reset all…” in the toolbar does it for every command, after a confirmation.
- Search matches a command’s name, its group, its description and the text of its chords (“ctrl+s” finds Save). The keyboard button next to the field finds by chord instead: press it, press the keys, and the list shows the commands that use exactly that chord. “Modified only” narrows the list to the commands the user changed.
Commands are sorted by name within a group and groups by their title, both in the interface language. Every visible string comes from the framework’s locale bundles.
Keyboard. The list is one Tab stop. The arrow keys move between rows and between a row’s chord, alternative and reset button; Home and End go to the first and last row. Every control carries its command in its accessible name (“Save: Ctrl+S”), its description and whether the user changed it in its description, and the group titles are headings.
The widget owns the armed key capture. Dropping the widget cancels it, so navigating away mid-recording cannot rebind the next key pressed somewhere else.
The list grows with its content and does not scroll; place the widget
in a ScrollArea when there are more shortcuts than fit.
// Inside a settings Dialog build():
ctx.add(
ShortcutSettings::new()
.on_conflict(|c| println!("{} loses its shortcut", c.displaced_name)),
);Structs§
- Shortcut
Conflict - Describes a rebind that collides with an existing binding.
- Shortcut
Settings - A settings panel for browsing and rebinding application shortcuts.