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