refactor: move panel stack state into app root
This commit is contained in:
@@ -6,15 +6,15 @@ use std::sync::Arc;
|
||||
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AppContext as _, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _,
|
||||
Render, SharedString, Styled as _, Subscription, Window, div, px,
|
||||
App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
||||
ParentElement as _, Render, SharedString, Styled as _, Subscription, Window, div, px,
|
||||
};
|
||||
use helpers::apply_appearance_mode;
|
||||
use settings::SettingsStore;
|
||||
use signed_state::{Backend, BackendEvent};
|
||||
use ui::common::{h_flex, v_flex};
|
||||
use ui::icons::IconRole;
|
||||
use ui::layout::panel::{PanelRow, PanelStack, PanelView};
|
||||
use ui::layout::panel::{PanelRow, PanelView};
|
||||
use ui::layout::root::RootContext as _;
|
||||
use ui::layout::titlebar::Titlebar;
|
||||
use ui::tabs::{Tabs, TabsVariant};
|
||||
@@ -31,10 +31,14 @@ use crate::titlebar::{
|
||||
};
|
||||
|
||||
pub struct AppRoot {
|
||||
panel: Entity<PanelStack>,
|
||||
/// The id of the main panel currently shown.
|
||||
main: Option<SharedString>,
|
||||
/// The open main panels in tab order.
|
||||
mains: Vec<(SharedString, Arc<dyn PanelView>)>,
|
||||
titlebar: Entity<TitlebarView>,
|
||||
sign_in: Entity<SignedOutView>,
|
||||
explore: Entity<ExploreView>,
|
||||
empty: Entity<PlaceholderView>,
|
||||
passphrase: Option<Entity<PassphraseDialog>>,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
}
|
||||
@@ -44,11 +48,10 @@ impl AppRoot {
|
||||
bind_repository_shortcuts(cx);
|
||||
|
||||
let app = cx.entity().downgrade();
|
||||
let empty = cx.new(|_| PlaceholderView::new("Select a repository"));
|
||||
let panel = cx.new(|cx| PanelStack::new(empty.clone().into(), cx));
|
||||
let titlebar = cx.new(|cx| TitlebarView::new(app.clone(), window, cx));
|
||||
let sign_in = cx.new(|_| SignedOutView::new());
|
||||
let explore = cx.new(|cx| ExploreView::new(app.clone(), cx));
|
||||
let empty = cx.new(|_| PlaceholderView::new("Select a repository"));
|
||||
|
||||
let backend = Backend::global(cx);
|
||||
let settings = SettingsStore::global(cx);
|
||||
@@ -67,12 +70,11 @@ impl AppRoot {
|
||||
BackendEvent::SignerChanged => {
|
||||
let app = cx.entity().downgrade();
|
||||
let backend = backend.clone();
|
||||
|
||||
// Fires while AppRoot may still be under construction;
|
||||
// opening panels reads the root, so run outside its lease.
|
||||
window.defer(cx, move |window, cx| {
|
||||
let signed_in = backend.read(cx).current_user().is_some();
|
||||
log_dropped(app.update(cx, |this, cx| {
|
||||
this.clear(cx);
|
||||
}));
|
||||
log_dropped(app.update(cx, |this, cx| this.clear(cx)));
|
||||
if signed_in {
|
||||
ExploreView::open(&app, window, cx);
|
||||
}
|
||||
@@ -94,10 +96,12 @@ impl AppRoot {
|
||||
});
|
||||
|
||||
Self {
|
||||
panel,
|
||||
main: None,
|
||||
mains: Vec::new(),
|
||||
titlebar,
|
||||
sign_in,
|
||||
explore,
|
||||
empty,
|
||||
passphrase: None,
|
||||
_subscriptions: subscriptions,
|
||||
}
|
||||
@@ -112,79 +116,127 @@ impl AppRoot {
|
||||
cx.open_dialog(dialog);
|
||||
}
|
||||
|
||||
/// The panel stack holding the main tile and the detail tiles.
|
||||
pub fn panel(&self) -> Entity<PanelStack> {
|
||||
self.panel.clone()
|
||||
pub fn active_main(&self) -> Option<Arc<dyn PanelView>> {
|
||||
let id = self.main.as_ref()?;
|
||||
self.mains
|
||||
.iter()
|
||||
.find(|(open, _)| open == id)
|
||||
.map(|(_, view)| view.clone())
|
||||
}
|
||||
|
||||
pub fn open_main(
|
||||
pub fn has_main(&self, id: &SharedString) -> bool {
|
||||
self.mains.iter().any(|(open, _)| open == id)
|
||||
}
|
||||
|
||||
/// Whether the active main panel owns an open sub panel with this id.
|
||||
pub(crate) fn has_detail(&self, id: &SharedString, cx: &App) -> bool {
|
||||
self.active_main()
|
||||
.is_some_and(|main| main.sub_panels(cx).iter().any(|(open, _)| open == id))
|
||||
}
|
||||
|
||||
pub fn show_main(
|
||||
&mut self,
|
||||
id: SharedString,
|
||||
view: Arc<dyn PanelView>,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
self.panel
|
||||
.update(cx, |panel, cx| panel.open_main(id, view, cx));
|
||||
match self.mains.iter_mut().find(|(open, _)| *open == id) {
|
||||
Some((_, open_view)) => *open_view = view,
|
||||
None => self.mains.push((id.clone(), view)),
|
||||
}
|
||||
self.main = Some(id);
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn activate_main(&mut self, id: &SharedString, cx: &mut Context<Self>) {
|
||||
self.main = Some(id.clone());
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// Opens the panel as a sub panel of the active main panel.
|
||||
pub fn open_detail(
|
||||
&mut self,
|
||||
id: SharedString,
|
||||
view: Arc<dyn PanelView>,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
self.panel
|
||||
.update(cx, |panel, cx| panel.open_split(id, view, cx));
|
||||
let Some(active) = self.active_main() else {
|
||||
log::warn!("no main panel open for detail {id}");
|
||||
return;
|
||||
};
|
||||
let panel_id = id.clone();
|
||||
if !active.open_sub(id, view, cx) {
|
||||
log::warn!("active panel ignored sub panel {panel_id}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Closes the active main panel's sub panel with `id`.
|
||||
pub fn close_detail(&mut self, id: &SharedString, cx: &mut Context<Self>) {
|
||||
self.panel.update(cx, |panel, cx| panel.close_split(id, cx));
|
||||
}
|
||||
|
||||
pub fn activate_main(&mut self, id: &SharedString, cx: &mut Context<Self>) {
|
||||
self.panel
|
||||
.update(cx, |panel, cx| panel.activate_main(id, cx));
|
||||
if let Some(active) = self.active_main() {
|
||||
active.close_sub(id, cx);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn close_main_at(&mut self, index: usize, cx: &mut Context<Self>) {
|
||||
self.panel
|
||||
.update(cx, |panel, cx| panel.close_main_at(index, cx));
|
||||
let Some((id, _)) = self.mains.get(index) else {
|
||||
return;
|
||||
};
|
||||
let id = id.clone();
|
||||
self.mains.remove(index);
|
||||
|
||||
if self.main.as_ref() == Some(&id) {
|
||||
self.main = self
|
||||
.mains
|
||||
.get(index)
|
||||
.or_else(|| index.checked_sub(1).and_then(|prev| self.mains.get(prev)))
|
||||
.map(|(id, _)| id.clone());
|
||||
}
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn clear(&mut self, cx: &mut Context<Self>) {
|
||||
self.panel.update(cx, |panel, cx| panel.clear(cx));
|
||||
self.main = None;
|
||||
self.mains.clear();
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// Tabs for the repositories opened in the main panel.
|
||||
fn render_repo_tabs(&self, cx: &mut Context<Self>) -> Option<Tabs> {
|
||||
let panel = self.panel.read(cx);
|
||||
|
||||
if panel.mains().is_empty() {
|
||||
if self.mains.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let selected = panel.active_main_index();
|
||||
let ids: Vec<SharedString> = panel
|
||||
.mains()
|
||||
let tabs: Vec<_> = self
|
||||
.mains
|
||||
.iter()
|
||||
.map(|panel| panel.id().clone())
|
||||
.map(|(id, view)| (id.clone(), view.clone()))
|
||||
.collect();
|
||||
let panel = self.panel.clone();
|
||||
|
||||
let selected = self
|
||||
.main
|
||||
.as_ref()
|
||||
.and_then(|id| self.mains.iter().position(|(open, _)| open == id))
|
||||
.unwrap_or(usize::MAX);
|
||||
|
||||
let app = cx.entity().downgrade();
|
||||
let close_app = app.clone();
|
||||
let open: Vec<SharedString> = self.mains.iter().map(|(id, _)| id.clone()).collect();
|
||||
|
||||
Some(
|
||||
Tabs::new("signed-repo-tabs")
|
||||
.variant(TabsVariant::Titlebar)
|
||||
.overflow_scroll(true)
|
||||
.selected(selected)
|
||||
.tabs(move |_, cx| panel.read(cx).main_tabs(cx))
|
||||
.tabs(move |_, cx| {
|
||||
tabs.iter()
|
||||
.map(|(id, view)| view.tab(id.clone().into(), cx).closeable(true))
|
||||
.collect()
|
||||
})
|
||||
.on_change(move |index, _, cx| {
|
||||
let Some(id) = ids.get(index) else {
|
||||
let Some(id) = open.get(index).cloned() else {
|
||||
return;
|
||||
};
|
||||
let id = id.clone();
|
||||
log_dropped(app.update(cx, |app, cx| {
|
||||
app.activate_main(&id, cx);
|
||||
}));
|
||||
@@ -205,6 +257,8 @@ impl Render for AppRoot {
|
||||
|
||||
let repo_tabs = self.render_repo_tabs(cx);
|
||||
let titlebar_view = self.titlebar.read(cx);
|
||||
let main = self.active_main();
|
||||
let has_main = main.is_some();
|
||||
|
||||
div()
|
||||
.relative()
|
||||
@@ -242,14 +296,15 @@ impl Render for AppRoot {
|
||||
titlebar.suffix(menu)
|
||||
}),
|
||||
)
|
||||
.child(if signed_in {
|
||||
self.panel.clone().into_any_element()
|
||||
} else {
|
||||
PanelRow::new("signed-out-panel")
|
||||
.main(self.sign_in.clone())
|
||||
.split_at(self.explore.clone(), px(300.))
|
||||
.into_any_element()
|
||||
}),
|
||||
.child(
|
||||
PanelRow::new("signed-panel")
|
||||
.when_some(main, |row, main| row.main(main))
|
||||
.when(!has_main && signed_in, |row| row.main(self.empty.clone()))
|
||||
.when(!has_main && !signed_in, |row| {
|
||||
row.main(self.sign_in.clone())
|
||||
.split_at(self.explore.clone(), px(300.))
|
||||
}),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
mod helpers;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use gpui::{
|
||||
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ListAlignment, ListState,
|
||||
ParentElement as _, Render, SharedString, Styled as _, Subscription, WeakEntity, Window, div,
|
||||
@@ -13,7 +15,7 @@ use ui::common::{h_flex, v_flex};
|
||||
use ui::empty_state::EmptyState;
|
||||
use ui::icons::{Icon, IconRole};
|
||||
use ui::input::{Input, InputState, InputStateEvent};
|
||||
use ui::layout::panel::Panel;
|
||||
use ui::layout::panel::{Panel, PanelView, SubPanels};
|
||||
use ui::scrollbar::Scrollbar;
|
||||
use ui::segmented::{Segmented, SegmentedOption};
|
||||
use ui::theme::ActiveTheme as _;
|
||||
@@ -35,6 +37,8 @@ pub struct ExploreView {
|
||||
search: Entity<InputState>,
|
||||
/// Profiles for the card owners.
|
||||
directory: Entity<ProfileDirectory>,
|
||||
/// The detail panels this panel owns, shown beside its content.
|
||||
subs: SubPanels,
|
||||
_search_subscription: Subscription,
|
||||
_store_subscription: Subscription,
|
||||
}
|
||||
@@ -88,6 +92,7 @@ impl ExploreView {
|
||||
visible: Vec::new(),
|
||||
search,
|
||||
directory,
|
||||
subs: SubPanels::default(),
|
||||
_search_subscription: search_subscription,
|
||||
_store_subscription: store_subscription,
|
||||
}
|
||||
@@ -181,6 +186,33 @@ impl Panel for ExploreView {
|
||||
SharedString::from("Explore")
|
||||
}
|
||||
|
||||
fn sub_panels(&self, _cx: &App) -> &SubPanels {
|
||||
&self.subs
|
||||
}
|
||||
|
||||
fn open_sub_panel(
|
||||
&mut self,
|
||||
id: SharedString,
|
||||
view: Arc<dyn PanelView>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> bool {
|
||||
if self.subs.open(id, view) {
|
||||
cx.notify();
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn close_sub_panel(&mut self, id: &SharedString, cx: &mut Context<Self>) -> bool {
|
||||
if self.subs.close(id) {
|
||||
cx.notify();
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn prefix(&self, cx: &App) -> Option<AnyElement> {
|
||||
Some(
|
||||
Icon::named(IconRole::Grid)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use gpui::{
|
||||
App, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _, Render,
|
||||
ScrollHandle, SharedString, Styled as _, Subscription, Window, div,
|
||||
ScrollHandle, SharedString, Styled as _, Subscription, WeakEntity, Window, div,
|
||||
};
|
||||
use metadata::ProfileDirectory;
|
||||
use nostr::prelude::EventId;
|
||||
@@ -16,11 +16,16 @@ use ui::spinner::Spinner;
|
||||
use ui::theme::ActiveTheme as _;
|
||||
use utils::relative_time;
|
||||
|
||||
use crate::app::AppRoot;
|
||||
use crate::issues::helpers::{comment_form, comments_section, sidebar_section};
|
||||
use crate::shared::log_dropped;
|
||||
use crate::shared::panels;
|
||||
use crate::shared::widgets::status_badge;
|
||||
|
||||
pub struct IssueDetailView {
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
/// The sub panel id this view closes through.
|
||||
panel_id: SharedString,
|
||||
store: Entity<RepoStore>,
|
||||
issue_id: EventId,
|
||||
comment_input: Entity<InputState>,
|
||||
@@ -31,7 +36,13 @@ pub struct IssueDetailView {
|
||||
}
|
||||
|
||||
impl IssueDetailView {
|
||||
pub fn new(store: Entity<RepoStore>, issue_id: EventId, cx: &mut Context<Self>) -> Self {
|
||||
pub fn new(
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
panel_id: SharedString,
|
||||
store: Entity<RepoStore>,
|
||||
issue_id: EventId,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
let comment_input = InputState::builder().multiline().build(cx);
|
||||
|
||||
let subscription = cx.observe(&store, |this, _store, cx| {
|
||||
@@ -46,6 +57,8 @@ impl IssueDetailView {
|
||||
});
|
||||
|
||||
Self {
|
||||
workspace,
|
||||
panel_id,
|
||||
store,
|
||||
issue_id,
|
||||
comment_input,
|
||||
@@ -125,7 +138,15 @@ impl Render for IssueDetailView {
|
||||
|
||||
h_flex()
|
||||
.id("issue-detail")
|
||||
.relative()
|
||||
.size_full()
|
||||
.child(
|
||||
div()
|
||||
.absolute()
|
||||
.top_1()
|
||||
.right_1()
|
||||
.child(panels::close_button(&self.workspace, &self.panel_id)),
|
||||
)
|
||||
.child(
|
||||
ScrollArea::new("issue-detail-scroll")
|
||||
.handle(self.scroll_handle.clone())
|
||||
|
||||
@@ -196,12 +196,22 @@ impl Render for IssuesView {
|
||||
let store = store.clone();
|
||||
Rc::new(move |_, window, cx| {
|
||||
let id = SharedString::from(format!("issue:{issue_id}"));
|
||||
let panel_id = id.clone();
|
||||
let workspace_for_build = workspace.clone();
|
||||
let store = store.clone();
|
||||
panels::open_detail(
|
||||
&workspace,
|
||||
id,
|
||||
move |_, cx| {
|
||||
cx.new(|cx| IssueDetailView::new(store.clone(), issue_id, cx))
|
||||
cx.new(|cx| {
|
||||
IssueDetailView::new(
|
||||
workspace_for_build.clone(),
|
||||
panel_id.clone(),
|
||||
store.clone(),
|
||||
issue_id,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
|
||||
@@ -32,7 +32,7 @@ use crate::issues::helpers::{comment_form, comments_section, sidebar_section};
|
||||
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::panels::{self, open_detail};
|
||||
use crate::shared::widgets::status_badge;
|
||||
|
||||
const NOT_FOUND: &str = "Pull request not found";
|
||||
@@ -50,6 +50,8 @@ struct PrBinding {
|
||||
|
||||
pub struct PullRequestDetailView {
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
/// The sub panel id this view closes through.
|
||||
panel_id: SharedString,
|
||||
store: Entity<RepoStore>,
|
||||
pr_id: EventId,
|
||||
update_dialog: Option<Entity<dialogs::update::UpdatePrDialog>>,
|
||||
@@ -73,6 +75,7 @@ pub struct PullRequestDetailView {
|
||||
impl PullRequestDetailView {
|
||||
pub fn new(
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
panel_id: SharedString,
|
||||
store: Entity<RepoStore>,
|
||||
pr_id: EventId,
|
||||
_window: &mut Window,
|
||||
@@ -92,6 +95,7 @@ impl PullRequestDetailView {
|
||||
|
||||
Self {
|
||||
workspace,
|
||||
panel_id,
|
||||
store,
|
||||
pr_id,
|
||||
update_dialog: None,
|
||||
@@ -304,13 +308,23 @@ impl PullRequestDetailView {
|
||||
None => SharedString::from(format!("commit:{}:{commit_id}", worktree.display())),
|
||||
};
|
||||
let workspace = self.workspace.clone();
|
||||
let workspace_for_build = workspace.clone();
|
||||
let panel_id = id.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)
|
||||
CommitDiffView::new(
|
||||
workspace_for_build.clone(),
|
||||
panel_id.clone(),
|
||||
worktree.clone(),
|
||||
commit_id.clone(),
|
||||
false,
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
},
|
||||
window,
|
||||
@@ -589,8 +603,16 @@ impl Render for PullRequestDetailView {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
v_flex()
|
||||
.id("pull-request-detail")
|
||||
.relative()
|
||||
.size_full()
|
||||
.min_h_0()
|
||||
.child(
|
||||
div()
|
||||
.absolute()
|
||||
.top_1()
|
||||
.right_1()
|
||||
.child(panels::close_button(&self.workspace, &self.panel_id)),
|
||||
)
|
||||
.child(self.render_header(cx))
|
||||
.when_some(self.update_dialog.clone(), |el, view| el.child(view))
|
||||
.child(self.render_tabs(cx))
|
||||
|
||||
@@ -309,6 +309,7 @@ impl Render for PullRequestsView {
|
||||
let store = store.clone();
|
||||
Rc::new(move |_, window, cx| {
|
||||
let id = SharedString::from(format!("pr:{pr_id}"));
|
||||
let panel_id = id.clone();
|
||||
let workspace_for_build = workspace.clone();
|
||||
let store = store.clone();
|
||||
open_detail(
|
||||
@@ -318,6 +319,7 @@ impl Render for PullRequestsView {
|
||||
cx.new(|cx| {
|
||||
PullRequestDetailView::new(
|
||||
workspace_for_build.clone(),
|
||||
panel_id.clone(),
|
||||
store.clone(),
|
||||
pr_id,
|
||||
window,
|
||||
|
||||
@@ -28,7 +28,7 @@ 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::open_detail;
|
||||
use crate::shared::panels::{self, open_detail};
|
||||
use crate::shared::progress::error_row;
|
||||
|
||||
pub struct NewPullRequestView {
|
||||
@@ -232,13 +232,23 @@ impl NewPullRequestView {
|
||||
None => SharedString::from(format!("commit:{}:{commit_id}", repo_path.display())),
|
||||
};
|
||||
let workspace = self.workspace.clone();
|
||||
let workspace_for_build = workspace.clone();
|
||||
let panel_id = id.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)
|
||||
CommitDiffView::new(
|
||||
workspace_for_build.clone(),
|
||||
panel_id.clone(),
|
||||
repo_path.clone(),
|
||||
commit_id.clone(),
|
||||
false,
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
},
|
||||
window,
|
||||
@@ -806,7 +816,15 @@ impl Render for NewPullRequestView {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
v_flex()
|
||||
.id("new-pr")
|
||||
.relative()
|
||||
.size_full()
|
||||
.child(
|
||||
div()
|
||||
.absolute()
|
||||
.top_1()
|
||||
.right_1()
|
||||
.child(panels::close_button(&self.workspace, &self.panel_id)),
|
||||
)
|
||||
.child(
|
||||
v_flex()
|
||||
.gap_3()
|
||||
|
||||
@@ -13,6 +13,7 @@ use ui::theme::ActiveTheme as _;
|
||||
|
||||
use crate::app::AppRoot;
|
||||
use crate::shared::log_dropped;
|
||||
use crate::shared::panels;
|
||||
use crate::shared::progress::error_row;
|
||||
|
||||
pub struct SendPatchView {
|
||||
@@ -144,7 +145,15 @@ impl Render for SendPatchView {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
v_flex()
|
||||
.id("send-patch")
|
||||
.relative()
|
||||
.size_full()
|
||||
.child(
|
||||
div()
|
||||
.absolute()
|
||||
.top_1()
|
||||
.right_1()
|
||||
.child(panels::close_button(&self.workspace, &self.panel_id)),
|
||||
)
|
||||
.child(
|
||||
v_flex()
|
||||
.p_4()
|
||||
|
||||
@@ -53,13 +53,21 @@ pub fn open_repo_item(
|
||||
match item {
|
||||
RepoItem::Issue(issue_id) => {
|
||||
let id = SharedString::from(format!("issue:{issue_id}"));
|
||||
let panel_id = id.clone();
|
||||
let workspace_for_build = workspace.clone();
|
||||
let store = store.clone();
|
||||
panels::open_detail(
|
||||
workspace,
|
||||
id,
|
||||
move |_, cx| {
|
||||
cx.new(|cx| {
|
||||
crate::issues::detail::IssueDetailView::new(store.clone(), issue_id, cx)
|
||||
crate::issues::detail::IssueDetailView::new(
|
||||
workspace_for_build.clone(),
|
||||
panel_id.clone(),
|
||||
store.clone(),
|
||||
issue_id,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
},
|
||||
window,
|
||||
@@ -68,6 +76,7 @@ pub fn open_repo_item(
|
||||
}
|
||||
RepoItem::PullRequest(pr_id) => {
|
||||
let id = SharedString::from(format!("pr:{pr_id}"));
|
||||
let panel_id = id.clone();
|
||||
let workspace_for_build = workspace.clone();
|
||||
let store = store.clone();
|
||||
panels::open_detail(
|
||||
@@ -77,6 +86,7 @@ pub fn open_repo_item(
|
||||
cx.new(|cx| {
|
||||
crate::pull_requests::PullRequestDetailView::new(
|
||||
workspace_for_build.clone(),
|
||||
panel_id.clone(),
|
||||
store.clone(),
|
||||
pr_id,
|
||||
window,
|
||||
|
||||
@@ -29,6 +29,8 @@ use ui::tree::{Tree, TreeItem, TreeItemSeed};
|
||||
use utils::relative_time_secs;
|
||||
|
||||
use super::helpers::{DiffRow, co_authors, diff_rows, short_id};
|
||||
use crate::app::AppRoot;
|
||||
use crate::shared::panels;
|
||||
|
||||
/// Emitted when the user activates the Download commit button.
|
||||
pub enum DiffPaneEvent {
|
||||
@@ -607,6 +609,9 @@ impl Render for DiffPane {
|
||||
}
|
||||
|
||||
pub struct CommitDiffView {
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
/// The sub panel id this view closes through.
|
||||
panel_id: SharedString,
|
||||
worktree: PathBuf,
|
||||
commit: FileCommit,
|
||||
/// The diff is being computed on a background task.
|
||||
@@ -619,6 +624,8 @@ pub struct CommitDiffView {
|
||||
|
||||
impl CommitDiffView {
|
||||
pub fn new(
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
panel_id: SharedString,
|
||||
worktree: PathBuf,
|
||||
commit_id: String,
|
||||
downloadable: bool,
|
||||
@@ -642,6 +649,8 @@ impl CommitDiffView {
|
||||
});
|
||||
|
||||
Self {
|
||||
workspace,
|
||||
panel_id,
|
||||
worktree,
|
||||
commit: FileCommit {
|
||||
id: commit_id,
|
||||
@@ -895,8 +904,16 @@ impl Render for CommitDiffView {
|
||||
};
|
||||
|
||||
v_flex()
|
||||
.relative()
|
||||
.size_full()
|
||||
.min_h_0()
|
||||
.child(
|
||||
div()
|
||||
.absolute()
|
||||
.top_1()
|
||||
.right_1()
|
||||
.child(panels::close_button(&self.workspace, &self.panel_id)),
|
||||
)
|
||||
.child(self.render_header(cx))
|
||||
.child(div().flex_1().min_h_0().child(body))
|
||||
}
|
||||
|
||||
@@ -142,13 +142,23 @@ impl RepoHistoryView {
|
||||
None => SharedString::from(format!("commit:{}:{}", worktree.display(), commit_id)),
|
||||
};
|
||||
let workspace = self.workspace.clone();
|
||||
let workspace_for_build = workspace.clone();
|
||||
let panel_id = id.clone();
|
||||
|
||||
panels::open_detail(
|
||||
&workspace,
|
||||
id,
|
||||
move |window, cx| {
|
||||
cx.new(|cx| {
|
||||
CommitDiffView::new(worktree.clone(), commit_id.clone(), true, window, cx)
|
||||
CommitDiffView::new(
|
||||
workspace_for_build.clone(),
|
||||
panel_id.clone(),
|
||||
worktree.clone(),
|
||||
commit_id.clone(),
|
||||
true,
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
},
|
||||
window,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use std::collections::HashSet;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Error;
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
@@ -25,7 +26,7 @@ use ui::common::{Sizable as _, StyledExt as _, h_flex, v_flex};
|
||||
use ui::dialog::Dialog;
|
||||
use ui::dropdown_menu::DropdownMenu;
|
||||
use ui::icons::{Icon, IconRole};
|
||||
use ui::layout::panel::Panel;
|
||||
use ui::layout::panel::{Panel, PanelView, SubPanels};
|
||||
use ui::menu::MenuItem;
|
||||
use ui::popover::Popover;
|
||||
use ui::sidebar::{Sidebar, SidebarEntry};
|
||||
@@ -107,6 +108,8 @@ pub struct RepoDetailView {
|
||||
sync_error: Option<SharedString>,
|
||||
pub(super) repo_menu_open: bool,
|
||||
pub(super) clone_open: bool,
|
||||
/// The detail panels this repo panel owns, shown beside its content.
|
||||
subs: SubPanels,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
}
|
||||
|
||||
@@ -231,6 +234,7 @@ impl RepoDetailView {
|
||||
sync_error: None,
|
||||
repo_menu_open: false,
|
||||
clone_open: false,
|
||||
subs: SubPanels::default(),
|
||||
_subscriptions: subscriptions,
|
||||
}
|
||||
}
|
||||
@@ -1479,6 +1483,33 @@ impl Panel for RepoDetailView {
|
||||
SharedString::from("Repository")
|
||||
}
|
||||
|
||||
fn sub_panels(&self, _cx: &App) -> &SubPanels {
|
||||
&self.subs
|
||||
}
|
||||
|
||||
fn open_sub_panel(
|
||||
&mut self,
|
||||
id: SharedString,
|
||||
view: Arc<dyn PanelView>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> bool {
|
||||
if self.subs.open(id, view) {
|
||||
cx.notify();
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn close_sub_panel(&mut self, id: &SharedString, cx: &mut Context<Self>) -> bool {
|
||||
if self.subs.close(id) {
|
||||
cx.notify();
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn prefix(&self, cx: &App) -> Option<AnyElement> {
|
||||
let store = self.store.read(cx);
|
||||
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use gpui::{App, Entity, SharedString, WeakEntity, Window};
|
||||
use gpui::{App, ElementId, Entity, SharedString, WeakEntity, Window};
|
||||
use ui::button::{Button, ButtonVariant};
|
||||
use ui::common::Sizable as _;
|
||||
use ui::icons::Icon;
|
||||
use ui::layout::panel::{Panel, PanelView};
|
||||
|
||||
use crate::app::AppRoot;
|
||||
|
||||
/// Opens a repository in the main panel, reusing its tab when it is already open.
|
||||
/// Opens a panel in the main panel, reusing it when it is already open.
|
||||
pub fn open_primary<P, F>(
|
||||
workspace: &WeakEntity<AppRoot>,
|
||||
id: impl Into<SharedString>,
|
||||
@@ -17,8 +20,9 @@ pub fn open_primary<P, F>(
|
||||
F: Fn(&mut Window, &mut App) -> Entity<P> + 'static,
|
||||
{
|
||||
let id = id.into();
|
||||
|
||||
if workspace
|
||||
.read_with(cx, |app, cx| app.panel().read(cx).has(&id))
|
||||
.read_with(cx, |app, _| app.has_main(&id))
|
||||
.unwrap_or(false)
|
||||
{
|
||||
if let Err(error) = workspace.update(cx, |app, cx| app.activate_main(&id, cx)) {
|
||||
@@ -28,12 +32,13 @@ pub fn open_primary<P, F>(
|
||||
}
|
||||
|
||||
let view: Arc<dyn PanelView> = Arc::new(build(window, cx));
|
||||
if let Err(error) = workspace.update(cx, |app, cx| app.open_main(id.clone(), view, cx)) {
|
||||
if let Err(error) = workspace.update(cx, |app, cx| app.show_main(id.clone(), view, cx)) {
|
||||
log::warn!("failed to open panel {id}: {error}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens a detail tile beside the main panel, reusing it when it is already open.
|
||||
/// Opens the panel as a sub panel of the active main panel, reusing the tile
|
||||
/// that is already open.
|
||||
pub fn open_detail<P, F>(
|
||||
workspace: &WeakEntity<AppRoot>,
|
||||
id: impl Into<SharedString>,
|
||||
@@ -45,8 +50,9 @@ pub fn open_detail<P, F>(
|
||||
F: Fn(&mut Window, &mut App) -> Entity<P> + 'static,
|
||||
{
|
||||
let id = id.into();
|
||||
|
||||
if workspace
|
||||
.read_with(cx, |app, cx| app.panel().read(cx).has(&id))
|
||||
.read_with(cx, |app, cx| app.has_detail(&id, cx))
|
||||
.unwrap_or(false)
|
||||
{
|
||||
return;
|
||||
@@ -57,3 +63,19 @@ pub fn open_detail<P, F>(
|
||||
log::warn!("failed to open panel {id}: {error}");
|
||||
}
|
||||
}
|
||||
|
||||
/// The corner button a sub panel renders to close itself.
|
||||
pub fn close_button(workspace: &WeakEntity<AppRoot>, panel_id: &SharedString) -> Button {
|
||||
let workspace = workspace.clone();
|
||||
let panel_id = panel_id.clone();
|
||||
Button::new((ElementId::from("close-sub-panel"), panel_id.clone()))
|
||||
.icon(Icon::named(ui::icons::IconRole::Close))
|
||||
.variant(ButtonVariant::Ghost)
|
||||
.xsmall()
|
||||
.on_click(move |_, _, cx| {
|
||||
let panel_id = panel_id.clone();
|
||||
if let Err(error) = workspace.update(cx, |app, cx| app.close_detail(&panel_id, cx)) {
|
||||
log::warn!("failed to close panel {panel_id}: {error}");
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user