Skip to content

Visual Studio Code, rebuilt in Rust

Rust

feat(menubar): add the macOS Dock menu's New Window item (#119)

ithieund77be64ea10b6
diff --git a/native/crates/app/src/workbench/menubar.rs b/native/crates/app/src/workbench/menubar.rs
index 2f5df0cc239..f6486826466 100644
--- a/native/crates/app/src/workbench/menubar.rs
+++ b/native/crates/app/src/workbench/menubar.rs
@@ -79,11 +79,12 @@ pub fn install(cx: &mut App) {
// With the window active, GPUI calls this inside its `window.update`, where a nested update fails.
let id = action.id.clone();
cx.defer(move |cx| {
- // menubar.ts `runActionInRenderer`: the focused window runs it; with no window Quit quits and the
- // others open an empty window first.
+ // menubar.ts `runActionInRenderer`: the focused window runs it; with no window Quit quits, New Window
+ // opens one and the others open an empty window first.
match menu_window(cx) {
Some(window) => update_menu_window(window, cx, |workbench, window, cx| workbench.run_menu_command(&id, window, cx)),
None if id == "workbench.action.quit" => cx.quit(),
+ None if id == "workbench.action.newWindow" => crate::open_window_or_log(crate::WindowRequest::default(), cx),
None => {
let Ok(window) = crate::open_window(crate::WindowRequest::default(), cx) else { return };
let _ = window.update(cx, |workbench, window, cx| workbench.run_menu_command(&id, window, cx));
@@ -101,6 +102,14 @@ pub fn install(cx: &mut App) {
cx.on_action(|_: &Hide, cx| cx.hide());
cx.on_action(|_: &HideOthers, cx| cx.hide_other_apps());
cx.on_action(|_: &ShowAll, cx| cx.unhide_other_apps());
+ #[cfg(target_os = "macos")]
+ cx.set_dock_menu(dock_menu());
+}
+
+/// menubar.ts `install`: the Dock menu's one item, New Window, opens an empty window.
+#[cfg(target_os = "macos")]
+fn dock_menu() -> Vec<MenuItem> {
+ vec![MenuItem::action(native_label(&main_label("miNewWindow", "New &&Window")), RunMenuCommand { id: "workbench.action.newWindow".into() })]
}
/// The window menu actions go to: the active workbench or editor window, else the frontmost workbench window, else
diff --git a/native/crates/app/src/workbench/menubar/tests.rs b/native/crates/app/src/workbench/menubar/tests.rs
index c968c6b3de9..42e09e29afb 100644
--- a/native/crates/app/src/workbench/menubar/tests.rs
+++ b/native/crates/app/src/workbench/menubar/tests.rs
@@ -164,6 +164,15 @@ fn the_custom_menu_bar_visibility_defaults_to_classic() {
}
}
+#[cfg(target_os = "macos")]
+#[test]
+fn the_dock_menu_has_only_new_window() {
+ let items = dock_menu();
+ let [MenuItem::Action { name, action, .. }] = items.as_slice() else { panic!("one action item, as menubar.ts install") };
+ assert_eq!(name.as_ref(), "New Window");
+ assert!(action.partial_eq(&RunMenuCommand { id: "workbench.action.newWindow".into() }));
+}
+
/// menubarControl.ts `insertActionsBefore`: Windows' Help menu has the update item and a separator before About.
#[gpui::test]
fn the_custom_help_menu_shows_the_update_state_before_about(cx: &mut TestAppContext) {
diff --git a/port/ledger/units/platform.md b/port/ledger/units/platform.md
index 992df8c34fb..3a911328f9e 100644
--- a/port/ledger/units/platform.md
+++ b/port/ledger/units/platform.md
@@ -67,7 +67,7 @@ Part of the Units table, generated by `bun port/tools/gen-ledger.ts`; the status
| platform/markdown | src/vs/platform | M13 | verified | | markdown.rs (pulldown-cmark in place of marked: paragraphs, headings, code blocks, lists, quotes, rules, bold/italic/strike/code/links, `$(icon)` drawn as 16px codicons between the text, HTML dropped, untrusted `command:` links dropped, 100000-char cap), workbench/markdown_view.rs (code blocks tokenized in their language): cargo test -p app markdown; ui-pair comment thread: the markdown comments with bold `add` as in the reference (port/results/language-features.md Comments) |
| platform/markers | src/vs/platform | M13 | verified | | markers.rs (markerService.ts: read filters, statistics, sanitizing, origins): cargo test -p app markers; ui-pair .vscode/settings.json: the `editor.fontSize: "big"` warning with its squiggle, status bar count and Problems row as in the reference (port/results/language-features.md JSON settings) |
| platform/mcp | src/vs/platform | | removed | | no sign-in/AI by decision (port/notes.md); not ported |
-| platform/menubar | src/vs/platform | M9 | verified | | workbench/menubar.rs: app, Window and Services menus of menubar.ts with key equivalents, chords in the label; AX tree of the port vs the reference (port/results/menubar.md); the menus the native bar shows match a fresh 1.147.0 `port/tools/ref-menubar` dump in the empty and file windows (cargo test -p app menubar: 12 passed, the_empty_window_menu_bar_matches_the_reference, the_folder_and_file_menu_bar_matches_the_reference); the update item after About per update state and the Window menu's Always on Top and Switch Window (cargo test -p app the_app_menu_shows_the_update_state_after_about the_window_menu_has_always_on_top_and_switch_window) |
+| platform/menubar | src/vs/platform | M9 | verified | | workbench/menubar.rs: app, Window and Services menus of menubar.ts with key equivalents, chords in the label; AX tree of the port vs the reference (port/results/menubar.md); the menus the native bar shows match a fresh 1.147.0 `port/tools/ref-menubar` dump in the empty and file windows (cargo test -p app menubar: 16 passed, the_empty_window_menu_bar_matches_the_reference, the_folder_and_file_menu_bar_matches_the_reference); the update item after About per update state and the Window menu's Always on Top and Switch Window (cargo test -p app the_app_menu_shows_the_update_state_after_about the_window_menu_has_always_on_top_and_switch_window); the Dock menu's New Window item (cargo test -p app the_dock_menu_has_only_new_window) |
| platform/meteredConnection | src/vs/platform | M19 | verified | | metered_connection.rs: Network.framework path monitor, metered when expensive or constrained (Low Data Mode), network.meteredConnection; port/tools/shell-check (port/fixtures/extensions/shell-tests, 6/6); cargo test -p app metered_connection |
| platform/native | src/vs/platform | M11 | verified | | workbench/host.rs, lifecycle.rs, dialog.rs, file_dialog.rs, clipboard.rs, workbench/shell_command.rs (the link port/tools/package-app writes): cargo test -p app host lifecycle dialog shell_command::; ui-pair hot-exit.json, messages.json, dialogs.json (port/results/windows.md, milestone 11 verification). n/a: devtools, tracing and GPU info; removed by decision: `window.nativeTabs` |
| platform/networkFilter | src/vs/platform | | removed | | no AI or Microsoft services by decision (port/notes.md); API stays inert |