application_menu.rs
1use ui::{prelude::*, ContextMenu, NumericStepper, PopoverMenu, PopoverMenuHandle, Tooltip};
2
3pub struct ApplicationMenu {
4 context_menu_handle: PopoverMenuHandle<ContextMenu>,
5}
6
7impl ApplicationMenu {
8 pub fn new(_: &mut ViewContext<Self>) -> Self {
9 Self {
10 context_menu_handle: PopoverMenuHandle::default(),
11 }
12 }
13}
14
15impl Render for ApplicationMenu {
16 fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
17 PopoverMenu::new("application-menu")
18 .menu(move |cx| {
19 ContextMenu::build(cx, move |menu, cx| {
20 menu.header("Workspace")
21 .action(
22 "Open Command Palette",
23 Box::new(zed_actions::command_palette::Toggle),
24 )
25 .when_some(cx.focused(), |menu, focused| menu.context(focused))
26 .custom_row(move |cx| {
27 h_flex()
28 .gap_2()
29 .w_full()
30 .justify_between()
31 .cursor(gpui::CursorStyle::Arrow)
32 .child(Label::new("Buffer Font Size"))
33 .child(
34 NumericStepper::new(
35 "buffer-font-size",
36 theme::get_buffer_font_size(cx).to_string(),
37 |_, cx| {
38 cx.dispatch_action(Box::new(
39 zed_actions::DecreaseBufferFontSize,
40 ))
41 },
42 |_, cx| {
43 cx.dispatch_action(Box::new(
44 zed_actions::IncreaseBufferFontSize,
45 ))
46 },
47 )
48 .reserve_space_for_reset(true)
49 .when(
50 theme::has_adjusted_buffer_font_size(cx),
51 |stepper| {
52 stepper.on_reset(|_, cx| {
53 cx.dispatch_action(Box::new(
54 zed_actions::ResetBufferFontSize,
55 ))
56 })
57 },
58 ),
59 )
60 .into_any_element()
61 })
62 .custom_row(move |cx| {
63 h_flex()
64 .gap_2()
65 .w_full()
66 .justify_between()
67 .cursor(gpui::CursorStyle::Arrow)
68 .child(Label::new("UI Font Size"))
69 .child(
70 NumericStepper::new(
71 "ui-font-size",
72 theme::get_ui_font_size(cx).to_string(),
73 |_, cx| {
74 cx.dispatch_action(Box::new(
75 zed_actions::DecreaseUiFontSize,
76 ))
77 },
78 |_, cx| {
79 cx.dispatch_action(Box::new(
80 zed_actions::IncreaseUiFontSize,
81 ))
82 },
83 )
84 .reserve_space_for_reset(true)
85 .when(
86 theme::has_adjusted_ui_font_size(cx),
87 |stepper| {
88 stepper.on_reset(|_, cx| {
89 cx.dispatch_action(Box::new(
90 zed_actions::ResetUiFontSize,
91 ))
92 })
93 },
94 ),
95 )
96 .into_any_element()
97 })
98 .header("Project")
99 .action(
100 "Add Folder to Project...",
101 Box::new(workspace::AddFolderToProject),
102 )
103 .action("Open a new Project...", Box::new(workspace::Open))
104 .action(
105 "Open Recent Projects...",
106 Box::new(zed_actions::OpenRecent {
107 create_new_window: false,
108 }),
109 )
110 .header("Help")
111 .action("About Zed", Box::new(zed_actions::About))
112 .action("Welcome", Box::new(workspace::Welcome))
113 .link(
114 "Documentation",
115 Box::new(zed_actions::OpenBrowser {
116 url: "https://zed.dev/docs".into(),
117 }),
118 )
119 .action(
120 "Give Feedback",
121 Box::new(zed_actions::feedback::GiveFeedback),
122 )
123 .action("Check for Updates", Box::new(auto_update::Check))
124 .action("View Telemetry", Box::new(zed_actions::OpenTelemetryLog))
125 .action(
126 "View Dependency Licenses",
127 Box::new(zed_actions::OpenLicenses),
128 )
129 .separator()
130 .action("Quit", Box::new(zed_actions::Quit))
131 })
132 .into()
133 })
134 .trigger(
135 IconButton::new("application-menu", ui::IconName::Menu)
136 .style(ButtonStyle::Subtle)
137 .icon_size(IconSize::Small)
138 .when(!self.context_menu_handle.is_deployed(), |this| {
139 this.tooltip(|cx| Tooltip::text("Open Application Menu", cx))
140 }),
141 )
142 .with_handle(self.context_menu_handle.clone())
143 .into_any_element()
144 }
145}