Render title root names without branches

This commit is contained in:
Petros Amoiridis 2023-05-04 20:27:22 +03:00 committed by Mikayla Maki
parent 92a222aba8
commit 797d47a08c
No known key found for this signature in database

View file

@ -1,6 +1,6 @@
use crate::{ use crate::{
contact_notification::ContactNotification, contacts_popover, face_pile::FacePile, contact_notification::ContactNotification, contacts_popover, face_pile::FacePile,
toggle_screen_sharing, ToggleScreenSharing, toggle_screen_sharing, BranchesButton, ToggleScreenSharing,
}; };
use call::{ActiveCall, ParticipantLocation, Room}; use call::{ActiveCall, ParticipantLocation, Room};
use client::{proto::PeerId, Client, ContactEventKind, SignIn, SignOut, User, UserStore}; use client::{proto::PeerId, Client, ContactEventKind, SignIn, SignOut, User, UserStore};
@ -48,6 +48,7 @@ pub struct CollabTitlebarItem {
workspace: WeakViewHandle<Workspace>, workspace: WeakViewHandle<Workspace>,
contacts_popover: Option<ViewHandle<ContactsPopover>>, contacts_popover: Option<ViewHandle<ContactsPopover>>,
user_menu: ViewHandle<ContextMenu>, user_menu: ViewHandle<ContextMenu>,
branches: ViewHandle<BranchesButton>,
_subscriptions: Vec<Subscription>, _subscriptions: Vec<Subscription>,
} }
@ -68,17 +69,14 @@ impl View for CollabTitlebarItem {
}; };
let project = self.project.read(cx); let project = self.project.read(cx);
let project_title = self.prepare_title(&project, cx);
let theme = cx.global::<Settings>().theme.clone(); let theme = cx.global::<Settings>().theme.clone();
let mut left_container = Flex::row(); let mut left_container = Flex::row();
let mut right_container = Flex::row().align_children_center(); let mut right_container = Flex::row().align_children_center();
left_container.add_child(self.render_title_with_information( let project_title = self.collect_title_root_names(&project, cx);
project, left_container.add_child(self.render_title_root_names(&project_title, theme.clone()));
&project_title,
theme.clone(), left_container.add_child(ChildView::new(&self.branches.clone().into_any(), cx));
));
let user = self.user_store.read(cx).current_user(); let user = self.user_store.read(cx).current_user();
let peer_id = self.client.peer_id(); let peer_id = self.client.peer_id();
@ -165,15 +163,16 @@ impl CollabTitlebarItem {
menu.set_position_mode(OverlayPositionMode::Local); menu.set_position_mode(OverlayPositionMode::Local);
menu menu
}), }),
branches: cx.add_view(|cx| BranchesButton::new(workspace_handle.to_owned(), cx)),
_subscriptions: subscriptions, _subscriptions: subscriptions,
} }
} }
fn decorate_with_git_branch( fn root_name_with_branch(
&self, &self,
worktree: &ModelHandle<Worktree>, worktree: &ModelHandle<Worktree>,
cx: &ViewContext<Self>, cx: &ViewContext<Self>,
) -> String { ) -> (String, String) {
let name = worktree.read(cx).root_name(); let name = worktree.read(cx).root_name();
let branch = worktree let branch = worktree
.read(cx) .read(cx)
@ -182,14 +181,23 @@ impl CollabTitlebarItem {
.and_then(|entry| entry.branch()) .and_then(|entry| entry.branch())
.map(|branch| branch.to_string()) .map(|branch| branch.to_string())
.unwrap_or_else(|| "".to_owned()); .unwrap_or_else(|| "".to_owned());
format!("{} / {}", name, branch) (name.to_owned(), branch)
} }
fn prepare_title(&self, project: &Project, cx: &ViewContext<Self>) -> String { fn collect_root_names_with_branches(
let decorated_root_names: Vec<String> = project &self,
project: &Project,
cx: &ViewContext<Self>,
) -> Vec<(String, String)> {
let root_names_with_branches: Vec<(String, String)> = project
.visible_worktrees(cx) .visible_worktrees(cx)
.map(|worktree| self.decorate_with_git_branch(&worktree, cx)) .map(|worktree| self.root_name_with_branch(&worktree, cx))
.collect(); .collect();
root_names_with_branches
}
fn collect_title_root_names(&self, project: &Project, cx: &ViewContext<Self>) -> String {
let decorated_root_names: Vec<&str> = project.worktree_root_names(cx).collect();
if decorated_root_names.is_empty() { if decorated_root_names.is_empty() {
"empty project".to_owned() "empty project".to_owned()
} else { } else {
@ -197,12 +205,7 @@ impl CollabTitlebarItem {
} }
} }
fn render_title_with_information( fn render_title_root_names(&self, title: &str, theme: Arc<Theme>) -> AnyElement<Self> {
&self,
_project: &Project,
title: &str,
theme: Arc<Theme>,
) -> AnyElement<Self> {
let text_style = theme.workspace.titlebar.title.clone(); let text_style = theme.workspace.titlebar.title.clone();
let item_spacing = theme.workspace.titlebar.item_spacing; let item_spacing = theme.workspace.titlebar.item_spacing;