Skip to content

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

Merge branch 'keymap-adoption' into keymap-shortcuts-dialog

aiongg7ac286e6d2dc
diff --cc Cargo.lock
index 59aee3de2,e9001af76..490ad375f
--- a/Cargo.lock
+++ b/Cargo.lock
@@@ -1248,10 -1246,10 +1266,10 @@@ dependencies =
[[package]]
name = "designcraft-ui-egui"
- version = "0.9.0"
+ version = "0.12.0"
dependencies = [
"craft-keymap",
- "craft-ui",
+ "craft-ui 0.1.0 (git+https://github.com/storytold/craft-libs?rev=5c874d51eeb3de70e735c8ce87a59a7dedd47675)",
"designcraft-color",
"designcraft-compose",
"designcraft-doc",
diff --cc Cargo.toml
index c8f1c1223,c0e3d8f19..9d23a6518
--- a/Cargo.toml
+++ b/Cargo.toml
@@@ -11,10 -11,10 +11,10 @@@ rust-version = "1.95
repository = "https://github.com/storytold/designcraft"
[workspace.dependencies]
- # Shared writer; the immutable revision must be published before this consumer.
- craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "c3487320b2d1de657b860b3c8abb44e1f2b32bd8", version = "=0.1.0", default-features = false }
+ # 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 }
-# Shared keyboard bindings: chords, overrides, conflicts, egui dispatch.
-craft-keymap = { git = "https://github.com/aiongg/craft-libs", rev = "9aaf9dfd3882c12b6aab5604cc2567fc3b64127b", 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"] }
# internal
designcraft-geom = { path = "crates/geom" }
designcraft-color = { path = "crates/color" }
diff --cc apps/designcraft/src/native_menu.rs
index 396254669,1ac9437d1..0f9b24257
--- a/apps/designcraft/src/native_menu.rs
+++ b/apps/designcraft/src/native_menu.rs
@@@ -22,12 -22,14 +22,15 @@@ pub struct NativeMenu
items: HashMap<String, (String, Value, Handle)>,
events: Receiver<MenuEvent>,
last_refresh: f64,
- /// The interface language the titles are in and whether CJK features are shown: the menu is
- /// rebuilt when either changes.
- shown_for: (String, bool),
+ /// The interface language the titles are in, whether CJK features are shown and whether the
+ /// Keyboard Shortcuts dialog records keys (the menu then has no key equivalents, so the keys
+ /// reach the dialog): the menu is rebuilt when any of them changes.
+ shown_for: (String, bool, bool),
/// File › Open Recent, rebuilt when the list of recent files changes.
recent: Option<RecentMenu>,
+ /// The commands with key equivalents and the shortcut each was given: the menu is rebuilt
+ /// when one changes, so a shortcut moved to another command leaves its old item.
+ keys: Vec<(String, Option<String>)>,
}
struct RecentMenu {
@@@ -76,7 -85,7 +86,7 @@@ impl NativeMenu
for entry in menus::MAC_APP_MENU {
let _ = match *entry {
AppMenuItem::Cmd { id, label, command } => {
- let sc = shortcut(command).filter(|_| !app.shortcut_recording()).and_then(accel);
- let sc = shortcut(app, command).as_deref().and_then(accel);
++ let sc = shortcut(app, command).filter(|_| !app.shortcut_recording()).as_deref().and_then(accel);
let item = MenuItem::with_id(id, menu_title(app, label), true, sc);
let appended = app_menu.append(&item);
items.insert(id.into(), (command.into(), Value::Null, Handle::Plain(item)));
@@@ -110,8 -127,9 +128,9 @@@
items,
events,
last_refresh: 0.0,
- shown_for: (app.ui.language.clone(), designcraft_ui_egui::cjk_features(app)),
+ shown_for: (app.ui.language.clone(), designcraft_ui_egui::cjk_features(app), app.shortcut_recording()),
recent,
+ keys,
}
}
@@@ -159,13 -177,10 +178,14 @@@
}
// 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
+ {
- *self = Self::install(app, ctx);
+ let events = std::mem::replace(&mut self.events, channel().1);
+ *self = Self::build_bar(app, events);
}
let now = designcraft_ui_egui::now_ms();
if now - self.last_refresh < 250.0 {
@@@ -211,10 -233,10 +238,10 @@@ fn build
}
// Hidden CJK commands; `NativeMenu::poll` rebuilds the bar when Show CJK Features changes.
Item::Cmd { id, .. } if !menus::shown(app, id) => {}
- Item::Cmd { label, id, params, shortcut } => {
+ Item::Cmd { label, id, params, .. } => {
*counter += 1;
let mid = format!("dc{counter}");
- let sc = if params.is_null() && !app.shortcut_recording() { shortcut.and_then(accel) } else { None };
- let sc = if params.is_null() { shortcut(app, id).as_deref().and_then(accel) } else { None };
++ let sc = if params.is_null() && !app.shortcut_recording() { shortcut(app, id).as_deref().and_then(accel) } else { None };
let label = menu_title(app, label);
let handle = if menus::checked(app, id, params).is_some() {
let c = CheckMenuItem::with_id(mid.clone(), label, true, false, sc);
diff --cc crates/ui-egui/src/i18n.rs
index 1244225d3,6057abc97..7eec82c7c
--- a/crates/ui-egui/src/i18n.rs
+++ b/crates/ui-egui/src/i18n.rs
@@@ -5033,43 -4924,7 +4925,9 @@@ mod tests
"{name}: import cancelled while a dialog is open; choose the file again",
"{name}: {count} step(s) done",
]);
- // A new English string falls back to English until it is translated, so only stale
- // entries (keys nothing passes to `tr` any more) fail.
+ // The Keyboard Shortcuts dialog's strings (craft-keymap) reach `tr` too.
+ keys.extend(crate::shortcuts_dialog::strings());
- let stale: Vec<_> = catalog.keys().filter(|k| !keys.contains(*k)).collect();
- assert!(stale.is_empty(), "Czech entries for unknown keys: {stale:?}");
- let placeholders =
- |s: &str| s.split('{').skip(1).filter_map(|part| part.split_once('}').map(|(name, _)| name.to_owned())).collect::<Vec<_>>();
- for (key, translation) in cs::TABLE {
- assert!(!translation.trim().is_empty(), "empty {key}");
- let mut source = placeholders(key);
- let mut translated = placeholders(translation);
- source.sort();
- translated.sort();
- assert_eq!(source, translated, "placeholders: {key}");
- // Dialog ellipses, label colons and padded button captions stay as in English.
- assert_eq!(key.ends_with('…'), translation.ends_with('…'), "ellipsis: {key}");
- assert_eq!(key.ends_with(':'), translation.ends_with(':'), "colon: {key}");
- assert_eq!(key.starts_with(' '), translation.starts_with(' '), "leading space: {key}");
- assert_eq!(key.ends_with(' '), translation.ends_with(' '), "trailing space: {key}");
- }
- assert!(!is_rtl("cs"));
- assert_eq!(tr("cs", "File"), "Soubor");
- assert_eq!(tr("cs", "New Document…"), "Nový dokument…");
- assert_eq!(tr("cs", "Spread"), "Dvoustrana");
- assert_eq!(tr("cs", "Bleed"), "Spadávka");
- assert_eq!(tr("cs", "Leading"), "Proklad");
- assert_eq!(tr("cs", "Unknown label"), "Unknown label");
- assert_eq!(tr_context("cs", "Group", "selection"), "Skupina");
- assert_eq!(tr_context("cs", "Name", "contributors"), "Jméno");
- assert_eq!(tr_context("cs", "Name", "unknown"), "Název");
- assert_eq!(tr("cs", "Group"), "Seskupit");
- assert_eq!(tr_context("cs", "Columns", "table"), tr("cs", "Columns"));
- assert_eq!(style_name("cs", "[Basic Paragraph]"), "[Základní odstavec]");
- assert_eq!(style_name("cs", "My layout style"), "My layout style");
- assert_eq!(workspace_name("cs", "Essentials"), "Základní");
- assert_eq!(workspace_name("cs", "My workspace"), "My workspace");
+ keys
}
#[test]