| @@ -1,10 +1,11 @@ |
| 1 | 1 | use crate::face_pile::FacePile; |
| 2 | +use auto_update::AutoUpdateStatus; |
| 2 | 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 | 5 | use gpui::{ |
| 5 | | − actions, canvas, div, overlay, point, px, rems, Action, AppContext, DismissEvent, Div, Element, |
| 6 | | − FocusableView, Hsla, InteractiveElement, IntoElement, Model, ParentElement, Path, Render, |
| 7 | | − Stateful, StatefulInteractiveElement, Styled, Subscription, ViewContext, VisualContext, |
| 6 | + actions, canvas, div, overlay, point, px, rems, Action, AnyElement, AppContext, DismissEvent, |
| 7 | + Div, Element, FocusableView, Hsla, InteractiveElement, IntoElement, Model, ParentElement, Path, |
| 8 | + Render, Stateful, StatefulInteractiveElement, Styled, Subscription, ViewContext, VisualContext, |
| 8 | 9 | WeakView, WindowBounds, |
| 9 | 10 | }; |
| 10 | 11 | use project::{Project, RepositoryEntry}; |
| @@ -16,7 +17,7 @@ use ui::{ · 5 unmodified lines |
| 16 | 17 | IconButton, IconElement, KeyBinding, Tooltip, |
| 17 | 18 | }; |
| 18 | 19 | use util::ResultExt; |
| 19 | | −use workspace::{notifications::NotifyResultExt, Feedback, Workspace, WORKSPACE_DB}; |
| 20 | +use workspace::{notifications::NotifyResultExt, Workspace, WORKSPACE_DB}; |
| 20 | 21 | |
| 21 | 22 | const MAX_PROJECT_NAME_LENGTH: usize = 40; |
| 22 | 23 | const MAX_BRANCH_NAME_LENGTH: usize = 40; |
| @@ -52,7 +53,6 @@ pub struct CollabTitlebarItem { · 29 unmodified lines |
| 52 | 53 | workspace: WeakView<Workspace>, |
| 53 | 54 | //branch_popover: Option<ViewHandle<BranchList>>, |
| 54 | 55 | project_popover: Option<recent_projects::RecentProjects>, |
| 55 | | − //user_menu: ViewHandle<ContextMenu>, |
| 56 | 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| { |
| 236 | | − if let Some(user) = current_user { |
| 237 | | − // TODO: Finish implementing user menu popover |
| 238 | | − // |
| 239 | | − this.child( |
| 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 | | − ) |
| 235 | + .map(|el| { |
| 236 | + let status = self.client.status(); |
| 237 | + let status = &*status.borrow(); |
| 238 | + if matches!(status, client::Status::Connected { .. }) { |
| 239 | + el.child(self.render_user_menu_button(cx)) |
| 274 | 240 | } else { |
| 275 | | − this.child(Button::new("sign_in", "Sign in").on_click(move |_, cx| { |
| 276 | | − let client = client.clone(); |
| 277 | | − cx.spawn(move |mut cx| async move { |
| 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 | | − ) |
| 241 | + el.children(self.render_connection_status(status, cx)) |
| 242 | + .child(self.render_sign_in_button(cx)) |
| 243 | + .child(self.render_user_menu_button(cx)) |
| 315 | 244 | } |
| 316 | | − })), |
| 245 | + }), |
| 317 | 246 | ) |
| 318 | 247 | } |
| 319 | 248 | } |
| @@ -355,12 +284,6 @@ impl CollabTitlebarItem { · 35 unmodified lines |
| 355 | 284 | project, |
| 356 | 285 | user_store, |
| 357 | 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 | 287 | // branch_popover: None, |
| 365 | 288 | project_popover: None, |
| 366 | 289 | _subscriptions: subscriptions, |
| @@ -535,34 +458,6 @@ impl CollabTitlebarItem { · 168 unmodified lines |
| 535 | 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 | 461 | // fn render_branches_popover_host<'a>( |
| 567 | 462 | // &'a self, |
| 568 | 463 | // _theme: &'a theme::Titlebar, |
| @@ -696,154 +591,113 @@ impl CollabTitlebarItem { · 127 unmodified lines |
| 696 | 591 | cx.notify(); |
| 697 | 592 | } |
| 698 | 593 | |
| 699 | | − // fn render_user_menu_button( |
| 700 | | − // &self, |
| 701 | | − // theme: &Theme, |
| 702 | | − // avatar: Option<Arc<ImageData>>, |
| 703 | | − // cx: &mut ViewContext<Self>, |
| 704 | | − // ) -> AnyElement<Self> { |
| 705 | | − // let tooltip = theme.tooltip.clone(); |
| 706 | | − // let user_menu_button_style = if avatar.is_some() { |
| 707 | | − // &theme.titlebar.user_menu.user_menu_button_online |
| 708 | | − // } else { |
| 709 | | − // &theme.titlebar.user_menu.user_menu_button_offline |
| 710 | | − // }; |
| 711 | | − |
| 712 | | − // let avatar_style = &user_menu_button_style.avatar; |
| 713 | | − // Stack::new() |
| 714 | | − // .with_child( |
| 715 | | − // MouseEventHandler::new::<ToggleUserMenu, _>(0, cx, |state, _| { |
| 716 | | − // let style = user_menu_button_style |
| 717 | | − // .user_menu |
| 718 | | − // .inactive_state() |
| 719 | | − // .style_for(state); |
| 720 | | − |
| 721 | | − // let mut dropdown = Flex::row().align_children_center(); |
| 722 | | − |
| 723 | | − // if let Some(avatar_img) = avatar { |
| 724 | | − // dropdown = dropdown.with_child(Self::render_face( |
| 725 | | − // avatar_img, |
| 726 | | − // *avatar_style, |
| 727 | | − // Color::transparent_black(), |
| 728 | | − // None, |
| 729 | | − // )); |
| 730 | | − // }; |
| 731 | | − |
| 732 | | − // dropdown |
| 733 | | − // .with_child( |
| 734 | | − // Svg::new("icons/caret_down.svg") |
| 735 | | − // .with_color(user_menu_button_style.icon.color) |
| 736 | | − // .constrained() |
| 737 | | − // .with_width(user_menu_button_style.icon.width) |
| 738 | | − // .contained() |
| 739 | | − // .into_any(), |
| 740 | | − // ) |
| 741 | | − // .aligned() |
| 742 | | − // .constrained() |
| 743 | | − // .with_height(style.width) |
| 744 | | − // .contained() |
| 745 | | − // .with_style(style.container) |
| 746 | | − // .into_any() |
| 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 | | − // } |
| 594 | + fn render_connection_status( |
| 595 | + &self, |
| 596 | + status: &client::Status, |
| 597 | + cx: &mut ViewContext<Self>, |
| 598 | + ) -> Option<AnyElement> { |
| 599 | + match status { |
| 600 | + client::Status::ConnectionError |
| 601 | + | client::Status::ConnectionLost |
| 602 | + | client::Status::Reauthenticating { .. } |
| 603 | + | client::Status::Reconnecting { .. } |
| 604 | + | client::Status::ReconnectionError { .. } => Some( |
| 605 | + div() |
| 606 | + .id("disconnected") |
| 607 | + .bg(gpui::red()) // todo!() @nate |
| 608 | + .child(IconElement::new(Icon::Disconnected)) |
| 609 | + .tooltip(|cx| Tooltip::text("Disconnected", cx)) |
| 610 | + .into_any_element(), |
| 611 | + ), |
| 612 | + client::Status::UpgradeRequired => { |
| 613 | + let auto_updater = auto_update::AutoUpdater::get(cx); |
| 614 | + let label = match auto_updater.map(|auto_update| auto_update.read(cx).status()) { |
| 615 | + Some(AutoUpdateStatus::Updated) => "Please restart Zed to Collaborate", |
| 616 | + Some(AutoUpdateStatus::Installing) |
| 617 | + | Some(AutoUpdateStatus::Downloading) |
| 618 | + | Some(AutoUpdateStatus::Checking) => "Updating...", |
| 619 | + Some(AutoUpdateStatus::Idle) | Some(AutoUpdateStatus::Errored) | None => { |
| 620 | + "Please update Zed to Collaborate" |
| 621 | + } |
| 622 | + }; |
| 623 | + |
| 624 | + Some( |
| 625 | + div() |
| 626 | + .bg(gpui::red()) // todo!() @nate |
| 627 | + .child(Button::new("connection-status", label).on_click(|_, cx| { |
| 628 | + if let Some(auto_updater) = auto_update::AutoUpdater::get(cx) { |
| 629 | + if auto_updater.read(cx).status() == AutoUpdateStatus::Updated { |
| 630 | + workspace::restart(&Default::default(), cx); |
| 631 | + return; |
| 632 | + } |
| 633 | + } |
| 634 | + auto_update::check(&Default::default(), cx); |
| 635 | + })) |
| 636 | + .into_any_element(), |
| 637 | + ) |
| 638 | + } |
| 639 | + _ => None, |
| 640 | + } |
| 641 | + } |
| 790 | 642 | |
| 791 | | − // fn render_connection_status( |
| 792 | | − // &self, |
| 793 | | − // status: &client::Status, |
| 794 | | − // cx: &mut ViewContext<Self>, |
| 795 | | − // ) -> Option<AnyElement<Self>> { |
| 796 | | − // enum ConnectionStatusButton {} |
| 797 | | − |
| 798 | | − // let theme = &theme::current(cx).clone(); |
| 799 | | − // match status { |
| 800 | | − // client::Status::ConnectionError |
| 801 | | − // | client::Status::ConnectionLost |
| 802 | | − // | client::Status::Reauthenticating { .. } |
| 803 | | − // | client::Status::Reconnecting { .. } |
| 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 | | − // }; |
| 643 | + pub fn render_sign_in_button(&mut self, _: &mut ViewContext<Self>) -> Button { |
| 644 | + let client = self.client.clone(); |
| 645 | + Button::new("sign_in", "Sign in").on_click(move |_, cx| { |
| 646 | + let client = client.clone(); |
| 647 | + cx.spawn(move |mut cx| async move { |
| 648 | + client |
| 649 | + .authenticate_and_connect(true, &cx) |
| 650 | + .await |
| 651 | + .notify_async_err(&mut cx); |
| 652 | + }) |
| 653 | + .detach(); |
| 654 | + }) |
| 655 | + } |
| 825 | 656 | |
| 826 | | − // Some( |
| 827 | | − // MouseEventHandler::new::<ConnectionStatusButton, _>(0, cx, |_, _| { |
| 828 | | − // Label::new(label, theme.titlebar.outdated_warning.text.clone()) |
| 829 | | − // .contained() |
| 830 | | − // .with_style(theme.titlebar.outdated_warning.container) |
| 831 | | − // .aligned() |
| 832 | | − // }) |
| 833 | | − // .with_cursor_style(CursorStyle::PointingHand) |
| 834 | | − // .on_click(MouseButton::Left, |_, _, cx| { |
| 835 | | − // if let Some(auto_updater) = auto_update::AutoUpdater::get(cx) { |
| 836 | | − // if auto_updater.read(cx).status() == AutoUpdateStatus::Updated { |
| 837 | | − // workspace::restart(&Default::default(), cx); |
| 838 | | − // return; |
| 839 | | − // } |
| 840 | | − // } |
| 841 | | − // auto_update::check(&Default::default(), cx); |
| 842 | | − // }) |
| 843 | | − // .into_any(), |
| 844 | | − // ) |
| 845 | | − // } |
| 846 | | − // _ => None, |
| 847 | | − // } |
| 848 | | − // } |
| 657 | + pub fn render_user_menu_button(&mut self, cx: &mut ViewContext<Self>) -> impl Element { |
| 658 | + if let Some(user) = self.user_store.read(cx).current_user() { |
| 659 | + popover_menu("user-menu") |
| 660 | + .menu(|cx| { |
| 661 | + ContextMenu::build(cx, |menu, _| { |
| 662 | + menu.action("Settings", zed_actions::OpenSettings.boxed_clone()) |
| 663 | + .action("Theme", theme_selector::Toggle.boxed_clone()) |
| 664 | + .separator() |
| 665 | + .action("Share Feedback", feedback::GiveFeedback.boxed_clone()) |
| 666 | + .action("Sign Out", client::SignOut.boxed_clone()) |
| 667 | + }) |
| 668 | + }) |
| 669 | + .trigger( |
| 670 | + ButtonLike::new("user-menu") |
| 671 | + .child( |
| 672 | + h_stack() |
| 673 | + .gap_0p5() |
| 674 | + .child(Avatar::new(user.avatar_uri.clone())) |
| 675 | + .child(IconElement::new(Icon::ChevronDown).color(Color::Muted)), |
| 676 | + ) |
| 677 | + .style(ButtonStyle::Subtle) |
| 678 | + .tooltip(move |cx| Tooltip::text("Toggle User Menu", cx)), |
| 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 | } |