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