title_bar.rs

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