title_bar.rs

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