refactor: merge workspace state into app root
This commit is contained in:
@@ -2,19 +2,24 @@ pub mod helpers;
|
||||
mod placeholder;
|
||||
mod sign_in;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AppContext as _, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _,
|
||||
Render, Styled as _, Subscription, Window, div, px,
|
||||
App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
||||
ParentElement as _, Render, SharedString, Styled as _, Subscription, WeakEntity, 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;
|
||||
use ui::layout::panel::{Panel, PanelRow, PanelView};
|
||||
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;
|
||||
@@ -26,10 +31,16 @@ use crate::titlebar::{
|
||||
CreateRepository, REPOSITORY_KEY_CONTEXT, SwitchRepository, TitlebarView,
|
||||
bind_repository_shortcuts,
|
||||
};
|
||||
use crate::workspace::Workspace;
|
||||
|
||||
pub struct AppRoot {
|
||||
workspace: Entity<Workspace>,
|
||||
/// 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>,
|
||||
titlebar: Entity<TitlebarView>,
|
||||
sign_in: Entity<SignedOutView>,
|
||||
explore: Entity<ExploreView>,
|
||||
@@ -42,11 +53,11 @@ impl AppRoot {
|
||||
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||
bind_repository_shortcuts(cx);
|
||||
|
||||
let workspace = cx.new(|_| Workspace::new());
|
||||
let titlebar = cx.new(|cx| TitlebarView::new(workspace.downgrade(), window, cx));
|
||||
|
||||
let app = cx.entity().downgrade();
|
||||
let detail_pane = cx.new(|_| DetailPane { app: app.clone() });
|
||||
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(workspace.downgrade(), cx));
|
||||
let explore = cx.new(|cx| ExploreView::new(app.clone(), cx));
|
||||
let empty = cx.new(|_| PlaceholderView::new("Select a repository"));
|
||||
|
||||
let backend = Backend::global(cx);
|
||||
@@ -64,12 +75,17 @@ impl AppRoot {
|
||||
cx.toast(Toast::new(message.clone()).icon(IconRole::Warning));
|
||||
}
|
||||
BackendEvent::SignerChanged => {
|
||||
this.workspace.update(cx, |workspace, cx| {
|
||||
workspace.clear(cx);
|
||||
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)));
|
||||
if signed_in {
|
||||
ExploreView::open(&app, window, cx);
|
||||
}
|
||||
});
|
||||
if backend.read(cx).current_user().is_some() {
|
||||
ExploreView::open(&this.workspace.downgrade(), window, cx);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
@@ -80,7 +96,6 @@ impl AppRoot {
|
||||
apply_appearance_mode(settings.appearance, cx);
|
||||
}));
|
||||
|
||||
let app = cx.entity().downgrade();
|
||||
window.defer(cx, move |_window, cx| {
|
||||
if backend.read(cx).passphrase_required() {
|
||||
log_dropped(app.update(cx, |this, cx| this.open_passphrase(cx)));
|
||||
@@ -88,7 +103,13 @@ impl AppRoot {
|
||||
});
|
||||
|
||||
Self {
|
||||
workspace,
|
||||
main: None,
|
||||
main_order: Vec::new(),
|
||||
main_views: HashMap::new(),
|
||||
details: Vec::new(),
|
||||
detail_views: HashMap::new(),
|
||||
active_detail: None,
|
||||
detail_pane,
|
||||
titlebar,
|
||||
sign_in,
|
||||
explore,
|
||||
@@ -106,6 +127,210 @@ impl AppRoot {
|
||||
self.passphrase = Some(dialog.clone());
|
||||
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()
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
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 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);
|
||||
}));
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for AppRoot {
|
||||
@@ -113,9 +338,9 @@ impl Render for AppRoot {
|
||||
let backend = Backend::global(cx);
|
||||
let signed_in = backend.read(cx).current_user().is_some();
|
||||
|
||||
let repo_tabs = self.render_repo_tabs(cx);
|
||||
let titlebar_view = self.titlebar.read(cx);
|
||||
let workspace = self.workspace.read(cx);
|
||||
let main = workspace.active_main();
|
||||
let main = self.active_main();
|
||||
|
||||
div()
|
||||
.relative()
|
||||
@@ -144,10 +369,11 @@ impl Render for AppRoot {
|
||||
.child(titlebar_view.render_explore())
|
||||
.child(titlebar_view.repository_switcher()),
|
||||
)
|
||||
.tab_bar(h_flex().gap_1().when_some(
|
||||
titlebar_view.render_repo_tabs(workspace),
|
||||
|bar, tabs| bar.child(tabs),
|
||||
))
|
||||
.tab_bar(
|
||||
h_flex()
|
||||
.gap_1()
|
||||
.when_some(repo_tabs, |bar, tabs| bar.child(tabs)),
|
||||
)
|
||||
.when_some(titlebar_view.render_user_menu(cx), |titlebar, menu| {
|
||||
titlebar.suffix(menu)
|
||||
}),
|
||||
@@ -155,8 +381,8 @@ impl Render for AppRoot {
|
||||
.child(
|
||||
PanelRow::new("signed-panel")
|
||||
.when_some(main.as_ref(), |row, main| {
|
||||
row.main(main.clone()).when(workspace.has_details(), |row| {
|
||||
row.split(self.workspace.clone())
|
||||
row.main(main.clone()).when(self.has_details(), |row| {
|
||||
row.split(self.detail_pane.clone())
|
||||
})
|
||||
})
|
||||
.when(!main.is_some() && signed_in, |row| {
|
||||
@@ -170,3 +396,72 @@ impl Render for AppRoot {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// 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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@ use ui::icons::{Icon, IconRole};
|
||||
use ui::theme::ActiveTheme as _;
|
||||
use utils::relative_time;
|
||||
|
||||
use crate::app::AppRoot;
|
||||
use crate::repo::actions::open_repo_panel;
|
||||
use crate::repo::helpers::{announcement_display_name, upstream_display_name};
|
||||
use crate::workspace::Workspace;
|
||||
|
||||
const RECENT_COUNT: usize = 10;
|
||||
|
||||
@@ -55,7 +55,7 @@ pub(super) fn render_card(
|
||||
last_activity: Option<Timestamp>,
|
||||
announcements: &[Announcement],
|
||||
directory: &Entity<ProfileDirectory>,
|
||||
workspace: &WeakEntity<Workspace>,
|
||||
workspace: &WeakEntity<AppRoot>,
|
||||
cx: &mut gpui::App,
|
||||
) -> AnyElement {
|
||||
let owner = directory.read(cx).profile(&announcement.owner, cx);
|
||||
|
||||
@@ -18,8 +18,8 @@ use ui::scrollbar::Scrollbar;
|
||||
use ui::segmented::{Segmented, SegmentedOption};
|
||||
use ui::theme::ActiveTheme as _;
|
||||
|
||||
use crate::app::AppRoot;
|
||||
use crate::shared::panels;
|
||||
use crate::workspace::Workspace;
|
||||
|
||||
const COLUMNS: usize = 2;
|
||||
// Name row, avatar strip, meta row, and their borders and gaps, in px.
|
||||
@@ -27,7 +27,7 @@ const CARD_HEIGHT: f32 = 40. + 64. + 48. + 2. + 6.;
|
||||
|
||||
pub struct ExploreView {
|
||||
store: Entity<RepoListStore>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
scroll_handle: ListState,
|
||||
filter: RepoFilter,
|
||||
/// Indices matching [`Self::filter`] into the store's `announcements`.
|
||||
@@ -44,7 +44,7 @@ impl ExploreView {
|
||||
pub(crate) const PANEL_ID: &'static str = "Explore";
|
||||
|
||||
/// Opens the explore panel in the main panel, reusing it when it is already cached.
|
||||
pub(crate) fn open(workspace: &WeakEntity<Workspace>, window: &mut Window, cx: &mut App) {
|
||||
pub(crate) fn open(workspace: &WeakEntity<AppRoot>, window: &mut Window, cx: &mut App) {
|
||||
panels::open_primary(
|
||||
workspace,
|
||||
Self::PANEL_ID,
|
||||
@@ -57,7 +57,7 @@ impl ExploreView {
|
||||
);
|
||||
}
|
||||
|
||||
pub fn new(workspace: WeakEntity<Workspace>, cx: &mut Context<Self>) -> Self {
|
||||
pub fn new(workspace: WeakEntity<AppRoot>, cx: &mut Context<Self>) -> Self {
|
||||
let store = RepoListStore::global(cx);
|
||||
let directory = ProfileDirectory::new(cx);
|
||||
|
||||
|
||||
@@ -24,9 +24,9 @@ mod helpers;
|
||||
|
||||
use helpers::{empty_section_row, repo_header, thread};
|
||||
|
||||
use crate::app::AppRoot;
|
||||
use crate::repo::actions::{RepoItem, open_repo_item};
|
||||
use crate::repo::helpers::announcement_display_name;
|
||||
use crate::workspace::Workspace;
|
||||
|
||||
const MAX_SUB_ACTIVITIES: usize = 5;
|
||||
|
||||
@@ -45,7 +45,7 @@ struct InboxSection {
|
||||
}
|
||||
|
||||
pub struct InboxView {
|
||||
workspace: WeakEntity<Workspace>,
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
threads: Arc<Vec<InboxItem>>,
|
||||
sections: Arc<Vec<InboxSection>>,
|
||||
rows: Arc<Vec<InboxRow>>,
|
||||
@@ -60,7 +60,7 @@ pub struct InboxView {
|
||||
}
|
||||
|
||||
impl InboxView {
|
||||
pub fn new(workspace: WeakEntity<Workspace>, cx: &mut Context<Self>) -> Self {
|
||||
pub fn new(workspace: WeakEntity<AppRoot>, cx: &mut Context<Self>) -> Self {
|
||||
let backend = Backend::global(cx);
|
||||
let inbox = backend.read(cx).inbox();
|
||||
|
||||
|
||||
@@ -19,18 +19,18 @@ use utils::relative_time;
|
||||
use std::rc::Rc;
|
||||
|
||||
use self::detail::IssueDetailView;
|
||||
use crate::app::AppRoot;
|
||||
use crate::repo::helpers::short_id;
|
||||
use crate::shared::event_list::{EventHandler, EventList, EventRow, filter_toolbar};
|
||||
use crate::shared::log_dropped;
|
||||
use crate::shared::panels;
|
||||
use crate::workspace::Workspace;
|
||||
|
||||
pub mod detail;
|
||||
pub(crate) mod helpers;
|
||||
pub mod new_issue;
|
||||
|
||||
pub struct IssuesView {
|
||||
workspace: WeakEntity<Workspace>,
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
store: Entity<RepoStore>,
|
||||
new_issue: Option<Entity<new_issue::NewIssueDialog>>,
|
||||
filter: IssueFilter,
|
||||
@@ -46,7 +46,7 @@ pub struct IssuesView {
|
||||
|
||||
impl IssuesView {
|
||||
pub fn new(
|
||||
workspace: WeakEntity<Workspace>,
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
store: Entity<RepoStore>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
|
||||
@@ -9,7 +9,6 @@ mod repo;
|
||||
mod settings;
|
||||
mod shared;
|
||||
mod titlebar;
|
||||
mod workspace;
|
||||
|
||||
pub use app::AppRoot;
|
||||
pub use app::helpers::apply_appearance_mode;
|
||||
|
||||
@@ -27,13 +27,13 @@ use ui::theme::ActiveTheme as _;
|
||||
use utils::relative_time;
|
||||
|
||||
use super::dialogs;
|
||||
use crate::app::AppRoot;
|
||||
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::widgets::status_badge;
|
||||
use crate::workspace::Workspace;
|
||||
|
||||
const NOT_FOUND: &str = "Pull request not found";
|
||||
|
||||
@@ -49,7 +49,7 @@ struct PrBinding {
|
||||
}
|
||||
|
||||
pub struct PullRequestDetailView {
|
||||
workspace: WeakEntity<Workspace>,
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
store: Entity<RepoStore>,
|
||||
pr_id: EventId,
|
||||
update_dialog: Option<Entity<dialogs::update::UpdatePrDialog>>,
|
||||
@@ -72,7 +72,7 @@ pub struct PullRequestDetailView {
|
||||
|
||||
impl PullRequestDetailView {
|
||||
pub fn new(
|
||||
workspace: WeakEntity<Workspace>,
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
store: Entity<RepoStore>,
|
||||
pr_id: EventId,
|
||||
_window: &mut Window,
|
||||
|
||||
@@ -29,15 +29,15 @@ use helpers::PullRequestFilter;
|
||||
pub use new::NewPullRequestView;
|
||||
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::log_dropped;
|
||||
use crate::shared::panels::open_detail;
|
||||
use crate::workspace::Workspace;
|
||||
|
||||
pub struct PullRequestsView {
|
||||
workspace: WeakEntity<Workspace>,
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
store: Entity<RepoStore>,
|
||||
filter: PullRequestFilter,
|
||||
visible_prs: Vec<usize>,
|
||||
@@ -51,7 +51,7 @@ pub struct PullRequestsView {
|
||||
|
||||
impl PullRequestsView {
|
||||
pub fn new(
|
||||
workspace: WeakEntity<Workspace>,
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
store: Entity<RepoStore>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
|
||||
@@ -23,16 +23,16 @@ use ui::spinner::Spinner;
|
||||
use ui::tabs::{Tab, Tabs};
|
||||
|
||||
use super::helpers::{ForkCompare, truncate_label};
|
||||
use crate::app::AppRoot;
|
||||
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::progress::error_row;
|
||||
use crate::workspace::Workspace;
|
||||
|
||||
pub struct NewPullRequestView {
|
||||
workspace: WeakEntity<Workspace>,
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
panel_id: SharedString,
|
||||
pub(super) store: Entity<RepoStore>,
|
||||
pub(super) repo_path: Option<PathBuf>,
|
||||
@@ -61,7 +61,7 @@ pub struct NewPullRequestView {
|
||||
|
||||
impl NewPullRequestView {
|
||||
pub fn new(
|
||||
workspace: WeakEntity<Workspace>,
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
panel_id: SharedString,
|
||||
store: Entity<RepoStore>,
|
||||
window: &mut Window,
|
||||
|
||||
@@ -11,12 +11,12 @@ use ui::input::{Input, InputState};
|
||||
use ui::layout::panel::Panel;
|
||||
use ui::theme::ActiveTheme as _;
|
||||
|
||||
use crate::app::AppRoot;
|
||||
use crate::shared::log_dropped;
|
||||
use crate::shared::progress::error_row;
|
||||
use crate::workspace::Workspace;
|
||||
|
||||
pub struct SendPatchView {
|
||||
workspace: WeakEntity<Workspace>,
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
panel_id: SharedString,
|
||||
store: Entity<RepoStore>,
|
||||
subject: Entity<InputState>,
|
||||
@@ -28,7 +28,7 @@ pub struct SendPatchView {
|
||||
|
||||
impl SendPatchView {
|
||||
pub fn new(
|
||||
workspace: WeakEntity<Workspace>,
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
panel_id: SharedString,
|
||||
store: Entity<RepoStore>,
|
||||
_window: &mut Window,
|
||||
|
||||
@@ -3,9 +3,9 @@ use nostr::prelude::EventId;
|
||||
use signed_core::{Announcement, RepoAddr};
|
||||
use signed_state::RepoStore;
|
||||
|
||||
use crate::app::AppRoot;
|
||||
use crate::repo::RepoDetailView;
|
||||
use crate::shared::panels;
|
||||
use crate::workspace::Workspace;
|
||||
|
||||
/// An item of a repository to open from outside its detail panel.
|
||||
pub enum RepoItem {
|
||||
@@ -16,7 +16,7 @@ pub enum RepoItem {
|
||||
|
||||
/// Opens a repository as the main panel, keyed by its address.
|
||||
pub fn open_repo_panel(
|
||||
workspace: &WeakEntity<Workspace>,
|
||||
workspace: &WeakEntity<AppRoot>,
|
||||
addr: &RepoAddr,
|
||||
hint: Option<&Announcement>,
|
||||
window: &mut Window,
|
||||
@@ -42,7 +42,7 @@ pub fn open_repo_panel(
|
||||
|
||||
/// Opens an issue or pull request using a store built here.
|
||||
pub fn open_repo_item(
|
||||
workspace: &WeakEntity<Workspace>,
|
||||
workspace: &WeakEntity<AppRoot>,
|
||||
addr: &RepoAddr,
|
||||
hint: Option<&Announcement>,
|
||||
item: RepoItem,
|
||||
|
||||
@@ -16,15 +16,15 @@ use ui::input::{Input, InputState};
|
||||
use ui::tooltip::Tooltip;
|
||||
|
||||
use super::grasp_servers::{GraspServersState, grasp_servers_field, load_user_grasp_servers};
|
||||
use crate::app::AppRoot;
|
||||
use crate::repo::actions::open_repo_panel;
|
||||
use crate::shared::progress::{
|
||||
DialogProgress, dialog_submit_button, error_row, push_steps_row, run_dialog_task_with,
|
||||
};
|
||||
use crate::workspace::Workspace;
|
||||
|
||||
/// Progress of the create-repository flow, so async results can be rendered.
|
||||
pub struct CreateRepoDialog {
|
||||
workspace: WeakEntity<Workspace>,
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
handle: DialogHandle,
|
||||
name_input: Entity<InputState>,
|
||||
desc_input: Entity<InputState>,
|
||||
@@ -37,11 +37,7 @@ pub struct CreateRepoDialog {
|
||||
}
|
||||
|
||||
impl CreateRepoDialog {
|
||||
pub fn new(
|
||||
workspace: WeakEntity<Workspace>,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> Entity<Self> {
|
||||
pub fn new(workspace: WeakEntity<AppRoot>, window: &mut Window, cx: &mut App) -> Entity<Self> {
|
||||
let settings = SettingsStore::global(cx);
|
||||
let grasp_settings = settings.read(cx).settings().grasp_servers.clone();
|
||||
|
||||
|
||||
@@ -20,13 +20,13 @@ use ui::tooltip::Tooltip;
|
||||
|
||||
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::workspace::Workspace;
|
||||
|
||||
pub struct RepoHistoryView {
|
||||
store: Entity<RepoStore>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
detail: WeakEntity<RepoDetailView>,
|
||||
sync_directory: Entity<SyncStatusDirectory>,
|
||||
worktree: Option<PathBuf>,
|
||||
@@ -43,7 +43,7 @@ pub struct RepoHistoryView {
|
||||
impl RepoHistoryView {
|
||||
pub fn new(
|
||||
store: Entity<RepoStore>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
detail: WeakEntity<RepoDetailView>,
|
||||
sync_directory: Entity<SyncStatusDirectory>,
|
||||
) -> Self {
|
||||
|
||||
@@ -50,11 +50,11 @@ use history::RepoHistoryView;
|
||||
use refs::RefSwitcher;
|
||||
use utils::relative_time_secs;
|
||||
|
||||
use crate::app::AppRoot;
|
||||
use crate::issues::IssuesView;
|
||||
use crate::pull_requests::PullRequestsView;
|
||||
use crate::repo::helpers::{short_id, sorted_worktree_paths};
|
||||
use crate::shared::log_dropped;
|
||||
use crate::workspace::Workspace;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub(super) enum RepoSection {
|
||||
@@ -73,7 +73,7 @@ pub enum RefKind {
|
||||
}
|
||||
|
||||
pub struct RepoDetailView {
|
||||
pub(super) workspace: WeakEntity<Workspace>,
|
||||
pub(super) workspace: WeakEntity<AppRoot>,
|
||||
pub(super) store: Entity<RepoStore>,
|
||||
about: Option<Entity<dialogs::about::AboutDialog>>,
|
||||
init: Option<Entity<dialogs::init::InitRepoDialog>>,
|
||||
@@ -112,7 +112,7 @@ pub struct RepoDetailView {
|
||||
|
||||
impl RepoDetailView {
|
||||
pub fn new(
|
||||
workspace: WeakEntity<Workspace>,
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
addr: RepoAddr,
|
||||
hint: Option<Announcement>,
|
||||
window: &mut Window,
|
||||
@@ -123,7 +123,7 @@ impl RepoDetailView {
|
||||
}
|
||||
|
||||
pub fn new_local(
|
||||
workspace: WeakEntity<Workspace>,
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
local_path: PathBuf,
|
||||
nip34: Option<Nip34Binding>,
|
||||
window: &mut Window,
|
||||
@@ -135,7 +135,7 @@ impl RepoDetailView {
|
||||
|
||||
/// A local repository whose detected binding matches an announcement.
|
||||
pub fn new_local_announced(
|
||||
workspace: WeakEntity<Workspace>,
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
announcement: Announcement,
|
||||
local_path: PathBuf,
|
||||
window: &mut Window,
|
||||
@@ -147,7 +147,7 @@ impl RepoDetailView {
|
||||
}
|
||||
|
||||
fn new_common(
|
||||
workspace: WeakEntity<Workspace>,
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
store: Entity<RepoStore>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::sync::Arc;
|
||||
use gpui::{App, Entity, SharedString, WeakEntity, Window};
|
||||
use ui::layout::panel::{Panel, PanelView};
|
||||
|
||||
use crate::workspace::Workspace;
|
||||
use crate::app::AppRoot;
|
||||
|
||||
/// Which slot of the workspace a panel opens into.
|
||||
#[derive(Clone, Copy)]
|
||||
@@ -14,7 +14,7 @@ enum PanelSlot {
|
||||
|
||||
impl PanelSlot {
|
||||
/// Whether the slot already holds a panel under `id`.
|
||||
fn has(self, workspace: &WeakEntity<Workspace>, id: &SharedString, cx: &App) -> bool {
|
||||
fn has(self, workspace: &WeakEntity<AppRoot>, id: &SharedString, cx: &App) -> bool {
|
||||
match self {
|
||||
PanelSlot::Main => workspace
|
||||
.read_with(cx, |workspace, _| workspace.has_main(id))
|
||||
@@ -26,7 +26,7 @@ impl PanelSlot {
|
||||
}
|
||||
|
||||
/// Activates the slot's cached panel under `id`.
|
||||
fn activate(self, workspace: &WeakEntity<Workspace>, id: &SharedString, cx: &mut App) {
|
||||
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))
|
||||
@@ -43,7 +43,7 @@ impl PanelSlot {
|
||||
/// Shows the panel in the slot.
|
||||
fn show(
|
||||
self,
|
||||
workspace: &WeakEntity<Workspace>,
|
||||
workspace: &WeakEntity<AppRoot>,
|
||||
id: SharedString,
|
||||
view: Arc<dyn PanelView>,
|
||||
cx: &mut App,
|
||||
@@ -65,7 +65,7 @@ impl PanelSlot {
|
||||
/// Opens a panel in `slot`, reusing it when it is already cached.
|
||||
fn open_slot<P, F>(
|
||||
slot: PanelSlot,
|
||||
workspace: &WeakEntity<Workspace>,
|
||||
workspace: &WeakEntity<AppRoot>,
|
||||
id: impl Into<SharedString>,
|
||||
build: F,
|
||||
window: &mut Window,
|
||||
@@ -87,7 +87,7 @@ fn open_slot<P, F>(
|
||||
|
||||
/// Opens a repository in the main panel, reusing it when it is already cached.
|
||||
pub fn open_primary<P, F>(
|
||||
workspace: &WeakEntity<Workspace>,
|
||||
workspace: &WeakEntity<AppRoot>,
|
||||
id: impl Into<SharedString>,
|
||||
build: F,
|
||||
window: &mut Window,
|
||||
@@ -101,7 +101,7 @@ pub fn open_primary<P, F>(
|
||||
|
||||
/// Opens a detail panel beside the main panel, reusing it when it is already cached.
|
||||
pub fn open_detail<P, F>(
|
||||
workspace: &WeakEntity<Workspace>,
|
||||
workspace: &WeakEntity<AppRoot>,
|
||||
id: impl Into<SharedString>,
|
||||
build: F,
|
||||
window: &mut Window,
|
||||
|
||||
@@ -15,18 +15,16 @@ use ui::avatar::Avatar;
|
||||
use ui::button::{Button, ButtonVariant};
|
||||
use ui::command_palette::{Command, CommandPalette, CommandPaletteState};
|
||||
use ui::icons::{Icon, IconRole};
|
||||
use ui::layout::panel::PanelView;
|
||||
use ui::layout::root::RootContext as _;
|
||||
use ui::menu::{Menu, MenuItem};
|
||||
use ui::tabs::{Tab, Tabs, TabsVariant};
|
||||
use ui::tooltip::Tooltip;
|
||||
|
||||
use crate::app::AppRoot;
|
||||
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::workspace::Workspace;
|
||||
|
||||
mod repository_switcher;
|
||||
|
||||
@@ -59,7 +57,7 @@ pub(crate) struct CreateRepository;
|
||||
|
||||
pub struct TitlebarView {
|
||||
weak: WeakEntity<Self>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
app: WeakEntity<AppRoot>,
|
||||
/// User's announced repositories.
|
||||
announcements: Arc<Vec<Announcement>>,
|
||||
/// Local repositories found by the scan that are not announced yet.
|
||||
@@ -72,11 +70,7 @@ pub struct TitlebarView {
|
||||
}
|
||||
|
||||
impl TitlebarView {
|
||||
pub fn new(
|
||||
workspace: WeakEntity<Workspace>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
pub fn new(app: WeakEntity<AppRoot>, window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||
let backend = Backend::global(cx);
|
||||
let repos = RepoListStore::global(cx);
|
||||
let local = LocalReposStore::global(cx);
|
||||
@@ -150,7 +144,7 @@ impl TitlebarView {
|
||||
|
||||
Self {
|
||||
weak: cx.entity().downgrade(),
|
||||
workspace,
|
||||
app,
|
||||
announcements: Arc::new(Vec::new()),
|
||||
local_repos: Arc::new(Vec::new()),
|
||||
directory,
|
||||
@@ -298,57 +292,6 @@ impl TitlebarView {
|
||||
self.repository_switcher.clone()
|
||||
}
|
||||
|
||||
/// Tabs for the repositories opened in the main panel.
|
||||
pub fn render_repo_tabs(&self, workspace: &Workspace) -> Option<Tabs> {
|
||||
let open = workspace.open_mains();
|
||||
|
||||
if open.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let tabs: Vec<_> = open
|
||||
.iter()
|
||||
.map(|id| (id.clone(), workspace.main_view(id)))
|
||||
.collect();
|
||||
|
||||
let selected = workspace
|
||||
.active_main_id()
|
||||
.and_then(|id| open.iter().position(|open_id| open_id == id))
|
||||
.unwrap_or(usize::MAX);
|
||||
|
||||
let change_workspace = self.workspace.clone();
|
||||
let close_workspace = self.workspace.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(change_workspace.update(cx, |workspace, cx| {
|
||||
workspace.activate_main(&id, cx);
|
||||
}));
|
||||
})
|
||||
.on_close(move |index, _, cx| {
|
||||
log_dropped(close_workspace.update(cx, |workspace, cx| {
|
||||
workspace.close_main_at(index, cx);
|
||||
}));
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn activate_shortcut(
|
||||
&mut self,
|
||||
index: usize,
|
||||
@@ -379,7 +322,7 @@ impl TitlebarView {
|
||||
}
|
||||
|
||||
fn open_create(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
let view = dialogs::create::CreateRepoDialog::new(self.workspace.clone(), window, cx);
|
||||
let view = dialogs::create::CreateRepoDialog::new(self.app.clone(), window, cx);
|
||||
cx.open_dialog(view);
|
||||
cx.notify();
|
||||
}
|
||||
@@ -387,7 +330,7 @@ impl TitlebarView {
|
||||
fn activate(&mut self, index: usize, window: &mut Window, cx: &mut Context<Self>) {
|
||||
if let Some(announcement) = self.announcements.get(index) {
|
||||
let addr = announcement.addr();
|
||||
actions::open_repo_panel(&self.workspace, &addr, Some(announcement), window, cx);
|
||||
actions::open_repo_panel(&self.app, &addr, Some(announcement), window, cx);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -416,7 +359,7 @@ impl TitlebarView {
|
||||
|
||||
if let Some(announcement) = announcement {
|
||||
let id = SharedString::from(format!("repo:{}", announcement.addr()));
|
||||
let workspace = self.workspace.clone();
|
||||
let workspace = self.app.clone();
|
||||
let workspace_for_build = workspace.clone();
|
||||
panels::open_primary(
|
||||
&workspace,
|
||||
@@ -439,7 +382,7 @@ impl TitlebarView {
|
||||
}
|
||||
|
||||
let id = SharedString::from(format!("repo-local:{}", path.display()));
|
||||
let workspace = self.workspace.clone();
|
||||
let workspace = self.app.clone();
|
||||
let workspace_for_build = workspace.clone();
|
||||
|
||||
panels::open_primary(
|
||||
@@ -471,7 +414,7 @@ impl TitlebarView {
|
||||
}
|
||||
|
||||
pub fn render_explore(&self) -> AnyElement {
|
||||
let workspace = self.workspace.clone();
|
||||
let workspace = self.app.clone();
|
||||
|
||||
Button::new("open-explore")
|
||||
.icon(IconRole::Grid)
|
||||
|
||||
@@ -1,244 +0,0 @@
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
App, Context, IntoElement, ParentElement as _, Render, SharedString, Styled as _, Window, div,
|
||||
};
|
||||
use ui::common::v_flex;
|
||||
use ui::layout::panel::{Panel, PanelView};
|
||||
use ui::tabs::{Tab, Tabs, TabsVariant};
|
||||
|
||||
use crate::shared::log_dropped;
|
||||
|
||||
/// The repository shown in the main panel and the detail panels opened beside it.
|
||||
#[derive(Default)]
|
||||
pub struct Workspace {
|
||||
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>,
|
||||
}
|
||||
|
||||
impl Workspace {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub fn active_main(&self) -> Option<Arc<dyn PanelView>> {
|
||||
self.main
|
||||
.as_ref()
|
||||
.and_then(|id| self.main_views.get(id))
|
||||
.cloned()
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
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 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>) {
|
||||
if index >= self.details.len() {
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
impl Panel for Workspace {
|
||||
fn title(&self, _cx: &App) -> SharedString {
|
||||
SharedString::from("Workspace")
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for Workspace {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let selected = self
|
||||
.active_detail
|
||||
.as_ref()
|
||||
.and_then(|active| self.details.iter().position(|id| id == active))
|
||||
.unwrap_or(usize::MAX);
|
||||
|
||||
let details: Vec<_> = self
|
||||
.details
|
||||
.iter()
|
||||
.map(|id| (id.clone(), self.detail_views.get(id).cloned()))
|
||||
.collect();
|
||||
|
||||
let weak = cx.entity().downgrade();
|
||||
let body = self.active_detail().map(|view| view.view());
|
||||
|
||||
v_flex()
|
||||
.size_full()
|
||||
.gap_2()
|
||||
.when(self.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, |workspace, cx| {
|
||||
workspace.activate_detail_at(index, cx);
|
||||
}));
|
||||
})
|
||||
.on_close(move |index, _, cx| {
|
||||
log_dropped(close_weak.update(cx, |workspace, cx| {
|
||||
workspace.close_detail_at(index, cx);
|
||||
}));
|
||||
}),
|
||||
)
|
||||
})
|
||||
.child(div().flex_1().min_h_0().w_full().children(body))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user