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