Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Merge keymap-adoption (#1298, on main) into keymap-shortcuts-dialog

aiongg77c718aa68f7
diff --cc Cargo.lock
index 490ad375f,0479123c2..41fcdacab
--- a/Cargo.lock
+++ b/Cargo.lock
@@@ -701,6 -758,39 +758,48 @@@ dependencies =
"error-code",
]
+ [[package]]
+ name = "cmake"
+ version = "0.1.58"
+ source = "registry+https://github.com/rust-lang/crates.io-index"
+ checksum = "c0f78a02292a74a88ac736019ab962ece0bc380e3f977bf72e376c5d78ff0678"
+ dependencies = [
+ "cc",
+ ]
+
+ [[package]]
+ name = "cmpv2"
+ version = "0.2.0"
+ source = "registry+https://github.com/rust-lang/crates.io-index"
+ checksum = "961b955a666e25ee5a1091d219128d6e6401e3dab84efb1a2bf6b4035d797b39"
+ dependencies = [
+ "crmf",
+ "der",
+ "spki",
+ "x509-cert",
+ ]
+
+ [[package]]
+ name = "cms"
+ version = "0.2.3"
+ source = "registry+https://github.com/rust-lang/crates.io-index"
+ checksum = "7b77c319abfd5219629c45c34c89ba945ed3c5e49fcde9d16b6c3885f118a730"
+ dependencies = [
+ "const-oid",
+ "der",
+ "spki",
+ "x509-cert",
+ ]
+
++[[package]]
++name = "cobs"
++version = "0.3.0"
++source = "registry+https://github.com/rust-lang/crates.io-index"
++checksum = "0fa961b519f0b462e3a3b4a34b64d119eeaca1d59af726fe450bbba07a9fc0a1"
++dependencies = [
++ "thiserror 2.0.21",
++]
++
[[package]]
name = "codespan-reporting"
version = "0.13.1"
@@@ -836,25 -966,13 +975,38 @@@ dependencies =
[[package]]
name = "craft-docpath"
version = "0.1.0"
- source = "git+https://github.com/storytold/craft-libs?rev=82a24b006eefa036b43c09a67fb9a3fbd17ffe63#82a24b006eefa036b43c09a67fb9a3fbd17ffe63"
+ source = "git+https://github.com/storytold/craft-libs?rev=e3b9e239c52c14677be462e94d8920ea243de4f3#e3b9e239c52c14677be462e94d8920ea243de4f3"
+[[package]]
+name = "craft-i18n"
+version = "0.1.0"
- source = "git+https://github.com/aiongg/craft-libs?rev=f9a65e813f5cb7986fc80b11bc0abfd410f1e224#f9a65e813f5cb7986fc80b11bc0abfd410f1e224"
++source = "git+https://github.com/storytold/craft-libs?rev=e3b9e239c52c14677be462e94d8920ea243de4f3#e3b9e239c52c14677be462e94d8920ea243de4f3"
+dependencies = [
- "intl_pluralrules",
++ "fixed_decimal",
++ "icu_decimal",
++ "icu_locale_core",
++ "icu_locale_fallback",
++ "icu_normalizer",
++ "icu_plurals",
++ "icu_properties",
++ "icu_provider",
++ "icu_provider_adapters",
++ "icu_provider_blob",
++ "log",
++ "objc2-foundation 0.3.2",
+ "sys-locale",
- "unic-langid",
++ "unicode-bidi",
++ "windows-registry",
++ "writeable",
+]
+
[[package]]
name = "craft-keymap"
version = "0.1.0"
- source = "git+https://github.com/aiongg/craft-libs?rev=f9a65e813f5cb7986fc80b11bc0abfd410f1e224#f9a65e813f5cb7986fc80b11bc0abfd410f1e224"
+ source = "git+https://github.com/storytold/craft-libs?rev=e3b9e239c52c14677be462e94d8920ea243de4f3#e3b9e239c52c14677be462e94d8920ea243de4f3"
dependencies = [
+ "craft-i18n",
- "craft-ui 0.1.0 (git+https://github.com/aiongg/craft-libs?rev=f9a65e813f5cb7986fc80b11bc0abfd410f1e224)",
++ "craft-ui",
"egui",
"serde",
"serde_json",
@@@ -1693,9 -1918,21 +1952,32 @@@ version = "0.1.14
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aedcfb3409746eddb02b9e19ebda1c3394f759a152e48ee875a0844d1b955484"
+[[package]]
- name = "flate2"
- version = "1.1.10"
++name = "fixed_decimal"
++version = "0.7.3"
++source = "registry+https://github.com/rust-lang/crates.io-index"
++checksum = "2214fb00f669ee96bee5bb29dfb1ddabe058b2bc426817efc79afa03c9bc55ae"
++dependencies = [
++ "displaydoc",
++ "smallvec",
++ "writeable",
++]
++
+ [[package]]
+ name = "fixedbitset"
+ version = "0.5.7"
+ source = "registry+https://github.com/rust-lang/crates.io-index"
+ checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99"
+
+ [[package]]
+ name = "flagset"
+ version = "0.4.7"
+ source = "registry+https://github.com/rust-lang/crates.io-index"
+ checksum = "b7ac824320a75a52197e8f2d787f6a38b6718bb6897a35142d749af3c0e8f4fe"
+
+ [[package]]
+ name = "flate2"
+ version = "1.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e634e2e0ebac1ee034020da1ca582e17ffe4e0f5e985823721e168928136dcb"
dependencies = [
@@@ -2288,6 -2745,6 +2790,23 @@@ dependencies =
"zerovec",
]
++[[package]]
++name = "icu_decimal"
++version = "2.3.0"
++source = "registry+https://github.com/rust-lang/crates.io-index"
++checksum = "9eb8f655bba2d0c0459e43a5b0e6cd3cd388109898fb3d85d048165e8b0abd08"
++dependencies = [
++ "displaydoc",
++ "fixed_decimal",
++ "icu_locale_core",
++ "icu_pattern",
++ "icu_plurals",
++ "icu_provider",
++ "serde",
++ "writeable",
++ "zerovec",
++]
++
[[package]]
name = "icu_locale_core"
version = "2.3.0"
@@@ -2296,11 -2753,11 +2815,32 @@@ checksum = "d56e28588da92eee5c3201a6eff
dependencies = [
"displaydoc",
"litemap",
++ "serde",
"tinystr",
"writeable",
"zerovec",
]
++[[package]]
++name = "icu_locale_fallback"
++version = "2.3.0"
++source = "registry+https://github.com/rust-lang/crates.io-index"
++checksum = "251af8e57c9400e3eb58242fe5b8b1152b2a64fdf4cf632f923c38ccee6f2fa9"
++dependencies = [
++ "icu_locale_core",
++ "icu_locale_fallback_data",
++ "icu_provider",
++ "potential_utf",
++ "tinystr",
++ "zerovec",
++]
++
++[[package]]
++name = "icu_locale_fallback_data"
++version = "2.3.0"
++source = "registry+https://github.com/rust-lang/crates.io-index"
++checksum = "decf2a22ec8fa68f1a0c1129a3f8583f8f8bc24e8b9ccbe98ead99f62a4dc3a8"
++
[[package]]
name = "icu_normalizer"
version = "2.3.0"
@@@ -2312,6 -2769,6 +2852,9 @@@ dependencies =
"icu_properties",
"icu_provider",
"smallvec",
++ "utf16_iter",
++ "utf8_iter",
++ "write16",
"zerovec",
]
@@@ -2321,6 -2778,6 +2864,32 @@@ version = "2.3.0
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1563da1ed3e0b3bf3d74c9b85917ac9c56464d2f57242270c09c9e752f8021a0"
++[[package]]
++name = "icu_pattern"
++version = "0.5.0"
++source = "registry+https://github.com/rust-lang/crates.io-index"
++checksum = "2b3db611446bd92c246b03e4aa0bafa71ddb194af431ddbb42b9d70e4bfce1a0"
++dependencies = [
++ "displaydoc",
++ "either",
++ "serde",
++ "writeable",
++ "zerovec",
++]
++
++[[package]]
++name = "icu_plurals"
++version = "2.3.0"
++source = "registry+https://github.com/rust-lang/crates.io-index"
++checksum = "e475e6766ef87b1d3c1f97be6363995b0bfaeddbc789671615df598a97ff0593"
++dependencies = [
++ "displaydoc",
++ "fixed_decimal",
++ "icu_provider",
++ "serde",
++ "zerovec",
++]
++
[[package]]
name = "icu_properties"
version = "2.3.0"
@@@ -2350,6 -2807,6 +2919,9 @@@ checksum = "d27bbb9d3abbefac45d55f647c9
dependencies = [
"displaydoc",
"icu_locale_core",
++ "postcard",
++ "serde",
++ "stable_deref_trait",
"writeable",
"yoke",
"zerofrom",
@@@ -2357,6 -2814,6 +2929,30 @@@
"zerovec",
]
++[[package]]
++name = "icu_provider_adapters"
++version = "2.3.0"
++source = "registry+https://github.com/rust-lang/crates.io-index"
++checksum = "df887bc4f55dbc773c7c45a0c7dfa75be886f7b7812830a71ab7271cc1801820"
++dependencies = [
++ "icu_locale_fallback",
++ "icu_provider",
++]
++
++[[package]]
++name = "icu_provider_blob"
++version = "2.3.0"
++source = "registry+https://github.com/rust-lang/crates.io-index"
++checksum = "5916b44fac319d3f58e4d8d805a627df19e27937b582cd99fcde3bb6b7ce1b0e"
++dependencies = [
++ "icu_provider",
++ "postcard",
++ "serde",
++ "writeable",
++ "zerotrie",
++ "zerovec",
++]
++
[[package]]
name = "idna"
version = "1.1.0"
@@@ -2716,6 -3170,6 +3309,9 @@@ name = "litemap
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae"
++dependencies = [
++ "serde_core",
++]
[[package]]
name = "litrs"
@@@ -3562,12 -4142,12 +4284,24 @@@ dependencies =
"portable-atomic",
]
++[[package]]
++name = "postcard"
++version = "1.1.3"
++source = "registry+https://github.com/rust-lang/crates.io-index"
++checksum = "6764c3b5dd454e283a30e6dfe78e9b31096d9e32036b5d1eaac7a6119ccb9a24"
++dependencies = [
++ "cobs",
++ "serde",
++]
++
[[package]]
name = "potential_utf"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661"
dependencies = [
++ "serde_core",
++ "writeable",
"zerovec",
]
@@@ -4417,18 -5566,38 +5720,50 @@@ dependencies =
"syn 3.0.6",
]
+[[package]]
+name = "sys-locale"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8eab9a99a024a169fe8a903cf9d4a3b3601109bcc13bd9e3c6fff259138626c4"
+dependencies = [
+ "js-sys",
+ "libc",
+ "wasm-bindgen",
+ "web-sys",
+]
+
+ [[package]]
+ name = "system-configuration"
+ version = "0.7.0"
+ source = "registry+https://github.com/rust-lang/crates.io-index"
+ checksum = "a13f3d0daba03132c0aa9767f98351b3488edc2c100cda2d2ec2b04f3d8d3c8b"
+ dependencies = [
+ "bitflags 2.13.2",
+ "core-foundation 0.9.4",
+ "system-configuration-sys",
+ ]
+
+ [[package]]
+ name = "system-configuration-sys"
+ version = "0.6.0"
+ source = "registry+https://github.com/rust-lang/crates.io-index"
+ checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4"
+ dependencies = [
+ "core-foundation-sys",
+ "libc",
+ ]
+
+ [[package]]
+ name = "tar"
+ version = "0.4.46"
+ source = "registry+https://github.com/rust-lang/crates.io-index"
+ checksum = "3f6221d9a6003c78398e3b239969f352578258df48c8eb051caadae0015bc840"
+ dependencies = [
+ "filetime",
+ "libc",
+ "xattr",
+ ]
+
[[package]]
name = "tempfile"
version = "3.27.0"
@@@ -4811,6 -6091,6 +6258,12 @@@ dependencies =
"xmlwriter",
]
++[[package]]
++name = "utf16_iter"
++version = "1.0.5"
++source = "registry+https://github.com/rust-lang/crates.io-index"
++checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246"
++
[[package]]
name = "utf8_iter"
version = "1.0.4"
@@@ -5802,11 -7129,11 +7302,20 @@@ dependencies =
"read-fonts 0.39.2",
]
++[[package]]
++name = "write16"
++version = "1.0.0"
++source = "registry+https://github.com/rust-lang/crates.io-index"
++checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936"
++
[[package]]
name = "writeable"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc"
++dependencies = [
++ "either",
++]
[[package]]
name = "x11-dl"
@@@ -6073,8 -7461,8 +7643,11 @@@ source = "registry+https://github.com/r
checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f"
dependencies = [
"displaydoc",
++ "litemap",
++ "serde_core",
"yoke",
"zerofrom",
++ "zerovec",
]
[[package]]
diff --cc Cargo.toml
index 9d23a6518,b1109a31d..fe0846afe
--- a/Cargo.toml
+++ b/Cargo.toml
@@@ -12,9 -12,9 +12,9 @@@ repository = "https://github.com/storyt
[workspace.dependencies]
# Shared reader and writer; publish the immutable revision before this consumer.
- craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "89dcbb3060377a26c99a6d80caa16084366704c4", version = "=0.1.0", default-features = false }
+ craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "e3b9e239c52c14677be462e94d8920ea243de4f3", version = "=0.1.0", default-features = false }
-# Shared keyboard bindings: chords, overrides, conflicts, egui dispatch.
-craft-keymap = { git = "https://github.com/storytold/craft-libs", rev = "e3b9e239c52c14677be462e94d8920ea243de4f3", version = "=0.1.0", features = ["egui"] }
+# Shared keyboard bindings: chords, overrides, conflicts, egui dispatch, the Keyboard Shortcuts dialog.
- craft-keymap = { git = "https://github.com/aiongg/craft-libs", rev = "f9a65e813f5cb7986fc80b11bc0abfd410f1e224", version = "=0.1.0", features = ["egui", "ui"] }
++craft-keymap = { git = "https://github.com/storytold/craft-libs", rev = "e3b9e239c52c14677be462e94d8920ea243de4f3", version = "=0.1.0", features = ["egui", "ui"] }
# internal
designcraft-geom = { path = "crates/geom" }
designcraft-color = { path = "crates/color" }
diff --cc apps/designcraft/src/native_menu.rs
index 0f9b24257,8996debe5..b589b5ecf
--- a/apps/designcraft/src/native_menu.rs
+++ b/apps/designcraft/src/native_menu.rs
@@@ -171,19 -171,18 +172,22 @@@ impl NativeMenu
}
pub fn poll(&mut self, app: &mut DesignApp, ctx: &egui::Context) {
- while let Ok(ev) = self.events.try_recv() {
- if let Some((cmd, params, _)) = self.items.get(ev.id.as_ref()) {
- menus::activate_native(app, ctx, &cmd.clone(), &params.clone());
+ app.poll_native_actions(ctx, || {
+ loop {
+ let ev = self.events.try_recv().ok()?;
+ if let Some((cmd, params, _)) = self.items.get(ev.id.as_ref()) {
+ return Some((cmd.clone(), params.clone()));
+ }
}
- }
+ });
// Interface Language and Show CJK Features (set in Preferences or by `app.language`, or put
// back by Cancel): the system menu bar follows at once, like the panels (the new menu
- // replaces the old one as the application's menu before that one is dropped).
- if app.ui.language != self.shown_for.0 || designcraft_ui_egui::cjk_features(app) != self.shown_for.1 {
+ // replaces the old one as the application's menu before that one is dropped). While the
+ // Keyboard Shortcuts dialog records, the bar has no key equivalents.
+ if app.ui.language != self.shown_for.0
+ || designcraft_ui_egui::cjk_features(app) != self.shown_for.1
+ || app.shortcut_recording() != self.shown_for.2
+ {
let events = std::mem::replace(&mut self.events, channel().1);
*self = Self::build_bar(app, events);
}
diff --cc crates/ui-egui/src/dialogs.rs
index 6f92a1cd5,99b0d2d0c..6c153ed53
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@@ -1940,16 -2274,8 +2162,17 @@@ fn check(ui: &mut egui::Ui, d: &mut Dia
}
}
+ /// Draw the active localized dialog; open popups own Enter/Escape, and result handling drives confirm or cancel.
pub fn show(app: &mut DesignApp, ctx: &egui::Context) {
+ let shortcuts = app.ui.dialog.as_ref().is_some_and(|d| d.id == crate::shortcuts_dialog::DIALOG_ID);
+ if shortcuts {
+ crate::shortcuts_dialog::show(app, ctx);
+ return;
+ }
+ if app.shortcut_dialog.is_some() {
+ // Another dialog took its place: its edits are cancelled.
+ let _ = crate::shortcuts_dialog::close(app, false);
+ }
let Some(mut d) = app.ui.dialog.clone() else { return };
// Enter and Escape belong to an open popup (a menu, a name field) rather than the dialog.
// Read before the dialog draws: a popup closed by this frame's Escape is still open here.
@@@ -2004,8 -2335,10 +2232,9 @@@
"print" => crate::i18n::tr(&app.ui.language, "Print"),
"pdfImport" => crate::i18n::tr(&app.ui.language, "Place PDF"),
"pdfExport" => crate::i18n::tr(&app.ui.language, "Export PDF"),
+ "epubExport" => crate::i18n::tr(&app.ui.language, "EPUB Export Options"),
"colorSettings" => crate::i18n::tr(&app.ui.language, "Color Settings"),
"layerOptions" => crate::i18n::tr(&app.ui.language, "Object Layer Options"),
- "keyboardShortcuts" => crate::i18n::tr(&app.ui.language, "Keyboard Shortcuts"),
"colorPicker" => crate::i18n::tr(&app.ui.language, "Color Picker"),
"swatchOptions" => crate::i18n::tr(&app.ui.language, "Swatch Options"),
"colorGroupOptions" => crate::i18n::tr(&app.ui.language, "Color Group Options"),
diff --cc crates/ui-egui/src/lib.rs
index 504def794,f93948cd5..71285f1ae
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@@ -252,27 -322,31 +323,35 @@@ pub struct UiState
pub rich_black: bool,
/// View › Overprint Preview.
pub overprint_preview: bool,
- /// Edit › Keyboard Shortcuts: the user's changes to the default shortcuts. Saved as
- /// `shortcuts` and `shortcutsMore` (see `prefs::saved_shortcuts`).
+ /// Edit › Keyboard Shortcuts: the active shortcut set's changes to the default shortcuts, which
+ /// the keymap uses. Saved as `shortcuts` and `shortcutsMore` (see `prefs::saved_shortcuts`),
+ /// which earlier versions read.
#[serde(flatten, with = "prefs::saved_shortcuts")]
pub shortcuts: craft_keymap::Overrides,
+ /// The user's named shortcut sets and which one is active (see `shortcuts_dialog`).
+ #[serde(deserialize_with = "prefs::lenient_sets")]
+ pub shortcut_sets: craft_keymap::Profiles,
pub control_bar: bool,
pub tools_double_column: bool,
- /// Expanded right-dock panel group tab.
+ /// The front tab of the default layout's Properties · Pages · Layers group. `dock_tab`,
+ /// `open_panel`, `floating`, `dock_expanded` and `icon_groups` describe a workspace's
+ /// default layout (`panel_docking::default_layout`).
pub dock_tab: String,
- /// Panel opened from the collapsed icon column (flyout).
+ /// The panel it opens below that group (Printing and Proofing: Swatches).
pub open_panel: Option<String>,
- /// Panels torn off the dock into their own floating windows: (panel id, top-left position).
+ /// Its floating panels, and the float-only panels' windows (Type › Tabs): (panel id,
+ /// top-left position). A customized layout holds its own floating panels.
pub floating: Vec<(String, [f32; 2])>,
- /// Shared panel layout after the user customizes the legacy dock.
+ /// The panel layout once the user customizes it; `None` is the workspace's default layout
+ /// (`panel_docking::default_layout`).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub docking: Option<craft_ui::docking::Layout<String>>,
- #[serde(default, skip_serializing_if = "std::collections::BTreeMap::is_empty")]
- pub docking_hidden: std::collections::BTreeMap<String, craft_ui::docking::Location<String>>,
+ #[serde(default, skip_serializing_if = "HiddenPanels::is_empty")]
+ pub docking_hidden: HiddenPanels,
+ /// The panel (or the canvas) last clicked or selected in the docking layout, while the panel
+ /// stays where the user left it.
+ #[serde(skip)]
+ pub docking_focused: Option<String>,
/// Invalidates in-flight gestures when a workspace is replaced.
#[serde(skip)]
pub docking_generation: u64,
@@@ -619,14 -799,10 +805,14 @@@ pub struct DesignApp
/// Every command's shortcuts, with the user's changes (`ui.shortcuts`) applied.
pub keymap: craft_keymap::Keymap,
pub(crate) key_dispatcher: craft_keymap::egui::Dispatcher,
+ /// The open Keyboard Shortcuts dialog.
+ pub(crate) shortcut_dialog: Option<Box<shortcuts_dialog::Host>>,
+ /// Answers the user gave in an import review (item → command), for later imports.
+ pub(crate) shortcut_answers: std::collections::BTreeMap<String, craft_keymap::CommandRef>,
last_time: f64,
- /// When recovery data was last written (seconds, egui time).
+ /// When recovery data was last written (seconds on the monotonic clock; see [`now_ms`]).
pub last_recovery: f64,
- /// The egui context (set by the first frame): copied text goes to the system clipboard through it.
+ /// The egui context (set by the first UI pass): copied text goes to the system clipboard through it.
egui_ctx: Option<egui::Context>,
/// A control-channel request is being handled: commands it runs never read or write the
/// user's system clipboard (a control client must not see or replace it).
@@@ -711,10 -924,8 +934,10 @@@ impl DesignApp
native_shortcuts: Default::default(),
keymap: keys::new_keymap(craft_keymap::Overrides::new()),
key_dispatcher: craft_keymap::egui::Dispatcher::new(),
+ shortcut_dialog: None,
+ shortcut_answers: Default::default(),
- last_time: 0.0,
- last_recovery: 0.0,
+ last_time: now,
+ last_recovery: now,
egui_ctx: None,
in_control: false,
object_clip_text: None,
diff --cc crates/ui-egui/src/prefs.rs
index 3ce8943db,a4573eb85..38d668065
--- a/crates/ui-egui/src/prefs.rs
+++ b/crates/ui-egui/src/prefs.rs
@@@ -74,25 -96,71 +96,78 @@@ pub(crate) mod saved_shortcuts
}
}
+/// `UiState::shortcut_sets`: anything that does not read as shortcut sets (a later format, a
+/// hand edit) loads as none, keeping the rest of ui.json and the `shortcuts` the keymap uses.
+pub(crate) fn lenient_sets<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result<craft_keymap::Profiles, D::Error> {
+ let value = <Value as serde::Deserialize>::deserialize(deserializer)?;
+ Ok(serde_json::from_value(value).unwrap_or_default())
+}
+
- fn recover_docking(saved: &mut Value) {
- let Some(fields) = saved.as_object_mut() else { return };
+ /// Files from before the canvas joined the panel layout saved the flyout open at quit as
+ /// `openPanel`, which is the panel a workspace opens below Properties · Pages · Layers. Only a
+ /// workspace's own panel stays: a built-in workspace's (Printing and Proofing: Swatches), and in a
+ /// saved workspace one a built-in workspace opens (saving copies it). The current workspace keeps
+ /// a saved workspace's panel.
+ fn clear_stale_open_panels(ui: &mut UiState) {
+ let built_in = |panel: &str| crate::menus::WORKSPACE_OPEN_PANELS.iter().any(|(_, p)| *p == panel);
+ for workspace in &mut ui.custom_workspaces {
+ if workspace.open_panel.as_deref().is_some_and(|panel| !built_in(panel)) {
+ workspace.open_panel = None;
+ }
+ }
+ let own = match ui.custom_workspaces.iter().find(|w| w.name == ui.workspace) {
+ Some(saved) => saved.open_panel.as_deref(),
+ None => crate::menus::workspace_open_panel(&ui.workspace),
+ };
+ if ui.open_panel.as_deref() != own {
+ ui.open_panel = None;
+ }
+ }
+
+ /// Drop docking data this version cannot read. True when nothing was dropped.
+ fn recover_docking(saved: &mut Value) -> bool {
+ let Some(fields) = saved.as_object_mut() else { return true };
+ let mut intact = true;
if fields.get("docking").is_some_and(|value| serde_json::from_value::<Option<Layout<String>>>(value.clone()).is_err()) {
fields.remove("docking");
+ intact = false;
}
if let Some(hidden) = fields.get_mut("dockingHidden") {
- if let Some(entries) = hidden.as_object_mut() {
+ // `[[panel, location], …]`, or an object keyed by panel from older files.
+ if let Some(entries) = hidden.as_array_mut() {
+ let before = entries.len();
+ entries.retain(|entry| serde_json::from_value::<(String, Location<String>)>(entry.clone()).is_ok());
+ intact &= entries.len() == before;
+ } else if let Some(entries) = hidden.as_object_mut() {
+ let before = entries.len();
entries.retain(|_, value| serde_json::from_value::<Location<String>>(value.clone()).is_ok());
+ intact &= entries.len() == before;
} else {
fields.remove("dockingHidden");
+ intact = false;
}
}
+ intact
+ }
+
+ /// Convert a layout saved before the canvas joined the panel layout. One that cannot be
+ /// converted gives way to the workspace's default layout, which the workspace fields
+ /// (`dockTab`, `openPanel`, `floating`, `dockExpanded`, `iconGroups`) still describe. False when
+ /// a layout was dropped that way.
+ fn migrate(
+ docking: &mut Option<Layout<String>>,
+ floating: &mut Vec<(String, [f32; 2])>,
+ hidden: &HiddenPanels,
+ dock_expanded: bool,
+ icon_groups: Option<&[Vec<String>]>,
+ ) -> bool {
+ let Some(old) = docking.as_ref().filter(|layout| panel_docking::dock_only(layout)) else { return true };
+ *docking = panel_docking::from_dock_only(old, hidden.keys(), dock_expanded, icon_groups);
+ if docking.is_some() {
+ // The converted layout holds the floating dock panels.
+ floating.retain(|(id, _)| crate::dock::float_only(id));
+ }
+ docking.is_some()
}
#[cfg(test)]
diff --cc crates/ui-egui/src/shortcut_import.rs
index f977b11bf,27373fa4d..d8387edc5
--- a/crates/ui-egui/src/shortcut_import.rs
+++ b/crates/ui-egui/src/shortcut_import.rs
@@@ -189,45 -186,28 +189,44 @@@ fn foreign(set: &ParsedSet) -> ForeignS
entry
})
.collect();
- ForeignSet { name: Some(set.name.clone()), entries, truncated: set.dropped }
- ForeignSet::new(entries).with_name(set.name.clone())
++ ForeignSet::new(entries).with_name(set.name.clone()).with_truncated(set.dropped)
}
-/// Imports a set: every matched command takes the set's shortcuts (or none, when every item
-/// matched to it has none), other commands lose keys it takes (unless they share them as
-/// defaults), and the rest keep theirs. Returns the report.
-pub fn import(app: &mut DesignApp, text: &str) -> Result<Value, String> {
+/// What DesignCraft's contexts take from a set: Default keys bind in the command's home scope; an
+/// item without Default keys takes its Text keys. Unmatched items get likely commands.
+pub fn import_options(remembered: BTreeMap<String, CommandRef>) -> ImportOptions {
+ ImportOptions {
+ contexts: vec![("Default".into(), ContextRule::Home), (crate::keys::TEXT_CONTEXT.into(), ContextRule::HomeWithoutHomeEntry)],
+ remembered,
+ suggest: true,
+ ..ImportOptions::default()
+ }
+}
+
+/// Reads a set's text for craft-keymap's importer. Items past [`MAX_IMPORT_ENTRIES`] are not read;
+/// the set counts them as truncated.
+pub fn read_set(text: &str) -> Result<ForeignSet, String> {
if text.len() > MAX_BYTES {
return Err(format!("the set is larger than {} MB", MAX_BYTES >> 20));
}
let parsed = parse(text)?;
- let set = foreign(&parsed);
- let options = ImportOptions {
- contexts: vec![("Default".into(), ContextRule::Home), (crate::keys::TEXT_CONTEXT.into(), ContextRule::HomeWithoutHomeEntry)],
- suggest: true,
- ..ImportOptions::default()
- };
+ Ok(foreign(&parsed))
+}
+
+/// Imports a set as a new shortcut set, which becomes active: every matched command takes the
+/// set's shortcuts (or none, when every item matched to it has none), other commands lose keys it
+/// takes (unless they share them as defaults), and the rest keep theirs. Returns the report, with
+/// the new set's name as `shortcutSet`.
+pub fn import(app: &mut DesignApp, text: &str) -> Result<Value, String> {
+ let set = read_set(text)?;
app.sync_keymap();
- let mut report = craft_keymap::plan(&set, &app.keymap, &options).apply(&mut app.keymap);
- report.truncated = report.truncated.saturating_add(parsed.dropped);
- crate::keys::store(app);
- Ok(report_json(&report))
+ let options = import_options(app.shortcut_answers.clone());
+ let plan = craft_keymap::plan(&set, &app.keymap, &options);
- let (name, report) =
- app.ui.shortcut_sets.import_plan(&plan, &app.keymap, None, &crate::shortcuts_dialog::BUILTINS).map_err(|e| e.to_string())?;
++ let (name, report) = app.ui.shortcut_sets.import_plan(&plan, &app.keymap, None, &crate::shortcuts_dialog::BUILTINS).map_err(|e| e.to_string())?;
+ crate::shortcuts_dialog::load_active_set(app);
+ let mut out = report_json(&report);
+ out["shortcutSet"] = json!(name);
+ Ok(out)
}
/// An enum of the report as its serde name (`noMatch`, `numpad`).
diff --cc crates/ui-egui/src/shortcuts_dialog.rs
index 62ea4518e,000000000..531c6ba69
mode 100644,000000..100644
--- a/crates/ui-egui/src/shortcuts_dialog.rs
+++ b/crates/ui-egui/src/shortcuts_dialog.rs
@@@ -1,470 -1,0 +1,466 @@@
+//! Edit › Keyboard Shortcuts: craft-keymap's shared dialog over DesignCraft's keymap and the user's
+//! named shortcut sets.
+//!
+//! The dialog edits `DesignApp::keymap` and `UiState::shortcut_sets` in place, so menus show new
+//! keys at once; Cancel puts both back. `UiState::shortcuts` follows the keymap every frame: it is
+//! what ui.json saves for earlier versions and what `sync_keymap` applies. While the dialog is open
+//! `app.ui.dialog` holds a `keyboardShortcuts` entry, so the canvas, the menus' key dispatch and
+//! the control channel treat it as the open modal dialog.
+//!
+//! The InDesign importer stays here (`shortcut_import`): the dialog's Import offers its format
+//! next to craft-keymap's JSON, and the dialog reviews the set before it becomes a new set.
+
+use std::borrow::Cow;
+
+use craft_keymap::ui::{DialogState, Format, Options, Outcome, ShortcutsDialog, Text};
+use craft_keymap::{Bindable, Overrides};
+use serde_json::json;
+
+use crate::DesignApp;
+use crate::i18n::tr;
+
+/// The `app.ui.dialog` id while the dialog is open.
+pub const DIALOG_ID: &str = "keyboardShortcuts";
+
+/// DesignCraft's built-in shortcut set: its default keys.
+pub static BUILTINS: [(&str, Overrides); 1] = [("Default", Overrides::new())];
+
+/// The name edits of the built-in set are saved under (translated, made unique).
+pub const CUSTOM_SET: &str = "Custom";
+
+/// The file-picker purpose of the dialog's Import (`Services::pick_open`, `open_async`).
+pub const PURPOSE: &str = "shortcuts";
+
+/// A set saved by InDesign's Show Set, read by `shortcut_import`.
+pub const INDESIGN_FORMAT: Format = Format { id: "indesign", label: "InDesign Shortcut Set (Show Set text)", extensions: &["txt"] };
+
+/// The open dialog: its state and options.
+pub struct Host {
+ state: DialogState,
+ options: Options,
+}
+
+impl Host {
+ fn new() -> Host {
+ Host { state: DialogState::new(), options: options() }
+ }
+
+ pub(crate) fn recording(&self) -> bool {
+ self.state.is_recording()
+ }
+}
+
+/// The owner-approved behavior: live editing with Cancel restoring, conflicts asked about, no
+/// double presses, the US keyboard pane, InDesign sets to import, and no rows for the engine
+/// commands only scripts run.
+fn options() -> Options {
+ Options::default().with(|o| {
+ o.keyboard = true;
+ o.import_formats = vec![INDESIGN_FORMAT];
+ o.visible = Some(crate::keys::listed);
+ })
+}
+
+/// The dialog's words through DesignCraft's catalogs; strings without a translation stay English.
+pub struct DcText<'a> {
+ pub lang: &'a str,
+}
+
+impl Text for DcText<'_> {
+ fn ui<'a>(&'a self, source: &'a str) -> Cow<'a, str> {
+ tr(self.lang, source).into()
+ }
+
+ fn plural(&self, n: u64, one: &str, other: &str) -> String {
+ tr(self.lang, if n == 1 { one } else { other }).replace("{n}", &n.to_string())
+ }
+
+ fn command<'a>(&'a self, b: &'a Bindable) -> Cow<'a, str> {
+ tr(self.lang, &b.label).into()
+ }
+
+ fn segment<'a>(&'a self, s: &'a str) -> Cow<'a, str> {
+ tr(self.lang, s).into()
+ }
+
+ fn rtl(&self) -> bool {
+ crate::i18n::is_rtl(self.lang)
+ }
-
- fn visual(&self, s: &str) -> String {
- crate::rtl::visual_text(s)
- }
+}
+
+/// Edit › Keyboard Shortcuts…; with `select`, the dialog opens on that command.
+pub fn open(app: &mut DesignApp, select: Option<&craft_keymap::CommandRef>) {
+ crate::dialogs::cancel(app);
+ app.sync_keymap();
+ let mut host = Host::new();
+ if let Some(command) = select {
+ host.state.select(command);
+ }
+ app.shortcut_dialog = Some(Box::new(host));
+ app.ui.dialog = Some(crate::dialogs::Dialog::new(DIALOG_ID, json!({})));
+}
+
+/// The dialog's size: most of the window, within the dialog's own limits.
+fn size(screen: egui::Vec2) -> egui::Vec2 {
+ let max = egui::vec2(1320.0, 900.0).min(screen - egui::vec2(48.0, 96.0)).max(egui::vec2(240.0, 180.0));
+ let min = egui::vec2(640.0, 480.0).min(max);
+ (screen * 0.8).clamp(min, max)
+}
+
+/// One frame of the open dialog, drawn in DesignCraft's movable modal.
+pub(crate) fn show(app: &mut DesignApp, ctx: &egui::Context) {
+ let mut host = app.shortcut_dialog.take().unwrap_or_else(|| Box::new(Host::new()));
+ let lang = app.ui.language.clone();
+ let text = DcText { lang: &lang };
+ let title = tr(&lang, "Keyboard Shortcuts");
- let area = egui::Id::new("dialog");
++ let area = egui::Id::unique("dialog");
+ let instance = area.with(DIALOG_ID);
+ let body = size(ctx.content_rect().size());
+ let mut out = None;
+ crate::modal_drag::modal(ctx, area, instance).backdrop_color(egui::Color32::TRANSPARENT).show(ctx, |ui| {
+ let title_top = ui.cursor().top();
+ crate::rtl::label(ui, egui::RichText::new(title).font(crate::theme::semibold(16.0)));
+ let margin = egui::Frame::popup(ui.style()).inner_margin;
+ let title_row = egui::Rect::from_min_max(
+ egui::pos2(ui.max_rect().left() - margin.leftf(), title_top - margin.topf()),
+ egui::pos2(ui.max_rect().left() + body.x + margin.rightf(), ui.min_rect().bottom()),
+ );
+ crate::modal_drag::title_drag(ui, instance, title_row);
+ ui.add_space(8.0);
+ let (rect, _) = ui.allocate_exact_size(body, egui::Sense::hover());
+ let mut child = ui.new_child(egui::UiBuilder::new().max_rect(rect).layout(egui::Layout::top_down(egui::Align::Min)));
+ let dialog = ShortcutsDialog::new(&mut app.keymap, &text).options(&host.options).sets(&mut app.ui.shortcut_sets, &BUILTINS);
+ out = dialog.ui(&mut child, &mut host.state);
+ });
+ // Live: the menus, `sync_keymap` and ui.json follow every edit, and a Cancel. The dialog
+ // saves the sets itself.
+ if app.ui.shortcuts != *app.keymap.overrides() {
+ app.ui.shortcuts = app.keymap.overrides().clone();
+ }
+ match out {
+ Some(Outcome::Import { .. }) => request_import(app, &mut host),
+ Some(Outcome::Export { name, json }) => save_file(app, &format!("{name}.json"), json.as_bytes()),
+ Some(Outcome::Summary { name, html, .. }) => save_file(app, &format!("{name}.html"), html.as_bytes()),
+ Some(Outcome::Remembered(answers)) => app.shortcut_answers = answers,
+ _ => {}
+ }
+ if host.state.is_open() {
+ app.shortcut_dialog = Some(host);
+ return;
+ }
+ if app.ui.dialog.as_ref().is_some_and(|d| d.id == DIALOG_ID) {
+ app.ui.dialog = None;
+ }
+ crate::keys::store(app);
+}
+
+/// OK (`ok`) or Cancel from outside the dialog: `ui.dialog.confirm` and `ui.dialog.cancel`, or
+/// another dialog taking its place. An OK the dialog refuses (no room for another set) leaves it
+/// open with its message and returns the error.
+pub(crate) fn close(app: &mut DesignApp, ok: bool) -> Result<(), String> {
+ let Some(mut host) = app.shortcut_dialog.take() else { return Ok(()) };
+ let lang = app.ui.language.clone();
+ let text = DcText { lang: &lang };
+ let dialog = ShortcutsDialog::new(&mut app.keymap, &text).options(&host.options).sets(&mut app.ui.shortcut_sets, &BUILTINS);
+ if ok {
+ dialog.ok(&mut host.state);
+ } else {
+ dialog.cancel(&mut host.state);
+ }
+ crate::keys::store(app);
+ if ok && host.state.is_open() {
+ app.shortcut_dialog = Some(host);
+ app.ui.dialog = Some(crate::dialogs::Dialog::new(DIALOG_ID, json!({})));
+ return Err("the shortcut set could not be saved".into());
+ }
+ Ok(())
+}
+
+/// Import: a native picker reads the file at once; in a browser it arrives later through
+/// [`deliver`].
+fn request_import(app: &mut DesignApp, host: &mut Host) {
+ if let Some(pick) = app.services.pick_open.as_mut() {
+ let Some(path) = pick(PURPOSE) else { return };
+ match crate::shortcut_import::read_file(&path) {
+ Ok(text) => review(app, host, &text),
+ Err(e) => host.state.show_error(e),
+ }
+ return;
+ }
+ let request = app.import_request(PURPOSE);
+ if let Some(open) = app.services.open_async.as_mut() {
+ open(request);
+ }
+}
+
+/// A set file chosen in the browser, for the open dialog. False when the dialog is closed.
+pub(crate) fn deliver(app: &mut DesignApp, bytes: &[u8]) -> bool {
+ let Some(mut host) = app.shortcut_dialog.take() else { return false };
+ match crate::shortcut_import::decode(bytes) {
+ Ok(text) => review(app, &mut host, &text),
+ Err(e) => host.state.show_error(e),
+ }
+ app.shortcut_dialog = Some(host);
+ true
+}
+
+/// A set file's text into the dialog: craft-keymap JSON becomes a new set at once (the dialog
+/// shows why it cannot); an InDesign set opens the import review.
+fn review(app: &mut DesignApp, host: &mut Host, text: &str) {
+ let lang = app.ui.language.clone();
+ let words = DcText { lang: &lang };
+ if text.trim_start().starts_with('{') {
+ let dialog = ShortcutsDialog::new(&mut app.keymap, &words).options(&host.options).sets(&mut app.ui.shortcut_sets, &BUILTINS);
+ // A refused file is reported in the dialog.
+ let _ = dialog.import_json(&mut host.state, text);
+ return;
+ }
+ match crate::shortcut_import::read_set(text) {
+ Ok(set) => {
+ let options = crate::shortcut_import::import_options(app.shortcut_answers.clone());
+ let dialog = ShortcutsDialog::new(&mut app.keymap, &words).options(&host.options).sets(&mut app.ui.shortcut_sets, &BUILTINS);
+ dialog.review_import(&mut host.state, set, options);
+ }
+ Err(e) => host.state.show_error(e),
+ }
+}
+
+/// Writes a file the dialog made where the user chooses (a download on the web).
+fn save_file(app: &mut DesignApp, name: &str, bytes: &[u8]) {
+ let name: String = name.chars().map(|c| if c.is_control() || matches!(c, '/' | '\\' | ':') { '_' } else { c }).collect();
+ let Some(path) = app.services.pick_save.as_mut().and_then(|f| f(&name)) else { return };
+ let result = match app.services.write.as_mut() {
+ Some(write) => write(&path, bytes),
+ None => Err("no writer".into()),
+ };
+ match result {
+ Ok(()) => app.status(tr(&app.ui.language, "Saved to {path}").replace("{path}", &path)),
+ Err(e) => app.status(e),
+ }
+}
+
+/// Loads the active set into the keymap and `ui.shortcuts` (after an import made a new set).
+pub(crate) fn load_active_set(app: &mut DesignApp) {
+ let overrides = app.ui.shortcut_sets.active_overrides(&BUILTINS).clone();
+ app.keymap.set_overrides(overrides.clone());
+ app.ui.shortcuts = overrides;
+}
+
+/// The strings the dialog looks up: `craft_keymap::ui::STRINGS` and both forms of its plurals.
+#[cfg(test)]
+pub(crate) fn strings() -> impl Iterator<Item = &'static str> {
+ craft_keymap::ui::STRINGS.iter().copied().chain(craft_keymap::ui::PLURALS.iter().flat_map(|(one, other)| [*one, *other]))
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use craft_keymap::{CommandRef, Trigger};
+ use egui::{Key, Modifiers, vec2};
+ use egui_kittest::Harness;
+ use egui_kittest::kittest::Queryable;
+
+ use crate::menus::shortcut_of;
+
+ fn app() -> DesignApp {
+ DesignApp::new(designcraft_engine::Session::new(), crate::Services::default())
+ }
+
+ /// The app's frame as far as shortcuts go: key dispatch, then the open dialog.
+ fn harness(app: DesignApp) -> Harness<'static, DesignApp> {
+ let mut ready = false;
+ let mut h = Harness::builder().with_size(vec2(1280.0, 860.0)).build_ui_state(
+ move |ui, app: &mut DesignApp| {
+ if !ready {
+ crate::theme::install_fonts(ui.ctx(), &app.ui.language);
+ crate::theme::apply(ui.ctx(), &crate::theme::Tokens::for_brightness(crate::theme::Brightness::default()));
+ ready = true;
+ return;
+ }
+ crate::menus::shortcuts(app, ui.ctx());
+ crate::dialogs::show(app, ui.ctx());
+ },
+ app,
+ );
+ h.run();
+ h
+ }
+
+ fn opened() -> Harness<'static, DesignApp> {
+ let mut app = app();
+ app.run("app.keyboardShortcuts", json!({})).unwrap();
+ harness(app)
+ }
+
+ fn click(h: &mut Harness<'_, DesignApp>, label: &str) {
+ h.get_by_label(label).click();
+ h.run();
+ }
+
+ fn press(h: &mut Harness<'_, DesignApp>, modifiers: Modifiers, key: Key) {
+ h.key_press_modifiers(modifiers, key);
+ h.run();
+ }
+
+ fn has(h: &Harness<'_, DesignApp>, label: &str) -> bool {
+ h.query_by_label(label).is_some()
+ }
+
+ fn chord(h: &Harness<'_, DesignApp>, text: &str) -> String {
+ Trigger::parse(text).unwrap().display(h.state().keymap.platform())
+ }
+
+ /// Searches for a command and returns the label of its row's shortcut cell, which starts
+ /// recording.
+ fn row(h: &mut Harness<'_, DesignApp>, label: &str, id: &str) -> String {
+ h.get_by_label("Search:").focus();
+ h.run();
+ h.get_by_label("Search:").type_text(label);
+ h.run();
+ format!("{label}: {}", crate::keys::shortcut_display(&h.state().keymap, &CommandRef::new(id)).unwrap())
+ }
+
+ /// A command's shortcut with no changes.
+ fn default_of(id: &str) -> Option<String> {
+ crate::keys::shortcut(&crate::keys::new_keymap(Overrides::new()), &CommandRef::new(id))
+ }
+
+ fn open(h: &Harness<'_, DesignApp>) -> bool {
+ h.state().ui.dialog.as_ref().is_some_and(|d| d.id == DIALOG_ID) && h.state().shortcut_dialog.is_some()
+ }
+
+ #[test]
+ fn a_recorded_chord_runs_nothing_changes_the_menus_at_once_and_ok_keeps_a_custom_set() {
+ let mut h = opened();
+ let quick_apply = row(&mut h, "Quick Apply…", "app.palette");
+ click(&mut h, &quick_apply);
+ // Preferences' chord is recorded, not run.
+ press(&mut h, Modifiers::COMMAND, Key::K);
+ assert!(open(&h), "Preferences did not open");
+ assert!(has(&h, &format!("⚠ {} is used by Preferences…", chord(&h, "Cmd+K"))));
+ click(&mut h, "Take It");
+ assert_eq!(shortcut_of(h.state(), "app.palette").as_deref(), Some("Cmd+K"));
+ assert_eq!(shortcut_of(h.state(), "app.preferences"), None);
+ assert_eq!(h.state().ui.shortcuts.get("app.palette"), Some(&["Cmd+K".to_string()][..]), "ui.json follows live");
+ assert!(h.state().ui.shortcut_sets.sets().is_empty(), "the set is saved by OK");
+
+ click(&mut h, "OK");
+ assert!(!open(&h) && h.state().ui.dialog.is_none());
+ let sets = &h.state().ui.shortcut_sets;
+ assert_eq!(sets.active(), "Custom", "edits of the built-in set become a copy");
+ assert_eq!(sets.active_overrides(&BUILTINS), &h.state().ui.shortcuts);
+ let saved = serde_json::to_value(&h.state().ui).unwrap();
+ assert_eq!(saved["shortcuts"]["app.palette"], "Cmd+K", "the map earlier versions read");
+ assert_eq!(saved["shortcutSets"]["active"], "Custom");
+ // The next frames keep it.
+ h.run();
+ assert_eq!(shortcut_of(h.state(), "app.palette").as_deref(), Some("Cmd+K"));
+ }
+
+ #[test]
+ fn cancel_puts_the_keys_and_the_sets_back() {
+ let mut h = opened();
+ let quick_apply = row(&mut h, "Quick Apply…", "app.palette");
+ click(&mut h, &quick_apply);
+ press(&mut h, Modifiers::COMMAND | Modifiers::ALT | Modifiers::SHIFT, Key::Num9);
+ assert_eq!(shortcut_of(h.state(), "app.palette").as_deref(), Some("Cmd+Alt+Shift+9"));
+ click(&mut h, "Cancel");
+ h.run();
+ assert!(!open(&h));
+ assert_eq!(shortcut_of(h.state(), "app.palette"), default_of("app.palette"));
+ assert!(h.state().ui.shortcuts.is_empty());
+ assert_eq!(h.state().ui.shortcut_sets, craft_keymap::Profiles::default());
+
+ // `ui.dialog.cancel` from the control channel does the same.
+ h.state_mut().run("app.keyboardShortcuts", json!({"command": "app.palette"})).unwrap();
+ h.run();
+ let quick_apply = row(&mut h, "Quick Apply…", "app.palette");
+ click(&mut h, &quick_apply);
+ press(&mut h, Modifiers::NONE, Key::F2);
+ assert_eq!(shortcut_of(h.state(), "app.palette").as_deref(), Some("F2"));
+ crate::dialogs::cancel(h.state_mut());
+ h.run();
+ assert!(!open(&h));
+ assert_eq!(shortcut_of(h.state(), "app.palette"), default_of("app.palette"));
+ }
+
+ /// An InDesign set through the dialog's Import: reviewed, then a new set with the Window menu
+ /// panel item on the panel and its twin command, and the Tools item on the tool.
+ #[test]
+ fn an_indesign_set_imports_through_the_review_as_a_new_set() {
+ let dir = tempfile::tempdir().unwrap();
+ let path = dir.path().join("studio.txt");
+ std::fs::write(
+ &path,
+ "Shortcut Set : Studio\r\n\
+ Product area : Window Menu\r\n\
+ \tType & Tables: Character --- Default: Ctrl+T\r\n\
+ Product area : Tools\r\n\
+ \tPen Tool --- Default: Shift+Ctrl+F3\r\n\
+ \tFrobnicate Tool --- Default: Shift+Ctrl+F4\r\n",
+ )
+ .unwrap();
+ let picked = path.to_string_lossy().to_string();
+ let mut app = app();
+ app.services.pick_open = Some(Box::new(move |purpose| (purpose == PURPOSE).then(|| picked.clone())));
+ app.run("app.keyboardShortcuts", json!({})).unwrap();
+ let mut h = harness(app);
+ click(&mut h, "Import…");
+ assert!(has(&h, "Import “Studio”"));
+ assert!(h.state().ui.shortcuts.is_empty(), "the review changes nothing");
+ click(&mut h, "Import as New Set");
+ assert!(has(&h, "Imported as “Studio”"));
+ let panel = |h: &Harness<'_, DesignApp>| crate::keys::shortcut(&h.state().keymap, &crate::keys::panel("character"));
+ assert_eq!(panel(&h).as_deref(), Some("Cmd+T"));
+ assert_eq!(shortcut_of(h.state(), "app.characterPanel").as_deref(), Some("Cmd+T"), "the panel's twin keeps the key they share");
+ assert_eq!(crate::keys::shortcut(&h.state().keymap, &crate::keys::tool("pen")).as_deref(), Some("Cmd+Shift+F3"));
+ click(&mut h, "Done");
+ click(&mut h, "OK");
+ assert!(!open(&h));
+ assert_eq!(h.state().ui.shortcut_sets.active(), "Studio");
+ assert_eq!(h.state().ui.shortcut_sets.active_overrides(&BUILTINS), &h.state().ui.shortcuts);
+ // Back to the defaults by switching sets.
+ h.state_mut().run("window.shortcutSets", json!({"select": "Default"})).unwrap();
+ assert_eq!(
+ crate::keys::shortcut(&h.state().keymap, &crate::keys::tool("pen")),
+ crate::keys::shortcut(&crate::keys::new_keymap(Overrides::new()), &crate::keys::tool("pen"))
+ );
+ assert!(h.state().ui.shortcuts.is_empty());
+ }
+
+ #[test]
+ fn shortcuts_from_an_earlier_version_become_the_active_set() {
+ // A ui.json without sets: its changes become Custom.
+ let mut app = app();
+ app.ui = crate::UiState::from_preferences_json(br#"{"shortcuts": {"app.palette": "Cmd+Alt+Shift+9"}, "shortcutSets": false}"#).unwrap();
+ app.sync_keymap();
+ assert_eq!(app.ui.shortcut_sets.active(), "Custom");
+ assert_eq!(shortcut_of(&app, "app.palette").as_deref(), Some("Cmd+Alt+Shift+9"));
+ // An earlier version changed the shortcuts of the active set "Mine".
+ let mut saved = serde_json::to_value(&app.ui).unwrap();
+ saved["shortcutSets"] = json!({"version": 1, "active": "Mine", "sets": [{"name": "Mine", "overrides": []}]});
+ saved["shortcuts"] = json!({"app.palette": "F2"});
+ app.ui = crate::UiState::from_preferences_json(&serde_json::to_vec(&saved).unwrap()).unwrap();
+ app.sync_keymap();
+ assert_eq!(app.ui.shortcut_sets.active(), "Mine");
+ assert_eq!(app.ui.shortcut_sets.active_overrides(&BUILTINS).get("app.palette"), Some(&["F2".to_string()][..]));
+ assert_eq!(shortcut_of(&app, "app.palette").as_deref(), Some("F2"));
+ let r = app.run("window.shortcutSets", json!({"select": "Default"})).unwrap();
+ assert_eq!(r, json!({"active": "Default", "sets": ["Default", "Mine"], "builtIn": ["Default"]}));
+ assert_eq!(shortcut_of(&app, "app.palette"), default_of("app.palette"));
+ assert!(app.run("window.shortcutSets", json!({"select": "Nope"})).is_err());
+ assert!(serde_json::to_value(&app.ui).unwrap()["shortcuts"].as_object().is_some_and(|m| m.is_empty()));
+ }
+
+ #[test]
+ fn every_dialog_string_reads_in_english_without_a_translation() {
+ let text = DcText { lang: "" };
+ for s in strings() {
+ assert_eq!(text.ui(s), s);
+ }
+ assert_eq!(craft_keymap::ui::STRINGS.len(), 175);
+ assert_eq!(craft_keymap::ui::PLURALS.len(), 11);
+ assert_eq!(text.plural(2, "{n} command will change", "{n} commands will change"), "2 commands will change");
+ assert_eq!(DcText { lang: "fr" }.ui("Cancel"), tr("fr", "Cancel"));
+ }
+}
diff --cc docs/target-app-parity.md
index c67de230a,8d30ca0bf..fe1b88c0e
--- a/docs/target-app-parity.md
+++ b/docs/target-app-parity.md
@@@ -1,6 -1,6 +1,6 @@@
# DesignCraft parity with Adobe InDesign
- > **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-20 · **Change:** minor (Keyboard Shortcuts on craft-keymap's shared dialog, with shortcut sets; File ▸ Open Recent; .indd and .indt open through indd-utils; text threads by hand; image clipping paths from IDML; anchored objects wrap text; Tabs panel listed as present (#343); spring-loaded Zoom navigation; recovery checkpoint retention; cancelable macOS Dock Quit; Based on Parent; object styles carry effects; colour management on craft-cms, Coated FOGRA39 default CMYK; swatches on placed greyscale and bitmap images) · **Target:** Adobe InDesign 2026 (21.6.0.57, macOS)
-> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-24 · **Change:** minor (Convert Variable to Text; list buttons with the default hanging indent; custom anchored objects honour Relative to Spine; PDF/X-4 visible unembedded font detection, #909; autoflow fills the following pages first; File ▸ Open Recent; .indd and .indt open through indd-utils; text threads by hand; image clipping paths from IDML; anchored objects wrap text; Tabs panel listed as present (#343); spring-loaded Zoom navigation; recovery checkpoint retention; cancelable macOS Dock Quit; Based on Parent; object styles carry effects; colour management on craft-cms, Coated FOGRA39 default CMYK; swatches on placed greyscale and bitmap images) · **Target:** Adobe InDesign 2026 (21.6.0.57, macOS)
++> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-24 · **Change:** minor (Keyboard Shortcuts on craft-keymap's shared dialog, with shortcut sets; Convert Variable to Text; list buttons with the default hanging indent; custom anchored objects honour Relative to Spine; PDF/X-4 visible unembedded font detection, #909; autoflow fills the following pages first; File ▸ Open Recent; .indd and .indt open through indd-utils; text threads by hand; image clipping paths from IDML; anchored objects wrap text; Tabs panel listed as present (#343); spring-loaded Zoom navigation; recovery checkpoint retention; cancelable macOS Dock Quit; Based on Parent; object styles carry effects; colour management on craft-cms, Coated FOGRA39 default CMYK; swatches on placed greyscale and bitmap images) · **Target:** Adobe InDesign 2026 (21.6.0.57, macOS)
The authoritative assessment of how close DesignCraft is to Adobe InDesign. [ROADMAP.md](../ROADMAP.md)
summarizes it; [gaps.md](gaps.md) lists every known shortfall one at a time; the feature-by-feature