title_bar.rs

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