refactor: move panel state into panel stack
This commit is contained in:
@@ -2,24 +2,19 @@ pub mod helpers;
|
||||
mod placeholder;
|
||||
mod sign_in;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
||||
ParentElement as _, Render, SharedString, Styled as _, Subscription, WeakEntity, Window, div,
|
||||
px,
|
||||
AnyView, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
||||
ParentElement as _, Render, 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::{Panel, PanelRow, PanelView};
|
||||
use ui::layout::panel::PanelStack;
|
||||
use ui::layout::root::RootContext as _;
|
||||
use ui::layout::titlebar::Titlebar;
|
||||
use ui::tabs::{Tab, Tabs, TabsVariant};
|
||||
use ui::toast::Toast;
|
||||
|
||||
use crate::app::placeholder::PlaceholderView;
|
||||
@@ -33,14 +28,7 @@ use crate::titlebar::{
|
||||
};
|
||||
|
||||
pub struct AppRoot {
|
||||
/// The repository shown in the main panel and the detail panels beside it.
|
||||
main: Option<SharedString>,
|
||||
main_order: Vec<SharedString>,
|
||||
main_views: HashMap<SharedString, Arc<dyn PanelView>>,
|
||||
details: Vec<SharedString>,
|
||||
detail_views: HashMap<SharedString, Arc<dyn PanelView>>,
|
||||
active_detail: Option<SharedString>,
|
||||
detail_pane: Entity<DetailPane>,
|
||||
panels: Entity<PanelStack>,
|
||||
titlebar: Entity<TitlebarView>,
|
||||
sign_in: Entity<SignedOutView>,
|
||||
explore: Entity<ExploreView>,
|
||||
@@ -54,13 +42,14 @@ impl AppRoot {
|
||||
bind_repository_shortcuts(cx);
|
||||
|
||||
let app = cx.entity().downgrade();
|
||||
let detail_pane = cx.new(|_| DetailPane { app: app.clone() });
|
||||
let panels = cx.new(|cx| PanelStack::new("signed-panel", 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 signed_in = backend.read(cx).current_user().is_some();
|
||||
let settings = SettingsStore::global(cx);
|
||||
let mut subscriptions = Vec::new();
|
||||
|
||||
@@ -77,11 +66,14 @@ 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.sync_session(signed_in, cx);
|
||||
}));
|
||||
|
||||
if signed_in {
|
||||
ExploreView::open(&app, window, cx);
|
||||
}
|
||||
@@ -96,20 +88,15 @@ impl AppRoot {
|
||||
apply_appearance_mode(settings.appearance, cx);
|
||||
}));
|
||||
|
||||
window.defer(cx, move |_window, cx| {
|
||||
cx.defer_in(window, move |this, _window, cx| {
|
||||
if backend.read(cx).passphrase_required() {
|
||||
log_dropped(app.update(cx, |this, cx| this.open_passphrase(cx)));
|
||||
}
|
||||
this.sync_session(signed_in, cx);
|
||||
});
|
||||
|
||||
Self {
|
||||
main: None,
|
||||
main_order: Vec::new(),
|
||||
main_views: HashMap::new(),
|
||||
details: Vec::new(),
|
||||
detail_views: HashMap::new(),
|
||||
active_detail: None,
|
||||
detail_pane,
|
||||
panels,
|
||||
titlebar,
|
||||
sign_in,
|
||||
explore,
|
||||
@@ -128,219 +115,32 @@ impl AppRoot {
|
||||
cx.open_dialog(dialog);
|
||||
}
|
||||
|
||||
pub fn active_main(&self) -> Option<Arc<dyn PanelView>> {
|
||||
self.main
|
||||
.as_ref()
|
||||
.and_then(|id| self.main_views.get(id))
|
||||
.cloned()
|
||||
/// The panel stack: the main stack, the split stack, and the divider between them.
|
||||
pub fn panels(&self) -> &Entity<PanelStack> {
|
||||
&self.panels
|
||||
}
|
||||
|
||||
pub fn active_main_id(&self) -> Option<&SharedString> {
|
||||
self.main.as_ref()
|
||||
}
|
||||
|
||||
pub fn open_mains(&self) -> &[SharedString] {
|
||||
&self.main_order
|
||||
}
|
||||
|
||||
/// The open main panel with this id.
|
||||
pub fn main_view(&self, id: &SharedString) -> Option<Arc<dyn PanelView>> {
|
||||
self.main_views.get(id).cloned()
|
||||
}
|
||||
|
||||
pub fn active_detail(&self) -> Option<Arc<dyn PanelView>> {
|
||||
self.active_detail
|
||||
.as_ref()
|
||||
.and_then(|id| self.detail_views.get(id))
|
||||
.cloned()
|
||||
}
|
||||
|
||||
pub fn has_main(&self, id: &SharedString) -> bool {
|
||||
self.main_views.contains_key(id)
|
||||
}
|
||||
|
||||
pub fn has_details(&self) -> bool {
|
||||
!self.details.is_empty()
|
||||
}
|
||||
|
||||
pub fn has_detail(&self, id: &SharedString) -> bool {
|
||||
self.detail_views.contains_key(id)
|
||||
}
|
||||
|
||||
pub fn show_main(
|
||||
&mut self,
|
||||
id: SharedString,
|
||||
view: Arc<dyn PanelView>,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
if self.main.as_ref() != Some(&id) {
|
||||
self.clear_details();
|
||||
}
|
||||
if !self.main_views.contains_key(&id) {
|
||||
self.main_order.push(id.clone());
|
||||
}
|
||||
self.main_views.insert(id.clone(), view);
|
||||
self.main = Some(id);
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn activate_main(&mut self, id: &SharedString, cx: &mut Context<Self>) {
|
||||
if self.main.as_ref() != Some(id) {
|
||||
self.clear_details();
|
||||
}
|
||||
self.main = Some(id.clone());
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn activate_detail(&mut self, id: &SharedString, cx: &mut Context<Self>) {
|
||||
if self.detail_views.contains_key(id) {
|
||||
self.active_detail = Some(id.clone());
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn show_detail(
|
||||
&mut self,
|
||||
id: SharedString,
|
||||
view: Arc<dyn PanelView>,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
if !self.details.contains(&id) {
|
||||
self.details.push(id.clone());
|
||||
}
|
||||
self.detail_views.insert(id.clone(), view);
|
||||
self.active_detail = Some(id);
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn close_detail(&mut self, id: &SharedString, cx: &mut Context<Self>) {
|
||||
let Some(index) = self.details.iter().position(|open| open == id) else {
|
||||
return;
|
||||
/// Empties the stack and sets what it shows until a panel opens.
|
||||
fn sync_session(&mut self, signed_in: bool, cx: &mut Context<Self>) {
|
||||
let main: AnyView = if signed_in {
|
||||
self.empty.clone().into()
|
||||
} else {
|
||||
self.sign_in.clone().into()
|
||||
};
|
||||
self.close_detail_at(index, cx);
|
||||
}
|
||||
|
||||
pub fn close_main_at(&mut self, index: usize, cx: &mut Context<Self>) {
|
||||
if index >= self.main_order.len() {
|
||||
return;
|
||||
}
|
||||
let split = (!signed_in).then(|| (self.explore.clone().into(), px(300.)));
|
||||
|
||||
let id = self.main_order.remove(index);
|
||||
self.main_views.remove(&id);
|
||||
|
||||
if self.main.as_ref() == Some(&id) {
|
||||
self.main = self
|
||||
.main_order
|
||||
.get(index)
|
||||
.or_else(|| {
|
||||
index
|
||||
.checked_sub(1)
|
||||
.and_then(|prev| self.main_order.get(prev))
|
||||
})
|
||||
.cloned();
|
||||
self.clear_details();
|
||||
}
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn clear(&mut self, cx: &mut Context<Self>) {
|
||||
self.main = None;
|
||||
self.main_order.clear();
|
||||
self.main_views.clear();
|
||||
self.clear_details();
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn clear_details(&mut self) {
|
||||
self.details.clear();
|
||||
self.detail_views.clear();
|
||||
self.active_detail = None;
|
||||
}
|
||||
|
||||
fn close_detail_at(&mut self, index: usize, cx: &mut Context<Self>) {
|
||||
let id = self.details.remove(index);
|
||||
self.detail_views.remove(&id);
|
||||
|
||||
if self.active_detail.as_ref() == Some(&id) {
|
||||
self.active_detail = self
|
||||
.details
|
||||
.get(index)
|
||||
.or_else(|| index.checked_sub(1).and_then(|prev| self.details.get(prev)))
|
||||
.cloned();
|
||||
}
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn activate_detail_at(&mut self, index: usize, cx: &mut Context<Self>) {
|
||||
let Some(id) = self.details.get(index) else {
|
||||
return;
|
||||
};
|
||||
self.active_detail = Some(id.clone());
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// Tabs for the repositories opened in the main panel.
|
||||
fn render_repo_tabs(&self, cx: &mut Context<Self>) -> Option<Tabs> {
|
||||
let open = self.open_mains();
|
||||
|
||||
if open.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let tabs: Vec<_> = open
|
||||
.iter()
|
||||
.map(|id| (id.clone(), self.main_view(id)))
|
||||
.collect();
|
||||
|
||||
let selected = self
|
||||
.active_main_id()
|
||||
.and_then(|id| open.iter().position(|open_id| open_id == id))
|
||||
.unwrap_or(usize::MAX);
|
||||
|
||||
let app = cx.entity().downgrade();
|
||||
let close_app = app.clone();
|
||||
let open_for_change = open.to_vec();
|
||||
|
||||
Some(
|
||||
Tabs::new("signed-repo-tabs")
|
||||
.variant(TabsVariant::Titlebar)
|
||||
.overflow_scroll(true)
|
||||
.selected(selected)
|
||||
.tabs(move |_, cx| {
|
||||
tabs.iter()
|
||||
.map(|(id, view)| match view {
|
||||
Some(view) => view.tab(id.clone().into(), cx).closeable(true),
|
||||
None => Tab::new(id.clone(), id.clone()).closeable(true),
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.on_change(move |index, _, cx| {
|
||||
let Some(id) = open_for_change.get(index).cloned() else {
|
||||
return;
|
||||
};
|
||||
log_dropped(app.update(cx, |app, cx| {
|
||||
app.activate_main(&id, cx);
|
||||
}));
|
||||
})
|
||||
.on_close(move |index, _, cx| {
|
||||
log_dropped(close_app.update(cx, |app, cx| {
|
||||
app.close_main_at(index, cx);
|
||||
}));
|
||||
}),
|
||||
)
|
||||
self.panels.update(cx, |panels, cx| {
|
||||
panels.clear(cx);
|
||||
panels.set_empty(main, split, cx);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for AppRoot {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let backend = Backend::global(cx);
|
||||
let signed_in = backend.read(cx).current_user().is_some();
|
||||
|
||||
let repo_tabs = self.render_repo_tabs(cx);
|
||||
let repo_tabs = PanelStack::main_tabs(self.panels.clone(), cx);
|
||||
let titlebar_view = self.titlebar.read(cx);
|
||||
let main = self.active_main();
|
||||
|
||||
div()
|
||||
.relative()
|
||||
@@ -378,90 +178,7 @@ impl Render for AppRoot {
|
||||
titlebar.suffix(menu)
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
PanelRow::new("signed-panel")
|
||||
.when_some(main.as_ref(), |row, main| {
|
||||
row.main(main.clone()).when(self.has_details(), |row| {
|
||||
row.split(self.detail_pane.clone())
|
||||
})
|
||||
})
|
||||
.when(!main.is_some() && signed_in, |row| {
|
||||
row.main(self.empty.clone())
|
||||
})
|
||||
.when(!main.is_some() && !signed_in, |row| {
|
||||
row.main(self.sign_in.clone())
|
||||
.split_at(self.explore.clone(), px(300.))
|
||||
}),
|
||||
),
|
||||
.child(self.panels.clone()),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// The split pane beside the main panel: detail tabs over the active detail.
|
||||
struct DetailPane {
|
||||
app: WeakEntity<AppRoot>,
|
||||
}
|
||||
|
||||
impl Panel for DetailPane {
|
||||
fn title(&self, _cx: &App) -> SharedString {
|
||||
SharedString::from("Workspace")
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for DetailPane {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let Some(app) = self.app.upgrade() else {
|
||||
return div().into_any_element();
|
||||
};
|
||||
let app = app.read(cx);
|
||||
|
||||
let selected = app
|
||||
.active_detail
|
||||
.as_ref()
|
||||
.and_then(|active| app.details.iter().position(|id| id == active))
|
||||
.unwrap_or(usize::MAX);
|
||||
|
||||
let details: Vec<_> = app
|
||||
.details
|
||||
.iter()
|
||||
.map(|id| (id.clone(), app.detail_views.get(id).cloned()))
|
||||
.collect();
|
||||
|
||||
let weak = self.app.clone();
|
||||
let body = app.active_detail().map(|view| view.view());
|
||||
|
||||
v_flex()
|
||||
.size_full()
|
||||
.gap_2()
|
||||
.when(app.details.len() > 1, |this| {
|
||||
let close_weak = weak.clone();
|
||||
this.child(
|
||||
Tabs::new("signed-detail-tabs")
|
||||
.variant(TabsVariant::Pill)
|
||||
.overflow_scroll(true)
|
||||
.selected(selected)
|
||||
.tabs(move |_, cx| {
|
||||
details
|
||||
.iter()
|
||||
.map(|(id, view)| match view {
|
||||
Some(view) => view.tab(id.clone().into(), cx).closeable(true),
|
||||
None => Tab::new(id.clone(), id.clone()).closeable(true),
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.on_change(move |index, _, cx| {
|
||||
log_dropped(weak.update(cx, |app, cx| {
|
||||
app.activate_detail_at(index, cx);
|
||||
}));
|
||||
})
|
||||
.on_close(move |index, _, cx| {
|
||||
log_dropped(close_weak.update(cx, |app, cx| {
|
||||
app.close_detail_at(index, cx);
|
||||
}));
|
||||
}),
|
||||
)
|
||||
})
|
||||
.child(div().flex_1().min_h_0().w_full().children(body))
|
||||
.into_any_element()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use gpui::{
|
||||
App, Context, IntoElement, ParentElement as _, Render, SharedString, Styled as _, Window, div,
|
||||
Context, IntoElement, ParentElement as _, Render, SharedString, Styled as _, Window, div,
|
||||
};
|
||||
use ui::empty_state::EmptyState;
|
||||
use ui::layout::panel::Panel;
|
||||
|
||||
/// A tab that stands in for a screen that is not ported yet.
|
||||
pub struct PlaceholderView {
|
||||
@@ -17,12 +16,6 @@ impl PlaceholderView {
|
||||
}
|
||||
}
|
||||
|
||||
impl Panel for PlaceholderView {
|
||||
fn title(&self, _cx: &App) -> SharedString {
|
||||
self.title.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for PlaceholderView {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
div().size_full().child(EmptyState::new(self.title.clone()))
|
||||
|
||||
@@ -2,12 +2,11 @@ use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
App, Context, Entity, IntoElement, ObjectFit, ParentElement as _, Render, SharedString,
|
||||
Styled as _, StyledImage as _, Window, div, img,
|
||||
Context, Entity, IntoElement, ObjectFit, ParentElement as _, Render, SharedString, Styled as _,
|
||||
StyledImage as _, Window, div, img,
|
||||
};
|
||||
use ui::button::{Button, ButtonVariant};
|
||||
use ui::common::v_flex;
|
||||
use ui::layout::panel::Panel;
|
||||
use ui::theme::ActiveTheme as _;
|
||||
|
||||
use crate::identity::import::ImportDialog;
|
||||
@@ -39,12 +38,6 @@ impl SignedOutView {
|
||||
}
|
||||
}
|
||||
|
||||
impl Panel for SignedOutView {
|
||||
fn title(&self, _cx: &App) -> SharedString {
|
||||
SharedString::from("Signed")
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for SignedOutView {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
|
||||
@@ -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::{close_detail, open_detail};
|
||||
use crate::shared::progress::error_row;
|
||||
|
||||
pub struct NewPullRequestView {
|
||||
@@ -215,9 +215,7 @@ impl NewPullRequestView {
|
||||
this.update(cx, |this, _cx| {
|
||||
this.submitting = false;
|
||||
})?;
|
||||
log_dropped(
|
||||
workspace.update(cx, |workspace, cx| workspace.close_detail(&panel_id, cx)),
|
||||
);
|
||||
close_detail(&workspace, &panel_id, cx);
|
||||
Ok(())
|
||||
});
|
||||
self.push_task(task);
|
||||
|
||||
@@ -13,6 +13,7 @@ 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 {
|
||||
@@ -83,11 +84,7 @@ impl SendPatchView {
|
||||
cx.spawn(async move |this, cx| match task.await {
|
||||
Ok(()) => {
|
||||
this.update(cx, |this, cx| {
|
||||
let panel_id = this.panel_id.clone();
|
||||
log_dropped(
|
||||
this.workspace
|
||||
.update(cx, |workspace, cx| workspace.close_detail(&panel_id, cx)),
|
||||
);
|
||||
close_detail(&this.workspace, &this.panel_id, cx)
|
||||
})
|
||||
.log_err();
|
||||
}
|
||||
|
||||
@@ -1,68 +1,10 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use gpui::{App, Entity, SharedString, WeakEntity, Window};
|
||||
use ui::layout::panel::{Panel, PanelView};
|
||||
use gpui::{App, AppContext, Entity, SharedString, WeakEntity, Window};
|
||||
use ui::layout::panel::{Panel, PanelSlot};
|
||||
|
||||
use crate::app::AppRoot;
|
||||
use crate::shared::log_dropped;
|
||||
|
||||
/// Which slot of the workspace a panel opens into.
|
||||
#[derive(Clone, Copy)]
|
||||
enum PanelSlot {
|
||||
Main,
|
||||
Detail,
|
||||
}
|
||||
|
||||
impl PanelSlot {
|
||||
/// Whether the slot already holds a panel under `id`.
|
||||
fn has(self, workspace: &WeakEntity<AppRoot>, id: &SharedString, cx: &App) -> bool {
|
||||
match self {
|
||||
PanelSlot::Main => workspace
|
||||
.read_with(cx, |workspace, _| workspace.has_main(id))
|
||||
.unwrap_or(false),
|
||||
PanelSlot::Detail => workspace
|
||||
.read_with(cx, |workspace, _| workspace.has_detail(id))
|
||||
.unwrap_or(false),
|
||||
}
|
||||
}
|
||||
|
||||
/// Activates the slot's cached panel under `id`.
|
||||
fn activate(self, workspace: &WeakEntity<AppRoot>, id: &SharedString, cx: &mut App) {
|
||||
let result = match self {
|
||||
PanelSlot::Main => {
|
||||
workspace.update(cx, |workspace, cx| workspace.activate_main(id, cx))
|
||||
}
|
||||
PanelSlot::Detail => {
|
||||
workspace.update(cx, |workspace, cx| workspace.activate_detail(id, cx))
|
||||
}
|
||||
};
|
||||
if let Err(error) = result {
|
||||
log::warn!("failed to activate panel {id}: {error}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Shows the panel in the slot.
|
||||
fn show(
|
||||
self,
|
||||
workspace: &WeakEntity<AppRoot>,
|
||||
id: SharedString,
|
||||
view: Arc<dyn PanelView>,
|
||||
cx: &mut App,
|
||||
) {
|
||||
let result = match self {
|
||||
PanelSlot::Main => {
|
||||
workspace.update(cx, |workspace, cx| workspace.show_main(id, view, cx))
|
||||
}
|
||||
PanelSlot::Detail => {
|
||||
workspace.update(cx, |workspace, cx| workspace.show_detail(id, view, cx))
|
||||
}
|
||||
};
|
||||
if let Err(error) = result {
|
||||
log::warn!("failed to open panel: {error}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens a panel in `slot`, reusing it when it is already cached.
|
||||
/// Opens a panel in `slot`, reusing it when it is already open.
|
||||
fn open_slot<P, F>(
|
||||
slot: PanelSlot,
|
||||
workspace: &WeakEntity<AppRoot>,
|
||||
@@ -74,18 +16,18 @@ fn open_slot<P, F>(
|
||||
P: Panel + 'static,
|
||||
F: Fn(&mut Window, &mut App) -> Entity<P> + 'static,
|
||||
{
|
||||
let id = id.into();
|
||||
|
||||
if slot.has(workspace, &id, cx) {
|
||||
slot.activate(workspace, &id, cx);
|
||||
return;
|
||||
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}");
|
||||
}
|
||||
|
||||
let view: Arc<dyn PanelView> = Arc::new(build(window, cx));
|
||||
slot.show(workspace, id, view, cx);
|
||||
}
|
||||
|
||||
/// Opens a repository in the main panel, reusing it when it is already cached.
|
||||
/// 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>,
|
||||
@@ -99,7 +41,7 @@ pub fn open_primary<P, F>(
|
||||
open_slot(PanelSlot::Main, workspace, id, build, window, cx);
|
||||
}
|
||||
|
||||
/// Opens a detail panel beside the main panel, reusing it when it is already cached.
|
||||
/// 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>,
|
||||
@@ -110,5 +52,16 @@ pub fn open_detail<P, F>(
|
||||
P: Panel + 'static,
|
||||
F: Fn(&mut Window, &mut App) -> Entity<P> + 'static,
|
||||
{
|
||||
open_slot(PanelSlot::Detail, workspace, id, build, window, cx);
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user