Use kit sidebar for repository navigation

- Replace custom repository nav rows with Sidebar and SidebarEntry.
- Remove the redundant Files menu item; the tree opens file content directly.
- Keep the file tree below the section list.
This commit is contained in:
2026-11-15 16:08:52 +07:00
parent edb34abc60
commit 546f1572ea
+59 -86
View File
@@ -6,13 +6,14 @@ use assets::CustomIconName;
use gpui::prelude::FluentBuilder as _;
use gpui::{
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
ParentElement as _, PathPromptOptions, Render, SharedString, StatefulInteractiveElement as _,
Styled as _, Subscription, Task, WeakEntity, Window, div, px,
ParentElement as _, PathPromptOptions, Render, SharedString, Styled as _, Subscription, Task,
WeakEntity, Window, div, px,
};
use gpui_native_kit::alert::{Alert, AlertSeverity};
use gpui_native_kit::badge::Badge;
use gpui_native_kit::button::{Button, ButtonVariant};
use gpui_native_kit::common::{Sizable as _, h_flex, v_flex};
use gpui_native_kit::data::sidebar::{Sidebar, SidebarEntry};
use gpui_native_kit::icons::{Icon, IconRole};
use gpui_native_kit::layout::panel::Panel;
use gpui_native_kit::spinner::Spinner;
@@ -48,6 +49,7 @@ use crate::shared::tree::{build_tree_items, sorted_worktree_paths};
use crate::workspace::Workspace;
const REPO_SIDEBAR_WIDTH: f32 = 240.;
const REPO_SIDEBAR_ROW_HEIGHT: f32 = 30.;
#[derive(Clone, Copy, PartialEq, Eq)]
pub(super) enum RepoSection {
@@ -57,17 +59,6 @@ pub(super) enum RepoSection {
PullRequests,
}
impl RepoSection {
fn id(self) -> &'static str {
match self {
Self::Files => "repo-section-files",
Self::Commits => "repo-section-commits",
Self::Issues => "repo-section-issues",
Self::PullRequests => "repo-section-pulls",
}
}
}
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum RefKind {
/// HEAD stays attached.
@@ -1227,88 +1218,70 @@ impl RepoDetailView {
.commit_count()
.map(|count| SharedString::from(format!("Commits ({count})")))
.unwrap_or_else(|| SharedString::from("Commits"));
let include_issues = self.store.read(cx).addr().is_some();
let selected = match self.active_section {
RepoSection::Commits => Some(0),
RepoSection::Issues if include_issues => Some(1),
RepoSection::PullRequests if include_issues => Some(2),
_ => None,
};
let weak = cx.entity().downgrade();
let rows = if include_issues { 3.0 } else { 1.0 };
let nav_height = px(REPO_SIDEBAR_ROW_HEIGHT * rows + 8.);
let mut sections = v_flex()
.p_2()
.gap_1()
.child(self.render_section_row(
RepoSection::Files,
"Files",
Icon::named(CustomIconName::GitFile),
cx,
))
.child(self.render_section_row(
RepoSection::Commits,
commits,
Icon::named(CustomIconName::GitCommit),
cx,
));
let nav = Sidebar::new("repo-sidebar-nav")
.selected(selected)
.on_change(move |index, _, cx| {
let section = match (index, include_issues) {
(Some(0), _) => RepoSection::Commits,
(Some(1), true) => RepoSection::Issues,
(Some(2), true) => RepoSection::PullRequests,
_ => return,
};
crate::shared::log_dropped(weak.update(cx, |this, cx| {
this.active_section = section;
cx.notify();
}));
})
.entries(move |_, cx| {
let color = cx.theme().colors.muted_foreground;
let mut entries = vec![
SidebarEntry::row("repo-nav-commits", commits.clone())
.prefix(Icon::named(CustomIconName::GitCommit).small().color(color)),
];
if include_issues {
entries.push(
SidebarEntry::row("repo-nav-issues", "Issues").prefix(
Icon::named(CustomIconName::GitIssueDone)
.small()
.color(color),
),
);
entries.push(
SidebarEntry::row("repo-nav-pulls", "Pull requests").prefix(
Icon::named(CustomIconName::GitPullRequest)
.small()
.color(color),
),
);
}
entries
});
if self.store.read(cx).addr().is_some() {
sections = sections
.child(self.render_section_row(
RepoSection::Issues,
"Issues",
Icon::named(CustomIconName::GitIssueDone),
cx,
))
.child(self.render_section_row(
RepoSection::PullRequests,
"Pull requests",
Icon::named(CustomIconName::GitPullRequest),
cx,
));
}
v_flex()
div()
.w(px(REPO_SIDEBAR_WIDTH))
.h_full()
.flex_none()
.border_r_1()
.border_color(cx.theme().colors.border)
.child(sections)
.child(div().flex_1().min_h_0().px_2().pb_2().child(tree))
.into_any_element()
}
fn render_section_row(
&self,
section: RepoSection,
label: impl Into<SharedString>,
icon: Icon,
cx: &mut Context<Self>,
) -> AnyElement {
let label = label.into();
let active = self.active_section == section;
let color = if active {
cx.theme().colors.foreground
} else {
cx.theme().colors.muted_foreground
};
h_flex()
.id(section.id())
.w_full()
.h_8()
.px_2()
.gap_2()
.rounded(cx.theme().radius.control)
.cursor_pointer()
.when(active, |this| this.bg(cx.theme().colors.muted_hover))
.when(!active, |this| {
this.hover(|this| this.bg(cx.theme().colors.muted))
})
.child(icon.size(px(14.)).color(color))
.child(
div()
.typeset(TextRole::Body, cx)
.text_color(color)
.child(label),
Sidebar::new("repo-sidebar").content(
v_flex()
.size_full()
.child(div().h(nav_height).flex_none().child(nav))
.child(div().flex_1().min_h_0().px_2().pb_2().child(tree)),
),
)
.on_click(cx.listener(move |this, _, _, cx| {
this.active_section = section;
cx.notify();
}))
.into_any_element()
}