title_bar.rs

  1mod application_menu;
  2mod collab;
  3mod onboarding_banner;
  4pub mod platform_title_bar;
  5mod platforms;
  6mod system_window_tabs;
  7mod title_bar_settings;
  8
  9#[cfg(feature = "stories")]
 10mod stories;
 11
 12use crate::{
 13    application_menu::{ApplicationMenu, show_menus},
 14    platform_title_bar::PlatformTitleBar,
 15    system_window_tabs::SystemWindowTabs,
 16};
 17
 18#[cfg(not(target_os = "macos"))]
 19use crate::application_menu::{
 20    ActivateDirection, ActivateMenuLeft, ActivateMenuRight, OpenApplicationMenu,
 21};
 22
 23use auto_update::AutoUpdateStatus;
 24use call::ActiveCall;
 25use client::{Client, UserStore, zed_urls};
 26use cloud_llm_client::Plan;
 27use gpui::{
 28    Action, AnyElement, App, Context, Corner, Element, Entity, Focusable, InteractiveElement,
 29    IntoElement, MouseButton, ParentElement, Render, StatefulInteractiveElement, Styled,
 30    Subscription, WeakEntity, Window, actions, div,
 31};
 32use keymap_editor;
 33use onboarding_banner::OnboardingBanner;
 34use project::Project;
 35use remote::RemoteConnectionOptions;
 36use settings::Settings as _;
 37use std::sync::Arc;
 38use theme::ActiveTheme;
 39use title_bar_settings::TitleBarSettings;
 40use ui::{
 41    Avatar, Button, ButtonLike, ButtonStyle, Chip, ContextMenu, Icon, IconName, IconSize,
 42    IconWithIndicator, Indicator, PopoverMenu, PopoverMenuHandle, Tooltip, h_flex, prelude::*,
 43};
 44use util::ResultExt;
 45use workspace::{Workspace, notifications::NotifyResultExt};
 46use zed_actions::{OpenRecent, OpenRemote};
 47
 48pub use onboarding_banner::restore_banner;
 49
 50#[cfg(feature = "stories")]
 51pub use stories::*;
 52
 53const MAX_PROJECT_NAME_LENGTH: usize = 40;
 54const MAX_BRANCH_NAME_LENGTH: usize = 40;
 55const MAX_SHORT_SHA_LENGTH: usize = 8;
 56
 57actions!(
 58    collab,
 59    [
 60        /// Toggles the user menu dropdown.
 61        ToggleUserMenu,
 62        /// Toggles the project menu dropdown.
 63        ToggleProjectMenu,
 64        /// Switches to a different git branch.
 65        SwitchBranch
 66    ]
 67);
 68
 69pub fn init(cx: &mut App) {
 70    TitleBarSettings::register(cx);
 71    SystemWindowTabs::init(cx);
 72
 73    cx.observe_new(|workspace: &mut Workspace, window, cx| {
 74        let Some(window) = window else {
 75            return;
 76        };
 77        let item = cx.new(|cx| TitleBar::new("title-bar", workspace, window, cx));
 78        workspace.set_titlebar_item(item.into(), window, cx);
 79
 80        #[cfg(not(target_os = "macos"))]
 81        workspace.register_action(|workspace, action: &OpenApplicationMenu, window, cx| {
 82            if let Some(titlebar) = workspace
 83                .titlebar_item()
 84                .and_then(|item| item.downcast::<TitleBar>().ok())
 85            {
 86                titlebar.update(cx, |titlebar, cx| {
 87                    if let Some(ref menu) = titlebar.application_menu {
 88                        menu.update(cx, |menu, cx| menu.open_menu(action, window, cx));
 89                    }
 90                });
 91            }
 92        });
 93
 94        #[cfg(not(target_os = "macos"))]
 95        workspace.register_action(|workspace, _: &ActivateMenuRight, window, cx| {
 96            if let Some(titlebar) = workspace
 97                .titlebar_item()
 98                .and_then(|item| item.downcast::<TitleBar>().ok())
 99            {
100                titlebar.update(cx, |titlebar, cx| {
101                    if let Some(ref menu) = titlebar.application_menu {
102                        menu.update(cx, |menu, cx| {
103                            menu.navigate_menus_in_direction(ActivateDirection::Right, window, cx)
104                        });
105                    }
106                });
107            }
108        });
109
110        #[cfg(not(target_os = "macos"))]
111        workspace.register_action(|workspace, _: &ActivateMenuLeft, window, cx| {
112            if let Some(titlebar) = workspace
113                .titlebar_item()
114                .and_then(|item| item.downcast::<TitleBar>().ok())
115            {
116                titlebar.update(cx, |titlebar, cx| {
117                    if let Some(ref menu) = titlebar.application_menu {
118                        menu.update(cx, |menu, cx| {
119                            menu.navigate_menus_in_direction(ActivateDirection::Left, window, cx)
120                        });
121                    }
122                });
123            }
124        });
125    })
126    .detach();
127}
128
129pub struct TitleBar {
130    platform_titlebar: Entity<PlatformTitleBar>,
131    project: Entity<Project>,
132    user_store: Entity<UserStore>,
133    client: Arc<Client>,
134    workspace: WeakEntity<Workspace>,
135    application_menu: Option<Entity<ApplicationMenu>>,
136    _subscriptions: Vec<Subscription>,
137    banner: Entity<OnboardingBanner>,
138    screen_share_popover_handle: PopoverMenuHandle<ContextMenu>,
139}
140
141impl Render for TitleBar {
142    fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
143        let title_bar_settings = *TitleBarSettings::get_global(cx);
144
145        let show_menus = show_menus(cx);
146
147        let mut children = Vec::new();
148
149        children.push(
150            h_flex()
151                .gap_1()
152                .map(|title_bar| {
153                    let mut render_project_items = title_bar_settings.show_branch_name
154                        || title_bar_settings.show_project_items;
155                    title_bar
156                        .when_some(
157                            self.application_menu.clone().filter(|_| !show_menus),
158                            |title_bar, menu| {
159                                render_project_items &=
160                                    !menu.update(cx, |menu, cx| menu.all_menus_shown(cx));
161                                title_bar.child(menu)
162                            },
163                        )
164                        .when(render_project_items, |title_bar| {
165                            title_bar
166                                .when(title_bar_settings.show_project_items, |title_bar| {
167                                    title_bar
168                                        .children(self.render_project_host(cx))
169                                        .child(self.render_project_name(cx))
170                                })
171                                .when(title_bar_settings.show_branch_name, |title_bar| {
172                                    title_bar.children(self.render_project_branch(cx))
173                                })
174                        })
175                })
176                .on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
177                .into_any_element(),
178        );
179
180        children.push(self.render_collaborator_list(window, cx).into_any_element());
181
182        if title_bar_settings.show_onboarding_banner {
183            children.push(self.banner.clone().into_any_element())
184        }
185
186        let status = self.client.status();
187        let status = &*status.borrow();
188        let user = self.user_store.read(cx).current_user();
189
190        children.push(
191            h_flex()
192                .gap_1()
193                .pr_1()
194                .on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
195                .children(self.render_call_controls(window, cx))
196                .children(self.render_connection_status(status, cx))
197                .when(
198                    user.is_none() && TitleBarSettings::get_global(cx).show_sign_in,
199                    |el| el.child(self.render_sign_in_button(cx)),
200                )
201                .when(user.is_some(), |parent| {
202                    parent.child(self.render_user_menu_button(cx))
203                })
204                .into_any_element(),
205        );
206
207        if show_menus {
208            self.platform_titlebar.update(cx, |this, _| {
209                this.set_children(
210                    self.application_menu
211                        .clone()
212                        .map(|menu| menu.into_any_element()),
213                );
214            });
215
216            let height = PlatformTitleBar::height(window);
217            let title_bar_color = self.platform_titlebar.update(cx, |platform_titlebar, cx| {
218                platform_titlebar.title_bar_color(window, cx)
219            });
220
221            v_flex()
222                .w_full()
223                .child(self.platform_titlebar.clone().into_any_element())
224                .child(
225                    h_flex()
226                        .bg(title_bar_color)
227                        .h(height)
228                        .pl_2()
229                        .justify_between()
230                        .w_full()
231                        .children(children),
232                )
233                .into_any_element()
234        } else {
235            self.platform_titlebar.update(cx, |this, _| {
236                this.set_children(children);
237            });
238            self.platform_titlebar.clone().into_any_element()
239        }
240    }
241}
242
243impl TitleBar {
244    pub fn new(
245        id: impl Into<ElementId>,
246        workspace: &Workspace,
247        window: &mut Window,
248        cx: &mut Context<Self>,
249    ) -> Self {
250        let project = workspace.project().clone();
251        let user_store = workspace.app_state().user_store.clone();
252        let client = workspace.app_state().client.clone();
253        let active_call = ActiveCall::global(cx);
254
255        let platform_style = PlatformStyle::platform();
256        let application_menu = match platform_style {
257            PlatformStyle::Mac => {
258                if option_env!("ZED_USE_CROSS_PLATFORM_MENU").is_some() {
259                    Some(cx.new(|cx| ApplicationMenu::new(window, cx)))
260                } else {
261                    None
262                }
263            }
264            PlatformStyle::Linux | PlatformStyle::Windows => {
265                Some(cx.new(|cx| ApplicationMenu::new(window, cx)))
266            }
267        };
268
269        let mut subscriptions = Vec::new();
270        subscriptions.push(
271            cx.observe(&workspace.weak_handle().upgrade().unwrap(), |_, _, cx| {
272                cx.notify()
273            }),
274        );
275        subscriptions.push(cx.subscribe(&project, |_, _, _: &project::Event, cx| cx.notify()));
276        subscriptions.push(cx.observe(&active_call, |this, _, cx| this.active_call_changed(cx)));
277        subscriptions.push(cx.observe_window_activation(window, Self::window_activation_changed));
278        subscriptions.push(cx.observe(&user_store, |_, _, cx| cx.notify()));
279
280        let banner = cx.new(|cx| {
281            OnboardingBanner::new(
282                "ACP Onboarding",
283                IconName::Sparkle,
284                "Bring Your Own Agent",
285                Some("Introducing:".into()),
286                zed_actions::agent::OpenAcpOnboardingModal.boxed_clone(),
287                cx,
288            )
289        });
290
291        let platform_titlebar = cx.new(|cx| PlatformTitleBar::new(id, cx));
292
293        Self {
294            platform_titlebar,
295            application_menu,
296            workspace: workspace.weak_handle(),
297            project,
298            user_store,
299            client,
300            _subscriptions: subscriptions,
301            banner,
302            screen_share_popover_handle: Default::default(),
303        }
304    }
305
306    fn render_remote_project_connection(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
307        let options = self.project.read(cx).remote_connection_options(cx)?;
308        let host: SharedString = options.display_name().into();
309
310        let nickname = if let RemoteConnectionOptions::Ssh(options) = options {
311            options.nickname.map(|nick| nick.into())
312        } else {
313            None
314        };
315        let nickname = nickname.unwrap_or_else(|| host.clone());
316
317        let (indicator_color, meta) = match self.project.read(cx).remote_connection_state(cx)? {
318            remote::ConnectionState::Connecting => (Color::Info, format!("Connecting to: {host}")),
319            remote::ConnectionState::Connected => (Color::Success, format!("Connected to: {host}")),
320            remote::ConnectionState::HeartbeatMissed => (
321                Color::Warning,
322                format!("Connection attempt to {host} missed. Retrying..."),
323            ),
324            remote::ConnectionState::Reconnecting => (
325                Color::Warning,
326                format!("Lost connection to {host}. Reconnecting..."),
327            ),
328            remote::ConnectionState::Disconnected => {
329                (Color::Error, format!("Disconnected from {host}"))
330            }
331        };
332
333        let icon_color = match self.project.read(cx).remote_connection_state(cx)? {
334            remote::ConnectionState::Connecting => Color::Info,
335            remote::ConnectionState::Connected => Color::Default,
336            remote::ConnectionState::HeartbeatMissed => Color::Warning,
337            remote::ConnectionState::Reconnecting => Color::Warning,
338            remote::ConnectionState::Disconnected => Color::Error,
339        };
340
341        let meta = SharedString::from(meta);
342
343        Some(
344            ButtonLike::new("ssh-server-icon")
345                .child(
346                    h_flex()
347                        .gap_2()
348                        .max_w_32()
349                        .child(
350                            IconWithIndicator::new(
351                                Icon::new(IconName::Server)
352                                    .size(IconSize::Small)
353                                    .color(icon_color),
354                                Some(Indicator::dot().color(indicator_color)),
355                            )
356                            .indicator_border_color(Some(cx.theme().colors().title_bar_background))
357                            .into_any_element(),
358                        )
359                        .child(Label::new(nickname).size(LabelSize::Small).truncate()),
360                )
361                .tooltip(move |window, cx| {
362                    Tooltip::with_meta(
363                        "Remote Project",
364                        Some(&OpenRemote {
365                            from_existing_connection: false,
366                            create_new_window: false,
367                        }),
368                        meta.clone(),
369                        window,
370                        cx,
371                    )
372                })
373                .on_click(|_, window, cx| {
374                    window.dispatch_action(
375                        OpenRemote {
376                            from_existing_connection: false,
377                            create_new_window: false,
378                        }
379                        .boxed_clone(),
380                        cx,
381                    );
382                })
383                .into_any_element(),
384        )
385    }
386
387    pub fn render_project_host(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
388        if self.project.read(cx).is_via_remote_server() {
389            return self.render_remote_project_connection(cx);
390        }
391
392        if self.project.read(cx).is_disconnected(cx) {
393            return Some(
394                Button::new("disconnected", "Disconnected")
395                    .disabled(true)
396                    .color(Color::Disabled)
397                    .style(ButtonStyle::Subtle)
398                    .label_size(LabelSize::Small)
399                    .into_any_element(),
400            );
401        }
402
403        let host = self.project.read(cx).host()?;
404        let host_user = self.user_store.read(cx).get_cached_user(host.user_id)?;
405        let participant_index = self
406            .user_store
407            .read(cx)
408            .participant_indices()
409            .get(&host_user.id)?;
410        Some(
411            Button::new("project_owner_trigger", host_user.github_login.clone())
412                .color(Color::Player(participant_index.0))
413                .style(ButtonStyle::Subtle)
414                .label_size(LabelSize::Small)
415                .tooltip(Tooltip::text(format!(
416                    "{} is sharing this project. Click to follow.",
417                    host_user.github_login
418                )))
419                .on_click({
420                    let host_peer_id = host.peer_id;
421                    cx.listener(move |this, _, window, cx| {
422                        this.workspace
423                            .update(cx, |workspace, cx| {
424                                workspace.follow(host_peer_id, window, cx);
425                            })
426                            .log_err();
427                    })
428                })
429                .into_any_element(),
430        )
431    }
432
433    pub fn render_project_name(&self, cx: &mut Context<Self>) -> impl IntoElement {
434        let name = {
435            let mut names = self.project.read(cx).visible_worktrees(cx).map(|worktree| {
436                let worktree = worktree.read(cx);
437                worktree.root_name()
438            });
439
440            names.next()
441        };
442        let is_project_selected = name.is_some();
443        let name = if let Some(name) = name {
444            util::truncate_and_trailoff(name, MAX_PROJECT_NAME_LENGTH)
445        } else {
446            "Open recent project".to_string()
447        };
448
449        Button::new("project_name_trigger", name)
450            .when(!is_project_selected, |b| b.color(Color::Muted))
451            .style(ButtonStyle::Subtle)
452            .label_size(LabelSize::Small)
453            .tooltip(move |window, cx| {
454                Tooltip::for_action(
455                    "Recent Projects",
456                    &zed_actions::OpenRecent {
457                        create_new_window: false,
458                    },
459                    window,
460                    cx,
461                )
462            })
463            .on_click(cx.listener(move |_, _, window, cx| {
464                window.dispatch_action(
465                    OpenRecent {
466                        create_new_window: false,
467                    }
468                    .boxed_clone(),
469                    cx,
470                );
471            }))
472    }
473
474    pub fn render_project_branch(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> {
475        let repository = self.project.read(cx).active_repository(cx)?;
476        let workspace = self.workspace.upgrade()?;
477        let branch_name = {
478            let repo = repository.read(cx);
479            repo.branch
480                .as_ref()
481                .map(|branch| branch.name())
482                .map(|name| util::truncate_and_trailoff(name, MAX_BRANCH_NAME_LENGTH))
483                .or_else(|| {
484                    repo.head_commit.as_ref().map(|commit| {
485                        commit
486                            .sha
487                            .chars()
488                            .take(MAX_SHORT_SHA_LENGTH)
489                            .collect::<String>()
490                    })
491                })
492        }?;
493
494        Some(
495            Button::new("project_branch_trigger", branch_name)
496                .color(Color::Muted)
497                .style(ButtonStyle::Subtle)
498                .label_size(LabelSize::Small)
499                .tooltip(move |window, cx| {
500                    Tooltip::with_meta(
501                        "Recent Branches",
502                        Some(&zed_actions::git::Branch),
503                        "Local branches only",
504                        window,
505                        cx,
506                    )
507                })
508                .on_click(move |_, window, cx| {
509                    let _ = workspace.update(cx, |this, cx| {
510                        window.focus(&this.active_pane().focus_handle(cx));
511                        window.dispatch_action(zed_actions::git::Branch.boxed_clone(), cx);
512                    });
513                })
514                .when(
515                    TitleBarSettings::get_global(cx).show_branch_icon,
516                    |branch_button| {
517                        branch_button
518                            .icon(IconName::GitBranch)
519                            .icon_position(IconPosition::Start)
520                            .icon_color(Color::Muted)
521                            .icon_size(IconSize::Indicator)
522                    },
523                ),
524        )
525    }
526
527    fn window_activation_changed(&mut self, window: &mut Window, cx: &mut Context<Self>) {
528        if window.is_window_active() {
529            ActiveCall::global(cx)
530                .update(cx, |call, cx| call.set_location(Some(&self.project), cx))
531                .detach_and_log_err(cx);
532        } else if cx.active_window().is_none() {
533            ActiveCall::global(cx)
534                .update(cx, |call, cx| call.set_location(None, cx))
535                .detach_and_log_err(cx);
536        }
537        self.workspace
538            .update(cx, |workspace, cx| {
539                workspace.update_active_view_for_followers(window, cx);
540            })
541            .ok();
542    }
543
544    fn active_call_changed(&mut self, cx: &mut Context<Self>) {
545        cx.notify();
546    }
547
548    fn share_project(&mut self, cx: &mut Context<Self>) {
549        let active_call = ActiveCall::global(cx);
550        let project = self.project.clone();
551        active_call
552            .update(cx, |call, cx| call.share_project(project, cx))
553            .detach_and_log_err(cx);
554    }
555
556    fn unshare_project(&mut self, _: &mut Window, cx: &mut Context<Self>) {
557        let active_call = ActiveCall::global(cx);
558        let project = self.project.clone();
559        active_call
560            .update(cx, |call, cx| call.unshare_project(project, cx))
561            .log_err();
562    }
563
564    fn render_connection_status(
565        &self,
566        status: &client::Status,
567        cx: &mut Context<Self>,
568    ) -> Option<AnyElement> {
569        match status {
570            client::Status::ConnectionError
571            | client::Status::ConnectionLost
572            | client::Status::Reauthenticating
573            | client::Status::Reconnecting
574            | client::Status::ReconnectionError { .. } => Some(
575                div()
576                    .id("disconnected")
577                    .child(Icon::new(IconName::Disconnected).size(IconSize::Small))
578                    .tooltip(Tooltip::text("Disconnected"))
579                    .into_any_element(),
580            ),
581            client::Status::UpgradeRequired => {
582                let auto_updater = auto_update::AutoUpdater::get(cx);
583                let label = match auto_updater.map(|auto_update| auto_update.read(cx).status()) {
584                    Some(AutoUpdateStatus::Updated { .. }) => "Please restart Zed to Collaborate",
585                    Some(AutoUpdateStatus::Installing { .. })
586                    | Some(AutoUpdateStatus::Downloading { .. })
587                    | Some(AutoUpdateStatus::Checking) => "Updating...",
588                    Some(AutoUpdateStatus::Idle) | Some(AutoUpdateStatus::Errored) | None => {
589                        "Please update Zed to Collaborate"
590                    }
591                };
592
593                Some(
594                    Button::new("connection-status", label)
595                        .label_size(LabelSize::Small)
596                        .on_click(|_, window, cx| {
597                            if let Some(auto_updater) = auto_update::AutoUpdater::get(cx)
598                                && auto_updater.read(cx).status().is_updated()
599                            {
600                                workspace::reload(cx);
601                                return;
602                            }
603                            auto_update::check(&Default::default(), window, cx);
604                        })
605                        .into_any_element(),
606                )
607            }
608            _ => None,
609        }
610    }
611
612    pub fn render_sign_in_button(&mut self, _: &mut Context<Self>) -> Button {
613        let client = self.client.clone();
614        Button::new("sign_in", "Sign in")
615            .label_size(LabelSize::Small)
616            .on_click(move |_, window, cx| {
617                let client = client.clone();
618                window
619                    .spawn(cx, async move |cx| {
620                        client
621                            .sign_in_with_optional_connect(true, cx)
622                            .await
623                            .notify_async_err(cx);
624                    })
625                    .detach();
626            })
627    }
628
629    pub fn render_user_menu_button(&mut self, cx: &mut Context<Self>) -> impl Element {
630        let user_store = self.user_store.read(cx);
631        if let Some(user) = user_store.current_user() {
632            let has_subscription_period = user_store.subscription_period().is_some();
633            let plan = user_store.plan().filter(|_| {
634                // Since the user might be on the legacy free plan we filter based on whether we have a subscription period.
635                has_subscription_period
636            });
637
638            let user_avatar = user.avatar_uri.clone();
639            let free_chip_bg = cx
640                .theme()
641                .colors()
642                .editor_background
643                .opacity(0.5)
644                .blend(cx.theme().colors().text_accent.opacity(0.05));
645
646            let pro_chip_bg = cx
647                .theme()
648                .colors()
649                .editor_background
650                .opacity(0.5)
651                .blend(cx.theme().colors().text_accent.opacity(0.2));
652
653            PopoverMenu::new("user-menu")
654                .anchor(Corner::TopRight)
655                .menu(move |window, cx| {
656                    ContextMenu::build(window, cx, |menu, _, _cx| {
657                        let user_login = user.github_login.clone();
658
659                        let (plan_name, label_color, bg_color) = match plan {
660                            None | Some(Plan::ZedFree) => ("Free", Color::Default, free_chip_bg),
661                            Some(Plan::ZedProTrial) => ("Pro Trial", Color::Accent, pro_chip_bg),
662                            Some(Plan::ZedPro) => ("Pro", Color::Accent, pro_chip_bg),
663                        };
664
665                        menu.custom_entry(
666                            move |_window, _cx| {
667                                let user_login = user_login.clone();
668
669                                h_flex()
670                                    .w_full()
671                                    .justify_between()
672                                    .child(Label::new(user_login))
673                                    .child(
674                                        Chip::new(plan_name.to_string())
675                                            .bg_color(bg_color)
676                                            .label_color(label_color),
677                                    )
678                                    .into_any_element()
679                            },
680                            move |_, cx| {
681                                cx.open_url(&zed_urls::account_url(cx));
682                            },
683                        )
684                        .separator()
685                        .action("Settings", zed_actions::OpenSettings.boxed_clone())
686                        .action(
687                            "Settings Profiles",
688                            zed_actions::settings_profile_selector::Toggle.boxed_clone(),
689                        )
690                        .action("Key Bindings", Box::new(keymap_editor::OpenKeymapEditor))
691                        .action(
692                            "Themes…",
693                            zed_actions::theme_selector::Toggle::default().boxed_clone(),
694                        )
695                        .action(
696                            "Icon Themes…",
697                            zed_actions::icon_theme_selector::Toggle::default().boxed_clone(),
698                        )
699                        .action(
700                            "Extensions",
701                            zed_actions::Extensions::default().boxed_clone(),
702                        )
703                        .separator()
704                        .action("Sign Out", client::SignOut.boxed_clone())
705                    })
706                    .into()
707                })
708                .trigger_with_tooltip(
709                    ButtonLike::new("user-menu")
710                        .child(
711                            h_flex()
712                                .gap_0p5()
713                                .children(
714                                    TitleBarSettings::get_global(cx)
715                                        .show_user_picture
716                                        .then(|| Avatar::new(user_avatar)),
717                                )
718                                .child(
719                                    Icon::new(IconName::ChevronDown)
720                                        .size(IconSize::Small)
721                                        .color(Color::Muted),
722                                ),
723                        )
724                        .style(ButtonStyle::Subtle),
725                    Tooltip::text("Toggle User Menu"),
726                )
727                .anchor(gpui::Corner::TopRight)
728        } else {
729            PopoverMenu::new("user-menu")
730                .anchor(Corner::TopRight)
731                .menu(|window, cx| {
732                    ContextMenu::build(window, cx, |menu, _, _| {
733                        menu.action("Settings", zed_actions::OpenSettings.boxed_clone())
734                            .action(
735                                "Settings Profiles",
736                                zed_actions::settings_profile_selector::Toggle.boxed_clone(),
737                            )
738                            .action("Key Bindings", Box::new(keymap_editor::OpenKeymapEditor))
739                            .action(
740                                "Themes…",
741                                zed_actions::theme_selector::Toggle::default().boxed_clone(),
742                            )
743                            .action(
744                                "Icon Themes…",
745                                zed_actions::icon_theme_selector::Toggle::default().boxed_clone(),
746                            )
747                            .action(
748                                "Extensions",
749                                zed_actions::Extensions::default().boxed_clone(),
750                            )
751                    })
752                    .into()
753                })
754                .trigger_with_tooltip(
755                    IconButton::new("user-menu", IconName::ChevronDown).icon_size(IconSize::Small),
756                    Tooltip::text("Toggle User Menu"),
757                )
758        }
759    }
760}