From 08445f8c8792121d6e792f0e39ec99ce7909a365 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sat, 21 Nov 2026 13:32:34 +0700 Subject: [PATCH] Contract stubs: craft-menu, craft-print, craft-table, craft-automation --- Cargo.lock | 1 + crates/automation/Cargo.toml | 13 +++-- crates/automation/src/access.rs | 69 +++++++++++++++++++++++ crates/automation/src/actions/list.rs | 15 +++++ crates/automation/src/actions/model.rs | 4 ++ crates/automation/src/control.rs | 2 +- crates/automation/src/dialogs.rs | 3 + crates/automation/src/lib.rs | 16 +++--- crates/automation/src/screenshot.rs | 3 +- crates/automation/src/synthetic.rs | 34 +++++++---- crates/automation/src/ui/actions/mod.rs | 4 +- crates/automation/src/ui/actions/panel.rs | 23 ++++++++ crates/automation/tests/it/synthetic.rs | 4 +- crates/menu/src/bar.rs | 5 +- crates/menu/src/context.rs | 3 +- crates/menu/src/driver.rs | 12 ++++ crates/menu/src/mac.rs | 1 + crates/menu/src/model.rs | 28 +++++++-- crates/menu/src/palette.rs | 2 +- crates/menu/src/shortcuts/mod.rs | 33 +++++++++-- crates/menu/src/shortcuts/pages.rs | 6 ++ crates/menu/src/shortcuts/state.rs | 42 ++++++++++++-- crates/print/src/ui/mod.rs | 8 +++ crates/table/src/ui/grid.rs | 16 ++++++ crates/table/src/ui/mod.rs | 4 +- 25 files changed, 305 insertions(+), 46 deletions(-) create mode 100644 crates/automation/src/access.rs diff --git a/Cargo.lock b/Cargo.lock index 7fc61e0bf..bdf41ac47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2070,6 +2070,7 @@ dependencies = [ "sha2 0.10.9", "tempfile", "thiserror 2.0.21", + "web-time", ] [[package]] diff --git a/crates/automation/Cargo.toml b/crates/automation/Cargo.toml index 9e4e079df..0fb000258 100644 --- a/crates/automation/Cargo.toml +++ b/crates/automation/Cargo.toml @@ -40,16 +40,17 @@ craft-ui = { workspace = true, optional = true } egui = { workspace = true, optional = true } serde = { workspace = true } serde_json = { workspace = true } - -# The control channel, its server and client, screenshots, the profiler and the trace. -[target.'cfg(not(target_arch = "wasm32"))'.dependencies] base64 = "0.22" -craft-platform = { workspace = true } craft-host = { workspace = true, optional = true } -getrandom = "0.3" -hmac = "0.12" +craft-platform = { workspace = true } log = "0.4" png = "0.17" +web-time = "1.1" + +# The control channel's server and client, the profiler and the trace. +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +getrandom = "0.3" +hmac = "0.12" sha2 = { version = "0.10", default-features = false, features = ["std"] } thiserror = { workspace = true } diff --git a/crates/automation/src/access.rs b/crates/automation/src/access.rs new file mode 100644 index 000000000..5b895a5be --- /dev/null +++ b/crates/automation/src/access.rs @@ -0,0 +1,69 @@ +//! Named controls over the window's access tree: the controls a client finds by name and role, describes, and places +//! a pointer on. Built with the in-process channel, under the `ui` feature. + +use craft_ui::runtime::egui::access::{AccessTree, NodeKey}; +use craft_ui::runtime::windows::WindowHost; +use egui::ViewportId; +use serde_json::Value; + +/// The error of a request made before the first kept pass has an access tree. +pub const NO_TREE: &str = "the window has no access tree yet"; + +/// The error of a target no control matches. +pub const NO_CONTROL: &str = "no control matches the target"; + +/// The error of a target several controls match, with no `index`. +pub const AMBIGUOUS: &str = "more than one control matches the target; add `index`, `role` or `within`"; + +/// The error of a control with no bounds to place a point on. +pub const NO_PLACE: &str = "the control has no bounds to place a point on"; + +/// The largest `index` a target takes. +pub const MAX_INDEX: usize = 1024; + +/// A control named by `{name, role?, within?, index?}`. +/// +/// A name match ignores surrounding white space and one trailing `:`; `role` is an AccessKit role name, compared +/// ignoring case; `within` is the name of any matching ancestor. Without `index` exactly one control matches; the +/// reading order is depth first. +#[derive(Clone, Debug, PartialEq)] +#[non_exhaustive] +pub struct Target { + /// The control's accessible name. + pub name: String, + /// The control's role. + pub role: Option, + /// The name of an ancestor the control is inside. + pub within: Option, + /// Which match to take, in reading order. + pub index: Option, +} + +impl Target { + /// The target `value` names: `{name, role?, within?, index?}` and no other field. + pub fn from_params(value: &Value) -> Result { + let _ = value; + todo!("wg.W51") + } + + /// The control of `tree` this target names: [`NO_CONTROL`] when none matches, [`AMBIGUOUS`] when several do and + /// there is no `index`. + pub fn find(&self, tree: &AccessTree) -> Result { + let _ = tree; + todo!("wg.W51") + } +} + +/// What `ui.find` answers for the control `key`: `{name, role, rect or null, enabled, focused, value?, numeric?, +/// expanded?, selected?, toggled?}`, the rect in screen points. +pub fn describe(tree: &AccessTree, key: NodeKey) -> Value { + let _ = (tree, key); + todo!("wg.W52") +} + +/// Runs the access method `method` with `params` in `viewport` from the tree the host kept ([`NO_TREE`] before the +/// first); `None` for a method this module does not have. +pub fn access_method(method: &str, params: &Value, host: &WindowHost, viewport: ViewportId) -> Option> { + let _ = (method, params, host, viewport); + todo!("wg.W52") +} diff --git a/crates/automation/src/actions/list.rs b/crates/automation/src/actions/list.rs index 9415f9d85..5241e6926 100644 --- a/crates/automation/src/actions/list.rs +++ b/crates/automation/src/actions/list.rs @@ -457,6 +457,21 @@ impl ActionList { Ok(()) } + /// Renames the set `set` to `name` (trimmed) in the order and in every member's `set`: [`ActionListError::EmptyName`] + /// for an empty name, [`ActionListError::NameTaken`] for a name another set has, [`ActionListError::NoSuchSet`] for an + /// unknown set. The same name succeeds and changes nothing. + pub fn rename_set(&mut self, set: &str, name: &str) -> Result<(), ActionListError> { + let _ = (set, name); + todo!("mn.M50") + } + + /// Removes the set `set` from the order and its actions from the list, and returns the actions in list order: + /// [`ActionListError::NoSuchSet`] for an unknown set. + pub fn delete_set(&mut self, set: &str) -> Result, ActionListError> { + let _ = set; + todo!("mn.M51") + } + /// Duplicates the set `set` under a unique name and returns that name; `shift` is as for /// [`duplicate_action`](Self::duplicate_action). The copies of its actions go after its last /// action; a set with none becomes an empty set after it. diff --git a/crates/automation/src/actions/model.rs b/crates/automation/src/actions/model.rs index 247d9f4d1..09b3b6df1 100644 --- a/crates/automation/src/actions/model.rs +++ b/crates/automation/src/actions/model.rs @@ -161,6 +161,10 @@ pub struct Action { /// Written by an automation client: playback keeps that client's gate. #[serde(default, skip_serializing_if = "std::ops::Not::not")] pub automation: bool, + /// The app's own options for the action. The framework never reads them; every edit, duplicate, move, merge and + /// the file keep them. + #[serde(default, skip_serializing_if = "serde_json::Map::is_empty")] + pub options: serde_json::Map, } fn is_no_color(color: &ActionColor) -> bool { diff --git a/crates/automation/src/control.rs b/crates/automation/src/control.rs index c0f594251..484e6d512 100644 --- a/crates/automation/src/control.rs +++ b/crates/automation/src/control.rs @@ -14,11 +14,11 @@ //! two happened, once, between the UI thread and the transport. use std::sync::mpsc::{Receiver, Sender}; -use std::time::Instant; use craft_ui::runtime::motion; use craft_ui::runtime::windows::WindowHost; use serde_json::{Value, json}; +use web_time::Instant; use crate::screenshot::{Captures, DocumentId, Finished, ScreenshotRequest, screenshot_reply}; use crate::synthetic::TARGET_CHANGED; diff --git a/crates/automation/src/dialogs.rs b/crates/automation/src/dialogs.rs index 62fc0b268..af05bd59e 100644 --- a/crates/automation/src/dialogs.rs +++ b/crates/automation/src/dialogs.rs @@ -12,6 +12,9 @@ use serde_json::{Value, json}; use crate::protocol::Params; +/// The most `fields` one `ui.dialog.set` call takes. +pub const MAX_DIALOG_FIELDS: usize = 256; + /// The open dialogs, the top one last: `{id, parent, key, fields}`, `null` for a missing parent, key or fields. Ids /// are 64-bit hashes, so they are listed as decimal strings, which every JSON reader keeps exact. pub fn inspect(host: &DialogHost) -> Value { diff --git a/crates/automation/src/lib.rs b/crates/automation/src/lib.rs index 52e967ead..ff250e33b 100644 --- a/crates/automation/src/lib.rs +++ b/crates/automation/src/lib.rs @@ -21,21 +21,22 @@ pub mod agents; #[cfg(feature = "ui")] pub mod ui; +#[cfg(feature = "ui")] +pub mod access; #[cfg(not(target_arch = "wasm32"))] pub mod args; -#[cfg(all(feature = "ui", not(target_arch = "wasm32")))] +#[cfg(feature = "ui")] pub mod control; -#[cfg(all(feature = "ui", not(target_arch = "wasm32")))] +#[cfg(feature = "ui")] pub mod dialogs; #[cfg(not(target_arch = "wasm32"))] pub mod profiler; -#[cfg(not(target_arch = "wasm32"))] pub mod protocol; -#[cfg(all(feature = "ui", not(target_arch = "wasm32")))] +#[cfg(feature = "ui")] pub mod screenshot; #[cfg(not(target_arch = "wasm32"))] pub mod security; -#[cfg(all(feature = "ui", not(target_arch = "wasm32")))] +#[cfg(feature = "ui")] pub mod synthetic; #[cfg(not(target_arch = "wasm32"))] pub mod trace; @@ -45,11 +46,10 @@ pub mod client; #[cfg(all(feature = "ui", not(target_arch = "wasm32")))] pub mod server; -#[cfg(all(feature = "ui", not(target_arch = "wasm32")))] +#[cfg(feature = "ui")] pub use control::{ControlChannel, ControlRequest, ControlResponse, Dispatch, Reply}; -#[cfg(not(target_arch = "wasm32"))] pub use protocol::REPLY_DEADLINE; -#[cfg(all(feature = "ui", not(target_arch = "wasm32")))] +#[cfg(feature = "ui")] pub use screenshot::Captures; #[cfg(not(target_arch = "wasm32"))] pub use security::AutomationError; diff --git a/crates/automation/src/screenshot.rs b/crates/automation/src/screenshot.rs index f3456c521..2c65e2944 100644 --- a/crates/automation/src/screenshot.rs +++ b/crates/automation/src/screenshot.rs @@ -18,11 +18,12 @@ use std::collections::HashMap; use std::sync::Arc; use std::sync::mpsc::Sender; -use std::time::{Duration, Instant}; +use std::time::Duration; use base64::Engine as _; use craft_ui::runtime::windows::{ScreenshotFacts, ScreenshotSlot, WindowHost}; use egui::{ColorImage, ViewportId}; +use web_time::Instant; use crate::control::ControlResponse; diff --git a/crates/automation/src/synthetic.rs b/crates/automation/src/synthetic.rs index 90e16fc1b..de99fbd9c 100644 --- a/crates/automation/src/synthetic.rs +++ b/crates/automation/src/synthetic.rs @@ -20,10 +20,12 @@ use craft_behavior::PointerButton; use craft_keymap::{Key, Mods}; +use craft_ui::runtime::egui::access::AccessTree; use craft_ui::runtime::windows::{Released, WindowHost}; use egui::{Pos2, Vec2, ViewportId, pos2, vec2}; use serde_json::Value; +use crate::access; use crate::protocol::{BUTTONS, KEY_MODIFIERS, Params}; /// Most clicks one `ui.click` may ask for (`count`). @@ -53,14 +55,22 @@ pub const NOT_FINITE: &str = "the point must be finite"; /// shows a document. Applications without documents pass `&|_| None`. pub type DocumentMap<'a> = &'a dyn Fn(Pos2) -> Option; -/// A point of a request: screen points, or document points the application maps. -#[derive(Clone, Copy, Debug, PartialEq)] +/// A point of a request: screen points, document points the application maps, or an offset from a named control. +#[derive(Clone, Debug, PartialEq)] #[non_exhaustive] pub enum At { /// Screen points. Screen(Pos2), /// Document points. Document(Pos2), + /// An offset from the centre of the rect of the control `target` names. + #[non_exhaustive] + Control { + /// The control. + target: access::Target, + /// The offset from the rect's centre. + offset: Vec2, + }, } impl At { @@ -77,8 +87,10 @@ impl At { /// The screen point, through `map` for a document point; [`NO_DOCUMENT`] when the map has none, and /// [`OFF_SCREEN`] when it maps beyond [`MAX_SCREEN_POINT`]; a point that is not finite is [`NOT_FINITE`]. - pub fn resolve(self, map: DocumentMap<'_>) -> Result { - match self { + pub fn resolve(&self, map: DocumentMap<'_>, tree: Option<&AccessTree>) -> Result { + let _ = tree; // P3(widgets-w8): wg.W53 + match *self { + Self::Control { .. } => todo!("wg.W53"), Self::Screen(at) if at.x.is_finite() && at.y.is_finite() => Ok(at), Self::Screen(_) => Err(NOT_FINITE.to_owned()), Self::Document(at) if !(at.x.is_finite() && at.y.is_finite()) => Err(NOT_FINITE.to_owned()), @@ -156,7 +168,7 @@ impl Click { /// Queues a move to the target, then `count` presses and releases of the button, in `viewport`. pub fn inject(&self, host: &WindowHost, viewport: ViewportId, map: DocumentMap<'_>) -> Result<(), String> { let count = u32::try_from(self.count).unwrap_or(u32::MAX); - host.inject_click(viewport, self.at.resolve(map)?, self.button, count, self.mods, self.hold); + host.inject_click(viewport, self.at.resolve(map, None)?, self.button, count, self.mods, self.hold); // P3(widgets-w8): wg.W53 Ok(()) } } @@ -187,7 +199,7 @@ impl Move { /// Queues the move in `viewport`. pub fn inject(&self, host: &WindowHost, viewport: ViewportId, map: DocumentMap<'_>) -> Result<(), String> { - host.inject_move(viewport, self.at.resolve(map)?, self.mods, self.rest); + host.inject_move(viewport, self.at.resolve(map, None)?, self.mods, self.rest); // P3(widgets-w8): wg.W53 Ok(()) } } @@ -200,6 +212,8 @@ pub struct Wheel { pub at: At, /// The scroll in points, as egui reports it (positive `y` scrolls towards the content's top). pub delta: Vec2, + /// Whether `delta` is in points or in whole notches of lines. + pub unit: egui::MouseWheelUnit, /// Modifiers held from the turn on. pub mods: Mods, } @@ -211,12 +225,12 @@ impl Wheel { let p = Params(&p); let dx = p.number_in("dx", "dx", None)?.unwrap_or(0.0) as f32; let dy = p.number_in("dy", "dy", None)?.unwrap_or(0.0) as f32; - Ok(Self { at: At::from_params(&p)?, delta: vec2(dx, dy), mods: p.modifiers(&KEY_MODIFIERS)? }) + Ok(Self { at: At::from_params(&p)?, delta: vec2(dx, dy), unit: egui::MouseWheelUnit::Point, mods: p.modifiers(&KEY_MODIFIERS)? }) } /// Queues the move and the turn in `viewport`. pub fn inject(&self, host: &WindowHost, viewport: ViewportId, map: DocumentMap<'_>) -> Result<(), String> { - host.inject_wheel(viewport, self.at.resolve(map)?, self.delta, self.mods); + host.inject_wheel(viewport, self.at.resolve(map, None)?, self.delta, self.unit, self.mods); // P3(widgets-w8): wg.W53, sh.K4 Ok(()) } } @@ -250,7 +264,7 @@ impl KeyPress { } /// A validated `ui.release`. -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq)] #[non_exhaustive] pub struct Release { /// Where the release happens; where the pointer is when absent. @@ -277,7 +291,7 @@ impl Release { /// Queues the release in `viewport`. pub fn inject(&self, host: &WindowHost, viewport: ViewportId, map: DocumentMap<'_>) -> Result<(), String> { - let at = self.at.map(|at| at.resolve(map)).transpose()?; + let at = self.at.as_ref().map(|at| at.resolve(map, None)).transpose()?; // P3(widgets-w8): wg.W53 host.inject_release(viewport, at, self.released); Ok(()) } diff --git a/crates/automation/src/ui/actions/mod.rs b/crates/automation/src/ui/actions/mod.rs index 2b9ed4304..e8fe4d797 100644 --- a/crates/automation/src/ui/actions/mod.rs +++ b/crates/automation/src/ui/actions/mod.rs @@ -23,7 +23,9 @@ mod words; pub use body::{ActionMove, ActionPlace}; pub use menu::{ActionsMenuAction, ActionsMenuFacts, ActionsPanelCommands, panel_rows}; -pub use panel::{ActionSelection, ActionsEvent, ActionsHost, ActionsPanel, ActionsPanelOutput, ActionsPanelState, ActionsSettings, ShortcutChoice}; +pub use panel::{ + ActionSelection, ActionsEvent, ActionsHost, ActionsPanel, ActionsPanelOutput, ActionsPanelState, ActionsSettings, ShortcutChoice, StepCells, +}; pub use prompt::LibraryPrompt; pub use rows::{DIALOG_COLUMN, INCLUDE_COLUMN}; pub use words::ActionsWords; diff --git a/crates/automation/src/ui/actions/panel.rs b/crates/automation/src/ui/actions/panel.rs index 8429d5025..5807ca44a 100644 --- a/crates/automation/src/ui/actions/panel.rs +++ b/crates/automation/src/ui/actions/panel.rs @@ -98,6 +98,20 @@ pub struct ActionsPanelState { pub selected: Option, /// The expanded actions, by name (names are unique, so expansion survives moves). pub expanded: BTreeSet, + /// The sets a shift-click selected, from the current set to the clicked one, in the set order; empty when there is + /// no range. + pub selected_sets: Vec, +} + +/// Which step cells the rows show. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] +#[non_exhaustive] +pub enum StepCells { + /// The include cell and the dialog cell. + #[default] + IncludeAndDialog, + /// The include cell only: the dialog column is left out of the cells and the list's columns. + Include, } /// A function-key shortcut chosen in the context menu (Photoshop's Action Options). @@ -235,6 +249,8 @@ pub enum ActionsEvent { /// Duplicate this row ([`ActionList::duplicate_action`], [`ActionList::duplicate_step`], /// [`ActionList::duplicate_set`]): from the menu row or a row dropped on New Action. Duplicate(ActionSelection), + /// Delete with a range of sets selected: the range, in one event, so the app asks one question. + DeleteSets(Vec), /// Record Again: replace step `step` of `action` with a new recording /// ([`ActionList::replace_step`]). #[non_exhaustive] @@ -395,6 +411,13 @@ impl<'a> ActionsPanel<'a> { self } + /// Which step cells the rows show. + #[must_use] + pub fn step_cells(self, cells: StepCells) -> Self { + let _ = cells; + todo!("mn.M40") + } + /// Whether the panel takes input (default true). pub fn enabled(mut self, enabled: bool) -> Self { self.enabled = enabled; diff --git a/crates/automation/tests/it/synthetic.rs b/crates/automation/tests/it/synthetic.rs index 9452879ae..cdc07374a 100644 --- a/crates/automation/tests/it/synthetic.rs +++ b/crates/automation/tests/it/synthetic.rs @@ -410,8 +410,8 @@ fn ui_ime_reaches_a_focused_text_field_as_a_preedit_then_a_commit_in_order() { fn a_point_that_is_not_finite_is_refused() { for bad in [f32::NAN, f32::INFINITY, f32::NEG_INFINITY] { for at in [At::Screen(pos2(bad, 1.0)), At::Screen(pos2(1.0, bad)), At::Document(pos2(bad, 1.0))] { - assert_eq!(at.resolve(&|p| Some(p)), Err(NOT_FINITE.to_owned()), "{at:?}"); + assert_eq!(at.resolve(&|p| Some(p), None), Err(NOT_FINITE.to_owned()), "{at:?}"); // P3(widgets-w8): wg.W53 } } - assert_eq!(At::Screen(pos2(3.0, 4.0)).resolve(&|_| None), Ok(pos2(3.0, 4.0))); + assert_eq!(At::Screen(pos2(3.0, 4.0)).resolve(&|_| None, None), Ok(pos2(3.0, 4.0))); // P3(widgets-w8): wg.W53 } diff --git a/crates/menu/src/bar.rs b/crates/menu/src/bar.rs index 3907b35de..7d9e668ad 100644 --- a/crates/menu/src/bar.rs +++ b/crates/menu/src/bar.rs @@ -63,6 +63,9 @@ pub struct MenuBarOutput { /// The menu titles alone, without the room the bar leaves after them /// ([`craft_ui::menu::MenuBarOutput::titles`]). pub titles: Rect, + /// True in the one pass where a menu of the bar opened while none was open + /// ([`craft_ui::menu::MenuBarOutput::opened`]). + pub opened: bool, } /// The bar for one frame: `MenuBarUi::new(&bar).show(ui)`. Draw it at the top of the window, in a top panel. @@ -143,6 +146,6 @@ impl<'a> MenuBarUi<'a> { if let Some(menu) = help { bar = bar.help(MenuHelp::new(menu, &entries)); } - MenuBarOutput { titles: bar.show(ui).titles } + MenuBarOutput { titles: bar.show(ui).titles, opened: false } // P3(menus-w3): mn.M26 } } diff --git a/crates/menu/src/context.rs b/crates/menu/src/context.rs index 7e1dfd667..ddf69cd5a 100644 --- a/crates/menu/src/context.rs +++ b/crates/menu/src/context.rs @@ -136,6 +136,7 @@ impl<'a> Rows<'a> { Menu::submenu_row(ui, label, |ui, _| self.show(ui, children)); } } + Node::Heading(_) => todo!("mn.M7"), Node::Standard { .. } => {} } } @@ -213,7 +214,7 @@ fn is_dead(nodes: &[Node]) -> bool { !nodes.iter().any(|node| match node { Node::Item(item) => item.enabled, Node::Submenu { children, .. } => !is_dead(children), - Node::Separator | Node::Standard { .. } => false, + Node::Separator | Node::Heading(_) | Node::Standard { .. } => false, }) } diff --git a/crates/menu/src/driver.rs b/crates/menu/src/driver.rs index 2d2c0c347..ac076caec 100644 --- a/crates/menu/src/driver.rs +++ b/crates/menu/src/driver.rs @@ -27,6 +27,8 @@ pub enum Event { /// A click the app's [`NativeMenu::on_command`] hook ran; [`NativeMenu::take_clicks`] leaves it /// out. Handled(CommandRef), + /// The platform began tracking a native menu. + Opened, } /// How ⌘C, ⌘X and ⌘V reach egui when the native menu takes them as key equivalents (an Edit @@ -222,6 +224,9 @@ pub struct NativeMenu { /// The commands whose items were check items in a layout so far: they stay check items, so /// that `checked` going from `Some` to `None` doesn't rebuild the menus. checkable: HashSet, + /// A backend reported [`Event::Opened`] since [`NativeMenu::take_opened`] last answered. + #[allow(dead_code)] // P3(menus-w1): mn.M10 + opened: bool, } impl NativeMenu { @@ -244,6 +249,7 @@ impl NativeMenu { bar: None, synced_gate: None, checkable: HashSet::new(), + opened: false, } } @@ -338,11 +344,17 @@ impl NativeMenu { Event::Tap(chord) => self.add_key(&host, &chord, true), Event::Click(command) => self.clicks.push(command), Event::Handled(_) => {} + Event::Opened => todo!("mn.M10"), } self.dirty = true; } } + /// Whether a backend reported [`Event::Opened`] since the last call; reports it once and clears it. + pub fn take_opened(&mut self) -> bool { + todo!("mn.M10") + } + /// `tap`: a press and its release, for a click that stands for the key (no key-up follows). fn add_key(&mut self, host: &WindowHost, chord: &Chord, tap: bool) { let clipboard = self.clipboard == ClipboardKeys::Egui && chord.mods == Mods::CMD && !self.gate.recording_shortcut; diff --git a/crates/menu/src/mac.rs b/crates/menu/src/mac.rs index 5223bfa78..1326ea5e6 100644 --- a/crates/menu/src/mac.rs +++ b/crates/menu/src/mac.rs @@ -174,6 +174,7 @@ fn lower_nodes(nodes: &[Node], targets: &mut HashMap) -> Vec native::Node::Separator, Node::Submenu { label, children, .. } => native::Node::Submenu { label: label.clone(), children: lower_nodes(children, targets) }, + Node::Heading(_) => todo!("mn.M9"), Node::Standard { kind, label } => native::Node::Platform { kind: match kind { Standard::Services => native::Platform::Services, diff --git a/crates/menu/src/model.rs b/crates/menu/src/model.rs index d0955032b..ba537791f 100644 --- a/crates/menu/src/model.rs +++ b/crates/menu/src/model.rs @@ -6,6 +6,7 @@ use std::ops::BitOr; use craft_keymap::{Chord, CommandRef, Mods}; use craft_theme::Srgba; +use craft_ui::primitives::FacePaint; /// The app's menus, in order, and its open documents. #[derive(Clone, Debug, Default, PartialEq)] @@ -151,6 +152,8 @@ pub enum Node { /// The platforms it is shown on. platforms: Platforms, }, + /// A caption over the rows that follow it. Never a command. + Heading(String), /// An item AppKit provides and runs itself (Services, Zoom, …), with the label to show. #[non_exhaustive] Standard { @@ -194,6 +197,9 @@ pub struct Item { pub tooltip: Option, /// The command the item runs instead while its modifiers are held as it is chosen. pub alternate: Option, + /// A small painted sample shown in the row (in-window bar only; the native menu ignores it, as it + /// ignores `tint`). + pub sample: Option, } /// The command a row runs while `mods` are held as it is chosen (Alt on Merge Visible runs Stamp @@ -362,6 +368,7 @@ impl Item { tint: None, tooltip: None, alternate: None, + sample: None, } } @@ -418,6 +425,12 @@ impl Item { self.tooltip = Some(text.into()); self } + + /// Show `sample` in the row, painted by the in-window bar. + pub fn sample(self, sample: FacePaint) -> Item { + let _ = sample; + todo!("mn.M6") + } } impl From for Node { @@ -437,12 +450,18 @@ impl Node { Node::Submenu { label: label.into(), children, role: None, platforms: Platforms::ALL } } + /// A caption over the rows that follow it. + pub fn heading(label: impl Into) -> Node { + let _ = label; + todo!("mn.M2") + } + /// Give an item or a submenu a role: `Node::submenu("Theme", pages).role(ItemRole::Appearance)`. pub fn role(mut self, role: ItemRole) -> Node { match &mut self { Node::Item(it) => it.role = Some(role), Node::Submenu { role: r, .. } => *r = Some(role), - Node::Separator | Node::Standard { .. } => {} + Node::Separator | Node::Heading(_) | Node::Standard { .. } => {} } self } @@ -452,7 +471,7 @@ impl Node { match &mut self { Node::Item(it) => it.platforms = platforms, Node::Submenu { platforms: p, .. } => *p = platforms, - Node::Separator | Node::Standard { .. } => {} + Node::Separator | Node::Heading(_) | Node::Standard { .. } => {} } self } @@ -490,7 +509,7 @@ impl MenuBar { match n { Node::Item(it) => out.push(it), Node::Submenu { children, .. } => walk(children, out), - Node::Separator | Node::Standard { .. } => {} + Node::Separator | Node::Heading(_) | Node::Standard { .. } => {} } } } @@ -508,7 +527,7 @@ impl MenuBar { match n { Node::Item(it) => f(it), Node::Submenu { children, .. } => walk(children, f), - Node::Separator | Node::Standard { .. } => {} + Node::Separator | Node::Heading(_) | Node::Standard { .. } => {} } } } @@ -770,6 +789,7 @@ fn hash_nodes(nodes: &[Node], h: &mut DefaultHasher) { ']'.hash(h); } Node::Standard { kind, label } => ('s', kind, label).hash(h), + Node::Heading(_) => todo!("mn.M4"), } } } diff --git a/crates/menu/src/palette.rs b/crates/menu/src/palette.rs index 07e2ab657..1303a1498 100644 --- a/crates/menu/src/palette.rs +++ b/crates/menu/src/palette.rs @@ -53,7 +53,7 @@ fn collect(nodes: &[Node], path: &mut Vec, english_of: &dyn Fn(Labeled<' collect(children, path, english_of, entries); path.pop(); } - Node::Item(_) | Node::Separator | Node::Standard { .. } => {} + Node::Item(_) | Node::Separator | Node::Heading(_) | Node::Standard { .. } => {} } } } diff --git a/crates/menu/src/shortcuts/mod.rs b/crates/menu/src/shortcuts/mod.rs index 6c08bb9d3..b79188aef 100644 --- a/crates/menu/src/shortcuts/mod.rs +++ b/crates/menu/src/shortcuts/mod.rs @@ -33,7 +33,7 @@ //! Some(Outcome::Import { formats, .. }) => self.pick_import_file(formats), //! Some(Outcome::Export { name, json, .. }) => self.save_file(&name, json), //! Some(Outcome::Summary { name, html, .. }) => self.show_summary(&name, html), -//! Some(Outcome::Remembered(answers)) => self.settings.import_answers.extend(answers), +//! Some(Outcome::Remembered { targets, codes }) => self.settings.import_answers.extend(targets, codes), //! _ => {} //! } //! if !state.is_open() { @@ -52,7 +52,7 @@ //! | `Import { formats }` | Opens a file of one of the formats, then calls [`ShortcutsDialog::import_json`] (craft-keymap JSON, [`JSON_FORMAT`]) or reads it into a `ForeignSet` and calls [`ShortcutsDialog::review_import`]. | //! | `Export { name, json }`, `ExportAs { format, name, keymap }` | Writes the set where the user chooses (a download on the web). | //! | `Summary { name, html, text }` | Shows, saves or prints the summary. | -//! | `Remembered(answers)` | Keeps the user's import answers for the next import (`ImportOptions::remembered`). | +//! | `Remembered { targets, codes }` | Keeps the user's import answers for the next import (`ImportOptions::remembered` and `ImportOptions::codes`). | //! //! The crate never opens a file dialog or touches the file system. When the app's own step fails //! while the dialog is open (a file it cannot read), [`DialogState::show_error`] shows the @@ -77,6 +77,7 @@ use std::cell::RefCell; use std::collections::BTreeMap; +use std::ops::RangeInclusive; use craft_behavior::edit_history::Step; use craft_keymap::{Binding, Builtins, CommandDef, CommandRef, ForeignSet, ImportOptions, Keymap, ProfileError, Profiles, Trigger}; @@ -172,8 +173,14 @@ pub enum Outcome { /// The summary as plain text. text: String, }, - /// Import answers the user gave (item → command), for the app to keep for later imports. - Remembered(BTreeMap), + /// Import answers the user gave, for the app to keep for later imports. + #[non_exhaustive] + Remembered { + /// The target picked by remember key (`None`: No equivalent), feeding `ImportOptions::remembered`. + targets: BTreeMap>, + /// The answer for each undecided code by `key:N` / `mods:N`, feeding `ImportOptions::codes`. + codes: BTreeMap>, + }, } /// What happens when a recorded chord is held by other commands. @@ -361,6 +368,17 @@ impl craft_ui::contract::Outcome for ShortcutsOutput { } } +/// The Hold Shortcuts setting the dialog shows and edits. +#[derive(Clone, Debug, PartialEq)] +pub struct HoldSetting { + /// Whether hold shortcuts are on. + pub on: bool, + /// The delay, in seconds, before a held key counts as a hold. + pub delay: f64, + /// The delays the field accepts. + pub range: RangeInclusive, +} + /// The dialog for one pass: what it edits, borrowed, and how it behaves. #[must_use = "show the dialog with `show`"] #[derive(Pattern)] @@ -372,6 +390,13 @@ pub struct ShortcutsDialog<'a> { } impl<'a> ShortcutsDialog<'a> { + /// Shows the Hold Shortcuts switch, its delay and the explanation, and a Hold column recorded like the + /// shortcut column. Cancel restores the setting; the app saves it on [`Outcome::Ok`]. + pub fn holds(self, holds: &'a mut HoldSetting) -> Self { + let _ = holds; + todo!("kb.C16a") + } + /// A dialog editing `keymap`; without further builder calls it has no sets and default options. pub fn new(keymap: &'a mut Keymap) -> Self { ShortcutsDialog { keymap, sets: None, options: None, tabs: None } diff --git a/crates/menu/src/shortcuts/pages.rs b/crates/menu/src/shortcuts/pages.rs index 0bd36b084..cbc6361c4 100644 --- a/crates/menu/src/shortcuts/pages.rs +++ b/crates/menu/src/shortcuts/pages.rs @@ -126,6 +126,10 @@ pub struct DialogSnapshot { pub set: Option, /// Whether there is an edit to undo. pub can_undo: bool, + /// Whether Hold Shortcuts is on, with the hold setting shown. + pub holds: Option, + /// The command a hold is being recorded for. + pub recording_hold: Option, } impl DialogState { @@ -149,6 +153,8 @@ impl DialogState { }), set: self.set.clone(), can_undo: self.can_undo(), + holds: None, + recording_hold: None, }) } } diff --git a/crates/menu/src/shortcuts/state.rs b/crates/menu/src/shortcuts/state.rs index 1ef0443d3..0d9178649 100644 --- a/crates/menu/src/shortcuts/state.rs +++ b/crates/menu/src/shortcuts/state.rs @@ -4,7 +4,7 @@ use std::collections::BTreeSet; use craft_keymap::editor::{self, DOUBLE_PRESS, EditSession, Recorded, Recorder}; -use craft_keymap::import::{self, ForeignSet, ImportOptions, ImportPlan, ImportReport}; +use craft_keymap::import::{self, ForeignSet, ImportOptions, ImportPlan, ImportReport, Start}; use craft_keymap::profiles::{Builtins, ProfileError, Profiles, set_name}; use craft_keymap::{ AssignError, Assigned, Binding, BindingError, Chord, CommandRef, Holder, Key, Keymap, MAX_BINDINGS, Overrides, ParseError, Policy, Scope, Trigger, @@ -154,6 +154,12 @@ pub(crate) struct Review { pub name: String, /// After Import as New Set: the set's name and the report. pub done: Option<(String, ImportReport)>, + /// Whether each entry of the set is imported. + #[allow(dead_code)] // P3(shortcuts-w4): kb.C12 + pub included: Vec, + /// The search over label, path and key text. + #[allow(dead_code)] // P3(shortcuts-w4): kb.C12 + pub search: String, } /// The set row's inline form: New Set… or Rename…. @@ -1074,7 +1080,7 @@ impl DialogState { let name = plan.report.set.clone().unwrap_or_else(|| word!(env, imported)); self.stop_recording(); self.conflict = None; - self.review = Some(Review { set, options, plan, name, done: None }); + self.review = Some(Review { set, options, plan, name, done: None, included: Vec::new(), search: String::new() }); } /// Picks candidate `candidate` for suggestion `suggestion`, re-plans, and reports the answers @@ -1084,9 +1090,37 @@ impl DialogState { let Some(s) = r.plan.report.suggestions.get(suggestion) else { return }; let Some(command) = s.candidates.get(candidate).cloned() else { return }; let Some(entry) = r.set.entries.iter().find(|e| e.item() == s.item && e.line == s.line) else { return }; - r.options.remembered.insert(entry.remember_key(), command); + r.options.remembered.insert(entry.remember_key(), Some(command)); // P3(shortcuts-w4): kb.C12 r.plan = import::plan(&r.set, env.keymap, &r.options); - self.outcome = Some(Outcome::Remembered(r.options.remembered.clone())); + self.outcome = Some(Outcome::Remembered { targets: r.options.remembered.clone(), codes: r.options.codes.clone() }); // P3(shortcuts-w4): kb.C29 + } + + /// Starts the review from `start` and re-plans. + #[allow(dead_code)] // P3(shortcuts-w4): kb.C12 + pub(crate) fn set_start(&mut self, env: &Env, start: Start) { + let _ = (env, start); + todo!("kb.C12") + } + + /// Imports entry `entry` or leaves it out, and re-plans. + #[allow(dead_code)] // P3(shortcuts-w4): kb.C12 + pub(crate) fn include(&mut self, env: &Env, entry: usize, on: bool) { + let _ = (env, entry, on); + todo!("kb.C12") + } + + /// Picks `command` for entry `entry` (`None` is No equivalent), re-plans and reports the answer. + #[allow(dead_code)] // P3(shortcuts-w4): kb.C12 + pub(crate) fn pick_target(&mut self, env: &Env, entry: usize, command: Option) { + let _ = (env, entry, command); + todo!("kb.C12") + } + + /// Answers the undecided `code` (`None` is No equivalent), re-plans and reports the answer. + #[allow(dead_code)] // P3(shortcuts-w4): kb.C12 + pub(crate) fn answer_code(&mut self, env: &Env, code: String, answer: Option) { + let _ = (env, code, answer); + todo!("kb.C12") } /// Import as New Set (with sets), else applies the plan to the keymap as one undo step. diff --git a/crates/print/src/ui/mod.rs b/crates/print/src/ui/mod.rs index 5ee97c047..11b62b379 100644 --- a/crates/print/src/ui/mod.rs +++ b/crates/print/src/ui/mod.rs @@ -52,6 +52,14 @@ impl Printer { } } +impl From for Printer { + /// The dialog's printer for a discovered one: `name`, the `description` as the label, and `default`. + fn from(printer: crate::Printer) -> Self { + let _ = printer; + todo!("ex.E58") + } +} + /// The text the dialog shows for each of `printers`, in order: its label, or its name when it has /// none. Text two printers would share is followed by the name in brackets, so neither hides the /// other; when even that text is shared (another printer's label is `Office (Office_1)`), those diff --git a/crates/table/src/ui/grid.rs b/crates/table/src/ui/grid.rs index 5fb00d400..1dfc20d43 100644 --- a/crates/table/src/ui/grid.rs +++ b/crates/table/src/ui/grid.rs @@ -37,6 +37,18 @@ pub use row::GridRow; pub(crate) use geometry::{digits_of, header_insets, row_digits}; pub(crate) use reference::edges; +/// Where a column's resize edge is drawn. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] +#[non_exhaustive] +pub enum ColumnEdges { + /// Only on the column headers. + #[default] + Headers, + /// Also over the cell rows in view, with the header edge's drag, cursor and double press; a press beside the + /// band selects the cell. + Cells, +} + /// The rows of a sheet as the collection's source: one key per row, equal to its position. struct SheetRows(Positions); @@ -192,6 +204,9 @@ pub struct CellGrid<'a> { /// The cell whose problem shows an error tag, with its fixes. #[prop] error_tag: Option>, + /// Where a column's resize edge is drawn. + #[prop] + column_edges: ColumnEdges, outline: Option<(&'a OutlineAxis, &'a OutlineAxis)>, selectable: Box) -> bool + 'a>, frame: Option, @@ -222,6 +237,7 @@ impl<'a> CellGrid<'a> { copy_mark: &[], filters: &[], error_tag: None, + column_edges: ColumnEdges::default(), outline: None, selectable: Box::new(move |cell| model.selectable(cell)), frame: None, diff --git a/crates/table/src/ui/mod.rs b/crates/table/src/ui/mod.rs index 2386a8e7a..096c6e59e 100644 --- a/crates/table/src/ui/mod.rs +++ b/crates/table/src/ui/mod.rs @@ -46,8 +46,8 @@ pub use fields::{ pub use filter::{FilterButton, FilterButtonEvent, FilterButtonOutput, FilterButtonStyle, FilterButtonWords}; pub use grid::{ CellAdvance, CellAt, CellDirection, CellEdit, CellGrid, CellGridStyle, CellGridWords, CellProblem, CellRange, CellSelection, CellSpace, - ColumnFilter, GridEdit, GridLayout, GridMenuTarget, GridModel, GridOutput, GridRow, GridState, HEADER_MIN_ZOOM, LineIndex, Positions, - SHEET_COLUMNS, SHEET_ROWS, SHEET_ZOOM, SheetGeometry, SheetMetrics, absolute_range_reference, absolute_reference, column_letters, + ColumnEdges, ColumnFilter, GridEdit, GridLayout, GridMenuTarget, GridModel, GridOutput, GridRow, GridState, HEADER_MIN_ZOOM, LineIndex, + Positions, SHEET_COLUMNS, SHEET_ROWS, SHEET_ZOOM, SheetGeometry, SheetMetrics, absolute_range_reference, absolute_reference, column_letters, }; pub use outline::{OutlineAction, OutlineAxis, OutlineBand, OutlineBandOutput, OutlineBandStyle, OutlineBandWords, OutlineGroup}; pub use refpick::ReferencePicker;