update
Rust / build (macos-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (push) Waiting to run
Rust / build (macos-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (pull_request) Waiting to run
Rust / build (macos-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (push) Waiting to run
Rust / build (macos-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (pull_request) Waiting to run
This commit is contained in:
@@ -119,10 +119,11 @@ impl Render for AppRoot {
|
|||||||
.child(titlebar_view.render_explore())
|
.child(titlebar_view.render_explore())
|
||||||
.child(titlebar_view.repository_switcher());
|
.child(titlebar_view.repository_switcher());
|
||||||
|
|
||||||
let tab_bar = h_flex().gap_1().when_some(
|
let tab_bar = h_flex()
|
||||||
titlebar_view.render_repo_tabs(workspace.open_mains(), workspace.active_main_id()),
|
.gap_1()
|
||||||
|bar, tabs| bar.child(tabs),
|
.when_some(titlebar_view.render_repo_tabs(workspace), |bar, tabs| {
|
||||||
);
|
bar.child(tabs)
|
||||||
|
});
|
||||||
|
|
||||||
div()
|
div()
|
||||||
.relative()
|
.relative()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use gpui::{
|
use gpui::{
|
||||||
Context, IntoElement, ParentElement as _, Render, SharedString, Styled as _, Window, div,
|
App, Context, IntoElement, ParentElement as _, Render, SharedString, Styled as _, Window, div,
|
||||||
};
|
};
|
||||||
use ui::empty_state::EmptyState;
|
use ui::empty_state::EmptyState;
|
||||||
use ui::layout::panel::Panel;
|
use ui::layout::panel::Panel;
|
||||||
@@ -17,7 +17,11 @@ impl PlaceholderView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Panel for PlaceholderView {}
|
impl Panel for PlaceholderView {
|
||||||
|
fn title(&self, _cx: &App) -> SharedString {
|
||||||
|
self.title.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Render for PlaceholderView {
|
impl Render for PlaceholderView {
|
||||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use gpui::{
|
use gpui::{
|
||||||
Context, FontWeight, IntoElement, ParentElement as _, Render, Styled as _, Window, div,
|
App, Context, FontWeight, IntoElement, ParentElement as _, Render, SharedString, Styled as _,
|
||||||
|
Window, div,
|
||||||
};
|
};
|
||||||
use ui::button::{Button, ButtonVariant};
|
use ui::button::{Button, ButtonVariant};
|
||||||
use ui::common::v_flex;
|
use ui::common::v_flex;
|
||||||
@@ -15,7 +16,11 @@ impl SignedOutView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Panel for SignedOutView {}
|
impl Panel for SignedOutView {
|
||||||
|
fn title(&self, _cx: &App) -> SharedString {
|
||||||
|
SharedString::from("Signed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Render for SignedOutView {
|
impl Render for SignedOutView {
|
||||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
|||||||
@@ -19,9 +19,8 @@ const RECENT_COUNT: usize = 10;
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||||
pub(super) enum RepoFilter {
|
pub(super) enum RepoFilter {
|
||||||
All,
|
|
||||||
#[default]
|
#[default]
|
||||||
Popular,
|
All,
|
||||||
Recent,
|
Recent,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,14 +42,6 @@ impl RepoFilter {
|
|||||||
match self {
|
match self {
|
||||||
Self::All => {}
|
Self::All => {}
|
||||||
Self::Recent => indices.truncate(RECENT_COUNT),
|
Self::Recent => indices.truncate(RECENT_COUNT),
|
||||||
Self::Popular => {
|
|
||||||
let counts = &store.counts;
|
|
||||||
let scores: Vec<u32> = announcements
|
|
||||||
.iter()
|
|
||||||
.map(|a| counts.get(&a.addr()).map_or(0, |c| c.score()))
|
|
||||||
.collect();
|
|
||||||
indices.sort_by(|&a, &b| scores[b].cmp(&scores[a]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
indices
|
indices
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
mod helpers;
|
mod helpers;
|
||||||
|
|
||||||
use gpui::prelude::FluentBuilder as _;
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ListAlignment, ListState,
|
||||||
ParentElement as _, Render, SharedString, Styled as _, Subscription, UniformListScrollHandle,
|
ParentElement as _, Render, SharedString, Styled as _, Subscription, WeakEntity, Window, div,
|
||||||
WeakEntity, Window, div, px, uniform_list,
|
list, px,
|
||||||
};
|
};
|
||||||
use helpers::{RepoFilter, render_card};
|
use helpers::{RepoFilter, render_card};
|
||||||
use metadata::ProfileDirectory;
|
use metadata::ProfileDirectory;
|
||||||
@@ -17,7 +16,7 @@ use ui::input::{Input, InputState, InputStateEvent};
|
|||||||
use ui::layout::panel::Panel;
|
use ui::layout::panel::Panel;
|
||||||
use ui::scrollbar::Scrollbar;
|
use ui::scrollbar::Scrollbar;
|
||||||
use ui::segmented::{Segmented, SegmentedOption};
|
use ui::segmented::{Segmented, SegmentedOption};
|
||||||
use ui::theme::{ActiveTheme as _, TextRole, Typeset as _};
|
use ui::theme::ActiveTheme as _;
|
||||||
|
|
||||||
use crate::shared::panels;
|
use crate::shared::panels;
|
||||||
use crate::workspace::Workspace;
|
use crate::workspace::Workspace;
|
||||||
@@ -28,7 +27,7 @@ const CARD_HEIGHT: f32 = 40. + 64. + 48. + 2. + 6.;
|
|||||||
pub struct ExploreView {
|
pub struct ExploreView {
|
||||||
store: Entity<RepoListStore>,
|
store: Entity<RepoListStore>,
|
||||||
workspace: WeakEntity<Workspace>,
|
workspace: WeakEntity<Workspace>,
|
||||||
scroll_handle: UniformListScrollHandle,
|
scroll_handle: ListState,
|
||||||
filter: RepoFilter,
|
filter: RepoFilter,
|
||||||
/// Indices matching [`Self::filter`] into the store's `announcements`.
|
/// Indices matching [`Self::filter`] into the store's `announcements`.
|
||||||
visible: Vec<usize>,
|
visible: Vec<usize>,
|
||||||
@@ -83,7 +82,7 @@ impl ExploreView {
|
|||||||
Self {
|
Self {
|
||||||
store,
|
store,
|
||||||
workspace,
|
workspace,
|
||||||
scroll_handle: UniformListScrollHandle::new(),
|
scroll_handle: ListState::new(0, ListAlignment::Top, px(320.)),
|
||||||
filter: RepoFilter::default(),
|
filter: RepoFilter::default(),
|
||||||
visible: Vec::new(),
|
visible: Vec::new(),
|
||||||
search,
|
search,
|
||||||
@@ -111,44 +110,60 @@ impl ExploreView {
|
|||||||
directory.track(owners, cx);
|
directory.track(owners, cx);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
self.scroll_handle.reset(self.item_count());
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_header(&self, count: usize, cx: &mut Context<Self>) -> AnyElement {
|
/// Header row, plus one row per card row, or the empty state when nothing matches.
|
||||||
let muted = cx.theme().colors.muted_foreground;
|
fn item_count(&self) -> usize {
|
||||||
let weak = cx.entity().downgrade();
|
if self.visible.is_empty() {
|
||||||
|
2
|
||||||
|
} else {
|
||||||
|
self.visible.len().div_ceil(COLUMNS) + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
h_flex()
|
fn render_header(
|
||||||
.px_4()
|
search: Entity<InputState>,
|
||||||
.py_2()
|
filter: RepoFilter,
|
||||||
|
weak: WeakEntity<Self>,
|
||||||
|
cx: &App,
|
||||||
|
) -> AnyElement {
|
||||||
|
let muted = cx.theme().colors.muted_foreground;
|
||||||
|
|
||||||
|
div()
|
||||||
|
.relative()
|
||||||
|
.h_96()
|
||||||
.w_full()
|
.w_full()
|
||||||
.gap_3()
|
|
||||||
.child(
|
|
||||||
v_flex()
|
|
||||||
.gap_1()
|
|
||||||
.child(div().typeset(TextRole::Caption2, cx).child("Repositories"))
|
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.typeset(TextRole::Caption, cx)
|
.absolute()
|
||||||
.text_color(muted)
|
.inset_0()
|
||||||
.child(SharedString::from(format!("Total: {count}"))),
|
.flex()
|
||||||
),
|
.items_center()
|
||||||
)
|
.justify_center()
|
||||||
|
.px_4()
|
||||||
.child(
|
.child(
|
||||||
div().w(px(180.)).child(
|
div().w_full().max_w(px(480.)).child(
|
||||||
Input::new("explore-search", self.search.clone())
|
Input::new("explore-search", search)
|
||||||
.placeholder("Search...")
|
.placeholder("Search...")
|
||||||
|
.fully_rounded(true)
|
||||||
.prefix(Icon::named(IconRole::Search).small().color(muted)),
|
.prefix(Icon::named(IconRole::Search).small().color(muted)),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.child(div().flex_1())
|
|
||||||
.child(
|
.child(
|
||||||
Segmented::new("explore-filter", self.filter)
|
div()
|
||||||
|
.absolute()
|
||||||
|
.left_0()
|
||||||
|
.bottom_0()
|
||||||
|
.pl_4()
|
||||||
|
.pb_4()
|
||||||
|
.child(
|
||||||
|
Segmented::new("explore-filter", filter)
|
||||||
.options(vec![
|
.options(vec![
|
||||||
SegmentedOption::new(RepoFilter::All, "All")
|
SegmentedOption::new(RepoFilter::All, "All")
|
||||||
.icon(Icon::named(IconRole::Grid).small().color(muted)),
|
.icon(Icon::named(IconRole::Grid).small().color(muted)),
|
||||||
SegmentedOption::new(RepoFilter::Popular, "Popular")
|
|
||||||
.icon(Icon::named(IconRole::Trending).small().color(muted)),
|
|
||||||
SegmentedOption::new(RepoFilter::Recent, "Recent")
|
SegmentedOption::new(RepoFilter::Recent, "Recent")
|
||||||
.icon(Icon::named(IconRole::Clock).small().color(muted)),
|
.icon(Icon::named(IconRole::Clock).small().color(muted)),
|
||||||
])
|
])
|
||||||
@@ -160,43 +175,61 @@ impl ExploreView {
|
|||||||
log::warn!("failed to change explore filter: {error}");
|
log::warn!("failed to change explore filter: {error}");
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.into_any_element()
|
.into_any_element()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Panel for ExploreView {}
|
impl Panel for ExploreView {
|
||||||
|
fn title(&self, _cx: &App) -> SharedString {
|
||||||
|
SharedString::from("Explore")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn prefix(&self, cx: &App) -> Option<AnyElement> {
|
||||||
|
Some(
|
||||||
|
Icon::named(IconRole::Grid)
|
||||||
|
.small()
|
||||||
|
.color(cx.theme().colors.muted_foreground)
|
||||||
|
.into_any_element(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Render for ExploreView {
|
impl Render for ExploreView {
|
||||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
let store = self.store.read(cx);
|
let store = self.store.read(cx);
|
||||||
let announcements = store.announcements.clone();
|
let announcements = store.announcements.clone();
|
||||||
let last_activity = store.last_activity.clone();
|
let last_activity = store.last_activity.clone();
|
||||||
let count = self.visible.len();
|
|
||||||
let visible = self.visible.clone();
|
let visible = self.visible.clone();
|
||||||
let directory = self.directory.clone();
|
let directory = self.directory.clone();
|
||||||
let workspace = self.workspace.clone();
|
let workspace = self.workspace.clone();
|
||||||
let has_repos = count > 0;
|
let has_repos = !visible.is_empty();
|
||||||
let rows = visible.len().div_ceil(COLUMNS);
|
let search = self.search.clone();
|
||||||
|
let filter = self.filter;
|
||||||
|
let weak = cx.entity().downgrade();
|
||||||
|
let scroll_handle = self.scroll_handle.clone();
|
||||||
|
|
||||||
v_flex()
|
div()
|
||||||
.relative()
|
.relative()
|
||||||
.size_full()
|
.size_full()
|
||||||
.child(self.render_header(count, cx))
|
.child(
|
||||||
.when(!has_repos, |this| {
|
list(self.scroll_handle.clone(), move |item, _, cx| {
|
||||||
this.child(
|
if item == 0 {
|
||||||
v_flex()
|
return Self::render_header(search.clone(), filter, weak.clone(), cx);
|
||||||
.size_full()
|
}
|
||||||
|
|
||||||
|
if !has_repos {
|
||||||
|
return v_flex()
|
||||||
|
.w_full()
|
||||||
|
.h(px(320.))
|
||||||
.items_center()
|
.items_center()
|
||||||
.justify_center()
|
.justify_center()
|
||||||
.child(EmptyState::new("No repositories match your search")),
|
.child(EmptyState::new("No repositories match your search"))
|
||||||
)
|
.into_any_element();
|
||||||
})
|
}
|
||||||
.when(has_repos, |this| {
|
|
||||||
this.child(
|
let row = item - 1;
|
||||||
uniform_list("explore-repos", rows, move |range, _, cx| {
|
|
||||||
range
|
|
||||||
.map(|row| {
|
|
||||||
let mut cards = Vec::with_capacity(COLUMNS);
|
let mut cards = Vec::with_capacity(COLUMNS);
|
||||||
|
|
||||||
for col in 0..COLUMNS {
|
for col in 0..COLUMNS {
|
||||||
@@ -219,7 +252,6 @@ impl Render for ExploreView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h_flex()
|
h_flex()
|
||||||
.id(row)
|
|
||||||
.w_full()
|
.w_full()
|
||||||
.h(px(CARD_HEIGHT))
|
.h(px(CARD_HEIGHT))
|
||||||
.gap_3()
|
.gap_3()
|
||||||
@@ -228,12 +260,8 @@ impl Render for ExploreView {
|
|||||||
.children(cards)
|
.children(cards)
|
||||||
.into_any_element()
|
.into_any_element()
|
||||||
})
|
})
|
||||||
.collect()
|
|
||||||
})
|
|
||||||
.track_scroll(&self.scroll_handle)
|
|
||||||
.size_full(),
|
.size_full(),
|
||||||
)
|
)
|
||||||
})
|
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.absolute()
|
.absolute()
|
||||||
@@ -241,10 +269,7 @@ impl Render for ExploreView {
|
|||||||
.left_0()
|
.left_0()
|
||||||
.right_0()
|
.right_0()
|
||||||
.bottom_0()
|
.bottom_0()
|
||||||
.child(Scrollbar::vertical(
|
.child(Scrollbar::vertical("explore-scroll", scroll_handle)),
|
||||||
"explore-scroll",
|
|
||||||
self.scroll_handle.clone(),
|
|
||||||
)),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -392,7 +392,11 @@ impl InboxView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Panel for InboxView {}
|
impl Panel for InboxView {
|
||||||
|
fn title(&self, _cx: &App) -> SharedString {
|
||||||
|
SharedString::from("Inbox")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Render for InboxView {
|
impl Render for InboxView {
|
||||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use gpui::{
|
use gpui::{
|
||||||
Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _, Render,
|
App, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _, Render,
|
||||||
ScrollHandle, SharedString, Styled as _, Subscription, Window, div,
|
ScrollHandle, SharedString, Styled as _, Subscription, Window, div,
|
||||||
};
|
};
|
||||||
use metadata::ProfileDirectory;
|
use metadata::ProfileDirectory;
|
||||||
@@ -80,7 +80,17 @@ impl IssueDetailView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Panel for IssueDetailView {}
|
impl Panel for IssueDetailView {
|
||||||
|
fn title(&self, _cx: &App) -> SharedString {
|
||||||
|
let hex = self.issue_id.to_hex();
|
||||||
|
let short = hex.get(..8).unwrap_or(&hex);
|
||||||
|
SharedString::from(format!("Issue {short}"))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn loading(&self, cx: &App) -> bool {
|
||||||
|
!self.store.read(cx).loaded
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Render for IssueDetailView {
|
impl Render for IssueDetailView {
|
||||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use gpui::prelude::FluentBuilder as _;
|
use gpui::prelude::FluentBuilder as _;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AnyElement, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
||||||
ParentElement as _, Render, SharedString, StatefulInteractiveElement as _, Styled as _,
|
ParentElement as _, Render, SharedString, StatefulInteractiveElement as _, Styled as _,
|
||||||
Subscription, UniformListScrollHandle, WeakEntity, Window, div, px, uniform_list,
|
Subscription, UniformListScrollHandle, WeakEntity, Window, div, px, uniform_list,
|
||||||
};
|
};
|
||||||
@@ -166,7 +166,11 @@ impl IssuesView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Panel for IssuesView {}
|
impl Panel for IssuesView {
|
||||||
|
fn title(&self, _cx: &App) -> SharedString {
|
||||||
|
SharedString::from("Issues")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Render for IssuesView {
|
impl Render for IssuesView {
|
||||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
@@ -215,15 +219,10 @@ impl Render for IssuesView {
|
|||||||
.on_click(move |_, window, cx| {
|
.on_click(move |_, window, cx| {
|
||||||
let id =
|
let id =
|
||||||
SharedString::from(format!("issue:{issue_id}"));
|
SharedString::from(format!("issue:{issue_id}"));
|
||||||
let hex = issue_id.to_hex();
|
|
||||||
let short = hex.get(..8).unwrap_or(&hex);
|
|
||||||
let label =
|
|
||||||
SharedString::from(format!("Issue {short}"));
|
|
||||||
let store = store.clone();
|
let store = store.clone();
|
||||||
panels::open_detail(
|
panels::open_detail(
|
||||||
&workspace,
|
&workspace,
|
||||||
id,
|
id,
|
||||||
label,
|
|
||||||
move |_, cx| {
|
move |_, cx| {
|
||||||
cx.new(|cx| {
|
cx.new(|cx| {
|
||||||
IssueDetailView::new(
|
IssueDetailView::new(
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::path::PathBuf;
|
|||||||
|
|
||||||
use gpui::prelude::FluentBuilder as _;
|
use gpui::prelude::FluentBuilder as _;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AnyElement, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
||||||
ParentElement as _, Render, SharedString, Styled as _, Subscription, UniformListScrollHandle,
|
ParentElement as _, Render, SharedString, Styled as _, Subscription, UniformListScrollHandle,
|
||||||
WeakEntity, Window, div, uniform_list,
|
WeakEntity, Window, div, uniform_list,
|
||||||
};
|
};
|
||||||
@@ -288,13 +288,10 @@ impl PullRequestDetailView {
|
|||||||
None => SharedString::from(format!("commit:{}:{commit_id}", worktree.display())),
|
None => SharedString::from(format!("commit:{}:{commit_id}", worktree.display())),
|
||||||
};
|
};
|
||||||
let workspace = self.workspace.clone();
|
let workspace = self.workspace.clone();
|
||||||
let short = commit_id.get(..8).unwrap_or(commit_id);
|
|
||||||
let label = SharedString::from(format!("Commit {short}"));
|
|
||||||
let commit_id = commit_id.to_owned();
|
let commit_id = commit_id.to_owned();
|
||||||
crate::shared::panels::open_detail(
|
crate::shared::panels::open_detail(
|
||||||
&workspace,
|
&workspace,
|
||||||
id,
|
id,
|
||||||
label,
|
|
||||||
move |window, cx| {
|
move |window, cx| {
|
||||||
cx.new(|cx| CommitDiffView::new(worktree.clone(), commit_id.clone(), window, cx))
|
cx.new(|cx| CommitDiffView::new(worktree.clone(), commit_id.clone(), window, cx))
|
||||||
},
|
},
|
||||||
@@ -579,7 +576,17 @@ impl PullRequestDetailView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Panel for PullRequestDetailView {}
|
impl Panel for PullRequestDetailView {
|
||||||
|
fn title(&self, _cx: &App) -> SharedString {
|
||||||
|
let hex = self.pr_id.to_hex();
|
||||||
|
let short = hex.get(..8).unwrap_or(&hex);
|
||||||
|
SharedString::from(format!("PR {short}"))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn loading(&self, _cx: &App) -> bool {
|
||||||
|
self.loading
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Render for PullRequestDetailView {
|
impl Render for PullRequestDetailView {
|
||||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use gpui::prelude::FluentBuilder as _;
|
use gpui::prelude::FluentBuilder as _;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AnyElement, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
||||||
ParentElement as _, Render, SharedString, StatefulInteractiveElement as _, Styled as _,
|
ParentElement as _, Render, SharedString, StatefulInteractiveElement as _, Styled as _,
|
||||||
Subscription, UniformListScrollHandle, WeakEntity, Window, div, px, uniform_list,
|
Subscription, UniformListScrollHandle, WeakEntity, Window, div, px, uniform_list,
|
||||||
};
|
};
|
||||||
@@ -145,7 +145,6 @@ impl PullRequestsView {
|
|||||||
crate::shared::panels::open_detail(
|
crate::shared::panels::open_detail(
|
||||||
&workspace,
|
&workspace,
|
||||||
id.clone(),
|
id.clone(),
|
||||||
"New pull request",
|
|
||||||
move |window, cx| {
|
move |window, cx| {
|
||||||
cx.new(|cx| {
|
cx.new(|cx| {
|
||||||
NewPullRequestView::new(
|
NewPullRequestView::new(
|
||||||
@@ -175,7 +174,6 @@ impl PullRequestsView {
|
|||||||
crate::shared::panels::open_detail(
|
crate::shared::panels::open_detail(
|
||||||
&workspace,
|
&workspace,
|
||||||
id.clone(),
|
id.clone(),
|
||||||
"Send patch",
|
|
||||||
move |window, cx| {
|
move |window, cx| {
|
||||||
cx.new(|cx| {
|
cx.new(|cx| {
|
||||||
SendPatchView::new(
|
SendPatchView::new(
|
||||||
@@ -279,7 +277,11 @@ impl PullRequestsView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Panel for PullRequestsView {}
|
impl Panel for PullRequestsView {
|
||||||
|
fn title(&self, _cx: &App) -> SharedString {
|
||||||
|
SharedString::from("Pull requests")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Render for PullRequestsView {
|
impl Render for PullRequestsView {
|
||||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
@@ -357,16 +359,11 @@ impl Render for PullRequestsView {
|
|||||||
.hover(|this| this.bg(cx.theme().colors.muted_hover))
|
.hover(|this| this.bg(cx.theme().colors.muted_hover))
|
||||||
.on_click(move |_, window, cx| {
|
.on_click(move |_, window, cx| {
|
||||||
let id = SharedString::from(format!("pr:{pr_id}"));
|
let id = SharedString::from(format!("pr:{pr_id}"));
|
||||||
let hex = pr_id.to_hex();
|
|
||||||
let short = hex.get(..8).unwrap_or(&hex);
|
|
||||||
let label =
|
|
||||||
SharedString::from(format!("PR {short}"));
|
|
||||||
let workspace_for_build = workspace.clone();
|
let workspace_for_build = workspace.clone();
|
||||||
let store = store.clone();
|
let store = store.clone();
|
||||||
crate::shared::panels::open_detail(
|
crate::shared::panels::open_detail(
|
||||||
&workspace,
|
&workspace,
|
||||||
id,
|
id,
|
||||||
label,
|
|
||||||
move |window, cx| {
|
move |window, cx| {
|
||||||
cx.new(|cx| {
|
cx.new(|cx| {
|
||||||
PullRequestDetailView::new(
|
PullRequestDetailView::new(
|
||||||
|
|||||||
@@ -222,13 +222,10 @@ impl NewPullRequestView {
|
|||||||
None => SharedString::from(format!("commit:{}:{commit_id}", repo_path.display())),
|
None => SharedString::from(format!("commit:{}:{commit_id}", repo_path.display())),
|
||||||
};
|
};
|
||||||
let workspace = self.workspace.clone();
|
let workspace = self.workspace.clone();
|
||||||
let short = commit_id.get(..8).unwrap_or(commit_id);
|
|
||||||
let label = SharedString::from(format!("Commit {short}"));
|
|
||||||
let commit_id = commit_id.to_owned();
|
let commit_id = commit_id.to_owned();
|
||||||
crate::shared::panels::open_detail(
|
crate::shared::panels::open_detail(
|
||||||
&workspace,
|
&workspace,
|
||||||
id,
|
id,
|
||||||
label,
|
|
||||||
move |window, cx| {
|
move |window, cx| {
|
||||||
cx.new(|cx| CommitDiffView::new(repo_path.clone(), commit_id.clone(), window, cx))
|
cx.new(|cx| CommitDiffView::new(repo_path.clone(), commit_id.clone(), window, cx))
|
||||||
},
|
},
|
||||||
@@ -443,7 +440,15 @@ impl NewPullRequestView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Panel for NewPullRequestView {}
|
impl Panel for NewPullRequestView {
|
||||||
|
fn title(&self, _cx: &App) -> SharedString {
|
||||||
|
SharedString::from("New pull request")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn loading(&self, _cx: &App) -> bool {
|
||||||
|
self.loading
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Render for NewPullRequestView {
|
impl Render for NewPullRequestView {
|
||||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use gpui::prelude::FluentBuilder as _;
|
use gpui::prelude::FluentBuilder as _;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AnyElement, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _, Render,
|
AnyElement, App, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _,
|
||||||
SharedString, Styled as _, WeakEntity, Window, div,
|
Render, SharedString, Styled as _, WeakEntity, Window, div,
|
||||||
};
|
};
|
||||||
use signed_state::RepoStore;
|
use signed_state::RepoStore;
|
||||||
use ui::button::Button;
|
use ui::button::Button;
|
||||||
@@ -120,7 +120,15 @@ impl SendPatchView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Panel for SendPatchView {}
|
impl Panel for SendPatchView {
|
||||||
|
fn title(&self, _cx: &App) -> SharedString {
|
||||||
|
SharedString::from("Send patch")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn loading(&self, _cx: &App) -> bool {
|
||||||
|
self.submitting
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Render for SendPatchView {
|
impl Render for SendPatchView {
|
||||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
|||||||
@@ -53,14 +53,10 @@ pub fn open_repo_item(
|
|||||||
match item {
|
match item {
|
||||||
RepoItem::Issue(issue_id) => {
|
RepoItem::Issue(issue_id) => {
|
||||||
let id = SharedString::from(format!("issue:{issue_id}"));
|
let id = SharedString::from(format!("issue:{issue_id}"));
|
||||||
let hex = issue_id.to_hex();
|
|
||||||
let short = hex.get(..8).unwrap_or(&hex);
|
|
||||||
let label = SharedString::from(format!("Issue {short}"));
|
|
||||||
let store = store.clone();
|
let store = store.clone();
|
||||||
panels::open_detail(
|
panels::open_detail(
|
||||||
workspace,
|
workspace,
|
||||||
id,
|
id,
|
||||||
label,
|
|
||||||
move |_, cx| {
|
move |_, cx| {
|
||||||
cx.new(|cx| {
|
cx.new(|cx| {
|
||||||
crate::issues::detail::IssueDetailView::new(store.clone(), issue_id, cx)
|
crate::issues::detail::IssueDetailView::new(store.clone(), issue_id, cx)
|
||||||
@@ -72,15 +68,11 @@ pub fn open_repo_item(
|
|||||||
}
|
}
|
||||||
RepoItem::PullRequest(pr_id) => {
|
RepoItem::PullRequest(pr_id) => {
|
||||||
let id = SharedString::from(format!("pr:{pr_id}"));
|
let id = SharedString::from(format!("pr:{pr_id}"));
|
||||||
let hex = pr_id.to_hex();
|
|
||||||
let short = hex.get(..8).unwrap_or(&hex);
|
|
||||||
let label = SharedString::from(format!("PR {short}"));
|
|
||||||
let workspace_for_build = workspace.clone();
|
let workspace_for_build = workspace.clone();
|
||||||
let store = store.clone();
|
let store = store.clone();
|
||||||
panels::open_detail(
|
panels::open_detail(
|
||||||
workspace,
|
workspace,
|
||||||
id,
|
id,
|
||||||
label,
|
|
||||||
move |window, cx| {
|
move |window, cx| {
|
||||||
cx.new(|cx| {
|
cx.new(|cx| {
|
||||||
crate::pull_requests::PullRequestDetailView::new(
|
crate::pull_requests::PullRequestDetailView::new(
|
||||||
|
|||||||
@@ -500,7 +500,16 @@ impl CommitDiffView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Panel for CommitDiffView {}
|
impl Panel for CommitDiffView {
|
||||||
|
fn title(&self, _cx: &App) -> SharedString {
|
||||||
|
let short = self.commit.id.get(..8).unwrap_or(&self.commit.id);
|
||||||
|
SharedString::from(format!("Commit {short}"))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn loading(&self, _cx: &App) -> bool {
|
||||||
|
self.loading
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Render for CommitDiffView {
|
impl Render for CommitDiffView {
|
||||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
|||||||
@@ -88,7 +88,6 @@ impl RepoDetailView {
|
|||||||
crate::shared::panels::open_detail(
|
crate::shared::panels::open_detail(
|
||||||
&workspace,
|
&workspace,
|
||||||
id.clone(),
|
id.clone(),
|
||||||
"New pull request",
|
|
||||||
move |window, cx| {
|
move |window, cx| {
|
||||||
cx.new(|cx| {
|
cx.new(|cx| {
|
||||||
NewPullRequestView::new(
|
NewPullRequestView::new(
|
||||||
|
|||||||
@@ -100,8 +100,6 @@ impl RepoHistoryView {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let store = self.store.clone();
|
let store = self.store.clone();
|
||||||
let short = commit_id.get(..8).unwrap_or(commit_id);
|
|
||||||
let label = SharedString::from(format!("Commit {short}"));
|
|
||||||
let commit_id = commit_id.to_owned();
|
let commit_id = commit_id.to_owned();
|
||||||
let id = match store.read(cx).addr() {
|
let id = match store.read(cx).addr() {
|
||||||
Some(addr) => SharedString::from(format!("commit:{addr}:{commit_id}")),
|
Some(addr) => SharedString::from(format!("commit:{addr}:{commit_id}")),
|
||||||
@@ -112,7 +110,6 @@ impl RepoHistoryView {
|
|||||||
panels::open_detail(
|
panels::open_detail(
|
||||||
&workspace,
|
&workspace,
|
||||||
id,
|
id,
|
||||||
label,
|
|
||||||
move |window, cx| {
|
move |window, cx| {
|
||||||
cx.new(|cx| CommitDiffView::new(worktree.clone(), commit_id.clone(), window, cx))
|
cx.new(|cx| CommitDiffView::new(worktree.clone(), commit_id.clone(), window, cx))
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ use signed_state::{
|
|||||||
Backend, CheckoutsStore, LocalReposStore, Mirrors, Nip34Binding, RepoStore, SyncStatusDirectory,
|
Backend, CheckoutsStore, LocalReposStore, Mirrors, Nip34Binding, RepoStore, SyncStatusDirectory,
|
||||||
};
|
};
|
||||||
use ui::alert::{Alert, AlertSeverity};
|
use ui::alert::{Alert, AlertSeverity};
|
||||||
use ui::common::{h_flex, v_flex};
|
use ui::avatar::Avatar;
|
||||||
|
use ui::common::{Sizable as _, h_flex, v_flex};
|
||||||
use ui::icons::{Icon, IconRole};
|
use ui::icons::{Icon, IconRole};
|
||||||
use ui::layout::panel::Panel;
|
use ui::layout::panel::Panel;
|
||||||
use ui::sidebar::{Sidebar, SidebarEntry};
|
use ui::sidebar::{Sidebar, SidebarEntry};
|
||||||
@@ -922,7 +923,51 @@ impl RepoDetailView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Panel for RepoDetailView {}
|
impl Panel for RepoDetailView {
|
||||||
|
fn title(&self, cx: &App) -> SharedString {
|
||||||
|
let store = self.store.read(cx);
|
||||||
|
if let Some(name) = store.path.as_ref().and_then(|path| path.file_name()) {
|
||||||
|
return SharedString::from(name.to_string_lossy().into_owned());
|
||||||
|
}
|
||||||
|
if let Some(announcement) = store.announcement.as_ref() {
|
||||||
|
return announcement
|
||||||
|
.name
|
||||||
|
.as_deref()
|
||||||
|
.map(SharedString::from)
|
||||||
|
.unwrap_or_else(|| SharedString::from(announcement.id.clone()));
|
||||||
|
}
|
||||||
|
SharedString::from("Repository")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn prefix(&self, cx: &App) -> Option<AnyElement> {
|
||||||
|
let store = self.store.read(cx);
|
||||||
|
let key = match (store.announcement.as_ref(), store.path.as_ref()) {
|
||||||
|
(Some(announcement), _) => SharedString::from(format!("repo:{}", announcement.addr())),
|
||||||
|
(None, Some(path)) => SharedString::from(format!("repo-local:{}", path.display())),
|
||||||
|
(None, None) => SharedString::from("repo"),
|
||||||
|
};
|
||||||
|
let owner = store
|
||||||
|
.nip34
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|binding| binding.owner)
|
||||||
|
.or_else(|| {
|
||||||
|
store
|
||||||
|
.announcement
|
||||||
|
.as_ref()
|
||||||
|
.map(|announcement| announcement.owner)
|
||||||
|
});
|
||||||
|
let mut avatar = Avatar::new(key);
|
||||||
|
if let Some(owner) = owner {
|
||||||
|
let profile = self.directory.read(cx).profile(&owner, cx);
|
||||||
|
avatar = avatar.name(profile.name()).picture(profile.picture());
|
||||||
|
}
|
||||||
|
Some(avatar.small().into_any_element())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn loading(&self, _cx: &App) -> bool {
|
||||||
|
self.loading
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Render for RepoDetailView {
|
impl Render for RepoDetailView {
|
||||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ pub fn open_primary<P, F>(
|
|||||||
pub fn open_detail<P, F>(
|
pub fn open_detail<P, F>(
|
||||||
workspace: &WeakEntity<Workspace>,
|
workspace: &WeakEntity<Workspace>,
|
||||||
id: impl Into<SharedString>,
|
id: impl Into<SharedString>,
|
||||||
label: impl Into<SharedString>,
|
|
||||||
build: F,
|
build: F,
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut App,
|
cx: &mut App,
|
||||||
@@ -50,7 +49,6 @@ pub fn open_detail<P, F>(
|
|||||||
F: Fn(&mut Window, &mut App) -> Entity<P> + 'static,
|
F: Fn(&mut Window, &mut App) -> Entity<P> + 'static,
|
||||||
{
|
{
|
||||||
let id = id.into();
|
let id = id.into();
|
||||||
let label = label.into();
|
|
||||||
|
|
||||||
if workspace
|
if workspace
|
||||||
.read_with(cx, |workspace, _| workspace.has_detail(&id))
|
.read_with(cx, |workspace, _| workspace.has_detail(&id))
|
||||||
@@ -66,7 +64,7 @@ pub fn open_detail<P, F>(
|
|||||||
let view: Arc<dyn PanelView> = Arc::new(build(window, cx));
|
let view: Arc<dyn PanelView> = Arc::new(build(window, cx));
|
||||||
|
|
||||||
if let Err(error) = workspace.update(cx, |workspace, cx| {
|
if let Err(error) = workspace.update(cx, |workspace, cx| {
|
||||||
workspace.show_detail(id.clone(), label, view, cx)
|
workspace.show_detail(id.clone(), view, cx)
|
||||||
}) {
|
}) {
|
||||||
log::warn!("failed to open detail panel {id}: {error}");
|
log::warn!("failed to open detail panel {id}: {error}");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use std::collections::HashMap;
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@@ -16,9 +15,9 @@ use ui::avatar::Avatar;
|
|||||||
use ui::button::{Button, ButtonVariant};
|
use ui::button::{Button, ButtonVariant};
|
||||||
use ui::command_palette::{Command, CommandPalette, CommandPaletteState};
|
use ui::command_palette::{Command, CommandPalette, CommandPaletteState};
|
||||||
use ui::icons::{Icon, IconRole};
|
use ui::icons::{Icon, IconRole};
|
||||||
|
use ui::layout::panel::PanelView;
|
||||||
use ui::menu::{Menu, MenuItem};
|
use ui::menu::{Menu, MenuItem};
|
||||||
use ui::tabs::{Tab, Tabs, TabsVariant};
|
use ui::tabs::{Tab, Tabs, TabsVariant};
|
||||||
use ui::theme::ActiveTheme as _;
|
|
||||||
use ui::tooltip::Tooltip;
|
use ui::tooltip::Tooltip;
|
||||||
|
|
||||||
use crate::explore::ExploreView;
|
use crate::explore::ExploreView;
|
||||||
@@ -340,29 +339,24 @@ impl TitlebarView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Tabs for the repositories opened in the main panel.
|
/// Tabs for the repositories opened in the main panel.
|
||||||
pub fn render_repo_tabs(
|
pub fn render_repo_tabs(&self, workspace: &Workspace) -> Option<Tabs> {
|
||||||
&self,
|
let open = workspace.open_mains();
|
||||||
open: &[SharedString],
|
|
||||||
active: Option<&SharedString>,
|
|
||||||
) -> Option<Tabs> {
|
|
||||||
if open.is_empty() {
|
if open.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let lookup: HashMap<SharedString, RepositoryEntry> = self
|
let tabs: Vec<_> = open
|
||||||
.repository_entries()
|
.iter()
|
||||||
.into_iter()
|
.map(|id| (id.clone(), workspace.main_view(id)))
|
||||||
.map(|entry| (entry.key.clone(), entry))
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let open_tabs = open.to_vec();
|
let selected = workspace
|
||||||
let lookup_for_tabs = lookup;
|
.active_main_id()
|
||||||
let lookup_directory = self.directory.clone();
|
|
||||||
let selected = active
|
|
||||||
.and_then(|id| open.iter().position(|open_id| open_id == id))
|
.and_then(|id| open.iter().position(|open_id| open_id == id))
|
||||||
.unwrap_or(usize::MAX);
|
.unwrap_or(usize::MAX);
|
||||||
|
|
||||||
let workspace = self.workspace.clone();
|
let change_workspace = self.workspace.clone();
|
||||||
let close_workspace = self.workspace.clone();
|
let close_workspace = self.workspace.clone();
|
||||||
let open_for_change = open.to_vec();
|
let open_for_change = open.to_vec();
|
||||||
|
|
||||||
@@ -372,25 +366,10 @@ impl TitlebarView {
|
|||||||
.overflow_scroll(true)
|
.overflow_scroll(true)
|
||||||
.selected(selected)
|
.selected(selected)
|
||||||
.tabs(move |_, cx| {
|
.tabs(move |_, cx| {
|
||||||
open_tabs
|
tabs.iter()
|
||||||
.iter()
|
.map(|(id, view)| match view {
|
||||||
.map(|id| {
|
Some(view) => view.tab(id.clone().into(), cx).closeable(true),
|
||||||
let entry = lookup_for_tabs.get(id);
|
None => Tab::new(id.clone(), id.clone()).closeable(true),
|
||||||
let label = entry
|
|
||||||
.map(|entry| entry.label.clone())
|
|
||||||
.unwrap_or_else(|| id.clone());
|
|
||||||
|
|
||||||
let mut tab = Tab::new(id.clone(), label).closeable(true);
|
|
||||||
if let Some(entry) = entry {
|
|
||||||
tab = tab.lead(entry.avatar(&lookup_directory, cx));
|
|
||||||
} else if *id == ExploreView::PANEL_ID {
|
|
||||||
tab = tab.lead(
|
|
||||||
Icon::named(IconRole::Grid)
|
|
||||||
.small()
|
|
||||||
.color(cx.theme().colors.muted_foreground),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
tab
|
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
})
|
})
|
||||||
@@ -398,7 +377,7 @@ impl TitlebarView {
|
|||||||
let Some(id) = open_for_change.get(index).cloned() else {
|
let Some(id) = open_for_change.get(index).cloned() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
log_dropped(workspace.update(cx, |workspace, cx| {
|
log_dropped(change_workspace.update(cx, |workspace, cx| {
|
||||||
workspace.activate_main(&id, cx);
|
workspace.activate_main(&id, cx);
|
||||||
}));
|
}));
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::collections::HashMap;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
Context, IntoElement, ParentElement as _, Render, SharedString, Styled as _, Window, div,
|
App, Context, IntoElement, ParentElement as _, Render, SharedString, Styled as _, Window, div,
|
||||||
};
|
};
|
||||||
use ui::common::v_flex;
|
use ui::common::v_flex;
|
||||||
use ui::layout::panel::{Panel, PanelView};
|
use ui::layout::panel::{Panel, PanelView};
|
||||||
@@ -16,7 +16,7 @@ pub struct Workspace {
|
|||||||
main: Option<SharedString>,
|
main: Option<SharedString>,
|
||||||
main_order: Vec<SharedString>,
|
main_order: Vec<SharedString>,
|
||||||
main_views: HashMap<SharedString, Arc<dyn PanelView>>,
|
main_views: HashMap<SharedString, Arc<dyn PanelView>>,
|
||||||
details: Vec<(SharedString, SharedString)>,
|
details: Vec<SharedString>,
|
||||||
detail_views: HashMap<SharedString, Arc<dyn PanelView>>,
|
detail_views: HashMap<SharedString, Arc<dyn PanelView>>,
|
||||||
active_detail: Option<SharedString>,
|
active_detail: Option<SharedString>,
|
||||||
}
|
}
|
||||||
@@ -41,6 +41,11 @@ impl Workspace {
|
|||||||
&self.main_order
|
&self.main_order
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The open main panel with this id.
|
||||||
|
pub fn main_view(&self, id: &SharedString) -> Option<Arc<dyn PanelView>> {
|
||||||
|
self.main_views.get(id).cloned()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn active_detail(&self) -> Option<Arc<dyn PanelView>> {
|
pub fn active_detail(&self) -> Option<Arc<dyn PanelView>> {
|
||||||
self.active_detail
|
self.active_detail
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@@ -95,13 +100,11 @@ impl Workspace {
|
|||||||
pub fn show_detail(
|
pub fn show_detail(
|
||||||
&mut self,
|
&mut self,
|
||||||
id: SharedString,
|
id: SharedString,
|
||||||
label: SharedString,
|
|
||||||
view: Arc<dyn PanelView>,
|
view: Arc<dyn PanelView>,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) {
|
) {
|
||||||
match self.details.iter_mut().find(|(open, _)| *open == id) {
|
if !self.details.contains(&id) {
|
||||||
Some((_, existing)) => *existing = label,
|
self.details.push(id.clone());
|
||||||
None => self.details.push((id.clone(), label)),
|
|
||||||
}
|
}
|
||||||
self.detail_views.insert(id.clone(), view);
|
self.detail_views.insert(id.clone(), view);
|
||||||
self.active_detail = Some(id);
|
self.active_detail = Some(id);
|
||||||
@@ -109,7 +112,7 @@ impl Workspace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn close_detail(&mut self, id: &SharedString, cx: &mut Context<Self>) {
|
pub fn close_detail(&mut self, id: &SharedString, cx: &mut Context<Self>) {
|
||||||
let Some(index) = self.details.iter().position(|(open, _)| open == id) else {
|
let Some(index) = self.details.iter().position(|open| open == id) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
self.close_detail_at(index, cx);
|
self.close_detail_at(index, cx);
|
||||||
@@ -158,7 +161,7 @@ impl Workspace {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (id, _) = self.details.remove(index);
|
let id = self.details.remove(index);
|
||||||
self.detail_views.remove(&id);
|
self.detail_views.remove(&id);
|
||||||
|
|
||||||
if self.active_detail.as_ref() == Some(&id) {
|
if self.active_detail.as_ref() == Some(&id) {
|
||||||
@@ -166,14 +169,14 @@ impl Workspace {
|
|||||||
.details
|
.details
|
||||||
.get(index)
|
.get(index)
|
||||||
.or_else(|| index.checked_sub(1).and_then(|prev| self.details.get(prev)))
|
.or_else(|| index.checked_sub(1).and_then(|prev| self.details.get(prev)))
|
||||||
.map(|(id, _)| id.clone());
|
.cloned();
|
||||||
}
|
}
|
||||||
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn activate_detail_at(&mut self, index: usize, cx: &mut Context<Self>) {
|
fn activate_detail_at(&mut self, index: usize, cx: &mut Context<Self>) {
|
||||||
let Some((id, _)) = self.details.get(index) else {
|
let Some(id) = self.details.get(index) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
self.active_detail = Some(id.clone());
|
self.active_detail = Some(id.clone());
|
||||||
@@ -181,17 +184,26 @@ impl Workspace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Panel for Workspace {}
|
impl Panel for Workspace {
|
||||||
|
fn title(&self, _cx: &App) -> SharedString {
|
||||||
|
SharedString::from("Workspace")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Render for Workspace {
|
impl Render for Workspace {
|
||||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
let selected = self
|
let selected = self
|
||||||
.active_detail
|
.active_detail
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|active| self.details.iter().position(|(id, _)| id == active))
|
.and_then(|active| self.details.iter().position(|id| id == active))
|
||||||
.unwrap_or(usize::MAX);
|
.unwrap_or(usize::MAX);
|
||||||
|
|
||||||
let details = self.details.clone();
|
let details: Vec<_> = self
|
||||||
|
.details
|
||||||
|
.iter()
|
||||||
|
.map(|id| (id.clone(), self.detail_views.get(id).cloned()))
|
||||||
|
.collect();
|
||||||
|
|
||||||
let weak = cx.entity().downgrade();
|
let weak = cx.entity().downgrade();
|
||||||
let close_weak = weak.clone();
|
let close_weak = weak.clone();
|
||||||
|
|
||||||
@@ -199,10 +211,13 @@ impl Render for Workspace {
|
|||||||
.variant(TabsVariant::Pill)
|
.variant(TabsVariant::Pill)
|
||||||
.overflow_scroll(true)
|
.overflow_scroll(true)
|
||||||
.selected(selected)
|
.selected(selected)
|
||||||
.tabs(move |_, _| {
|
.tabs(move |_, cx| {
|
||||||
details
|
details
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(id, label)| Tab::new(id.clone(), label.clone()).closeable(true))
|
.map(|(id, view)| match view {
|
||||||
|
Some(view) => view.tab(id.clone().into(), cx).closeable(true),
|
||||||
|
None => Tab::new(id.clone(), id.clone()).closeable(true),
|
||||||
|
})
|
||||||
.collect()
|
.collect()
|
||||||
})
|
})
|
||||||
.on_change(move |index, _, cx| {
|
.on_change(move |index, _, cx| {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use gpui::{
|
|||||||
Render, RenderOnce, SharedString, StyleRefinement, Styled as _, Window, div, px,
|
Render, RenderOnce, SharedString, StyleRefinement, Styled as _, Window, div, px,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::components::tabs::Tab;
|
||||||
use crate::layout::StyledExt as _;
|
use crate::layout::StyledExt as _;
|
||||||
use crate::layout::resizable::{Resizable, ResizableState};
|
use crate::layout::resizable::{Resizable, ResizableState};
|
||||||
use crate::theme::ActiveTheme as _;
|
use crate::theme::ActiveTheme as _;
|
||||||
@@ -21,6 +22,19 @@ pub trait Panel: Render + 'static {
|
|||||||
fn kind(&self, cx: &App) -> Option<SharedString> {
|
fn kind(&self, cx: &App) -> Option<SharedString> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The title shown in the panel's tab.
|
||||||
|
fn title(&self, cx: &App) -> SharedString;
|
||||||
|
|
||||||
|
/// The element drawn before the tab's title, e.g. an avatar or icon.
|
||||||
|
fn prefix(&self, cx: &App) -> Option<AnyElement> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether the tab shows the loading spinner.
|
||||||
|
fn loading(&self, cx: &App) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An object-safe handle to a panel, so apps can hold panels by kind.
|
/// An object-safe handle to a panel, so apps can hold panels by kind.
|
||||||
@@ -33,6 +47,28 @@ pub trait PanelView: 'static {
|
|||||||
fn kind(&self, cx: &App) -> Option<SharedString> {
|
fn kind(&self, cx: &App) -> Option<SharedString> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The panel's title, read live from the panel.
|
||||||
|
fn title(&self, cx: &App) -> SharedString;
|
||||||
|
|
||||||
|
/// The panel's tab prefix, read live from the panel.
|
||||||
|
fn prefix(&self, cx: &App) -> Option<AnyElement> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether the panel's tab shows the loading spinner.
|
||||||
|
fn loading(&self, cx: &App) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Builds the panel's tab from its title, prefix, and loading state.
|
||||||
|
fn tab(&self, key: ElementId, cx: &App) -> Tab {
|
||||||
|
let mut tab = Tab::new(key, self.title(cx)).busy(self.loading(cx));
|
||||||
|
if let Some(prefix) = self.prefix(cx) {
|
||||||
|
tab = tab.lead(prefix);
|
||||||
|
}
|
||||||
|
tab
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Panel> PanelView for Entity<T> {
|
impl<T: Panel> PanelView for Entity<T> {
|
||||||
@@ -43,6 +79,18 @@ impl<T: Panel> PanelView for Entity<T> {
|
|||||||
fn kind(&self, cx: &App) -> Option<SharedString> {
|
fn kind(&self, cx: &App) -> Option<SharedString> {
|
||||||
self.read(cx).kind(cx)
|
self.read(cx).kind(cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn title(&self, cx: &App) -> SharedString {
|
||||||
|
self.read(cx).title(cx)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn prefix(&self, cx: &App) -> Option<AnyElement> {
|
||||||
|
self.read(cx).prefix(cx)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn loading(&self, cx: &App) -> bool {
|
||||||
|
self.read(cx).loading(cx)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P: PanelView + ?Sized> PanelView for Arc<P> {
|
impl<P: PanelView + ?Sized> PanelView for Arc<P> {
|
||||||
@@ -53,6 +101,18 @@ impl<P: PanelView + ?Sized> PanelView for Arc<P> {
|
|||||||
fn kind(&self, cx: &App) -> Option<SharedString> {
|
fn kind(&self, cx: &App) -> Option<SharedString> {
|
||||||
(**self).kind(cx)
|
(**self).kind(cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn title(&self, cx: &App) -> SharedString {
|
||||||
|
(**self).title(cx)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn prefix(&self, cx: &App) -> Option<AnyElement> {
|
||||||
|
(**self).prefix(cx)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn loading(&self, cx: &App) -> bool {
|
||||||
|
(**self).loading(cx)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The layout the cached panel content lays out with.
|
/// The layout the cached panel content lays out with.
|
||||||
|
|||||||
+113
-5
@@ -2,11 +2,14 @@
|
|||||||
//! half-width islands with a drag divider that resizes them.
|
//! half-width islands with a drag divider that resizes them.
|
||||||
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AppContext as _, Context, Entity, InteractiveElement as _, IntoElement, Modifiers, MouseButton,
|
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
||||||
MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement as _, Render, SharedString,
|
Modifiers, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement as _,
|
||||||
Styled as _, TestAppContext, VisualTestContext, Window, div, point, px, size,
|
Render, SharedString, Styled as _, TestAppContext, VisualTestContext, Window, div, point, px,
|
||||||
|
size,
|
||||||
};
|
};
|
||||||
use ui::layout::panel::{Panel, PanelRow};
|
use ui::common::v_flex;
|
||||||
|
use ui::layout::panel::{Panel, PanelRow, PanelView};
|
||||||
|
use ui::tabs::Tabs;
|
||||||
use ui::theme::Theme;
|
use ui::theme::Theme;
|
||||||
|
|
||||||
const WINDOW_WIDTH: f32 = 1024.0;
|
const WINDOW_WIDTH: f32 = 1024.0;
|
||||||
@@ -34,7 +37,11 @@ impl Render for TagView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Panel for TagView {}
|
impl Panel for TagView {
|
||||||
|
fn title(&self, _cx: &App) -> SharedString {
|
||||||
|
self.selector.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct PanelHarness {
|
struct PanelHarness {
|
||||||
split: bool,
|
split: bool,
|
||||||
@@ -150,3 +157,104 @@ fn dragging_the_divider_resizes_the_panels(cx: &mut TestAppContext) {
|
|||||||
.expect("main panel laid out after the drag");
|
.expect("main panel laid out after the drag");
|
||||||
assert_eq!(after.size.width, before.size.width + px(100.0));
|
assert_eq!(after.size.width, before.size.width + px(100.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct MetaView {
|
||||||
|
loading: bool,
|
||||||
|
prefix: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for MetaView {
|
||||||
|
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
div().size_full()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Panel for MetaView {
|
||||||
|
fn title(&self, _cx: &App) -> SharedString {
|
||||||
|
SharedString::from("Meta")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn prefix(&self, _cx: &App) -> Option<AnyElement> {
|
||||||
|
self.prefix.then(|| {
|
||||||
|
div()
|
||||||
|
.debug_selector(|| "meta-prefix".to_string())
|
||||||
|
.into_any_element()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn loading(&self, _cx: &App) -> bool {
|
||||||
|
self.loading
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct MetaStripHarness {
|
||||||
|
busy: Entity<MetaView>,
|
||||||
|
idle: Entity<MetaView>,
|
||||||
|
prefixed: Entity<MetaView>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for MetaStripHarness {
|
||||||
|
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
let busy = self.busy.clone();
|
||||||
|
let idle = self.idle.clone();
|
||||||
|
let prefixed = self.prefixed.clone();
|
||||||
|
v_flex()
|
||||||
|
.size_full()
|
||||||
|
.gap_1()
|
||||||
|
.child(
|
||||||
|
Tabs::new("busy-strip")
|
||||||
|
.tabs(move |_, cx| vec![busy.tab("busy".into(), cx).closeable(false)]),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Tabs::new("idle-strip")
|
||||||
|
.tabs(move |_, cx| vec![idle.tab("idle".into(), cx).closeable(false)]),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Tabs::new("prefix-strip")
|
||||||
|
.tabs(move |_, cx| vec![prefixed.tab("prefix".into(), cx).closeable(false)]),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
fn panel_tab_uses_title_prefix_and_loading(cx: &mut TestAppContext) {
|
||||||
|
cx.update(Theme::init);
|
||||||
|
let busy = cx.new(|_| MetaView {
|
||||||
|
loading: true,
|
||||||
|
prefix: false,
|
||||||
|
});
|
||||||
|
let idle = cx.new(|_| MetaView {
|
||||||
|
loading: false,
|
||||||
|
prefix: false,
|
||||||
|
});
|
||||||
|
let prefixed = cx.new(|_| MetaView {
|
||||||
|
loading: false,
|
||||||
|
prefix: true,
|
||||||
|
});
|
||||||
|
let window = cx.open_window(size(px(800.), px(600.)), |_, _| MetaStripHarness {
|
||||||
|
busy,
|
||||||
|
idle,
|
||||||
|
prefixed,
|
||||||
|
});
|
||||||
|
let mut cx = VisualTestContext::from_window(window.into(), cx);
|
||||||
|
cx.run_until_parked();
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
cx.debug_bounds("busy-strip-tab-Meta").is_some(),
|
||||||
|
"title becomes the tab label"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
cx.debug_bounds("meta-prefix").is_some(),
|
||||||
|
"prefix becomes the tab lead"
|
||||||
|
);
|
||||||
|
let busy = cx
|
||||||
|
.debug_bounds("busy-strip-tab-Meta")
|
||||||
|
.expect("busy tab laid out");
|
||||||
|
let idle = cx
|
||||||
|
.debug_bounds("idle-strip-tab-Meta")
|
||||||
|
.expect("idle tab laid out");
|
||||||
|
assert!(
|
||||||
|
busy.size.width > idle.size.width,
|
||||||
|
"loading adds the spinner to the tab"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user