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, WorktreeSettings};
 35use remote::RemoteConnectionOptions;
 36use settings::{Settings, SettingsLocation};
 37use std::{path::Path, 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 = self
437            .project
438            .read(cx)
439            .visible_worktrees(cx)
440            .map(|worktree| {
441                let worktree = worktree.read(cx);
442                let settings_location = SettingsLocation {
443                    worktree_id: worktree.id(),
444                    path: Path::new(""),
445                };
446
447                let settings = WorktreeSettings::get(Some(settings_location), cx);
448                match &settings.project_name {
449                    Some(name) => name.as_str(),
450                    None => worktree.root_name(),
451                }
452            })
453            .next();
454        let is_project_selected = name.is_some();
455        let name = if let Some(name) = name {
456            util::truncate_and_trailoff(name, MAX_PROJECT_NAME_LENGTH)
457        } else {
458            "Open recent project".to_string()
459        };
460
461        Button::new("project_name_trigger", name)
462            .when(!is_project_selected, |b| b.color(Color::Muted))
463            .style(ButtonStyle::Subtle)
464            .label_size(LabelSize::Small)
465            .tooltip(move |window, cx| {
466                Tooltip::for_action(
467                    "Recent Projects",
468                    &zed_actions::OpenRecent {
469                        create_new_window: false,
470                    },
471                    window,
472                    cx,
473                )
474            })
475            .on_click(cx.listener(move |_, _, window, cx| {
476                window.dispatch_action(
477                    OpenRecent {
478                        create_new_window: false,
479                    }
480                    .boxed_clone(),
481                    cx,
482                );
483            }))
484    }
485
486    pub fn render_project_branch(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> {
487        let repository = self.project.read(cx).active_repository(cx)?;
488        let workspace = self.workspace.upgrade()?;
489        let branch_name = {
490            let repo = repository.read(cx);
491            repo.branch
492                .as_ref()
493                .map(|branch| branch.name())
494                .map(|name| util::truncate_and_trailoff(name, MAX_BRANCH_NAME_LENGTH))
495                .or_else(|| {
496                    repo.head_commit.as_ref().map(|commit| {
497                        commit
498                            .sha
499                            .chars()
500                            .take(MAX_SHORT_SHA_LENGTH)
501                            .collect::<String>()
502                    })
503                })
504        }?;
505
506        Some(
507            Button::new("project_branch_trigger", branch_name)
508                .color(Color::Muted)
509                .style(ButtonStyle::Subtle)
510                .label_size(LabelSize::Small)
511                .tooltip(move |window, cx| {
512                    Tooltip::with_meta(
513                        "Recent Branches",
514                        Some(&zed_actions::git::Branch),
515                        "Local branches only",
516                        window,
517                        cx,
518                    )
519                })
520                .on_click(move |_, window, cx| {
521                    let _ = workspace.update(cx, |this, cx| {
522                        window.focus(&this.active_pane().focus_handle(cx));
523                        window.dispatch_action(zed_actions::git::Branch.boxed_clone(), cx);
524                    });
525                })
526                .when(
527                    TitleBarSettings::get_global(cx).show_branch_icon,
528                    |branch_button| {
529                        branch_button
530                            .icon(IconName::GitBranch)
531                            .icon_position(IconPosition::Start)
532                            .icon_color(Color::Muted)
533                            .icon_size(IconSize::Indicator)
534                    },
535                ),
536        )
537    }
538
539    fn window_activation_changed(&mut self, window: &mut Window, cx: &mut Context<Self>) {
540        if window.is_window_active() {
541            ActiveCall::global(cx)
542                .update(cx, |call, cx| call.set_location(Some(&self.project), cx))
543                .detach_and_log_err(cx);
544        } else if cx.active_window().is_none() {
545            ActiveCall::global(cx)
546                .update(cx, |call, cx| call.set_location(None, cx))
547                .detach_and_log_err(cx);
548        }
549        self.workspace
550            .update(cx, |workspace, cx| {
551                workspace.update_active_view_for_followers(window, cx);
552            })
553            .ok();
554    }
555
556    fn active_call_changed(&mut self, cx: &mut Context<Self>) {
557        cx.notify();
558    }
559
560    fn share_project(&mut self, cx: &mut Context<Self>) {
561        let active_call = ActiveCall::global(cx);
562        let project = self.project.clone();
563        active_call
564            .update(cx, |call, cx| call.share_project(project, cx))
565            .detach_and_log_err(cx);
566    }
567
568    fn unshare_project(&mut self, _: &mut Window, cx: &mut Context<Self>) {
569        let active_call = ActiveCall::global(cx);
570        let project = self.project.clone();
571        active_call
572            .update(cx, |call, cx| call.unshare_project(project, cx))
573            .log_err();
574    }
575
576    fn render_connection_status(
577        &self,
578        status: &client::Status,
579        cx: &mut Context<Self>,
580    ) -> Option<AnyElement> {
581        match status {
582            client::Status::ConnectionError
583            | client::Status::ConnectionLost
584            | client::Status::Reauthenticating
585            | client::Status::Reconnecting
586            | client::Status::ReconnectionError { .. } => Some(
587                div()
588                    .id("disconnected")
589                    .child(Icon::new(IconName::Disconnected).size(IconSize::Small))
590                    .tooltip(Tooltip::text("Disconnected"))
591                    .into_any_element(),
592            ),
593            client::Status::UpgradeRequired => {
594                let auto_updater = auto_update::AutoUpdater::get(cx);
595                let label = match auto_updater.map(|auto_update| auto_update.read(cx).status()) {
596                    Some(AutoUpdateStatus::Updated { .. }) => "Please restart Zed to Collaborate",
597                    Some(AutoUpdateStatus::Installing { .. })
598                    | Some(AutoUpdateStatus::Downloading { .. })
599                    | Some(AutoUpdateStatus::Checking) => "Updating...",
600                    Some(AutoUpdateStatus::Idle) | Some(AutoUpdateStatus::Errored) | None => {
601                        "Please update Zed to Collaborate"
602                    }
603                };
604
605                Some(
606                    Button::new("connection-status", label)
607                        .label_size(LabelSize::Small)
608                        .on_click(|_, window, cx| {
609                            if let Some(auto_updater) = auto_update::AutoUpdater::get(cx)
610                                && auto_updater.read(cx).status().is_updated()
611                            {
612                                workspace::reload(cx);
613                                return;
614                            }
615                            auto_update::check(&Default::default(), window, cx);
616                        })
617                        .into_any_element(),
618                )
619            }
620            _ => None,
621        }
622    }
623
624    pub fn render_sign_in_button(&mut self, _: &mut Context<Self>) -> Button {
625        let client = self.client.clone();
626        Button::new("sign_in", "Sign in")
627            .label_size(LabelSize::Small)
628            .on_click(move |_, window, cx| {
629                let client = client.clone();
630                window
631                    .spawn(cx, async move |cx| {
632                        client
633                            .sign_in_with_optional_connect(true, cx)
634                            .await
635                            .notify_async_err(cx);
636                    })
637                    .detach();
638            })
639    }
640
641    pub fn render_user_menu_button(&mut self, cx: &mut Context<Self>) -> impl Element {
642        let user_store = self.user_store.read(cx);
643        if let Some(user) = user_store.current_user() {
644            let has_subscription_period = user_store.subscription_period().is_some();
645            let plan = user_store.plan().filter(|_| {
646                // Since the user might be on the legacy free plan we filter based on whether we have a subscription period.
647                has_subscription_period
648            });
649
650            let user_avatar = user.avatar_uri.clone();
651            let free_chip_bg = cx
652                .theme()
653                .colors()
654                .editor_background
655                .opacity(0.5)
656                .blend(cx.theme().colors().text_accent.opacity(0.05));
657
658            let pro_chip_bg = cx
659                .theme()
660                .colors()
661                .editor_background
662                .opacity(0.5)
663                .blend(cx.theme().colors().text_accent.opacity(0.2));
664
665            PopoverMenu::new("user-menu")
666                .anchor(Corner::TopRight)
667                .menu(move |window, cx| {
668                    ContextMenu::build(window, cx, |menu, _, _cx| {
669                        let user_login = user.github_login.clone();
670
671                        let (plan_name, label_color, bg_color) = match plan {
672                            None | Some(Plan::ZedFree | Plan::ZedFreeV2) => {
673                                ("Free", Color::Default, free_chip_bg)
674                            }
675                            Some(Plan::ZedProTrial | Plan::ZedProTrialV2) => {
676                                ("Pro Trial", Color::Accent, pro_chip_bg)
677                            }
678                            Some(Plan::ZedPro | Plan::ZedProV2) => {
679                                ("Pro", Color::Accent, pro_chip_bg)
680                            }
681                        };
682
683                        menu.custom_entry(
684                            move |_window, _cx| {
685                                let user_login = user_login.clone();
686
687                                h_flex()
688                                    .w_full()
689                                    .justify_between()
690                                    .child(Label::new(user_login))
691                                    .child(
692                                        Chip::new(plan_name.to_string())
693                                            .bg_color(bg_color)
694                                            .label_color(label_color),
695                                    )
696                                    .into_any_element()
697                            },
698                            move |_, cx| {
699                                cx.open_url(&zed_urls::account_url(cx));
700                            },
701                        )
702                        .separator()
703                        .action("Settings", zed_actions::OpenSettings.boxed_clone())
704                        .action(
705                            "Settings Profiles",
706                            zed_actions::settings_profile_selector::Toggle.boxed_clone(),
707                        )
708                        .action("Keymap Editor", Box::new(keymap_editor::OpenKeymapEditor))
709                        .action(
710                            "Themes…",
711                            zed_actions::theme_selector::Toggle::default().boxed_clone(),
712                        )
713                        .action(
714                            "Icon Themes…",
715                            zed_actions::icon_theme_selector::Toggle::default().boxed_clone(),
716                        )
717                        .action(
718                            "Extensions",
719                            zed_actions::Extensions::default().boxed_clone(),
720                        )
721                        .separator()
722                        .action("Sign Out", client::SignOut.boxed_clone())
723                    })
724                    .into()
725                })
726                .trigger_with_tooltip(
727                    ButtonLike::new("user-menu")
728                        .child(
729                            h_flex()
730                                .gap_0p5()
731                                .children(
732                                    TitleBarSettings::get_global(cx)
733                                        .show_user_picture
734                                        .then(|| Avatar::new(user_avatar)),
735                                )
736                                .child(
737                                    Icon::new(IconName::ChevronDown)
738                                        .size(IconSize::Small)
739                                        .color(Color::Muted),
740                                ),
741                        )
742                        .style(ButtonStyle::Subtle),
743                    Tooltip::text("Toggle User Menu"),
744                )
745                .anchor(gpui::Corner::TopRight)
746        } else {
747            PopoverMenu::new("user-menu")
748                .anchor(Corner::TopRight)
749                .menu(|window, cx| {
750                    ContextMenu::build(window, cx, |menu, _, _| {
751                        menu.action("Settings", zed_actions::OpenSettings.boxed_clone())
752                            .action(
753                                "Settings Profiles",
754                                zed_actions::settings_profile_selector::Toggle.boxed_clone(),
755                            )
756                            .action("Key Bindings", Box::new(keymap_editor::OpenKeymapEditor))
757                            .action(
758                                "Themes…",
759                                zed_actions::theme_selector::Toggle::default().boxed_clone(),
760                            )
761                            .action(
762                                "Icon Themes…",
763                                zed_actions::icon_theme_selector::Toggle::default().boxed_clone(),
764                            )
765                            .action(
766                                "Extensions",
767                                zed_actions::Extensions::default().boxed_clone(),
768                            )
769                    })
770                    .into()
771                })
772                .trigger_with_tooltip(
773                    IconButton::new("user-menu", IconName::ChevronDown).icon_size(IconSize::Small),
774                    Tooltip::text("Toggle User Menu"),
775                )
776        }
777    }
778}