application_menu.rs
1use settings::Settings;
2use theme::ThemeSettings;
3use ui::{prelude::*, ContextMenu, PopoverMenu, Tooltip};
4
5#[derive(IntoElement)]
6pub struct ApplicationMenu;
7
8impl ApplicationMenu {
9 pub fn new() -> Self {
10 Self
11 }
12}
13
14impl RenderOnce for ApplicationMenu {
15 fn render(self, cx: &mut WindowContext) -> impl IntoElement {
16 let ui_font_size = ThemeSettings::get_global(cx).ui_font_size;
17 let font = cx.text_style().font();
18 let font_id = cx.text_system().resolve_font(&font);
19 let width = cx
20 .text_system()
21 .typographic_bounds(font_id, ui_font_size, 'm')
22 .unwrap()
23 .size
24 .width
25 * 3.0;
26
27 PopoverMenu::new("application-menu")
28 .menu(move |cx| {
29 let width = width;
30 ContextMenu::build(cx, move |menu, _cx| {
31 let width = width;
32 menu.header("Workspace")
33 .action("Open Command Palette", Box::new(command_palette::Toggle))
34 .custom_row(move |cx| {
35 div()
36 .w_full()
37 .flex()
38 .flex_row()
39 .justify_between()
40 .cursor(gpui::CursorStyle::Arrow)
41 .child(Label::new("Buffer Font Size"))
42 .child(
43 div()
44 .flex()
45 .flex_row()
46 .child(div().w(px(16.0)))
47 .child(
48 IconButton::new(
49 "reset-buffer-zoom",
50 IconName::RotateCcw,
51 )
52 .on_click(
53 |_, cx| {
54 cx.dispatch_action(Box::new(
55 zed_actions::ResetBufferFontSize,
56 ))
57 },
58 ),
59 )
60 .child(
61 IconButton::new("--buffer-zoom", IconName::Dash)
62 .on_click(|_, cx| {
63 cx.dispatch_action(Box::new(
64 zed_actions::DecreaseBufferFontSize,
65 ))
66 }),
67 )
68 .child(
69 div()
70 .w(width)
71 .flex()
72 .flex_row()
73 .justify_around()
74 .child(Label::new(
75 theme::get_buffer_font_size(cx).to_string(),
76 )),
77 )
78 .child(
79 IconButton::new("+-buffer-zoom", IconName::Plus)
80 .on_click(|_, cx| {
81 cx.dispatch_action(Box::new(
82 zed_actions::IncreaseBufferFontSize,
83 ))
84 }),
85 ),
86 )
87 .into_any_element()
88 })
89 .custom_row(move |cx| {
90 div()
91 .w_full()
92 .flex()
93 .flex_row()
94 .justify_between()
95 .cursor(gpui::CursorStyle::Arrow)
96 .child(Label::new("UI Font Size"))
97 .child(
98 div()
99 .flex()
100 .flex_row()
101 .child(
102 IconButton::new("reset-ui-zoom", IconName::RotateCcw)
103 .on_click(|_, cx| {
104 cx.dispatch_action(Box::new(
105 zed_actions::ResetUiFontSize,
106 ))
107 }),
108 )
109 .child(
110 IconButton::new("--ui-zoom", IconName::Dash).on_click(
111 |_, cx| {
112 cx.dispatch_action(Box::new(
113 zed_actions::DecreaseUiFontSize,
114 ))
115 },
116 ),
117 )
118 .child(
119 div()
120 .w(width)
121 .flex()
122 .flex_row()
123 .justify_around()
124 .child(Label::new(
125 theme::get_ui_font_size(cx).to_string(),
126 )),
127 )
128 .child(
129 IconButton::new("+-ui-zoom", IconName::Plus).on_click(
130 |_, cx| {
131 cx.dispatch_action(Box::new(
132 zed_actions::IncreaseUiFontSize,
133 ))
134 },
135 ),
136 ),
137 )
138 .into_any_element()
139 })
140 .header("Project")
141 .action(
142 "Add Folder to Project...",
143 Box::new(workspace::AddFolderToProject),
144 )
145 .action("Open a new Project...", Box::new(workspace::Open))
146 .action(
147 "Open Recent Projects...",
148 Box::new(recent_projects::OpenRecent {
149 create_new_window: false,
150 }),
151 )
152 .header("Help")
153 .action("About Zed", Box::new(zed_actions::About))
154 .action("Welcome", Box::new(workspace::Welcome))
155 .link(
156 "Documentation",
157 Box::new(zed_actions::OpenBrowser {
158 url: "https://zed.dev/docs".into(),
159 }),
160 )
161 .action("Give Feedback", Box::new(feedback::GiveFeedback))
162 .action("Check for Updates", Box::new(auto_update::Check))
163 .action("View Telemetry", Box::new(zed_actions::OpenTelemetryLog))
164 .action(
165 "View Dependency Licenses",
166 Box::new(zed_actions::OpenLicenses),
167 )
168 .separator()
169 .action("Quit", Box::new(zed_actions::Quit))
170 })
171 .into()
172 })
173 .trigger(
174 IconButton::new("application-menu", ui::IconName::Menu)
175 .style(ButtonStyle::Subtle)
176 .tooltip(|cx| Tooltip::text("Open Application Menu", cx))
177 .icon_size(IconSize::Small),
178 )
179 .into_any_element()
180 }
181}