Add render_project_name and render_project_branch

Co-Authored-By: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
This commit is contained in:
Nate Butler 2023-11-30 12:51:55 -05:00
parent 8d4652a4db
commit 679851e349

View file

@ -35,7 +35,7 @@ use gpui::{
ParentElement, Render, RenderOnce, Stateful, StatefulInteractiveElement, Styled, Subscription, ParentElement, Render, RenderOnce, Stateful, StatefulInteractiveElement, Styled, Subscription,
ViewContext, VisualContext, WeakView, WindowBounds, ViewContext, VisualContext, WeakView, WindowBounds,
}; };
use project::Project; use project::{Project, RepositoryEntry};
use theme::ActiveTheme; use theme::ActiveTheme;
use ui::{ use ui::{
h_stack, prelude::*, Avatar, Button, ButtonLike, ButtonStyle2, Icon, IconButton, IconElement, h_stack, prelude::*, Avatar, Button, ButtonLike, ButtonStyle2, Icon, IconButton, IconElement,
@ -46,8 +46,8 @@ use workspace::{notifications::NotifyResultExt, Workspace};
use crate::face_pile::FacePile; use crate::face_pile::FacePile;
// const MAX_PROJECT_NAME_LENGTH: usize = 40; const MAX_PROJECT_NAME_LENGTH: usize = 40;
// const MAX_BRANCH_NAME_LENGTH: usize = 40; const MAX_BRANCH_NAME_LENGTH: usize = 40;
// actions!( // actions!(
// collab, // collab,
@ -153,6 +153,8 @@ impl Render for CollabTitlebarItem {
.when(is_in_room, |this| { .when(is_in_room, |this| {
this.children(self.render_project_owner(cx)) this.children(self.render_project_owner(cx))
}) })
.child(self.render_project_name(cx))
.children(self.render_project_branch(cx)),
// TODO - Add player menu // TODO - Add player menu
// .when(is_in_room, |this| { // .when(is_in_room, |this| {
// this.child( // this.child(
@ -169,42 +171,42 @@ impl Render for CollabTitlebarItem {
// ) // )
// }) // })
// TODO - Add project menu // TODO - Add project menu
.child( // .child(
div() // div()
.border() // .border()
.border_color(gpui::red()) // .border_color(gpui::red())
.id("titlebar_project_menu_button") // .id("titlebar_project_menu_button")
.child( // .child(
Button::new("project_name", "project_name") // Button::new("project_name", "project_name")
.style(ButtonStyle2::Subtle), // .style(ButtonStyle2::Subtle),
) // )
.tooltip(move |cx| Tooltip::text("Recent Projects", cx)), // .tooltip(move |cx| Tooltip::text("Recent Projects", cx)),
) // )
// TODO - Add git menu // TODO - Add git menu
.child( // .child(
div() // div()
.border() // .border()
.border_color(gpui::red()) // .border_color(gpui::red())
.id("titlebar_git_menu_button") // .id("titlebar_git_menu_button")
.child( // .child(
Button::new("branch_name", "branch_name") // Button::new("branch_name", "branch_name")
.style(ButtonStyle2::Subtle) // .style(ButtonStyle2::Subtle)
.color(Some(Color::Muted)), // .color(Some(Color::Muted)),
) // )
.tooltip(move |cx| { // .tooltip(move |cx| {
cx.build_view(|_| { // cx.build_view(|_| {
Tooltip::new("Recent Branches") // Tooltip::new("Recent Branches")
.key_binding(KeyBinding::new(gpui::KeyBinding::new( // .key_binding(KeyBinding::new(gpui::KeyBinding::new(
"cmd-b", // "cmd-b",
// todo!() Replace with real action. // // todo!() Replace with real action.
gpui::NoAction, // gpui::NoAction,
None, // None,
))) // )))
.meta("Only local branches shown") // .meta("Only local branches shown")
}) // })
.into() // .into()
}), // }),
), // ),
) )
.when_some( .when_some(
users.zip(current_user.clone()), users.zip(current_user.clone()),
@ -523,8 +525,46 @@ impl CollabTitlebarItem {
.style(ButtonStyle2::Subtle) .style(ButtonStyle2::Subtle)
.into_element(), .into_element(),
) )
}
// add lock if you are in a locked project pub fn render_project_name(&self, cx: &mut ViewContext<Self>) -> impl Element {
let name = {
let mut names = self.project.read(cx).visible_worktrees(cx).map(|worktree| {
let worktree = worktree.read(cx);
worktree.root_name()
});
names.next().unwrap_or("")
};
let name = util::truncate_and_trailoff(name, MAX_PROJECT_NAME_LENGTH);
Button::new("project_name_trigger", name)
.style(ButtonStyle2::Subtle)
.into_element()
}
pub fn render_project_branch(&self, cx: &mut ViewContext<Self>) -> Option<impl Element> {
let entry = {
let mut names_and_branches =
self.project.read(cx).visible_worktrees(cx).map(|worktree| {
let worktree = worktree.read(cx);
worktree.root_git_entry()
});
names_and_branches.next().flatten()
};
let branch_name = entry
.as_ref()
.and_then(RepositoryEntry::branch)
.map(|branch| util::truncate_and_trailoff(&branch, MAX_BRANCH_NAME_LENGTH))?;
Some(
Button::new("project_branch_trigger", branch_name)
.style(ButtonStyle2::Subtle)
.into_element(),
)
} }
// fn collect_title_root_names( // fn collect_title_root_names(