Add render_project_name
and render_project_branch
Co-Authored-By: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
This commit is contained in:
parent
8d4652a4db
commit
679851e349
1 changed files with 96 additions and 56 deletions
|
@ -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,58 +153,60 @@ 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))
|
||||||
})
|
})
|
||||||
// TODO - Add player menu
|
.child(self.render_project_name(cx))
|
||||||
// .when(is_in_room, |this| {
|
.children(self.render_project_branch(cx)),
|
||||||
// this.child(
|
// TODO - Add player menu
|
||||||
// div()
|
// .when(is_in_room, |this| {
|
||||||
// .border()
|
// this.child(
|
||||||
// .border_color(gpui::red())
|
// div()
|
||||||
// .id("project_owner_indicator")
|
// .border()
|
||||||
// .child(
|
// .border_color(gpui::red())
|
||||||
// Button::new("project_owner", "project_owner")
|
// .id("project_owner_indicator")
|
||||||
// .style(ButtonStyle2::Subtle)
|
// .child(
|
||||||
// .color(Some(Color::Player(0))),
|
// Button::new("project_owner", "project_owner")
|
||||||
// )
|
// .style(ButtonStyle2::Subtle)
|
||||||
// .tooltip(move |cx| Tooltip::text("Toggle following", cx)),
|
// .color(Some(Color::Player(0))),
|
||||||
// )
|
// )
|
||||||
// })
|
// .tooltip(move |cx| Tooltip::text("Toggle following", cx)),
|
||||||
// TODO - Add project menu
|
// )
|
||||||
.child(
|
// })
|
||||||
div()
|
// TODO - Add project menu
|
||||||
.border()
|
// .child(
|
||||||
.border_color(gpui::red())
|
// div()
|
||||||
.id("titlebar_project_menu_button")
|
// .border()
|
||||||
.child(
|
// .border_color(gpui::red())
|
||||||
Button::new("project_name", "project_name")
|
// .id("titlebar_project_menu_button")
|
||||||
.style(ButtonStyle2::Subtle),
|
// .child(
|
||||||
)
|
// Button::new("project_name", "project_name")
|
||||||
.tooltip(move |cx| Tooltip::text("Recent Projects", cx)),
|
// .style(ButtonStyle2::Subtle),
|
||||||
)
|
// )
|
||||||
// TODO - Add git menu
|
// .tooltip(move |cx| Tooltip::text("Recent Projects", cx)),
|
||||||
.child(
|
// )
|
||||||
div()
|
// TODO - Add git menu
|
||||||
.border()
|
// .child(
|
||||||
.border_color(gpui::red())
|
// div()
|
||||||
.id("titlebar_git_menu_button")
|
// .border()
|
||||||
.child(
|
// .border_color(gpui::red())
|
||||||
Button::new("branch_name", "branch_name")
|
// .id("titlebar_git_menu_button")
|
||||||
.style(ButtonStyle2::Subtle)
|
// .child(
|
||||||
.color(Some(Color::Muted)),
|
// Button::new("branch_name", "branch_name")
|
||||||
)
|
// .style(ButtonStyle2::Subtle)
|
||||||
.tooltip(move |cx| {
|
// .color(Some(Color::Muted)),
|
||||||
cx.build_view(|_| {
|
// )
|
||||||
Tooltip::new("Recent Branches")
|
// .tooltip(move |cx| {
|
||||||
.key_binding(KeyBinding::new(gpui::KeyBinding::new(
|
// cx.build_view(|_| {
|
||||||
"cmd-b",
|
// Tooltip::new("Recent Branches")
|
||||||
// todo!() Replace with real action.
|
// .key_binding(KeyBinding::new(gpui::KeyBinding::new(
|
||||||
gpui::NoAction,
|
// "cmd-b",
|
||||||
None,
|
// // todo!() Replace with real action.
|
||||||
)))
|
// gpui::NoAction,
|
||||||
.meta("Only local branches shown")
|
// None,
|
||||||
})
|
// )))
|
||||||
.into()
|
// .meta("Only local branches shown")
|
||||||
}),
|
// })
|
||||||
),
|
// .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(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue