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 gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AnyElement, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render,
|
||||
SharedString, Styled as _, Task, WeakEntity, Window, div, px,
|
||||
AnyElement, App, AppContext as _, Context, Entity, EventEmitter, IntoElement,
|
||||
ParentElement as _, SharedString, Styled as _, Task, WeakEntity, Window, div, px,
|
||||
};
|
||||
use gpui_native_kit::common::{h_flex, v_flex};
|
||||
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::widgets::empty_state;
|
||||
|
||||
const TREE_WIDTH: f32 = 240.;
|
||||
const MAX_PREVIEW_BYTES: usize = 1024 * 1024;
|
||||
const MAX_PREVIEWED_FILES: usize = 32;
|
||||
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 {
|
||||
Text(String),
|
||||
Binary,
|
||||
@@ -68,6 +73,8 @@ pub struct RepoFilesView {
|
||||
tasks: Vec<Task<Result<(), Error>>>,
|
||||
}
|
||||
|
||||
impl EventEmitter<RepoFilesEvent> for RepoFilesView {}
|
||||
|
||||
impl RepoFilesView {
|
||||
pub fn new(_cx: &mut Context<Self>) -> Self {
|
||||
Self {
|
||||
@@ -237,81 +244,72 @@ impl RepoFilesView {
|
||||
} else {
|
||||
self.open_file(&id, window, cx);
|
||||
}
|
||||
cx.emit(RepoFilesEvent::Activated);
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn render_tree_column(
|
||||
&self,
|
||||
rows: Vec<TreeRow>,
|
||||
selected: Option<usize>,
|
||||
view: WeakEntity<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> impl IntoElement {
|
||||
pub fn render_tree(&self, view: WeakEntity<Self>) -> AnyElement {
|
||||
let rows = self.rows.clone();
|
||||
let selected = self.selected_index;
|
||||
let change_view = view.clone();
|
||||
let disclosure_view = view;
|
||||
|
||||
v_flex()
|
||||
.h_full()
|
||||
.w(px(TREE_WIDTH))
|
||||
.p_2()
|
||||
.flex_none()
|
||||
.border_r_1()
|
||||
.border_color(cx.theme().colors.border)
|
||||
div()
|
||||
.flex_1()
|
||||
.min_h_0()
|
||||
.w_full()
|
||||
.child(
|
||||
div().flex_1().min_h_0().child(
|
||||
Tree::new("repo-tree")
|
||||
.selected(selected)
|
||||
.items(move |_, _| {
|
||||
rows.iter()
|
||||
.map(|row| {
|
||||
let item = TreeItem::new(row.id.clone(), row.label.clone())
|
||||
.depth(row.depth)
|
||||
.expandable(row.expandable)
|
||||
.expanded(row.expanded);
|
||||
Tree::new("repo-tree")
|
||||
.selected(selected)
|
||||
.items(move |_, _| {
|
||||
rows.iter()
|
||||
.map(|row| {
|
||||
let item = TreeItem::new(row.id.clone(), row.label.clone())
|
||||
.depth(row.depth)
|
||||
.expandable(row.expandable)
|
||||
.expanded(row.expanded);
|
||||
|
||||
if row.expandable {
|
||||
item.icon(Icon::named(IconRole::Folder))
|
||||
} else {
|
||||
item.icon(Icon::named(IconRole::File))
|
||||
}
|
||||
if row.expandable {
|
||||
item.icon(Icon::named(IconRole::Folder))
|
||||
} else {
|
||||
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()
|
||||
})
|
||||
.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}");
|
||||
}
|
||||
{
|
||||
log::warn!("failed to activate tree row: {error}");
|
||||
}
|
||||
})
|
||||
.on_disclosure({
|
||||
let view = disclosure_view;
|
||||
move |index, _, cx| {
|
||||
if let Err(error) = view.update(cx, |this, cx| {
|
||||
let id = this.rows.get(index).map(|row| row.id.clone());
|
||||
if let Some(id) = id {
|
||||
this.toggle_folder(&id);
|
||||
cx.notify();
|
||||
}
|
||||
}) {
|
||||
log::warn!("failed to toggle folder: {error}");
|
||||
}
|
||||
})
|
||||
.on_disclosure({
|
||||
let view = disclosure_view;
|
||||
move |index, _, cx| {
|
||||
if let Err(error) = view.update(cx, |this, cx| {
|
||||
let id = this.rows.get(index).map(|row| row.id.clone());
|
||||
if let Some(id) = id {
|
||||
this.toggle_folder(&id);
|
||||
cx.emit(RepoFilesEvent::Activated);
|
||||
cx.notify();
|
||||
}
|
||||
}) {
|
||||
log::warn!("failed to toggle folder: {error}");
|
||||
}
|
||||
}),
|
||||
),
|
||||
}
|
||||
}),
|
||||
)
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
fn render_content_column(
|
||||
&self,
|
||||
pane_title: SharedString,
|
||||
cx: &mut Context<Self>,
|
||||
) -> impl IntoElement {
|
||||
pub fn render_content(&self, cx: &App) -> AnyElement {
|
||||
let pane_title = self.pane_title();
|
||||
let body: AnyElement = if let Some(path) = self.selected_file.clone() {
|
||||
match self.files.get(path.as_ref()) {
|
||||
Some(FileContent::Text(_)) => {
|
||||
@@ -383,6 +381,7 @@ impl RepoFilesView {
|
||||
}),
|
||||
)
|
||||
.child(div().flex_1().min_h_0().child(body))
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
fn set_markdown(
|
||||
@@ -709,19 +708,3 @@ impl RepoFilesView {
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user