chore: move new issue/pull form into a split panel
Rust / build (macos-latest, stable) (push) Canceled after 0s
Rust / build (ubuntu-latest, stable) (push) Canceled after 0s
Rust / build (windows-latest, stable) (push) Canceled after 0s

This commit is contained in:
2026-11-25 10:01:11 +07:00
parent e54364b716
commit f305c56e9e
18 changed files with 576 additions and 451 deletions
+2
View File
@@ -13,6 +13,7 @@
- Keep the Explore list at its scroll position across background refreshes, a new search or filter still starts at the top - Keep the Explore list at its scroll position across background refreshes, a new search or filter still starts at the top
- Reuse the rendered file tree, commit diffs, README previews and split pane instead of rebuilding them on every repaint - Reuse the rendered file tree, commit diffs, README previews and split pane instead of rebuilding them on every repaint
- Truncate long tab and file tree labels with an ellipsis instead of letting them widen their row - Truncate long tab and file tree labels with an ellipsis instead of letting them widen their row
- Open the New issue form in a split panel instead of a dialog, it now stays open until the issue is published and shows a failed publish in the form
### Fixed ### Fixed
@@ -34,6 +35,7 @@
- Fix an open dialog taking keyboard focus back from the command palette or a toast button on every repaint - Fix an open dialog taking keyboard focus back from the command palette or a toast button on every repaint
- Fix the remove button of a Settings or grasp server row carrying its hover state over to the next row after a removal - Fix the remove button of a Settings or grasp server row carrying its hover state over to the next row after a removal
- Fix the file tree's scrollbar sitting inset from the sidebar's right border, it now rides beside it - Fix the file tree's scrollbar sitting inset from the sidebar's right border, it now rides beside it
- Fix the selected filter in the Explore, Issues and Pull requests views highlighting only after the pointer crossed it, it now highlights as soon as the filter is drawn
## v0.2.0 - 2026/10/21 ## v0.2.0 - 2026/10/21
+19 -13
View File
@@ -24,7 +24,7 @@ use crate::app::AppRoot;
use crate::explore::helpers::pick_banner; use crate::explore::helpers::pick_banner;
use crate::identity::import::ImportDialog; use crate::identity::import::ImportDialog;
use crate::identity::onboarding::OnboardingDialog; use crate::identity::onboarding::OnboardingDialog;
use crate::shared::panels; use crate::shared::log_dropped;
mod helpers; mod helpers;
@@ -54,16 +54,20 @@ impl ExploreView {
/// Opens the explore panel in the main panel, reusing it when it is already cached. /// Opens the explore panel in the main panel, reusing it when it is already cached.
pub(crate) fn open(workspace: &WeakEntity<AppRoot>, window: &mut Window, cx: &mut App) { pub(crate) fn open(workspace: &WeakEntity<AppRoot>, window: &mut Window, cx: &mut App) {
panels::open_primary( log_dropped(workspace.update(cx, |root, cx| {
workspace, root.panels().clone().update(cx, |panels, cx| {
Self::PANEL_ID, panels.open(
{ PanelSlot::Main,
let workspace = workspace.clone(); Self::PANEL_ID,
move |_, cx| cx.new(|cx| Self::new(workspace.clone(), cx)) {
}, let workspace = workspace.clone();
window, move |_, cx| cx.new(|cx| Self::new(workspace.clone(), cx))
cx, },
); window,
cx,
)
})
}));
} }
pub fn new(workspace: WeakEntity<AppRoot>, cx: &mut Context<Self>) -> Self { pub fn new(workspace: WeakEntity<AppRoot>, cx: &mut Context<Self>) -> Self {
@@ -220,9 +224,11 @@ impl ExploreView {
div().absolute().left_0().bottom_0().pl_4().pb_4().child( div().absolute().left_0().bottom_0().pl_4().pb_4().child(
Segmented::new("explore-filter", filter) Segmented::new("explore-filter", filter)
.options(vec![ .options(vec![
SegmentedOption::new(RepoFilter::All, "All") SegmentedOption::new(RepoFilter::All)
.label("All")
.icon(Icon::named(IconRole::Grid).small().color(muted)), .icon(Icon::named(IconRole::Grid).small().color(muted)),
SegmentedOption::new(RepoFilter::Recent, "Recent") SegmentedOption::new(RepoFilter::Recent)
.label("Recent")
.icon(Icon::named(IconRole::Clock).small().color(muted)), .icon(Icon::named(IconRole::Clock).small().color(muted)),
]) ])
.on_change(move |filter, _, cx| { .on_change(move |filter, _, cx| {
+78 -38
View File
@@ -10,20 +10,19 @@ use nostr::prelude::PublicKey;
use signed_core::GitEvent; use signed_core::GitEvent;
use signed_state::RepoStore; use signed_state::RepoStore;
use ui::button::Button; use ui::button::Button;
use ui::common::v_flex; use ui::common::{Sizable, h_flex, v_flex};
use ui::icons::{Icon, IconRole}; use ui::icons::{Icon, IconRole};
use ui::layout::panel::Panel; use ui::layout::panel::{Panel, PanelSlot};
use ui::layout::root::RootContext as _;
use ui::segmented::{Segmented, SegmentedOption}; use ui::segmented::{Segmented, SegmentedOption};
use ui::theme::ActiveTheme as _; use ui::theme::ActiveTheme as _;
use utils::relative_time; use utils::relative_time;
use self::detail::IssueDetailView; use self::detail::IssueDetailView;
use crate::app::AppRoot; use crate::app::AppRoot;
use crate::issues::new_issue::NewIssueDialog; use crate::issues::new_issue::NewIssueView;
use crate::repo::helpers::short_id; use crate::repo::helpers::short_id;
use crate::shared::event_list::{EventHandler, EventList, EventRow, filter_toolbar}; use crate::shared::event_list::{EventHandler, EventList, EventRow};
use crate::shared::{log_dropped, panels}; use crate::shared::log_dropped;
pub mod detail; pub mod detail;
pub(crate) mod helpers; pub(crate) mod helpers;
@@ -73,9 +72,36 @@ impl IssuesView {
} }
} }
fn open_new_issue(&mut self, cx: &mut Context<Self>) { fn open_new_issue(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let dialog = NewIssueDialog::new(self.store.clone(), cx); let Some(addr) = self.store.read(cx).addr().cloned() else {
cx.open_dialog(dialog); return;
};
let id = SharedString::from(format!("new-issue:{addr}"));
let workspace = self.workspace.clone();
let workspace_for_build = workspace.clone();
let store = self.store.clone();
log_dropped(workspace.update(cx, |root, cx| {
root.panels().clone().update(cx, |panels, cx| {
panels.open(
PanelSlot::Split,
id.clone(),
move |_, cx| {
cx.new(|cx| {
NewIssueView::new(
workspace_for_build.clone(),
id.clone(),
store.clone(),
cx,
)
})
},
window,
cx,
)
})
}));
} }
/// Total number of issues across all statuses, for the sidebar label. /// Total number of issues across all statuses, for the sidebar label.
@@ -127,23 +153,30 @@ impl IssuesView {
fn render_header(&self, cx: &mut Context<Self>) -> AnyElement { fn render_header(&self, cx: &mut Context<Self>) -> AnyElement {
let counts = self.counts; let counts = self.counts;
let muted = cx.theme().colors.muted_foreground; let colors = cx.theme().colors;
let muted = colors.muted_foreground;
let weak = cx.entity().downgrade(); let weak = cx.entity().downgrade();
filter_toolbar( h_flex()
cx, .px_2()
[ .h_12()
.w_full()
.gap_3()
.border_b_1()
.border_color(colors.border)
.bg(colors.muted)
.child(
Segmented::new("issue-filter", self.filter) Segmented::new("issue-filter", self.filter)
.options(vec![ .options(vec![
SegmentedOption::new(IssueFilter::All, format!("All ({})", counts.total)) SegmentedOption::new(IssueFilter::All)
.label(format!("All ({})", counts.total))
.icon(Icon::named(IconRole::GitIssueDone).color(muted)), .icon(Icon::named(IconRole::GitIssueDone).color(muted)),
SegmentedOption::new(IssueFilter::Open, format!("Open ({})", counts.open)) SegmentedOption::new(IssueFilter::Open)
.label(format!("Open ({})", counts.open))
.icon(Icon::named(IconRole::GitIssueOngoing).color(muted)), .icon(Icon::named(IconRole::GitIssueOngoing).color(muted)),
SegmentedOption::new( SegmentedOption::new(IssueFilter::Closed)
IssueFilter::Closed, .label(format!("Closed ({})", counts.closed))
format!("Closed ({})", counts.closed), .icon(Icon::named(IconRole::GitIssueClosed).color(muted)),
)
.icon(Icon::named(IconRole::GitIssueClosed).color(muted)),
]) ])
.on_change(move |filter, _, cx| { .on_change(move |filter, _, cx| {
if let Err(error) = weak.update(cx, |this, cx| { if let Err(error) = weak.update(cx, |this, cx| {
@@ -152,18 +185,19 @@ impl IssuesView {
}) { }) {
log::warn!("failed to switch issue filter: {error}"); log::warn!("failed to switch issue filter: {error}");
} }
}) }),
.into_any_element(), )
div().flex_1().into_any_element(), .child(div().flex_1())
.child(
Button::new("new-issue") Button::new("new-issue")
.label("New issue") .label("New issue")
.icon(Icon::named(IconRole::CirclePlus)) .icon(Icon::named(IconRole::CirclePlus))
.on_click(cx.listener(|this, _, _, cx| { .small()
this.open_new_issue(cx); .on_click(cx.listener(|this, _, window, cx| {
})) this.open_new_issue(window, cx);
.into_any_element(), })),
], )
) .into_any_element()
} }
} }
@@ -197,15 +231,21 @@ impl Render for IssuesView {
Rc::new(move |_, window, cx| { Rc::new(move |_, window, cx| {
let id = SharedString::from(format!("issue:{issue_id}")); let id = SharedString::from(format!("issue:{issue_id}"));
let store = store.clone(); let store = store.clone();
panels::open_detail( log_dropped(workspace.update(cx, |root, cx| {
&workspace, root.panels().clone().update(cx, |panels, cx| {
id, panels.open(
move |_, cx| { PanelSlot::Split,
cx.new(|cx| IssueDetailView::new(store.clone(), issue_id, cx)) id,
}, move |_, cx| {
window, cx.new(|cx| {
cx, IssueDetailView::new(store.clone(), issue_id, cx)
); })
},
window,
cx,
)
})
}));
}) })
}; };
+100 -55
View File
@@ -1,70 +1,132 @@
use gpui::prelude::FluentBuilder as _;
use gpui::{ use gpui::{
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render, AnyElement, App, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _,
Styled as _, Window, div, Render, SharedString, Styled as _, Task, WeakEntity, Window, div,
}; };
use signed_state::RepoStore; use signed_state::RepoStore;
use ui::common::v_flex; use ui::button::Button;
use ui::dialog::{Dialog, DialogHandle}; use ui::common::{h_flex, v_flex};
use ui::field::Field; use ui::field::Field;
use ui::input::{Input, InputState}; use ui::input::{Input, InputState};
use ui::layout::panel::{Panel, PanelSlot};
use ui::theme::ActiveTheme as _; use ui::theme::ActiveTheme as _;
use crate::shared::progress::{DialogProgress, dialog_submit_button}; use crate::app::AppRoot;
use crate::shared::log_dropped;
use crate::shared::progress::error_row;
pub struct NewIssueDialog { pub struct NewIssueView {
handle: DialogHandle, workspace: WeakEntity<AppRoot>,
panel_id: SharedString,
store: Entity<RepoStore>, store: Entity<RepoStore>,
subject: Entity<InputState>, subject: Entity<InputState>,
content: Entity<InputState>, content: Entity<InputState>,
state: Entity<DialogProgress>, submitting: bool,
error: Option<SharedString>,
/// The running publish, cancelled when the view closes.
submit_task: Option<Task<()>>,
} }
impl NewIssueDialog { impl NewIssueView {
pub fn new(store: Entity<RepoStore>, cx: &mut App) -> Entity<Self> { pub fn new(
workspace: WeakEntity<AppRoot>,
panel_id: SharedString,
store: Entity<RepoStore>,
cx: &mut Context<Self>,
) -> Self {
let subject = InputState::new(cx); let subject = InputState::new(cx);
let content = InputState::builder().multiline().build(cx); let content = InputState::builder().multiline().build(cx);
let state = cx.new(|_| DialogProgress::default());
cx.new(|_| Self { Self {
handle: DialogHandle::new(true), workspace,
panel_id,
store, store,
subject, subject,
content, content,
state, submitting: false,
}) error: None,
submit_task: None,
}
} }
fn submit(&mut self, cx: &mut Context<Self>) { fn submit(&mut self, cx: &mut Context<Self>) {
// The publish runs detached in the store; one submission per dialog. if self.submitting {
if self.state.read(cx).busy {
return; return;
} }
let subject = self.subject.read(cx).value().to_string(); let subject = self.subject.read(cx).value().to_string();
let content = self.content.read(cx).value().to_string(); let content = self.content.read(cx).value().to_string();
let subject = (!subject.trim().is_empty()).then_some(subject); let subject = (!subject.trim().is_empty()).then_some(subject);
self.state.update(cx, |state, _| state.begin()); self.submitting = true;
self.store.update(cx, |store, cx| { self.error = None;
store.open_issue(subject, content, cx); cx.notify();
});
self.handle.close(cx); let workspace = self.workspace.clone();
let panel_id = self.panel_id.clone();
let task = self
.store
.update(cx, |store, cx| store.open_issue(subject, content, cx));
self.submit_task = Some(cx.spawn(async move |this, cx| match task.await {
Ok(()) => {
log_dropped(workspace.update(cx, |root, cx| {
root.panels().clone().update(cx, |panels, cx| {
panels.close(PanelSlot::Split, &panel_id, cx)
})
}));
}
Err(error) => {
log_dropped(this.update(cx, |this, cx| {
this.submitting = false;
this.error = Some(error.to_string().into());
cx.notify();
}));
}
}));
}
fn render_footer(&self, cx: &Context<Self>) -> AnyElement {
let weak = cx.entity().downgrade();
h_flex()
.px_4()
.py_2()
.w_full()
.justify_end()
.border_t_1()
.border_color(cx.theme().colors.border)
.child(
Button::new("create-issue")
.label("Create issue")
.loading(self.submitting)
.disabled(self.submitting)
.on_click(move |_, _, cx| {
log_dropped(weak.update(cx, |this, cx| this.submit(cx)));
}),
)
.into_any_element()
} }
} }
impl Render for NewIssueDialog { impl Panel for NewIssueView {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { fn title(&self, _cx: &App) -> SharedString {
let subject = self.subject.clone(); SharedString::from("New issue")
let content = self.content.clone(); }
let this = cx.entity().downgrade();
let action_state = self.state.clone();
Dialog::new("new-issue-dialog") fn loading(&self, _cx: &App) -> bool {
.handle(self.handle.clone()) self.submitting
.min_width(gpui::px(520.)) }
.title("New issue") }
.content(move |_, cx| {
impl Render for NewIssueView {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
v_flex()
.id("new-issue")
.size_full()
.child(
v_flex() v_flex()
.p_4()
.flex_1()
.gap_3() .gap_3()
.child( .child(
div() div()
@@ -74,31 +136,14 @@ impl Render for NewIssueDialog {
) )
.child( .child(
Field::new("issue-title", "Title") Field::new("issue-title", "Title")
.child(Input::new("issue-title-input", subject.clone())), .child(Input::new("issue-title-input", self.subject.clone())),
) )
.child( .child(
Field::new("issue-content", "Content") Field::new("issue-content", "Content")
.child(Input::new("issue-content-input", content.clone()).rows(6)), .child(Input::new("issue-content-input", self.content.clone()).rows(6)),
) )
.into_any_element() .when_some(error_row(&self.error, cx), |this, error| this.child(error)),
}) )
.actions(move |_, cx| { .child(self.render_footer(cx))
let this = this.clone();
let busy = action_state.read(cx).busy;
vec![
dialog_submit_button(
"create-issue",
"Create issue",
None,
busy,
&this,
|this, _window, cx| {
this.submit(cx);
Ok(())
},
)
.into_any_element() as AnyElement,
]
})
} }
} }
+24 -13
View File
@@ -19,7 +19,7 @@ use ui::common::{Sizable as _, StyledExt as _, h_flex, v_flex};
use ui::empty_state::EmptyState; use ui::empty_state::EmptyState;
use ui::icons::{Icon, IconRole}; use ui::icons::{Icon, IconRole};
use ui::input::InputState; use ui::input::InputState;
use ui::layout::panel::Panel; use ui::layout::panel::{Panel, PanelSlot};
use ui::layout::root::RootContext as _; use ui::layout::root::RootContext as _;
use ui::scroll_area::ScrollArea; use ui::scroll_area::ScrollArea;
use ui::spinner::Spinner; use ui::spinner::Spinner;
@@ -33,7 +33,6 @@ use crate::pull_requests::dialogs::update::UpdatePrDialog;
use crate::repo::commit_diff::{CommitDiffView, DiffPane}; use crate::repo::commit_diff::{CommitDiffView, DiffPane};
use crate::shared::event_list::commit_list; use crate::shared::event_list::commit_list;
use crate::shared::log_dropped; use crate::shared::log_dropped;
use crate::shared::panels::open_detail;
use crate::shared::widgets::status_badge; use crate::shared::widgets::status_badge;
const NOT_FOUND: &str = "Pull request not found"; const NOT_FOUND: &str = "Pull request not found";
@@ -315,19 +314,31 @@ impl PullRequestDetailView {
Some(addr) => SharedString::from(format!("commit:{addr}:{commit_id}")), Some(addr) => SharedString::from(format!("commit:{addr}:{commit_id}")),
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 commit_id = commit_id.to_owned(); let commit_id = commit_id.to_owned();
open_detail(
&workspace, log_dropped(workspace.update(cx, |root, cx| {
id, root.panels().clone().update(cx, |panels, cx| {
move |window, cx| { panels.open(
cx.new(|cx| { PanelSlot::Split,
CommitDiffView::new(worktree.clone(), commit_id.clone(), false, window, cx) id,
}) move |window, cx| {
}, cx.new(|cx| {
window, CommitDiffView::new(
cx, worktree.clone(),
); commit_id.clone(),
false,
window,
cx,
)
})
},
window,
cx,
)
})
}));
} }
fn render_tabs(&self, cx: &mut Context<Self>) -> AnyElement { fn render_tabs(&self, cx: &mut Context<Self>) -> AnyElement {
+102 -92
View File
@@ -1,3 +1,5 @@
use std::rc::Rc;
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder as _;
use gpui::{ use gpui::{
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render, AnyElement, App, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render,
@@ -7,12 +9,11 @@ use metadata::ProfileDirectory;
use nostr::prelude::{Kind, PublicKey}; use nostr::prelude::{Kind, PublicKey};
use signed_core::GitEvent; use signed_core::GitEvent;
use signed_state::RepoStore; use signed_state::RepoStore;
use std::rc::Rc;
use ui::alert::{Alert, AlertSeverity}; use ui::alert::{Alert, AlertSeverity};
use ui::common::v_flex; use ui::common::{Sizable, h_flex, v_flex};
use ui::dropdown_menu::DropdownMenu; use ui::dropdown_menu::DropdownMenu;
use ui::icons::{Icon, IconRole}; use ui::icons::{Icon, IconRole};
use ui::layout::panel::Panel; use ui::layout::panel::{Panel, PanelSlot};
use ui::menu::MenuItem; use ui::menu::MenuItem;
use ui::segmented::{Segmented, SegmentedOption}; use ui::segmented::{Segmented, SegmentedOption};
use ui::theme::ActiveTheme as _; use ui::theme::ActiveTheme as _;
@@ -32,9 +33,8 @@ pub use send_patch::SendPatchView;
use crate::app::AppRoot; use crate::app::AppRoot;
use crate::issues::helpers::{StatusCounts, filter_by_status}; use crate::issues::helpers::{StatusCounts, filter_by_status};
use crate::repo::helpers::short_id; use crate::repo::helpers::short_id;
use crate::shared::event_list::{EventHandler, EventList, EventRow, filter_toolbar}; use crate::shared::event_list::{EventHandler, EventList, EventRow};
use crate::shared::log_dropped; use crate::shared::log_dropped;
use crate::shared::panels::open_detail;
pub struct PullRequestsView { pub struct PullRequestsView {
workspace: WeakEntity<AppRoot>, workspace: WeakEntity<AppRoot>,
@@ -141,23 +141,27 @@ impl PullRequestsView {
let workspace_for_build = workspace.clone(); let workspace_for_build = workspace.clone();
let store = self.store.clone(); let store = self.store.clone();
open_detail( log_dropped(workspace.update(cx, |root, cx| {
&workspace, root.panels().clone().update(cx, |panels, cx| {
id.clone(), panels.open(
move |window, cx| { PanelSlot::Split,
cx.new(|cx| { id.clone(),
NewPullRequestView::new( move |window, cx| {
workspace_for_build.clone(), cx.new(|cx| {
id.clone(), NewPullRequestView::new(
store.clone(), workspace_for_build.clone(),
window, id.clone(),
cx, store.clone(),
) window,
}) cx,
}, )
window, })
cx, },
); window,
cx,
)
})
}));
} }
fn open_send_patch(&mut self, window: &mut Window, cx: &mut Context<Self>) { fn open_send_patch(&mut self, window: &mut Window, cx: &mut Context<Self>) {
@@ -170,63 +174,64 @@ impl PullRequestsView {
let workspace_for_build = workspace.clone(); let workspace_for_build = workspace.clone();
let store = self.store.clone(); let store = self.store.clone();
open_detail( log_dropped(workspace.update(cx, |root, cx| {
&workspace, root.panels().clone().update(cx, |panels, cx| {
id.clone(), panels.open(
move |window, cx| { PanelSlot::Split,
cx.new(|cx| { id.clone(),
SendPatchView::new( move |window, cx| {
workspace_for_build.clone(), cx.new(|cx| {
id.clone(), SendPatchView::new(
store.clone(), workspace_for_build.clone(),
window, id.clone(),
cx, store.clone(),
) window,
}) cx,
}, )
window, })
cx, },
); window,
cx,
)
})
}));
} }
fn render_header(&self, cx: &mut Context<Self>) -> AnyElement { fn render_header(&self, cx: &mut Context<Self>) -> AnyElement {
let counts = self.counts; let counts = self.counts;
let muted = cx.theme().colors.muted_foreground; let colors = cx.theme().colors;
let muted = colors.muted_foreground;
let weak = cx.entity().downgrade(); let weak = cx.entity().downgrade();
let open_weak = cx.entity().downgrade(); let open_weak = cx.entity().downgrade();
let menu_open_weak = cx.entity().downgrade(); let menu_open_weak = cx.entity().downgrade();
let patch_weak = cx.entity().downgrade(); let patch_weak = cx.entity().downgrade();
filter_toolbar( h_flex()
cx, .px_2()
[ .h_12()
.w_full()
.gap_3()
.border_b_1()
.border_color(colors.border)
.bg(colors.muted)
.child(
Segmented::new("pr-filter", self.filter) Segmented::new("pr-filter", self.filter)
.options(vec![ .options(vec![
SegmentedOption::new( SegmentedOption::new(PullRequestFilter::All)
PullRequestFilter::All, .label(format!("All ({})", counts.total))
format!("All ({})", counts.total), .icon(Icon::named(IconRole::GitPullRequest).color(muted)),
) SegmentedOption::new(PullRequestFilter::Open)
.icon(Icon::named(IconRole::GitPullRequest).color(muted)), .label(format!("Open ({})", counts.open))
SegmentedOption::new( .icon(Icon::named(IconRole::GitPullRequest).color(muted)),
PullRequestFilter::Open, SegmentedOption::new(PullRequestFilter::Closed)
format!("Open ({})", counts.open), .label(format!("Closed ({})", counts.closed))
) .icon(Icon::named(IconRole::GitPullRequestClosed).color(muted)),
.icon(Icon::named(IconRole::GitPullRequest).color(muted)), SegmentedOption::new(PullRequestFilter::Draft)
SegmentedOption::new( .label(format!("Draft ({})", counts.draft))
PullRequestFilter::Closed, .icon(Icon::named(IconRole::GitPullRequestDraft).color(muted)),
format!("Closed ({})", counts.closed), SegmentedOption::new(PullRequestFilter::Merged)
) .label(format!("Merged ({})", counts.applied))
.icon(Icon::named(IconRole::GitPullRequestClosed).color(muted)), .icon(Icon::named(IconRole::GitPullRequestMerged).color(muted)),
SegmentedOption::new(
PullRequestFilter::Draft,
format!("Draft ({})", counts.draft),
)
.icon(Icon::named(IconRole::GitPullRequestDraft).color(muted)),
SegmentedOption::new(
PullRequestFilter::Merged,
format!("Merged ({})", counts.applied),
)
.icon(Icon::named(IconRole::GitPullRequestMerged).color(muted)),
]) ])
.on_change(move |filter, _, cx| { .on_change(move |filter, _, cx| {
if let Err(error) = weak.update(cx, |this, cx| { if let Err(error) = weak.update(cx, |this, cx| {
@@ -235,12 +240,14 @@ impl PullRequestsView {
}) { }) {
log::warn!("failed to switch PR filter: {error}"); log::warn!("failed to switch PR filter: {error}");
} }
}) }),
.into_any_element(), )
div().flex_1().into_any_element(), .child(div().flex_1())
.child(
DropdownMenu::new("new-pr-actions") DropdownMenu::new("new-pr-actions")
.label("New") .label("New")
.icon(Icon::named(IconRole::GitPullRequest)) .icon(Icon::named(IconRole::GitPullRequest))
.small()
.open(self.new_pr_menu_open) .open(self.new_pr_menu_open)
.on_click(move |_, window, cx| { .on_click(move |_, window, cx| {
if let Err(error) = if let Err(error) =
@@ -264,10 +271,9 @@ impl PullRequestsView {
})); }));
} }
})] })]
}) }),
.into_any_element(), )
], .into_any_element()
)
} }
} }
@@ -310,23 +316,27 @@ impl Render for PullRequestsView {
let id = SharedString::from(format!("pr:{pr_id}")); let id = SharedString::from(format!("pr:{pr_id}"));
let workspace_for_build = workspace.clone(); let workspace_for_build = workspace.clone();
let store = store.clone(); let store = store.clone();
open_detail( log_dropped(workspace.update(cx, |root, cx| {
&workspace, root.panels().clone().update(cx, |panels, cx| {
id, panels.open(
move |window, cx| { PanelSlot::Split,
cx.new(|cx| { id,
PullRequestDetailView::new( move |window, cx| {
workspace_for_build.clone(), cx.new(|cx| {
store.clone(), PullRequestDetailView::new(
pr_id, workspace_for_build.clone(),
window, store.clone(),
cx, pr_id,
) window,
}) cx,
}, )
window, })
cx, },
); window,
cx,
)
})
}));
}) })
}; };
+27 -14
View File
@@ -17,7 +17,7 @@ use ui::common::{StyledExt as _, h_flex, v_flex};
use ui::empty_state::EmptyState; use ui::empty_state::EmptyState;
use ui::icons::{Icon, IconRole}; use ui::icons::{Icon, IconRole};
use ui::input::{Input, InputState}; use ui::input::{Input, InputState};
use ui::layout::panel::Panel; use ui::layout::panel::{Panel, PanelSlot};
use ui::menu::Menu; use ui::menu::Menu;
use ui::spinner::Spinner; use ui::spinner::Spinner;
use ui::tabs::{Tab, Tabs}; use ui::tabs::{Tab, Tabs};
@@ -28,7 +28,6 @@ use crate::repo::commit_diff::{CommitDiffView, DiffPane};
use crate::repo::helpers::announcement_display_name; use crate::repo::helpers::announcement_display_name;
use crate::shared::event_list::commit_list; use crate::shared::event_list::commit_list;
use crate::shared::log_dropped; use crate::shared::log_dropped;
use crate::shared::panels::{close_detail, open_detail};
use crate::shared::progress::error_row; use crate::shared::progress::error_row;
pub struct NewPullRequestView { pub struct NewPullRequestView {
@@ -245,7 +244,11 @@ impl NewPullRequestView {
this.update(cx, |this, _cx| { this.update(cx, |this, _cx| {
this.submitting = false; this.submitting = false;
})?; })?;
close_detail(&workspace, &panel_id, cx); log_dropped(workspace.update(cx, |root, cx| {
root.panels().clone().update(cx, |panels, cx| {
panels.close(PanelSlot::Split, &panel_id, cx)
})
}));
Ok(()) Ok(())
}); });
self.push_task(task); self.push_task(task);
@@ -261,17 +264,27 @@ impl NewPullRequestView {
}; };
let workspace = self.workspace.clone(); let workspace = self.workspace.clone();
let commit_id = commit_id.to_owned(); let commit_id = commit_id.to_owned();
open_detail( log_dropped(workspace.update(cx, |root, cx| {
&workspace, root.panels().clone().update(cx, |panels, cx| {
id, panels.open(
move |window, cx| { PanelSlot::Split,
cx.new(|cx| { id,
CommitDiffView::new(repo_path.clone(), commit_id.clone(), false, window, cx) move |window, cx| {
}) cx.new(|cx| {
}, CommitDiffView::new(
window, repo_path.clone(),
cx, commit_id.clone(),
); false,
window,
cx,
)
})
},
window,
cx,
)
})
}));
} }
fn submit_enabled(&self, cx: &App) -> bool { fn submit_enabled(&self, cx: &App) -> bool {
@@ -8,12 +8,11 @@ use ui::button::Button;
use ui::common::{ResultLogErr as _, h_flex, v_flex}; use ui::common::{ResultLogErr as _, h_flex, v_flex};
use ui::icons::{Icon, IconRole}; use ui::icons::{Icon, IconRole};
use ui::input::{Input, InputState}; use ui::input::{Input, InputState};
use ui::layout::panel::Panel; use ui::layout::panel::{Panel, PanelSlot};
use ui::theme::ActiveTheme as _; use ui::theme::ActiveTheme as _;
use crate::app::AppRoot; use crate::app::AppRoot;
use crate::shared::log_dropped; use crate::shared::log_dropped;
use crate::shared::panels::close_detail;
use crate::shared::progress::error_row; use crate::shared::progress::error_row;
pub struct SendPatchView { pub struct SendPatchView {
@@ -80,13 +79,16 @@ impl SendPatchView {
cx, cx,
) )
}); });
let workspace = self.workspace.clone();
let panel_id = self.panel_id.clone();
cx.spawn(async move |this, cx| match task.await { cx.spawn(async move |this, cx| match task.await {
Ok(()) => { Ok(()) => {
this.update(cx, |this, cx| { log_dropped(workspace.update(cx, |root, cx| {
close_detail(&this.workspace, &this.panel_id, cx) root.panels().clone().update(cx, |panels, cx| {
}) panels.close(PanelSlot::Split, &panel_id, cx)
.log_err(); })
}));
} }
Err(error) => { Err(error) => {
this.update(cx, |this, cx| { this.update(cx, |this, cx| {
+59 -40
View File
@@ -2,10 +2,11 @@ use gpui::{App, AppContext as _, SharedString, WeakEntity, Window};
use nostr::prelude::EventId; use nostr::prelude::EventId;
use signed_core::{Announcement, RepoAddr}; use signed_core::{Announcement, RepoAddr};
use signed_state::RepoStore; use signed_state::RepoStore;
use ui::layout::panel::PanelSlot;
use crate::app::AppRoot; use crate::app::AppRoot;
use crate::repo::RepoDetailView; use crate::repo::RepoDetailView;
use crate::shared::panels; use crate::shared::log_dropped;
/// An item of a repository to open from outside its detail panel. /// An item of a repository to open from outside its detail panel.
pub enum RepoItem { pub enum RepoItem {
@@ -27,17 +28,23 @@ pub fn open_repo_panel(
let hint = hint.cloned(); let hint = hint.cloned();
let workspace_for_build = workspace.clone(); let workspace_for_build = workspace.clone();
panels::open_primary( log_dropped(workspace.update(cx, |root, cx| {
workspace, root.panels().clone().update(cx, |panels, cx| {
id, panels.open(
move |window, cx| { PanelSlot::Main,
let addr = addr.clone(); id,
let hint = hint.clone(); move |window, cx| {
cx.new(|cx| RepoDetailView::new(workspace_for_build.clone(), addr, hint, window, cx)) let addr = addr.clone();
}, let hint = hint.clone();
window, cx.new(|cx| {
cx, RepoDetailView::new(workspace_for_build.clone(), addr, hint, window, cx)
); })
},
window,
cx,
)
})
}));
} }
/// Opens an issue or pull request using a store built here. /// Opens an issue or pull request using a store built here.
@@ -54,39 +61,51 @@ pub fn open_repo_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 store = store.clone(); let store = store.clone();
panels::open_detail( log_dropped(workspace.update(cx, |root, cx| {
workspace, root.panels().clone().update(cx, |panels, cx| {
id, panels.open(
move |_, cx| { PanelSlot::Split,
cx.new(|cx| { id,
crate::issues::detail::IssueDetailView::new(store.clone(), issue_id, cx) move |_, cx| {
}) cx.new(|cx| {
}, crate::issues::detail::IssueDetailView::new(
window, store.clone(),
cx, issue_id,
); cx,
)
})
},
window,
cx,
)
})
}));
} }
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 workspace_for_build = workspace.clone(); let workspace_for_build = workspace.clone();
let store = store.clone(); let store = store.clone();
panels::open_detail( log_dropped(workspace.update(cx, |root, cx| {
workspace, root.panels().clone().update(cx, |panels, cx| {
id, panels.open(
move |window, cx| { PanelSlot::Split,
cx.new(|cx| { id,
crate::pull_requests::PullRequestDetailView::new( move |window, cx| {
workspace_for_build.clone(), cx.new(|cx| {
store.clone(), crate::pull_requests::PullRequestDetailView::new(
pr_id, workspace_for_build.clone(),
window, store.clone(),
cx, pr_id,
) window,
}) cx,
}, )
window, })
cx, },
); window,
cx,
)
})
}));
} }
// Opening a patch series directly is not a feature. // Opening a patch series directly is not a feature.
_ => {} _ => {}
-1
View File
@@ -260,7 +260,6 @@ impl RepoFilesView {
let change_view = view.clone(); let change_view = view.clone();
let disclosure_view = view; let disclosure_view = view;
// Mirrors the sidebar's left inset, so rows stay aligned while the scrollbar hugs its border.
Tree::new("repo-tree") Tree::new("repo-tree")
.pr_2() .pr_2()
.selected(selected) .selected(selected)
+23 -12
View File
@@ -14,6 +14,7 @@ use ui::button::{Button, ButtonVariant};
use ui::common::{Sizable as _, v_flex}; use ui::common::{Sizable as _, v_flex};
use ui::empty_state::EmptyState; use ui::empty_state::EmptyState;
use ui::icons::{Icon, IconRole}; use ui::icons::{Icon, IconRole};
use ui::layout::panel::PanelSlot;
use ui::spinner::Spinner; use ui::spinner::Spinner;
use ui::theme::ActiveTheme as _; use ui::theme::ActiveTheme as _;
use ui::tooltip::Tooltip; use ui::tooltip::Tooltip;
@@ -22,7 +23,7 @@ use super::RepoDetailView;
use super::commit_diff::CommitDiffView; use super::commit_diff::CommitDiffView;
use crate::app::AppRoot; use crate::app::AppRoot;
use crate::shared::event_list::commit_list; use crate::shared::event_list::commit_list;
use crate::shared::panels; use crate::shared::log_dropped;
pub struct RepoHistoryView { pub struct RepoHistoryView {
store: Entity<RepoStore>, store: Entity<RepoStore>,
@@ -138,17 +139,27 @@ impl RepoHistoryView {
}; };
let workspace = self.workspace.clone(); let workspace = self.workspace.clone();
panels::open_detail( log_dropped(workspace.update(cx, |root, cx| {
&workspace, root.panels().clone().update(cx, |panels, cx| {
id, panels.open(
move |window, cx| { PanelSlot::Split,
cx.new(|cx| { id,
CommitDiffView::new(worktree.clone(), commit_id.clone(), true, window, cx) move |window, cx| {
}) cx.new(|cx| {
}, CommitDiffView::new(
window, worktree.clone(),
cx, commit_id.clone(),
); true,
window,
cx,
)
})
},
window,
cx,
)
})
}));
} }
} }
+1
View File
@@ -1451,6 +1451,7 @@ impl RepoDetailView {
}) })
.child( .child(
h_flex() h_flex()
.px_2()
.w_full() .w_full()
.gap_2() .gap_2()
.child( .child(
+2 -15
View File
@@ -1,5 +1,5 @@
//! The shared issue and pull-request lists: toolbar, uniform rows, scrollbar //! The shared issue and pull-request lists: uniform rows, scrollbar overlay, and
//! overlay, and empty state, plus the scrollable commit list. //! empty state, plus the scrollable commit list.
use std::rc::Rc; use std::rc::Rc;
use std::sync::Arc; use std::sync::Arc;
@@ -189,19 +189,6 @@ impl EventList {
} }
} }
/// The toolbar above the issue and pull-request lists: a filter and its actions.
pub fn filter_toolbar(cx: &App, children: impl IntoIterator<Item = AnyElement>) -> AnyElement {
h_flex()
.px_4()
.w_full()
.gap_3()
.border_b_1()
.border_color(cx.theme().colors.border)
.bg(cx.theme().colors.muted)
.children(children)
.into_any_element()
}
/// A scrollable commit list: uniform `commit_row`s under a scrollbar overlay. /// A scrollable commit list: uniform `commit_row`s under a scrollbar overlay.
pub fn commit_list( pub fn commit_list(
id: &'static str, id: &'static str,
-1
View File
@@ -3,7 +3,6 @@ use metadata::ProfileDirectory;
use nostr::prelude::PublicKey; use nostr::prelude::PublicKey;
pub mod event_list; pub mod event_list;
pub mod panels;
pub mod progress; pub mod progress;
pub mod widgets; pub mod widgets;
-67
View File
@@ -1,67 +0,0 @@
use gpui::{App, AppContext, Entity, SharedString, WeakEntity, Window};
use ui::layout::panel::{Panel, PanelSlot};
use crate::app::AppRoot;
use crate::shared::log_dropped;
/// Opens a panel in `slot`, reusing it when it is already open.
fn open_slot<P, F>(
slot: PanelSlot,
workspace: &WeakEntity<AppRoot>,
id: impl Into<SharedString>,
build: F,
window: &mut Window,
cx: &mut App,
) where
P: Panel + 'static,
F: Fn(&mut Window, &mut App) -> Entity<P> + 'static,
{
let result = workspace.update(cx, |workspace, cx| {
workspace
.panels()
.clone()
.update(cx, |panels, cx| panels.open(slot, id, build, window, cx))
});
if let Err(error) = result {
log::warn!("failed to open panel: {error}");
}
}
/// Opens a repository in the main panel, reusing it when it is already open.
pub fn open_primary<P, F>(
workspace: &WeakEntity<AppRoot>,
id: impl Into<SharedString>,
build: F,
window: &mut Window,
cx: &mut App,
) where
P: Panel + 'static,
F: Fn(&mut Window, &mut App) -> Entity<P> + 'static,
{
open_slot(PanelSlot::Main, workspace, id, build, window, cx);
}
/// Opens a detail panel beside the main panel, reusing it when it is already open.
pub fn open_detail<P, F>(
workspace: &WeakEntity<AppRoot>,
id: impl Into<SharedString>,
build: F,
window: &mut Window,
cx: &mut App,
) where
P: Panel + 'static,
F: Fn(&mut Window, &mut App) -> Entity<P> + 'static,
{
open_slot(PanelSlot::Split, workspace, id, build, window, cx);
}
/// Closes the detail panel open under `id`.
pub fn close_detail(workspace: &WeakEntity<AppRoot>, id: &SharedString, cx: &mut impl AppContext) {
let result = workspace.update(cx, |workspace, cx| {
workspace
.panels()
.clone()
.update(cx, |panels, cx| panels.close(PanelSlot::Split, id, cx))
});
log_dropped(result);
}
+45 -35
View File
@@ -15,6 +15,7 @@ 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::PanelSlot;
use ui::layout::root::RootContext as _; use ui::layout::root::RootContext as _;
use ui::menu::{Menu, MenuItem}; use ui::menu::{Menu, MenuItem};
use ui::tooltip::Tooltip; use ui::tooltip::Tooltip;
@@ -24,7 +25,7 @@ use crate::explore::ExploreView;
use crate::identity::exit::ExitDialog; use crate::identity::exit::ExitDialog;
use crate::repo::{RepoDetailView, actions, dialogs}; use crate::repo::{RepoDetailView, actions, dialogs};
use crate::settings::SettingsDialog; use crate::settings::SettingsDialog;
use crate::shared::{log_dropped, panels}; use crate::shared::log_dropped;
mod repository_switcher; mod repository_switcher;
@@ -361,23 +362,28 @@ impl TitlebarView {
let id = SharedString::from(format!("repo:{}", announcement.addr())); let id = SharedString::from(format!("repo:{}", announcement.addr()));
let workspace = self.app.clone(); let workspace = self.app.clone();
let workspace_for_build = workspace.clone(); let workspace_for_build = workspace.clone();
panels::open_primary(
&workspace, log_dropped(workspace.update(cx, |root, cx| {
id, root.panels().clone().update(cx, |panels, cx| {
move |window, cx| { panels.open(
cx.new(|cx| { PanelSlot::Main,
RepoDetailView::new_local_announced( id,
workspace_for_build.clone(), move |window, cx| {
announcement.clone(), cx.new(|cx| {
path.clone(), RepoDetailView::new_local_announced(
window, workspace_for_build.clone(),
cx, announcement.clone(),
) path.clone(),
}) window,
}, cx,
window, )
cx, })
); },
window,
cx,
)
})
}));
return; return;
} }
@@ -385,23 +391,27 @@ impl TitlebarView {
let workspace = self.app.clone(); let workspace = self.app.clone();
let workspace_for_build = workspace.clone(); let workspace_for_build = workspace.clone();
panels::open_primary( log_dropped(workspace.update(cx, |root, cx| {
&workspace, root.panels().clone().update(cx, |panels, cx| {
id, panels.open(
move |window, cx| { PanelSlot::Main,
cx.new(|cx| { id,
RepoDetailView::new_local( move |window, cx| {
workspace_for_build.clone(), cx.new(|cx| {
path.clone(), RepoDetailView::new_local(
nip34.clone(), workspace_for_build.clone(),
window, path.clone(),
cx, nip34.clone(),
) window,
}) cx,
}, )
window, })
cx, },
); window,
cx,
)
})
}));
} }
pub fn render_user_menu(&self, cx: &App) -> Option<AnyElement> { pub fn render_user_menu(&self, cx: &App) -> Option<AnyElement> {
+21 -11
View File
@@ -605,10 +605,14 @@ impl RepoStore {
.is_some_and(|addr| addr.public_key() == *user) .is_some_and(|addr| addr.public_key() == *user)
} }
pub fn open_issue(&mut self, subject: Option<String>, content: String, cx: &mut Context<Self>) { pub fn open_issue(
&mut self,
subject: Option<String>,
content: String,
cx: &mut Context<Self>,
) -> Task<Result<(), Error>> {
let Some(addr) = self.addr.clone() else { let Some(addr) = self.addr.clone() else {
self.not_announced(cx); return self.action_error("This repository is not published to Nostr yet", cx);
return;
}; };
let builder = GitIssue { let builder = GitIssue {
@@ -619,7 +623,7 @@ impl RepoStore {
} }
.into_event_builder(); .into_event_builder();
self.publish(builder, cx); self.publish(builder, cx)
} }
pub fn comments_of(&self, root: &EventId) -> impl Iterator<Item = &Event> { pub fn comments_of(&self, root: &EventId) -> impl Iterator<Item = &Event> {
@@ -650,10 +654,11 @@ impl RepoStore {
.and_then(|a| a.relays.first()) .and_then(|a| a.relays.first())
.cloned(); .cloned();
self.publish( let task = self.publish(
comment_builder(root, parent, relay_hint.as_ref(), &addr, content), comment_builder(root, parent, relay_hint.as_ref(), &addr, content),
cx, cx,
); );
self.tasks.push(task);
} }
#[expect(clippy::too_many_arguments, reason = "mirrors the PR event")] #[expect(clippy::too_many_arguments, reason = "mirrors the PR event")]
@@ -1167,7 +1172,8 @@ impl RepoStore {
Tag::coordinate(addr.clone().into(), None), Tag::coordinate(addr.clone().into(), None),
]); ]);
self.publish(builder, cx); let task = self.publish(builder, cx);
self.tasks.push(task);
} }
fn action_announcement(&self, cx: &App) -> Option<Announcement> { fn action_announcement(&self, cx: &App) -> Option<Announcement> {
@@ -1403,8 +1409,12 @@ impl RepoStore {
Task::ready(Err(anyhow::anyhow!("{message}"))) Task::ready(Err(anyhow::anyhow!("{message}")))
} }
/// Publish an event to the repository's relays, and update the store with any error. /// Publish an event to the repository's relays; the task fails when it is not accepted and the store records the error.
fn publish(&mut self, builder: EventBuilder, cx: &mut Context<Self>) { fn publish(
&mut self,
builder: EventBuilder,
cx: &mut Context<Self>,
) -> Task<Result<(), Error>> {
self.last_error = None; self.last_error = None;
let backend = Backend::global(cx); let backend = Backend::global(cx);
@@ -1432,17 +1442,17 @@ impl RepoStore {
} }
.await; .await;
if let Err(e) = publish_result { if let Err(e) = &publish_result {
this.update(cx, |this, cx| { this.update(cx, |this, cx| {
this.last_error = Some(e.to_string()); this.last_error = Some(e.to_string());
cx.notify(); cx.notify();
})?; })?;
} }
Ok(()) publish_result.map(|_| ())
}); });
self.tasks.push(task); task
} }
} }
+65 -38
View File
@@ -7,8 +7,8 @@
//! //!
//! let mode = Segmented::new("editor-mode", "text") //! let mode = Segmented::new("editor-mode", "text")
//! .options([ //! .options([
//! SegmentedOption::new("text", "Text"), //! SegmentedOption::new("text").label("Text"),
//! SegmentedOption::new("preview", "Preview"), //! SegmentedOption::new("preview").label("Preview"),
//! ]) //! ])
//! .on_change(|value, _window, _cx| println!("mode: {value}")); //! .on_change(|value, _window, _cx| println!("mode: {value}"));
//! ``` //! ```
@@ -18,8 +18,9 @@ use std::rc::Rc;
use gpui::prelude::FluentBuilder; use gpui::prelude::FluentBuilder;
use gpui::{ use gpui::{
AnimationExt as _, App, Bounds, ElementId, Entity, InteractiveElement as _, IntoElement, AnimationExt as _, App, Bounds, ElementId, Entity, InteractiveElement as _, IntoElement,
KeyDownEvent, ParentElement as _, Point, RenderOnce, Role, SharedString, SpringAnimation, KeyDownEvent, ParentElement as _, Pixels, Point, RenderOnce, Role, SharedString,
StatefulInteractiveElement as _, StyleRefinement, Styled as _, Toggled, Window, canvas, div, SpringAnimation, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Toggled,
Window, canvas, div,
}; };
use crate::components::common::{ use crate::components::common::{
@@ -36,21 +37,29 @@ type ChangeHandler<T> = Rc<dyn Fn(T, &mut Window, &mut App)>;
#[must_use] #[must_use]
pub struct SegmentedOption<T> { pub struct SegmentedOption<T> {
value: T, value: T,
label: SharedString, label: Option<SharedString>,
icon: Option<Icon>, icon: Option<Icon>,
a11y_label: Option<SharedString>,
} }
impl<T> SegmentedOption<T> { impl<T> SegmentedOption<T> {
/// Creates a choice showing `label`; picking it reports `value`. /// Creates a choice that reports `value` when picked.
pub fn new<L>(value: T, label: L) -> Self pub fn new(value: T) -> Self {
Self {
value,
label: None,
icon: None,
a11y_label: None,
}
}
/// Sets the text shown for the segment.
pub fn label<L>(mut self, label: L) -> Self
where where
L: Into<SharedString>, L: Into<SharedString>,
{ {
Self { self.label = Some(label.into());
value, self
label: label.into(),
icon: None,
}
} }
/// Sets a leading icon for the segment. /// Sets a leading icon for the segment.
@@ -61,6 +70,15 @@ impl<T> SegmentedOption<T> {
self.icon = Some(icon.into()); self.icon = Some(icon.into());
self self
} }
/// Overrides the accessibility label, which defaults to the visible label.
pub fn accessibility_label<L>(mut self, label: L) -> Self
where
L: Into<SharedString>,
{
self.a11y_label = Some(label.into());
self
}
} }
/// Converts a `(value, label)` pair into an option. /// Converts a `(value, label)` pair into an option.
@@ -69,11 +87,7 @@ where
L: Into<SharedString>, L: Into<SharedString>,
{ {
fn from((value, label): (T, L)) -> Self { fn from((value, label): (T, L)) -> Self {
Self { Self::new(value).label(label)
value,
label: label.into(),
icon: None,
}
} }
} }
@@ -195,10 +209,10 @@ where
.unwrap_or_else(|| SharedString::from(self.id.to_string())); .unwrap_or_else(|| SharedString::from(self.id.to_string()));
window.with_element_namespace(self.id.clone(), |window| { window.with_element_namespace(self.id.clone(), |window| {
let geometry: Entity<Vec<Option<Bounds<gpui::Pixels>>>> = let geometry: Entity<Vec<Option<Bounds<Pixels>>>> =
window.use_keyed_state("segmented-geometry", cx, |_, _| Vec::new()); window.use_keyed_state("segmented-geometry", cx, |_, _| Vec::new());
let track_origin: Entity<Option<Point<gpui::Pixels>>> = let track_origin: Entity<Option<Point<Pixels>>> =
window.use_keyed_state("segmented-track-origin", cx, |_, _| None); window.use_keyed_state("segmented-track-origin", cx, |_, _| None);
let focus = focus_handle(&self.id, window, cx); let focus = focus_handle(&self.id, window, cx);
@@ -226,6 +240,7 @@ where
} else { } else {
muted_foreground muted_foreground
}; };
let a11y_label = segment.a11y_label.clone().or_else(|| segment.label.clone());
h_flex() h_flex()
.id(("segment", index)) .id(("segment", index))
@@ -240,26 +255,24 @@ where
.when(!is_selected, |segment| { .when(!is_selected, |segment| {
segment.hover(|style| style.bg(surface)) segment.hover(|style| style.bg(surface))
}) })
.role(Role::RadioButton) .when_some(a11y_label, |segment, label| segment.aria_label(label))
.aria_label(segment.label.clone())
.aria_toggled(Toggled::from(is_selected)) .aria_toggled(Toggled::from(is_selected))
.when_some(segment.icon.clone(), |segment, icon| { .when_some(segment.icon.clone(), |segment, icon| {
segment.child(icon.size(self.size.icon_rems()).color(content_color)) segment.child(icon.size(self.size.icon_rems()).color(content_color))
}) })
.child(segment.label.clone()) .when_some(segment.label.clone(), |segment, label| segment.child(label))
.child( .child(
canvas( canvas(
{ measure(&geometry, move |geometry, bounds| {
let geometry = geometry.clone(); if geometry.get(index) == Some(&Some(bounds)) {
move |bounds, _, cx| { return false;
geometry.update(cx, |geometry, _| {
if geometry.len() <= index {
geometry.resize(index + 1, None);
}
geometry[index] = Some(bounds);
});
} }
}, if geometry.len() <= index {
geometry.resize(index + 1, None);
}
geometry[index] = Some(bounds);
true
}),
|_, _, _, _| {}, |_, _, _, _| {},
) )
.absolute() .absolute()
@@ -298,13 +311,13 @@ where
.control_text(self.size) .control_text(self.size)
.child( .child(
canvas( canvas(
{ measure(&track_origin, |origin, bounds| {
let track_origin = track_origin.clone(); if *origin == Some(bounds.origin) {
move |bounds, _, cx| { return false;
track_origin
.update(cx, |origin, _| *origin = Some(bounds.origin));
} }
}, *origin = Some(bounds.origin);
true
}),
|_, _, _, _| {}, |_, _, _, _| {},
) )
.absolute() .absolute()
@@ -367,3 +380,17 @@ where
}) })
} }
} }
/// Stores what a frame measured and requests the frame that draws from it.
fn measure<S: 'static>(
state: &Entity<S>,
record: impl Fn(&mut S, Bounds<Pixels>) -> bool + 'static,
) -> impl Fn(Bounds<Pixels>, &mut Window, &mut App) + 'static {
let state = state.clone();
move |bounds, window, cx| {
let changed = state.update(cx, |state, _| record(state, bounds));
if changed {
window.request_animation_frame();
}
}
}