title_bar.rs

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