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:
@@ -4,8 +4,8 @@ use std::path::{Component, Path, PathBuf};
|
|||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
use gpui::prelude::FluentBuilder as _;
|
use gpui::prelude::FluentBuilder as _;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AnyElement, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render,
|
AnyElement, App, AppContext as _, Context, Entity, EventEmitter, IntoElement,
|
||||||
SharedString, Styled as _, Task, WeakEntity, Window, div, px,
|
ParentElement as _, SharedString, Styled as _, Task, WeakEntity, Window, div, px,
|
||||||
};
|
};
|
||||||
use gpui_native_kit::common::{h_flex, v_flex};
|
use gpui_native_kit::common::{h_flex, v_flex};
|
||||||
use gpui_native_kit::data::tree::{Tree, TreeItem};
|
use gpui_native_kit::data::tree::{Tree, TreeItem};
|
||||||
@@ -19,11 +19,16 @@ use super::helpers::{code_language, is_markdown_path, preview_spinner, source_ha
|
|||||||
use crate::shared::tree::{TreeItemSeed, TreeRow, collect_expanded, flatten};
|
use crate::shared::tree::{TreeItemSeed, TreeRow, collect_expanded, flatten};
|
||||||
use crate::shared::widgets::empty_state;
|
use crate::shared::widgets::empty_state;
|
||||||
|
|
||||||
const TREE_WIDTH: f32 = 240.;
|
|
||||||
const MAX_PREVIEW_BYTES: usize = 1024 * 1024;
|
const MAX_PREVIEW_BYTES: usize = 1024 * 1024;
|
||||||
const MAX_PREVIEWED_FILES: usize = 32;
|
const MAX_PREVIEWED_FILES: usize = 32;
|
||||||
const MAX_PREVIEW_CACHE_BYTES: usize = 8 * 1024 * 1024;
|
const MAX_PREVIEW_CACHE_BYTES: usize = 8 * 1024 * 1024;
|
||||||
|
|
||||||
|
/// The tree picked a folder or file, so the repository panel should show Files.
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
pub enum RepoFilesEvent {
|
||||||
|
Activated,
|
||||||
|
}
|
||||||
|
|
||||||
enum FileContent {
|
enum FileContent {
|
||||||
Text(String),
|
Text(String),
|
||||||
Binary,
|
Binary,
|
||||||
@@ -68,6 +73,8 @@ pub struct RepoFilesView {
|
|||||||
tasks: Vec<Task<Result<(), Error>>>,
|
tasks: Vec<Task<Result<(), Error>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl EventEmitter<RepoFilesEvent> for RepoFilesView {}
|
||||||
|
|
||||||
impl RepoFilesView {
|
impl RepoFilesView {
|
||||||
pub fn new(_cx: &mut Context<Self>) -> Self {
|
pub fn new(_cx: &mut Context<Self>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
@@ -237,81 +244,72 @@ impl RepoFilesView {
|
|||||||
} else {
|
} else {
|
||||||
self.open_file(&id, window, cx);
|
self.open_file(&id, window, cx);
|
||||||
}
|
}
|
||||||
|
cx.emit(RepoFilesEvent::Activated);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_tree_column(
|
pub fn render_tree(&self, view: WeakEntity<Self>) -> AnyElement {
|
||||||
&self,
|
let rows = self.rows.clone();
|
||||||
rows: Vec<TreeRow>,
|
let selected = self.selected_index;
|
||||||
selected: Option<usize>,
|
|
||||||
view: WeakEntity<Self>,
|
|
||||||
cx: &mut Context<Self>,
|
|
||||||
) -> impl IntoElement {
|
|
||||||
let change_view = view.clone();
|
let change_view = view.clone();
|
||||||
let disclosure_view = view;
|
let disclosure_view = view;
|
||||||
|
|
||||||
v_flex()
|
div()
|
||||||
.h_full()
|
.flex_1()
|
||||||
.w(px(TREE_WIDTH))
|
.min_h_0()
|
||||||
.p_2()
|
.w_full()
|
||||||
.flex_none()
|
|
||||||
.border_r_1()
|
|
||||||
.border_color(cx.theme().colors.border)
|
|
||||||
.child(
|
.child(
|
||||||
div().flex_1().min_h_0().child(
|
Tree::new("repo-tree")
|
||||||
Tree::new("repo-tree")
|
.selected(selected)
|
||||||
.selected(selected)
|
.items(move |_, _| {
|
||||||
.items(move |_, _| {
|
rows.iter()
|
||||||
rows.iter()
|
.map(|row| {
|
||||||
.map(|row| {
|
let item = TreeItem::new(row.id.clone(), row.label.clone())
|
||||||
let item = TreeItem::new(row.id.clone(), row.label.clone())
|
.depth(row.depth)
|
||||||
.depth(row.depth)
|
.expandable(row.expandable)
|
||||||
.expandable(row.expandable)
|
.expanded(row.expanded);
|
||||||
.expanded(row.expanded);
|
|
||||||
|
|
||||||
if row.expandable {
|
if row.expandable {
|
||||||
item.icon(Icon::named(IconRole::Folder))
|
item.icon(Icon::named(IconRole::Folder))
|
||||||
} else {
|
} else {
|
||||||
item.icon(Icon::named(IconRole::File))
|
item.icon(Icon::named(IconRole::File))
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
})
|
||||||
|
.on_change({
|
||||||
|
let view = change_view;
|
||||||
|
move |index, window, cx| {
|
||||||
|
if let Some(index) = index
|
||||||
|
&& let Err(error) = view.update(cx, |this, cx| {
|
||||||
|
this.activate_row(index, window, cx);
|
||||||
})
|
})
|
||||||
.collect()
|
{
|
||||||
})
|
log::warn!("failed to activate tree row: {error}");
|
||||||
.on_change({
|
|
||||||
let view = change_view;
|
|
||||||
move |index, window, cx| {
|
|
||||||
if let Some(index) = index
|
|
||||||
&& let Err(error) = view.update(cx, |this, cx| {
|
|
||||||
this.activate_row(index, window, cx);
|
|
||||||
})
|
|
||||||
{
|
|
||||||
log::warn!("failed to activate tree row: {error}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
.on_disclosure({
|
})
|
||||||
let view = disclosure_view;
|
.on_disclosure({
|
||||||
move |index, _, cx| {
|
let view = disclosure_view;
|
||||||
if let Err(error) = view.update(cx, |this, cx| {
|
move |index, _, cx| {
|
||||||
let id = this.rows.get(index).map(|row| row.id.clone());
|
if let Err(error) = view.update(cx, |this, cx| {
|
||||||
if let Some(id) = id {
|
let id = this.rows.get(index).map(|row| row.id.clone());
|
||||||
this.toggle_folder(&id);
|
if let Some(id) = id {
|
||||||
cx.notify();
|
this.toggle_folder(&id);
|
||||||
}
|
cx.emit(RepoFilesEvent::Activated);
|
||||||
}) {
|
cx.notify();
|
||||||
log::warn!("failed to toggle folder: {error}");
|
|
||||||
}
|
}
|
||||||
|
}) {
|
||||||
|
log::warn!("failed to toggle folder: {error}");
|
||||||
}
|
}
|
||||||
}),
|
}
|
||||||
),
|
}),
|
||||||
)
|
)
|
||||||
|
.into_any_element()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_content_column(
|
pub fn render_content(&self, cx: &App) -> AnyElement {
|
||||||
&self,
|
let pane_title = self.pane_title();
|
||||||
pane_title: SharedString,
|
|
||||||
cx: &mut Context<Self>,
|
|
||||||
) -> impl IntoElement {
|
|
||||||
let body: AnyElement = if let Some(path) = self.selected_file.clone() {
|
let body: AnyElement = if let Some(path) = self.selected_file.clone() {
|
||||||
match self.files.get(path.as_ref()) {
|
match self.files.get(path.as_ref()) {
|
||||||
Some(FileContent::Text(_)) => {
|
Some(FileContent::Text(_)) => {
|
||||||
@@ -383,6 +381,7 @@ impl RepoFilesView {
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.child(div().flex_1().min_h_0().child(body))
|
.child(div().flex_1().min_h_0().child(body))
|
||||||
|
.into_any_element()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_markdown(
|
fn set_markdown(
|
||||||
@@ -709,19 +708,3 @@ impl RepoFilesView {
|
|||||||
self.tasks.push(task);
|
self.tasks.push(task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Render for RepoFilesView {
|
|
||||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
|
||||||
let rows = self.rows.clone();
|
|
||||||
let selected = self.selected_index;
|
|
||||||
let view = cx.entity().downgrade();
|
|
||||||
let pane_title = self.pane_title();
|
|
||||||
|
|
||||||
h_flex()
|
|
||||||
.flex_1()
|
|
||||||
.w_full()
|
|
||||||
.overflow_hidden()
|
|
||||||
.child(self.render_tree_column(rows, selected, view, cx))
|
|
||||||
.child(self.render_content_column(pane_title, cx))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ use gpui_native_kit::avatar::Avatar;
|
|||||||
use gpui_native_kit::button::{Button, ButtonVariant};
|
use gpui_native_kit::button::{Button, ButtonVariant};
|
||||||
use gpui_native_kit::clipboard::ClipboardButton;
|
use gpui_native_kit::clipboard::ClipboardButton;
|
||||||
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::tabs::{Tab, Tabs};
|
|
||||||
use gpui_native_kit::dropdown_menu::DropdownMenu;
|
use gpui_native_kit::dropdown_menu::DropdownMenu;
|
||||||
use gpui_native_kit::icons::{Icon, IconRole};
|
use gpui_native_kit::icons::{Icon, IconRole};
|
||||||
use gpui_native_kit::menu::MenuItem;
|
use gpui_native_kit::menu::MenuItem;
|
||||||
@@ -25,8 +24,7 @@ use super::dialogs;
|
|||||||
use super::helpers::{
|
use super::helpers::{
|
||||||
ShareTargets, bound_repo_label, clone_group, fork_row, nostr_clone_url, repo_display_name,
|
ShareTargets, bound_repo_label, clone_group, fork_row, nostr_clone_url, repo_display_name,
|
||||||
};
|
};
|
||||||
use crate::issues::IssuesView;
|
use crate::pull_requests::NewPullRequestView;
|
||||||
use crate::pull_requests::{NewPullRequestView, PullRequestsView, SendPatchView};
|
|
||||||
|
|
||||||
impl RepoDetailView {
|
impl RepoDetailView {
|
||||||
pub(super) fn open_upstream(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
pub(super) fn open_upstream(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
@@ -49,28 +47,6 @@ impl RepoDetailView {
|
|||||||
dialogs::init::open(local_path, cx.entity().downgrade(), window, cx);
|
dialogs::init::open(local_path, cx.entity().downgrade(), window, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open_pulls(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
|
||||||
let Some(addr) = self.store.read(cx).addr().cloned() else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
let id = SharedString::from(format!("pulls:{addr}"));
|
|
||||||
let workspace = self.workspace.clone();
|
|
||||||
let workspace_for_build = workspace.clone();
|
|
||||||
let store = self.store.clone();
|
|
||||||
|
|
||||||
crate::shared::panels::open_detail(
|
|
||||||
&workspace,
|
|
||||||
id,
|
|
||||||
"Pull requests",
|
|
||||||
move |_, cx| {
|
|
||||||
cx.new(|cx| PullRequestsView::new(workspace_for_build.clone(), store.clone(), cx))
|
|
||||||
},
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(super) fn open_new_pull_request(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
pub(super) fn open_new_pull_request(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
let Some(addr) = self.store.read(cx).addr().cloned() else {
|
let Some(addr) = self.store.read(cx).addr().cloned() else {
|
||||||
return;
|
return;
|
||||||
@@ -101,57 +77,6 @@ impl RepoDetailView {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open_send_patch(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
|
||||||
let Some(addr) = self.store.read(cx).addr().cloned() else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
let id = SharedString::from(format!("send-patch:{addr}"));
|
|
||||||
let workspace = self.workspace.clone();
|
|
||||||
let workspace_for_build = workspace.clone();
|
|
||||||
let store = self.store.clone();
|
|
||||||
|
|
||||||
crate::shared::panels::open_detail(
|
|
||||||
&workspace,
|
|
||||||
id.clone(),
|
|
||||||
"Send patch",
|
|
||||||
move |window, cx| {
|
|
||||||
cx.new(|cx| {
|
|
||||||
SendPatchView::new(
|
|
||||||
workspace_for_build.clone(),
|
|
||||||
id.clone(),
|
|
||||||
store.clone(),
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn open_issues(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
|
||||||
let Some(addr) = self.store.read(cx).addr().cloned() else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
let id = SharedString::from(format!("issues:{addr}"));
|
|
||||||
let workspace = self.workspace.clone();
|
|
||||||
let workspace_for_build = workspace.clone();
|
|
||||||
let store = self.store.clone();
|
|
||||||
|
|
||||||
crate::shared::panels::open_detail(
|
|
||||||
&workspace,
|
|
||||||
id,
|
|
||||||
"Issues",
|
|
||||||
move |_, cx| {
|
|
||||||
cx.new(|cx| IssuesView::new(workspace_for_build.clone(), store.clone(), cx))
|
|
||||||
},
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(super) fn render_header(&mut self, cx: &mut Context<Self>) -> AnyElement {
|
pub(super) fn render_header(&mut self, cx: &mut Context<Self>) -> AnyElement {
|
||||||
if self.store.read(cx).addr().is_none() {
|
if self.store.read(cx).addr().is_none() {
|
||||||
return self.render_local_header(cx);
|
return self.render_local_header(cx);
|
||||||
@@ -249,90 +174,6 @@ impl RepoDetailView {
|
|||||||
.flex_none()
|
.flex_none()
|
||||||
.gap_2()
|
.gap_2()
|
||||||
.justify_end()
|
.justify_end()
|
||||||
.child({
|
|
||||||
let weak_pulls = cx.entity().downgrade();
|
|
||||||
let weak_pulls_open = cx.entity().downgrade();
|
|
||||||
let _store_for_pulls = self.store.clone();
|
|
||||||
let pulls_count = self.store.read(cx).pull_request_count();
|
|
||||||
|
|
||||||
DropdownMenu::new("pulls")
|
|
||||||
.label(format!("Pull requests {pulls_count}"))
|
|
||||||
.icon(Icon::named(CustomIconName::GitPullRequest))
|
|
||||||
.variant(ButtonVariant::Secondary)
|
|
||||||
.open(self.pulls_menu_open)
|
|
||||||
.on_click(move |_, window, cx| {
|
|
||||||
if let Err(error) = weak_pulls.update(cx, |this, cx| {
|
|
||||||
this.open_pulls(window, cx);
|
|
||||||
}) {
|
|
||||||
log::warn!("failed to open pull requests: {error}");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.on_open_change(move |open, _, cx| {
|
|
||||||
if let Err(error) = weak_pulls_open.update(cx, |this, cx| {
|
|
||||||
this.pulls_menu_open = open;
|
|
||||||
cx.notify();
|
|
||||||
}) {
|
|
||||||
log::warn!("failed to update pulls menu: {error}");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.items({
|
|
||||||
let weak_new = cx.entity().downgrade();
|
|
||||||
let weak_patch = cx.entity().downgrade();
|
|
||||||
move |_, _| {
|
|
||||||
let weak_new = weak_new.clone();
|
|
||||||
let weak_patch = weak_patch.clone();
|
|
||||||
vec![
|
|
||||||
MenuItem::new("New pull request").handler(move |window, cx| {
|
|
||||||
crate::shared::log_dropped(weak_new.update(cx, |this, cx| {
|
|
||||||
this.open_new_pull_request(window, cx);
|
|
||||||
}));
|
|
||||||
}),
|
|
||||||
MenuItem::new("Send patch").handler(move |window, cx| {
|
|
||||||
crate::shared::log_dropped(weak_patch.update(cx, |this, cx| {
|
|
||||||
this.open_send_patch(window, cx);
|
|
||||||
}));
|
|
||||||
}),
|
|
||||||
]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.child({
|
|
||||||
let weak_issues = cx.entity().downgrade();
|
|
||||||
let weak_issues_open = cx.entity().downgrade();
|
|
||||||
let store_for_issues = self.store.clone();
|
|
||||||
let issues_count = self.store.read(cx).issue_count();
|
|
||||||
|
|
||||||
DropdownMenu::new("issues")
|
|
||||||
.label(format!("Issues {issues_count}"))
|
|
||||||
.icon(Icon::named(CustomIconName::GitIssueDone))
|
|
||||||
.variant(ButtonVariant::Secondary)
|
|
||||||
.open(self.issues_menu_open)
|
|
||||||
.on_click(move |_, window, cx| {
|
|
||||||
if let Err(error) = weak_issues.update(cx, |this, cx| {
|
|
||||||
this.open_issues(window, cx);
|
|
||||||
}) {
|
|
||||||
log::warn!("failed to open issues: {error}");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.on_open_change(move |open, _, cx| {
|
|
||||||
if let Err(error) =
|
|
||||||
weak_issues_open.update(cx, |this, cx| {
|
|
||||||
this.issues_menu_open = open;
|
|
||||||
cx.notify();
|
|
||||||
})
|
|
||||||
{
|
|
||||||
log::warn!("failed to update issues menu: {error}");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.items(move |_, _| {
|
|
||||||
vec![MenuItem::new("New issue").handler({
|
|
||||||
let store = store_for_issues.clone();
|
|
||||||
move |_, cx| {
|
|
||||||
crate::issues::new_issue::open(store.clone(), cx);
|
|
||||||
}
|
|
||||||
})]
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.child(
|
.child(
|
||||||
DropdownMenu::new("share")
|
DropdownMenu::new("share")
|
||||||
.icon(Icon::named(IconRole::Copy))
|
.icon(Icon::named(IconRole::Copy))
|
||||||
@@ -526,7 +367,6 @@ impl RepoDetailView {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.child(self.render_tabs(cx))
|
|
||||||
.into_any_element()
|
.into_any_element()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -593,37 +433,6 @@ impl RepoDetailView {
|
|||||||
)
|
)
|
||||||
.child(action),
|
.child(action),
|
||||||
)
|
)
|
||||||
.child(self.render_tabs(cx))
|
|
||||||
.into_any_element()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn render_tabs(&self, cx: &mut Context<Self>) -> AnyElement {
|
|
||||||
let count = self.history.read(cx).commit_count();
|
|
||||||
let muted = cx.theme().colors.muted_foreground;
|
|
||||||
let weak = cx.entity().downgrade();
|
|
||||||
let commits_label = match count {
|
|
||||||
Some(count) => SharedString::from(format!("Commits ({count})")),
|
|
||||||
None => SharedString::from("Commits"),
|
|
||||||
};
|
|
||||||
|
|
||||||
Tabs::new("repo-tabs")
|
|
||||||
.selected(self.active_tab)
|
|
||||||
.tabs(move |_, _| {
|
|
||||||
vec![
|
|
||||||
Tab::new("files", "Files")
|
|
||||||
.lead(Icon::named(CustomIconName::GitFile).color(muted)),
|
|
||||||
Tab::new("commits", commits_label.clone())
|
|
||||||
.lead(Icon::named(CustomIconName::GitCommit).color(muted)),
|
|
||||||
]
|
|
||||||
})
|
|
||||||
.on_change(move |index, _, cx| {
|
|
||||||
if let Err(error) = weak.update(cx, |this, cx| {
|
|
||||||
this.active_tab = index;
|
|
||||||
cx.notify();
|
|
||||||
}) {
|
|
||||||
log::warn!("failed to switch repo tab: {error}");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.into_any_element()
|
.into_any_element()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ 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, Styled as _, Subscription, Task,
|
ParentElement as _, PathPromptOptions, Render, SharedString, StatefulInteractiveElement as _,
|
||||||
WeakEntity, Window, div,
|
Styled as _, Subscription, Task, 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;
|
||||||
@@ -42,9 +42,32 @@ use helpers::{RepoData, load_repo_data};
|
|||||||
use history::RepoHistoryView;
|
use history::RepoHistoryView;
|
||||||
use refs::RefSwitcher;
|
use refs::RefSwitcher;
|
||||||
|
|
||||||
|
use crate::issues::IssuesView;
|
||||||
|
use crate::pull_requests::PullRequestsView;
|
||||||
use crate::shared::tree::{build_tree_items, sorted_worktree_paths};
|
use crate::shared::tree::{build_tree_items, sorted_worktree_paths};
|
||||||
use crate::workspace::Workspace;
|
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)]
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum RefKind {
|
pub enum RefKind {
|
||||||
/// HEAD stays attached.
|
/// HEAD stays attached.
|
||||||
@@ -58,12 +81,16 @@ pub struct RepoDetailView {
|
|||||||
pub(super) store: Entity<RepoStore>,
|
pub(super) store: Entity<RepoStore>,
|
||||||
/// A repository opened by address alone starts without an announcement.
|
/// A repository opened by address alone starts without an announcement.
|
||||||
repo_started: bool,
|
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>,
|
files: Entity<RepoFilesView>,
|
||||||
/// The Commits tab, which walks HEAD and opens commit diffs.
|
/// The commit history section.
|
||||||
pub(super) history: Entity<RepoHistoryView>,
|
pub(super) history: Entity<RepoHistoryView>,
|
||||||
/// The active tab: Files or Commits.
|
/// The issues list shown in the repository panel.
|
||||||
pub(super) active_tab: usize,
|
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.
|
/// The checked-out worktree path.
|
||||||
worktree: Option<PathBuf>,
|
worktree: Option<PathBuf>,
|
||||||
loading: bool,
|
loading: bool,
|
||||||
@@ -79,8 +106,6 @@ pub struct RepoDetailView {
|
|||||||
pub(super) share_open: bool,
|
pub(super) share_open: bool,
|
||||||
pub(super) repo_menu_open: bool,
|
pub(super) repo_menu_open: bool,
|
||||||
pub(super) clone_open: bool,
|
pub(super) clone_open: bool,
|
||||||
pub(super) issues_menu_open: bool,
|
|
||||||
pub(super) pulls_menu_open: bool,
|
|
||||||
_subscriptions: Vec<Subscription>,
|
_subscriptions: Vec<Subscription>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,14 +154,24 @@ impl RepoDetailView {
|
|||||||
let checkouts = CheckoutsStore::global(cx);
|
let checkouts = CheckoutsStore::global(cx);
|
||||||
let files = cx.new(RepoFilesView::new);
|
let files = cx.new(RepoFilesView::new);
|
||||||
let history = cx.new(|_| RepoHistoryView::new(store.clone(), workspace.clone()));
|
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 weak = cx.entity().downgrade();
|
||||||
let refs = RefSwitcher::new(weak.clone(), window, cx);
|
let refs = RefSwitcher::new(weak.clone(), window, cx);
|
||||||
|
|
||||||
let subscriptions = vec![cx.observe(&checkouts, |this, _checkouts, cx| {
|
let subscriptions = vec![
|
||||||
if this.refresh_statuses(cx) {
|
cx.observe(&checkouts, |this, _checkouts, cx| {
|
||||||
cx.notify();
|
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();
|
let store_for_attach = store.clone();
|
||||||
window.defer(cx, move |window, cx| {
|
window.defer(cx, move |window, cx| {
|
||||||
@@ -152,7 +187,9 @@ impl RepoDetailView {
|
|||||||
repo_started: false,
|
repo_started: false,
|
||||||
files,
|
files,
|
||||||
history,
|
history,
|
||||||
active_tab: 0,
|
issues,
|
||||||
|
pulls,
|
||||||
|
active_section: RepoSection::Files,
|
||||||
worktree: None,
|
worktree: None,
|
||||||
loading: true,
|
loading: true,
|
||||||
error: None,
|
error: None,
|
||||||
@@ -165,8 +202,6 @@ impl RepoDetailView {
|
|||||||
share_open: false,
|
share_open: false,
|
||||||
repo_menu_open: false,
|
repo_menu_open: false,
|
||||||
clone_open: false,
|
clone_open: false,
|
||||||
issues_menu_open: false,
|
|
||||||
pulls_menu_open: false,
|
|
||||||
_subscriptions: subscriptions,
|
_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 {
|
if self.loading {
|
||||||
let label = if self.store.read(cx).path.is_some() {
|
let label = if self.store.read(cx).path.is_some() {
|
||||||
"Loading repository..."
|
"Loading repository..."
|
||||||
@@ -1181,7 +1216,109 @@ impl RepoDetailView {
|
|||||||
.into_any_element();
|
.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 {
|
.child(
|
||||||
0 => this.child(self.render_files_tab(cx)),
|
h_flex()
|
||||||
_ => this.child(self.history.clone()),
|
.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)),
|
||||||
|
),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user