title_bar.rs

  1mod application_menu;
  2mod collab;
  3mod onboarding_banner;
  4mod platforms;
  5mod title_bar_settings;
  6
  7#[cfg(feature = "stories")]
  8mod stories;
  9
 10use crate::application_menu::ApplicationMenu;
 11
 12#[cfg(not(target_os = "macos"))]
 13use crate::application_menu::{
 14    ActivateDirection, ActivateMenuLeft, ActivateMenuRight, OpenApplicationMenu,
 15};
 16
 17use crate::platforms::{platform_linux, platform_mac, platform_windows};
 18use auto_update::AutoUpdateStatus;
 19use call::ActiveCall;
 20use client::{Client, UserStore};
 21use gpui::{
 22    Action, AnyElement, App, Context, Corner, Decorations, Element, Entity, InteractiveElement,
 23    Interactivity, IntoElement, MouseButton, ParentElement, Render, Stateful,
 24    StatefulInteractiveElement, Styled, Subscription, WeakEntity, Window, WindowControlArea,
 25    actions, div, px,
 26};
 27use onboarding_banner::OnboardingBanner;
 28use project::Project;
 29use rpc::proto;
 30use settings::Settings as _;
 31use smallvec::SmallVec;
 32use std::sync::Arc;
 33use theme::ActiveTheme;
 34use title_bar_settings::TitleBarSettings;
 35use ui::{
 36    Avatar, Button, ButtonLike, ButtonStyle, ContextMenu, Icon, IconName, IconSize,
 37    IconWithIndicator, Indicator, PopoverMenu, Tooltip, h_flex, prelude::*,
 38};
 39use util::ResultExt;
 40use workspace::{Workspace, notifications::NotifyResultExt};
 41use zed_actions::{OpenRecent, OpenRemote};
 42
 43pub use onboarding_banner::restore_banner;
 44
 45#[cfg(feature = "stories")]
 46pub use stories::*;
 47
 48const MAX_PROJECT_NAME_LENGTH: usize = 40;
 49const MAX_BRANCH_NAME_LENGTH: usize = 40;
 50const MAX_SHORT_SHA_LENGTH: usize = 8;
 51
 52actions!(collab, [ToggleUserMenu, ToggleProjectMenu, SwitchBranch]);
 53
 54pub fn init(cx: &mut App) {
 55    TitleBarSettings::register(cx);
 56
 57    cx.observe_new(|workspace: &mut Workspace, window, cx| {
 58        let Some(window) = window else {
 59            return;
 60        };
 61        let item = cx.new(|cx| TitleBar::new("title-bar", workspace, window, cx));
 62        workspace.set_titlebar_item(item.into(), window, cx);
 63
 64        #[cfg(not(target_os = "macos"))]
 65        workspace.register_action(|workspace, action: &OpenApplicationMenu, window, cx| {
 66            if let Some(titlebar) = workspace
 67                .titlebar_item()
 68                .and_then(|item| item.downcast::<TitleBar>().ok())
 69            {
 70                titlebar.update(cx, |titlebar, cx| {
 71                    if let Some(ref menu) = titlebar.application_menu {
 72                        menu.update(cx, |menu, cx| menu.open_menu(action, window, cx));
 73                    }
 74                });
 75            }
 76        });
 77
 78        #[cfg(not(target_os = "macos"))]
 79        workspace.register_action(|workspace, _: &ActivateMenuRight, window, cx| {
 80            if let Some(titlebar) = workspace
 81                .titlebar_item()
 82                .and_then(|item| item.downcast::<TitleBar>().ok())
 83            {
 84                titlebar.update(cx, |titlebar, cx| {
 85                    if let Some(ref menu) = titlebar.application_menu {
 86                        menu.update(cx, |menu, cx| {
 87                            menu.navigate_menus_in_direction(ActivateDirection::Right, window, cx)
 88                        });
 89                    }
 90                });
 91            }
 92        });
 93
 94        #[cfg(not(target_os = "macos"))]
 95        workspace.register_action(|workspace, _: &ActivateMenuLeft, 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::Left, window, cx)
104                        });
105                    }
106                });
107            }
108        });
109    })
110    .detach();
111}
112
113pub struct TitleBar {
114    platform_style: PlatformStyle,
115    content: Stateful<Div>,
116    children: SmallVec<[AnyElement; 2]>,
117    project: Entity<Project>,
118    user_store: Entity<UserStore>,
119    client: Arc<Client>,
120    workspace: WeakEntity<Workspace>,
121    should_move: bool,
122    application_menu: Option<Entity<ApplicationMenu>>,
123    _subscriptions: Vec<Subscription>,
124    banner: Entity<OnboardingBanner>,
125}
126
127impl Render for TitleBar {
128    fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
129        let title_bar_settings = *TitleBarSettings::get_global(cx);
130        let close_action = Box::new(workspace::CloseWindow);
131        let height = Self::height(window);
132        let supported_controls = window.window_controls();
133        let decorations = window.window_decorations();
134        let titlebar_color = if cfg!(any(target_os = "linux", target_os = "freebsd")) {
135            if window.is_window_active() && !self.should_move {
136                cx.theme().colors().title_bar_background
137            } else {
138                cx.theme().colors().title_bar_inactive_background
139            }
140        } else {
141            cx.theme().colors().title_bar_background
142        };
143
144        h_flex()
145            .id("titlebar")
146            .window_control_area(WindowControlArea::Drag)
147            .w_full()
148            .h(height)
149            .map(|this| {
150                if window.is_fullscreen() {
151                    this.pl_2()
152                } else if self.platform_style == PlatformStyle::Mac {
153                    this.pl(px(platform_mac::TRAFFIC_LIGHT_PADDING))
154                } else {
155                    this.pl_2()
156                }
157            })
158            .map(|el| match decorations {
159                Decorations::Server => el,
160                Decorations::Client { tiling, .. } => el
161                    .when(!(tiling.top || tiling.right), |el| {
162                        el.rounded_tr(theme::CLIENT_SIDE_DECORATION_ROUNDING)
163                    })
164                    .when(!(tiling.top || tiling.left), |el| {
165                        el.rounded_tl(theme::CLIENT_SIDE_DECORATION_ROUNDING)
166                    })
167                    // this border is to avoid a transparent gap in the rounded corners
168                    .mt(px(-1.))
169                    .border(px(1.))
170                    .border_color(titlebar_color),
171            })
172            .bg(titlebar_color)
173            .content_stretch()
174            .child(
175                div()
176                    .id("titlebar-content")
177                    .flex()
178                    .flex_row()
179                    .items_center()
180                    .justify_between()
181                    .w_full()
182                    // Note: On Windows the title bar behavior is handled by the platform implementation.
183                    .when(self.platform_style == PlatformStyle::Mac, |this| {
184                        this.on_click(|event, window, _| {
185                            if event.up.click_count == 2 {
186                                window.titlebar_double_click();
187                            }
188                        })
189                    })
190                    .when(self.platform_style == PlatformStyle::Linux, |this| {
191                        this.on_click(|event, window, _| {
192                            if event.up.click_count == 2 {
193                                window.zoom_window();
194                            }
195                        })
196                    })
197                    .child(
198                        h_flex()
199                            .gap_1()
200                            .map(|title_bar| {
201                                let mut render_project_items = title_bar_settings.show_branch_name
202                                    || title_bar_settings.show_project_items;
203                                title_bar
204                                    .when_some(self.application_menu.clone(), |title_bar, menu| {
205                                        render_project_items &= !menu.read(cx).all_menus_shown();
206                                        title_bar.child(menu)
207                                    })
208                                    .when(render_project_items, |title_bar| {
209                                        title_bar
210                                            .when(
211                                                title_bar_settings.show_project_items,
212                                                |title_bar| {
213                                                    title_bar
214                                                        .children(self.render_project_host(cx))
215                                                        .child(self.render_project_name(cx))
216                                                },
217                                            )
218                                            .when(
219                                                title_bar_settings.show_branch_name,
220                                                |title_bar| {
221                                                    title_bar
222                                                        .children(self.render_project_branch(cx))
223                                                },
224                                            )
225                                    })
226                            })
227                            .on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation()),
228                    )
229                    .child(self.render_collaborator_list(window, cx))
230                    .when(title_bar_settings.show_onboarding_banner, |title_bar| {
231                        title_bar.child(self.banner.clone())
232                    })
233                    .child(
234                        h_flex()
235                            .gap_1()
236                            .pr_1()
237                            .on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
238                            .children(self.render_call_controls(window, cx))
239                            .map(|el| {
240                                let status = self.client.status();
241                                let status = &*status.borrow();
242                                if matches!(status, client::Status::Connected { .. }) {
243                                    el.child(self.render_user_menu_button(cx))
244                                } else {
245                                    el.children(self.render_connection_status(status, cx))
246                                        .when(TitleBarSettings::get_global(cx).show_sign_in, |el| {
247                                            el.child(self.render_sign_in_button(cx))
248                                        })
249                                        .child(self.render_user_menu_button(cx))
250                                }
251                            }),
252                    ),
253            )
254            .when(!window.is_fullscreen(), |title_bar| {
255                match self.platform_style {
256                    PlatformStyle::Mac => title_bar,
257                    PlatformStyle::Linux => {
258                        if matches!(decorations, Decorations::Client { .. }) {
259                            title_bar
260                                .child(platform_linux::LinuxWindowControls::new(close_action))
261                                .when(supported_controls.window_menu, |titlebar| {
262                                    titlebar.on_mouse_down(
263                                        gpui::MouseButton::Right,
264                                        move |ev, window, _| window.show_window_menu(ev.position),
265                                    )
266                                })
267                                .on_mouse_move(cx.listener(move |this, _ev, window, _| {
268                                    if this.should_move {
269                                        this.should_move = false;
270                                        window.start_window_move();
271                                    }
272                                }))
273                                .on_mouse_down_out(cx.listener(move |this, _ev, _window, _cx| {
274                                    this.should_move = false;
275                                }))
276                                .on_mouse_up(
277                                    gpui::MouseButton::Left,
278                                    cx.listener(move |this, _ev, _window, _cx| {
279                                        this.should_move = false;
280                                    }),
281                                )
282                                .on_mouse_down(
283                                    gpui::MouseButton::Left,
284                                    cx.listener(move |this, _ev, _window, _cx| {
285                                        this.should_move = true;
286                                    }),
287                                )
288                        } else {
289                            title_bar
290                        }
291                    }
292                    PlatformStyle::Windows => {
293                        title_bar.child(platform_windows::WindowsWindowControls::new(height))
294                    }
295                }
296            })
297    }
298}
299
300impl TitleBar {
301    pub fn new(
302        id: impl Into<ElementId>,
303        workspace: &Workspace,
304        window: &mut Window,
305        cx: &mut Context<Self>,
306    ) -> Self {
307        let project = workspace.project().clone();
308        let user_store = workspace.app_state().user_store.clone();
309        let client = workspace.app_state().client.clone();
310        let active_call = ActiveCall::global(cx);
311
312        let platform_style = PlatformStyle::platform();
313        let application_menu = match platform_style {
314            PlatformStyle::Mac => {
315                if option_env!("ZED_USE_CROSS_PLATFORM_MENU").is_some() {
316                    Some(cx.new(|cx| ApplicationMenu::new(window, cx)))
317                } else {
318                    None
319                }
320            }
321            PlatformStyle::Linux | PlatformStyle::Windows => {
322                Some(cx.new(|cx| ApplicationMenu::new(window, cx)))
323            }
324        };
325
326        let mut subscriptions = Vec::new();
327        subscriptions.push(
328            cx.observe(&workspace.weak_handle().upgrade().unwrap(), |_, _, cx| {
329                cx.notify()
330            }),
331        );
332        subscriptions.push(cx.subscribe(&project, |_, _, _: &project::Event, cx| cx.notify()));
333        subscriptions.push(cx.observe(&active_call, |this, _, cx| this.active_call_changed(cx)));
334        subscriptions.push(cx.observe_window_activation(window, Self::window_activation_changed));
335        subscriptions.push(cx.observe(&user_store, |_, _, cx| cx.notify()));
336
337        let banner = cx.new(|cx| {
338            OnboardingBanner::new(
339                "Debugger Onboarding",
340                IconName::Debug,
341                "The Debugger",
342                None,
343                zed_actions::debugger::OpenOnboardingModal.boxed_clone(),
344                cx,
345            )
346        });
347
348        Self {
349            platform_style,
350            content: div().id(id.into()),
351            children: SmallVec::new(),
352            application_menu,
353            workspace: workspace.weak_handle(),
354            should_move: false,
355            project,
356            user_store,
357            client,
358            _subscriptions: subscriptions,
359            banner,
360        }
361    }
362
363    #[cfg(not(target_os = "windows"))]
364    pub fn height(window: &mut Window) -> Pixels {
365        (1.75 * window.rem_size()).max(px(34.))
366    }
367
368    #[cfg(target_os = "windows")]
369    pub fn height(_window: &mut Window) -> Pixels {
370        // todo(windows) instead of hard coded size report the actual size to the Windows platform API
371        px(32.)
372    }
373
374    /// Sets the platform style.
375    pub fn platform_style(mut self, style: PlatformStyle) -> Self {
376        self.platform_style = style;
377        self
378    }
379
380    fn render_ssh_project_host(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
381        let options = self.project.read(cx).ssh_connection_options(cx)?;
382        let host: SharedString = options.connection_string().into();
383
384        let nickname = options
385            .nickname
386            .clone()
387            .map(|nick| nick.into())
388            .unwrap_or_else(|| host.clone());
389
390        let (indicator_color, meta) = match self.project.read(cx).ssh_connection_state(cx)? {
391            remote::ConnectionState::Connecting => (Color::Info, format!("Connecting to: {host}")),
392            remote::ConnectionState::Connected => (Color::Success, format!("Connected to: {host}")),
393            remote::ConnectionState::HeartbeatMissed => (
394                Color::Warning,
395                format!("Connection attempt to {host} missed. Retrying..."),
396            ),
397            remote::ConnectionState::Reconnecting => (
398                Color::Warning,
399                format!("Lost connection to {host}. Reconnecting..."),
400            ),
401            remote::ConnectionState::Disconnected => {
402                (Color::Error, format!("Disconnected from {host}"))
403            }
404        };
405
406        let icon_color = match self.project.read(cx).ssh_connection_state(cx)? {
407            remote::ConnectionState::Connecting => Color::Info,
408            remote::ConnectionState::Connected => Color::Default,
409            remote::ConnectionState::HeartbeatMissed => Color::Warning,
410            remote::ConnectionState::Reconnecting => Color::Warning,
411            remote::ConnectionState::Disconnected => Color::Error,
412        };
413
414        let meta = SharedString::from(meta);
415
416        Some(
417            ButtonLike::new("ssh-server-icon")
418                .child(
419                    h_flex()
420                        .gap_2()
421                        .max_w_32()
422                        .child(
423                            IconWithIndicator::new(
424                                Icon::new(IconName::Server)
425                                    .size(IconSize::XSmall)
426                                    .color(icon_color),
427                                Some(Indicator::dot().color(indicator_color)),
428                            )
429                            .indicator_border_color(Some(cx.theme().colors().title_bar_background))
430                            .into_any_element(),
431                        )
432                        .child(
433                            Label::new(nickname.clone())
434                                .size(LabelSize::Small)
435                                .truncate(),
436                        ),
437                )
438                .tooltip(move |window, cx| {
439                    Tooltip::with_meta(
440                        "Remote Project",
441                        Some(&OpenRemote {
442                            from_existing_connection: false,
443                            create_new_window: false,
444                        }),
445                        meta.clone(),
446                        window,
447                        cx,
448                    )
449                })
450                .on_click(|_, window, cx| {
451                    window.dispatch_action(
452                        OpenRemote {
453                            from_existing_connection: false,
454                            create_new_window: false,
455                        }
456                        .boxed_clone(),
457                        cx,
458                    );
459                })
460                .into_any_element(),
461        )
462    }
463
464    pub fn render_project_host(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
465        if self.project.read(cx).is_via_ssh() {
466            return self.render_ssh_project_host(cx);
467        }
468
469        if self.project.read(cx).is_disconnected(cx) {
470            return Some(
471                Button::new("disconnected", "Disconnected")
472                    .disabled(true)
473                    .color(Color::Disabled)
474                    .style(ButtonStyle::Subtle)
475                    .label_size(LabelSize::Small)
476                    .into_any_element(),
477            );
478        }
479
480        let host = self.project.read(cx).host()?;
481        let host_user = self.user_store.read(cx).get_cached_user(host.user_id)?;
482        let participant_index = self
483            .user_store
484            .read(cx)
485            .participant_indices()
486            .get(&host_user.id)?;
487        Some(
488            Button::new("project_owner_trigger", host_user.github_login.clone())
489                .color(Color::Player(participant_index.0))
490                .style(ButtonStyle::Subtle)
491                .label_size(LabelSize::Small)
492                .tooltip(Tooltip::text(format!(
493                    "{} is sharing this project. Click to follow.",
494                    host_user.github_login
495                )))
496                .on_click({
497                    let host_peer_id = host.peer_id;
498                    cx.listener(move |this, _, window, cx| {
499                        this.workspace
500                            .update(cx, |workspace, cx| {
501                                workspace.follow(host_peer_id, window, cx);
502                            })
503                            .log_err();
504                    })
505                })
506                .into_any_element(),
507        )
508    }
509
510    pub fn render_project_name(&self, cx: &mut Context<Self>) -> impl IntoElement {
511        let name = {
512            let mut names = self.project.read(cx).visible_worktrees(cx).map(|worktree| {
513                let worktree = worktree.read(cx);
514                worktree.root_name()
515            });
516
517            names.next()
518        };
519        let is_project_selected = name.is_some();
520        let name = if let Some(name) = name {
521            util::truncate_and_trailoff(name, MAX_PROJECT_NAME_LENGTH)
522        } else {
523            "Open recent project".to_string()
524        };
525
526        Button::new("project_name_trigger", name)
527            .when(!is_project_selected, |b| b.color(Color::Muted))
528            .style(ButtonStyle::Subtle)
529            .label_size(LabelSize::Small)
530            .tooltip(move |window, cx| {
531                Tooltip::for_action(
532                    "Recent Projects",
533                    &zed_actions::OpenRecent {
534                        create_new_window: false,
535                    },
536                    window,
537                    cx,
538                )
539            })
540            .on_click(cx.listener(move |_, _, window, cx| {
541                window.dispatch_action(
542                    OpenRecent {
543                        create_new_window: false,
544                    }
545                    .boxed_clone(),
546                    cx,
547                );
548            }))
549    }
550
551    pub fn render_project_branch(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> {
552        let repository = self.project.read(cx).active_repository(cx)?;
553        let workspace = self.workspace.upgrade()?;
554        let branch_name = {
555            let repo = repository.read(cx);
556            repo.branch
557                .as_ref()
558                .map(|branch| branch.name())
559                .map(|name| util::truncate_and_trailoff(&name, MAX_BRANCH_NAME_LENGTH))
560                .or_else(|| {
561                    repo.head_commit.as_ref().map(|commit| {
562                        commit
563                            .sha
564                            .chars()
565                            .take(MAX_SHORT_SHA_LENGTH)
566                            .collect::<String>()
567                    })
568                })
569        }?;
570
571        Some(
572            Button::new("project_branch_trigger", branch_name)
573                .color(Color::Muted)
574                .style(ButtonStyle::Subtle)
575                .label_size(LabelSize::Small)
576                .tooltip(move |window, cx| {
577                    Tooltip::with_meta(
578                        "Recent Branches",
579                        Some(&zed_actions::git::Branch),
580                        "Local branches only",
581                        window,
582                        cx,
583                    )
584                })
585                .on_click(move |_, window, cx| {
586                    let _ = workspace.update(cx, |_this, cx| {
587                        window.dispatch_action(zed_actions::git::Branch.boxed_clone(), cx);
588                    });
589                })
590                .when(
591                    TitleBarSettings::get_global(cx).show_branch_icon,
592                    |branch_button| {
593                        branch_button
594                            .icon(IconName::GitBranch)
595                            .icon_position(IconPosition::Start)
596                            .icon_color(Color::Muted)
597                            .icon_size(IconSize::Indicator)
598                    },
599                ),
600        )
601    }
602
603    fn window_activation_changed(&mut self, window: &mut Window, cx: &mut Context<Self>) {
604        if window.is_window_active() {
605            ActiveCall::global(cx)
606                .update(cx, |call, cx| call.set_location(Some(&self.project), cx))
607                .detach_and_log_err(cx);
608        } else if cx.active_window().is_none() {
609            ActiveCall::global(cx)
610                .update(cx, |call, cx| call.set_location(None, cx))
611                .detach_and_log_err(cx);
612        }
613        self.workspace
614            .update(cx, |workspace, cx| {
615                workspace.update_active_view_for_followers(window, cx);
616            })
617            .ok();
618    }
619
620    fn active_call_changed(&mut self, cx: &mut Context<Self>) {
621        cx.notify();
622    }
623
624    fn share_project(&mut self, cx: &mut Context<Self>) {
625        let active_call = ActiveCall::global(cx);
626        let project = self.project.clone();
627        active_call
628            .update(cx, |call, cx| call.share_project(project, cx))
629            .detach_and_log_err(cx);
630    }
631
632    fn unshare_project(&mut self, _: &mut Window, cx: &mut Context<Self>) {
633        let active_call = ActiveCall::global(cx);
634        let project = self.project.clone();
635        active_call
636            .update(cx, |call, cx| call.unshare_project(project, cx))
637            .log_err();
638    }
639
640    fn render_connection_status(
641        &self,
642        status: &client::Status,
643        cx: &mut Context<Self>,
644    ) -> Option<AnyElement> {
645        match status {
646            client::Status::ConnectionError
647            | client::Status::ConnectionLost
648            | client::Status::Reauthenticating { .. }
649            | client::Status::Reconnecting { .. }
650            | client::Status::ReconnectionError { .. } => Some(
651                div()
652                    .id("disconnected")
653                    .child(Icon::new(IconName::Disconnected).size(IconSize::Small))
654                    .tooltip(Tooltip::text("Disconnected"))
655                    .into_any_element(),
656            ),
657            client::Status::UpgradeRequired => {
658                let auto_updater = auto_update::AutoUpdater::get(cx);
659                let label = match auto_updater.map(|auto_update| auto_update.read(cx).status()) {
660                    Some(AutoUpdateStatus::Updated { .. }) => "Please restart Zed to Collaborate",
661                    Some(AutoUpdateStatus::Installing { .. })
662                    | Some(AutoUpdateStatus::Downloading { .. })
663                    | Some(AutoUpdateStatus::Checking) => "Updating...",
664                    Some(AutoUpdateStatus::Idle) | Some(AutoUpdateStatus::Errored) | None => {
665                        "Please update Zed to Collaborate"
666                    }
667                };
668
669                Some(
670                    Button::new("connection-status", label)
671                        .label_size(LabelSize::Small)
672                        .on_click(|_, window, cx| {
673                            if let Some(auto_updater) = auto_update::AutoUpdater::get(cx) {
674                                if auto_updater.read(cx).status().is_updated() {
675                                    workspace::reload(&Default::default(), cx);
676                                    return;
677                                }
678                            }
679                            auto_update::check(&Default::default(), window, cx);
680                        })
681                        .into_any_element(),
682                )
683            }
684            _ => None,
685        }
686    }
687
688    pub fn render_sign_in_button(&mut self, _: &mut Context<Self>) -> Button {
689        let client = self.client.clone();
690        Button::new("sign_in", "Sign in")
691            .label_size(LabelSize::Small)
692            .on_click(move |_, window, cx| {
693                let client = client.clone();
694                window
695                    .spawn(cx, async move |cx| {
696                        client
697                            .authenticate_and_connect(true, &cx)
698                            .await
699                            .into_response()
700                            .notify_async_err(cx);
701                    })
702                    .detach();
703            })
704    }
705
706    pub fn render_user_menu_button(&mut self, cx: &mut Context<Self>) -> impl Element {
707        let user_store = self.user_store.read(cx);
708        if let Some(user) = user_store.current_user() {
709            let has_subscription_period = self.user_store.read(cx).subscription_period().is_some();
710            let plan = self.user_store.read(cx).current_plan().filter(|_| {
711                // Since the user might be on the legacy free plan we filter based on whether we have a subscription period.
712                has_subscription_period
713            });
714            PopoverMenu::new("user-menu")
715                .anchor(Corner::TopRight)
716                .menu(move |window, cx| {
717                    ContextMenu::build(window, cx, |menu, _, _cx| {
718                        menu.link(
719                            format!(
720                                "Current Plan: {}",
721                                match plan {
722                                    None => "None",
723                                    Some(proto::Plan::Free) => "Zed Free",
724                                    Some(proto::Plan::ZedPro) => "Zed Pro",
725                                    Some(proto::Plan::ZedProTrial) => "Zed Pro (Trial)",
726                                }
727                            ),
728                            zed_actions::OpenAccountSettings.boxed_clone(),
729                        )
730                        .separator()
731                        .action("Settings", zed_actions::OpenSettings.boxed_clone())
732                        .action("Key Bindings", Box::new(zed_actions::OpenKeymap))
733                        .action(
734                            "Themes…",
735                            zed_actions::theme_selector::Toggle::default().boxed_clone(),
736                        )
737                        .action(
738                            "Icon Themes…",
739                            zed_actions::icon_theme_selector::Toggle::default().boxed_clone(),
740                        )
741                        .action(
742                            "Extensions",
743                            zed_actions::Extensions::default().boxed_clone(),
744                        )
745                        .separator()
746                        .action("Sign Out", client::SignOut.boxed_clone())
747                    })
748                    .into()
749                })
750                .trigger_with_tooltip(
751                    ButtonLike::new("user-menu")
752                        .child(
753                            h_flex()
754                                .gap_0p5()
755                                .children(
756                                    TitleBarSettings::get_global(cx)
757                                        .show_user_picture
758                                        .then(|| Avatar::new(user.avatar_uri.clone())),
759                                )
760                                .child(
761                                    Icon::new(IconName::ChevronDown)
762                                        .size(IconSize::Small)
763                                        .color(Color::Muted),
764                                ),
765                        )
766                        .style(ButtonStyle::Subtle),
767                    Tooltip::text("Toggle User Menu"),
768                )
769                .anchor(gpui::Corner::TopRight)
770        } else {
771            PopoverMenu::new("user-menu")
772                .anchor(Corner::TopRight)
773                .menu(|window, cx| {
774                    ContextMenu::build(window, cx, |menu, _, _| {
775                        menu.action("Settings", zed_actions::OpenSettings.boxed_clone())
776                            .action("Key Bindings", Box::new(zed_actions::OpenKeymap))
777                            .action(
778                                "Themes…",
779                                zed_actions::theme_selector::Toggle::default().boxed_clone(),
780                            )
781                            .action(
782                                "Icon Themes…",
783                                zed_actions::icon_theme_selector::Toggle::default().boxed_clone(),
784                            )
785                            .action(
786                                "Extensions",
787                                zed_actions::Extensions::default().boxed_clone(),
788                            )
789                    })
790                    .into()
791                })
792                .trigger_with_tooltip(
793                    IconButton::new("user-menu", IconName::ChevronDown).icon_size(IconSize::Small),
794                    Tooltip::text("Toggle User Menu"),
795                )
796        }
797    }
798}
799
800impl InteractiveElement for TitleBar {
801    fn interactivity(&mut self) -> &mut Interactivity {
802        self.content.interactivity()
803    }
804}
805
806impl StatefulInteractiveElement for TitleBar {}
807
808impl ParentElement for TitleBar {
809    fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>) {
810        self.children.extend(elements)
811    }
812}