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 create_new_window: false,
443 }),
444 meta.clone(),
445 window,
446 cx,
447 )
448 })
449 .on_click(|_, window, cx| {
450 window.dispatch_action(
451 OpenRemote {
452 from_existing_connection: false,
453 create_new_window: false,
454 }
455 .boxed_clone(),
456 cx,
457 );
458 })
459 .into_any_element(),
460 )
461 }
462
463 pub fn render_project_host(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
464 if self.project.read(cx).is_via_ssh() {
465 return self.render_ssh_project_host(cx);
466 }
467
468 if self.project.read(cx).is_disconnected(cx) {
469 return Some(
470 Button::new("disconnected", "Disconnected")
471 .disabled(true)
472 .color(Color::Disabled)
473 .style(ButtonStyle::Subtle)
474 .label_size(LabelSize::Small)
475 .into_any_element(),
476 );
477 }
478
479 let host = self.project.read(cx).host()?;
480 let host_user = self.user_store.read(cx).get_cached_user(host.user_id)?;
481 let participant_index = self
482 .user_store
483 .read(cx)
484 .participant_indices()
485 .get(&host_user.id)?;
486 Some(
487 Button::new("project_owner_trigger", host_user.github_login.clone())
488 .color(Color::Player(participant_index.0))
489 .style(ButtonStyle::Subtle)
490 .label_size(LabelSize::Small)
491 .tooltip(Tooltip::text(format!(
492 "{} is sharing this project. Click to follow.",
493 host_user.github_login
494 )))
495 .on_click({
496 let host_peer_id = host.peer_id;
497 cx.listener(move |this, _, window, cx| {
498 this.workspace
499 .update(cx, |workspace, cx| {
500 workspace.follow(host_peer_id, window, cx);
501 })
502 .log_err();
503 })
504 })
505 .into_any_element(),
506 )
507 }
508
509 pub fn render_project_name(&self, cx: &mut Context<Self>) -> impl IntoElement {
510 let name = {
511 let mut names = self.project.read(cx).visible_worktrees(cx).map(|worktree| {
512 let worktree = worktree.read(cx);
513 worktree.root_name()
514 });
515
516 names.next()
517 };
518 let is_project_selected = name.is_some();
519 let name = if let Some(name) = name {
520 util::truncate_and_trailoff(name, MAX_PROJECT_NAME_LENGTH)
521 } else {
522 "Open recent project".to_string()
523 };
524
525 Button::new("project_name_trigger", name)
526 .when(!is_project_selected, |b| b.color(Color::Muted))
527 .style(ButtonStyle::Subtle)
528 .label_size(LabelSize::Small)
529 .tooltip(move |window, cx| {
530 Tooltip::for_action(
531 "Recent Projects",
532 &zed_actions::OpenRecent {
533 create_new_window: false,
534 },
535 window,
536 cx,
537 )
538 })
539 .on_click(cx.listener(move |_, _, window, cx| {
540 window.dispatch_action(
541 OpenRecent {
542 create_new_window: false,
543 }
544 .boxed_clone(),
545 cx,
546 );
547 }))
548 }
549
550 pub fn render_project_branch(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> {
551 let repository = self.project.read(cx).active_repository(cx)?;
552 let workspace = self.workspace.upgrade()?;
553 let branch_name = {
554 let repo = repository.read(cx);
555 repo.branch
556 .as_ref()
557 .map(|branch| branch.name())
558 .map(|name| util::truncate_and_trailoff(&name, MAX_BRANCH_NAME_LENGTH))
559 .or_else(|| {
560 repo.head_commit.as_ref().map(|commit| {
561 commit
562 .sha
563 .chars()
564 .take(MAX_SHORT_SHA_LENGTH)
565 .collect::<String>()
566 })
567 })
568 }?;
569
570 Some(
571 Button::new("project_branch_trigger", branch_name)
572 .color(Color::Muted)
573 .style(ButtonStyle::Subtle)
574 .label_size(LabelSize::Small)
575 .tooltip(move |window, cx| {
576 Tooltip::with_meta(
577 "Recent Branches",
578 Some(&zed_actions::git::Branch),
579 "Local branches only",
580 window,
581 cx,
582 )
583 })
584 .on_click(move |_, window, cx| {
585 let _ = workspace.update(cx, |_this, cx| {
586 window.dispatch_action(zed_actions::git::Branch.boxed_clone(), cx);
587 });
588 })
589 .when(
590 TitleBarSettings::get_global(cx).show_branch_icon,
591 |branch_button| {
592 branch_button
593 .icon(IconName::GitBranch)
594 .icon_position(IconPosition::Start)
595 .icon_color(Color::Muted)
596 },
597 ),
598 )
599 }
600
601 fn window_activation_changed(&mut self, window: &mut Window, cx: &mut Context<Self>) {
602 if window.is_window_active() {
603 ActiveCall::global(cx)
604 .update(cx, |call, cx| call.set_location(Some(&self.project), cx))
605 .detach_and_log_err(cx);
606 } else if cx.active_window().is_none() {
607 ActiveCall::global(cx)
608 .update(cx, |call, cx| call.set_location(None, cx))
609 .detach_and_log_err(cx);
610 }
611 self.workspace
612 .update(cx, |workspace, cx| {
613 workspace.update_active_view_for_followers(window, cx);
614 })
615 .ok();
616 }
617
618 fn active_call_changed(&mut self, cx: &mut Context<Self>) {
619 cx.notify();
620 }
621
622 fn share_project(&mut self, cx: &mut Context<Self>) {
623 let active_call = ActiveCall::global(cx);
624 let project = self.project.clone();
625 active_call
626 .update(cx, |call, cx| call.share_project(project, cx))
627 .detach_and_log_err(cx);
628 }
629
630 fn unshare_project(&mut self, _: &mut Window, cx: &mut Context<Self>) {
631 let active_call = ActiveCall::global(cx);
632 let project = self.project.clone();
633 active_call
634 .update(cx, |call, cx| call.unshare_project(project, cx))
635 .log_err();
636 }
637
638 fn render_connection_status(
639 &self,
640 status: &client::Status,
641 cx: &mut Context<Self>,
642 ) -> Option<AnyElement> {
643 match status {
644 client::Status::ConnectionError
645 | client::Status::ConnectionLost
646 | client::Status::Reauthenticating { .. }
647 | client::Status::Reconnecting { .. }
648 | client::Status::ReconnectionError { .. } => Some(
649 div()
650 .id("disconnected")
651 .child(Icon::new(IconName::Disconnected).size(IconSize::Small))
652 .tooltip(Tooltip::text("Disconnected"))
653 .into_any_element(),
654 ),
655 client::Status::UpgradeRequired => {
656 let auto_updater = auto_update::AutoUpdater::get(cx);
657 let label = match auto_updater.map(|auto_update| auto_update.read(cx).status()) {
658 Some(AutoUpdateStatus::Updated { .. }) => "Please restart Zed to Collaborate",
659 Some(AutoUpdateStatus::Installing { .. })
660 | Some(AutoUpdateStatus::Downloading { .. })
661 | Some(AutoUpdateStatus::Checking) => "Updating...",
662 Some(AutoUpdateStatus::Idle) | Some(AutoUpdateStatus::Errored) | None => {
663 "Please update Zed to Collaborate"
664 }
665 };
666
667 Some(
668 Button::new("connection-status", label)
669 .label_size(LabelSize::Small)
670 .on_click(|_, window, cx| {
671 if let Some(auto_updater) = auto_update::AutoUpdater::get(cx) {
672 if auto_updater.read(cx).status().is_updated() {
673 workspace::reload(&Default::default(), cx);
674 return;
675 }
676 }
677 auto_update::check(&Default::default(), window, cx);
678 })
679 .into_any_element(),
680 )
681 }
682 _ => None,
683 }
684 }
685
686 pub fn render_sign_in_button(&mut self, _: &mut Context<Self>) -> Button {
687 let client = self.client.clone();
688 Button::new("sign_in", "Sign in")
689 .label_size(LabelSize::Small)
690 .on_click(move |_, window, cx| {
691 let client = client.clone();
692 window
693 .spawn(cx, async move |cx| {
694 client
695 .authenticate_and_connect(true, &cx)
696 .await
697 .into_response()
698 .notify_async_err(cx);
699 })
700 .detach();
701 })
702 }
703
704 pub fn render_user_menu_button(&mut self, cx: &mut Context<Self>) -> impl Element {
705 let user_store = self.user_store.read(cx);
706 if let Some(user) = user_store.current_user() {
707 let has_subscription_period = self.user_store.read(cx).subscription_period().is_some();
708 let plan = self.user_store.read(cx).current_plan().filter(|_| {
709 // Since the user might be on the legacy free plan we filter based on whether we have a subscription period.
710 has_subscription_period
711 });
712 PopoverMenu::new("user-menu")
713 .anchor(Corner::TopRight)
714 .menu(move |window, cx| {
715 ContextMenu::build(window, cx, |menu, _, _cx| {
716 menu.link(
717 format!(
718 "Current Plan: {}",
719 match plan {
720 None => "None",
721 Some(proto::Plan::Free) => "Zed Free",
722 Some(proto::Plan::ZedPro) => "Zed Pro",
723 Some(proto::Plan::ZedProTrial) => "Zed Pro (Trial)",
724 }
725 ),
726 zed_actions::OpenAccountSettings.boxed_clone(),
727 )
728 .separator()
729 .action("Settings", zed_actions::OpenSettings.boxed_clone())
730 .action("Key Bindings", Box::new(zed_actions::OpenKeymap))
731 .action(
732 "Themes…",
733 zed_actions::theme_selector::Toggle::default().boxed_clone(),
734 )
735 .action(
736 "Icon Themes…",
737 zed_actions::icon_theme_selector::Toggle::default().boxed_clone(),
738 )
739 .action(
740 "Extensions",
741 zed_actions::Extensions::default().boxed_clone(),
742 )
743 .separator()
744 .action("Sign Out", client::SignOut.boxed_clone())
745 })
746 .into()
747 })
748 .trigger_with_tooltip(
749 ButtonLike::new("user-menu")
750 .child(
751 h_flex()
752 .gap_0p5()
753 .children(
754 TitleBarSettings::get_global(cx)
755 .show_user_picture
756 .then(|| Avatar::new(user.avatar_uri.clone())),
757 )
758 .child(
759 Icon::new(IconName::ChevronDown)
760 .size(IconSize::Small)
761 .color(Color::Muted),
762 ),
763 )
764 .style(ButtonStyle::Subtle),
765 Tooltip::text("Toggle User Menu"),
766 )
767 .anchor(gpui::Corner::TopRight)
768 } else {
769 PopoverMenu::new("user-menu")
770 .anchor(Corner::TopRight)
771 .menu(|window, cx| {
772 ContextMenu::build(window, cx, |menu, _, _| {
773 menu.action("Settings", zed_actions::OpenSettings.boxed_clone())
774 .action("Key Bindings", Box::new(zed_actions::OpenKeymap))
775 .action(
776 "Themes…",
777 zed_actions::theme_selector::Toggle::default().boxed_clone(),
778 )
779 .action(
780 "Icon Themes…",
781 zed_actions::icon_theme_selector::Toggle::default().boxed_clone(),
782 )
783 .action(
784 "Extensions",
785 zed_actions::Extensions::default().boxed_clone(),
786 )
787 })
788 .into()
789 })
790 .trigger_with_tooltip(
791 IconButton::new("user-menu", IconName::ChevronDown).icon_size(IconSize::Small),
792 Tooltip::text("Toggle User Menu"),
793 )
794 }
795 }
796}
797
798impl InteractiveElement for TitleBar {
799 fn interactivity(&mut self) -> &mut Interactivity {
800 self.content.interactivity()
801 }
802}
803
804impl StatefulInteractiveElement for TitleBar {}
805
806impl ParentElement for TitleBar {
807 fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>) {
808 self.children.extend(elements)
809 }
810}