chore: move new issue/pull form into a split panel
This commit is contained in:
@@ -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
|
||||
- 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
|
||||
- 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
|
||||
|
||||
@@ -34,6 +35,7 @@
|
||||
- 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 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
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ use crate::app::AppRoot;
|
||||
use crate::explore::helpers::pick_banner;
|
||||
use crate::identity::import::ImportDialog;
|
||||
use crate::identity::onboarding::OnboardingDialog;
|
||||
use crate::shared::panels;
|
||||
use crate::shared::log_dropped;
|
||||
|
||||
mod helpers;
|
||||
|
||||
@@ -54,16 +54,20 @@ impl ExploreView {
|
||||
|
||||
/// 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) {
|
||||
panels::open_primary(
|
||||
workspace,
|
||||
Self::PANEL_ID,
|
||||
{
|
||||
let workspace = workspace.clone();
|
||||
move |_, cx| cx.new(|cx| Self::new(workspace.clone(), cx))
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
log_dropped(workspace.update(cx, |root, cx| {
|
||||
root.panels().clone().update(cx, |panels, cx| {
|
||||
panels.open(
|
||||
PanelSlot::Main,
|
||||
Self::PANEL_ID,
|
||||
{
|
||||
let workspace = workspace.clone();
|
||||
move |_, cx| cx.new(|cx| Self::new(workspace.clone(), cx))
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
}));
|
||||
}
|
||||
|
||||
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(
|
||||
Segmented::new("explore-filter", filter)
|
||||
.options(vec![
|
||||
SegmentedOption::new(RepoFilter::All, "All")
|
||||
SegmentedOption::new(RepoFilter::All)
|
||||
.label("All")
|
||||
.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)),
|
||||
])
|
||||
.on_change(move |filter, _, cx| {
|
||||
|
||||
@@ -10,20 +10,19 @@ use nostr::prelude::PublicKey;
|
||||
use signed_core::GitEvent;
|
||||
use signed_state::RepoStore;
|
||||
use ui::button::Button;
|
||||
use ui::common::v_flex;
|
||||
use ui::common::{Sizable, h_flex, v_flex};
|
||||
use ui::icons::{Icon, IconRole};
|
||||
use ui::layout::panel::Panel;
|
||||
use ui::layout::root::RootContext as _;
|
||||
use ui::layout::panel::{Panel, PanelSlot};
|
||||
use ui::segmented::{Segmented, SegmentedOption};
|
||||
use ui::theme::ActiveTheme as _;
|
||||
use utils::relative_time;
|
||||
|
||||
use self::detail::IssueDetailView;
|
||||
use crate::app::AppRoot;
|
||||
use crate::issues::new_issue::NewIssueDialog;
|
||||
use crate::issues::new_issue::NewIssueView;
|
||||
use crate::repo::helpers::short_id;
|
||||
use crate::shared::event_list::{EventHandler, EventList, EventRow, filter_toolbar};
|
||||
use crate::shared::{log_dropped, panels};
|
||||
use crate::shared::event_list::{EventHandler, EventList, EventRow};
|
||||
use crate::shared::log_dropped;
|
||||
|
||||
pub mod detail;
|
||||
pub(crate) mod helpers;
|
||||
@@ -73,9 +72,36 @@ impl IssuesView {
|
||||
}
|
||||
}
|
||||
|
||||
fn open_new_issue(&mut self, cx: &mut Context<Self>) {
|
||||
let dialog = NewIssueDialog::new(self.store.clone(), cx);
|
||||
cx.open_dialog(dialog);
|
||||
fn open_new_issue(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
let Some(addr) = self.store.read(cx).addr().cloned() else {
|
||||
return;
|
||||
};
|
||||
|
||||
let id = SharedString::from(format!("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.
|
||||
@@ -127,23 +153,30 @@ impl IssuesView {
|
||||
|
||||
fn render_header(&self, cx: &mut Context<Self>) -> AnyElement {
|
||||
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();
|
||||
|
||||
filter_toolbar(
|
||||
cx,
|
||||
[
|
||||
h_flex()
|
||||
.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)
|
||||
.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)),
|
||||
SegmentedOption::new(IssueFilter::Open, format!("Open ({})", counts.open))
|
||||
SegmentedOption::new(IssueFilter::Open)
|
||||
.label(format!("Open ({})", counts.open))
|
||||
.icon(Icon::named(IconRole::GitIssueOngoing).color(muted)),
|
||||
SegmentedOption::new(
|
||||
IssueFilter::Closed,
|
||||
format!("Closed ({})", counts.closed),
|
||||
)
|
||||
.icon(Icon::named(IconRole::GitIssueClosed).color(muted)),
|
||||
SegmentedOption::new(IssueFilter::Closed)
|
||||
.label(format!("Closed ({})", counts.closed))
|
||||
.icon(Icon::named(IconRole::GitIssueClosed).color(muted)),
|
||||
])
|
||||
.on_change(move |filter, _, cx| {
|
||||
if let Err(error) = weak.update(cx, |this, cx| {
|
||||
@@ -152,18 +185,19 @@ impl IssuesView {
|
||||
}) {
|
||||
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")
|
||||
.label("New issue")
|
||||
.icon(Icon::named(IconRole::CirclePlus))
|
||||
.on_click(cx.listener(|this, _, _, cx| {
|
||||
this.open_new_issue(cx);
|
||||
}))
|
||||
.into_any_element(),
|
||||
],
|
||||
)
|
||||
.small()
|
||||
.on_click(cx.listener(|this, _, window, cx| {
|
||||
this.open_new_issue(window, cx);
|
||||
})),
|
||||
)
|
||||
.into_any_element()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,15 +231,21 @@ impl Render for IssuesView {
|
||||
Rc::new(move |_, window, cx| {
|
||||
let id = SharedString::from(format!("issue:{issue_id}"));
|
||||
let store = store.clone();
|
||||
panels::open_detail(
|
||||
&workspace,
|
||||
id,
|
||||
move |_, cx| {
|
||||
cx.new(|cx| IssueDetailView::new(store.clone(), issue_id, cx))
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
log_dropped(workspace.update(cx, |root, cx| {
|
||||
root.panels().clone().update(cx, |panels, cx| {
|
||||
panels.open(
|
||||
PanelSlot::Split,
|
||||
id,
|
||||
move |_, cx| {
|
||||
cx.new(|cx| {
|
||||
IssueDetailView::new(store.clone(), issue_id, cx)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
}));
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
@@ -1,70 +1,132 @@
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render,
|
||||
Styled as _, Window, div,
|
||||
AnyElement, App, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _,
|
||||
Render, SharedString, Styled as _, Task, WeakEntity, Window, div,
|
||||
};
|
||||
use signed_state::RepoStore;
|
||||
use ui::common::v_flex;
|
||||
use ui::dialog::{Dialog, DialogHandle};
|
||||
use ui::button::Button;
|
||||
use ui::common::{h_flex, v_flex};
|
||||
use ui::field::Field;
|
||||
use ui::input::{Input, InputState};
|
||||
use ui::layout::panel::{Panel, PanelSlot};
|
||||
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 {
|
||||
handle: DialogHandle,
|
||||
pub struct NewIssueView {
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
panel_id: SharedString,
|
||||
store: Entity<RepoStore>,
|
||||
subject: 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 {
|
||||
pub fn new(store: Entity<RepoStore>, cx: &mut App) -> Entity<Self> {
|
||||
impl NewIssueView {
|
||||
pub fn new(
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
panel_id: SharedString,
|
||||
store: Entity<RepoStore>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
let subject = InputState::new(cx);
|
||||
let content = InputState::builder().multiline().build(cx);
|
||||
let state = cx.new(|_| DialogProgress::default());
|
||||
|
||||
cx.new(|_| Self {
|
||||
handle: DialogHandle::new(true),
|
||||
Self {
|
||||
workspace,
|
||||
panel_id,
|
||||
store,
|
||||
subject,
|
||||
content,
|
||||
state,
|
||||
})
|
||||
submitting: false,
|
||||
error: None,
|
||||
submit_task: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn submit(&mut self, cx: &mut Context<Self>) {
|
||||
// The publish runs detached in the store; one submission per dialog.
|
||||
if self.state.read(cx).busy {
|
||||
if self.submitting {
|
||||
return;
|
||||
}
|
||||
|
||||
let subject = self.subject.read(cx).value().to_string();
|
||||
let content = self.content.read(cx).value().to_string();
|
||||
let subject = (!subject.trim().is_empty()).then_some(subject);
|
||||
|
||||
self.state.update(cx, |state, _| state.begin());
|
||||
self.store.update(cx, |store, cx| {
|
||||
store.open_issue(subject, content, cx);
|
||||
});
|
||||
self.submitting = true;
|
||||
self.error = None;
|
||||
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 {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let subject = self.subject.clone();
|
||||
let content = self.content.clone();
|
||||
let this = cx.entity().downgrade();
|
||||
let action_state = self.state.clone();
|
||||
impl Panel for NewIssueView {
|
||||
fn title(&self, _cx: &App) -> SharedString {
|
||||
SharedString::from("New issue")
|
||||
}
|
||||
|
||||
Dialog::new("new-issue-dialog")
|
||||
.handle(self.handle.clone())
|
||||
.min_width(gpui::px(520.))
|
||||
.title("New issue")
|
||||
.content(move |_, cx| {
|
||||
fn loading(&self, _cx: &App) -> bool {
|
||||
self.submitting
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
.p_4()
|
||||
.flex_1()
|
||||
.gap_3()
|
||||
.child(
|
||||
div()
|
||||
@@ -74,31 +136,14 @@ impl Render for NewIssueDialog {
|
||||
)
|
||||
.child(
|
||||
Field::new("issue-title", "Title")
|
||||
.child(Input::new("issue-title-input", subject.clone())),
|
||||
.child(Input::new("issue-title-input", self.subject.clone())),
|
||||
)
|
||||
.child(
|
||||
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()
|
||||
})
|
||||
.actions(move |_, 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,
|
||||
]
|
||||
})
|
||||
.when_some(error_row(&self.error, cx), |this, error| this.child(error)),
|
||||
)
|
||||
.child(self.render_footer(cx))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ use ui::common::{Sizable as _, StyledExt as _, h_flex, v_flex};
|
||||
use ui::empty_state::EmptyState;
|
||||
use ui::icons::{Icon, IconRole};
|
||||
use ui::input::InputState;
|
||||
use ui::layout::panel::Panel;
|
||||
use ui::layout::panel::{Panel, PanelSlot};
|
||||
use ui::layout::root::RootContext as _;
|
||||
use ui::scroll_area::ScrollArea;
|
||||
use ui::spinner::Spinner;
|
||||
@@ -33,7 +33,6 @@ use crate::pull_requests::dialogs::update::UpdatePrDialog;
|
||||
use crate::repo::commit_diff::{CommitDiffView, DiffPane};
|
||||
use crate::shared::event_list::commit_list;
|
||||
use crate::shared::log_dropped;
|
||||
use crate::shared::panels::open_detail;
|
||||
use crate::shared::widgets::status_badge;
|
||||
|
||||
const NOT_FOUND: &str = "Pull request not found";
|
||||
@@ -315,19 +314,31 @@ impl PullRequestDetailView {
|
||||
Some(addr) => SharedString::from(format!("commit:{addr}:{commit_id}")),
|
||||
None => SharedString::from(format!("commit:{}:{commit_id}", worktree.display())),
|
||||
};
|
||||
|
||||
let workspace = self.workspace.clone();
|
||||
let commit_id = commit_id.to_owned();
|
||||
open_detail(
|
||||
&workspace,
|
||||
id,
|
||||
move |window, cx| {
|
||||
cx.new(|cx| {
|
||||
CommitDiffView::new(worktree.clone(), commit_id.clone(), false, window, cx)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
|
||||
log_dropped(workspace.update(cx, |root, cx| {
|
||||
root.panels().clone().update(cx, |panels, cx| {
|
||||
panels.open(
|
||||
PanelSlot::Split,
|
||||
id,
|
||||
move |window, cx| {
|
||||
cx.new(|cx| {
|
||||
CommitDiffView::new(
|
||||
worktree.clone(),
|
||||
commit_id.clone(),
|
||||
false,
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
}));
|
||||
}
|
||||
|
||||
fn render_tabs(&self, cx: &mut Context<Self>) -> AnyElement {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render,
|
||||
@@ -7,12 +9,11 @@ use metadata::ProfileDirectory;
|
||||
use nostr::prelude::{Kind, PublicKey};
|
||||
use signed_core::GitEvent;
|
||||
use signed_state::RepoStore;
|
||||
use std::rc::Rc;
|
||||
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::icons::{Icon, IconRole};
|
||||
use ui::layout::panel::Panel;
|
||||
use ui::layout::panel::{Panel, PanelSlot};
|
||||
use ui::menu::MenuItem;
|
||||
use ui::segmented::{Segmented, SegmentedOption};
|
||||
use ui::theme::ActiveTheme as _;
|
||||
@@ -32,9 +33,8 @@ pub use send_patch::SendPatchView;
|
||||
use crate::app::AppRoot;
|
||||
use crate::issues::helpers::{StatusCounts, filter_by_status};
|
||||
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::panels::open_detail;
|
||||
|
||||
pub struct PullRequestsView {
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
@@ -141,23 +141,27 @@ impl PullRequestsView {
|
||||
let workspace_for_build = workspace.clone();
|
||||
let store = self.store.clone();
|
||||
|
||||
open_detail(
|
||||
&workspace,
|
||||
id.clone(),
|
||||
move |window, cx| {
|
||||
cx.new(|cx| {
|
||||
NewPullRequestView::new(
|
||||
workspace_for_build.clone(),
|
||||
id.clone(),
|
||||
store.clone(),
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
log_dropped(workspace.update(cx, |root, cx| {
|
||||
root.panels().clone().update(cx, |panels, cx| {
|
||||
panels.open(
|
||||
PanelSlot::Split,
|
||||
id.clone(),
|
||||
move |window, cx| {
|
||||
cx.new(|cx| {
|
||||
NewPullRequestView::new(
|
||||
workspace_for_build.clone(),
|
||||
id.clone(),
|
||||
store.clone(),
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
}));
|
||||
}
|
||||
|
||||
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 store = self.store.clone();
|
||||
|
||||
open_detail(
|
||||
&workspace,
|
||||
id.clone(),
|
||||
move |window, cx| {
|
||||
cx.new(|cx| {
|
||||
SendPatchView::new(
|
||||
workspace_for_build.clone(),
|
||||
id.clone(),
|
||||
store.clone(),
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
log_dropped(workspace.update(cx, |root, cx| {
|
||||
root.panels().clone().update(cx, |panels, cx| {
|
||||
panels.open(
|
||||
PanelSlot::Split,
|
||||
id.clone(),
|
||||
move |window, cx| {
|
||||
cx.new(|cx| {
|
||||
SendPatchView::new(
|
||||
workspace_for_build.clone(),
|
||||
id.clone(),
|
||||
store.clone(),
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
}));
|
||||
}
|
||||
|
||||
fn render_header(&self, cx: &mut Context<Self>) -> AnyElement {
|
||||
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 open_weak = cx.entity().downgrade();
|
||||
let menu_open_weak = cx.entity().downgrade();
|
||||
let patch_weak = cx.entity().downgrade();
|
||||
|
||||
filter_toolbar(
|
||||
cx,
|
||||
[
|
||||
h_flex()
|
||||
.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)
|
||||
.options(vec![
|
||||
SegmentedOption::new(
|
||||
PullRequestFilter::All,
|
||||
format!("All ({})", counts.total),
|
||||
)
|
||||
.icon(Icon::named(IconRole::GitPullRequest).color(muted)),
|
||||
SegmentedOption::new(
|
||||
PullRequestFilter::Open,
|
||||
format!("Open ({})", counts.open),
|
||||
)
|
||||
.icon(Icon::named(IconRole::GitPullRequest).color(muted)),
|
||||
SegmentedOption::new(
|
||||
PullRequestFilter::Closed,
|
||||
format!("Closed ({})", counts.closed),
|
||||
)
|
||||
.icon(Icon::named(IconRole::GitPullRequestClosed).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)),
|
||||
SegmentedOption::new(PullRequestFilter::All)
|
||||
.label(format!("All ({})", counts.total))
|
||||
.icon(Icon::named(IconRole::GitPullRequest).color(muted)),
|
||||
SegmentedOption::new(PullRequestFilter::Open)
|
||||
.label(format!("Open ({})", counts.open))
|
||||
.icon(Icon::named(IconRole::GitPullRequest).color(muted)),
|
||||
SegmentedOption::new(PullRequestFilter::Closed)
|
||||
.label(format!("Closed ({})", counts.closed))
|
||||
.icon(Icon::named(IconRole::GitPullRequestClosed).color(muted)),
|
||||
SegmentedOption::new(PullRequestFilter::Draft)
|
||||
.label(format!("Draft ({})", counts.draft))
|
||||
.icon(Icon::named(IconRole::GitPullRequestDraft).color(muted)),
|
||||
SegmentedOption::new(PullRequestFilter::Merged)
|
||||
.label(format!("Merged ({})", counts.applied))
|
||||
.icon(Icon::named(IconRole::GitPullRequestMerged).color(muted)),
|
||||
])
|
||||
.on_change(move |filter, _, cx| {
|
||||
if let Err(error) = weak.update(cx, |this, cx| {
|
||||
@@ -235,12 +240,14 @@ impl PullRequestsView {
|
||||
}) {
|
||||
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")
|
||||
.label("New")
|
||||
.icon(Icon::named(IconRole::GitPullRequest))
|
||||
.small()
|
||||
.open(self.new_pr_menu_open)
|
||||
.on_click(move |_, window, cx| {
|
||||
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 workspace_for_build = workspace.clone();
|
||||
let store = store.clone();
|
||||
open_detail(
|
||||
&workspace,
|
||||
id,
|
||||
move |window, cx| {
|
||||
cx.new(|cx| {
|
||||
PullRequestDetailView::new(
|
||||
workspace_for_build.clone(),
|
||||
store.clone(),
|
||||
pr_id,
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
log_dropped(workspace.update(cx, |root, cx| {
|
||||
root.panels().clone().update(cx, |panels, cx| {
|
||||
panels.open(
|
||||
PanelSlot::Split,
|
||||
id,
|
||||
move |window, cx| {
|
||||
cx.new(|cx| {
|
||||
PullRequestDetailView::new(
|
||||
workspace_for_build.clone(),
|
||||
store.clone(),
|
||||
pr_id,
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
}));
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ use ui::common::{StyledExt as _, h_flex, v_flex};
|
||||
use ui::empty_state::EmptyState;
|
||||
use ui::icons::{Icon, IconRole};
|
||||
use ui::input::{Input, InputState};
|
||||
use ui::layout::panel::Panel;
|
||||
use ui::layout::panel::{Panel, PanelSlot};
|
||||
use ui::menu::Menu;
|
||||
use ui::spinner::Spinner;
|
||||
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::shared::event_list::commit_list;
|
||||
use crate::shared::log_dropped;
|
||||
use crate::shared::panels::{close_detail, open_detail};
|
||||
use crate::shared::progress::error_row;
|
||||
|
||||
pub struct NewPullRequestView {
|
||||
@@ -245,7 +244,11 @@ impl NewPullRequestView {
|
||||
this.update(cx, |this, _cx| {
|
||||
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(())
|
||||
});
|
||||
self.push_task(task);
|
||||
@@ -261,17 +264,27 @@ impl NewPullRequestView {
|
||||
};
|
||||
let workspace = self.workspace.clone();
|
||||
let commit_id = commit_id.to_owned();
|
||||
open_detail(
|
||||
&workspace,
|
||||
id,
|
||||
move |window, cx| {
|
||||
cx.new(|cx| {
|
||||
CommitDiffView::new(repo_path.clone(), commit_id.clone(), false, window, cx)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
log_dropped(workspace.update(cx, |root, cx| {
|
||||
root.panels().clone().update(cx, |panels, cx| {
|
||||
panels.open(
|
||||
PanelSlot::Split,
|
||||
id,
|
||||
move |window, cx| {
|
||||
cx.new(|cx| {
|
||||
CommitDiffView::new(
|
||||
repo_path.clone(),
|
||||
commit_id.clone(),
|
||||
false,
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
}));
|
||||
}
|
||||
|
||||
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::icons::{Icon, IconRole};
|
||||
use ui::input::{Input, InputState};
|
||||
use ui::layout::panel::Panel;
|
||||
use ui::layout::panel::{Panel, PanelSlot};
|
||||
use ui::theme::ActiveTheme as _;
|
||||
|
||||
use crate::app::AppRoot;
|
||||
use crate::shared::log_dropped;
|
||||
use crate::shared::panels::close_detail;
|
||||
use crate::shared::progress::error_row;
|
||||
|
||||
pub struct SendPatchView {
|
||||
@@ -80,13 +79,16 @@ impl SendPatchView {
|
||||
cx,
|
||||
)
|
||||
});
|
||||
let workspace = self.workspace.clone();
|
||||
let panel_id = self.panel_id.clone();
|
||||
|
||||
cx.spawn(async move |this, cx| match task.await {
|
||||
Ok(()) => {
|
||||
this.update(cx, |this, cx| {
|
||||
close_detail(&this.workspace, &this.panel_id, cx)
|
||||
})
|
||||
.log_err();
|
||||
log_dropped(workspace.update(cx, |root, cx| {
|
||||
root.panels().clone().update(cx, |panels, cx| {
|
||||
panels.close(PanelSlot::Split, &panel_id, cx)
|
||||
})
|
||||
}));
|
||||
}
|
||||
Err(error) => {
|
||||
this.update(cx, |this, cx| {
|
||||
|
||||
@@ -2,10 +2,11 @@ use gpui::{App, AppContext as _, SharedString, WeakEntity, Window};
|
||||
use nostr::prelude::EventId;
|
||||
use signed_core::{Announcement, RepoAddr};
|
||||
use signed_state::RepoStore;
|
||||
use ui::layout::panel::PanelSlot;
|
||||
|
||||
use crate::app::AppRoot;
|
||||
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.
|
||||
pub enum RepoItem {
|
||||
@@ -27,17 +28,23 @@ pub fn open_repo_panel(
|
||||
let hint = hint.cloned();
|
||||
let workspace_for_build = workspace.clone();
|
||||
|
||||
panels::open_primary(
|
||||
workspace,
|
||||
id,
|
||||
move |window, cx| {
|
||||
let addr = addr.clone();
|
||||
let hint = hint.clone();
|
||||
cx.new(|cx| RepoDetailView::new(workspace_for_build.clone(), addr, hint, window, cx))
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
log_dropped(workspace.update(cx, |root, cx| {
|
||||
root.panels().clone().update(cx, |panels, cx| {
|
||||
panels.open(
|
||||
PanelSlot::Main,
|
||||
id,
|
||||
move |window, cx| {
|
||||
let addr = addr.clone();
|
||||
let hint = hint.clone();
|
||||
cx.new(|cx| {
|
||||
RepoDetailView::new(workspace_for_build.clone(), addr, hint, window, cx)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
}));
|
||||
}
|
||||
|
||||
/// Opens an issue or pull request using a store built here.
|
||||
@@ -54,39 +61,51 @@ pub fn open_repo_item(
|
||||
RepoItem::Issue(issue_id) => {
|
||||
let id = SharedString::from(format!("issue:{issue_id}"));
|
||||
let store = store.clone();
|
||||
panels::open_detail(
|
||||
workspace,
|
||||
id,
|
||||
move |_, cx| {
|
||||
cx.new(|cx| {
|
||||
crate::issues::detail::IssueDetailView::new(store.clone(), issue_id, cx)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
log_dropped(workspace.update(cx, |root, cx| {
|
||||
root.panels().clone().update(cx, |panels, cx| {
|
||||
panels.open(
|
||||
PanelSlot::Split,
|
||||
id,
|
||||
move |_, cx| {
|
||||
cx.new(|cx| {
|
||||
crate::issues::detail::IssueDetailView::new(
|
||||
store.clone(),
|
||||
issue_id,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
}));
|
||||
}
|
||||
RepoItem::PullRequest(pr_id) => {
|
||||
let id = SharedString::from(format!("pr:{pr_id}"));
|
||||
let workspace_for_build = workspace.clone();
|
||||
let store = store.clone();
|
||||
panels::open_detail(
|
||||
workspace,
|
||||
id,
|
||||
move |window, cx| {
|
||||
cx.new(|cx| {
|
||||
crate::pull_requests::PullRequestDetailView::new(
|
||||
workspace_for_build.clone(),
|
||||
store.clone(),
|
||||
pr_id,
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
log_dropped(workspace.update(cx, |root, cx| {
|
||||
root.panels().clone().update(cx, |panels, cx| {
|
||||
panels.open(
|
||||
PanelSlot::Split,
|
||||
id,
|
||||
move |window, cx| {
|
||||
cx.new(|cx| {
|
||||
crate::pull_requests::PullRequestDetailView::new(
|
||||
workspace_for_build.clone(),
|
||||
store.clone(),
|
||||
pr_id,
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
}));
|
||||
}
|
||||
// Opening a patch series directly is not a feature.
|
||||
_ => {}
|
||||
|
||||
@@ -260,7 +260,6 @@ impl RepoFilesView {
|
||||
let change_view = view.clone();
|
||||
let disclosure_view = view;
|
||||
|
||||
// Mirrors the sidebar's left inset, so rows stay aligned while the scrollbar hugs its border.
|
||||
Tree::new("repo-tree")
|
||||
.pr_2()
|
||||
.selected(selected)
|
||||
|
||||
@@ -14,6 +14,7 @@ use ui::button::{Button, ButtonVariant};
|
||||
use ui::common::{Sizable as _, v_flex};
|
||||
use ui::empty_state::EmptyState;
|
||||
use ui::icons::{Icon, IconRole};
|
||||
use ui::layout::panel::PanelSlot;
|
||||
use ui::spinner::Spinner;
|
||||
use ui::theme::ActiveTheme as _;
|
||||
use ui::tooltip::Tooltip;
|
||||
@@ -22,7 +23,7 @@ use super::RepoDetailView;
|
||||
use super::commit_diff::CommitDiffView;
|
||||
use crate::app::AppRoot;
|
||||
use crate::shared::event_list::commit_list;
|
||||
use crate::shared::panels;
|
||||
use crate::shared::log_dropped;
|
||||
|
||||
pub struct RepoHistoryView {
|
||||
store: Entity<RepoStore>,
|
||||
@@ -138,17 +139,27 @@ impl RepoHistoryView {
|
||||
};
|
||||
let workspace = self.workspace.clone();
|
||||
|
||||
panels::open_detail(
|
||||
&workspace,
|
||||
id,
|
||||
move |window, cx| {
|
||||
cx.new(|cx| {
|
||||
CommitDiffView::new(worktree.clone(), commit_id.clone(), true, window, cx)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
log_dropped(workspace.update(cx, |root, cx| {
|
||||
root.panels().clone().update(cx, |panels, cx| {
|
||||
panels.open(
|
||||
PanelSlot::Split,
|
||||
id,
|
||||
move |window, cx| {
|
||||
cx.new(|cx| {
|
||||
CommitDiffView::new(
|
||||
worktree.clone(),
|
||||
commit_id.clone(),
|
||||
true,
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1451,6 +1451,7 @@ impl RepoDetailView {
|
||||
})
|
||||
.child(
|
||||
h_flex()
|
||||
.px_2()
|
||||
.w_full()
|
||||
.gap_2()
|
||||
.child(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! The shared issue and pull-request lists: toolbar, uniform rows, scrollbar
|
||||
//! overlay, and empty state, plus the scrollable commit list.
|
||||
//! The shared issue and pull-request lists: uniform rows, scrollbar overlay, and
|
||||
//! empty state, plus the scrollable commit list.
|
||||
|
||||
use std::rc::Rc;
|
||||
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.
|
||||
pub fn commit_list(
|
||||
id: &'static str,
|
||||
|
||||
@@ -3,7 +3,6 @@ use metadata::ProfileDirectory;
|
||||
use nostr::prelude::PublicKey;
|
||||
|
||||
pub mod event_list;
|
||||
pub mod panels;
|
||||
pub mod progress;
|
||||
|
||||
pub mod widgets;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -15,6 +15,7 @@ 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::PanelSlot;
|
||||
use ui::layout::root::RootContext as _;
|
||||
use ui::menu::{Menu, MenuItem};
|
||||
use ui::tooltip::Tooltip;
|
||||
@@ -24,7 +25,7 @@ use crate::explore::ExploreView;
|
||||
use crate::identity::exit::ExitDialog;
|
||||
use crate::repo::{RepoDetailView, actions, dialogs};
|
||||
use crate::settings::SettingsDialog;
|
||||
use crate::shared::{log_dropped, panels};
|
||||
use crate::shared::log_dropped;
|
||||
|
||||
mod repository_switcher;
|
||||
|
||||
@@ -361,23 +362,28 @@ impl TitlebarView {
|
||||
let id = SharedString::from(format!("repo:{}", announcement.addr()));
|
||||
let workspace = self.app.clone();
|
||||
let workspace_for_build = workspace.clone();
|
||||
panels::open_primary(
|
||||
&workspace,
|
||||
id,
|
||||
move |window, cx| {
|
||||
cx.new(|cx| {
|
||||
RepoDetailView::new_local_announced(
|
||||
workspace_for_build.clone(),
|
||||
announcement.clone(),
|
||||
path.clone(),
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
|
||||
log_dropped(workspace.update(cx, |root, cx| {
|
||||
root.panels().clone().update(cx, |panels, cx| {
|
||||
panels.open(
|
||||
PanelSlot::Main,
|
||||
id,
|
||||
move |window, cx| {
|
||||
cx.new(|cx| {
|
||||
RepoDetailView::new_local_announced(
|
||||
workspace_for_build.clone(),
|
||||
announcement.clone(),
|
||||
path.clone(),
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -385,23 +391,27 @@ impl TitlebarView {
|
||||
let workspace = self.app.clone();
|
||||
let workspace_for_build = workspace.clone();
|
||||
|
||||
panels::open_primary(
|
||||
&workspace,
|
||||
id,
|
||||
move |window, cx| {
|
||||
cx.new(|cx| {
|
||||
RepoDetailView::new_local(
|
||||
workspace_for_build.clone(),
|
||||
path.clone(),
|
||||
nip34.clone(),
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
log_dropped(workspace.update(cx, |root, cx| {
|
||||
root.panels().clone().update(cx, |panels, cx| {
|
||||
panels.open(
|
||||
PanelSlot::Main,
|
||||
id,
|
||||
move |window, cx| {
|
||||
cx.new(|cx| {
|
||||
RepoDetailView::new_local(
|
||||
workspace_for_build.clone(),
|
||||
path.clone(),
|
||||
nip34.clone(),
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
}));
|
||||
}
|
||||
|
||||
pub fn render_user_menu(&self, cx: &App) -> Option<AnyElement> {
|
||||
|
||||
@@ -605,10 +605,14 @@ impl RepoStore {
|
||||
.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 {
|
||||
self.not_announced(cx);
|
||||
return;
|
||||
return self.action_error("This repository is not published to Nostr yet", cx);
|
||||
};
|
||||
|
||||
let builder = GitIssue {
|
||||
@@ -619,7 +623,7 @@ impl RepoStore {
|
||||
}
|
||||
.into_event_builder();
|
||||
|
||||
self.publish(builder, cx);
|
||||
self.publish(builder, cx)
|
||||
}
|
||||
|
||||
pub fn comments_of(&self, root: &EventId) -> impl Iterator<Item = &Event> {
|
||||
@@ -650,10 +654,11 @@ impl RepoStore {
|
||||
.and_then(|a| a.relays.first())
|
||||
.cloned();
|
||||
|
||||
self.publish(
|
||||
let task = self.publish(
|
||||
comment_builder(root, parent, relay_hint.as_ref(), &addr, content),
|
||||
cx,
|
||||
);
|
||||
self.tasks.push(task);
|
||||
}
|
||||
|
||||
#[expect(clippy::too_many_arguments, reason = "mirrors the PR event")]
|
||||
@@ -1167,7 +1172,8 @@ impl RepoStore {
|
||||
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> {
|
||||
@@ -1403,8 +1409,12 @@ impl RepoStore {
|
||||
Task::ready(Err(anyhow::anyhow!("{message}")))
|
||||
}
|
||||
|
||||
/// Publish an event to the repository's relays, and update the store with any error.
|
||||
fn publish(&mut self, builder: EventBuilder, cx: &mut Context<Self>) {
|
||||
/// 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>,
|
||||
) -> Task<Result<(), Error>> {
|
||||
self.last_error = None;
|
||||
|
||||
let backend = Backend::global(cx);
|
||||
@@ -1432,17 +1442,17 @@ impl RepoStore {
|
||||
}
|
||||
.await;
|
||||
|
||||
if let Err(e) = publish_result {
|
||||
if let Err(e) = &publish_result {
|
||||
this.update(cx, |this, cx| {
|
||||
this.last_error = Some(e.to_string());
|
||||
cx.notify();
|
||||
})?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
publish_result.map(|_| ())
|
||||
});
|
||||
|
||||
self.tasks.push(task);
|
||||
task
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
//!
|
||||
//! let mode = Segmented::new("editor-mode", "text")
|
||||
//! .options([
|
||||
//! SegmentedOption::new("text", "Text"),
|
||||
//! SegmentedOption::new("preview", "Preview"),
|
||||
//! SegmentedOption::new("text").label("Text"),
|
||||
//! SegmentedOption::new("preview").label("Preview"),
|
||||
//! ])
|
||||
//! .on_change(|value, _window, _cx| println!("mode: {value}"));
|
||||
//! ```
|
||||
@@ -18,8 +18,9 @@ use std::rc::Rc;
|
||||
use gpui::prelude::FluentBuilder;
|
||||
use gpui::{
|
||||
AnimationExt as _, App, Bounds, ElementId, Entity, InteractiveElement as _, IntoElement,
|
||||
KeyDownEvent, ParentElement as _, Point, RenderOnce, Role, SharedString, SpringAnimation,
|
||||
StatefulInteractiveElement as _, StyleRefinement, Styled as _, Toggled, Window, canvas, div,
|
||||
KeyDownEvent, ParentElement as _, Pixels, Point, RenderOnce, Role, SharedString,
|
||||
SpringAnimation, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Toggled,
|
||||
Window, canvas, div,
|
||||
};
|
||||
|
||||
use crate::components::common::{
|
||||
@@ -36,21 +37,29 @@ type ChangeHandler<T> = Rc<dyn Fn(T, &mut Window, &mut App)>;
|
||||
#[must_use]
|
||||
pub struct SegmentedOption<T> {
|
||||
value: T,
|
||||
label: SharedString,
|
||||
label: Option<SharedString>,
|
||||
icon: Option<Icon>,
|
||||
a11y_label: Option<SharedString>,
|
||||
}
|
||||
|
||||
impl<T> SegmentedOption<T> {
|
||||
/// Creates a choice showing `label`; picking it reports `value`.
|
||||
pub fn new<L>(value: T, label: L) -> Self
|
||||
/// Creates a choice that reports `value` when picked.
|
||||
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
|
||||
L: Into<SharedString>,
|
||||
{
|
||||
Self {
|
||||
value,
|
||||
label: label.into(),
|
||||
icon: None,
|
||||
}
|
||||
self.label = Some(label.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets a leading icon for the segment.
|
||||
@@ -61,6 +70,15 @@ impl<T> SegmentedOption<T> {
|
||||
self.icon = Some(icon.into());
|
||||
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.
|
||||
@@ -69,11 +87,7 @@ where
|
||||
L: Into<SharedString>,
|
||||
{
|
||||
fn from((value, label): (T, L)) -> Self {
|
||||
Self {
|
||||
value,
|
||||
label: label.into(),
|
||||
icon: None,
|
||||
}
|
||||
Self::new(value).label(label)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,10 +209,10 @@ where
|
||||
.unwrap_or_else(|| SharedString::from(self.id.to_string()));
|
||||
|
||||
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());
|
||||
|
||||
let track_origin: Entity<Option<Point<gpui::Pixels>>> =
|
||||
let track_origin: Entity<Option<Point<Pixels>>> =
|
||||
window.use_keyed_state("segmented-track-origin", cx, |_, _| None);
|
||||
|
||||
let focus = focus_handle(&self.id, window, cx);
|
||||
@@ -226,6 +240,7 @@ where
|
||||
} else {
|
||||
muted_foreground
|
||||
};
|
||||
let a11y_label = segment.a11y_label.clone().or_else(|| segment.label.clone());
|
||||
|
||||
h_flex()
|
||||
.id(("segment", index))
|
||||
@@ -240,26 +255,24 @@ where
|
||||
.when(!is_selected, |segment| {
|
||||
segment.hover(|style| style.bg(surface))
|
||||
})
|
||||
.role(Role::RadioButton)
|
||||
.aria_label(segment.label.clone())
|
||||
.when_some(a11y_label, |segment, label| segment.aria_label(label))
|
||||
.aria_toggled(Toggled::from(is_selected))
|
||||
.when_some(segment.icon.clone(), |segment, icon| {
|
||||
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(
|
||||
canvas(
|
||||
{
|
||||
let geometry = geometry.clone();
|
||||
move |bounds, _, cx| {
|
||||
geometry.update(cx, |geometry, _| {
|
||||
if geometry.len() <= index {
|
||||
geometry.resize(index + 1, None);
|
||||
}
|
||||
geometry[index] = Some(bounds);
|
||||
});
|
||||
measure(&geometry, move |geometry, bounds| {
|
||||
if geometry.get(index) == Some(&Some(bounds)) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
if geometry.len() <= index {
|
||||
geometry.resize(index + 1, None);
|
||||
}
|
||||
geometry[index] = Some(bounds);
|
||||
true
|
||||
}),
|
||||
|_, _, _, _| {},
|
||||
)
|
||||
.absolute()
|
||||
@@ -298,13 +311,13 @@ where
|
||||
.control_text(self.size)
|
||||
.child(
|
||||
canvas(
|
||||
{
|
||||
let track_origin = track_origin.clone();
|
||||
move |bounds, _, cx| {
|
||||
track_origin
|
||||
.update(cx, |origin, _| *origin = Some(bounds.origin));
|
||||
measure(&track_origin, |origin, bounds| {
|
||||
if *origin == Some(bounds.origin) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
*origin = Some(bounds.origin);
|
||||
true
|
||||
}),
|
||||
|_, _, _, _| {},
|
||||
)
|
||||
.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user