From f0d979576da71d3e81706d57ec0ebab650987473 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Sat, 1 Jun 2024 18:40:25 +0200 Subject: [PATCH] collab_ui: remove branch menu popover in favor of opening a modal (#12562) This commit also removes a bunch of dead code. Fixes #12544 Release Notes: - Removed branch popover menu - clicking on the branch name in left-hand corner now always opens a branch modal --- crates/collab_ui/src/collab_titlebar_item.rs | 49 ++++++++----------- crates/recent_projects/src/recent_projects.rs | 10 ---- crates/vcs_menu/src/lib.rs | 14 +----- 3 files changed, 22 insertions(+), 51 deletions(-) diff --git a/crates/collab_ui/src/collab_titlebar_item.rs b/crates/collab_ui/src/collab_titlebar_item.rs index 2e7bc13c11..4f72c4abe2 100644 --- a/crates/collab_ui/src/collab_titlebar_item.rs +++ b/crates/collab_ui/src/collab_titlebar_item.rs @@ -5,7 +5,7 @@ use client::{proto::PeerId, Client, User, UserStore}; use gpui::{ actions, canvas, div, point, px, Action, AnyElement, AppContext, Element, Hsla, InteractiveElement, IntoElement, Model, ParentElement, Path, Render, - StatefulInteractiveElement, Styled, Subscription, View, ViewContext, VisualContext, WeakView, + StatefulInteractiveElement, Styled, Subscription, ViewContext, VisualContext, WeakView, }; use project::{Project, RepositoryEntry}; use recent_projects::RecentProjects; @@ -17,7 +17,7 @@ use ui::{ ButtonStyle, ContextMenu, Icon, IconButton, IconName, Indicator, TintColor, TitleBar, Tooltip, }; use util::ResultExt; -use vcs_menu::{build_branch_list, BranchList, OpenRecent as ToggleVcsMenu}; +use vcs_menu::{BranchList, OpenRecent as ToggleVcsMenu}; use workspace::{notifications::NotifyResultExt, Workspace}; const MAX_PROJECT_NAME_LENGTH: usize = 40; @@ -487,7 +487,7 @@ impl CollabTitlebarItem { })) } - pub fn render_project_branch(&self, cx: &mut ViewContext) -> Option { + pub fn render_project_branch(&self, cx: &mut ViewContext) -> Option { let entry = { let mut names_and_branches = self.project.read(cx).visible_worktrees(cx).map(|worktree| { @@ -503,22 +503,23 @@ impl CollabTitlebarItem { .and_then(RepositoryEntry::branch) .map(|branch| util::truncate_and_trailoff(&branch, MAX_BRANCH_NAME_LENGTH))?; Some( - popover_menu("project_branch_trigger") - .trigger( - Button::new("project_branch_trigger", branch_name) - .color(Color::Muted) - .style(ButtonStyle::Subtle) - .label_size(LabelSize::Small) - .tooltip(move |cx| { - Tooltip::with_meta( - "Recent Branches", - Some(&ToggleVcsMenu), - "Local branches only", - cx, - ) - }), - ) - .menu(move |cx| Self::render_vcs_popover(workspace.clone(), cx)), + Button::new("project_branch_trigger", branch_name) + .color(Color::Muted) + .style(ButtonStyle::Subtle) + .label_size(LabelSize::Small) + .tooltip(move |cx| { + Tooltip::with_meta( + "Recent Branches", + Some(&ToggleVcsMenu), + "Local branches only", + cx, + ) + }) + .on_click(move |_, cx| { + let _ = workspace.update(cx, |this, cx| { + BranchList::open(this, &Default::default(), cx) + }); + }), ) } @@ -650,16 +651,6 @@ impl CollabTitlebarItem { .log_err(); } - pub fn render_vcs_popover( - workspace: View, - cx: &mut WindowContext<'_>, - ) -> Option> { - let view = build_branch_list(workspace, cx).log_err()?; - let focus_handle = view.focus_handle(cx); - cx.focus(&focus_handle); - Some(view) - } - fn render_connection_status( &self, status: &client::Status, diff --git a/crates/recent_projects/src/recent_projects.rs b/crates/recent_projects/src/recent_projects.rs index 880defbf70..5e6a2bca24 100644 --- a/crates/recent_projects/src/recent_projects.rs +++ b/crates/recent_projects/src/recent_projects.rs @@ -118,16 +118,6 @@ impl RecentProjects { modal }) } - - pub fn open_popover(workspace: WeakView, cx: &mut WindowContext<'_>) -> View { - cx.new_view(|cx| { - Self::new( - RecentProjectsDelegate::new(workspace, false, false), - 20., - cx, - ) - }) - } } impl EventEmitter for RecentProjects {} diff --git a/crates/vcs_menu/src/lib.rs b/crates/vcs_menu/src/lib.rs index 5f06305a74..af8a7736ff 100644 --- a/crates/vcs_menu/src/lib.rs +++ b/crates/vcs_menu/src/lib.rs @@ -21,7 +21,7 @@ actions!(branches, [OpenRecent]); pub fn init(cx: &mut AppContext) { cx.observe_new_views(|workspace: &mut Workspace, _| { workspace.register_action(|workspace, action, cx| { - BranchList::toggle_modal(workspace, action, cx).log_err(); + BranchList::open(workspace, action, cx).log_err(); }); }) .detach(); @@ -43,7 +43,7 @@ impl BranchList { _subscription, } } - fn toggle_modal( + pub fn open( workspace: &mut Workspace, _: &OpenRecent, cx: &mut ViewContext, @@ -77,16 +77,6 @@ impl Render for BranchList { } } -pub fn build_branch_list( - workspace: View, - cx: &mut WindowContext<'_>, -) -> Result> { - let delegate = workspace.update(cx, |workspace, cx| { - BranchListDelegate::new(workspace, cx.view().clone(), 29, cx) - })?; - Ok(cx.new_view(move |cx| BranchList::new(delegate, 20., cx))) -} - pub struct BranchListDelegate { matches: Vec, all_branches: Vec,