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::{
 34    Project, WorktreeSettings,
 35    git_store::{GitStoreEvent, RepositoryEvent},
 36};
 37use remote::RemoteConnectionOptions;
 38use settings::{Settings, SettingsLocation};
 39use std::sync::Arc;
 40use theme::ActiveTheme;
 41use title_bar_settings::TitleBarSettings;
 42use ui::{
 43    Avatar, Button, ButtonLike, ButtonStyle, Chip, ContextMenu, Icon, IconName, IconSize,
 44    IconWithIndicator, Indicator, PopoverMenu, PopoverMenuHandle, Tooltip, h_flex, prelude::*,
 45};
 46use util::{ResultExt, rel_path::RelPath};
 47use workspace::{Workspace, notifications::NotifyResultExt};
 48use zed_actions::{OpenRecent, OpenRemote};
 49
 50pub use onboarding_banner::restore_banner;
 51
 52#[cfg(feature = "stories")]
 53pub use stories::*;
 54
 55const MAX_PROJECT_NAME_LENGTH: usize = 40;
 56const MAX_BRANCH_NAME_LENGTH: usize = 40;
 57const MAX_SHORT_SHA_LENGTH: usize = 8;
 58
 59actions!(
 60    collab,
 61    [
 62        /// Toggles the user menu dropdown.
 63        ToggleUserMenu,
 64        /// Toggles the project menu dropdown.
 65        ToggleProjectMenu,
 66        /// Switches to a different git branch.
 67        SwitchBranch
 68    ]
 69);
 70
 71pub fn init(cx: &mut App) {
 72    TitleBarSettings::register(cx);
 73    SystemWindowTabs::init(cx);
 74
 75    cx.observe_new(|workspace: &mut Workspace, window, cx| {
 76        let Some(window) = window else {
 77            return;
 78        };
 79        let item = cx.new(|cx| TitleBar::new("title-bar", workspace, window, cx));
 80        workspace.set_titlebar_item(item.into(), window, cx);
 81
 82        #[cfg(not(target_os = "macos"))]
 83        workspace.register_action(|workspace, action: &OpenApplicationMenu, window, cx| {
 84            if let Some(titlebar) = workspace
 85                .titlebar_item()
 86                .and_then(|item| item.downcast::<TitleBar>().ok())
 87            {
 88                titlebar.update(cx, |titlebar, cx| {
 89                    if let Some(ref menu) = titlebar.application_menu {
 90                        menu.update(cx, |menu, cx| menu.open_menu(action, window, cx));
 91                    }
 92                });
 93            }
 94        });
 95
 96        #[cfg(not(target_os = "macos"))]
 97        workspace.register_action(|workspace, _: &ActivateMenuRight, window, cx| {
 98            if let Some(titlebar) = workspace
 99                .titlebar_item()
100                .and_then(|item| item.downcast::<TitleBar>().ok())
101            {
102                titlebar.update(cx, |titlebar, cx| {
103                    if let Some(ref menu) = titlebar.application_menu {
104                        menu.update(cx, |menu, cx| {
105                            menu.navigate_menus_in_direction(ActivateDirection::Right, window, cx)
106                        });
107                    }
108                });
109            }
110        });
111
112        #[cfg(not(target_os = "macos"))]
113        workspace.register_action(|workspace, _: &ActivateMenuLeft, window, cx| {
114            if let Some(titlebar) = workspace
115                .titlebar_item()
116                .and_then(|item| item.downcast::<TitleBar>().ok())
117            {
118                titlebar.update(cx, |titlebar, cx| {
119                    if let Some(ref menu) = titlebar.application_menu {
120                        menu.update(cx, |menu, cx| {
121                            menu.navigate_menus_in_direction(ActivateDirection::Left, window, cx)
122                        });
123                    }
124                });
125            }
126        });
127    })
128    .detach();
129}
130
131pub struct TitleBar {
132    platform_titlebar: Entity<PlatformTitleBar>,
133    project: Entity<Project>,
134    user_store: Entity<UserStore>,
135    client: Arc<Client>,
136    workspace: WeakEntity<Workspace>,
137    application_menu: Option<Entity<ApplicationMenu>>,
138    _subscriptions: Vec<Subscription>,
139    banner: Entity<OnboardingBanner>,
140    screen_share_popover_handle: PopoverMenuHandle<ContextMenu>,
141}
142
143impl Render for TitleBar {
144    fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
145        let title_bar_settings = *TitleBarSettings::get_global(cx);
146
147        let show_menus = show_menus(cx);
148
149        let mut children = Vec::new();
150
151        children.push(
152            h_flex()
153                .gap_1()
154                .map(|title_bar| {
155                    let mut render_project_items = title_bar_settings.show_branch_name
156                        || title_bar_settings.show_project_items;
157                    title_bar
158                        .when_some(
159                            self.application_menu.clone().filter(|_| !show_menus),
160                            |title_bar, menu| {
161                                render_project_items &=
162                                    !menu.update(cx, |menu, cx| menu.all_menus_shown(cx));
163                                title_bar.child(menu)
164                            },
165                        )
166                        .when(render_project_items, |title_bar| {
167                            title_bar
168                                .when(title_bar_settings.show_project_items, |title_bar| {
169                                    title_bar
170                                        .children(self.render_project_host(cx))
171                                        .child(self.render_project_name(cx))
172                                })
173                                .when(title_bar_settings.show_branch_name, |title_bar| {
174                                    title_bar.children(self.render_project_branch(cx))
175                                })
176                        })
177                })
178                .on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
179                .into_any_element(),
180        );
181
182        children.push(self.render_collaborator_list(window, cx).into_any_element());
183
184        if title_bar_settings.show_onboarding_banner {
185            children.push(self.banner.clone().into_any_element())
186        }
187
188        let status = self.client.status();
189        let status = &*status.borrow();
190        let user = self.user_store.read(cx).current_user();
191
192        children.push(
193            h_flex()
194                .gap_1()
195                .pr_1()
196                .on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
197                .children(self.render_call_controls(window, cx))
198                .children(self.render_connection_status(status, cx))
199                .when(
200                    user.is_none() && TitleBarSettings::get_global(cx).show_sign_in,
201                    |el| el.child(self.render_sign_in_button(cx)),
202                )
203                .child(self.render_app_menu_button(cx))
204                .into_any_element(),
205        );
206
207        if show_menus {
208            self.platform_titlebar.update(cx, |this, _| {
209                this.set_children(
210                    self.application_menu
211                        .clone()
212                        .map(|menu| menu.into_any_element()),
213                );
214            });
215
216            let height = PlatformTitleBar::height(window);
217            let title_bar_color = self.platform_titlebar.update(cx, |platform_titlebar, cx| {
218                platform_titlebar.title_bar_color(window, cx)
219            });
220
221            v_flex()
222                .w_full()
223                .child(self.platform_titlebar.clone().into_any_element())
224                .child(
225                    h_flex()
226                        .bg(title_bar_color)
227                        .h(height)
228                        .pl_2()
229                        .justify_between()
230                        .w_full()
231                        .children(children),
232                )
233                .into_any_element()
234        } else {
235            self.platform_titlebar.update(cx, |this, _| {
236                this.set_children(children);
237            });
238            self.platform_titlebar.clone().into_any_element()
239        }
240    }
241}
242
243impl TitleBar {
244    pub fn new(
245        id: impl Into<ElementId>,
246        workspace: &Workspace,
247        window: &mut Window,
248        cx: &mut Context<Self>,
249    ) -> Self {
250        let project = workspace.project().clone();
251        let git_store = project.read(cx).git_store().clone();
252        let user_store = workspace.app_state().user_store.clone();
253        let client = workspace.app_state().client.clone();
254        let active_call = ActiveCall::global(cx);
255
256        let platform_style = PlatformStyle::platform();
257        let application_menu = match platform_style {
258            PlatformStyle::Mac => {
259                if option_env!("ZED_USE_CROSS_PLATFORM_MENU").is_some() {
260                    Some(cx.new(|cx| ApplicationMenu::new(window, cx)))
261                } else {
262                    None
263                }
264            }
265            PlatformStyle::Linux | PlatformStyle::Windows => {
266                Some(cx.new(|cx| ApplicationMenu::new(window, cx)))
267            }
268        };
269
270        let mut subscriptions = Vec::new();
271        subscriptions.push(
272            cx.observe(&workspace.weak_handle().upgrade().unwrap(), |_, _, cx| {
273                cx.notify()
274            }),
275        );
276        subscriptions.push(cx.subscribe(&project, |_, _, _: &project::Event, cx| cx.notify()));
277        subscriptions.push(cx.observe(&active_call, |this, _, cx| this.active_call_changed(cx)));
278        subscriptions.push(cx.observe_window_activation(window, Self::window_activation_changed));
279        subscriptions.push(
280            cx.subscribe(&git_store, move |_, _, event, cx| match event {
281                GitStoreEvent::ActiveRepositoryChanged(_)
282                | GitStoreEvent::RepositoryUpdated(_, RepositoryEvent::Updated { .. }, _)
283                | GitStoreEvent::RepositoryAdded(_)
284                | GitStoreEvent::RepositoryRemoved(_) => {
285                    cx.notify();
286                }
287                _ => {}
288            }),
289        );
290        subscriptions.push(cx.observe(&user_store, |_, _, cx| cx.notify()));
291
292        let banner = cx.new(|cx| {
293            OnboardingBanner::new(
294                "ACP Claude Code Onboarding",
295                IconName::AiClaude,
296                "Claude Code",
297                Some("Introducing:".into()),
298                zed_actions::agent::OpenClaudeCodeOnboardingModal.boxed_clone(),
299                cx,
300            )
301            // When updating this to a non-AI feature release, remove this line.
302            .visible_when(|cx| !project::DisableAiSettings::get_global(cx).disable_ai)
303        });
304
305        let platform_titlebar = cx.new(|cx| PlatformTitleBar::new(id, cx));
306
307        Self {
308            platform_titlebar,
309            application_menu,
310            workspace: workspace.weak_handle(),
311            project,
312            user_store,
313            client,
314            _subscriptions: subscriptions,
315            banner,
316            screen_share_popover_handle: Default::default(),
317        }
318    }
319
320    fn render_remote_project_connection(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
321        let options = self.project.read(cx).remote_connection_options(cx)?;
322        let host: SharedString = options.display_name().into();
323
324        let (nickname, icon) = match options {
325            RemoteConnectionOptions::Ssh(options) => {
326                (options.nickname.map(|nick| nick.into()), IconName::Server)
327            }
328            RemoteConnectionOptions::Wsl(_) => (None, IconName::Linux),
329        };
330        let nickname = nickname.unwrap_or_else(|| host.clone());
331
332        let (indicator_color, meta) = match self.project.read(cx).remote_connection_state(cx)? {
333            remote::ConnectionState::Connecting => (Color::Info, format!("Connecting to: {host}")),
334            remote::ConnectionState::Connected => (Color::Success, format!("Connected to: {host}")),
335            remote::ConnectionState::HeartbeatMissed => (
336                Color::Warning,
337                format!("Connection attempt to {host} missed. Retrying..."),
338            ),
339            remote::ConnectionState::Reconnecting => (
340                Color::Warning,
341                format!("Lost connection to {host}. Reconnecting..."),
342            ),
343            remote::ConnectionState::Disconnected => {
344                (Color::Error, format!("Disconnected from {host}"))
345            }
346        };
347
348        let icon_color = match self.project.read(cx).remote_connection_state(cx)? {
349            remote::ConnectionState::Connecting => Color::Info,
350            remote::ConnectionState::Connected => Color::Default,
351            remote::ConnectionState::HeartbeatMissed => Color::Warning,
352            remote::ConnectionState::Reconnecting => Color::Warning,
353            remote::ConnectionState::Disconnected => Color::Error,
354        };
355
356        let meta = SharedString::from(meta);
357
358        Some(
359            ButtonLike::new("ssh-server-icon")
360                .child(
361                    h_flex()
362                        .gap_2()
363                        .max_w_32()
364                        .child(
365                            IconWithIndicator::new(
366                                Icon::new(icon).size(IconSize::Small).color(icon_color),
367                                Some(Indicator::dot().color(indicator_color)),
368                            )
369                            .indicator_border_color(Some(cx.theme().colors().title_bar_background))
370                            .into_any_element(),
371                        )
372                        .child(Label::new(nickname).size(LabelSize::Small).truncate()),
373                )
374                .tooltip(move |window, cx| {
375                    Tooltip::with_meta(
376                        "Remote Project",
377                        Some(&OpenRemote {
378                            from_existing_connection: false,
379                            create_new_window: false,
380                        }),
381                        meta.clone(),
382                        window,
383                        cx,
384                    )
385                })
386                .on_click(|_, window, cx| {
387                    window.dispatch_action(
388                        OpenRemote {
389                            from_existing_connection: false,
390                            create_new_window: false,
391                        }
392                        .boxed_clone(),
393                        cx,
394                    );
395                })
396                .into_any_element(),
397        )
398    }
399
400    pub fn render_project_host(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
401        if self.project.read(cx).is_via_remote_server() {
402            return self.render_remote_project_connection(cx);
403        }
404
405        if self.project.read(cx).is_disconnected(cx) {
406            return Some(
407                Button::new("disconnected", "Disconnected")
408                    .disabled(true)
409                    .color(Color::Disabled)
410                    .style(ButtonStyle::Subtle)
411                    .label_size(LabelSize::Small)
412                    .into_any_element(),
413            );
414        }
415
416        let host = self.project.read(cx).host()?;
417        let host_user = self.user_store.read(cx).get_cached_user(host.user_id)?;
418        let participant_index = self
419            .user_store
420            .read(cx)
421            .participant_indices()
422            .get(&host_user.id)?;
423        Some(
424            Button::new("project_owner_trigger", host_user.github_login.clone())
425                .color(Color::Player(participant_index.0))
426                .style(ButtonStyle::Subtle)
427                .label_size(LabelSize::Small)
428                .tooltip(Tooltip::text(format!(
429                    "{} is sharing this project. Click to follow.",
430                    host_user.github_login
431                )))
432                .on_click({
433                    let host_peer_id = host.peer_id;
434                    cx.listener(move |this, _, window, cx| {
435                        this.workspace
436                            .update(cx, |workspace, cx| {
437                                workspace.follow(host_peer_id, window, cx);
438                            })
439                            .log_err();
440                    })
441                })
442                .into_any_element(),
443        )
444    }
445
446    pub fn render_project_name(&self, cx: &mut Context<Self>) -> impl IntoElement {
447        let name = self
448            .project
449            .read(cx)
450            .visible_worktrees(cx)
451            .map(|worktree| {
452                let worktree = worktree.read(cx);
453                let settings_location = SettingsLocation {
454                    worktree_id: worktree.id(),
455                    path: RelPath::empty(),
456                };
457
458                let settings = WorktreeSettings::get(Some(settings_location), cx);
459                match &settings.project_name {
460                    Some(name) => name.as_str(),
461                    None => worktree.root_name_str(),
462                }
463            })
464            .next();
465        let is_project_selected = name.is_some();
466        let name = if let Some(name) = name {
467            util::truncate_and_trailoff(name, MAX_PROJECT_NAME_LENGTH)
468        } else {
469            "Open recent project".to_string()
470        };
471
472        Button::new("project_name_trigger", name)
473            .when(!is_project_selected, |b| b.color(Color::Muted))
474            .style(ButtonStyle::Subtle)
475            .label_size(LabelSize::Small)
476            .tooltip(move |window, cx| {
477                Tooltip::for_action(
478                    "Recent Projects",
479                    &zed_actions::OpenRecent {
480                        create_new_window: false,
481                    },
482                    window,
483                    cx,
484                )
485            })
486            .on_click(cx.listener(move |_, _, window, cx| {
487                window.dispatch_action(
488                    OpenRecent {
489                        create_new_window: false,
490                    }
491                    .boxed_clone(),
492                    cx,
493                );
494            }))
495    }
496
497    pub fn render_project_branch(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> {
498        let settings = TitleBarSettings::get_global(cx);
499        let repository = self.project.read(cx).active_repository(cx)?;
500        let workspace = self.workspace.upgrade()?;
501        let repo = repository.read(cx);
502        let branch_name = repo
503            .branch
504            .as_ref()
505            .map(|branch| branch.name())
506            .map(|name| util::truncate_and_trailoff(name, MAX_BRANCH_NAME_LENGTH))
507            .or_else(|| {
508                repo.head_commit.as_ref().map(|commit| {
509                    commit
510                        .sha
511                        .chars()
512                        .take(MAX_SHORT_SHA_LENGTH)
513                        .collect::<String>()
514                })
515            })?;
516
517        Some(
518            Button::new("project_branch_trigger", branch_name)
519                .color(Color::Muted)
520                .style(ButtonStyle::Subtle)
521                .label_size(LabelSize::Small)
522                .tooltip(move |window, cx| {
523                    Tooltip::with_meta(
524                        "Recent Branches",
525                        Some(&zed_actions::git::Branch),
526                        "Local branches only",
527                        window,
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 {
757                    this.trigger_with_tooltip(
758                        ButtonLike::new("user-menu")
759                            .child(
760                                h_flex()
761                                    .gap_0p5()
762                                    .children(
763                                        TitleBarSettings::get_global(cx)
764                                            .show_user_picture
765                                            .then(|| user_avatar.clone())
766                                            .flatten()
767                                            .map(|avatar| Avatar::new(avatar)),
768                                    )
769                                    .child(
770                                        Icon::new(IconName::ChevronDown)
771                                            .size(IconSize::Small)
772                                            .color(Color::Muted),
773                                    ),
774                            )
775                            .style(ButtonStyle::Subtle),
776                        Tooltip::text("Toggle User Menu"),
777                    )
778                } else {
779                    this.trigger_with_tooltip(
780                        IconButton::new("user-menu", IconName::ChevronDown)
781                            .icon_size(IconSize::Small),
782                        Tooltip::text("Toggle User Menu"),
783                    )
784                }
785            })
786            .anchor(gpui::Corner::TopRight)
787    }
788}