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