Move repository navigation into a sidebar

- Replace the repository tabs and header Issues/PR menus with sidebar sections.
- Keep the file tree visible beside Files, Commits, Issues, and Pull requests.
- Switch back to Files when a tree folder or file is activated.
This commit is contained in:
2026-11-15 15:43:39 +07:00
parent 6c34392d74
commit edb34abc60
3 changed files with 234 additions and 293 deletions
+171 -22
View File
@@ -6,8 +6,8 @@ use assets::CustomIconName;
use gpui::prelude::FluentBuilder as _;
use gpui::{
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
ParentElement as _, PathPromptOptions, Render, SharedString, Styled as _, Subscription, Task,
WeakEntity, Window, div,
ParentElement as _, PathPromptOptions, Render, SharedString, StatefulInteractiveElement as _,
Styled as _, Subscription, Task, WeakEntity, Window, div, px,
};
use gpui_native_kit::alert::{Alert, AlertSeverity};
use gpui_native_kit::badge::Badge;
@@ -42,9 +42,32 @@ use helpers::{RepoData, load_repo_data};
use history::RepoHistoryView;
use refs::RefSwitcher;
use crate::issues::IssuesView;
use crate::pull_requests::PullRequestsView;
use crate::shared::tree::{build_tree_items, sorted_worktree_paths};
use crate::workspace::Workspace;
const REPO_SIDEBAR_WIDTH: f32 = 240.;
#[derive(Clone, Copy, PartialEq, Eq)]
pub(super) enum RepoSection {
Files,
Commits,
Issues,
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.
@@ -58,12 +81,16 @@ pub struct RepoDetailView {
pub(super) store: Entity<RepoStore>,
/// A repository opened by address alone starts without an announcement.
repo_started: bool,
/// The Files tab, which owns the explorer, previews and the per-file commit map.
/// The file explorer and preview.
files: Entity<RepoFilesView>,
/// The Commits tab, which walks HEAD and opens commit diffs.
/// The commit history section.
pub(super) history: Entity<RepoHistoryView>,
/// The active tab: Files or Commits.
pub(super) active_tab: usize,
/// The issues list shown in the repository panel.
issues: Entity<IssuesView>,
/// The pull request list shown in the repository panel.
pulls: Entity<PullRequestsView>,
/// The section selected in the repository sidebar.
active_section: RepoSection,
/// The checked-out worktree path.
worktree: Option<PathBuf>,
loading: bool,
@@ -79,8 +106,6 @@ pub struct RepoDetailView {
pub(super) share_open: bool,
pub(super) repo_menu_open: bool,
pub(super) clone_open: bool,
pub(super) issues_menu_open: bool,
pub(super) pulls_menu_open: bool,
_subscriptions: Vec<Subscription>,
}
@@ -129,14 +154,24 @@ impl RepoDetailView {
let checkouts = CheckoutsStore::global(cx);
let files = cx.new(RepoFilesView::new);
let history = cx.new(|_| RepoHistoryView::new(store.clone(), workspace.clone()));
let issues = cx.new(|cx| IssuesView::new(workspace.clone(), store.clone(), cx));
let pulls = cx.new(|cx| PullRequestsView::new(workspace.clone(), store.clone(), cx));
let weak = cx.entity().downgrade();
let refs = RefSwitcher::new(weak.clone(), window, cx);
let subscriptions = vec![cx.observe(&checkouts, |this, _checkouts, cx| {
if this.refresh_statuses(cx) {
cx.notify();
}
})];
let subscriptions = vec![
cx.observe(&checkouts, |this, _checkouts, cx| {
if this.refresh_statuses(cx) {
cx.notify();
}
}),
cx.subscribe(&files, |this, _files, _event, cx| {
if this.active_section != RepoSection::Files {
this.active_section = RepoSection::Files;
cx.notify();
}
}),
];
let store_for_attach = store.clone();
window.defer(cx, move |window, cx| {
@@ -152,7 +187,9 @@ impl RepoDetailView {
repo_started: false,
files,
history,
active_tab: 0,
issues,
pulls,
active_section: RepoSection::Files,
worktree: None,
loading: true,
error: None,
@@ -165,8 +202,6 @@ impl RepoDetailView {
share_open: false,
repo_menu_open: false,
clone_open: false,
issues_menu_open: false,
pulls_menu_open: false,
_subscriptions: subscriptions,
}
}
@@ -1157,7 +1192,7 @@ impl RepoDetailView {
)
}
fn render_files_tab(&self, cx: &mut Context<Self>) -> AnyElement {
fn render_files_tab(&self, cx: &App) -> AnyElement {
if self.loading {
let label = if self.store.read(cx).path.is_some() {
"Loading repository..."
@@ -1181,7 +1216,109 @@ impl RepoDetailView {
.into_any_element();
}
self.files.clone().into_any_element()
self.files.read(cx).render_content(cx)
}
fn render_sidebar(&self, cx: &mut Context<Self>) -> AnyElement {
let tree = self.files.read(cx).render_tree(self.files.downgrade());
let commits = self
.history
.read(cx)
.commit_count()
.map(|count| SharedString::from(format!("Commits ({count})")))
.unwrap_or_else(|| SharedString::from("Commits"));
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,
));
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()
.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),
)
.on_click(cx.listener(move |this, _, _, cx| {
this.active_section = section;
cx.notify();
}))
.into_any_element()
}
fn render_content(&mut self, cx: &mut Context<Self>) -> AnyElement {
match self.active_section {
RepoSection::Files => self.render_files_tab(cx),
RepoSection::Commits => self.history.clone().into_any_element(),
RepoSection::Issues => self.issues.clone().into_any_element(),
RepoSection::PullRequests => self.pulls.clone().into_any_element(),
}
}
}
@@ -1232,9 +1369,21 @@ impl Render for RepoDetailView {
}),
)
})
.map(|this| match self.active_tab {
0 => this.child(self.render_files_tab(cx)),
_ => this.child(self.history.clone()),
})
.child(
h_flex()
.flex_1()
.min_h_0()
.w_full()
.overflow_hidden()
.child(self.render_sidebar(cx))
.child(
v_flex()
.flex_1()
.min_w_0()
.h_full()
.overflow_hidden()
.child(self.render_content(cx)),
),
)
}
}