Added git status to the project panel, added worktree test

This commit is contained in:
Mikayla Maki 2023-05-09 14:42:51 -07:00 committed by Mikayla Maki
parent 93f57430da
commit e98507d8bf
No known key found for this signature in database
4 changed files with 246 additions and 19 deletions

View file

@ -13,10 +13,10 @@ use gpui::{
keymap_matcher::KeymapContext,
platform::{CursorStyle, MouseButton, PromptLevel},
AnyElement, AppContext, ClipboardItem, Element, Entity, ModelHandle, Task, View, ViewContext,
ViewHandle, WeakViewHandle,
ViewHandle, WeakViewHandle, color::Color,
};
use menu::{Confirm, SelectNext, SelectPrev};
use project::{Entry, EntryKind, Project, ProjectEntryId, ProjectPath, Worktree, WorktreeId};
use project::{Entry, EntryKind, Project, ProjectEntryId, ProjectPath, Worktree, WorktreeId, repository::GitStatus};
use settings::Settings;
use std::{
cmp::Ordering,
@ -86,6 +86,7 @@ pub struct EntryDetails {
is_editing: bool,
is_processing: bool,
is_cut: bool,
git_status: Option<GitStatus>
}
actions!(
@ -1008,6 +1009,13 @@ impl ProjectPanel {
let entry_range = range.start.saturating_sub(ix)..end_ix - ix;
for entry in &visible_worktree_entries[entry_range] {
let path = &entry.path;
let status = snapshot.repo_for(path)
.and_then(|entry| {
entry.status_for(&snapshot, path)
});
let mut details = EntryDetails {
filename: entry
.path
@ -1028,6 +1036,7 @@ impl ProjectPanel {
is_cut: self
.clipboard_entry
.map_or(false, |e| e.is_cut() && e.entry_id() == entry.id),
git_status: status
};
if let Some(edit_state) = &self.edit_state {
@ -1069,6 +1078,15 @@ impl ProjectPanel {
let kind = details.kind;
let show_editor = details.is_editing && !details.is_processing;
let git_color = details.git_status.as_ref().and_then(|status| {
match status {
GitStatus::Added => Some(Color::green()),
GitStatus::Modified => Some(Color::blue()),
GitStatus::Conflict => Some(Color::red()),
GitStatus::Untracked => None,
}
}).unwrap_or(Color::transparent_black());
Flex::row()
.with_child(
if kind == EntryKind::Dir {
@ -1107,6 +1125,7 @@ impl ProjectPanel {
.with_height(style.height)
.contained()
.with_style(row_container_style)
.with_background_color(git_color)
.with_padding_left(padding)
.into_any_named("project panel entry visual element")
}