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
This commit is contained in:
Piotr Osiewicz 2024-06-01 18:40:25 +02:00 committed by GitHub
parent fbcc5ccdb9
commit f0d979576d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 51 deletions

View file

@ -5,7 +5,7 @@ use client::{proto::PeerId, Client, User, UserStore};
use gpui::{ use gpui::{
actions, canvas, div, point, px, Action, AnyElement, AppContext, Element, Hsla, actions, canvas, div, point, px, Action, AnyElement, AppContext, Element, Hsla,
InteractiveElement, IntoElement, Model, ParentElement, Path, Render, InteractiveElement, IntoElement, Model, ParentElement, Path, Render,
StatefulInteractiveElement, Styled, Subscription, View, ViewContext, VisualContext, WeakView, StatefulInteractiveElement, Styled, Subscription, ViewContext, VisualContext, WeakView,
}; };
use project::{Project, RepositoryEntry}; use project::{Project, RepositoryEntry};
use recent_projects::RecentProjects; use recent_projects::RecentProjects;
@ -17,7 +17,7 @@ use ui::{
ButtonStyle, ContextMenu, Icon, IconButton, IconName, Indicator, TintColor, TitleBar, Tooltip, ButtonStyle, ContextMenu, Icon, IconButton, IconName, Indicator, TintColor, TitleBar, Tooltip,
}; };
use util::ResultExt; 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}; use workspace::{notifications::NotifyResultExt, Workspace};
const MAX_PROJECT_NAME_LENGTH: usize = 40; const MAX_PROJECT_NAME_LENGTH: usize = 40;
@ -487,7 +487,7 @@ impl CollabTitlebarItem {
})) }))
} }
pub fn render_project_branch(&self, cx: &mut ViewContext<Self>) -> Option<impl Element> { pub fn render_project_branch(&self, cx: &mut ViewContext<Self>) -> Option<impl IntoElement> {
let entry = { let entry = {
let mut names_and_branches = let mut names_and_branches =
self.project.read(cx).visible_worktrees(cx).map(|worktree| { self.project.read(cx).visible_worktrees(cx).map(|worktree| {
@ -503,22 +503,23 @@ impl CollabTitlebarItem {
.and_then(RepositoryEntry::branch) .and_then(RepositoryEntry::branch)
.map(|branch| util::truncate_and_trailoff(&branch, MAX_BRANCH_NAME_LENGTH))?; .map(|branch| util::truncate_and_trailoff(&branch, MAX_BRANCH_NAME_LENGTH))?;
Some( Some(
popover_menu("project_branch_trigger") Button::new("project_branch_trigger", branch_name)
.trigger( .color(Color::Muted)
Button::new("project_branch_trigger", branch_name) .style(ButtonStyle::Subtle)
.color(Color::Muted) .label_size(LabelSize::Small)
.style(ButtonStyle::Subtle) .tooltip(move |cx| {
.label_size(LabelSize::Small) Tooltip::with_meta(
.tooltip(move |cx| { "Recent Branches",
Tooltip::with_meta( Some(&ToggleVcsMenu),
"Recent Branches", "Local branches only",
Some(&ToggleVcsMenu), cx,
"Local branches only", )
cx, })
) .on_click(move |_, cx| {
}), let _ = workspace.update(cx, |this, cx| {
) BranchList::open(this, &Default::default(), cx)
.menu(move |cx| Self::render_vcs_popover(workspace.clone(), cx)), });
}),
) )
} }
@ -650,16 +651,6 @@ impl CollabTitlebarItem {
.log_err(); .log_err();
} }
pub fn render_vcs_popover(
workspace: View<Workspace>,
cx: &mut WindowContext<'_>,
) -> Option<View<BranchList>> {
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( fn render_connection_status(
&self, &self,
status: &client::Status, status: &client::Status,

View file

@ -118,16 +118,6 @@ impl RecentProjects {
modal modal
}) })
} }
pub fn open_popover(workspace: WeakView<Workspace>, cx: &mut WindowContext<'_>) -> View<Self> {
cx.new_view(|cx| {
Self::new(
RecentProjectsDelegate::new(workspace, false, false),
20.,
cx,
)
})
}
} }
impl EventEmitter<DismissEvent> for RecentProjects {} impl EventEmitter<DismissEvent> for RecentProjects {}

View file

@ -21,7 +21,7 @@ actions!(branches, [OpenRecent]);
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
cx.observe_new_views(|workspace: &mut Workspace, _| { cx.observe_new_views(|workspace: &mut Workspace, _| {
workspace.register_action(|workspace, action, cx| { workspace.register_action(|workspace, action, cx| {
BranchList::toggle_modal(workspace, action, cx).log_err(); BranchList::open(workspace, action, cx).log_err();
}); });
}) })
.detach(); .detach();
@ -43,7 +43,7 @@ impl BranchList {
_subscription, _subscription,
} }
} }
fn toggle_modal( pub fn open(
workspace: &mut Workspace, workspace: &mut Workspace,
_: &OpenRecent, _: &OpenRecent,
cx: &mut ViewContext<Workspace>, cx: &mut ViewContext<Workspace>,
@ -77,16 +77,6 @@ impl Render for BranchList {
} }
} }
pub fn build_branch_list(
workspace: View<Workspace>,
cx: &mut WindowContext<'_>,
) -> Result<View<BranchList>> {
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 { pub struct BranchListDelegate {
matches: Vec<StringMatch>, matches: Vec<StringMatch>,
all_branches: Vec<Branch>, all_branches: Vec<Branch>,