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, WindowControlArea,
26 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::{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
53actions!(collab, [ToggleUserMenu, ToggleProjectMenu, SwitchBranch]);
54
55pub fn init(cx: &mut App) {
56 TitleBarSettings::register(cx);
57
58 cx.observe_new(|workspace: &mut Workspace, window, cx| {
59 let Some(window) = window else {
60 return;
61 };
62 let item = cx.new(|cx| TitleBar::new("title-bar", workspace, window, cx));
63 workspace.set_titlebar_item(item.into(), window, cx);
64
65 #[cfg(not(target_os = "macos"))]
66 workspace.register_action(|workspace, action: &OpenApplicationMenu, window, cx| {
67 if let Some(titlebar) = workspace
68 .titlebar_item()
69 .and_then(|item| item.downcast::<TitleBar>().ok())
70 {
71 titlebar.update(cx, |titlebar, cx| {
72 if let Some(ref menu) = titlebar.application_menu {
73 menu.update(cx, |menu, cx| menu.open_menu(action, window, cx));
74 }
75 });
76 }
77 });
78
79 #[cfg(not(target_os = "macos"))]
80 workspace.register_action(|workspace, _: &ActivateMenuRight, window, cx| {
81 if let Some(titlebar) = workspace
82 .titlebar_item()
83 .and_then(|item| item.downcast::<TitleBar>().ok())
84 {
85 titlebar.update(cx, |titlebar, cx| {
86 if let Some(ref menu) = titlebar.application_menu {
87 menu.update(cx, |menu, cx| {
88 menu.navigate_menus_in_direction(ActivateDirection::Right, window, cx)
89 });
90 }
91 });
92 }
93 });
94
95 #[cfg(not(target_os = "macos"))]
96 workspace.register_action(|workspace, _: &ActivateMenuLeft, window, cx| {
97 if let Some(titlebar) = workspace
98 .titlebar_item()
99 .and_then(|item| item.downcast::<TitleBar>().ok())
100 {
101 titlebar.update(cx, |titlebar, cx| {
102 if let Some(ref menu) = titlebar.application_menu {
103 menu.update(cx, |menu, cx| {
104 menu.navigate_menus_in_direction(ActivateDirection::Left, window, cx)
105 });
106 }
107 });
108 }
109 });
110 })
111 .detach();
112}
113
114pub struct TitleBar {
115 platform_style: PlatformStyle,
116 content: Stateful<Div>,
117 children: SmallVec<[AnyElement; 2]>,
118 project: Entity<Project>,
119 user_store: Entity<UserStore>,
120 client: Arc<Client>,
121 workspace: WeakEntity<Workspace>,
122 should_move: bool,
123 application_menu: Option<Entity<ApplicationMenu>>,
124 _subscriptions: Vec<Subscription>,
125 banner: Entity<OnboardingBanner>,
126}
127
128impl Render for TitleBar {
129 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
130 let title_bar_settings = *TitleBarSettings::get_global(cx);
131 let close_action = Box::new(workspace::CloseWindow);
132 let height = Self::height(window);
133 let supported_controls = window.window_controls();
134 let decorations = window.window_decorations();
135 let titlebar_color = if cfg!(any(target_os = "linux", target_os = "freebsd")) {
136 if window.is_window_active() && !self.should_move {
137 cx.theme().colors().title_bar_background
138 } else {
139 cx.theme().colors().title_bar_inactive_background
140 }
141 } else {
142 cx.theme().colors().title_bar_background
143 };
144
145 h_flex()
146 .id("titlebar")
147 .window_control_area(WindowControlArea::Drag)
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::Mac, |this| {
185 this.on_click(|event, window, _| {
186 if event.up.click_count == 2 {
187 window.titlebar_double_click();
188 }
189 })
190 })
191 .when(self.platform_style == PlatformStyle::Linux, |this| {
192 this.on_click(|event, window, _| {
193 if event.up.click_count == 2 {
194 window.zoom_window();
195 }
196 })
197 })
198 .child(
199 h_flex()
200 .gap_1()
201 .map(|title_bar| {
202 let mut render_project_items = title_bar_settings.show_branch_name
203 || title_bar_settings.show_project_items;
204 title_bar
205 .when_some(self.application_menu.clone(), |title_bar, menu| {
206 render_project_items &= !menu.read(cx).all_menus_shown();
207 title_bar.child(menu)
208 })
209 .when(render_project_items, |title_bar| {
210 title_bar
211 .when(
212 title_bar_settings.show_project_items,
213 |title_bar| {
214 title_bar
215 .children(self.render_project_host(cx))
216 .child(self.render_project_name(cx))
217 },
218 )
219 .when(
220 title_bar_settings.show_branch_name,
221 |title_bar| {
222 title_bar
223 .children(self.render_project_branch(cx))
224 },
225 )
226 })
227 })
228 .on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation()),
229 )
230 .child(self.render_collaborator_list(window, cx))
231 .when(title_bar_settings.show_onboarding_banner, |title_bar| {
232 title_bar.child(self.banner.clone())
233 })
234 .child(
235 h_flex()
236 .gap_1()
237 .pr_1()
238 .on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
239 .children(self.render_call_controls(window, cx))
240 .map(|el| {
241 let status = self.client.status();
242 let status = &*status.borrow();
243 if matches!(status, client::Status::Connected { .. }) {
244 el.child(self.render_user_menu_button(cx))
245 } else {
246 el.children(self.render_connection_status(status, cx))
247 .when(TitleBarSettings::get_global(cx).show_sign_in, |el| {
248 el.child(self.render_sign_in_button(cx))
249 })
250 .child(self.render_user_menu_button(cx))
251 }
252 }),
253 ),
254 )
255 .when(!window.is_fullscreen(), |title_bar| {
256 match self.platform_style {
257 PlatformStyle::Mac => title_bar,
258 PlatformStyle::Linux => {
259 if matches!(decorations, Decorations::Client { .. }) {
260 title_bar
261 .child(platform_linux::LinuxWindowControls::new(close_action))
262 .when(supported_controls.window_menu, |titlebar| {
263 titlebar.on_mouse_down(
264 gpui::MouseButton::Right,
265 move |ev, window, _| window.show_window_menu(ev.position),
266 )
267 })
268 .on_mouse_move(cx.listener(move |this, _ev, window, _| {
269 if this.should_move {
270 this.should_move = false;
271 window.start_window_move();
272 }
273 }))
274 .on_mouse_down_out(cx.listener(move |this, _ev, _window, _cx| {
275 this.should_move = false;
276 }))
277 .on_mouse_up(
278 gpui::MouseButton::Left,
279 cx.listener(move |this, _ev, _window, _cx| {
280 this.should_move = false;
281 }),
282 )
283 .on_mouse_down(
284 gpui::MouseButton::Left,
285 cx.listener(move |this, _ev, _window, _cx| {
286 this.should_move = true;
287 }),
288 )
289 } else {
290 title_bar
291 }
292 }
293 PlatformStyle::Windows => {
294 title_bar.child(platform_windows::WindowsWindowControls::new(height))
295 }
296 }
297 })
298 }
299}
300
301impl TitleBar {
302 pub fn new(
303 id: impl Into<ElementId>,
304 workspace: &Workspace,
305 window: &mut Window,
306 cx: &mut Context<Self>,
307 ) -> Self {
308 let project = workspace.project().clone();
309 let user_store = workspace.app_state().user_store.clone();
310 let client = workspace.app_state().client.clone();
311 let active_call = ActiveCall::global(cx);
312
313 let platform_style = PlatformStyle::platform();
314 let application_menu = match platform_style {
315 PlatformStyle::Mac => {
316 if option_env!("ZED_USE_CROSS_PLATFORM_MENU").is_some() {
317 Some(cx.new(|cx| ApplicationMenu::new(window, cx)))
318 } else {
319 None
320 }
321 }
322 PlatformStyle::Linux | PlatformStyle::Windows => {
323 Some(cx.new(|cx| ApplicationMenu::new(window, cx)))
324 }
325 };
326
327 let mut subscriptions = Vec::new();
328 subscriptions.push(
329 cx.observe(&workspace.weak_handle().upgrade().unwrap(), |_, _, cx| {
330 cx.notify()
331 }),
332 );
333 subscriptions.push(cx.subscribe(&project, |_, _, _: &project::Event, cx| cx.notify()));
334 subscriptions.push(cx.observe(&active_call, |this, _, cx| this.active_call_changed(cx)));
335 subscriptions.push(cx.observe_window_activation(window, Self::window_activation_changed));
336 subscriptions.push(cx.observe(&user_store, |_, _, cx| cx.notify()));
337
338 let banner = cx.new(|cx| {
339 OnboardingBanner::new(
340 "Agentic Onboarding",
341 IconName::ZedAssistant,
342 "Agentic Editing",
343 None,
344 zed_actions::agent::OpenOnboardingModal.boxed_clone(),
345 cx,
346 )
347 });
348
349 Self {
350 platform_style,
351 content: div().id(id.into()),
352 children: SmallVec::new(),
353 application_menu,
354 workspace: workspace.weak_handle(),
355 should_move: false,
356 project,
357 user_store,
358 client,
359 _subscriptions: subscriptions,
360 banner,
361 }
362 }
363
364 #[cfg(not(target_os = "windows"))]
365 pub fn height(window: &mut Window) -> Pixels {
366 (1.75 * window.rem_size()).max(px(34.))
367 }
368
369 #[cfg(target_os = "windows")]
370 pub fn height(_window: &mut Window) -> Pixels {
371 // todo(windows) instead of hard coded size report the actual size to the Windows platform API
372 px(32.)
373 }
374
375 /// Sets the platform style.
376 pub fn platform_style(mut self, style: PlatformStyle) -> Self {
377 self.platform_style = style;
378 self
379 }
380
381 fn render_ssh_project_host(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
382 let options = self.project.read(cx).ssh_connection_options(cx)?;
383 let host: SharedString = options.connection_string().into();
384
385 let nickname = options
386 .nickname
387 .clone()
388 .map(|nick| nick.into())
389 .unwrap_or_else(|| host.clone());
390
391 let (indicator_color, meta) = match self.project.read(cx).ssh_connection_state(cx)? {
392 remote::ConnectionState::Connecting => (Color::Info, format!("Connecting to: {host}")),
393 remote::ConnectionState::Connected => (Color::Success, format!("Connected to: {host}")),
394 remote::ConnectionState::HeartbeatMissed => (
395 Color::Warning,
396 format!("Connection attempt to {host} missed. Retrying..."),
397 ),
398 remote::ConnectionState::Reconnecting => (
399 Color::Warning,
400 format!("Lost connection to {host}. Reconnecting..."),
401 ),
402 remote::ConnectionState::Disconnected => {
403 (Color::Error, format!("Disconnected from {host}"))
404 }
405 };
406
407 let icon_color = match self.project.read(cx).ssh_connection_state(cx)? {
408 remote::ConnectionState::Connecting => Color::Info,
409 remote::ConnectionState::Connected => Color::Default,
410 remote::ConnectionState::HeartbeatMissed => Color::Warning,
411 remote::ConnectionState::Reconnecting => Color::Warning,
412 remote::ConnectionState::Disconnected => Color::Error,
413 };
414
415 let meta = SharedString::from(meta);
416
417 Some(
418 ButtonLike::new("ssh-server-icon")
419 .child(
420 h_flex()
421 .gap_2()
422 .max_w_32()
423 .child(
424 IconWithIndicator::new(
425 Icon::new(IconName::Server)
426 .size(IconSize::XSmall)
427 .color(icon_color),
428 Some(Indicator::dot().color(indicator_color)),
429 )
430 .indicator_border_color(Some(cx.theme().colors().title_bar_background))
431 .into_any_element(),
432 )
433 .child(
434 Label::new(nickname.clone())
435 .size(LabelSize::Small)
436 .truncate(),
437 ),
438 )
439 .tooltip(move |window, cx| {
440 Tooltip::with_meta(
441 "Remote Project",
442 Some(&OpenRemote {
443 from_existing_connection: false,
444 create_new_window: false,
445 }),
446 meta.clone(),
447 window,
448 cx,
449 )
450 })
451 .on_click(|_, window, cx| {
452 window.dispatch_action(
453 OpenRemote {
454 from_existing_connection: false,
455 create_new_window: false,
456 }
457 .boxed_clone(),
458 cx,
459 );
460 })
461 .into_any_element(),
462 )
463 }
464
465 pub fn render_project_host(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
466 if self.project.read(cx).is_via_ssh() {
467 return self.render_ssh_project_host(cx);
468 }
469
470 if self.project.read(cx).is_disconnected(cx) {
471 return Some(
472 Button::new("disconnected", "Disconnected")
473 .disabled(true)
474 .color(Color::Disabled)
475 .style(ButtonStyle::Subtle)
476 .label_size(LabelSize::Small)
477 .into_any_element(),
478 );
479 }
480
481 let host = self.project.read(cx).host()?;
482 let host_user = self.user_store.read(cx).get_cached_user(host.user_id)?;
483 let participant_index = self
484 .user_store
485 .read(cx)
486 .participant_indices()
487 .get(&host_user.id)?;
488 Some(
489 Button::new("project_owner_trigger", host_user.github_login.clone())
490 .color(Color::Player(participant_index.0))
491 .style(ButtonStyle::Subtle)
492 .label_size(LabelSize::Small)
493 .tooltip(Tooltip::text(format!(
494 "{} is sharing this project. Click to follow.",
495 host_user.github_login
496 )))
497 .on_click({
498 let host_peer_id = host.peer_id;
499 cx.listener(move |this, _, window, cx| {
500 this.workspace
501 .update(cx, |workspace, cx| {
502 workspace.follow(host_peer_id, window, cx);
503 })
504 .log_err();
505 })
506 })
507 .into_any_element(),
508 )
509 }
510
511 pub fn render_project_name(&self, cx: &mut Context<Self>) -> impl IntoElement {
512 let name = {
513 let mut names = self.project.read(cx).visible_worktrees(cx).map(|worktree| {
514 let worktree = worktree.read(cx);
515 worktree.root_name()
516 });
517
518 names.next()
519 };
520 let is_project_selected = name.is_some();
521 let name = if let Some(name) = name {
522 util::truncate_and_trailoff(name, MAX_PROJECT_NAME_LENGTH)
523 } else {
524 "Open recent project".to_string()
525 };
526
527 Button::new("project_name_trigger", name)
528 .when(!is_project_selected, |b| b.color(Color::Muted))
529 .style(ButtonStyle::Subtle)
530 .label_size(LabelSize::Small)
531 .tooltip(move |window, cx| {
532 Tooltip::for_action(
533 "Recent Projects",
534 &zed_actions::OpenRecent {
535 create_new_window: false,
536 },
537 window,
538 cx,
539 )
540 })
541 .on_click(cx.listener(move |_, _, window, cx| {
542 window.dispatch_action(
543 OpenRecent {
544 create_new_window: false,
545 }
546 .boxed_clone(),
547 cx,
548 );
549 }))
550 }
551
552 pub fn render_project_branch(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> {
553 let repository = self.project.read(cx).active_repository(cx)?;
554 let workspace = self.workspace.upgrade()?;
555 let branch_name = {
556 let repo = repository.read(cx);
557 repo.branch
558 .as_ref()
559 .map(|branch| branch.name())
560 .map(|name| util::truncate_and_trailoff(&name, MAX_BRANCH_NAME_LENGTH))
561 .or_else(|| {
562 repo.head_commit.as_ref().map(|commit| {
563 commit
564 .sha
565 .chars()
566 .take(MAX_SHORT_SHA_LENGTH)
567 .collect::<String>()
568 })
569 })
570 }?;
571
572 Some(
573 Button::new("project_branch_trigger", branch_name)
574 .color(Color::Muted)
575 .style(ButtonStyle::Subtle)
576 .label_size(LabelSize::Small)
577 .tooltip(move |window, cx| {
578 Tooltip::with_meta(
579 "Recent Branches",
580 Some(&zed_actions::git::Branch),
581 "Local branches only",
582 window,
583 cx,
584 )
585 })
586 .on_click(move |_, window, cx| {
587 let _ = workspace.update(cx, |_this, cx| {
588 window.dispatch_action(zed_actions::git::Branch.boxed_clone(), cx);
589 });
590 })
591 .when(
592 TitleBarSettings::get_global(cx).show_branch_icon,
593 |branch_button| {
594 branch_button
595 .icon(IconName::GitBranch)
596 .icon_position(IconPosition::Start)
597 .icon_color(Color::Muted)
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}