Skip to content

VectorCraft: An open-source, vector art tool written by scratch in pure Rust

M14.7: Cmd/Ctrl+N opens the New Document dialog

bflatasticd0d934bfda25
diff --git a/crates/engine/src/cmd/edit.rs b/crates/engine/src/cmd/edit.rs
index c230b009b..fa58a619f 100644
--- a/crates/engine/src/cmd/edit.rs
+++ b/crates/engine/src/cmd/edit.rs
@@ -17,7 +17,7 @@ pub fn specs() -> Vec<CommandSpec> {
"file.new",
"New…",
["File"],
- Some("Cmd+N"),
+ None,
"{preset?: a name from file.newPresets (start from it; the other params change it), name?|title?: document name (default Untitled-N), width?: pt=612|\"210 mm\", height?: pt=792, units?: \"Pixels\"|\"Points\"|\"Picas\"|\"Inches\"|\"Millimeters\"|\"Centimeters\"|\"Feet\"|\"Yards\"|\"Meters\"|\"Feet & Inches\" (default: prefs unitsGeneral, as print presets; screen presets: Pixels), orientation?: \"portrait\"|\"landscape\" (swaps width and height to match), artboards?: n (1–1000), artboardLayout?: {layout?: \"gridByRow\"|\"gridByColumn\"|\"row\"|\"column\", columns?: n (default: all in one row), spacing?: pt=20, rightToLeft?: bool}, bleed?: pt|[top, bottom, left, right]|{top?, …} (0–72 pt), backgroundContents?: \"transparent\"|\"white\" (a white artboard background, not an object), colorMode?: \"rgb\"|\"cmyk\" (a CMYK document starts with CMYK swatches and stores the colours applied to it as CMYK), rasterEffectsPpi?: 72|150|300 (1–2400), previewMode?: \"default\"|\"pixel\"|\"overprint\" (overprint turns Overprint Preview on, pixel Pixel Preview in the app; default leaves both), created?: Unix seconds|null (File Info's created date; default now, recorded in the journal so a replay matches)} → {index, previewMode}; the size is remembered in file.newPresets' Recent",
always,
super::newdoc::file_new
diff --git a/crates/ui-egui/src/tests_home.rs b/crates/ui-egui/src/tests_home.rs
index c3208f535..0fd8f0caf 100644
--- a/crates/ui-egui/src/tests_home.rs
+++ b/crates/ui-egui/src/tests_home.rs
@@ -1,4 +1,4 @@
-//! The Home icon shows the Home screen over open documents.
+//! The Home icon shows the Home screen over open documents; Cmd+N opens the New Document dialog.
use serde_json::json;
@@ -38,3 +38,12 @@ fn home_shows_over_open_documents_until_a_document_is_chosen() {
assert!(shows_document(&mut app));
assert!(app.ui.home.is_none());
}
+
+#[test]
+fn cmd_n_opens_the_new_document_dialog() {
+ assert_eq!(crate::shortcut_editor::command_for_key("Cmd+N"), Some("file.newDialog"));
+ let mut app = app_with_doc();
+ app.run("file.newDialog", json!({})).unwrap();
+ assert_eq!(app.ui.dialog.as_ref().map(|d| d.kind.as_str()), Some("newDocument"));
+ assert_eq!(app.session.documents().len(), 1, "no document is made until the dialog's OK");
+}