From b51a28b75fbf5e94c69ef81d279d3f7000807367 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sun, 22 Dec 2024 00:03:17 +0200 Subject: [PATCH] Return back Windows menu (#22339) Follow-up of https://github.com/zed-industries/zed/pull/21873 Release Notes: - N/A --- crates/gpui/src/platform/windows/platform.rs | 11 ++++++++- crates/title_bar/src/title_bar.rs | 25 ++++++++++---------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/crates/gpui/src/platform/windows/platform.rs b/crates/gpui/src/platform/windows/platform.rs index 1da9dbc0cf..d292610768 100644 --- a/crates/gpui/src/platform/windows/platform.rs +++ b/crates/gpui/src/platform/windows/platform.rs @@ -48,6 +48,7 @@ pub(crate) struct WindowsPlatform { pub(crate) struct WindowsPlatformState { callbacks: PlatformCallbacks, + menus: Vec, // NOTE: standard cursor handles don't need to close. pub(crate) current_cursor: HCURSOR, } @@ -70,6 +71,7 @@ impl WindowsPlatformState { Self { callbacks, current_cursor, + menus: Vec::new(), } } } @@ -449,8 +451,15 @@ impl Platform for WindowsPlatform { self.state.borrow_mut().callbacks.reopen = Some(callback); } + fn set_menus(&self, menus: Vec, _keymap: &Keymap) { + self.state.borrow_mut().menus = menus.into_iter().map(|menu| menu.owned()).collect(); + } + + fn get_menus(&self) -> Option> { + Some(self.state.borrow().menus.clone()) + } + // todo(windows) - fn set_menus(&self, _menus: Vec, _keymap: &Keymap) {} fn set_dock_menu(&self, _menus: Vec, _keymap: &Keymap) {} fn on_app_menu_action(&self, callback: Box) { diff --git a/crates/title_bar/src/title_bar.rs b/crates/title_bar/src/title_bar.rs index 55834d982f..dac9a98d69 100644 --- a/crates/title_bar/src/title_bar.rs +++ b/crates/title_bar/src/title_bar.rs @@ -134,18 +134,19 @@ impl Render for TitleBar { .child( h_flex() .gap_1() - .when_some(self.application_menu.clone(), |this, menu| { - let is_any_menu_deployed = menu.read(cx).is_any_deployed(); - this.child(menu).when(!is_any_menu_deployed, |this| { - this.children(self.render_project_host(cx)) - .child(self.render_project_name(cx)) - .children(self.render_project_branch(cx)) - }) - }) - .when(self.application_menu.is_none(), |this| { - this.children(self.render_project_host(cx)) - .child(self.render_project_name(cx)) - .children(self.render_project_branch(cx)) + .map(|title_bar| { + let mut render_project_items = true; + title_bar + .when_some(self.application_menu.clone(), |title_bar, menu| { + render_project_items = !menu.read(cx).is_any_deployed(); + title_bar.child(menu) + }) + .when(render_project_items, |title_bar| { + title_bar + .children(self.render_project_host(cx)) + .child(self.render_project_name(cx)) + .children(self.render_project_branch(cx)) + }) }) .on_mouse_down(MouseButton::Left, |_, cx| cx.stop_propagation()), )