Actions
An Action carries the application’s message. One definition feeds
menus, toolbars, shortcuts, footer hints, and the command palette.
update decides what happens when that message arrives.
key::handle plus KeyContext is the default path. An open modal
consumes (even if a field is focused). Set KeyContext.modal_open
from menu_bar / drop_menu on_open (true on open, false on
Escape or a pick). Otherwise focused text owns
unmodified typing. Otherwise the focused focus::target owns arrows,
Page, Home, End, Enter, and Space. Wrap the window view with
focus::cycle so Tab walks those targets. run! already listens;
implement From<keyboard::Event> on the application message so
handle still sees Save.
#![allow(unused)]
fn main() {
use icedtea::action::{Action, ActionTable};
use icedtea::key::{handle, KeyContext};
use icedtea::shortcut::Shortcut;
let mut table = ActionTable::new();
table.insert(
Action::new("file.save", "Save", "saved")
.with_shortcut(Shortcut::parse("ctrl+s").unwrap()),
);
assert_eq!(table.invoke("file.save"), Some("saved"));
let _ = handle;
let _ = KeyContext::default();
}
Write ctrl+s once. icedtea stores Command on macOS and Control on
Linux and Windows; menus print that host form.
First window is that Save path: the toolbar row and
ctrl+s both send Message::Save.
key::typed and key::press read what the user typed: Shift+8 is
*, not 8. F1-F24 are Press::Function. Control, alt, and logo
chords return None from typed / press so handle still owns
them.
ActionTable::conflicts reports duplicate shortcuts in the same
context. with_sequence plus key::SequenceBuffer is ctrl+k then
g. handle_in takes a keymap context. The palette keeps recent and
favorites. pattern::cheatsheet lists the
table.
Own stack
dispatch / KeyLayer are for an application that builds its own
layer list. Most windows only need key::handle and KeyContext.
pattern::context_menu places the same Action list under the
pointer. The application stores the point and whether the menu is
open. Click-away and Escape close it. Empty-space right-click is
layout::listen_cursor (including when an editor captured the press).
List, table, grid, and tree rows emit ItemClick; secondary on an
already-selected row keeps the selection. Editors enable Cut/Copy
from text_editor::Content::selection.
Subscribe with key::listen and map events into update, as
examples/hello.rs does.
When a text field is focused, plain typing is not matched against the
action table. Modifier chords (ctrl/alt/logo) still are. For
Enter, Escape, and F1–F24 while typing (activate selection, cancel,
function chords), set
KeyContext { text_input_focused: true, ..Default::default() }.chrome_over_input()
so those bare keys match too (key::WhileInput::Chrome).