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 = if let RemoteConnectionOptions::Ssh(options) = options {
353            options.nickname.map(|nick| nick.into())
354        } else {
355            None
356        };
357        let nickname = nickname.unwrap_or_else(|| host.clone());
358
359        let (indicator_color, meta) = match self.project.read(cx).remote_connection_state(cx)? {
360            remote::ConnectionState::Connecting => (Color::Info, format!("Connecting to: {host}")),
361            remote::ConnectionState::Connected => (Color::Success, format!("Connected to: {host}")),
362            remote::ConnectionState::HeartbeatMissed => (
363                Color::Warning,
364                format!("Connection attempt to {host} missed. Retrying..."),
365            ),
366            remote::ConnectionState::Reconnecting => (
367                Color::Warning,
368                format!("Lost connection to {host}. Reconnecting..."),
369            ),
370            remote::ConnectionState::Disconnected => {
371                (Color::Error, format!("Disconnected from {host}"))
372            }
373        };
374
375        let icon_color = match self.project.read(cx).remote_connection_state(cx)? {
376            remote::ConnectionState::Connecting => Color::Info,
377            remote::ConnectionState::Connected => Color::Default,
378            remote::ConnectionState::HeartbeatMissed => Color::Warning,
379            remote::ConnectionState::Reconnecting => Color::Warning,
380            remote::ConnectionState::Disconnected => Color::Error,
381        };
382
383        let meta = SharedString::from(meta);
384
385        Some(
386            ButtonLike::new("ssh-server-icon")
387                .child(
388                    h_flex()
389                        .gap_2()
390                        .max_w_32()
391                        .child(
392                            IconWithIndicator::new(
393                                Icon::new(IconName::Server)
394                                    .size(IconSize::Small)
395                                    .color(icon_color),
396                                Some(Indicator::dot().color(indicator_color)),
397                            )
398                            .indicator_border_color(Some(cx.theme().colors().title_bar_background))
399                            .into_any_element(),
400                        )
401                        .child(Label::new(nickname).size(LabelSize::Small).truncate()),
402                )
403                .tooltip(move |window, cx| {
404                    Tooltip::with_meta(
405                        "Remote Project",
406                        Some(&OpenRemote {
407                            from_existing_connection: false,
408                            create_new_window: false,
409                        }),
410                        meta.clone(),
411                        window,
412                        cx,
413                    )
414                })
415                .on_click(|_, window, cx| {
416                    window.dispatch_action(
417                        OpenRemote {
418                            from_existing_connection: false,
419                            create_new_window: false,
420                        }
421                        .boxed_clone(),
422                        cx,
423                    );
424                })
425                .into_any_element(),
426        )
427    }
428
429    pub fn render_project_host(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
430        if self.project.read(cx).is_via_remote_server() {
431            return self.render_remote_project_connection(cx);
432        }
433
434        if self.project.read(cx).is_disconnected(cx) {
435            return Some(
436                Button::new("disconnected", "Disconnected")
437                    .disabled(true)
438                    .color(Color::Disabled)
439                    .style(ButtonStyle::Subtle)
440                    .label_size(LabelSize::Small)
441                    .into_any_element(),
442            );
443        }
444
445        let host = self.project.read(cx).host()?;
446        let host_user = self.user_store.read(cx).get_cached_user(host.user_id)?;
447        let participant_index = self
448            .user_store
449            .read(cx)
450            .participant_indices()
451            .get(&host_user.id)?;
452        Some(
453            Button::new("project_owner_trigger", host_user.github_login.clone())
454                .color(Color::Player(participant_index.0))
455                .style(ButtonStyle::Subtle)
456                .label_size(LabelSize::Small)
457                .tooltip(Tooltip::text(format!(
458                    "{} is sharing this project. Click to follow.",
459                    host_user.github_login
460                )))
461                .on_click({
462                    let host_peer_id = host.peer_id;
463                    cx.listener(move |this, _, window, cx| {
464                        this.workspace
465                            .update(cx, |workspace, cx| {
466                                workspace.follow(host_peer_id, window, cx);
467                            })
468                            .log_err();
469                    })
470                })
471                .into_any_element(),
472        )
473    }
474
475    pub fn render_project_name(&self, cx: &mut Context<Self>) -> impl IntoElement {
476        let name = self
477            .project
478            .read(cx)
479            .visible_worktrees(cx)
480            .map(|worktree| {
481                let worktree = worktree.read(cx);
482                let settings_location = SettingsLocation {
483                    worktree_id: worktree.id(),
484                    path: Path::new(""),
485                };
486
487                let settings = WorktreeSettings::get(Some(settings_location), cx);
488                match &settings.project_name {
489                    Some(name) => name.as_str(),
490                    None => worktree.root_name(),
491                }
492            })
493            .next();
494        let is_project_selected = name.is_some();
495        let name = if let Some(name) = name {
496            util::truncate_and_trailoff(name, MAX_PROJECT_NAME_LENGTH)
497        } else {
498            "Open recent project".to_string()
499        };
500
501        Button::new("project_name_trigger", name)
502            .when(!is_project_selected, |b| b.color(Color::Muted))
503            .style(ButtonStyle::Subtle)
504            .label_size(LabelSize::Small)
505            .tooltip(move |window, cx| {
506                Tooltip::for_action(
507                    "Recent Projects",
508                    &zed_actions::OpenRecent {
509                        create_new_window: false,
510                    },
511                    window,
512                    cx,
513                )
514            })
515            .on_click(cx.listener(move |_, _, window, cx| {
516                window.dispatch_action(
517                    OpenRecent {
518                        create_new_window: false,
519                    }
520                    .boxed_clone(),
521                    cx,
522                );
523            }))
524    }
525
526    pub fn render_project_branch(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> {
527        let repository = self.project.read(cx).active_repository(cx)?;
528        let workspace = self.workspace.upgrade()?;
529        let branch_name = {
530            let repo = repository.read(cx);
531            repo.branch
532                .as_ref()
533                .map(|branch| branch.name())
534                .map(|name| util::truncate_and_trailoff(name, MAX_BRANCH_NAME_LENGTH))
535                .or_else(|| {
536                    repo.head_commit.as_ref().map(|commit| {
537                        commit
538                            .sha
539                            .chars()
540                            .take(MAX_SHORT_SHA_LENGTH)
541                            .collect::<String>()
542                    })
543                })
544        }?;
545
546        Some(
547            Button::new("project_branch_trigger", branch_name)
548                .color(Color::Muted)
549                .style(ButtonStyle::Subtle)
550                .label_size(LabelSize::Small)
551                .tooltip(move |window, cx| {
552                    Tooltip::with_meta(
553                        "Recent Branches",
554                        Some(&zed_actions::git::Branch),
555                        "Local branches only",
556                        window,
557                        cx,
558                    )
559                })
560                .on_click(move |_, window, cx| {
561                    let _ = workspace.update(cx, |this, cx| {
562                        window.focus(&this.active_pane().focus_handle(cx));
563                        window.dispatch_action(zed_actions::git::Branch.boxed_clone(), cx);
564                    });
565                })
566                .when(
567                    TitleBarSettings::get_global(cx).show_branch_icon,
568                    |branch_button| {
569                        branch_button
570                            .icon(IconName::GitBranch)
571                            .icon_position(IconPosition::Start)
572                            .icon_color(Color::Muted)
573                            .icon_size(IconSize::Indicator)
574                    },
575                ),
576        )
577    }
578
579    fn window_activation_changed(&mut self, window: &mut Window, cx: &mut Context<Self>) {
580        if window.is_window_active() {
581            ActiveCall::global(cx)
582                .update(cx, |call, cx| call.set_location(Some(&self.project), cx))
583                .detach_and_log_err(cx);
584        } else if cx.active_window().is_none() {
585            ActiveCall::global(cx)
586                .update(cx, |call, cx| call.set_location(None, cx))
587                .detach_and_log_err(cx);
588        }
589        self.workspace
590            .update(cx, |workspace, cx| {
591                workspace.update_active_view_for_followers(window, cx);
592            })
593            .ok();
594    }
595
596    fn active_call_changed(&mut self, cx: &mut Context<Self>) {
597        cx.notify();
598    }
599
600    fn share_project(&mut self, cx: &mut Context<Self>) {
601        let active_call = ActiveCall::global(cx);
602        let project = self.project.clone();
603        active_call
604            .update(cx, |call, cx| call.share_project(project, cx))
605            .detach_and_log_err(cx);
606    }
607
608    fn unshare_project(&mut self, _: &mut Window, cx: &mut Context<Self>) {
609        let active_call = ActiveCall::global(cx);
610        let project = self.project.clone();
611        active_call
612            .update(cx, |call, cx| call.unshare_project(project, cx))
613            .log_err();
614    }
615
616    fn render_connection_status(
617        &self,
618        status: &client::Status,
619        cx: &mut Context<Self>,
620    ) -> Option<AnyElement> {
621        match status {
622            client::Status::ConnectionError
623            | client::Status::ConnectionLost
624            | client::Status::Reauthenticating
625            | client::Status::Reconnecting
626            | client::Status::ReconnectionError { .. } => Some(
627                div()
628                    .id("disconnected")
629                    .child(Icon::new(IconName::Disconnected).size(IconSize::Small))
630                    .tooltip(Tooltip::text("Disconnected"))
631                    .into_any_element(),
632            ),
633            client::Status::UpgradeRequired => {
634                let auto_updater = auto_update::AutoUpdater::get(cx);
635                let label = match auto_updater.map(|auto_update| auto_update.read(cx).status()) {
636                    Some(AutoUpdateStatus::Updated { .. }) => "Please restart Zed to Collaborate",
637                    Some(AutoUpdateStatus::Installing { .. })
638                    | Some(AutoUpdateStatus::Downloading { .. })
639                    | Some(AutoUpdateStatus::Checking) => "Updating...",
640                    Some(AutoUpdateStatus::Idle)
641                    | Some(AutoUpdateStatus::Errored { .. })
642                    | None => "Please update Zed to Collaborate",
643                };
644
645                Some(
646                    Button::new("connection-status", label)
647                        .label_size(LabelSize::Small)
648                        .on_click(|_, window, cx| {
649                            if let Some(auto_updater) = auto_update::AutoUpdater::get(cx)
650                                && auto_updater.read(cx).status().is_updated()
651                            {
652                                workspace::reload(cx);
653                                return;
654                            }
655                            auto_update::check(&Default::default(), window, cx);
656                        })
657                        .into_any_element(),
658                )
659            }
660            _ => None,
661        }
662    }
663
664    pub fn render_sign_in_button(&mut self, _: &mut Context<Self>) -> Button {
665        let client = self.client.clone();
666        Button::new("sign_in", "Sign in")
667            .label_size(LabelSize::Small)
668            .on_click(move |_, window, cx| {
669                let client = client.clone();
670                window
671                    .spawn(cx, async move |cx| {
672                        client
673                            .sign_in_with_optional_connect(true, cx)
674                            .await
675                            .notify_async_err(cx);
676                    })
677                    .detach();
678            })
679    }
680
681    pub fn render_user_menu_button(&mut self, cx: &mut Context<Self>) -> impl Element {
682        let user_store = self.user_store.read(cx);
683        if let Some(user) = user_store.current_user() {
684            let has_subscription_period = user_store.subscription_period().is_some();
685            let plan = user_store.plan().filter(|_| {
686                // Since the user might be on the legacy free plan we filter based on whether we have a subscription period.
687                has_subscription_period
688            });
689
690            let user_avatar = user.avatar_uri.clone();
691            let free_chip_bg = cx
692                .theme()
693                .colors()
694                .editor_background
695                .opacity(0.5)
696                .blend(cx.theme().colors().text_accent.opacity(0.05));
697
698            let pro_chip_bg = cx
699                .theme()
700                .colors()
701                .editor_background
702                .opacity(0.5)
703                .blend(cx.theme().colors().text_accent.opacity(0.2));
704
705            PopoverMenu::new("user-menu")
706                .anchor(Corner::TopRight)
707                .menu(move |window, cx| {
708                    ContextMenu::build(window, cx, |menu, _, _cx| {
709                        let user_login = user.github_login.clone();
710
711                        let (plan_name, label_color, bg_color) = match plan {
712                            None | Some(Plan::V1(PlanV1::ZedFree) | Plan::V2(PlanV2::ZedFree)) => {
713                                ("Free", Color::Default, free_chip_bg)
714                            }
715                            Some(Plan::V1(PlanV1::ZedProTrial) | Plan::V2(PlanV2::ZedProTrial)) => {
716                                ("Pro Trial", Color::Accent, pro_chip_bg)
717                            }
718                            Some(Plan::V1(PlanV1::ZedPro) | Plan::V2(PlanV2::ZedPro)) => {
719                                ("Pro", Color::Accent, pro_chip_bg)
720                            }
721                        };
722
723                        menu.custom_entry(
724                            move |_window, _cx| {
725                                let user_login = user_login.clone();
726
727                                h_flex()
728                                    .w_full()
729                                    .justify_between()
730                                    .child(Label::new(user_login))
731                                    .child(
732                                        Chip::new(plan_name.to_string())
733                                            .bg_color(bg_color)
734                                            .label_color(label_color),
735                                    )
736                                    .into_any_element()
737                            },
738                            move |_, cx| {
739                                cx.open_url(&zed_urls::account_url(cx));
740                            },
741                        )
742                        .separator()
743                        .action("Settings", zed_actions::OpenSettings.boxed_clone())
744                        .action(
745                            "Settings Profiles",
746                            zed_actions::settings_profile_selector::Toggle.boxed_clone(),
747                        )
748                        .action("Keymap Editor", Box::new(zed_actions::OpenKeymapEditor))
749                        .action(
750                            "Themes…",
751                            zed_actions::theme_selector::Toggle::default().boxed_clone(),
752                        )
753                        .action(
754                            "Icon Themes…",
755                            zed_actions::icon_theme_selector::Toggle::default().boxed_clone(),
756                        )
757                        .action(
758                            "Extensions",
759                            zed_actions::Extensions::default().boxed_clone(),
760                        )
761                        .separator()
762                        .action("Sign Out", client::SignOut.boxed_clone())
763                    })
764                    .into()
765                })
766                .trigger_with_tooltip(
767                    ButtonLike::new("user-menu")
768                        .child(
769                            h_flex()
770                                .gap_0p5()
771                                .children(
772                                    TitleBarSettings::get_global(cx)
773                                        .show_user_picture
774                                        .then(|| Avatar::new(user_avatar)),
775                                )
776                                .child(
777                                    Icon::new(IconName::ChevronDown)
778                                        .size(IconSize::Small)
779                                        .color(Color::Muted),
780                                ),
781                        )
782                        .style(ButtonStyle::Subtle),
783                    Tooltip::text("Toggle User Menu"),
784                )
785                .anchor(gpui::Corner::TopRight)
786        } else {
787            PopoverMenu::new("user-menu")
788                .anchor(Corner::TopRight)
789                .menu(|window, cx| {
790                    ContextMenu::build(window, cx, |menu, _, _| {
791                        menu.action("Settings", zed_actions::OpenSettings.boxed_clone())
792                            .action(
793                                "Settings Profiles",
794                                zed_actions::settings_profile_selector::Toggle.boxed_clone(),
795                            )
796                            .action("Key Bindings", Box::new(zed_actions::OpenKeymapEditor))
797                            .action(
798                                "Themes…",
799                                zed_actions::theme_selector::Toggle::default().boxed_clone(),
800                            )
801                            .action(
802                                "Icon Themes…",
803                                zed_actions::icon_theme_selector::Toggle::default().boxed_clone(),
804                            )
805                            .action(
806                                "Extensions",
807                                zed_actions::Extensions::default().boxed_clone(),
808                            )
809                    })
810                    .into()
811                })
812                .trigger_with_tooltip(
813                    IconButton::new("user-menu", IconName::ChevronDown).icon_size(IconSize::Small),
814                    Tooltip::text("Toggle User Menu"),
815                )
816        }
817    }
818}