Skip to content

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

U: menu customization and Show All Menu Items

Brandon Thomas43ba0bf086ac
diff --git a/ROADMAP.md b/ROADMAP.md
index 87fb84830..bbdf404b6 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -79,6 +79,7 @@ DesignCraft aims at full Adobe InDesign parity — and to be better: faster, ope
- Adjust Layout / Layout Adjustment (`adjustLayout` on Document Setup and Margins and Columns): objects follow each page's margin box to its new size and position.
- Content Collector and Placer tools (B; `conveyor.collect/place/list/clear`): copies of objects (with stories, styles, images) ride a conveyor between pages and documents; Alt-click keeps them on it.
- Linked stories (Edit ▸ Place and Link, `story.placeAndLink/links/updateLink/unlink`): child stories copy a parent, show out of date in the Links panel and update.
+- Edit ▸ Menus (`window.hideMenuItem`): hide menu items; menus with hidden items end in Show All Menu Items.
- Drag and drop text editing: drag selected text to move it (Alt copies) with its formatting (`text.release`).
- Image Import Options: place any page of a multi-page PDF (`file.place {pdfPage}`; the app asks which page), shown on screen and embedded as that page in PDF export.
- Define Lists: named numbered lists that continue across stories in page order (`list.define`, paragraph `listName` / `startAt`), round-tripped through IDML; `null` in `type.para` / `type.char` now removes an override.
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index 174f3b019..f260783b6 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -643,6 +643,7 @@ pub fn show(app: &mut DesignApp, ctx: &egui::Context) {
"polygonSettings" => "Polygon Settings",
"userDictionary" => "User Dictionary",
"newWorkspace" => "New Workspace",
+ "menus" => "Menu Customization",
"importOptions" => "Import Options",
"fittingOptions" => "Frame Fitting Options",
"qrCode" => "Generate QR Code",
@@ -871,6 +872,19 @@ pub fn show(app: &mut DesignApp, ctx: &egui::Context) {
}
"keyboardShortcuts" => keyboard_shortcuts(app, ui, &mut d),
"userDictionary" => user_dictionary(app, ui, &mut d),
+ "menus" => {
+ text_field(ui, &mut d, "query", 260.0);
+ let q = d.s("query").to_lowercase();
+ egui::ScrollArea::vertical().max_height(320.0).show(ui, |ui| {
+ for (menu, label) in crate::menus::all_menu_items().into_iter().filter(|(m, l)| q.is_empty() || m.to_lowercase().contains(&q) || l.to_lowercase().contains(&q)) {
+ let key = crate::menus::menu_key(&menu, &label);
+ let mut visible = !app.ui.hidden_menu_items.contains(&key);
+ if ui.checkbox(&mut visible, format!("{menu} › {label}")).changed() {
+ let _ = app.run("window.hideMenuItem", json!({"item": key, "hidden": !visible}));
+ }
+ }
+ });
+ }
"importOptions" => {
ui.label(egui::RichText::new(d.s("path")).size(10.5));
check(ui, &mut d, "removeStyles", "Remove Styles and Formatting from Text and Tables");
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 36793f2d8..453c45b44 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -99,6 +99,9 @@ pub struct UiState {
pub hidden_characters: bool,
/// View › Structure › Show Tagged Frames.
pub tagged_frames: bool,
+ /// Edit › Menus: hidden menu items (`menu/label`), and Show Full Menus.
+ pub hidden_menu_items: Vec<String>,
+ pub show_full_menus: bool,
/// View › Display Performance.
pub display_quality: designcraft_render::DisplayQuality,
/// Preferences › Interface › UI scaling (1 = 100%).
@@ -159,6 +162,8 @@ impl Default for UiState {
text_threads: false,
hidden_characters: false,
tagged_frames: false,
+ hidden_menu_items: Vec::new(),
+ show_full_menus: false,
display_quality: designcraft_render::DisplayQuality::High,
ui_scale: 1.0,
rich_black: false,
diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs
index 05754fcac..34d8c2f5c 100644
--- a/crates/ui-egui/src/menus.rs
+++ b/crates/ui-egui/src/menus.rs
@@ -24,6 +24,8 @@ pub const UI_COMMANDS: &[(&str, &str, Option<&str>, &str)] = &[
("app.qrCode", "Generate QR Code…", None, "{} — the QR Code dialog (object.qrCode does the work)"),
("app.userDictionary", "User Dictionary…", None, "{} — hyphenation exceptions (hyphenation.* commands)"),
("app.fittingOptions", "Frame Fitting Options…", None, "{} — the dialog for object.fittingOptions"),
+ ("app.menus", "Menus…", None, "{} — show or hide menu items"),
+ ("window.hideMenuItem", "Hide Menu Item", None, "{item: \"Menu/Label\", hidden?: bool}"),
("app.placeAndLink", "Place and Link", None, "{} — a linked copy of the selected frame's story, beside it"),
("app.placeWithOptions", "Place with Import Options…", Some("Cmd+Shift+D"), "{} — Word/RTF style mapping before placing"),
("app.exportText", "Export Text…", None, "{path?} — the story being edited, as Text Only (.txt) or Rich Text Format (.rtf)"),
@@ -167,6 +169,7 @@ pub const MENUS: &[(&str, &[&str])] = &[
"-",
"ui:app.palette",
"ui:app.keyboardShortcuts",
+ "ui:app.menus",
"ui:app.preferences",
],
),
@@ -593,6 +596,20 @@ pub fn run_ui(app: &mut DesignApp, id: &str, p: &Value) -> Option<Result<Value,
"app.exportHtml" => export_bytes(app, p, "html", "file.exportHtml"),
"app.exportXml" => export_bytes(app, p, "xml", "file.exportXml"),
"app.printBooklet" => export_bytes(app, p, "pdf", "file.printBooklet"),
+ "app.menus" => {
+ app.ui.dialog = Some(crate::dialogs::Dialog::new("menus", json!({"query": ""})));
+ Ok(Value::Null)
+ }
+ "window.hideMenuItem" => {
+ let Some(item) = p.get("item").and_then(Value::as_str) else { return Some(Err("missing item".into())) };
+ let hide = p.get("hidden").and_then(Value::as_bool).unwrap_or(true);
+ app.ui.hidden_menu_items.retain(|x| x != item);
+ if hide {
+ app.ui.hidden_menu_items.push(item.to_string());
+ }
+ app.ui.show_full_menus = false;
+ Ok(Value::Null)
+ }
"app.placeAndLink" => {
let target = app.session.active().and_then(|d| {
let id = *d.selection.items.first()?;
@@ -1362,20 +1379,37 @@ pub fn menu_bar(app: &mut DesignApp, ui: &mut egui::Ui) {
for (menu, entries) in menu_tree() {
ui.menu_button(menu, |ui| {
ui.set_min_width(240.0);
- menu_items(app, ui, &entries);
+ let hidden = menu_items(app, ui, &entries, menu);
+ if hidden > 0 && !app.ui.show_full_menus {
+ ui.separator();
+ if ui.button("Show All Menu Items").clicked() {
+ app.ui.show_full_menus = true;
+ }
+ }
});
}
}
-fn menu_items(app: &mut DesignApp, ui: &mut egui::Ui, items: &[Item]) {
+/// The key a menu item is hidden by (Edit › Menus).
+pub fn menu_key(menu: &str, label: &str) -> String {
+ format!("{menu}/{label}")
+}
+
+/// Draws a menu's items; returns how many were hidden.
+fn menu_items(app: &mut DesignApp, ui: &mut egui::Ui, items: &[Item], path: &str) -> usize {
+ let mut hidden = 0;
for it in items {
match it {
Item::Sep => {
ui.separator();
}
Item::Sub(name, children) => {
- ui.menu_button(name, |ui| menu_items(app, ui, children));
+ let sub = format!("{path}/{name}");
+ ui.menu_button(name, |ui| {
+ hidden += menu_items(app, ui, children, &sub);
+ });
}
+ Item::Cmd { label, .. } if !app.ui.show_full_menus && app.ui.hidden_menu_items.contains(&menu_key(path, label)) => hidden += 1,
Item::Cmd { label, id, params, shortcut: _ } => {
let text = match checked(app, id, params) {
Some(true) => format!("✓ {label}"),
@@ -1393,6 +1427,25 @@ fn menu_items(app: &mut DesignApp, ui: &mut egui::Ui, items: &[Item]) {
}
}
}
+ hidden
+}
+
+/// Every menu item as (menu path, label), for Edit › Menus.
+pub fn all_menu_items() -> Vec<(String, String)> {
+ fn walk(items: &[Item], path: &str, out: &mut Vec<(String, String)>) {
+ for it in items {
+ match it {
+ Item::Sub(name, children) => walk(children, &format!("{path}/{name}"), out),
+ Item::Cmd { label, .. } => out.push((path.to_string(), label.clone())),
+ Item::Sep => {}
+ }
+ }
+ }
+ let mut out = Vec::new();
+ for (menu, entries) in menu_tree() {
+ walk(&entries, menu, &mut out);
+ }
+ out
}
fn parse_shortcut(sc: &str) -> Option<(egui::Modifiers, egui::Key)> {
@@ -1674,4 +1727,17 @@ mod tests {
assert!(app.ui.custom_workspaces.is_empty());
assert_eq!(app.ui.workspace, "Essentials");
}
+
+ #[test]
+ fn hide_and_show_menu_items() {
+ let mut app = crate::DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ let items = all_menu_items();
+ let (menu, label) = items.iter().find(|(m, _)| m == "Edit").cloned().expect("Edit items");
+ let key = menu_key(&menu, &label);
+ run_ui(&mut app, "window.hideMenuItem", &json!({"item": key})).unwrap().unwrap();
+ assert!(app.ui.hidden_menu_items.contains(&key));
+ run_ui(&mut app, "window.hideMenuItem", &json!({"item": key, "hidden": false})).unwrap().unwrap();
+ assert!(app.ui.hidden_menu_items.is_empty());
+ assert!(items.len() > 100, "every menu's items are listed: {}", items.len());
+ }
}
diff --git a/docs/parity.md b/docs/parity.md
index e2d86516a..3aea863d5 100644
--- a/docs/parity.md
+++ b/docs/parity.md
@@ -11,11 +11,11 @@ Each row of the InDesign feature catalogue is scored **D** (done), **P** (partia
|---|---|---|---|---|---|
| P0 | 102 | 99 | 3 | 0 | 99% |
| P1 | 97 | 92 | 4 | 1 | 97% |
-| P2 | 76 | 31 | 18 | 27 | 53% |
+| P2 | 76 | 33 | 18 | 25 | 55% |
| Area | Parity |
|---|---|
-| Application shell & workspace | 82% |
+| Application shell & workspace | 88% |
| Documents, pages, spreads | 90% |
| Layers | 95% |
| Frames, shapes & paths | 99% |
@@ -52,8 +52,8 @@ Open P0 items: Preferences, Vector/page formats (PDF/AI/SVG/EPS place), Export t
| Application shell & workspace | Themes | P0 | D |
| Application shell & workspace | UI scaling | P1 | D |
| Application shell & workspace | Keyboard shortcut editor | P1 | D |
-| Application shell & workspace | Menu customization | P2 | M |
-| Application shell & workspace | Show Full Menus | P2 | M |
+| Application shell & workspace | Menu customization | P2 | D |
+| Application shell & workspace | Show Full Menus | P2 | D |
| Application shell & workspace | Recovery / autosave | P0 | D |
| Application shell & workspace | Preferences | P0 | P |
| Application shell & workspace | Localization | P2 | M |