title_bar.rs

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