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