1mod application_menu;
2pub mod collab;
3mod onboarding_banner;
4pub mod platform_title_bar;
5mod platforms;
6mod system_window_tabs;
7mod title_bar_settings;
8
9#[cfg(feature = "stories")]
10mod stories;
11
12use crate::{
13 application_menu::{ApplicationMenu, show_menus},
14 platform_title_bar::PlatformTitleBar,
15 system_window_tabs::SystemWindowTabs,
16};
17
18#[cfg(not(target_os = "macos"))]
19use crate::application_menu::{
20 ActivateDirection, ActivateMenuLeft, ActivateMenuRight, OpenApplicationMenu,
21};
22
23use auto_update::AutoUpdateStatus;
24use call::ActiveCall;
25use client::{Client, UserStore, zed_urls};
26use cloud_llm_client::{Plan, PlanV1, PlanV2};
27use gpui::{
28 Action, AnyElement, App, Context, Corner, Element, Entity, Focusable, InteractiveElement,
29 IntoElement, MouseButton, ParentElement, Render, StatefulInteractiveElement, Styled,
30 Subscription, WeakEntity, Window, actions, div,
31};
32use onboarding_banner::OnboardingBanner;
33use project::{
34 Project, WorktreeSettings, git_store::GitStoreEvent, trusted_worktrees::TrustedWorktrees,
35};
36use remote::RemoteConnectionOptions;
37use settings::{Settings, SettingsLocation};
38use std::sync::Arc;
39use theme::ActiveTheme;
40use title_bar_settings::TitleBarSettings;
41use ui::{
42 Avatar, ButtonLike, Chip, ContextMenu, IconWithIndicator, Indicator, PopoverMenu,
43 PopoverMenuHandle, TintColor, Tooltip, prelude::*,
44};
45use util::{ResultExt, rel_path::RelPath};
46use workspace::{ToggleWorktreeSecurity, Workspace, notifications::NotifyResultExt};
47use zed_actions::OpenRemote;
48
49pub use onboarding_banner::restore_banner;
50
51#[cfg(feature = "stories")]
52pub use stories::*;
53
54const MAX_PROJECT_NAME_LENGTH: usize = 40;
55const MAX_BRANCH_NAME_LENGTH: usize = 40;
56const MAX_SHORT_SHA_LENGTH: usize = 8;
57
58actions!(
59 collab,
60 [
61 /// Toggles the user menu dropdown.
62 ToggleUserMenu,
63 /// Toggles the project menu dropdown.
64 ToggleProjectMenu,
65 /// Switches to a different git branch.
66 SwitchBranch
67 ]
68);
69
70pub fn init(cx: &mut App) {
71 SystemWindowTabs::init(cx);
72
73 cx.observe_new(|workspace: &mut Workspace, window, cx| {
74 let Some(window) = window else {
75 return;
76 };
77 let item = cx.new(|cx| TitleBar::new("title-bar", workspace, window, cx));
78 workspace.set_titlebar_item(item.into(), window, cx);
79
80 #[cfg(not(target_os = "macos"))]
81 workspace.register_action(|workspace, action: &OpenApplicationMenu, window, cx| {
82 if let Some(titlebar) = workspace
83 .titlebar_item()
84 .and_then(|item| item.downcast::<TitleBar>().ok())
85 {
86 titlebar.update(cx, |titlebar, cx| {
87 if let Some(ref menu) = titlebar.application_menu {
88 menu.update(cx, |menu, cx| menu.open_menu(action, window, cx));
89 }
90 });
91 }
92 });
93
94 #[cfg(not(target_os = "macos"))]
95 workspace.register_action(|workspace, _: &ActivateMenuRight, 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::Right, window, cx)
104 });
105 }
106 });
107 }
108 });
109
110 #[cfg(not(target_os = "macos"))]
111 workspace.register_action(|workspace, _: &ActivateMenuLeft, window, cx| {
112 if let Some(titlebar) = workspace
113 .titlebar_item()
114 .and_then(|item| item.downcast::<TitleBar>().ok())
115 {
116 titlebar.update(cx, |titlebar, cx| {
117 if let Some(ref menu) = titlebar.application_menu {
118 menu.update(cx, |menu, cx| {
119 menu.navigate_menus_in_direction(ActivateDirection::Left, window, cx)
120 });
121 }
122 });
123 }
124 });
125 })
126 .detach();
127}
128
129pub struct TitleBar {
130 platform_titlebar: Entity<PlatformTitleBar>,
131 project: Entity<Project>,
132 user_store: Entity<UserStore>,
133 client: Arc<Client>,
134 workspace: WeakEntity<Workspace>,
135 application_menu: Option<Entity<ApplicationMenu>>,
136 _subscriptions: Vec<Subscription>,
137 banner: Entity<OnboardingBanner>,
138 screen_share_popover_handle: PopoverMenuHandle<ContextMenu>,
139}
140
141impl Render for TitleBar {
142 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
143 let title_bar_settings = *TitleBarSettings::get_global(cx);
144
145 let show_menus = show_menus(cx);
146
147 let mut children = Vec::new();
148
149 children.push(
150 h_flex()
151 .gap_1()
152 .map(|title_bar| {
153 let mut render_project_items = title_bar_settings.show_branch_name
154 || title_bar_settings.show_project_items;
155 title_bar
156 .when_some(
157 self.application_menu.clone().filter(|_| !show_menus),
158 |title_bar, menu| {
159 render_project_items &=
160 !menu.update(cx, |menu, cx| menu.all_menus_shown(cx));
161 title_bar.child(menu)
162 },
163 )
164 .children(self.render_restricted_mode(cx))
165 .when(render_project_items, |title_bar| {
166 title_bar
167 .when(title_bar_settings.show_project_items, |title_bar| {
168 title_bar
169 .children(self.render_project_host(cx))
170 .child(self.render_project_name(cx))
171 })
172 .when(title_bar_settings.show_branch_name, |title_bar| {
173 title_bar.children(self.render_project_repo(cx))
174 })
175 })
176 })
177 .on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
178 .into_any_element(),
179 );
180
181 children.push(self.render_collaborator_list(window, cx).into_any_element());
182
183 if title_bar_settings.show_onboarding_banner {
184 children.push(self.banner.clone().into_any_element())
185 }
186
187 let status = self.client.status();
188 let status = &*status.borrow();
189 let user = self.user_store.read(cx).current_user();
190
191 let signed_in = user.is_some();
192
193 children.push(
194 h_flex()
195 .map(|this| {
196 if signed_in {
197 this.pr_1p5()
198 } else {
199 this.pr_1()
200 }
201 })
202 .gap_1()
203 .on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
204 .children(self.render_call_controls(window, cx))
205 .children(self.render_connection_status(status, cx))
206 .when(
207 user.is_none() && TitleBarSettings::get_global(cx).show_sign_in,
208 |this| this.child(self.render_sign_in_button(cx)),
209 )
210 .when(TitleBarSettings::get_global(cx).show_user_menu, |this| {
211 this.child(self.render_user_menu_button(cx))
212 })
213 .into_any_element(),
214 );
215
216 if show_menus {
217 self.platform_titlebar.update(cx, |this, _| {
218 this.set_children(
219 self.application_menu
220 .clone()
221 .map(|menu| menu.into_any_element()),
222 );
223 });
224
225 let height = PlatformTitleBar::height(window);
226 let title_bar_color = self.platform_titlebar.update(cx, |platform_titlebar, cx| {
227 platform_titlebar.title_bar_color(window, cx)
228 });
229
230 v_flex()
231 .w_full()
232 .child(self.platform_titlebar.clone().into_any_element())
233 .child(
234 h_flex()
235 .bg(title_bar_color)
236 .h(height)
237 .pl_2()
238 .justify_between()
239 .w_full()
240 .children(children),
241 )
242 .into_any_element()
243 } else {
244 self.platform_titlebar.update(cx, |this, _| {
245 this.set_children(children);
246 });
247 self.platform_titlebar.clone().into_any_element()
248 }
249 }
250}
251
252impl TitleBar {
253 pub fn new(
254 id: impl Into<ElementId>,
255 workspace: &Workspace,
256 window: &mut Window,
257 cx: &mut Context<Self>,
258 ) -> Self {
259 let project = workspace.project().clone();
260 let git_store = project.read(cx).git_store().clone();
261 let user_store = workspace.app_state().user_store.clone();
262 let client = workspace.app_state().client.clone();
263 let active_call = ActiveCall::global(cx);
264
265 let platform_style = PlatformStyle::platform();
266 let application_menu = match platform_style {
267 PlatformStyle::Mac => {
268 if option_env!("ZED_USE_CROSS_PLATFORM_MENU").is_some() {
269 Some(cx.new(|cx| ApplicationMenu::new(window, cx)))
270 } else {
271 None
272 }
273 }
274 PlatformStyle::Linux | PlatformStyle::Windows => {
275 Some(cx.new(|cx| ApplicationMenu::new(window, cx)))
276 }
277 };
278
279 let mut subscriptions = Vec::new();
280 subscriptions.push(
281 cx.observe(&workspace.weak_handle().upgrade().unwrap(), |_, _, cx| {
282 cx.notify()
283 }),
284 );
285 subscriptions.push(cx.subscribe(&project, |_, _, _: &project::Event, cx| cx.notify()));
286 subscriptions.push(cx.observe(&active_call, |this, _, cx| this.active_call_changed(cx)));
287 subscriptions.push(cx.observe_window_activation(window, Self::window_activation_changed));
288 subscriptions.push(
289 cx.subscribe(&git_store, move |_, _, event, cx| match event {
290 GitStoreEvent::ActiveRepositoryChanged(_)
291 | GitStoreEvent::RepositoryUpdated(_, _, true) => {
292 cx.notify();
293 }
294 _ => {}
295 }),
296 );
297 subscriptions.push(cx.observe(&user_store, |_a, _, cx| cx.notify()));
298 if let Some(trusted_worktrees) = TrustedWorktrees::try_get_global(cx) {
299 subscriptions.push(cx.subscribe(&trusted_worktrees, |_, _, _, cx| {
300 cx.notify();
301 }));
302 }
303
304 let banner = cx.new(|cx| {
305 OnboardingBanner::new(
306 "ACP Claude Code Onboarding",
307 IconName::AiClaude,
308 "Claude Code",
309 Some("Introducing:".into()),
310 zed_actions::agent::OpenClaudeCodeOnboardingModal.boxed_clone(),
311 cx,
312 )
313 // When updating this to a non-AI feature release, remove this line.
314 .visible_when(|cx| !project::DisableAiSettings::get_global(cx).disable_ai)
315 });
316
317 let platform_titlebar = cx.new(|cx| PlatformTitleBar::new(id, cx));
318
319 Self {
320 platform_titlebar,
321 application_menu,
322 workspace: workspace.weak_handle(),
323 project,
324 user_store,
325 client,
326 _subscriptions: subscriptions,
327 banner,
328 screen_share_popover_handle: PopoverMenuHandle::default(),
329 }
330 }
331
332 fn project_name(&self, cx: &Context<Self>) -> Option<SharedString> {
333 self.project
334 .read(cx)
335 .visible_worktrees(cx)
336 .map(|worktree| {
337 let worktree = worktree.read(cx);
338 let settings_location = SettingsLocation {
339 worktree_id: worktree.id(),
340 path: RelPath::empty(),
341 };
342
343 let settings = WorktreeSettings::get(Some(settings_location), cx);
344 let name = match &settings.project_name {
345 Some(name) => name.as_str(),
346 None => worktree.root_name_str(),
347 };
348 SharedString::new(name)
349 })
350 .next()
351 }
352
353 fn render_remote_project_connection(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
354 let workspace = self.workspace.clone();
355
356 let options = self.project.read(cx).remote_connection_options(cx)?;
357 let host: SharedString = options.display_name().into();
358
359 let (nickname, tooltip_title, icon) = match options {
360 RemoteConnectionOptions::Ssh(options) => (
361 options.nickname.map(|nick| nick.into()),
362 "Remote Project",
363 IconName::Server,
364 ),
365 RemoteConnectionOptions::Wsl(_) => (None, "Remote Project", IconName::Linux),
366 RemoteConnectionOptions::Docker(_dev_container_connection) => {
367 (None, "Dev Container", IconName::Box)
368 }
369 };
370
371 let nickname = nickname.unwrap_or_else(|| host.clone());
372
373 let (indicator_color, meta) = match self.project.read(cx).remote_connection_state(cx)? {
374 remote::ConnectionState::Connecting => (Color::Info, format!("Connecting to: {host}")),
375 remote::ConnectionState::Connected => (Color::Success, format!("Connected to: {host}")),
376 remote::ConnectionState::HeartbeatMissed => (
377 Color::Warning,
378 format!("Connection attempt to {host} missed. Retrying..."),
379 ),
380 remote::ConnectionState::Reconnecting => (
381 Color::Warning,
382 format!("Lost connection to {host}. Reconnecting..."),
383 ),
384 remote::ConnectionState::Disconnected => {
385 (Color::Error, format!("Disconnected from {host}"))
386 }
387 };
388
389 let icon_color = match self.project.read(cx).remote_connection_state(cx)? {
390 remote::ConnectionState::Connecting => Color::Info,
391 remote::ConnectionState::Connected => Color::Default,
392 remote::ConnectionState::HeartbeatMissed => Color::Warning,
393 remote::ConnectionState::Reconnecting => Color::Warning,
394 remote::ConnectionState::Disconnected => Color::Error,
395 };
396
397 let meta = SharedString::from(meta);
398
399 Some(
400 PopoverMenu::new("remote-project-menu")
401 .menu(move |window, cx| {
402 let workspace_entity = workspace.upgrade()?;
403 let fs = workspace_entity.read(cx).project().read(cx).fs().clone();
404 Some(recent_projects::RemoteServerProjects::popover(
405 fs,
406 workspace.clone(),
407 false,
408 window,
409 cx,
410 ))
411 })
412 .trigger_with_tooltip(
413 ButtonLike::new("remote_project")
414 .selected_style(ButtonStyle::Tinted(TintColor::Accent))
415 .child(
416 h_flex()
417 .gap_2()
418 .max_w_32()
419 .child(
420 IconWithIndicator::new(
421 Icon::new(icon).size(IconSize::Small).color(icon_color),
422 Some(Indicator::dot().color(indicator_color)),
423 )
424 .indicator_border_color(Some(
425 cx.theme().colors().title_bar_background,
426 ))
427 .into_any_element(),
428 )
429 .child(Label::new(nickname).size(LabelSize::Small).truncate()),
430 ),
431 move |_window, cx| {
432 Tooltip::with_meta(
433 tooltip_title,
434 Some(&OpenRemote {
435 from_existing_connection: false,
436 create_new_window: false,
437 }),
438 meta.clone(),
439 cx,
440 )
441 },
442 )
443 .anchor(gpui::Corner::TopLeft)
444 .into_any_element(),
445 )
446 }
447
448 pub fn render_restricted_mode(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
449 let has_restricted_worktrees = TrustedWorktrees::try_get_global(cx)
450 .map(|trusted_worktrees| {
451 trusted_worktrees
452 .read(cx)
453 .has_restricted_worktrees(&self.project.read(cx).worktree_store(), cx)
454 })
455 .unwrap_or(false);
456 if !has_restricted_worktrees {
457 return None;
458 }
459
460 let button = Button::new("restricted_mode_trigger", "Restricted Mode")
461 .style(ButtonStyle::Tinted(TintColor::Warning))
462 .label_size(LabelSize::Small)
463 .color(Color::Warning)
464 .icon(IconName::Warning)
465 .icon_color(Color::Warning)
466 .icon_size(IconSize::Small)
467 .icon_position(IconPosition::Start)
468 .tooltip(|_, cx| {
469 Tooltip::with_meta(
470 "You're in Restricted Mode",
471 Some(&ToggleWorktreeSecurity),
472 "Mark this project as trusted and unlock all features",
473 cx,
474 )
475 })
476 .on_click({
477 cx.listener(move |this, _, window, cx| {
478 this.workspace
479 .update(cx, |workspace, cx| {
480 workspace.show_worktree_trust_security_modal(true, window, cx)
481 })
482 .log_err();
483 })
484 });
485
486 if cfg!(macos_sdk_26) {
487 // Make up for Tahoe's traffic light buttons having less spacing around them
488 Some(div().child(button).ml_0p5().into_any_element())
489 } else {
490 Some(button.into_any_element())
491 }
492 }
493
494 pub fn render_project_host(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
495 if self.project.read(cx).is_via_remote_server() {
496 return self.render_remote_project_connection(cx);
497 }
498
499 if self.project.read(cx).is_disconnected(cx) {
500 return Some(
501 Button::new("disconnected", "Disconnected")
502 .disabled(true)
503 .color(Color::Disabled)
504 .label_size(LabelSize::Small)
505 .into_any_element(),
506 );
507 }
508
509 let host = self.project.read(cx).host()?;
510 let host_user = self.user_store.read(cx).get_cached_user(host.user_id)?;
511 let participant_index = self
512 .user_store
513 .read(cx)
514 .participant_indices()
515 .get(&host_user.id)?;
516
517 Some(
518 Button::new("project_owner_trigger", host_user.github_login.clone())
519 .color(Color::Player(participant_index.0))
520 .label_size(LabelSize::Small)
521 .tooltip(move |_, cx| {
522 let tooltip_title = format!(
523 "{} is sharing this project. Click to follow.",
524 host_user.github_login
525 );
526
527 Tooltip::with_meta(tooltip_title, None, "Click to Follow", cx)
528 })
529 .on_click({
530 let host_peer_id = host.peer_id;
531 cx.listener(move |this, _, window, cx| {
532 this.workspace
533 .update(cx, |workspace, cx| {
534 workspace.follow(host_peer_id, window, cx);
535 })
536 .log_err();
537 })
538 })
539 .into_any_element(),
540 )
541 }
542
543 pub fn render_project_name(&self, cx: &mut Context<Self>) -> impl IntoElement {
544 let workspace = self.workspace.clone();
545
546 let name = self.project_name(cx);
547 let is_project_selected = name.is_some();
548 let name = if let Some(name) = name {
549 util::truncate_and_trailoff(&name, MAX_PROJECT_NAME_LENGTH)
550 } else {
551 "Open Recent Project".to_string()
552 };
553
554 let focus_handle = workspace
555 .upgrade()
556 .map(|w| w.read(cx).focus_handle(cx))
557 .unwrap_or_else(|| cx.focus_handle());
558
559 PopoverMenu::new("recent-projects-menu")
560 .menu(move |window, cx| {
561 Some(recent_projects::RecentProjects::popover(
562 workspace.clone(),
563 false,
564 focus_handle.clone(),
565 window,
566 cx,
567 ))
568 })
569 .trigger_with_tooltip(
570 Button::new("project_name_trigger", name)
571 .label_size(LabelSize::Small)
572 .selected_style(ButtonStyle::Tinted(TintColor::Accent))
573 .when(!is_project_selected, |s| s.color(Color::Muted)),
574 move |_window, cx| {
575 Tooltip::for_action(
576 "Recent Projects",
577 &zed_actions::OpenRecent {
578 create_new_window: false,
579 },
580 cx,
581 )
582 },
583 )
584 .anchor(gpui::Corner::TopLeft)
585 }
586
587 pub fn render_project_repo(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> {
588 let repository = self.project.read(cx).active_repository(cx)?;
589 let repository_count = self.project.read(cx).repositories(cx).len();
590 let workspace = self.workspace.upgrade()?;
591
592 let (branch_name, icon_info) = {
593 let repo = repository.read(cx);
594 let branch_name = repo
595 .branch
596 .as_ref()
597 .map(|branch| branch.name())
598 .map(|name| util::truncate_and_trailoff(name, MAX_BRANCH_NAME_LENGTH))
599 .or_else(|| {
600 repo.head_commit.as_ref().map(|commit| {
601 commit
602 .sha
603 .chars()
604 .take(MAX_SHORT_SHA_LENGTH)
605 .collect::<String>()
606 })
607 });
608
609 let branch_name = branch_name?;
610
611 let project_name = self.project_name(cx);
612 let repo_name = repo
613 .work_directory_abs_path
614 .file_name()
615 .and_then(|name| name.to_str())
616 .map(SharedString::new);
617 let show_repo_name =
618 repository_count > 1 && repo.branch.is_some() && repo_name != project_name;
619 let branch_name = if let Some(repo_name) = repo_name.filter(|_| show_repo_name) {
620 format!("{repo_name}/{branch_name}")
621 } else {
622 branch_name
623 };
624
625 let status = repo.status_summary();
626 let tracked = status.index + status.worktree;
627 let icon_info = if status.conflict > 0 {
628 (IconName::Warning, Color::VersionControlConflict)
629 } else if tracked.modified > 0 {
630 (IconName::SquareDot, Color::VersionControlModified)
631 } else if tracked.added > 0 || status.untracked > 0 {
632 (IconName::SquarePlus, Color::VersionControlAdded)
633 } else if tracked.deleted > 0 {
634 (IconName::SquareMinus, Color::VersionControlDeleted)
635 } else {
636 (IconName::GitBranch, Color::Muted)
637 };
638
639 (branch_name, icon_info)
640 };
641
642 let settings = TitleBarSettings::get_global(cx);
643 let project = self.project.clone();
644
645 Some(
646 PopoverMenu::new("branch-menu")
647 .menu(move |window, cx| {
648 let repository = project.read(cx).active_repository(cx);
649 Some(git_ui::branch_picker::popover(
650 workspace.downgrade(),
651 true,
652 repository,
653 window,
654 cx,
655 ))
656 })
657 .trigger_with_tooltip(
658 Button::new("project_branch_trigger", branch_name)
659 .selected_style(ButtonStyle::Tinted(TintColor::Accent))
660 .label_size(LabelSize::Small)
661 .color(Color::Muted)
662 .when(settings.show_branch_icon, |branch_button| {
663 let (icon, icon_color) = icon_info;
664 branch_button
665 .icon(icon)
666 .icon_position(IconPosition::Start)
667 .icon_color(icon_color)
668 .icon_size(IconSize::Indicator)
669 }),
670 move |_window, cx| {
671 Tooltip::with_meta(
672 "Recent Branches",
673 Some(&zed_actions::git::Branch),
674 "Local branches only",
675 cx,
676 )
677 },
678 )
679 .anchor(gpui::Corner::TopLeft),
680 )
681 }
682
683 fn window_activation_changed(&mut self, window: &mut Window, cx: &mut Context<Self>) {
684 if window.is_window_active() {
685 ActiveCall::global(cx)
686 .update(cx, |call, cx| call.set_location(Some(&self.project), cx))
687 .detach_and_log_err(cx);
688 } else if cx.active_window().is_none() {
689 ActiveCall::global(cx)
690 .update(cx, |call, cx| call.set_location(None, cx))
691 .detach_and_log_err(cx);
692 }
693 self.workspace
694 .update(cx, |workspace, cx| {
695 workspace.update_active_view_for_followers(window, cx);
696 })
697 .ok();
698 }
699
700 fn active_call_changed(&mut self, cx: &mut Context<Self>) {
701 cx.notify();
702 }
703
704 fn share_project(&mut self, cx: &mut Context<Self>) {
705 let active_call = ActiveCall::global(cx);
706 let project = self.project.clone();
707 active_call
708 .update(cx, |call, cx| call.share_project(project, cx))
709 .detach_and_log_err(cx);
710 }
711
712 fn unshare_project(&mut self, _: &mut Window, cx: &mut Context<Self>) {
713 let active_call = ActiveCall::global(cx);
714 let project = self.project.clone();
715 active_call
716 .update(cx, |call, cx| call.unshare_project(project, cx))
717 .log_err();
718 }
719
720 fn render_connection_status(
721 &self,
722 status: &client::Status,
723 cx: &mut Context<Self>,
724 ) -> Option<AnyElement> {
725 match status {
726 client::Status::ConnectionError
727 | client::Status::ConnectionLost
728 | client::Status::Reauthenticating
729 | client::Status::Reconnecting
730 | client::Status::ReconnectionError { .. } => Some(
731 div()
732 .id("disconnected")
733 .child(Icon::new(IconName::Disconnected).size(IconSize::Small))
734 .tooltip(Tooltip::text("Disconnected"))
735 .into_any_element(),
736 ),
737 client::Status::UpgradeRequired => {
738 let auto_updater = auto_update::AutoUpdater::get(cx);
739 let label = match auto_updater.map(|auto_update| auto_update.read(cx).status()) {
740 Some(AutoUpdateStatus::Updated { .. }) => "Please restart Zed to Collaborate",
741 Some(AutoUpdateStatus::Installing { .. })
742 | Some(AutoUpdateStatus::Downloading { .. })
743 | Some(AutoUpdateStatus::Checking) => "Updating...",
744 Some(AutoUpdateStatus::Idle)
745 | Some(AutoUpdateStatus::Errored { .. })
746 | None => "Please update Zed to Collaborate",
747 };
748
749 Some(
750 Button::new("connection-status", label)
751 .label_size(LabelSize::Small)
752 .on_click(|_, window, cx| {
753 if let Some(auto_updater) = auto_update::AutoUpdater::get(cx)
754 && auto_updater.read(cx).status().is_updated()
755 {
756 workspace::reload(cx);
757 return;
758 }
759 auto_update::check(&Default::default(), window, cx);
760 })
761 .into_any_element(),
762 )
763 }
764 _ => None,
765 }
766 }
767
768 pub fn render_sign_in_button(&mut self, _: &mut Context<Self>) -> Button {
769 let client = self.client.clone();
770 Button::new("sign_in", "Sign In")
771 .label_size(LabelSize::Small)
772 .on_click(move |_, window, cx| {
773 let client = client.clone();
774 window
775 .spawn(cx, async move |cx| {
776 client
777 .sign_in_with_optional_connect(true, cx)
778 .await
779 .notify_async_err(cx);
780 })
781 .detach();
782 })
783 }
784
785 pub fn render_user_menu_button(&mut self, cx: &mut Context<Self>) -> impl Element {
786 let user_store = self.user_store.read(cx);
787 let user = user_store.current_user();
788
789 let user_avatar = user.as_ref().map(|u| u.avatar_uri.clone());
790 let user_login = user.as_ref().map(|u| u.github_login.clone());
791
792 let is_signed_in = user.is_some();
793
794 let has_subscription_period = user_store.subscription_period().is_some();
795 let plan = user_store.plan().filter(|_| {
796 // Since the user might be on the legacy free plan we filter based on whether we have a subscription period.
797 has_subscription_period
798 });
799
800 let free_chip_bg = cx
801 .theme()
802 .colors()
803 .editor_background
804 .opacity(0.5)
805 .blend(cx.theme().colors().text_accent.opacity(0.05));
806
807 let pro_chip_bg = cx
808 .theme()
809 .colors()
810 .editor_background
811 .opacity(0.5)
812 .blend(cx.theme().colors().text_accent.opacity(0.2));
813
814 PopoverMenu::new("user-menu")
815 .anchor(Corner::TopRight)
816 .menu(move |window, cx| {
817 ContextMenu::build(window, cx, |menu, _, _cx| {
818 let user_login = user_login.clone();
819
820 let (plan_name, label_color, bg_color) = match plan {
821 None | Some(Plan::V1(PlanV1::ZedFree) | Plan::V2(PlanV2::ZedFree)) => {
822 ("Free", Color::Default, free_chip_bg)
823 }
824 Some(Plan::V1(PlanV1::ZedProTrial) | Plan::V2(PlanV2::ZedProTrial)) => {
825 ("Pro Trial", Color::Accent, pro_chip_bg)
826 }
827 Some(Plan::V1(PlanV1::ZedPro) | Plan::V2(PlanV2::ZedPro)) => {
828 ("Pro", Color::Accent, pro_chip_bg)
829 }
830 };
831
832 menu.when(is_signed_in, |this| {
833 this.custom_entry(
834 move |_window, _cx| {
835 let user_login = user_login.clone().unwrap_or_default();
836
837 h_flex()
838 .w_full()
839 .justify_between()
840 .child(Label::new(user_login))
841 .child(
842 Chip::new(plan_name.to_string())
843 .bg_color(bg_color)
844 .label_color(label_color),
845 )
846 .into_any_element()
847 },
848 move |_, cx| {
849 cx.open_url(&zed_urls::account_url(cx));
850 },
851 )
852 .separator()
853 })
854 .action("Settings", zed_actions::OpenSettings.boxed_clone())
855 .action("Keymap", Box::new(zed_actions::OpenKeymap))
856 .action(
857 "Themes…",
858 zed_actions::theme_selector::Toggle::default().boxed_clone(),
859 )
860 .action(
861 "Icon Themes…",
862 zed_actions::icon_theme_selector::Toggle::default().boxed_clone(),
863 )
864 .action(
865 "Extensions",
866 zed_actions::Extensions::default().boxed_clone(),
867 )
868 .when(is_signed_in, |this| {
869 this.separator()
870 .action("Sign Out", client::SignOut.boxed_clone())
871 })
872 })
873 .into()
874 })
875 .map(|this| {
876 if is_signed_in && TitleBarSettings::get_global(cx).show_user_picture {
877 this.trigger_with_tooltip(
878 ButtonLike::new("user-menu")
879 .children(user_avatar.clone().map(|avatar| Avatar::new(avatar))),
880 Tooltip::text("Toggle User Menu"),
881 )
882 } else {
883 this.trigger_with_tooltip(
884 IconButton::new("user-menu", IconName::ChevronDown)
885 .icon_size(IconSize::Small),
886 Tooltip::text("Toggle User Menu"),
887 )
888 }
889 })
890 .anchor(gpui::Corner::TopRight)
891 }
892}