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.repository_switcher());
|
||||
|
||||
let tab_bar = h_flex().gap_1().when_some(
|
||||
titlebar_view.render_repo_tabs(workspace.open_mains(), workspace.active_main_id()),
|
||||
|bar, tabs| bar.child(tabs),
|
||||
);
|
||||
let tab_bar = h_flex()
|
||||
.gap_1()
|
||||
.when_some(titlebar_view.render_repo_tabs(workspace), |bar, tabs| {
|
||||
bar.child(tabs)
|
||||
});
|
||||
|
||||
div()
|
||||
.relative()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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::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 {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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::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 {
|
||||
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)]
|
||||
pub(super) enum RepoFilter {
|
||||
All,
|
||||
#[default]
|
||||
Popular,
|
||||
All,
|
||||
Recent,
|
||||
}
|
||||
|
||||
@@ -43,14 +42,6 @@ impl RepoFilter {
|
||||
match self {
|
||||
Self::All => {}
|
||||
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
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
mod helpers;
|
||||
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
||||
ParentElement as _, Render, SharedString, Styled as _, Subscription, UniformListScrollHandle,
|
||||
WeakEntity, Window, div, px, uniform_list,
|
||||
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ListAlignment, ListState,
|
||||
ParentElement as _, Render, SharedString, Styled as _, Subscription, WeakEntity, Window, div,
|
||||
list, px,
|
||||
};
|
||||
use helpers::{RepoFilter, render_card};
|
||||
use metadata::ProfileDirectory;
|
||||
@@ -17,7 +16,7 @@ use ui::input::{Input, InputState, InputStateEvent};
|
||||
use ui::layout::panel::Panel;
|
||||
use ui::scrollbar::Scrollbar;
|
||||
use ui::segmented::{Segmented, SegmentedOption};
|
||||
use ui::theme::{ActiveTheme as _, TextRole, Typeset as _};
|
||||
use ui::theme::ActiveTheme as _;
|
||||
|
||||
use crate::shared::panels;
|
||||
use crate::workspace::Workspace;
|
||||
@@ -28,7 +27,7 @@ const CARD_HEIGHT: f32 = 40. + 64. + 48. + 2. + 6.;
|
||||
pub struct ExploreView {
|
||||
store: Entity<RepoListStore>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
scroll_handle: UniformListScrollHandle,
|
||||
scroll_handle: ListState,
|
||||
filter: RepoFilter,
|
||||
/// Indices matching [`Self::filter`] into the store's `announcements`.
|
||||
visible: Vec<usize>,
|
||||
@@ -83,7 +82,7 @@ impl ExploreView {
|
||||
Self {
|
||||
store,
|
||||
workspace,
|
||||
scroll_handle: UniformListScrollHandle::new(),
|
||||
scroll_handle: ListState::new(0, ListAlignment::Top, px(320.)),
|
||||
filter: RepoFilter::default(),
|
||||
visible: Vec::new(),
|
||||
search,
|
||||
@@ -111,129 +110,158 @@ impl ExploreView {
|
||||
directory.track(owners, cx);
|
||||
});
|
||||
|
||||
self.scroll_handle.reset(self.item_count());
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn render_header(&self, count: usize, cx: &mut Context<Self>) -> AnyElement {
|
||||
let muted = cx.theme().colors.muted_foreground;
|
||||
let weak = cx.entity().downgrade();
|
||||
/// Header row, plus one row per card row, or the empty state when nothing matches.
|
||||
fn item_count(&self) -> usize {
|
||||
if self.visible.is_empty() {
|
||||
2
|
||||
} else {
|
||||
self.visible.len().div_ceil(COLUMNS) + 1
|
||||
}
|
||||
}
|
||||
|
||||
h_flex()
|
||||
.px_4()
|
||||
.py_2()
|
||||
fn render_header(
|
||||
search: Entity<InputState>,
|
||||
filter: RepoFilter,
|
||||
weak: WeakEntity<Self>,
|
||||
cx: &App,
|
||||
) -> AnyElement {
|
||||
let muted = cx.theme().colors.muted_foreground;
|
||||
|
||||
div()
|
||||
.relative()
|
||||
.h_96()
|
||||
.w_full()
|
||||
.gap_3()
|
||||
.child(
|
||||
v_flex()
|
||||
.gap_1()
|
||||
.child(div().typeset(TextRole::Caption2, cx).child("Repositories"))
|
||||
div()
|
||||
.absolute()
|
||||
.inset_0()
|
||||
.flex()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.px_4()
|
||||
.child(
|
||||
div()
|
||||
.typeset(TextRole::Caption, cx)
|
||||
.text_color(muted)
|
||||
.child(SharedString::from(format!("Total: {count}"))),
|
||||
div().w_full().max_w(px(480.)).child(
|
||||
Input::new("explore-search", search)
|
||||
.placeholder("Search...")
|
||||
.fully_rounded(true)
|
||||
.prefix(Icon::named(IconRole::Search).small().color(muted)),
|
||||
),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
div().w(px(180.)).child(
|
||||
Input::new("explore-search", self.search.clone())
|
||||
.placeholder("Search...")
|
||||
.prefix(Icon::named(IconRole::Search).small().color(muted)),
|
||||
),
|
||||
)
|
||||
.child(div().flex_1())
|
||||
.child(
|
||||
Segmented::new("explore-filter", self.filter)
|
||||
.options(vec![
|
||||
SegmentedOption::new(RepoFilter::All, "All")
|
||||
.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")
|
||||
.icon(Icon::named(IconRole::Clock).small().color(muted)),
|
||||
])
|
||||
.on_change(move |filter, _, cx| {
|
||||
if let Err(error) = weak.update(cx, |this, cx| {
|
||||
this.filter = filter;
|
||||
this.rebuild_rows(cx);
|
||||
}) {
|
||||
log::warn!("failed to change explore filter: {error}");
|
||||
}
|
||||
}),
|
||||
div()
|
||||
.absolute()
|
||||
.left_0()
|
||||
.bottom_0()
|
||||
.pl_4()
|
||||
.pb_4()
|
||||
.child(
|
||||
Segmented::new("explore-filter", filter)
|
||||
.options(vec![
|
||||
SegmentedOption::new(RepoFilter::All, "All")
|
||||
.icon(Icon::named(IconRole::Grid).small().color(muted)),
|
||||
SegmentedOption::new(RepoFilter::Recent, "Recent")
|
||||
.icon(Icon::named(IconRole::Clock).small().color(muted)),
|
||||
])
|
||||
.on_change(move |filter, _, cx| {
|
||||
if let Err(error) = weak.update(cx, |this, cx| {
|
||||
this.filter = filter;
|
||||
this.rebuild_rows(cx);
|
||||
}) {
|
||||
log::warn!("failed to change explore filter: {error}");
|
||||
}
|
||||
}),
|
||||
),
|
||||
)
|
||||
.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 {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let store = self.store.read(cx);
|
||||
let announcements = store.announcements.clone();
|
||||
let last_activity = store.last_activity.clone();
|
||||
let count = self.visible.len();
|
||||
let visible = self.visible.clone();
|
||||
let directory = self.directory.clone();
|
||||
let workspace = self.workspace.clone();
|
||||
let has_repos = count > 0;
|
||||
let rows = visible.len().div_ceil(COLUMNS);
|
||||
let has_repos = !visible.is_empty();
|
||||
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()
|
||||
.size_full()
|
||||
.child(self.render_header(count, cx))
|
||||
.when(!has_repos, |this| {
|
||||
this.child(
|
||||
v_flex()
|
||||
.size_full()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.child(EmptyState::new("No repositories match your search")),
|
||||
)
|
||||
})
|
||||
.when(has_repos, |this| {
|
||||
this.child(
|
||||
uniform_list("explore-repos", rows, move |range, _, cx| {
|
||||
range
|
||||
.map(|row| {
|
||||
let mut cards = Vec::with_capacity(COLUMNS);
|
||||
.child(
|
||||
list(self.scroll_handle.clone(), move |item, _, cx| {
|
||||
if item == 0 {
|
||||
return Self::render_header(search.clone(), filter, weak.clone(), cx);
|
||||
}
|
||||
|
||||
for col in 0..COLUMNS {
|
||||
let Some(&ix) = visible.get(row * COLUMNS + col) else {
|
||||
break;
|
||||
};
|
||||
let Some(announcement) = announcements.get(ix) else {
|
||||
break;
|
||||
};
|
||||
let activity = last_activity.get(&announcement.addr()).copied();
|
||||
cards.push(render_card(
|
||||
ix,
|
||||
announcement,
|
||||
activity,
|
||||
&announcements,
|
||||
&directory,
|
||||
&workspace,
|
||||
cx,
|
||||
));
|
||||
}
|
||||
if !has_repos {
|
||||
return v_flex()
|
||||
.w_full()
|
||||
.h(px(320.))
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.child(EmptyState::new("No repositories match your search"))
|
||||
.into_any_element();
|
||||
}
|
||||
|
||||
h_flex()
|
||||
.id(row)
|
||||
.w_full()
|
||||
.h(px(CARD_HEIGHT))
|
||||
.gap_3()
|
||||
.px_4()
|
||||
.pt_4()
|
||||
.children(cards)
|
||||
.into_any_element()
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.track_scroll(&self.scroll_handle)
|
||||
.size_full(),
|
||||
)
|
||||
})
|
||||
let row = item - 1;
|
||||
let mut cards = Vec::with_capacity(COLUMNS);
|
||||
|
||||
for col in 0..COLUMNS {
|
||||
let Some(&ix) = visible.get(row * COLUMNS + col) else {
|
||||
break;
|
||||
};
|
||||
let Some(announcement) = announcements.get(ix) else {
|
||||
break;
|
||||
};
|
||||
let activity = last_activity.get(&announcement.addr()).copied();
|
||||
cards.push(render_card(
|
||||
ix,
|
||||
announcement,
|
||||
activity,
|
||||
&announcements,
|
||||
&directory,
|
||||
&workspace,
|
||||
cx,
|
||||
));
|
||||
}
|
||||
|
||||
h_flex()
|
||||
.w_full()
|
||||
.h(px(CARD_HEIGHT))
|
||||
.gap_3()
|
||||
.px_4()
|
||||
.pt_4()
|
||||
.children(cards)
|
||||
.into_any_element()
|
||||
})
|
||||
.size_full(),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.absolute()
|
||||
@@ -241,10 +269,7 @@ impl Render for ExploreView {
|
||||
.left_0()
|
||||
.right_0()
|
||||
.bottom_0()
|
||||
.child(Scrollbar::vertical(
|
||||
"explore-scroll",
|
||||
self.scroll_handle.clone(),
|
||||
)),
|
||||
.child(Scrollbar::vertical("explore-scroll", scroll_handle)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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,
|
||||
};
|
||||
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 {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
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 _,
|
||||
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 {
|
||||
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| {
|
||||
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();
|
||||
panels::open_detail(
|
||||
&workspace,
|
||||
id,
|
||||
label,
|
||||
move |_, cx| {
|
||||
cx.new(|cx| {
|
||||
IssueDetailView::new(
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::path::PathBuf;
|
||||
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
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,
|
||||
WeakEntity, Window, div, uniform_list,
|
||||
};
|
||||
@@ -288,13 +288,10 @@ impl PullRequestDetailView {
|
||||
None => SharedString::from(format!("commit:{}:{commit_id}", worktree.display())),
|
||||
};
|
||||
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();
|
||||
crate::shared::panels::open_detail(
|
||||
&workspace,
|
||||
id,
|
||||
label,
|
||||
move |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 {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
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 _,
|
||||
Subscription, UniformListScrollHandle, WeakEntity, Window, div, px, uniform_list,
|
||||
};
|
||||
@@ -145,7 +145,6 @@ impl PullRequestsView {
|
||||
crate::shared::panels::open_detail(
|
||||
&workspace,
|
||||
id.clone(),
|
||||
"New pull request",
|
||||
move |window, cx| {
|
||||
cx.new(|cx| {
|
||||
NewPullRequestView::new(
|
||||
@@ -175,7 +174,6 @@ impl PullRequestsView {
|
||||
crate::shared::panels::open_detail(
|
||||
&workspace,
|
||||
id.clone(),
|
||||
"Send patch",
|
||||
move |window, cx| {
|
||||
cx.new(|cx| {
|
||||
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 {
|
||||
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))
|
||||
.on_click(move |_, window, cx| {
|
||||
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 store = store.clone();
|
||||
crate::shared::panels::open_detail(
|
||||
&workspace,
|
||||
id,
|
||||
label,
|
||||
move |window, cx| {
|
||||
cx.new(|cx| {
|
||||
PullRequestDetailView::new(
|
||||
|
||||
@@ -222,13 +222,10 @@ impl NewPullRequestView {
|
||||
None => SharedString::from(format!("commit:{}:{commit_id}", repo_path.display())),
|
||||
};
|
||||
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();
|
||||
crate::shared::panels::open_detail(
|
||||
&workspace,
|
||||
id,
|
||||
label,
|
||||
move |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 {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AnyElement, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _, Render,
|
||||
SharedString, Styled as _, WeakEntity, Window, div,
|
||||
AnyElement, App, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _,
|
||||
Render, SharedString, Styled as _, WeakEntity, Window, div,
|
||||
};
|
||||
use signed_state::RepoStore;
|
||||
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 {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
|
||||
@@ -53,14 +53,10 @@ pub fn open_repo_item(
|
||||
match item {
|
||||
RepoItem::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();
|
||||
panels::open_detail(
|
||||
workspace,
|
||||
id,
|
||||
label,
|
||||
move |_, cx| {
|
||||
cx.new(|cx| {
|
||||
crate::issues::detail::IssueDetailView::new(store.clone(), issue_id, cx)
|
||||
@@ -72,15 +68,11 @@ pub fn open_repo_item(
|
||||
}
|
||||
RepoItem::PullRequest(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 store = store.clone();
|
||||
panels::open_detail(
|
||||
workspace,
|
||||
id,
|
||||
label,
|
||||
move |window, cx| {
|
||||
cx.new(|cx| {
|
||||
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 {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
|
||||
@@ -88,7 +88,6 @@ impl RepoDetailView {
|
||||
crate::shared::panels::open_detail(
|
||||
&workspace,
|
||||
id.clone(),
|
||||
"New pull request",
|
||||
move |window, cx| {
|
||||
cx.new(|cx| {
|
||||
NewPullRequestView::new(
|
||||
|
||||
@@ -100,8 +100,6 @@ impl RepoHistoryView {
|
||||
};
|
||||
|
||||
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 id = match store.read(cx).addr() {
|
||||
Some(addr) => SharedString::from(format!("commit:{addr}:{commit_id}")),
|
||||
@@ -112,7 +110,6 @@ impl RepoHistoryView {
|
||||
panels::open_detail(
|
||||
&workspace,
|
||||
id,
|
||||
label,
|
||||
move |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,
|
||||
};
|
||||
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::layout::panel::Panel;
|
||||
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 {
|
||||
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>(
|
||||
workspace: &WeakEntity<Workspace>,
|
||||
id: impl Into<SharedString>,
|
||||
label: impl Into<SharedString>,
|
||||
build: F,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
@@ -50,7 +49,6 @@ pub fn open_detail<P, F>(
|
||||
F: Fn(&mut Window, &mut App) -> Entity<P> + 'static,
|
||||
{
|
||||
let id = id.into();
|
||||
let label = label.into();
|
||||
|
||||
if workspace
|
||||
.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));
|
||||
|
||||
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}");
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -16,9 +15,9 @@ use ui::avatar::Avatar;
|
||||
use ui::button::{Button, ButtonVariant};
|
||||
use ui::command_palette::{Command, CommandPalette, CommandPaletteState};
|
||||
use ui::icons::{Icon, IconRole};
|
||||
use ui::layout::panel::PanelView;
|
||||
use ui::menu::{Menu, MenuItem};
|
||||
use ui::tabs::{Tab, Tabs, TabsVariant};
|
||||
use ui::theme::ActiveTheme as _;
|
||||
use ui::tooltip::Tooltip;
|
||||
|
||||
use crate::explore::ExploreView;
|
||||
@@ -340,29 +339,24 @@ impl TitlebarView {
|
||||
}
|
||||
|
||||
/// Tabs for the repositories opened in the main panel.
|
||||
pub fn render_repo_tabs(
|
||||
&self,
|
||||
open: &[SharedString],
|
||||
active: Option<&SharedString>,
|
||||
) -> Option<Tabs> {
|
||||
pub fn render_repo_tabs(&self, workspace: &Workspace) -> Option<Tabs> {
|
||||
let open = workspace.open_mains();
|
||||
|
||||
if open.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let lookup: HashMap<SharedString, RepositoryEntry> = self
|
||||
.repository_entries()
|
||||
.into_iter()
|
||||
.map(|entry| (entry.key.clone(), entry))
|
||||
let tabs: Vec<_> = open
|
||||
.iter()
|
||||
.map(|id| (id.clone(), workspace.main_view(id)))
|
||||
.collect();
|
||||
|
||||
let open_tabs = open.to_vec();
|
||||
let lookup_for_tabs = lookup;
|
||||
let lookup_directory = self.directory.clone();
|
||||
let selected = active
|
||||
let selected = workspace
|
||||
.active_main_id()
|
||||
.and_then(|id| open.iter().position(|open_id| open_id == id))
|
||||
.unwrap_or(usize::MAX);
|
||||
|
||||
let workspace = self.workspace.clone();
|
||||
let change_workspace = self.workspace.clone();
|
||||
let close_workspace = self.workspace.clone();
|
||||
let open_for_change = open.to_vec();
|
||||
|
||||
@@ -372,25 +366,10 @@ impl TitlebarView {
|
||||
.overflow_scroll(true)
|
||||
.selected(selected)
|
||||
.tabs(move |_, cx| {
|
||||
open_tabs
|
||||
.iter()
|
||||
.map(|id| {
|
||||
let entry = lookup_for_tabs.get(id);
|
||||
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
|
||||
tabs.iter()
|
||||
.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()
|
||||
})
|
||||
@@ -398,7 +377,7 @@ impl TitlebarView {
|
||||
let Some(id) = open_for_change.get(index).cloned() else {
|
||||
return;
|
||||
};
|
||||
log_dropped(workspace.update(cx, |workspace, cx| {
|
||||
log_dropped(change_workspace.update(cx, |workspace, cx| {
|
||||
workspace.activate_main(&id, cx);
|
||||
}));
|
||||
})
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
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::layout::panel::{Panel, PanelView};
|
||||
@@ -16,7 +16,7 @@ pub struct Workspace {
|
||||
main: Option<SharedString>,
|
||||
main_order: Vec<SharedString>,
|
||||
main_views: HashMap<SharedString, Arc<dyn PanelView>>,
|
||||
details: Vec<(SharedString, SharedString)>,
|
||||
details: Vec<SharedString>,
|
||||
detail_views: HashMap<SharedString, Arc<dyn PanelView>>,
|
||||
active_detail: Option<SharedString>,
|
||||
}
|
||||
@@ -41,6 +41,11 @@ impl Workspace {
|
||||
&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>> {
|
||||
self.active_detail
|
||||
.as_ref()
|
||||
@@ -95,13 +100,11 @@ impl Workspace {
|
||||
pub fn show_detail(
|
||||
&mut self,
|
||||
id: SharedString,
|
||||
label: SharedString,
|
||||
view: Arc<dyn PanelView>,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
match self.details.iter_mut().find(|(open, _)| *open == id) {
|
||||
Some((_, existing)) => *existing = label,
|
||||
None => self.details.push((id.clone(), label)),
|
||||
if !self.details.contains(&id) {
|
||||
self.details.push(id.clone());
|
||||
}
|
||||
self.detail_views.insert(id.clone(), view);
|
||||
self.active_detail = Some(id);
|
||||
@@ -109,7 +112,7 @@ impl Workspace {
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
self.close_detail_at(index, cx);
|
||||
@@ -158,7 +161,7 @@ impl Workspace {
|
||||
return;
|
||||
}
|
||||
|
||||
let (id, _) = self.details.remove(index);
|
||||
let id = self.details.remove(index);
|
||||
self.detail_views.remove(&id);
|
||||
|
||||
if self.active_detail.as_ref() == Some(&id) {
|
||||
@@ -166,14 +169,14 @@ impl Workspace {
|
||||
.details
|
||||
.get(index)
|
||||
.or_else(|| index.checked_sub(1).and_then(|prev| self.details.get(prev)))
|
||||
.map(|(id, _)| id.clone());
|
||||
.cloned();
|
||||
}
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
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 {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let selected = self
|
||||
.active_detail
|
||||
.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);
|
||||
|
||||
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 close_weak = weak.clone();
|
||||
|
||||
@@ -199,10 +211,13 @@ impl Render for Workspace {
|
||||
.variant(TabsVariant::Pill)
|
||||
.overflow_scroll(true)
|
||||
.selected(selected)
|
||||
.tabs(move |_, _| {
|
||||
.tabs(move |_, cx| {
|
||||
details
|
||||
.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()
|
||||
})
|
||||
.on_change(move |index, _, cx| {
|
||||
|
||||
@@ -10,6 +10,7 @@ use gpui::{
|
||||
Render, RenderOnce, SharedString, StyleRefinement, Styled as _, Window, div, px,
|
||||
};
|
||||
|
||||
use crate::components::tabs::Tab;
|
||||
use crate::layout::StyledExt as _;
|
||||
use crate::layout::resizable::{Resizable, ResizableState};
|
||||
use crate::theme::ActiveTheme as _;
|
||||
@@ -21,6 +22,19 @@ pub trait Panel: Render + 'static {
|
||||
fn kind(&self, cx: &App) -> Option<SharedString> {
|
||||
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.
|
||||
@@ -33,6 +47,28 @@ pub trait PanelView: 'static {
|
||||
fn kind(&self, cx: &App) -> Option<SharedString> {
|
||||
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> {
|
||||
@@ -43,6 +79,18 @@ impl<T: Panel> PanelView for Entity<T> {
|
||||
fn kind(&self, cx: &App) -> Option<SharedString> {
|
||||
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> {
|
||||
@@ -53,6 +101,18 @@ impl<P: PanelView + ?Sized> PanelView for Arc<P> {
|
||||
fn kind(&self, cx: &App) -> Option<SharedString> {
|
||||
(**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.
|
||||
|
||||
+113
-5
@@ -2,11 +2,14 @@
|
||||
//! half-width islands with a drag divider that resizes them.
|
||||
|
||||
use gpui::{
|
||||
AppContext as _, Context, Entity, InteractiveElement as _, IntoElement, Modifiers, MouseButton,
|
||||
MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement as _, Render, SharedString,
|
||||
Styled as _, TestAppContext, VisualTestContext, Window, div, point, px, size,
|
||||
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
||||
Modifiers, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement as _,
|
||||
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;
|
||||
|
||||
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 {
|
||||
split: bool,
|
||||
@@ -150,3 +157,104 @@ fn dragging_the_divider_resizes_the_panels(cx: &mut TestAppContext) {
|
||||
.expect("main panel laid out after the drag");
|
||||
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