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