| @@ -1,10 +1,11 @@ |
| 1 | use crate::face_pile::FacePile; | 1 | use crate::face_pile::FacePile; |
| | 2 | use auto_update::AutoUpdateStatus; |
| 2 | use call::{ActiveCall, ParticipantLocation, Room}; | 3 | use call::{ActiveCall, ParticipantLocation, Room}; |
| 3 | use client::{proto::PeerId, Client, ParticipantIndex, SignOut, User, UserStore}; | 4 | use client::{proto::PeerId, Client, ParticipantIndex, User, UserStore}; |
| 4 | use gpui::{ | 5 | use gpui::{ |
| 5 | actions, canvas, div, overlay, point, px, rems, Action, AppContext, DismissEvent, Div, Element, | 6 | actions, canvas, div, overlay, point, px, rems, Action, AnyElement, AppContext, DismissEvent, |
| 6 | FocusableView, Hsla, InteractiveElement, IntoElement, Model, ParentElement, Path, Render, | 7 | Div, Element, FocusableView, Hsla, InteractiveElement, IntoElement, Model, ParentElement, Path, |
| 7 | Stateful, StatefulInteractiveElement, Styled, Subscription, ViewContext, VisualContext, | 8 | Render, Stateful, StatefulInteractiveElement, Styled, Subscription, ViewContext, VisualContext, |
| 8 | WeakView, WindowBounds, | 9 | WeakView, WindowBounds, |
| 9 | }; | 10 | }; |
| 10 | use project::{Project, RepositoryEntry}; | 11 | use project::{Project, RepositoryEntry}; |
| @@ -16,7 +17,7 @@ use ui::{ · 5 unmodified lines |
| 16 | IconButton, IconElement, KeyBinding, Tooltip, | 17 | IconButton, IconElement, KeyBinding, Tooltip, |
| 17 | }; | 18 | }; |
| 18 | use util::ResultExt; | 19 | use util::ResultExt; |
| 19 | use workspace::{notifications::NotifyResultExt, Feedback, Workspace, WORKSPACE_DB}; | 20 | use workspace::{notifications::NotifyResultExt, Workspace, WORKSPACE_DB}; |
| 20 | | 21 | |
| 21 | const MAX_PROJECT_NAME_LENGTH: usize = 40; | 22 | const MAX_PROJECT_NAME_LENGTH: usize = 40; |
| 22 | const MAX_BRANCH_NAME_LENGTH: usize = 40; | 23 | const MAX_BRANCH_NAME_LENGTH: usize = 40; |
| @@ -52,7 +53,6 @@ pub struct CollabTitlebarItem { · 29 unmodified lines |
| 52 | workspace: WeakView<Workspace>, | 53 | workspace: WeakView<Workspace>, |
| 53 | //branch_popover: Option<ViewHandle<BranchList>>, | 54 | //branch_popover: Option<ViewHandle<BranchList>>, |
| 54 | project_popover: Option<recent_projects::RecentProjects>, | 55 | project_popover: Option<recent_projects::RecentProjects>, |
| 55 | //user_menu: ViewHandle<ContextMenu>, | | |
| 56 | _subscriptions: Vec<Subscription>, | 56 | _subscriptions: Vec<Subscription>, |
| 57 | } | 57 | } |
| 58 | | 58 | |
| @@ -232,88 +232,17 @@ impl Render for CollabTitlebarItem { · 173 unmodified lines |
| 232 | }), | 232 | }), |
| 233 | ) | 233 | ) |
| 234 | }) | 234 | }) |
| 235 | .child(h_stack().px_1p5().map(|this| { | 235 | .map(|el| { |
| 236 | if let Some(user) = current_user { | 236 | let status = self.client.status(); |
| 237 | // TODO: Finish implementing user menu popover | 237 | let status = &*status.borrow(); |
| 238 | // | 238 | if matches!(status, client::Status::Connected { .. }) { |
| 239 | this.child( | 239 | el.child(self.render_user_menu_button(cx)) |
| 240 | popover_menu("user-menu") | | |
| 241 | .menu(|cx| { | | |
| 242 | ContextMenu::build(cx, |menu, _| { | | |
| 243 | menu.action( | | |
| 244 | "Settings", | | |
| 245 | zed_actions::OpenSettings.boxed_clone(), | | |
| 246 | ) | | |
| 247 | .action("Theme", theme_selector::Toggle.boxed_clone()) | | |
| 248 | .separator() | | |
| 249 | .action( | | |
| 250 | "Share Feedback", | | |
| 251 | feedback::GiveFeedback.boxed_clone(), | | |
| 252 | ) | | |
| 253 | .action("Sign Out", client::SignOut.boxed_clone()) | | |
| 254 | }) | | |
| 255 | }) | | |
| 256 | .trigger( | | |
| 257 | ButtonLike::new("user-menu") | | |
| 258 | .child( | | |
| 259 | h_stack() | | |
| 260 | .gap_0p5() | | |
| 261 | .child(Avatar::new(user.avatar_uri.clone())) | | |
| 262 | .child( | | |
| 263 | IconElement::new(Icon::ChevronDown) | | |
| 264 | .color(Color::Muted), | | |
| 265 | ), | | |
| 266 | ) | | |
| 267 | .style(ButtonStyle::Subtle) | | |
| 268 | .tooltip(move |cx| { | | |
| 269 | Tooltip::text("Toggle User Menu", cx) | | |
| 270 | }), | | |
| 271 | ) | | |
| 272 | .anchor(gpui::AnchorCorner::TopRight), | | |
| 273 | ) | | |
| 274 | } else { | 240 | } else { |
| 275 | this.child(Button::new("sign_in", "Sign in").on_click(move |_, cx| { | 241 | el.children(self.render_connection_status(status, cx)) |
| 276 | let client = client.clone(); | 242 | .child(self.render_sign_in_button(cx)) |
| 277 | cx.spawn(move |mut cx| async move { | 243 | .child(self.render_user_menu_button(cx)) |
| 278 | client | | |
| 279 | .authenticate_and_connect(true, &cx) | | |
| 280 | .await | | |
| 281 | .notify_async_err(&mut cx); | | |
| 282 | }) | | |
| 283 | .detach(); | | |
| 284 | })) | | |
| 285 | .child( | | |
| 286 | popover_menu("user-menu") | | |
| 287 | .menu(|cx| { | | |
| 288 | ContextMenu::build(cx, |menu, _| { | | |
| 289 | menu.action( | | |
| 290 | "Settings", | | |
| 291 | zed_actions::OpenSettings.boxed_clone(), | | |
| 292 | ) | | |
| 293 | .action("Theme", theme_selector::Toggle.boxed_clone()) | | |
| 294 | .separator() | | |
| 295 | .action( | | |
| 296 | "Share Feedback", | | |
| 297 | feedback::GiveFeedback.boxed_clone(), | | |
| 298 | ) | | |
| 299 | }) | | |
| 300 | }) | | |
| 301 | .trigger( | | |
| 302 | ButtonLike::new("user-menu") | | |
| 303 | .child( | | |
| 304 | h_stack().gap_0p5().child( | | |
| 305 | IconElement::new(Icon::ChevronDown) | | |
| 306 | .color(Color::Muted), | | |
| 307 | ), | | |
| 308 | ) | | |
| 309 | .style(ButtonStyle::Subtle) | | |
| 310 | .tooltip(move |cx| { | | |
| 311 | Tooltip::text("Toggle User Menu", cx) | | |
| 312 | }), | | |
| 313 | ), | | |
| 314 | ) | | |
| 315 | } | 244 | } |
| 316 | })), | 245 | }), |
| 317 | ) | 246 | ) |
| 318 | } | 247 | } |
| 319 | } | 248 | } |
| @@ -355,12 +284,6 @@ impl CollabTitlebarItem { · 35 unmodified lines |
| 355 | project, | 284 | project, |
| 356 | user_store, | 285 | user_store, |
| 357 | client, | 286 | client, |
| 358 | // user_menu: cx.add_view(|cx| { | | |
| 359 | // let view_id = cx.view_id(); | | |
| 360 | // let mut menu = ContextMenu::new(view_id, cx); | | |
| 361 | // menu.set_position_mode(OverlayPositionMode::Local); | | |
| 362 | // menu | | |
| 363 | // }), | | |
| 364 | // branch_popover: None, | 287 | // branch_popover: None, |
| 365 | project_popover: None, | 288 | project_popover: None, |
| 366 | _subscriptions: subscriptions, | 289 | _subscriptions: subscriptions, |
| @@ -535,34 +458,6 @@ impl CollabTitlebarItem { · 168 unmodified lines |
| 535 | .log_err(); | 458 | .log_err(); |
| 536 | } | 459 | } |
| 537 | | 460 | |
| 538 | // pub fn toggle_user_menu(&mut self, _: &ToggleUserMenu, cx: &mut ViewContext<Self>) { | | |
| 539 | // self.user_menu.update(cx, |user_menu, cx| { | | |
| 540 | // let items = if let Some(_) = self.user_store.read(cx).current_user() { | | |
| 541 | // vec![ | | |
| 542 | // ContextMenuItem::action("Settings", zed_actions::OpenSettings), | | |
| 543 | // ContextMenuItem::action("Theme", theme_selector::Toggle), | | |
| 544 | // ContextMenuItem::separator(), | | |
| 545 | // ContextMenuItem::action( | | |
| 546 | // "Share Feedback", | | |
| 547 | // feedback::feedback_editor::GiveFeedback, | | |
| 548 | // ), | | |
| 549 | // ContextMenuItem::action("Sign Out", SignOut), | | |
| 550 | // ] | | |
| 551 | // } else { | | |
| 552 | // vec![ | | |
| 553 | // ContextMenuItem::action("Settings", zed_actions::OpenSettings), | | |
| 554 | // ContextMenuItem::action("Theme", theme_selector::Toggle), | | |
| 555 | // ContextMenuItem::separator(), | | |
| 556 | // ContextMenuItem::action( | | |
| 557 | // "Share Feedback", | | |
| 558 | // feedback::feedback_editor::GiveFeedback, | | |
| 559 | // ), | | |
| 560 | // ] | | |
| 561 | // }; | | |
| 562 | // user_menu.toggle(Default::default(), AnchorCorner::TopRight, items, cx); | | |
| 563 | // }); | | |
| 564 | // } | | |
| 565 | | | |
| 566 | // fn render_branches_popover_host<'a>( | 461 | // fn render_branches_popover_host<'a>( |
| 567 | // &'a self, | 462 | // &'a self, |
| 568 | // _theme: &'a theme::Titlebar, | 463 | // _theme: &'a theme::Titlebar, |
| @@ -696,154 +591,113 @@ impl CollabTitlebarItem { · 127 unmodified lines |
| 696 | cx.notify(); | 591 | cx.notify(); |
| 697 | } | 592 | } |
| 698 | | 593 | |
| 699 | // fn render_user_menu_button( | 594 | fn render_connection_status( |
| 700 | // &self, | 595 | &self, |
| 701 | // theme: &Theme, | 596 | status: &client::Status, |
| 702 | // avatar: Option<Arc<ImageData>>, | 597 | cx: &mut ViewContext<Self>, |
| 703 | // cx: &mut ViewContext<Self>, | 598 | ) -> Option<AnyElement> { |
| 704 | // ) -> AnyElement<Self> { | 599 | match status { |
| 705 | // let tooltip = theme.tooltip.clone(); | 600 | client::Status::ConnectionError |
| 706 | // let user_menu_button_style = if avatar.is_some() { | 601 | | client::Status::ConnectionLost |
| 707 | // &theme.titlebar.user_menu.user_menu_button_online | 602 | | client::Status::Reauthenticating { .. } |
| 708 | // } else { | 603 | | client::Status::Reconnecting { .. } |
| 709 | // &theme.titlebar.user_menu.user_menu_button_offline | 604 | | client::Status::ReconnectionError { .. } => Some( |
| 710 | // }; | 605 | div() |
| 711 | | 606 | .id("disconnected") |
| 712 | // let avatar_style = &user_menu_button_style.avatar; | 607 | .bg(gpui::red()) // todo!() @nate |
| 713 | // Stack::new() | 608 | .child(IconElement::new(Icon::Disconnected)) |
| 714 | // .with_child( | 609 | .tooltip(|cx| Tooltip::text("Disconnected", cx)) |
| 715 | // MouseEventHandler::new::<ToggleUserMenu, _>(0, cx, |state, _| { | 610 | .into_any_element(), |
| 716 | // let style = user_menu_button_style | 611 | ), |
| 717 | // .user_menu | 612 | client::Status::UpgradeRequired => { |
| 718 | // .inactive_state() | 613 | let auto_updater = auto_update::AutoUpdater::get(cx); |
| 719 | // .style_for(state); | 614 | let label = match auto_updater.map(|auto_update| auto_update.read(cx).status()) { |
| 720 | | 615 | Some(AutoUpdateStatus::Updated) => "Please restart Zed to Collaborate", |
| 721 | // let mut dropdown = Flex::row().align_children_center(); | 616 | Some(AutoUpdateStatus::Installing) |
| 722 | | 617 | | Some(AutoUpdateStatus::Downloading) |
| 723 | // if let Some(avatar_img) = avatar { | 618 | | Some(AutoUpdateStatus::Checking) => "Updating...", |
| 724 | // dropdown = dropdown.with_child(Self::render_face( | 619 | Some(AutoUpdateStatus::Idle) | Some(AutoUpdateStatus::Errored) | None => { |
| 725 | // avatar_img, | 620 | "Please update Zed to Collaborate" |
| 726 | // *avatar_style, | 621 | } |
| 727 | // Color::transparent_black(), | 622 | }; |
| 728 | // None, | 623 | |
| 729 | // )); | 624 | Some( |
| 730 | // }; | 625 | div() |
| 731 | | 626 | .bg(gpui::red()) // todo!() @nate |
| 732 | // dropdown | 627 | .child(Button::new("connection-status", label).on_click(|_, cx| { |
| 733 | // .with_child( | 628 | if let Some(auto_updater) = auto_update::AutoUpdater::get(cx) { |
| 734 | // Svg::new("icons/caret_down.svg") | 629 | if auto_updater.read(cx).status() == AutoUpdateStatus::Updated { |
| 735 | // .with_color(user_menu_button_style.icon.color) | 630 | workspace::restart(&Default::default(), cx); |
| 736 | // .constrained() | 631 | return; |
| 737 | // .with_width(user_menu_button_style.icon.width) | 632 | } |
| 738 | // .contained() | 633 | } |
| 739 | // .into_any(), | 634 | auto_update::check(&Default::default(), cx); |
| 740 | // ) | 635 | })) |
| 741 | // .aligned() | 636 | .into_any_element(), |
| 742 | // .constrained() | 637 | ) |
| 743 | // .with_height(style.width) | 638 | } |
| 744 | // .contained() | 639 | _ => None, |
| 745 | // .with_style(style.container) | 640 | } |
| 746 | // .into_any() | 641 | } |
| 747 | // }) | | |
| 748 | // .with_cursor_style(CursorStyle::PointingHand) | | |
| 749 | // .on_down(MouseButton::Left, move |_, this, cx| { | | |
| 750 | // this.user_menu.update(cx, |menu, _| menu.delay_cancel()); | | |
| 751 | // }) | | |
| 752 | // .on_click(MouseButton::Left, move |_, this, cx| { | | |
| 753 | // this.toggle_user_menu(&Default::default(), cx) | | |
| 754 | // }) | | |
| 755 | // .with_tooltip::<ToggleUserMenu>( | | |
| 756 | // 0, | | |
| 757 | // "Toggle User Menu".to_owned(), | | |
| 758 | // Some(Box::new(ToggleUserMenu)), | | |
| 759 | // tooltip, | | |
| 760 | // cx, | | |
| 761 | // ) | | |
| 762 | // .contained(), | | |
| 763 | // ) | | |
| 764 | // .with_child( | | |
| 765 | // ChildView::new(&self.user_menu, cx) | | |
| 766 | // .aligned() | | |
| 767 | // .bottom() | | |
| 768 | // .right(), | | |
| 769 | // ) | | |
| 770 | // .into_any() | | |
| 771 | // } | | |
| 772 | | | |
| 773 | // fn render_sign_in_button(&self, theme: &Theme, cx: &mut ViewContext<Self>) -> AnyElement<Self> { | | |
| 774 | // let titlebar = &theme.titlebar; | | |
| 775 | // MouseEventHandler::new::<SignIn, _>(0, cx, |state, _| { | | |
| 776 | // let style = titlebar.sign_in_button.inactive_state().style_for(state); | | |
| 777 | // Label::new("Sign In", style.text.clone()) | | |
| 778 | // .contained() | | |
| 779 | // .with_style(style.container) | | |
| 780 | // }) | | |
| 781 | // .with_cursor_style(CursorStyle::PointingHand) | | |
| 782 | // .on_click(MouseButton::Left, move |_, this, cx| { | | |
| 783 | // let client = this.client.clone(); | | |
| 784 | // cx.app_context() | | |
| 785 | // .spawn(|cx| async move { client.authenticate_and_connect(true, &cx).await }) | | |
| 786 | // .detach_and_log_err(cx); | | |
| 787 | // }) | | |
| 788 | // .into_any() | | |
| 789 | // } | | |
| 790 | | 642 | |
| 791 | // fn render_connection_status( | 643 | pub fn render_sign_in_button(&mut self, _: &mut ViewContext<Self>) -> Button { |
| 792 | // &self, | 644 | let client = self.client.clone(); |
| 793 | // status: &client::Status, | 645 | Button::new("sign_in", "Sign in").on_click(move |_, cx| { |
| 794 | // cx: &mut ViewContext<Self>, | 646 | let client = client.clone(); |
| 795 | // ) -> Option<AnyElement<Self>> { | 647 | cx.spawn(move |mut cx| async move { |
| 796 | // enum ConnectionStatusButton {} | 648 | client |
| 797 | | 649 | .authenticate_and_connect(true, &cx) |
| 798 | // let theme = &theme::current(cx).clone(); | 650 | .await |
| 799 | // match status { | 651 | .notify_async_err(&mut cx); |
| 800 | // client::Status::ConnectionError | 652 | }) |
| 801 | // | client::Status::ConnectionLost | 653 | .detach(); |
| 802 | // | client::Status::Reauthenticating { .. } | 654 | }) |
| 803 | // | client::Status::Reconnecting { .. } | 655 | } |
| 804 | // | client::Status::ReconnectionError { .. } => Some( | | |
| 805 | // Svg::new("icons/disconnected.svg") | | |
| 806 | // .with_color(theme.titlebar.offline_icon.color) | | |
| 807 | // .constrained() | | |
| 808 | // .with_width(theme.titlebar.offline_icon.width) | | |
| 809 | // .aligned() | | |
| 810 | // .contained() | | |
| 811 | // .with_style(theme.titlebar.offline_icon.container) | | |
| 812 | // .into_any(), | | |
| 813 | // ), | | |
| 814 | // client::Status::UpgradeRequired => { | | |
| 815 | // let auto_updater = auto_update::AutoUpdater::get(cx); | | |
| 816 | // let label = match auto_updater.map(|auto_update| auto_update.read(cx).status()) { | | |
| 817 | // Some(AutoUpdateStatus::Updated) => "Please restart Zed to Collaborate", | | |
| 818 | // Some(AutoUpdateStatus::Installing) | | |
| 819 | // | Some(AutoUpdateStatus::Downloading) | | |
| 820 | // | Some(AutoUpdateStatus::Checking) => "Updating...", | | |
| 821 | // Some(AutoUpdateStatus::Idle) | Some(AutoUpdateStatus::Errored) | None => { | | |
| 822 | // "Please update Zed to Collaborate" | | |
| 823 | // } | | |
| 824 | // }; | | |
| 825 | | 656 | |
| 826 | // Some( | 657 | pub fn render_user_menu_button(&mut self, cx: &mut ViewContext<Self>) -> impl Element { |
| 827 | // MouseEventHandler::new::<ConnectionStatusButton, _>(0, cx, |_, _| { | 658 | if let Some(user) = self.user_store.read(cx).current_user() { |
| 828 | // Label::new(label, theme.titlebar.outdated_warning.text.clone()) | 659 | popover_menu("user-menu") |
| 829 | // .contained() | 660 | .menu(|cx| { |
| 830 | // .with_style(theme.titlebar.outdated_warning.container) | 661 | ContextMenu::build(cx, |menu, _| { |
| 831 | // .aligned() | 662 | menu.action("Settings", zed_actions::OpenSettings.boxed_clone()) |
| 832 | // }) | 663 | .action("Theme", theme_selector::Toggle.boxed_clone()) |
| 833 | // .with_cursor_style(CursorStyle::PointingHand) | 664 | .separator() |
| 834 | // .on_click(MouseButton::Left, |_, _, cx| { | 665 | .action("Share Feedback", feedback::GiveFeedback.boxed_clone()) |
| 835 | // if let Some(auto_updater) = auto_update::AutoUpdater::get(cx) { | 666 | .action("Sign Out", client::SignOut.boxed_clone()) |
| 836 | // if auto_updater.read(cx).status() == AutoUpdateStatus::Updated { | 667 | }) |
| 837 | // workspace::restart(&Default::default(), cx); | 668 | }) |
| 838 | // return; | 669 | .trigger( |
| 839 | // } | 670 | ButtonLike::new("user-menu") |
| 840 | // } | 671 | .child( |
| 841 | // auto_update::check(&Default::default(), cx); | 672 | h_stack() |
| 842 | // }) | 673 | .gap_0p5() |
| 843 | // .into_any(), | 674 | .child(Avatar::new(user.avatar_uri.clone())) |
| 844 | // ) | 675 | .child(IconElement::new(Icon::ChevronDown).color(Color::Muted)), |
| 845 | // } | 676 | ) |
| 846 | // _ => None, | 677 | .style(ButtonStyle::Subtle) |
| 847 | // } | 678 | .tooltip(move |cx| Tooltip::text("Toggle User Menu", cx)), |
| 848 | // } | 679 | ) |
| | 680 | .anchor(gpui::AnchorCorner::TopRight) |
| | 681 | } else { |
| | 682 | popover_menu("user-menu") |
| | 683 | .menu(|cx| { |
| | 684 | ContextMenu::build(cx, |menu, _| { |
| | 685 | menu.action("Settings", zed_actions::OpenSettings.boxed_clone()) |
| | 686 | .action("Theme", theme_selector::Toggle.boxed_clone()) |
| | 687 | .separator() |
| | 688 | .action("Share Feedback", feedback::GiveFeedback.boxed_clone()) |
| | 689 | }) |
| | 690 | }) |
| | 691 | .trigger( |
| | 692 | ButtonLike::new("user-menu") |
| | 693 | .child( |
| | 694 | h_stack() |
| | 695 | .gap_0p5() |
| | 696 | .child(IconElement::new(Icon::ChevronDown).color(Color::Muted)), |
| | 697 | ) |
| | 698 | .style(ButtonStyle::Subtle) |
| | 699 | .tooltip(move |cx| Tooltip::text("Toggle User Menu", cx)), |
| | 700 | ) |
| | 701 | } |
| | 702 | } |
| 849 | } | 703 | } |