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 .icon_size(IconSize::Indicator)
599 },
600 ),
601 )
602 }
603
604 fn window_activation_changed(&mut self, window: &mut Window, cx: &mut Context<Self>) {
605 if window.is_window_active() {
606 ActiveCall::global(cx)
607 .update(cx, |call, cx| call.set_location(Some(&self.project), cx))
608 .detach_and_log_err(cx);
609 } else if cx.active_window().is_none() {
610 ActiveCall::global(cx)
611 .update(cx, |call, cx| call.set_location(None, cx))
612 .detach_and_log_err(cx);
613 }
614 self.workspace
615 .update(cx, |workspace, cx| {
616 workspace.update_active_view_for_followers(window, cx);
617 })
618 .ok();
619 }
620
621 fn active_call_changed(&mut self, cx: &mut Context<Self>) {
622 cx.notify();
623 }
624
625 fn share_project(&mut self, cx: &mut Context<Self>) {
626 let active_call = ActiveCall::global(cx);
627 let project = self.project.clone();
628 active_call
629 .update(cx, |call, cx| call.share_project(project, cx))
630 .detach_and_log_err(cx);
631 }
632
633 fn unshare_project(&mut self, _: &mut Window, cx: &mut Context<Self>) {
634 let active_call = ActiveCall::global(cx);
635 let project = self.project.clone();
636 active_call
637 .update(cx, |call, cx| call.unshare_project(project, cx))
638 .log_err();
639 }
640
641 fn render_connection_status(
642 &self,
643 status: &client::Status,
644 cx: &mut Context<Self>,
645 ) -> Option<AnyElement> {
646 match status {
647 client::Status::ConnectionError
648 | client::Status::ConnectionLost
649 | client::Status::Reauthenticating { .. }
650 | client::Status::Reconnecting { .. }
651 | client::Status::ReconnectionError { .. } => Some(
652 div()
653 .id("disconnected")
654 .child(Icon::new(IconName::Disconnected).size(IconSize::Small))
655 .tooltip(Tooltip::text("Disconnected"))
656 .into_any_element(),
657 ),
658 client::Status::UpgradeRequired => {
659 let auto_updater = auto_update::AutoUpdater::get(cx);
660 let label = match auto_updater.map(|auto_update| auto_update.read(cx).status()) {
661 Some(AutoUpdateStatus::Updated { .. }) => "Please restart Zed to Collaborate",
662 Some(AutoUpdateStatus::Installing { .. })
663 | Some(AutoUpdateStatus::Downloading { .. })
664 | Some(AutoUpdateStatus::Checking) => "Updating...",
665 Some(AutoUpdateStatus::Idle) | Some(AutoUpdateStatus::Errored) | None => {
666 "Please update Zed to Collaborate"
667 }
668 };
669
670 Some(
671 Button::new("connection-status", label)
672 .label_size(LabelSize::Small)
673 .on_click(|_, window, cx| {
674 if let Some(auto_updater) = auto_update::AutoUpdater::get(cx) {
675 if auto_updater.read(cx).status().is_updated() {
676 workspace::reload(&Default::default(), cx);
677 return;
678 }
679 }
680 auto_update::check(&Default::default(), window, cx);
681 })
682 .into_any_element(),
683 )
684 }
685 _ => None,
686 }
687 }
688
689 pub fn render_sign_in_button(&mut self, _: &mut Context<Self>) -> Button {
690 let client = self.client.clone();
691 Button::new("sign_in", "Sign in")
692 .label_size(LabelSize::Small)
693 .on_click(move |_, window, cx| {
694 let client = client.clone();
695 window
696 .spawn(cx, async move |cx| {
697 client
698 .authenticate_and_connect(true, &cx)
699 .await
700 .into_response()
701 .notify_async_err(cx);
702 })
703 .detach();
704 })
705 }
706
707 pub fn render_user_menu_button(&mut self, cx: &mut Context<Self>) -> impl Element {
708 let user_store = self.user_store.read(cx);
709 if let Some(user) = user_store.current_user() {
710 let has_subscription_period = self.user_store.read(cx).subscription_period().is_some();
711 let plan = self.user_store.read(cx).current_plan().filter(|_| {
712 // Since the user might be on the legacy free plan we filter based on whether we have a subscription period.
713 has_subscription_period
714 });
715 PopoverMenu::new("user-menu")
716 .anchor(Corner::TopRight)
717 .menu(move |window, cx| {
718 ContextMenu::build(window, cx, |menu, _, _cx| {
719 menu.link(
720 format!(
721 "Current Plan: {}",
722 match plan {
723 None => "None",
724 Some(proto::Plan::Free) => "Zed Free",
725 Some(proto::Plan::ZedPro) => "Zed Pro",
726 Some(proto::Plan::ZedProTrial) => "Zed Pro (Trial)",
727 }
728 ),
729 zed_actions::OpenAccountSettings.boxed_clone(),
730 )
731 .separator()
732 .action("Settings", zed_actions::OpenSettings.boxed_clone())
733 .action("Key Bindings", Box::new(zed_actions::OpenKeymap))
734 .action(
735 "Themes…",
736 zed_actions::theme_selector::Toggle::default().boxed_clone(),
737 )
738 .action(
739 "Icon Themes…",
740 zed_actions::icon_theme_selector::Toggle::default().boxed_clone(),
741 )
742 .action(
743 "Extensions",
744 zed_actions::Extensions::default().boxed_clone(),
745 )
746 .separator()
747 .action("Sign Out", client::SignOut.boxed_clone())
748 })
749 .into()
750 })
751 .trigger_with_tooltip(
752 ButtonLike::new("user-menu")
753 .child(
754 h_flex()
755 .gap_0p5()
756 .children(
757 TitleBarSettings::get_global(cx)
758 .show_user_picture
759 .then(|| Avatar::new(user.avatar_uri.clone())),
760 )
761 .child(
762 Icon::new(IconName::ChevronDown)
763 .size(IconSize::Small)
764 .color(Color::Muted),
765 ),
766 )
767 .style(ButtonStyle::Subtle),
768 Tooltip::text("Toggle User Menu"),
769 )
770 .anchor(gpui::Corner::TopRight)
771 } else {
772 PopoverMenu::new("user-menu")
773 .anchor(Corner::TopRight)
774 .menu(|window, cx| {
775 ContextMenu::build(window, cx, |menu, _, _| {
776 menu.action("Settings", zed_actions::OpenSettings.boxed_clone())
777 .action("Key Bindings", Box::new(zed_actions::OpenKeymap))
778 .action(
779 "Themes…",
780 zed_actions::theme_selector::Toggle::default().boxed_clone(),
781 )
782 .action(
783 "Icon Themes…",
784 zed_actions::icon_theme_selector::Toggle::default().boxed_clone(),
785 )
786 .action(
787 "Extensions",
788 zed_actions::Extensions::default().boxed_clone(),
789 )
790 })
791 .into()
792 })
793 .trigger_with_tooltip(
794 IconButton::new("user-menu", IconName::ChevronDown).icon_size(IconSize::Small),
795 Tooltip::text("Toggle User Menu"),
796 )
797 }
798 }
799}
800
801impl InteractiveElement for TitleBar {
802 fn interactivity(&mut self) -> &mut Interactivity {
803 self.content.interactivity()
804 }
805}
806
807impl StatefulInteractiveElement for TitleBar {}
808
809impl ParentElement for TitleBar {
810 fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>) {
811 self.children.extend(elements)
812 }
813}