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