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
+58 -85
View File
@@ -6,13 +6,14 @@ use assets::CustomIconName;
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder as _;
use gpui::{ use gpui::{
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement, AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
ParentElement as _, PathPromptOptions, Render, SharedString, StatefulInteractiveElement as _, ParentElement as _, PathPromptOptions, Render, SharedString, Styled as _, Subscription, Task,
Styled as _, Subscription, Task, WeakEntity, Window, div, px, WeakEntity, Window, div, px,
}; };
use gpui_native_kit::alert::{Alert, AlertSeverity}; use gpui_native_kit::alert::{Alert, AlertSeverity};
use gpui_native_kit::badge::Badge; use gpui_native_kit::badge::Badge;
use gpui_native_kit::button::{Button, ButtonVariant}; use gpui_native_kit::button::{Button, ButtonVariant};
use gpui_native_kit::common::{Sizable as _, h_flex, v_flex}; 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::icons::{Icon, IconRole};
use gpui_native_kit::layout::panel::Panel; use gpui_native_kit::layout::panel::Panel;
use gpui_native_kit::spinner::Spinner; use gpui_native_kit::spinner::Spinner;
@@ -48,6 +49,7 @@ use crate::shared::tree::{build_tree_items, sorted_worktree_paths};
use crate::workspace::Workspace; use crate::workspace::Workspace;
const REPO_SIDEBAR_WIDTH: f32 = 240.; const REPO_SIDEBAR_WIDTH: f32 = 240.;
const REPO_SIDEBAR_ROW_HEIGHT: f32 = 30.;
#[derive(Clone, Copy, PartialEq, Eq)] #[derive(Clone, Copy, PartialEq, Eq)]
pub(super) enum RepoSection { pub(super) enum RepoSection {
@@ -57,17 +59,6 @@ pub(super) enum RepoSection {
PullRequests, 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)] #[derive(Clone, Copy, PartialEq, Eq)]
pub enum RefKind { pub enum RefKind {
/// HEAD stays attached. /// HEAD stays attached.
@@ -1227,88 +1218,70 @@ impl RepoDetailView {
.commit_count() .commit_count()
.map(|count| SharedString::from(format!("Commits ({count})"))) .map(|count| SharedString::from(format!("Commits ({count})")))
.unwrap_or_else(|| SharedString::from("Commits")); .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() let nav = Sidebar::new("repo-sidebar-nav")
.p_2() .selected(selected)
.gap_1() .on_change(move |index, _, cx| {
.child(self.render_section_row( let section = match (index, include_issues) {
RepoSection::Files, (Some(0), _) => RepoSection::Commits,
"Files", (Some(1), true) => RepoSection::Issues,
Icon::named(CustomIconName::GitFile), (Some(2), true) => RepoSection::PullRequests,
cx, _ => return,
)) };
.child(self.render_section_row( crate::shared::log_dropped(weak.update(cx, |this, cx| {
RepoSection::Commits, this.active_section = section;
commits, cx.notify();
Icon::named(CustomIconName::GitCommit), }));
cx, })
)); .entries(move |_, cx| {
let color = cx.theme().colors.muted_foreground;
if self.store.read(cx).addr().is_some() { let mut entries = vec![
sections = sections SidebarEntry::row("repo-nav-commits", commits.clone())
.child(self.render_section_row( .prefix(Icon::named(CustomIconName::GitCommit).small().color(color)),
RepoSection::Issues, ];
"Issues", if include_issues {
Icon::named(CustomIconName::GitIssueDone), entries.push(
cx, SidebarEntry::row("repo-nav-issues", "Issues").prefix(
)) Icon::named(CustomIconName::GitIssueDone)
.child(self.render_section_row( .small()
RepoSection::PullRequests, .color(color),
"Pull requests", ),
Icon::named(CustomIconName::GitPullRequest), );
cx, entries.push(
)); SidebarEntry::row("repo-nav-pulls", "Pull requests").prefix(
Icon::named(CustomIconName::GitPullRequest)
.small()
.color(color),
),
);
} }
entries
});
v_flex() div()
.w(px(REPO_SIDEBAR_WIDTH)) .w(px(REPO_SIDEBAR_WIDTH))
.h_full() .h_full()
.flex_none() .flex_none()
.border_r_1() .border_r_1()
.border_color(cx.theme().colors.border) .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( .child(
div() Sidebar::new("repo-sidebar").content(
.typeset(TextRole::Body, cx) v_flex()
.text_color(color) .size_full()
.child(label), .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() .into_any_element()
} }