title_bar: Add setting to always show menu for Linux and Windows (#34139)
Closes #22869 Release Notes: - Added `show_menus` setting to always show menu bar for Linux and Windows. --------- Co-authored-by: Cole Miller <cole@zed.dev> Co-authored-by: Danilo Leal <daniloleal09@gmail.com>
This commit is contained in:
parent
6d26f107dd
commit
d5cc1cbaa9
7 changed files with 97 additions and 32 deletions
|
@ -7,7 +7,7 @@ use super::{
|
|||
use crate::{
|
||||
Action, AnyWindowHandle, BackgroundExecutor, ClipboardEntry, ClipboardItem, ClipboardString,
|
||||
CursorStyle, ForegroundExecutor, Image, ImageFormat, KeyContext, Keymap, MacDispatcher,
|
||||
MacDisplay, MacWindow, Menu, MenuItem, PathPromptOptions, Platform, PlatformDisplay,
|
||||
MacDisplay, MacWindow, Menu, MenuItem, OwnedMenu, PathPromptOptions, Platform, PlatformDisplay,
|
||||
PlatformKeyboardLayout, PlatformTextSystem, PlatformWindow, Result, SemanticVersion, Task,
|
||||
WindowAppearance, WindowParams, hash,
|
||||
};
|
||||
|
@ -170,6 +170,7 @@ pub(crate) struct MacPlatformState {
|
|||
open_urls: Option<Box<dyn FnMut(Vec<String>)>>,
|
||||
finish_launching: Option<Box<dyn FnOnce()>>,
|
||||
dock_menu: Option<id>,
|
||||
menus: Option<Vec<OwnedMenu>>,
|
||||
}
|
||||
|
||||
impl Default for MacPlatform {
|
||||
|
@ -207,6 +208,7 @@ impl MacPlatform {
|
|||
finish_launching: None,
|
||||
dock_menu: None,
|
||||
on_keyboard_layout_change: None,
|
||||
menus: None,
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -226,7 +228,7 @@ impl MacPlatform {
|
|||
|
||||
unsafe fn create_menu_bar(
|
||||
&self,
|
||||
menus: Vec<Menu>,
|
||||
menus: &Vec<Menu>,
|
||||
delegate: id,
|
||||
actions: &mut Vec<Box<dyn Action>>,
|
||||
keymap: &Keymap,
|
||||
|
@ -241,7 +243,7 @@ impl MacPlatform {
|
|||
menu.setTitle_(menu_title);
|
||||
menu.setDelegate_(delegate);
|
||||
|
||||
for item_config in menu_config.items {
|
||||
for item_config in &menu_config.items {
|
||||
menu.addItem_(Self::create_menu_item(
|
||||
item_config,
|
||||
delegate,
|
||||
|
@ -277,7 +279,7 @@ impl MacPlatform {
|
|||
dock_menu.setDelegate_(delegate);
|
||||
for item_config in menu_items {
|
||||
dock_menu.addItem_(Self::create_menu_item(
|
||||
item_config,
|
||||
&item_config,
|
||||
delegate,
|
||||
actions,
|
||||
keymap,
|
||||
|
@ -289,7 +291,7 @@ impl MacPlatform {
|
|||
}
|
||||
|
||||
unsafe fn create_menu_item(
|
||||
item: MenuItem,
|
||||
item: &MenuItem,
|
||||
delegate: id,
|
||||
actions: &mut Vec<Box<dyn Action>>,
|
||||
keymap: &Keymap,
|
||||
|
@ -399,7 +401,7 @@ impl MacPlatform {
|
|||
|
||||
let tag = actions.len() as NSInteger;
|
||||
let _: () = msg_send![item, setTag: tag];
|
||||
actions.push(action);
|
||||
actions.push(action.boxed_clone());
|
||||
item
|
||||
}
|
||||
MenuItem::Submenu(Menu { name, items }) => {
|
||||
|
@ -865,10 +867,15 @@ impl Platform for MacPlatform {
|
|||
let app: id = msg_send![APP_CLASS, sharedApplication];
|
||||
let mut state = self.0.lock();
|
||||
let actions = &mut state.menu_actions;
|
||||
let menu = self.create_menu_bar(menus, NSWindow::delegate(app), actions, keymap);
|
||||
let menu = self.create_menu_bar(&menus, NSWindow::delegate(app), actions, keymap);
|
||||
drop(state);
|
||||
app.setMainMenu_(menu);
|
||||
}
|
||||
self.0.lock().menus = Some(menus.into_iter().map(|menu| menu.owned()).collect());
|
||||
}
|
||||
|
||||
fn get_menus(&self) -> Option<Vec<OwnedMenu>> {
|
||||
self.0.lock().menus.clone()
|
||||
}
|
||||
|
||||
fn set_dock_menu(&self, menu: Vec<MenuItem>, keymap: &Keymap) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue