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 .when(render_project_items, |title_bar| {
165 title_bar
166 .when(title_bar_settings.show_project_items, |title_bar| {
167 title_bar
168 .children(self.render_restricted_mode(cx))
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 #[cfg(any(test, feature = "test-support"))]
370 RemoteConnectionOptions::Mock(_) => (None, "Mock Remote Project", IconName::Server),
371 };
372
373 let nickname = nickname.unwrap_or_else(|| host.clone());
374
375 let (indicator_color, meta) = match self.project.read(cx).remote_connection_state(cx)? {
376 remote::ConnectionState::Connecting => (Color::Info, format!("Connecting to: {host}")),
377 remote::ConnectionState::Connected => (Color::Success, format!("Connected to: {host}")),
378 remote::ConnectionState::HeartbeatMissed => (
379 Color::Warning,
380 format!("Connection attempt to {host} missed. Retrying..."),
381 ),
382 remote::ConnectionState::Reconnecting => (
383 Color::Warning,
384 format!("Lost connection to {host}. Reconnecting..."),
385 ),
386 remote::ConnectionState::Disconnected => {
387 (Color::Error, format!("Disconnected from {host}"))
388 }
389 };
390
391 let icon_color = match self.project.read(cx).remote_connection_state(cx)? {
392 remote::ConnectionState::Connecting => Color::Info,
393 remote::ConnectionState::Connected => Color::Default,
394 remote::ConnectionState::HeartbeatMissed => Color::Warning,
395 remote::ConnectionState::Reconnecting => Color::Warning,
396 remote::ConnectionState::Disconnected => Color::Error,
397 };
398
399 let meta = SharedString::from(meta);
400
401 Some(
402 PopoverMenu::new("remote-project-menu")
403 .menu(move |window, cx| {
404 let workspace_entity = workspace.upgrade()?;
405 let fs = workspace_entity.read(cx).project().read(cx).fs().clone();
406 Some(recent_projects::RemoteServerProjects::popover(
407 fs,
408 workspace.clone(),
409 false,
410 window,
411 cx,
412 ))
413 })
414 .trigger_with_tooltip(
415 ButtonLike::new("remote_project")
416 .selected_style(ButtonStyle::Tinted(TintColor::Accent))
417 .child(
418 h_flex()
419 .gap_2()
420 .max_w_32()
421 .child(
422 IconWithIndicator::new(
423 Icon::new(icon).size(IconSize::Small).color(icon_color),
424 Some(Indicator::dot().color(indicator_color)),
425 )
426 .indicator_border_color(Some(
427 cx.theme().colors().title_bar_background,
428 ))
429 .into_any_element(),
430 )
431 .child(Label::new(nickname).size(LabelSize::Small).truncate()),
432 ),
433 move |_window, cx| {
434 Tooltip::with_meta(
435 tooltip_title,
436 Some(&OpenRemote {
437 from_existing_connection: false,
438 create_new_window: false,
439 }),
440 meta.clone(),
441 cx,
442 )
443 },
444 )
445 .anchor(gpui::Corner::TopLeft)
446 .into_any_element(),
447 )
448 }
449
450 pub fn render_restricted_mode(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
451 let has_restricted_worktrees = TrustedWorktrees::try_get_global(cx)
452 .map(|trusted_worktrees| {
453 trusted_worktrees
454 .read(cx)
455 .has_restricted_worktrees(&self.project.read(cx).worktree_store(), cx)
456 })
457 .unwrap_or(false);
458 if !has_restricted_worktrees {
459 return None;
460 }
461
462 let button = Button::new("restricted_mode_trigger", "Restricted Mode")
463 .style(ButtonStyle::Tinted(TintColor::Warning))
464 .label_size(LabelSize::Small)
465 .color(Color::Warning)
466 .icon(IconName::Warning)
467 .icon_color(Color::Warning)
468 .icon_size(IconSize::Small)
469 .icon_position(IconPosition::Start)
470 .tooltip(|_, cx| {
471 Tooltip::with_meta(
472 "You're in Restricted Mode",
473 Some(&ToggleWorktreeSecurity),
474 "Mark this project as trusted and unlock all features",
475 cx,
476 )
477 })
478 .on_click({
479 cx.listener(move |this, _, window, cx| {
480 this.workspace
481 .update(cx, |workspace, cx| {
482 workspace.show_worktree_trust_security_modal(true, window, cx)
483 })
484 .log_err();
485 })
486 });
487
488 if cfg!(macos_sdk_26) {
489 // Make up for Tahoe's traffic light buttons having less spacing around them
490 Some(div().child(button).ml_0p5().into_any_element())
491 } else {
492 Some(button.into_any_element())
493 }
494 }
495
496 pub fn render_project_host(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
497 if self.project.read(cx).is_via_remote_server() {
498 return self.render_remote_project_connection(cx);
499 }
500
501 if self.project.read(cx).is_disconnected(cx) {
502 return Some(
503 Button::new("disconnected", "Disconnected")
504 .disabled(true)
505 .color(Color::Disabled)
506 .label_size(LabelSize::Small)
507 .into_any_element(),
508 );
509 }
510
511 let host = self.project.read(cx).host()?;
512 let host_user = self.user_store.read(cx).get_cached_user(host.user_id)?;
513 let participant_index = self
514 .user_store
515 .read(cx)
516 .participant_indices()
517 .get(&host_user.id)?;
518
519 Some(
520 Button::new("project_owner_trigger", host_user.github_login.clone())
521 .color(Color::Player(participant_index.0))
522 .label_size(LabelSize::Small)
523 .tooltip(move |_, cx| {
524 let tooltip_title = format!(
525 "{} is sharing this project. Click to follow.",
526 host_user.github_login
527 );
528
529 Tooltip::with_meta(tooltip_title, None, "Click to Follow", cx)
530 })
531 .on_click({
532 let host_peer_id = host.peer_id;
533 cx.listener(move |this, _, window, cx| {
534 this.workspace
535 .update(cx, |workspace, cx| {
536 workspace.follow(host_peer_id, window, cx);
537 })
538 .log_err();
539 })
540 })
541 .into_any_element(),
542 )
543 }
544
545 pub fn render_project_name(&self, cx: &mut Context<Self>) -> impl IntoElement {
546 let workspace = self.workspace.clone();
547
548 let name = self.project_name(cx);
549 let is_project_selected = name.is_some();
550 let name = if let Some(name) = name {
551 util::truncate_and_trailoff(&name, MAX_PROJECT_NAME_LENGTH)
552 } else {
553 "Open Recent Project".to_string()
554 };
555
556 let focus_handle = workspace
557 .upgrade()
558 .map(|w| w.read(cx).focus_handle(cx))
559 .unwrap_or_else(|| cx.focus_handle());
560
561 PopoverMenu::new("recent-projects-menu")
562 .menu(move |window, cx| {
563 Some(recent_projects::RecentProjects::popover(
564 workspace.clone(),
565 false,
566 focus_handle.clone(),
567 window,
568 cx,
569 ))
570 })
571 .trigger_with_tooltip(
572 Button::new("project_name_trigger", name)
573 .label_size(LabelSize::Small)
574 .selected_style(ButtonStyle::Tinted(TintColor::Accent))
575 .when(!is_project_selected, |s| s.color(Color::Muted)),
576 move |_window, cx| {
577 Tooltip::for_action(
578 "Recent Projects",
579 &zed_actions::OpenRecent {
580 create_new_window: false,
581 },
582 cx,
583 )
584 },
585 )
586 .anchor(gpui::Corner::TopLeft)
587 }
588
589 pub fn render_project_repo(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> {
590 let repository = self.project.read(cx).active_repository(cx)?;
591 let repository_count = self.project.read(cx).repositories(cx).len();
592 let workspace = self.workspace.upgrade()?;
593
594 let (branch_name, icon_info) = {
595 let repo = repository.read(cx);
596 let branch_name = repo
597 .branch
598 .as_ref()
599 .map(|branch| branch.name())
600 .map(|name| util::truncate_and_trailoff(name, MAX_BRANCH_NAME_LENGTH))
601 .or_else(|| {
602 repo.head_commit.as_ref().map(|commit| {
603 commit
604 .sha
605 .chars()
606 .take(MAX_SHORT_SHA_LENGTH)
607 .collect::<String>()
608 })
609 });
610
611 let branch_name = branch_name?;
612
613 let project_name = self.project_name(cx);
614 let repo_name = repo
615 .work_directory_abs_path
616 .file_name()
617 .and_then(|name| name.to_str())
618 .map(SharedString::new);
619 let show_repo_name =
620 repository_count > 1 && repo.branch.is_some() && repo_name != project_name;
621 let branch_name = if let Some(repo_name) = repo_name.filter(|_| show_repo_name) {
622 format!("{repo_name}/{branch_name}")
623 } else {
624 branch_name
625 };
626
627 let status = repo.status_summary();
628 let tracked = status.index + status.worktree;
629 let icon_info = if status.conflict > 0 {
630 (IconName::Warning, Color::VersionControlConflict)
631 } else if tracked.modified > 0 {
632 (IconName::SquareDot, Color::VersionControlModified)
633 } else if tracked.added > 0 || status.untracked > 0 {
634 (IconName::SquarePlus, Color::VersionControlAdded)
635 } else if tracked.deleted > 0 {
636 (IconName::SquareMinus, Color::VersionControlDeleted)
637 } else {
638 (IconName::GitBranch, Color::Muted)
639 };
640
641 (branch_name, icon_info)
642 };
643
644 let settings = TitleBarSettings::get_global(cx);
645 let project = self.project.clone();
646
647 Some(
648 PopoverMenu::new("branch-menu")
649 .menu(move |window, cx| {
650 let repository = project.read(cx).active_repository(cx);
651 Some(git_ui::branch_picker::popover(
652 workspace.downgrade(),
653 true,
654 repository,
655 window,
656 cx,
657 ))
658 })
659 .trigger_with_tooltip(
660 Button::new("project_branch_trigger", branch_name)
661 .selected_style(ButtonStyle::Tinted(TintColor::Accent))
662 .label_size(LabelSize::Small)
663 .color(Color::Muted)
664 .when(settings.show_branch_icon, |branch_button| {
665 let (icon, icon_color) = icon_info;
666 branch_button
667 .icon(icon)
668 .icon_position(IconPosition::Start)
669 .icon_color(icon_color)
670 .icon_size(IconSize::Indicator)
671 }),
672 move |_window, cx| {
673 Tooltip::with_meta(
674 "Recent Branches",
675 Some(&zed_actions::git::Branch),
676 "Local branches only",
677 cx,
678 )
679 },
680 )
681 .anchor(gpui::Corner::TopLeft),
682 )
683 }
684
685 fn window_activation_changed(&mut self, window: &mut Window, cx: &mut Context<Self>) {
686 if window.is_window_active() {
687 ActiveCall::global(cx)
688 .update(cx, |call, cx| call.set_location(Some(&self.project), cx))
689 .detach_and_log_err(cx);
690 } else if cx.active_window().is_none() {
691 ActiveCall::global(cx)
692 .update(cx, |call, cx| call.set_location(None, cx))
693 .detach_and_log_err(cx);
694 }
695 self.workspace
696 .update(cx, |workspace, cx| {
697 workspace.update_active_view_for_followers(window, cx);
698 })
699 .ok();
700 }
701
702 fn active_call_changed(&mut self, cx: &mut Context<Self>) {
703 cx.notify();
704 }
705
706 fn share_project(&mut self, cx: &mut Context<Self>) {
707 let active_call = ActiveCall::global(cx);
708 let project = self.project.clone();
709 active_call
710 .update(cx, |call, cx| call.share_project(project, cx))
711 .detach_and_log_err(cx);
712 }
713
714 fn unshare_project(&mut self, _: &mut Window, cx: &mut Context<Self>) {
715 let active_call = ActiveCall::global(cx);
716 let project = self.project.clone();
717 active_call
718 .update(cx, |call, cx| call.unshare_project(project, cx))
719 .log_err();
720 }
721
722 fn render_connection_status(
723 &self,
724 status: &client::Status,
725 cx: &mut Context<Self>,
726 ) -> Option<AnyElement> {
727 match status {
728 client::Status::ConnectionError
729 | client::Status::ConnectionLost
730 | client::Status::Reauthenticating
731 | client::Status::Reconnecting
732 | client::Status::ReconnectionError { .. } => Some(
733 div()
734 .id("disconnected")
735 .child(Icon::new(IconName::Disconnected).size(IconSize::Small))
736 .tooltip(Tooltip::text("Disconnected"))
737 .into_any_element(),
738 ),
739 client::Status::UpgradeRequired => {
740 let auto_updater = auto_update::AutoUpdater::get(cx);
741 let label = match auto_updater.map(|auto_update| auto_update.read(cx).status()) {
742 Some(AutoUpdateStatus::Updated { .. }) => "Please restart Zed to Collaborate",
743 Some(AutoUpdateStatus::Installing { .. })
744 | Some(AutoUpdateStatus::Downloading { .. })
745 | Some(AutoUpdateStatus::Checking) => "Updating...",
746 Some(AutoUpdateStatus::Idle)
747 | Some(AutoUpdateStatus::Errored { .. })
748 | None => "Please update Zed to Collaborate",
749 };
750
751 Some(
752 Button::new("connection-status", label)
753 .label_size(LabelSize::Small)
754 .on_click(|_, window, cx| {
755 if let Some(auto_updater) = auto_update::AutoUpdater::get(cx)
756 && auto_updater.read(cx).status().is_updated()
757 {
758 workspace::reload(cx);
759 return;
760 }
761 auto_update::check(&Default::default(), window, cx);
762 })
763 .into_any_element(),
764 )
765 }
766 _ => None,
767 }
768 }
769
770 pub fn render_sign_in_button(&mut self, _: &mut Context<Self>) -> Button {
771 let client = self.client.clone();
772 Button::new("sign_in", "Sign In")
773 .label_size(LabelSize::Small)
774 .on_click(move |_, window, cx| {
775 let client = client.clone();
776 window
777 .spawn(cx, async move |cx| {
778 client
779 .sign_in_with_optional_connect(true, cx)
780 .await
781 .notify_async_err(cx);
782 })
783 .detach();
784 })
785 }
786
787 pub fn render_user_menu_button(&mut self, cx: &mut Context<Self>) -> impl Element {
788 let user_store = self.user_store.read(cx);
789 let user = user_store.current_user();
790
791 let user_avatar = user.as_ref().map(|u| u.avatar_uri.clone());
792 let user_login = user.as_ref().map(|u| u.github_login.clone());
793
794 let is_signed_in = user.is_some();
795
796 let has_subscription_period = user_store.subscription_period().is_some();
797 let plan = user_store.plan().filter(|_| {
798 // Since the user might be on the legacy free plan we filter based on whether we have a subscription period.
799 has_subscription_period
800 });
801
802 let free_chip_bg = cx
803 .theme()
804 .colors()
805 .editor_background
806 .opacity(0.5)
807 .blend(cx.theme().colors().text_accent.opacity(0.05));
808
809 let pro_chip_bg = cx
810 .theme()
811 .colors()
812 .editor_background
813 .opacity(0.5)
814 .blend(cx.theme().colors().text_accent.opacity(0.2));
815
816 PopoverMenu::new("user-menu")
817 .anchor(Corner::TopRight)
818 .menu(move |window, cx| {
819 ContextMenu::build(window, cx, |menu, _, _cx| {
820 let user_login = user_login.clone();
821
822 let (plan_name, label_color, bg_color) = match plan {
823 None | Some(Plan::V1(PlanV1::ZedFree) | Plan::V2(PlanV2::ZedFree)) => {
824 ("Free", Color::Default, free_chip_bg)
825 }
826 Some(Plan::V1(PlanV1::ZedProTrial) | Plan::V2(PlanV2::ZedProTrial)) => {
827 ("Pro Trial", Color::Accent, pro_chip_bg)
828 }
829 Some(Plan::V1(PlanV1::ZedPro) | Plan::V2(PlanV2::ZedPro)) => {
830 ("Pro", Color::Accent, pro_chip_bg)
831 }
832 };
833
834 menu.when(is_signed_in, |this| {
835 this.custom_entry(
836 move |_window, _cx| {
837 let user_login = user_login.clone().unwrap_or_default();
838
839 h_flex()
840 .w_full()
841 .justify_between()
842 .child(Label::new(user_login))
843 .child(
844 Chip::new(plan_name.to_string())
845 .bg_color(bg_color)
846 .label_color(label_color),
847 )
848 .into_any_element()
849 },
850 move |_, cx| {
851 cx.open_url(&zed_urls::account_url(cx));
852 },
853 )
854 .separator()
855 })
856 .action("Settings", zed_actions::OpenSettings.boxed_clone())
857 .action("Keymap", Box::new(zed_actions::OpenKeymap))
858 .action(
859 "Themes…",
860 zed_actions::theme_selector::Toggle::default().boxed_clone(),
861 )
862 .action(
863 "Icon Themes…",
864 zed_actions::icon_theme_selector::Toggle::default().boxed_clone(),
865 )
866 .action(
867 "Extensions",
868 zed_actions::Extensions::default().boxed_clone(),
869 )
870 .when(is_signed_in, |this| {
871 this.separator()
872 .action("Sign Out", client::SignOut.boxed_clone())
873 })
874 })
875 .into()
876 })
877 .map(|this| {
878 if is_signed_in && TitleBarSettings::get_global(cx).show_user_picture {
879 this.trigger_with_tooltip(
880 ButtonLike::new("user-menu")
881 .children(user_avatar.clone().map(|avatar| Avatar::new(avatar))),
882 Tooltip::text("Toggle User Menu"),
883 )
884 } else {
885 this.trigger_with_tooltip(
886 IconButton::new("user-menu", IconName::ChevronDown)
887 .icon_size(IconSize::Small),
888 Tooltip::text("Toggle User Menu"),
889 )
890 }
891 })
892 .anchor(gpui::Corner::TopRight)
893 }
894}