From 5bd289b418d21e875467ce7db389aad27a22d434 Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Sun, 15 Nov 2026 13:37:32 +0700 Subject: [PATCH] Replace dock shell with titlebar repository tabs - Move repository navigation from the dock sidebar to titlebar tabs. - Route main and detail panels through Workspace. - Move sign-in into the main panel and remove unlinked navigation. --- Cargo.lock | 18 +- Cargo.toml | 2 +- crates/signed_app/src/app/mod.rs | 159 ++--- crates/signed_app/src/app/placeholder.rs | 10 +- crates/signed_app/src/app/sign_in.rs | 76 ++ crates/signed_app/src/explore/helpers.rs | 14 +- crates/signed_app/src/explore/mod.rs | 35 +- crates/signed_app/src/inbox/mod.rs | 29 +- crates/signed_app/src/issues/detail.rs | 28 +- crates/signed_app/src/issues/mod.rs | 40 +- crates/signed_app/src/lib.rs | 5 +- crates/signed_app/src/pull_requests/detail.rs | 49 +- .../signed_app/src/pull_requests/helpers.rs | 8 - crates/signed_app/src/pull_requests/mod.rs | 65 +- crates/signed_app/src/pull_requests/new.rs | 65 +- .../src/pull_requests/send_patch.rs | 42 +- crates/signed_app/src/repo/actions.rs | 36 +- crates/signed_app/src/repo/commit_diff.rs | 35 +- crates/signed_app/src/repo/dialogs/create.rs | 26 +- crates/signed_app/src/repo/header.rs | 48 +- crates/signed_app/src/repo/history.rs | 31 +- crates/signed_app/src/repo/mod.rs | 36 +- crates/signed_app/src/shared/panels.rs | 68 +- crates/signed_app/src/shared/widgets.rs | 44 +- crates/signed_app/src/sidebar/helpers.rs | 47 -- crates/signed_app/src/sidebar/mod.rs | 661 ------------------ crates/signed_app/src/titlebar/helpers.rs | 25 + crates/signed_app/src/titlebar/mod.rs | 388 ++++++++++ crates/signed_app/src/workspace.rs | 193 +++++ 29 files changed, 1041 insertions(+), 1242 deletions(-) create mode 100644 crates/signed_app/src/app/sign_in.rs delete mode 100644 crates/signed_app/src/sidebar/helpers.rs delete mode 100644 crates/signed_app/src/sidebar/mod.rs create mode 100644 crates/signed_app/src/titlebar/helpers.rs create mode 100644 crates/signed_app/src/titlebar/mod.rs create mode 100644 crates/signed_app/src/workspace.rs diff --git a/Cargo.lock b/Cargo.lock index 1639f46..ed669e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3059,7 +3059,7 @@ dependencies = [ [[package]] name = "gpui-native-core" version = "0.1.0" -source = "git+https://git.reya.info/reya/gpui-native-kit?rev=c3e3c37731e389d858712369e47eec9c205cdfbe#c3e3c37731e389d858712369e47eec9c205cdfbe" +source = "git+https://git.reya.info/reya/gpui-native-kit?rev=f6ba9c0d4737ade726ad57ef5a075606bf045164#f6ba9c0d4737ade726ad57ef5a075606bf045164" dependencies = [ "cpal", "flume 0.12.0", @@ -3067,6 +3067,7 @@ dependencies = [ "gpui-native-icons", "gpui-native-theme", "gpui-native-utils", + "image", "log", "unicode-segmentation", ] @@ -3074,7 +3075,7 @@ dependencies = [ [[package]] name = "gpui-native-data" version = "0.1.0" -source = "git+https://git.reya.info/reya/gpui-native-kit?rev=c3e3c37731e389d858712369e47eec9c205cdfbe#c3e3c37731e389d858712369e47eec9c205cdfbe" +source = "git+https://git.reya.info/reya/gpui-native-kit?rev=f6ba9c0d4737ade726ad57ef5a075606bf045164#f6ba9c0d4737ade726ad57ef5a075606bf045164" dependencies = [ "gpui", "gpui-native-core", @@ -3086,7 +3087,7 @@ dependencies = [ [[package]] name = "gpui-native-editor" version = "0.1.0" -source = "git+https://git.reya.info/reya/gpui-native-kit?rev=c3e3c37731e389d858712369e47eec9c205cdfbe#c3e3c37731e389d858712369e47eec9c205cdfbe" +source = "git+https://git.reya.info/reya/gpui-native-kit?rev=f6ba9c0d4737ade726ad57ef5a075606bf045164#f6ba9c0d4737ade726ad57ef5a075606bf045164" dependencies = [ "gpui", "gpui-native-core", @@ -3105,7 +3106,7 @@ dependencies = [ [[package]] name = "gpui-native-icons" version = "0.1.0" -source = "git+https://git.reya.info/reya/gpui-native-kit?rev=c3e3c37731e389d858712369e47eec9c205cdfbe#c3e3c37731e389d858712369e47eec9c205cdfbe" +source = "git+https://git.reya.info/reya/gpui-native-kit?rev=f6ba9c0d4737ade726ad57ef5a075606bf045164#f6ba9c0d4737ade726ad57ef5a075606bf045164" dependencies = [ "anyhow", "gpui", @@ -3114,7 +3115,7 @@ dependencies = [ [[package]] name = "gpui-native-kit" version = "0.1.0" -source = "git+https://git.reya.info/reya/gpui-native-kit?rev=c3e3c37731e389d858712369e47eec9c205cdfbe#c3e3c37731e389d858712369e47eec9c205cdfbe" +source = "git+https://git.reya.info/reya/gpui-native-kit?rev=f6ba9c0d4737ade726ad57ef5a075606bf045164#f6ba9c0d4737ade726ad57ef5a075606bf045164" dependencies = [ "gpui", "gpui-native-core", @@ -3128,11 +3129,10 @@ dependencies = [ [[package]] name = "gpui-native-layout" version = "0.1.0" -source = "git+https://git.reya.info/reya/gpui-native-kit?rev=c3e3c37731e389d858712369e47eec9c205cdfbe#c3e3c37731e389d858712369e47eec9c205cdfbe" +source = "git+https://git.reya.info/reya/gpui-native-kit?rev=f6ba9c0d4737ade726ad57ef5a075606bf045164#f6ba9c0d4737ade726ad57ef5a075606bf045164" dependencies = [ "gpui", "gpui-native-core", - "gpui-native-data", "gpui-native-icons", "gpui-native-theme", "gpui-native-utils", @@ -3141,7 +3141,7 @@ dependencies = [ [[package]] name = "gpui-native-theme" version = "0.1.0" -source = "git+https://git.reya.info/reya/gpui-native-kit?rev=c3e3c37731e389d858712369e47eec9c205cdfbe#c3e3c37731e389d858712369e47eec9c205cdfbe" +source = "git+https://git.reya.info/reya/gpui-native-kit?rev=f6ba9c0d4737ade726ad57ef5a075606bf045164#f6ba9c0d4737ade726ad57ef5a075606bf045164" dependencies = [ "anyhow", "async-channel", @@ -3162,7 +3162,7 @@ dependencies = [ [[package]] name = "gpui-native-utils" version = "0.1.0" -source = "git+https://git.reya.info/reya/gpui-native-kit?rev=c3e3c37731e389d858712369e47eec9c205cdfbe#c3e3c37731e389d858712369e47eec9c205cdfbe" +source = "git+https://git.reya.info/reya/gpui-native-kit?rev=f6ba9c0d4737ade726ad57ef5a075606bf045164#f6ba9c0d4737ade726ad57ef5a075606bf045164" dependencies = [ "gpui", "gpui-native-theme", diff --git a/Cargo.toml b/Cargo.toml index 623e1af..1b1a78c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ gpui = { git = "https://github.com/zed-industries/zed", rev = "f8cfc7ed9e57503de gpui_platform = { git = "https://github.com/zed-industries/zed", rev = "f8cfc7ed9e57503def9479138894f3139f5400cc", features = ["font-kit"] } reqwest_client = { git = "https://github.com/zed-industries/zed", rev = "f8cfc7ed9e57503def9479138894f3139f5400cc" } -gpui-native-kit = { git = "https://git.reya.info/reya/gpui-native-kit", rev = "c3e3c37731e389d858712369e47eec9c205cdfbe", features = ["layout", "editor"] } +gpui-native-kit = { git = "https://git.reya.info/reya/gpui-native-kit", rev = "f6ba9c0d4737ade726ad57ef5a075606bf045164", features = ["layout", "editor"] } settings = { path = "crates/settings" } signed_app = { path = "crates/signed_app" } diff --git a/crates/signed_app/src/app/mod.rs b/crates/signed_app/src/app/mod.rs index 0515787..d9731f3 100644 --- a/crates/signed_app/src/app/mod.rs +++ b/crates/signed_app/src/app/mod.rs @@ -1,56 +1,46 @@ pub mod helpers; mod placeholder; +mod sign_in; -use gpui::prelude::FluentBuilder as _; use gpui::{ - AppContext as _, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _, - Render, Styled as _, Subscription, Window, div, + AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render, Styled as _, + Subscription, Window, div, }; -use gpui_native_kit::common::h_flex; use gpui_native_kit::icons::IconRole; -use gpui_native_kit::layout::dock::{Dock, DockState}; -use gpui_native_kit::layout::shell::{LayoutState, Shell, SidebarToggles}; -use gpui_native_kit::layout::window_controls::{TRAFFIC_LIGHT_PAD, titlebar_strip}; +use gpui_native_kit::layout::panel::PanelRow; +use gpui_native_kit::layout::shell::Shell; +use gpui_native_kit::layout::titlebar::Titlebar; use gpui_native_kit::theme::ActiveTheme as _; -use gpui_native_kit::toast::Toast; +use gpui_native_kit::toast::{Toast, Toasts}; use helpers::apply_appearance; use settings::SettingsStore; use signed_state::{Backend, BackendEvent}; use crate::app::placeholder::PlaceholderView; +use crate::app::sign_in::SignedOutView; use crate::identity; use crate::shared::dialogs::DialogHost; -use crate::sidebar::SidebarView; +use crate::titlebar::TitlebarView; +use crate::workspace::Workspace; pub struct AppRoot { - layout: Entity, - dock: Entity, - sidebar: Entity, + workspace: Entity, + titlebar: Entity, + toasts: Entity, + sign_in: Entity, + empty: Entity, dialogs: Entity, _subscriptions: Vec, } impl AppRoot { pub fn new(window: &mut Window, cx: &mut Context) -> Self { - let dock = DockState::new(cx); - let layout = LayoutState::new(cx); + let workspace = cx.new(|_| Workspace::new()); + let titlebar = cx.new(|cx| TitlebarView::new(workspace.downgrade(), cx)); + let toasts = cx.new(|_| Toasts::default()); + let sign_in = cx.new(|_| SignedOutView::new()); + let empty = cx.new(|_| PlaceholderView::new("Select a repository")); - layout.update(cx, |layout, cx| { - layout.set_sidebar_toggles(SidebarToggles::Hidden, cx); - }); - - dock.update(cx, |dock, cx| { - dock.register_panel("welcome", |_, cx| { - cx.new(|_| PlaceholderView::new("Welcome")) - }); - dock.register_panel("profile", |_, cx| { - cx.new(|_| PlaceholderView::new("Profile")) - }); - dock.register_panel("relays", |_, cx| cx.new(|_| PlaceholderView::new("Relays"))); - dock.open_panel("welcome", window, cx); - }); - - let sidebar = cx.new(|cx| SidebarView::new(dock.downgrade(), cx)); let dialogs = cx.new(DialogHost::new); DialogHost::set_global(dialogs.clone(), cx); @@ -63,10 +53,14 @@ impl AppRoot { cx.subscribe(&backend, |this, _backend, event, cx| match event { BackendEvent::PassphraseRequired => identity::helpers::open_passphrase(cx), BackendEvent::Error(message) => { - this.layout.update(cx, |layout, cx| { - layout.push_toast(Toast::new(message.clone()).icon(IconRole::Warning), cx); + this.toasts.update(cx, |toasts, cx| { + toasts.push(Toast::new(message.clone()).icon(IconRole::Warning), cx); }); } + BackendEvent::SignerChanged => { + this.workspace + .update(cx, |workspace, cx| workspace.clear(cx)); + } _ => {} }), ); @@ -76,22 +70,6 @@ impl AppRoot { apply_appearance(&settings, cx); })); - subscriptions.push(cx.observe(&dock, |this, dock, cx| { - let Some(panel) = dock.read(cx).active_panel() else { - return; - }; - - if !panel.starts_with("repo:") && !panel.starts_with("repo-local:") { - return; - } - - this.layout.update(cx, |layout, cx| { - if !layout.is_right_sidebar_visible() { - layout.set_right_sidebar_visible(true, cx); - } - }); - })); - window.defer(cx, move |_window, cx| { if backend.read(cx).passphrase_required() { identity::helpers::open_passphrase(cx); @@ -99,9 +77,11 @@ impl AppRoot { }); Self { - layout, - dock, - sidebar, + workspace, + titlebar, + toasts, + sign_in, + empty, dialogs, _subscriptions: subscriptions, } @@ -109,60 +89,47 @@ impl AppRoot { } impl Render for AppRoot { - fn render(&mut self, window: &mut Window, cx: &mut Context) -> impl IntoElement { - let theme = *cx.theme(); - let layout = self.layout.read(cx); - let left_visible = layout.is_left_sidebar_visible(); - let sidebar_width = layout.left_sidebar_width(); + fn render(&mut self, _window: &mut Window, cx: &mut Context) -> impl IntoElement { + let is_signed_in = Backend::global(cx).read(cx).current_user().is_some(); + let titlebar_view = self.titlebar.read(cx); - let titlebar = if left_visible { - self.sidebar.read(cx).render_titlebar(cx) + let mut titlebar = Titlebar::new("signed-titlebar"); + if let Some(menu) = titlebar_view.render_user_menu(cx) { + titlebar = titlebar.child(menu); + } + if let Some(tabs) = titlebar_view.render_tabs(cx) { + titlebar = titlebar.tab_bar(tabs); + } + if let Some(actions) = titlebar_view.render_actions(cx) { + titlebar = titlebar.suffix(actions); + } + + let workspace = self.workspace.read(cx); + let mut row = PanelRow::new("signed-panel"); + if is_signed_in { + match workspace.active_main() { + Some(main) => row = row.main(main), + None => row = row.main(self.empty.clone()), + } + if workspace.has_details() { + row = row.split(self.workspace.clone()); + } } else { - None - }; - - let titlebar = titlebar.map(|row| { - let strip = h_flex() - .id("signed-sidebar-titlebar") - .size_full() - .when(cfg!(target_os = "macos"), |strip| { - strip.pl(TRAFFIC_LIGHT_PAD) - }) - .when(cfg!(not(target_os = "macos")), |strip| strip.pl_2()) - .pr_2(); - - titlebar_strip(strip, "signed-sidebar-titlebar-drag", window, cx) - .child(row) - .into_any_element() - }); + row = row.main(self.sign_in.clone()); + } div() .relative() .size_full() .font_family(".SystemUIFont") - .text_color(theme.colors.foreground) + .text_color(cx.theme().colors.foreground) .child( - Shell::new("signed-shell", self.layout.clone()) - .left_sidebar(self.sidebar.read(cx).build(cx)) - .right_sidebar(div()) - .center( - Dock::new("signed-dock", self.dock.clone()) - .window_controls(true) - .traffic_light_pad(!left_visible) - .sidebar_toggles(self.layout.clone()), - ), + Shell::new("signed-shell") + .titlebar(titlebar) + .panel(row) + .transparent(true) + .toasts(self.toasts.clone()), ) - .when_some(titlebar, |root, titlebar| { - root.child( - div() - .absolute() - .top_0() - .left_0() - .w(sidebar_width) - .h(theme.titlebar_height) - .child(titlebar), - ) - }) .child(self.dialogs.clone()) } } diff --git a/crates/signed_app/src/app/placeholder.rs b/crates/signed_app/src/app/placeholder.rs index d37130b..11fd817 100644 --- a/crates/signed_app/src/app/placeholder.rs +++ b/crates/signed_app/src/app/placeholder.rs @@ -1,8 +1,8 @@ use gpui::{ - App, Context, IntoElement, ParentElement as _, Render, SharedString, Styled as _, Window, div, + Context, IntoElement, ParentElement as _, Render, SharedString, Styled as _, Window, div, }; use gpui_native_kit::empty_state::EmptyState; -use gpui_native_kit::layout::dock::Panel; +use gpui_native_kit::layout::panel::Panel; /// A tab that stands in for a screen that is not ported yet. pub struct PlaceholderView { @@ -17,11 +17,7 @@ impl PlaceholderView { } } -impl Panel for PlaceholderView { - fn title(&self, _cx: &App) -> Option { - Some(self.title.clone()) - } -} +impl Panel for PlaceholderView {} impl Render for PlaceholderView { fn render(&mut self, _window: &mut Window, _cx: &mut Context) -> impl IntoElement { diff --git a/crates/signed_app/src/app/sign_in.rs b/crates/signed_app/src/app/sign_in.rs new file mode 100644 index 0000000..175c0b8 --- /dev/null +++ b/crates/signed_app/src/app/sign_in.rs @@ -0,0 +1,76 @@ +use std::time::{SystemTime, UNIX_EPOCH}; + +use gpui::{ + Context, IntoElement, ObjectFit, ParentElement as _, Render, SharedString, Styled as _, + StyledImage as _, Window, div, img, +}; +use gpui_native_kit::button::{Button, ButtonVariant}; +use gpui_native_kit::common::v_flex; +use gpui_native_kit::layout::panel::Panel; + +use crate::identity; + +pub struct SignedOutView { + banner: SharedString, +} + +impl SignedOutView { + pub fn new() -> Self { + Self { + banner: pick_banner(), + } + } +} + +impl Panel for SignedOutView {} + +impl Render for SignedOutView { + fn render(&mut self, _window: &mut Window, _cx: &mut Context) -> impl IntoElement { + v_flex() + .size_full() + .relative() + .child( + div().absolute().inset_0().child( + img(self.banner.clone()) + .size_full() + .object_fit(ObjectFit::Cover), + ), + ) + .child( + v_flex() + .size_full() + .justify_end() + .p_4() + .gap_4() + .child(img("backgrounds/headline.png").max_w_48()) + .child( + v_flex() + .gap_1() + .w_full() + .child(Button::new("onboarding").label("Join now").on_click( + |_, _, cx| { + identity::helpers::open_onboarding(cx); + }, + )) + .child( + Button::new("import") + .label("Import identity") + .variant(ButtonVariant::Secondary) + .on_click(|_, _, cx| { + identity::helpers::open_import(cx); + }), + ), + ), + ) + } +} + +fn pick_banner() -> SharedString { + let num = SystemTime::now() + .duration_since(UNIX_EPOCH) + .map(|duration| duration.subsec_nanos()) + .unwrap_or(1) + % 3 + + 1; + format!("backgrounds/banner{num}.jpg").into() +} diff --git a/crates/signed_app/src/explore/helpers.rs b/crates/signed_app/src/explore/helpers.rs index ccdc33d..8044d13 100644 --- a/crates/signed_app/src/explore/helpers.rs +++ b/crates/signed_app/src/explore/helpers.rs @@ -7,7 +7,6 @@ use gpui::{ use gpui_native_kit::avatar::Avatar; use gpui_native_kit::common::{Sizable as _, h_flex, v_flex}; use gpui_native_kit::icons::Icon; -use gpui_native_kit::layout::dock::DockState; use gpui_native_kit::theme::{ActiveTheme as _, TextRole, Typeset as _}; use metadata::ProfileDirectory; use signed_core::Announcement; @@ -15,6 +14,7 @@ use signed_state::{RepoListStore, Timestamp}; use utils::relative_time; use crate::repo::actions::open_repo_panel; +use crate::workspace::Workspace; const RECENT_COUNT: usize = 10; @@ -64,12 +64,12 @@ pub(super) fn render_card( last_activity: Option, announcements: &[Announcement], directory: &Entity, - dock: &WeakEntity, + workspace: &WeakEntity, cx: &mut gpui::App, ) -> AnyElement { let owner = directory.read(cx).profile(&announcement.owner, cx); let owner_name = owner.name(); - let dock = dock.clone(); + let workspace = workspace.clone(); let announcement = announcement.clone(); let name = announcement @@ -184,7 +184,13 @@ pub(super) fn render_card( ), ) .on_click(move |_, window, cx| { - open_repo_panel(&dock, &announcement.addr(), Some(&announcement), window, cx); + open_repo_panel( + &workspace, + &announcement.addr(), + Some(&announcement), + window, + cx, + ); }) .into_any_element() } diff --git a/crates/signed_app/src/explore/mod.rs b/crates/signed_app/src/explore/mod.rs index d472a1b..da568e7 100644 --- a/crates/signed_app/src/explore/mod.rs +++ b/crates/signed_app/src/explore/mod.rs @@ -3,15 +3,15 @@ mod helpers; use assets::CustomIconName; use gpui::prelude::FluentBuilder as _; use gpui::{ - AnyElement, App, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _, - Render, SharedString, Styled as _, Subscription, UniformListScrollHandle, WeakEntity, Window, - div, px, uniform_list, + AnyElement, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _, Render, + SharedString, Styled as _, Subscription, UniformListScrollHandle, WeakEntity, Window, div, px, + uniform_list, }; use gpui_native_kit::common::{h_flex, v_flex}; use gpui_native_kit::empty_state::EmptyState; use gpui_native_kit::icons::{Icon, IconRole}; use gpui_native_kit::input::{Input, InputState, InputStateEvent}; -use gpui_native_kit::layout::dock::{DockState, Panel}; +use gpui_native_kit::layout::panel::Panel; use gpui_native_kit::scrollbar::Scrollbar; use gpui_native_kit::segmented::{Segmented, SegmentedOption}; use gpui_native_kit::theme::{ActiveTheme as _, TextRole, Typeset as _}; @@ -20,12 +20,14 @@ use metadata::ProfileDirectory; use nostr::prelude::PublicKey; use signed_state::RepoListStore; +use crate::workspace::Workspace; + const COLUMNS: usize = 2; const CARD_HEIGHT: f32 = 40. + 64. + 48. + 2. + 6.; pub struct ExploreView { store: Entity, - dock: WeakEntity, + workspace: WeakEntity, scroll_handle: UniformListScrollHandle, filter: RepoFilter, /// Indices matching [`Self::filter`] into the store's `announcements`. @@ -38,7 +40,7 @@ pub struct ExploreView { } impl ExploreView { - pub fn new(dock: WeakEntity, cx: &mut Context) -> Self { + pub fn new(workspace: WeakEntity, cx: &mut Context) -> Self { let store = RepoListStore::global(cx); let directory = ProfileDirectory::new(cx); @@ -63,7 +65,7 @@ impl ExploreView { Self { store, - dock, + workspace, scroll_handle: UniformListScrollHandle::new(), filter: RepoFilter::default(), visible: Vec::new(), @@ -146,20 +148,7 @@ impl ExploreView { } } -impl Panel for ExploreView { - fn title(&self, _cx: &App) -> Option { - Some(SharedString::from("Explore")) - } - - fn lead(&self, cx: &App) -> Option { - Some( - Icon::named(CustomIconName::Globe) - .small() - .color(cx.theme().colors.muted_foreground) - .into_any_element(), - ) - } -} +impl Panel for ExploreView {} impl Render for ExploreView { fn render(&mut self, _window: &mut Window, cx: &mut Context) -> impl IntoElement { @@ -169,7 +158,7 @@ impl Render for ExploreView { let count = self.visible.len(); let visible = self.visible.clone(); let directory = self.directory.clone(); - let dock = self.dock.clone(); + let workspace = self.workspace.clone(); let has_repos = count > 0; let rows = visible.len().div_ceil(COLUMNS); @@ -207,7 +196,7 @@ impl Render for ExploreView { activity, &announcements, &directory, - &dock, + &workspace, cx, )); } diff --git a/crates/signed_app/src/inbox/mod.rs b/crates/signed_app/src/inbox/mod.rs index d87f3c5..7231739 100644 --- a/crates/signed_app/src/inbox/mod.rs +++ b/crates/signed_app/src/inbox/mod.rs @@ -2,7 +2,6 @@ use std::collections::HashMap; use std::sync::Arc; use anyhow::Error; -use assets::CustomIconName; use gpui::{ AnyElement, App, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render, SharedString, StatefulInteractiveElement as _, Styled as _, Subscription, Task, WeakEntity, @@ -11,9 +10,9 @@ use gpui::{ use gpui_native_kit::button::Button; use gpui_native_kit::common::{h_flex, v_flex}; use gpui_native_kit::icons::{Icon, IconRole}; -use gpui_native_kit::layout::dock::{DockState, Panel}; +use gpui_native_kit::layout::panel::Panel; use gpui_native_kit::scroll_area::ScrollArea; -use gpui_native_kit::theme::{ActiveTheme as _, TextRole, Typeset as _}; +use gpui_native_kit::theme::{TextRole, Typeset as _}; use metadata::ProfileDirectory; use nostr::prelude::{Event, EventId, Kind, PublicKey, Timestamp}; use signed_core::{InboxItem, InboxReadState, RepoAddr}; @@ -24,6 +23,7 @@ mod helpers; use helpers::{empty_section_row, empty_state, repo_header, thread}; use crate::repo::actions::{RepoItem, open_repo_item}; +use crate::workspace::Workspace; const MAX_SUB_ACTIVITIES: usize = 5; @@ -42,7 +42,7 @@ struct InboxSection { } pub struct InboxView { - dock: WeakEntity, + workspace: WeakEntity, threads: Arc>, sections: Arc>, rows: Arc>, @@ -55,7 +55,7 @@ pub struct InboxView { } impl InboxView { - pub fn new(dock: WeakEntity, cx: &mut Context) -> Self { + pub fn new(workspace: WeakEntity, cx: &mut Context) -> Self { let backend = Backend::global(cx); let inbox = backend.read(cx).inbox(); @@ -84,7 +84,7 @@ impl InboxView { }); Self { - dock, + workspace, threads: Arc::new(Vec::new()), sections: Arc::new(Vec::new()), rows: Arc::new(Vec::new()), @@ -328,7 +328,7 @@ impl InboxView { Some(Kind::GitPatch) => RepoItem::Patch, _ => return, }; - open_repo_item(&self.dock, &address, None, item, window, cx); + open_repo_item(&self.workspace, &address, None, item, window, cx); } fn render_entry(&self, ix: usize, cx: &mut Context) -> AnyElement { @@ -392,20 +392,7 @@ impl InboxView { } } -impl Panel for InboxView { - fn title(&self, _cx: &App) -> Option { - Some(SharedString::from("Inbox")) - } - - fn lead(&self, cx: &App) -> Option { - Some( - Icon::named(CustomIconName::Inbox) - .size(gpui::px(14.)) - .color(cx.theme().colors.muted_foreground) - .into_any_element(), - ) - } -} +impl Panel for InboxView {} impl Render for InboxView { fn render(&mut self, _window: &mut Window, cx: &mut Context) -> impl IntoElement { diff --git a/crates/signed_app/src/issues/detail.rs b/crates/signed_app/src/issues/detail.rs index af0431a..383a526 100644 --- a/crates/signed_app/src/issues/detail.rs +++ b/crates/signed_app/src/issues/detail.rs @@ -1,12 +1,12 @@ use gpui::{ - AnyElement, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _, Render, + Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _, Render, ScrollHandle, SharedString, Styled as _, Subscription, Window, div, }; use gpui_native_kit::avatar::Avatar; use gpui_native_kit::common::{Sizable as _, h_flex, v_flex}; use gpui_native_kit::empty_state::EmptyState; use gpui_native_kit::input::InputState; -use gpui_native_kit::layout::dock::Panel; +use gpui_native_kit::layout::panel::Panel; use gpui_native_kit::scroll_area::ScrollArea; use gpui_native_kit::theme::{ActiveTheme as _, TextRole, Typeset as _}; use metadata::ProfileDirectory; @@ -16,7 +16,7 @@ use signed_state::RepoStore; use utils::relative_time; use crate::issues::helpers::{comment_form, comments_section, issue_roots, sidebar_section}; -use crate::shared::widgets::{repo_tab_avatar, status_badge}; +use crate::shared::widgets::status_badge; pub struct IssueDetailView { store: Entity, @@ -80,27 +80,7 @@ impl IssueDetailView { } } -impl Panel for IssueDetailView { - fn title(&self, cx: &gpui::App) -> Option { - let short_id = self - .store - .read(cx) - .issues - .iter() - .find(|issue| issue.id == self.issue_id) - .map(|issue| { - let hex = issue.id.to_hex(); - SharedString::from(&hex[..8]) - }) - .unwrap_or_else(|| SharedString::from("Issue")); - - Some(short_id) - } - - fn lead(&self, cx: &gpui::App) -> Option { - Some(repo_tab_avatar(self.store.read(cx), &self.directory, cx)) - } -} +impl Panel for IssueDetailView {} impl Render for IssueDetailView { fn render(&mut self, _window: &mut Window, cx: &mut Context) -> impl IntoElement { diff --git a/crates/signed_app/src/issues/mod.rs b/crates/signed_app/src/issues/mod.rs index 4bd7f53..748e789 100644 --- a/crates/signed_app/src/issues/mod.rs +++ b/crates/signed_app/src/issues/mod.rs @@ -1,7 +1,7 @@ use assets::CustomIconName; use gpui::prelude::FluentBuilder as _; use gpui::{ - AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement, + AnyElement, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _, Render, SharedString, StatefulInteractiveElement as _, Styled as _, Subscription, UniformListScrollHandle, WeakEntity, Window, div, px, uniform_list, }; @@ -10,7 +10,7 @@ use gpui_native_kit::button::Button; use gpui_native_kit::common::{Sizable as _, h_flex, v_flex}; use gpui_native_kit::empty_state::EmptyState; use gpui_native_kit::icons::Icon; -use gpui_native_kit::layout::dock::{DockState, Panel}; +use gpui_native_kit::layout::panel::Panel; use gpui_native_kit::scrollbar::Scrollbar; use gpui_native_kit::segmented::{Segmented, SegmentedOption}; use gpui_native_kit::theme::{ActiveTheme as _, TextRole, Typeset as _}; @@ -24,7 +24,8 @@ use self::detail::IssueDetailView; use helpers::{IssueFilter, StatusCounts, filter_by_status}; use crate::shared::panels; -use crate::shared::widgets::{repo_tab_avatar, status_badge}; +use crate::shared::widgets::status_badge; +use crate::workspace::Workspace; pub mod detail; pub(crate) mod helpers; @@ -33,9 +34,8 @@ pub mod new_issue; const ISSUE_ROW_HEIGHT: f32 = 73.; pub struct IssuesView { - dock: WeakEntity, + workspace: WeakEntity, store: Entity, - repo_name: SharedString, filter: IssueFilter, visible_issues: Vec, counts: StatusCounts, @@ -49,12 +49,10 @@ pub struct IssuesView { impl IssuesView { pub fn new( - dock: WeakEntity, + workspace: WeakEntity, store: Entity, cx: &mut Context, ) -> Self { - let repo_name = store.read(cx).name(); - let subscription = cx.observe(&store, |this, _store, cx| { this.rebuild(cx); }); @@ -64,9 +62,8 @@ impl IssuesView { }); Self { - dock, + workspace, store, - repo_name, filter: IssueFilter::Open, visible_issues: Vec::new(), counts: StatusCounts::default(), @@ -166,15 +163,7 @@ impl IssuesView { } } -impl Panel for IssuesView { - fn title(&self, _cx: &App) -> Option { - Some(SharedString::from(format!("{}/issues", self.repo_name))) - } - - fn lead(&self, cx: &App) -> Option { - Some(repo_tab_avatar(self.store.read(cx), &self.directory, cx)) - } -} +impl Panel for IssuesView {} impl Render for IssuesView { fn render(&mut self, _window: &mut Window, cx: &mut Context) -> impl IntoElement { @@ -183,7 +172,7 @@ impl Render for IssuesView { let visible_issues = self.visible_issues.clone(); let directory = self.directory.clone(); let store = self.store.clone(); - let dock = self.dock.clone(); + let workspace = self.workspace.clone(); v_flex() .size_full() @@ -208,7 +197,7 @@ impl Render for IssuesView { let age = relative_time(issue.created_at); let status = store.read(cx).status_of(issue); let issue_id = issue.id; - let dock = dock.clone(); + let workspace = workspace.clone(); let store = store.clone(); h_flex() @@ -223,10 +212,15 @@ impl Render for IssuesView { .on_click(move |_, window, cx| { let id = SharedString::from(format!("issue:{issue_id}")); + let hex = issue_id.to_hex(); + let short = hex.get(..8).unwrap_or(&hex); + let label = + SharedString::from(format!("Issue {short}")); let store = store.clone(); - panels::open( - &dock, + panels::open_detail( + &workspace, id, + label, move |_, cx| { cx.new(|cx| { IssueDetailView::new( diff --git a/crates/signed_app/src/lib.rs b/crates/signed_app/src/lib.rs index c567644..a14673a 100644 --- a/crates/signed_app/src/lib.rs +++ b/crates/signed_app/src/lib.rs @@ -1,13 +1,16 @@ mod app; +#[allow(dead_code)] // temporarily unlinked while the shell migrates mod explore; mod identity; +#[allow(dead_code)] // temporarily unlinked while the shell migrates mod inbox; mod issues; mod pull_requests; mod repo; mod settings; mod shared; -mod sidebar; +mod titlebar; +mod workspace; pub use app::AppRoot; pub use app::helpers::{apply_appearance, apply_appearance_mode}; diff --git a/crates/signed_app/src/pull_requests/detail.rs b/crates/signed_app/src/pull_requests/detail.rs index 7fe7d1a..ef77027 100644 --- a/crates/signed_app/src/pull_requests/detail.rs +++ b/crates/signed_app/src/pull_requests/detail.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use assets::CustomIconName; use gpui::prelude::FluentBuilder as _; use gpui::{ - AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement, + AnyElement, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _, Render, SharedString, Styled as _, Subscription, UniformListScrollHandle, WeakEntity, Window, div, uniform_list, }; @@ -14,7 +14,7 @@ use gpui_native_kit::common::{Sizable as _, h_flex, v_flex}; use gpui_native_kit::data::tabs::{Tab, Tabs}; use gpui_native_kit::icons::Icon; use gpui_native_kit::input::InputState; -use gpui_native_kit::layout::dock::{DockState, Panel}; +use gpui_native_kit::layout::panel::Panel; use gpui_native_kit::scroll_area::ScrollArea; use gpui_native_kit::scrollbar::Scrollbar; use gpui_native_kit::spinner::Spinner; @@ -30,7 +30,8 @@ use super::dialogs; use crate::issues::helpers::{comment_form, comments_section, pr_roots, sidebar_section}; use crate::repo::commit_diff::{CommitDiffView, DiffPane}; use crate::repo::helpers::commit_row; -use crate::shared::widgets::{empty_state, repo_tab_avatar, status_badge}; +use crate::shared::widgets::{empty_state, status_badge}; +use crate::workspace::Workspace; const NOT_FOUND: &str = "Pull request not found"; @@ -46,11 +47,10 @@ struct PrBinding { } pub struct PullRequestDetailView { - dock: WeakEntity, + workspace: WeakEntity, store: Entity, pr_id: EventId, comment_input: Entity, - repo_name: SharedString, worktree: Option, description: SharedString, current_commit: Option, @@ -69,7 +69,7 @@ pub struct PullRequestDetailView { impl PullRequestDetailView { pub fn new( - dock: WeakEntity, + workspace: WeakEntity, store: Entity, pr_id: EventId, _window: &mut Window, @@ -78,7 +78,6 @@ impl PullRequestDetailView { let pane = cx.new(DiffPane::new); let comment_input = InputState::builder().multiline().build(cx); let weak = cx.entity().downgrade(); - let repo_name = store.read(cx).name(); let subscription = cx.observe(&store, |this, _store, cx| { this.sync(cx); @@ -89,11 +88,10 @@ impl PullRequestDetailView { }); Self { - dock, + workspace, store, pr_id, comment_input, - repo_name, worktree: None, description: SharedString::default(), current_commit: None, @@ -290,24 +288,16 @@ impl PullRequestDetailView { Some(addr) => SharedString::from(format!("commit:{addr}:{commit_id}")), None => SharedString::from(format!("commit:{}:{commit_id}", worktree.display())), }; - let dock = self.dock.clone(); - let store = self.store.clone(); - let repo_name = self.repo_name.clone(); + let workspace = self.workspace.clone(); + let short = commit_id.get(..8).unwrap_or(commit_id); + let label = SharedString::from(format!("Commit {short}")); let commit_id = commit_id.to_owned(); - crate::shared::panels::open( - &dock, + crate::shared::panels::open_detail( + &workspace, id, + label, move |window, cx| { - cx.new(|cx| { - CommitDiffView::new( - store.clone(), - worktree.clone(), - repo_name.clone(), - commit_id.clone(), - window, - cx, - ) - }) + cx.new(|cx| CommitDiffView::new(worktree.clone(), commit_id.clone(), window, cx)) }, window, cx, @@ -590,16 +580,7 @@ impl PullRequestDetailView { } } -impl Panel for PullRequestDetailView { - fn title(&self, _cx: &App) -> Option { - let hex = self.pr_id.to_hex(); - Some(super::helpers::pr_label(&self.repo_name, &hex[..8])) - } - - fn lead(&self, cx: &App) -> Option { - Some(repo_tab_avatar(self.store.read(cx), &self.directory, cx)) - } -} +impl Panel for PullRequestDetailView {} impl Render for PullRequestDetailView { fn render(&mut self, _window: &mut Window, cx: &mut Context) -> impl IntoElement { diff --git a/crates/signed_app/src/pull_requests/helpers.rs b/crates/signed_app/src/pull_requests/helpers.rs index 8c69c59..1e52efb 100644 --- a/crates/signed_app/src/pull_requests/helpers.rs +++ b/crates/signed_app/src/pull_requests/helpers.rs @@ -55,14 +55,6 @@ impl ForkCompare { } } -pub fn pr_label(repo_name: &SharedString, pr_id: &str) -> SharedString { - if repo_name.is_empty() { - SharedString::from(pr_id) - } else { - SharedString::from(format!("{repo_name}/{pr_id}")) - } -} - pub fn fork_display_name(announcement: &Announcement) -> SharedString { announcement .name diff --git a/crates/signed_app/src/pull_requests/mod.rs b/crates/signed_app/src/pull_requests/mod.rs index 9753693..28bcb5d 100644 --- a/crates/signed_app/src/pull_requests/mod.rs +++ b/crates/signed_app/src/pull_requests/mod.rs @@ -1,7 +1,7 @@ use assets::CustomIconName; use gpui::prelude::FluentBuilder as _; use gpui::{ - AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement, + AnyElement, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _, Render, SharedString, StatefulInteractiveElement as _, Styled as _, Subscription, UniformListScrollHandle, WeakEntity, Window, div, px, uniform_list, }; @@ -10,7 +10,7 @@ use gpui_native_kit::avatar::Avatar; use gpui_native_kit::common::{Sizable as _, h_flex, v_flex}; use gpui_native_kit::dropdown_menu::DropdownMenu; use gpui_native_kit::icons::Icon; -use gpui_native_kit::layout::dock::{DockState, Panel}; +use gpui_native_kit::layout::panel::Panel; use gpui_native_kit::menu::MenuItem; use gpui_native_kit::scrollbar::Scrollbar; use gpui_native_kit::segmented::{Segmented, SegmentedOption}; @@ -33,14 +33,14 @@ pub use new::NewPullRequestView; pub use send_patch::SendPatchView; use crate::issues::helpers::{StatusCounts, filter_by_status}; -use crate::shared::widgets::{empty_state, repo_tab_avatar, status_badge}; +use crate::shared::widgets::{empty_state, status_badge}; +use crate::workspace::Workspace; const ROW_HEIGHT: f32 = 73.; pub struct PullRequestsView { - dock: WeakEntity, + workspace: WeakEntity, store: Entity, - repo_name: SharedString, filter: PullRequestFilter, visible_prs: Vec, counts: StatusCounts, @@ -53,12 +53,11 @@ pub struct PullRequestsView { impl PullRequestsView { pub fn new( - dock: WeakEntity, + workspace: WeakEntity, store: Entity, cx: &mut Context, ) -> Self { let weak = cx.entity().downgrade(); - let repo_name = store.read(cx).name(); let subscription = cx.observe(&store, |this, _store, cx| { this.rebuild(cx); }); @@ -70,9 +69,8 @@ impl PullRequestsView { }); Self { - dock, + workspace, store, - repo_name, filter: PullRequestFilter::Open, visible_prs: Vec::new(), counts: StatusCounts::default(), @@ -136,17 +134,18 @@ impl PullRequestsView { }; let id = SharedString::from(format!("new-pr:{addr}")); - let dock = self.dock.clone(); - let dock_for_build = dock.clone(); + let workspace = self.workspace.clone(); + let workspace_for_build = workspace.clone(); let store = self.store.clone(); - crate::shared::panels::open( - &dock, + crate::shared::panels::open_detail( + &workspace, id.clone(), + "New pull request", move |window, cx| { cx.new(|cx| { NewPullRequestView::new( - dock_for_build.clone(), + workspace_for_build.clone(), id.clone(), store.clone(), window, @@ -165,17 +164,18 @@ impl PullRequestsView { }; let id = SharedString::from(format!("send-patch:{addr}")); - let dock = self.dock.clone(); - let dock_for_build = dock.clone(); + let workspace = self.workspace.clone(); + let workspace_for_build = workspace.clone(); let store = self.store.clone(); - crate::shared::panels::open( - &dock, + crate::shared::panels::open_detail( + &workspace, id.clone(), + "Send patch", move |window, cx| { cx.new(|cx| { SendPatchView::new( - dock_for_build.clone(), + workspace_for_build.clone(), id.clone(), store.clone(), window, @@ -275,15 +275,7 @@ impl PullRequestsView { } } -impl Panel for PullRequestsView { - fn title(&self, _cx: &App) -> Option { - Some(SharedString::from(format!("{}/pulls", self.repo_name))) - } - - fn lead(&self, cx: &App) -> Option { - Some(repo_tab_avatar(self.store.read(cx), &self.directory, cx)) - } -} +impl Panel for PullRequestsView {} impl Render for PullRequestsView { fn render(&mut self, _window: &mut Window, cx: &mut Context) -> impl IntoElement { @@ -292,7 +284,7 @@ impl Render for PullRequestsView { let visible = self.visible_prs.clone(); let directory = self.directory.clone(); let store = self.store.clone(); - let dock = self.dock.clone(); + let workspace = self.workspace.clone(); let (last_error, last_warning) = { let store = self.store.read(cx); @@ -347,7 +339,7 @@ impl Render for PullRequestsView { let status = store.read(cx).status_of(pr); let profile = directory.read(cx).profile(&pr.pubkey, cx); let author = profile.name(); - let dock = dock.clone(); + let workspace = workspace.clone(); let store = store.clone(); h_flex() @@ -361,15 +353,20 @@ impl Render for PullRequestsView { .hover(|this| this.bg(cx.theme().colors.muted_hover)) .on_click(move |_, window, cx| { let id = SharedString::from(format!("pr:{pr_id}")); - let dock_for_build = dock.clone(); + let hex = pr_id.to_hex(); + let short = hex.get(..8).unwrap_or(&hex); + let label = + SharedString::from(format!("PR {short}")); + let workspace_for_build = workspace.clone(); let store = store.clone(); - crate::shared::panels::open( - &dock, + crate::shared::panels::open_detail( + &workspace, id, + label, move |window, cx| { cx.new(|cx| { PullRequestDetailView::new( - dock_for_build.clone(), + workspace_for_build.clone(), store.clone(), pr_id, window, diff --git a/crates/signed_app/src/pull_requests/new.rs b/crates/signed_app/src/pull_requests/new.rs index fdd6a01..699877b 100644 --- a/crates/signed_app/src/pull_requests/new.rs +++ b/crates/signed_app/src/pull_requests/new.rs @@ -13,26 +13,25 @@ use gpui_native_kit::common::{h_flex, v_flex}; use gpui_native_kit::data::tabs::{Tab, Tabs}; use gpui_native_kit::icons::{Icon, IconRole}; use gpui_native_kit::input::{Input, InputState}; -use gpui_native_kit::layout::dock::{DockState, Panel}; +use gpui_native_kit::layout::panel::Panel; use gpui_native_kit::menu::Menu; use gpui_native_kit::scrollbar::Scrollbar; use gpui_native_kit::spinner::Spinner; use gpui_native_kit::theme::{ActiveTheme as _, TextRole, Typeset as _}; -use metadata::ProfileDirectory; use signed_state::{CheckoutsStore, RepoStore}; use super::helpers::{ForkCompare, fork_display_name, truncate_label}; use crate::repo::commit_diff::{CommitDiffView, DiffPane}; use crate::repo::helpers::commit_row; use crate::shared::widgets::empty_state; +use crate::workspace::Workspace; mod source; pub struct NewPullRequestView { - dock: WeakEntity, + workspace: WeakEntity, panel_id: SharedString, pub(super) store: Entity, - repo_name: SharedString, pub(super) repo_path: Option, pub(super) branches: Vec, pub(super) fork: Option, @@ -53,21 +52,18 @@ pub struct NewPullRequestView { pub(super) pane: Entity, scroll_handle: UniformListScrollHandle, pub(super) tasks: Vec>>, - directory: Entity, source_open: bool, _subscriptions: Vec, } impl NewPullRequestView { pub fn new( - dock: WeakEntity, + workspace: WeakEntity, panel_id: SharedString, store: Entity, window: &mut Window, cx: &mut Context, ) -> Self { - let directory = ProfileDirectory::new(cx); - let repo_name = store.read(cx).name(); let pane = cx.new(DiffPane::new); let weak = cx.entity().downgrade(); @@ -116,10 +112,6 @@ impl NewPullRequestView { ) }); - if let Some(owner) = store.read(cx).announcement.as_ref().map(|a| a.owner) { - directory.update(cx, |directory, cx| directory.track([owner], cx)); - } - window.defer(cx, move |window, cx| { crate::shared::log_dropped(weak.update(cx, |this, cx| { let Some(addr) = this.store.read(cx).addr().cloned() else { @@ -140,10 +132,9 @@ impl NewPullRequestView { }); Self { - dock, + workspace, panel_id, store, - repo_name, repo_path: None, branches: Vec::new(), fork: None, @@ -164,7 +155,6 @@ impl NewPullRequestView { pane, scroll_handle: UniformListScrollHandle::new(), tasks: Vec::new(), - directory, source_open: false, _subscriptions: Vec::new(), } @@ -185,7 +175,7 @@ impl NewPullRequestView { let branch_name = self.compare.to_string(); let compare_ref = self.compare_ref(); let store = self.store.clone(); - let dock = self.dock.clone(); + let workspace = self.workspace.clone(); let panel_id = self.panel_id.clone(); self.submitting = true; @@ -216,7 +206,9 @@ impl NewPullRequestView { this.update(cx, |this, _cx| { this.submitting = false; })?; - crate::shared::log_dropped(dock.update(cx, |dock, cx| dock.close_panel(&panel_id, cx))); + crate::shared::log_dropped( + workspace.update(cx, |workspace, cx| workspace.close_detail(&panel_id, cx)), + ); Ok(()) }); self.tasks.push(task); @@ -230,24 +222,16 @@ impl NewPullRequestView { Some(addr) => SharedString::from(format!("commit:{addr}:{commit_id}")), None => SharedString::from(format!("commit:{}:{commit_id}", repo_path.display())), }; - let dock = self.dock.clone(); - let store = self.store.clone(); - let repo_name = self.repo_name.clone(); + let workspace = self.workspace.clone(); + let short = commit_id.get(..8).unwrap_or(commit_id); + let label = SharedString::from(format!("Commit {short}")); let commit_id = commit_id.to_owned(); - crate::shared::panels::open( - &dock, + crate::shared::panels::open_detail( + &workspace, id, + label, move |window, cx| { - cx.new(|cx| { - CommitDiffView::new( - store.clone(), - repo_path.clone(), - repo_name.clone(), - commit_id.clone(), - window, - cx, - ) - }) + cx.new(|cx| CommitDiffView::new(repo_path.clone(), commit_id.clone(), window, cx)) }, window, cx, @@ -461,22 +445,7 @@ impl NewPullRequestView { } } -impl Panel for NewPullRequestView { - fn title(&self, _cx: &gpui::App) -> Option { - Some(SharedString::from(format!( - "{}/new-pull-request", - self.repo_name - ))) - } - - fn lead(&self, cx: &gpui::App) -> Option { - Some(crate::shared::widgets::repo_tab_avatar( - self.store.read(cx), - &self.directory, - cx, - )) - } -} +impl Panel for NewPullRequestView {} impl Render for NewPullRequestView { fn render(&mut self, _window: &mut Window, cx: &mut Context) -> impl IntoElement { diff --git a/crates/signed_app/src/pull_requests/send_patch.rs b/crates/signed_app/src/pull_requests/send_patch.rs index b0c5e15..cd3318c 100644 --- a/crates/signed_app/src/pull_requests/send_patch.rs +++ b/crates/signed_app/src/pull_requests/send_patch.rs @@ -1,36 +1,33 @@ use assets::CustomIconName; use gpui::prelude::FluentBuilder as _; use gpui::{ - AnyElement, App, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _, - Render, SharedString, Styled as _, WeakEntity, Window, div, + AnyElement, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _, Render, + SharedString, Styled as _, WeakEntity, Window, div, }; use gpui_native_kit::button::Button; use gpui_native_kit::common::{h_flex, v_flex}; use gpui_native_kit::icons::Icon; use gpui_native_kit::input::{Input, InputState}; -use gpui_native_kit::layout::dock::{DockState, Panel}; +use gpui_native_kit::layout::panel::Panel; use gpui_native_kit::theme::{ActiveTheme as _, TextRole, Typeset as _}; -use metadata::ProfileDirectory; use signed_state::RepoStore; -use crate::shared::widgets::repo_tab_avatar; +use crate::workspace::Workspace; pub struct SendPatchView { - dock: WeakEntity, + workspace: WeakEntity, panel_id: SharedString, store: Entity, - repo_name: SharedString, subject: Entity, description: Entity, patch: Entity, submitting: bool, error: Option, - directory: Entity, } impl SendPatchView { pub fn new( - dock: WeakEntity, + workspace: WeakEntity, panel_id: SharedString, store: Entity, _window: &mut Window, @@ -40,26 +37,15 @@ impl SendPatchView { let description = InputState::builder().multiline().build(cx); let patch = InputState::builder().multiline().build(cx); - let repo_name = store.read(cx).name(); - let directory = ProfileDirectory::new(cx); - - if let Some(owner) = store.read(cx).announcement.as_ref().map(|a| a.owner) { - directory.update(cx, |directory, cx| { - directory.track([owner], cx); - }); - } - Self { - dock, + workspace, panel_id, store, - repo_name, subject, description, patch, submitting: false, error: None, - directory, } } @@ -103,8 +89,8 @@ impl SendPatchView { let panel_id = self.panel_id.clone(); crate::shared::log_dropped( - self.dock - .update(cx, |dock, cx| dock.close_panel(&panel_id, cx)), + self.workspace + .update(cx, |workspace, cx| workspace.close_detail(&panel_id, cx)), ); } @@ -135,15 +121,7 @@ impl SendPatchView { } } -impl Panel for SendPatchView { - fn title(&self, _cx: &App) -> Option { - Some(SharedString::from(format!("{}/send-patch", self.repo_name))) - } - - fn lead(&self, cx: &App) -> Option { - Some(repo_tab_avatar(self.store.read(cx), &self.directory, cx)) - } -} +impl Panel for SendPatchView {} impl Render for SendPatchView { fn render(&mut self, _window: &mut Window, cx: &mut Context) -> impl IntoElement { diff --git a/crates/signed_app/src/repo/actions.rs b/crates/signed_app/src/repo/actions.rs index 056a103..0378564 100644 --- a/crates/signed_app/src/repo/actions.rs +++ b/crates/signed_app/src/repo/actions.rs @@ -1,11 +1,11 @@ use gpui::{App, AppContext as _, SharedString, WeakEntity, Window}; -use gpui_native_kit::layout::dock::DockState; use nostr::prelude::EventId; use signed_core::{Announcement, RepoAddr}; use signed_state::RepoStore; 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 { @@ -14,9 +14,9 @@ pub enum RepoItem { Patch, } -/// Opens a repository as a dock panel, keyed by its address. +/// Opens a repository as the main panel, keyed by its address. pub fn open_repo_panel( - dock: &WeakEntity, + workspace: &WeakEntity, addr: &RepoAddr, hint: Option<&Announcement>, window: &mut Window, @@ -25,15 +25,15 @@ pub fn open_repo_panel( let id = SharedString::from(format!("repo:{addr}")); let addr = addr.clone(); let hint = hint.cloned(); - let dock_for_build = dock.clone(); + let workspace_for_build = workspace.clone(); - panels::open( - dock, + panels::open_primary( + workspace, id, move |window, cx| { let addr = addr.clone(); let hint = hint.clone(); - cx.new(|cx| RepoDetailView::new(dock_for_build.clone(), addr, hint, window, cx)) + cx.new(|cx| RepoDetailView::new(workspace_for_build.clone(), addr, hint, window, cx)) }, window, cx, @@ -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( - dock: &WeakEntity, + workspace: &WeakEntity, addr: &RepoAddr, hint: Option<&Announcement>, item: RepoItem, @@ -53,10 +53,14 @@ pub fn open_repo_item( match item { RepoItem::Issue(issue_id) => { let id = SharedString::from(format!("issue:{issue_id}")); + let hex = issue_id.to_hex(); + let short = hex.get(..8).unwrap_or(&hex); + let label = SharedString::from(format!("Issue {short}")); let store = store.clone(); - panels::open( - dock, + panels::open_detail( + workspace, id, + label, move |_, cx| { cx.new(|cx| { crate::issues::detail::IssueDetailView::new(store.clone(), issue_id, cx) @@ -68,15 +72,19 @@ pub fn open_repo_item( } RepoItem::PullRequest(pr_id) => { let id = SharedString::from(format!("pr:{pr_id}")); - let dock_for_build = dock.clone(); + let hex = pr_id.to_hex(); + let short = hex.get(..8).unwrap_or(&hex); + let label = SharedString::from(format!("PR {short}")); + let workspace_for_build = workspace.clone(); let store = store.clone(); - panels::open( - dock, + panels::open_detail( + workspace, id, + label, move |window, cx| { cx.new(|cx| { crate::pull_requests::PullRequestDetailView::new( - dock_for_build.clone(), + workspace_for_build.clone(), store.clone(), pr_id, window, diff --git a/crates/signed_app/src/repo/commit_diff.rs b/crates/signed_app/src/repo/commit_diff.rs index e016682..1e64ea9 100644 --- a/crates/signed_app/src/repo/commit_diff.rs +++ b/crates/signed_app/src/repo/commit_diff.rs @@ -12,19 +12,17 @@ use gpui_native_kit::clipboard::ClipboardButton; use gpui_native_kit::common::{h_flex, v_flex}; use gpui_native_kit::data::tree::{Tree, TreeItem}; use gpui_native_kit::icons::{Icon, IconRole}; -use gpui_native_kit::layout::dock::Panel; +use gpui_native_kit::layout::panel::Panel; use gpui_native_kit::layout::resizable::{Resizable, ResizableState}; use gpui_native_kit::scrollbar::Scrollbar; use gpui_native_kit::spinner::Spinner; use gpui_native_kit::theme::{ActiveTheme as _, TextRole, Typeset as _}; -use metadata::ProfileDirectory; use signed_git::{CommitDiff, DiffStatus, FileCommit, FileDiff, Repo}; -use signed_state::RepoStore; use utils::relative_time_secs; use super::helpers::{DiffRow, diff_rows, render_diff_row}; use crate::shared::tree::{TreeItemSeed, TreeRow, build_tree_items, collect_expanded, flatten}; -use crate::shared::widgets::{empty_state, repo_tab_avatar}; +use crate::shared::widgets::empty_state; pub struct DiffPane { diff: Option, @@ -340,36 +338,23 @@ impl Render for DiffPane { } pub struct CommitDiffView { - store: Entity, worktree: PathBuf, - repo_name: SharedString, commit: FileCommit, /// The diff is being computed on a background task. loading: bool, error: Option, pane: Entity, - /// Profile for the repository owner in the tab title. - directory: Entity, tasks: Vec>>, } impl CommitDiffView { pub fn new( - store: Entity, worktree: PathBuf, - repo_name: SharedString, commit_id: String, window: &mut Window, cx: &mut Context, ) -> Self { let pane = cx.new(DiffPane::new); - let directory = ProfileDirectory::new(cx); - - if let Some(owner) = store.read(cx).announcement.as_ref().map(|a| a.owner) { - directory.update(cx, |directory, cx| { - directory.track([owner], cx); - }); - } let weak = cx.entity().downgrade(); window.defer(cx, move |window, cx| { @@ -379,9 +364,7 @@ impl CommitDiffView { }); Self { - store, worktree, - repo_name, commit: FileCommit { id: commit_id, summary: String::new(), @@ -392,7 +375,6 @@ impl CommitDiffView { loading: true, error: None, pane, - directory, tasks: Vec::new(), } } @@ -518,18 +500,7 @@ impl CommitDiffView { } } -impl Panel for CommitDiffView { - fn title(&self, _cx: &App) -> Option { - Some(SharedString::from(format!( - "{}/{}", - self.repo_name, self.commit.id - ))) - } - - fn lead(&self, cx: &App) -> Option { - Some(repo_tab_avatar(self.store.read(cx), &self.directory, cx)) - } -} +impl Panel for CommitDiffView {} impl Render for CommitDiffView { fn render(&mut self, _window: &mut Window, cx: &mut Context) -> impl IntoElement { diff --git a/crates/signed_app/src/repo/dialogs/create.rs b/crates/signed_app/src/repo/dialogs/create.rs index 95d6fb2..b6bf6de 100644 --- a/crates/signed_app/src/repo/dialogs/create.rs +++ b/crates/signed_app/src/repo/dialogs/create.rs @@ -11,7 +11,6 @@ use gpui_native_kit::dialog::Dialog; use gpui_native_kit::field::Field; use gpui_native_kit::icons::{Icon, IconRole}; use gpui_native_kit::input::{Input, InputState}; -use gpui_native_kit::layout::dock::DockState; use gpui_native_kit::theme::{ActiveTheme as _, TextRole, Typeset as _}; use gpui_native_kit::tooltip::Tooltip; use settings::SettingsStore; @@ -21,6 +20,7 @@ use super::grasp_servers::{GraspServersState, grasp_servers_field, load_user_gra use crate::repo::actions::open_repo_panel; use crate::shared::dialogs::{close_global, open_global}; use crate::shared::progress::{DialogProgress, error_row, push_steps_row}; +use crate::workspace::Workspace; /// Progress of the create-repository flow, so async results can be rendered. pub struct CreateRepoDialog { @@ -30,11 +30,15 @@ pub struct CreateRepoDialog { relay_input: Entity, state: Entity, grasp_state: Entity, - dock: WeakEntity, + workspace: WeakEntity, } impl CreateRepoDialog { - pub fn new(dock: WeakEntity, window: &mut Window, cx: &mut App) -> Entity { + pub fn new( + workspace: WeakEntity, + window: &mut Window, + cx: &mut App, + ) -> Entity { let settings = SettingsStore::global(cx); let default_folder = settings .read(cx) @@ -65,7 +69,7 @@ impl CreateRepoDialog { relay_input, state, grasp_state, - dock, + workspace, }) } @@ -105,7 +109,7 @@ impl CreateRepoDialog { backend.create_repository(&name, &description, folder, servers, cx) }); let state = self.state.clone(); - let dock = self.dock.clone(); + let workspace = self.workspace.clone(); let handle = window.window_handle(); cx.spawn(async move |_this, cx| match task.await { @@ -116,7 +120,13 @@ impl CreateRepoDialog { store.record(local_path.clone(), announcement.addr(), cx); }); cx.open_with_system(&local_path); - open_repo_panel(&dock, &announcement.addr(), Some(&announcement), window, cx); + open_repo_panel( + &workspace, + &announcement.addr(), + Some(&announcement), + window, + cx, + ); close_global(cx); }) .ok(); @@ -267,6 +277,6 @@ fn choose_folder(folder_input: &Entity, window: &mut Window, cx: &mu } /// Opens the create-repository form. -pub fn open(dock: WeakEntity, window: &mut Window, cx: &mut App) { - open_global(CreateRepoDialog::new(dock, window, cx), cx); +pub fn open(workspace: WeakEntity, window: &mut Window, cx: &mut App) { + open_global(CreateRepoDialog::new(workspace, window, cx), cx); } diff --git a/crates/signed_app/src/repo/header.rs b/crates/signed_app/src/repo/header.rs index 9568fb8..a964f4e 100644 --- a/crates/signed_app/src/repo/header.rs +++ b/crates/signed_app/src/repo/header.rs @@ -38,7 +38,7 @@ impl RepoDetailView { return; }; - actions::open_repo_panel(&self.dock, &addr, None, window, cx); + actions::open_repo_panel(&self.workspace, &addr, None, window, cx); } /// Open the dialog that publishes the local repository to NIP-34. @@ -55,15 +55,16 @@ impl RepoDetailView { }; let id = SharedString::from(format!("pulls:{addr}")); - let dock = self.dock.clone(); - let dock_for_build = dock.clone(); + let workspace = self.workspace.clone(); + let workspace_for_build = workspace.clone(); let store = self.store.clone(); - crate::shared::panels::open( - &dock, + crate::shared::panels::open_detail( + &workspace, id, + "Pull requests", move |_, cx| { - cx.new(|cx| PullRequestsView::new(dock_for_build.clone(), store.clone(), cx)) + cx.new(|cx| PullRequestsView::new(workspace_for_build.clone(), store.clone(), cx)) }, window, cx, @@ -76,17 +77,18 @@ impl RepoDetailView { }; let id = SharedString::from(format!("new-pr:{addr}")); - let dock = self.dock.clone(); - let dock_for_build = dock.clone(); + let workspace = self.workspace.clone(); + let workspace_for_build = workspace.clone(); let store = self.store.clone(); - crate::shared::panels::open( - &dock, + crate::shared::panels::open_detail( + &workspace, id.clone(), + "New pull request", move |window, cx| { cx.new(|cx| { NewPullRequestView::new( - dock_for_build.clone(), + workspace_for_build.clone(), id.clone(), store.clone(), window, @@ -105,17 +107,18 @@ impl RepoDetailView { }; let id = SharedString::from(format!("send-patch:{addr}")); - let dock = self.dock.clone(); - let dock_for_build = dock.clone(); + let workspace = self.workspace.clone(); + let workspace_for_build = workspace.clone(); let store = self.store.clone(); - crate::shared::panels::open( - &dock, + crate::shared::panels::open_detail( + &workspace, id.clone(), + "Send patch", move |window, cx| { cx.new(|cx| { SendPatchView::new( - dock_for_build.clone(), + workspace_for_build.clone(), id.clone(), store.clone(), window, @@ -133,14 +136,17 @@ impl RepoDetailView { return; }; let id = SharedString::from(format!("issues:{addr}")); - let dock = self.dock.clone(); - let dock_for_build = dock.clone(); + let workspace = self.workspace.clone(); + let workspace_for_build = workspace.clone(); let store = self.store.clone(); - crate::shared::panels::open( - &dock, + crate::shared::panels::open_detail( + &workspace, id, - move |_, cx| cx.new(|cx| IssuesView::new(dock_for_build.clone(), store.clone(), cx)), + "Issues", + move |_, cx| { + cx.new(|cx| IssuesView::new(workspace_for_build.clone(), store.clone(), cx)) + }, window, cx, ); diff --git a/crates/signed_app/src/repo/history.rs b/crates/signed_app/src/repo/history.rs index dbb1335..d0c0db0 100644 --- a/crates/signed_app/src/repo/history.rs +++ b/crates/signed_app/src/repo/history.rs @@ -7,7 +7,6 @@ use gpui::{ Styled as _, Task, UniformListScrollHandle, WeakEntity, Window, div, uniform_list, }; use gpui_native_kit::common::v_flex; -use gpui_native_kit::layout::dock::DockState; use gpui_native_kit::scrollbar::Scrollbar; use gpui_native_kit::spinner::Spinner; use gpui_native_kit::theme::{ActiveTheme as _, TextRole, Typeset as _}; @@ -16,12 +15,12 @@ use signed_state::RepoStore; use super::commit_diff::CommitDiffView; use super::helpers::commit_row; -use super::helpers::repo_display_name; use crate::shared::panels; +use crate::workspace::Workspace; pub struct RepoHistoryView { store: Entity, - dock: WeakEntity, + workspace: WeakEntity, worktree: Option, all_commits: Option, loading_all_commits: bool, @@ -30,10 +29,10 @@ pub struct RepoHistoryView { } impl RepoHistoryView { - pub fn new(store: Entity, dock: WeakEntity) -> Self { + pub fn new(store: Entity, workspace: WeakEntity) -> Self { Self { store, - dock, + workspace, worktree: None, all_commits: None, loading_all_commits: false, @@ -100,30 +99,22 @@ impl RepoHistoryView { return; }; - // Same display name as the repo detail panel's title. - let repo_name = repo_display_name(self.store.read(cx)); let store = self.store.clone(); + let short = commit_id.get(..8).unwrap_or(commit_id); + let label = SharedString::from(format!("Commit {short}")); let commit_id = commit_id.to_owned(); let id = match store.read(cx).addr() { Some(addr) => SharedString::from(format!("commit:{addr}:{commit_id}")), None => SharedString::from(format!("commit:{}:{}", worktree.display(), commit_id)), }; - let dock = self.dock.clone(); + let workspace = self.workspace.clone(); - panels::open( - &dock, + panels::open_detail( + &workspace, id, + label, move |window, cx| { - cx.new(|cx| { - CommitDiffView::new( - store.clone(), - worktree.clone(), - repo_name.clone(), - commit_id.clone(), - window, - cx, - ) - }) + cx.new(|cx| CommitDiffView::new(worktree.clone(), commit_id.clone(), window, cx)) }, window, cx, diff --git a/crates/signed_app/src/repo/mod.rs b/crates/signed_app/src/repo/mod.rs index 7cfa0b0..baf0e61 100644 --- a/crates/signed_app/src/repo/mod.rs +++ b/crates/signed_app/src/repo/mod.rs @@ -14,7 +14,7 @@ use gpui_native_kit::badge::Badge; use gpui_native_kit::button::{Button, ButtonVariant}; use gpui_native_kit::common::{Sizable as _, h_flex, v_flex}; use gpui_native_kit::icons::{Icon, IconRole}; -use gpui_native_kit::layout::dock::{DockState, Panel}; +use gpui_native_kit::layout::panel::Panel; use gpui_native_kit::spinner::Spinner; use gpui_native_kit::theme::{ActiveTheme as _, TextRole, Typeset as _}; use metadata::ProfileDirectory; @@ -38,12 +38,12 @@ pub mod refs; use banners::Banners; use files::RepoFilesView; -use helpers::{RepoData, load_repo_data, repo_display_name}; +use helpers::{RepoData, load_repo_data}; use history::RepoHistoryView; use refs::RefSwitcher; use crate::shared::tree::{build_tree_items, sorted_worktree_paths}; -use crate::shared::widgets::repo_tab_avatar; +use crate::workspace::Workspace; #[derive(Clone, Copy, PartialEq, Eq)] pub enum RefKind { @@ -54,7 +54,7 @@ pub enum RefKind { } pub struct RepoDetailView { - pub(super) dock: WeakEntity, + pub(super) workspace: WeakEntity, pub(super) store: Entity, /// A repository opened by address alone starts without an announcement. repo_started: bool, @@ -86,30 +86,30 @@ pub struct RepoDetailView { impl RepoDetailView { pub fn new( - dock: WeakEntity, + workspace: WeakEntity, addr: RepoAddr, hint: Option, window: &mut Window, cx: &mut Context, ) -> Self { let store = cx.new(|cx| RepoStore::new(addr, hint, cx)); - Self::new_common(dock, store, window, cx) + Self::new_common(workspace, store, window, cx) } pub fn new_local( - dock: WeakEntity, + workspace: WeakEntity, local_path: PathBuf, nip34: Option, window: &mut Window, cx: &mut Context, ) -> Self { let store = cx.new(move |_cx| RepoStore::new_local(local_path, nip34)); - Self::new_common(dock, store, window, cx) + Self::new_common(workspace, store, window, cx) } /// A local repository whose detected binding matches an announcement. pub fn new_local_announced( - dock: WeakEntity, + workspace: WeakEntity, announcement: Announcement, local_path: PathBuf, window: &mut Window, @@ -117,18 +117,18 @@ impl RepoDetailView { ) -> Self { let addr = announcement.addr(); let store = cx.new(move |cx| RepoStore::from_worktree(addr, announcement, local_path, cx)); - Self::new_common(dock, store, window, cx) + Self::new_common(workspace, store, window, cx) } fn new_common( - dock: WeakEntity, + workspace: WeakEntity, store: Entity, window: &mut Window, cx: &mut Context, ) -> Self { let checkouts = CheckoutsStore::global(cx); let files = cx.new(RepoFilesView::new); - let history = cx.new(|_| RepoHistoryView::new(store.clone(), dock.clone())); + let history = cx.new(|_| RepoHistoryView::new(store.clone(), workspace.clone())); let weak = cx.entity().downgrade(); let refs = RefSwitcher::new(weak.clone(), window, cx); @@ -147,7 +147,7 @@ impl RepoDetailView { }); Self { - dock, + workspace, store: store.clone(), repo_started: false, files, @@ -1185,15 +1185,7 @@ impl RepoDetailView { } } -impl Panel for RepoDetailView { - fn title(&self, cx: &App) -> Option { - Some(repo_display_name(self.store.read(cx))) - } - - fn lead(&self, cx: &App) -> Option { - Some(repo_tab_avatar(self.store.read(cx), &self.directory, cx)) - } -} +impl Panel for RepoDetailView {} impl Render for RepoDetailView { fn render(&mut self, _window: &mut Window, cx: &mut Context) -> impl IntoElement { diff --git a/crates/signed_app/src/shared/panels.rs b/crates/signed_app/src/shared/panels.rs index ad60d37..af8f4af 100644 --- a/crates/signed_app/src/shared/panels.rs +++ b/crates/signed_app/src/shared/panels.rs @@ -1,9 +1,13 @@ -use gpui::{App, Entity, SharedString, WeakEntity, Window}; -use gpui_native_kit::layout::dock::{DockState, Panel}; +use std::sync::Arc; -/// Registers a panel builder under `id` and opens it in the dock. -pub fn open( - dock: &WeakEntity, +use gpui::{App, Entity, SharedString, WeakEntity, Window}; +use gpui_native_kit::layout::panel::{Panel, PanelView}; + +use crate::workspace::Workspace; + +/// Opens a repository in the main panel, reusing it when it is already cached. +pub fn open_primary( + workspace: &WeakEntity, id: impl Into, build: F, window: &mut Window, @@ -14,10 +18,56 @@ pub fn open( { let id = id.into(); - if let Err(error) = dock.update(cx, |dock, cx| { - dock.register_panel(id.clone(), build); - dock.open_panel(&id, window, cx); + if workspace + .read_with(cx, |workspace, _| workspace.has_main(&id)) + .unwrap_or(false) + { + if let Err(error) = workspace.update(cx, |workspace, cx| workspace.activate_main(&id, cx)) { + log::warn!("failed to activate repository {id}: {error}"); + } + return; + } + + let view: Arc = Arc::new(build(window, cx)); + + if let Err(error) = workspace.update(cx, |workspace, cx| { + workspace.show_main(id.clone(), view, cx) }) { - log::warn!("failed to open panel {id}: {error}"); + log::warn!("failed to open repository {id}: {error}"); + } +} + +/// Opens a detail panel beside the main panel, reusing it when it is already cached. +pub fn open_detail( + workspace: &WeakEntity, + id: impl Into, + label: impl Into, + build: F, + window: &mut Window, + cx: &mut App, +) where + P: Panel + 'static, + F: Fn(&mut Window, &mut App) -> Entity

+ 'static, +{ + let id = id.into(); + let label = label.into(); + + if workspace + .read_with(cx, |workspace, _| workspace.has_detail(&id)) + .unwrap_or(false) + { + if let Err(error) = workspace.update(cx, |workspace, cx| workspace.activate_detail(&id, cx)) + { + log::warn!("failed to activate detail panel {id}: {error}"); + } + return; + } + + let view: Arc = Arc::new(build(window, cx)); + + if let Err(error) = workspace.update(cx, |workspace, cx| { + workspace.show_detail(id.clone(), label, view, cx) + }) { + log::warn!("failed to open detail panel {id}: {error}"); } } diff --git a/crates/signed_app/src/shared/widgets.rs b/crates/signed_app/src/shared/widgets.rs index 68982b9..fb943da 100644 --- a/crates/signed_app/src/shared/widgets.rs +++ b/crates/signed_app/src/shared/widgets.rs @@ -1,17 +1,11 @@ use assets::CustomIconName; -use gpui::{ - AnyElement, App, Entity, IntoElement, ParentElement as _, SharedString, Styled as _, div, -}; -use gpui_native_kit::avatar::Avatar; +use gpui::{AnyElement, App, IntoElement, ParentElement as _, SharedString, Styled as _, div}; use gpui_native_kit::badge::{Badge, BadgeVariant}; -use gpui_native_kit::common::Sizable as _; use gpui_native_kit::empty_state::EmptyState; use gpui_native_kit::icons::Icon; use gpui_native_kit::theme::{ActiveTheme as _, TextRole, Typeset as _}; use gpui_native_kit::tooltip::Tooltip; -use metadata::ProfileDirectory; use signed_core::RepoStatus; -use signed_state::RepoStore; /// The status pill shown on issue and pull-request rows. pub fn status_badge(status: RepoStatus) -> Badge { @@ -51,42 +45,6 @@ pub fn empty_state(message: impl Into) -> AnyElement { .into_any_element() } -/// The profile avatar shown on a repository's panel tab. -pub fn repo_tab_avatar( - store: &RepoStore, - directory: &Entity, - cx: &App, -) -> AnyElement { - let seed = store - .announcement - .as_ref() - .map(|announcement| format!("{}:{}", announcement.owner, announcement.id)) - .or_else(|| store.addr().map(|addr| addr.to_string())) - .or_else(|| { - store - .path - .as_ref() - .map(|path| path.to_string_lossy().into_owned()) - }) - .unwrap_or_default(); - - let owner = store - .announcement - .as_ref() - .map(|announcement| directory.read(cx).profile(&announcement.owner, cx)); - - let (name, picture) = owner - .map(|profile| (Some(profile.name()), profile.picture())) - .unwrap_or((None, None)); - - let avatar = match name { - Some(name) => Avatar::new(seed).name(name), - None => Avatar::new(seed), - }; - - avatar.picture(picture).small().into_any_element() -} - /// A one-line muted label used by section headers. pub fn section_label(text: impl Into, cx: &App) -> AnyElement { div() diff --git a/crates/signed_app/src/sidebar/helpers.rs b/crates/signed_app/src/sidebar/helpers.rs deleted file mode 100644 index ca53981..0000000 --- a/crates/signed_app/src/sidebar/helpers.rs +++ /dev/null @@ -1,47 +0,0 @@ -use std::time::{SystemTime, UNIX_EPOCH}; - -use gpui::{AnyElement, App, IntoElement, SharedString}; -use gpui_native_kit::avatar::Avatar; -use metadata::ProfileDirectory; -use signed_state::{Nip34Binding, ResolvedLocalRepo}; - -pub(super) fn pick_banner() -> SharedString { - let num = SystemTime::now() - .duration_since(UNIX_EPOCH) - .map(|duration| duration.subsec_nanos()) - .unwrap_or(1) - % 3 - + 1; - format!("backgrounds/banner{num}.jpg").into() -} - -/// The platform that bound a repository, `"nak"` or `"ngit"`. -pub(super) fn local_platform(binding: &Nip34Binding) -> Option<&'static str> { - let signals = &binding.signals; - - if signals.nip34_json || signals.nip34_grasp_remote || signals.nip34_state_refs { - Some("nak") - } else if signals.nostr_repo_config { - Some("ngit") - } else { - None - } -} - -/// The bound owner's avatar, falling back to the path's pixel avatar when unowned. -pub(super) fn local_avatar( - entry: &ResolvedLocalRepo, - directory: &gpui::Entity, - cx: &App, -) -> AnyElement { - let Some(owner) = entry.nip34.as_ref().and_then(|binding| binding.owner) else { - return Avatar::new(entry.path.to_string_lossy()).into_any_element(); - }; - - let profile = directory.read(cx).profile(&owner, cx); - - Avatar::new(owner) - .name(profile.name()) - .picture(profile.picture()) - .into_any_element() -} diff --git a/crates/signed_app/src/sidebar/mod.rs b/crates/signed_app/src/sidebar/mod.rs deleted file mode 100644 index 6bcddf4..0000000 --- a/crates/signed_app/src/sidebar/mod.rs +++ /dev/null @@ -1,661 +0,0 @@ -use std::collections::HashMap; -use std::sync::Arc; - -use assets::CustomIconName; -use gpui::{ - AnyElement, App, AppContext as _, Context, IntoElement, ObjectFit, ParentElement as _, - SharedString, Styled as _, StyledImage as _, Subscription, WeakEntity, Window, div, img, px, -}; -use gpui_native_kit::avatar::Avatar; -use gpui_native_kit::badge::{Badge, BadgeVariant}; -use gpui_native_kit::button::{Button, ButtonVariant}; -use gpui_native_kit::common::{h_flex, v_flex}; -use gpui_native_kit::data::sidebar::{Sidebar, SidebarEntry}; -use gpui_native_kit::icons::{Icon, IconRole}; -use gpui_native_kit::layout::dock::DockState; -use gpui_native_kit::menu::{Menu, MenuItem}; -use gpui_native_kit::theme::ActiveTheme as _; -use gpui_native_kit::tooltip::Tooltip; -use helpers::{local_avatar, local_platform, pick_banner}; -use metadata::{Profile, ProfileDirectory}; -use nostr::prelude::PublicKey; -use signed_core::{Announcement, RepoAddr}; -use signed_state::{ - Backend, BackendEvent, CheckoutsStore, LocalReposStore, Nip34Kind, RepoListStore, - ResolvedLocalRepo, SyncStatusDirectory, -}; - -use crate::explore::ExploreView; -use crate::inbox::InboxView; -use crate::repo::dialogs; -use crate::shared::log_dropped; -use crate::{identity, settings}; - -mod helpers; - -#[derive(Clone, Copy)] -enum SidebarSlot { - Inbox, - Browse, - Search, - Header, - Repo(usize), - Local(usize), -} - -pub struct SidebarView { - weak: WeakEntity, - dock: WeakEntity, - banner: SharedString, - scanning: bool, - /// User's announced repositories. - announcements: Arc>, - /// Local repositories found by the scan that are not announced yet. - local_repos: Arc>, - /// Unpushed commit counts per announced repository. - unpushed: HashMap, - /// Profiles rendered by the sidebar. - directory: gpui::Entity, - /// Sync statuses for the announced repositories. - sync_directory: gpui::Entity, - user_menu_open: bool, - _subscriptions: Vec, -} - -impl SidebarView { - pub fn new(dock: WeakEntity, cx: &mut Context) -> Self { - let backend = Backend::global(cx); - let repos = RepoListStore::global(cx); - let local = LocalReposStore::global(cx); - let checkouts = CheckoutsStore::global(cx); - - let mut subscriptions = Vec::new(); - - // Identity changes swap the whole sidebar between the sign-in screen and the signed-in content. - subscriptions.push(cx.subscribe(&backend, |this, _backend, event, cx| { - let signer_changed = matches!(event, BackendEvent::SignerChanged); - let signer_required = matches!(event, BackendEvent::SignerRequired); - - if signer_required { - this.banner = pick_banner(); - cx.notify(); - } - - if this.refresh(cx) || signer_changed { - cx.notify(); - } - })); - - subscriptions.push(cx.observe(&repos, |this, _repos, cx| { - if this.refresh(cx) { - cx.notify(); - } - })); - - subscriptions.push(cx.observe(&local, |this, _local, cx| { - if this.refresh(cx) { - cx.notify(); - } - })); - - // Push statuses are recomputed in the background, so only the badge counts change. - subscriptions.push(cx.observe(&checkouts, |this, _checkouts, cx| { - if this.refresh_unpushed(cx) { - cx.notify(); - } - })); - - Self { - weak: cx.entity().downgrade(), - dock, - banner: pick_banner(), - announcements: Arc::new(Vec::new()), - local_repos: Arc::new(Vec::new()), - scanning: false, - unpushed: HashMap::new(), - directory: ProfileDirectory::new(cx), - sync_directory: SyncStatusDirectory::new(cx), - user_menu_open: false, - _subscriptions: subscriptions, - } - } - - fn refresh(&mut self, cx: &mut Context) -> bool { - let backend = Backend::global(cx); - let user = backend.read(cx).current_user(); - - let (announcements, local_repos, scanning) = { - let repo_list = RepoListStore::global(cx).read(cx); - - let announcements = user - .as_ref() - .map(|user| repo_list.announcements_of(user)) - .unwrap_or_default(); - - let local = LocalReposStore::global(cx).read(cx); - let local_repos = - LocalReposStore::resolve(&local.repos, &repo_list.announcements, &announcements); - - (announcements, local_repos, local.scanning) - }; - - let announcements_changed = *self.announcements != announcements; - let local_changed = *self.local_repos != local_repos; - let scanning_changed = self.scanning != scanning; - - self.announcements = Arc::new(announcements); - self.local_repos = Arc::new(local_repos); - self.scanning = scanning; - - let mut profiles: Vec = user.into_iter().collect(); - let owners: Vec = self - .local_repos - .iter() - .filter_map(|entry| { - entry - .nip34 - .as_ref() - .and_then(|binding| binding.owner) - .filter(|owner| !profiles.contains(owner)) - }) - .collect(); - - profiles.extend(owners); - - self.directory.update(cx, |directory, cx| { - directory.track(profiles, cx); - }); - - let addrs: Vec = self - .announcements - .iter() - .map(|announcement| announcement.addr()) - .collect(); - - self.sync_directory.update(cx, |directory, cx| { - directory.track(addrs, cx); - }); - - if announcements_changed { - self.request_push_watches(cx); - self.unpushed.clear(); - } - - announcements_changed || local_changed || scanning_changed - } - - fn refresh_unpushed(&mut self, cx: &mut Context) -> bool { - let checkouts = CheckoutsStore::global(cx); - let mut unpushed = HashMap::with_capacity(self.announcements.len()); - - for announcement in self.announcements.iter() { - let addr = announcement.addr(); - let count = checkouts.read(cx).unpushed(&addr); - if count > 0 { - unpushed.insert(addr, count); - } - } - - if unpushed == self.unpushed { - return false; - } - - self.unpushed = unpushed; - true - } - - fn request_push_watches(&self, cx: &mut Context) { - let checkouts = CheckoutsStore::global(cx); - checkouts.update(cx, |checkouts, cx| { - for announcement in self.announcements.iter() { - checkouts.request_push_statuses(&announcement.addr(), cx); - } - }); - } - - /// Renders the sidebar for the current identity state. - pub fn build(&self, cx: &App) -> Sidebar { - let backend = Backend::global(cx); - - if backend.read(cx).current_user().is_none() { - return Sidebar::new("signed-sidebar").content(self.render_sign_in(cx)); - } - - let weak = self.weak.clone(); - let announcements = self.announcements.clone(); - let local_repos = self.local_repos.clone(); - let unpushed = self.unpushed.clone(); - let directory = self.directory.clone(); - let sync_directory = self.sync_directory.clone(); - - Sidebar::new("signed-sidebar") - .transparent(true) - .footer(self.render_footer(cx)) - .entries(move |_, cx| { - let muted = cx.theme().colors.muted_foreground; - - let mut entries = vec![ - SidebarEntry::row("inbox", "Inbox") - .prefix(Icon::named(CustomIconName::Inbox).color(muted)), - SidebarEntry::row("browse", "Browse") - .prefix(Icon::named(CustomIconName::Globe).color(muted)), - SidebarEntry::row("search", "Search") - .prefix(Icon::named(IconRole::Search).color(muted)), - SidebarEntry::header("Repositories"), - ]; - - for announcement in announcements.iter() { - let addr = announcement.addr(); - let owner = directory.read(cx).profile(&announcement.owner, cx); - - let count = unpushed.get(&addr).copied().unwrap_or(0); - let unsynced = sync_directory.read(cx).unsynced(&addr, cx); - - let name = announcement - .name - .as_deref() - .map(SharedString::from) - .unwrap_or_else(|| SharedString::from(announcement.id.clone())); - - let mut row = SidebarEntry::row(format!("repo:{}", announcement.id), name) - .prefix( - Avatar::new(announcement.owner) - .name(owner.name()) - .picture(owner.picture()), - ); - - if count > 0 || unsynced > 0 { - let mut badges = h_flex().gap_1(); - if count > 0 { - badges = badges.child( - Badge::new(format!("unpushed:{addr}"), count.to_string()) - .variant(BadgeVariant::Warning), - ); - } - if unsynced > 0 { - badges = badges.child( - Badge::new(format!("unsynced:{addr}"), unsynced.to_string()) - .variant(BadgeVariant::Accent), - ); - } - row = row.suffix(badges); - } - - entries.push(row); - } - - for entry in local_repos.iter() { - let suffix: AnyElement = match entry.nip34.as_ref() { - Some(binding) => { - let (label, note) = match binding.kind { - Nip34Kind::Initialized => { - let platform = local_platform(binding).unwrap_or("Grasp"); - (platform, "Initialized for NIP-34") - } - Nip34Kind::Cloned => ("Cloned", "Cloned but not initialized"), - Nip34Kind::ToolingOnly => ("Tooling", "Grasp tooling only"), - }; - Badge::new(format!("lbadge:{}", entry.path.display()), label) - .tooltip(Tooltip::text(note)) - .into_any_element() - } - None => Badge::new(format!("un-{}", entry.path.display()), "Unpublished") - .variant(BadgeVariant::Outline) - .into_any_element(), - }; - - entries.push( - SidebarEntry::row(format!("lrepo:{}", entry.path.display()), entry.name()) - .prefix(local_avatar(entry, &directory, cx)) - .suffix(suffix), - ); - } - - debug_assert_eq!( - entries.len(), - slots(announcements.len(), local_repos.len()).len() - ); - entries - }) - .on_change(move |index, window, cx| { - if let Err(error) = weak.update(cx, |this, cx| this.activate(index, window, cx)) { - log::warn!("failed to activate sidebar row: {error}"); - } - }) - } - - fn activate(&mut self, index: Option, window: &mut Window, cx: &mut Context) { - let Some(index) = index else { - return; - }; - let Some(slot) = slots(self.announcements.len(), self.local_repos.len()) - .get(index) - .copied() - else { - return; - }; - - match slot { - SidebarSlot::Inbox => self.open_inbox(window, cx), - SidebarSlot::Browse | SidebarSlot::Search => self.open_explore(window, cx), - SidebarSlot::Header => {} - SidebarSlot::Repo(ix) => { - if let Some(announcement) = self.announcements.get(ix).cloned() { - let addr = announcement.addr(); - crate::repo::actions::open_repo_panel( - &self.dock, - &addr, - Some(&announcement), - window, - cx, - ); - } - } - SidebarSlot::Local(ix) => { - if let Some(entry) = self.local_repos.get(ix).cloned() { - self.open_local_entry(entry, window, cx); - } - } - } - } - - /// A local repository opens as the announced repository when its binding matches one. - fn open_local_entry( - &mut self, - entry: ResolvedLocalRepo, - window: &mut Window, - cx: &mut Context, - ) { - let ResolvedLocalRepo { - path, - nip34, - announcement, - } = entry; - - if let Some(announcement) = announcement { - let id = SharedString::from(format!("repo:{}", announcement.addr())); - let dock = self.dock.clone(); - let dock_for_build = dock.clone(); - crate::shared::panels::open( - &dock, - id, - move |window, cx| { - cx.new(|cx| { - crate::repo::RepoDetailView::new_local_announced( - dock_for_build.clone(), - announcement.clone(), - path.clone(), - window, - cx, - ) - }) - }, - window, - cx, - ); - return; - } - - let id = SharedString::from(format!("repo-local:{}", path.display())); - let dock = self.dock.clone(); - let dock_for_build = dock.clone(); - - crate::shared::panels::open( - &dock, - id, - move |window, cx| { - cx.new(|cx| { - crate::repo::RepoDetailView::new_local( - dock_for_build.clone(), - path.clone(), - nip34.clone(), - window, - cx, - ) - }) - }, - window, - cx, - ); - } - - fn render_footer(&self, _cx: &App) -> impl IntoElement { - let guide_weak = self.weak.clone(); - - v_flex() - .p_2() - .gap_1() - .w_full() - .child( - Button::new("guide") - .icon(IconRole::Info) - .label("Guide") - .side(gpui_native_kit::button::ButtonSide::Left) - .variant(ButtonVariant::Ghost) - .on_click(move |_, window, cx| { - log_dropped(guide_weak.update(cx, |this, cx| { - this.open_explore(window, cx); - })); - }), - ) - .child( - Button::new("settings") - .icon(IconRole::Settings) - .label("Settings") - .side(gpui_native_kit::button::ButtonSide::Left) - .variant(ButtonVariant::Ghost) - .on_click(|_, _, cx| { - settings::open(cx); - }), - ) - } - - fn open_inbox(&mut self, window: &mut Window, cx: &mut Context) { - let dock = self.dock.clone(); - let dock_for_build = dock.clone(); - - crate::shared::panels::open( - &dock, - "inbox", - move |_, cx| cx.new(|cx| InboxView::new(dock_for_build.clone(), cx)), - window, - cx, - ); - } - - fn open_explore(&mut self, window: &mut Window, cx: &mut Context) { - let dock = self.dock.clone(); - let dock_for_build = dock.clone(); - - crate::shared::panels::open( - &dock, - "explore", - move |_window, cx| cx.new(|cx| ExploreView::new(dock_for_build.clone(), cx)), - window, - cx, - ); - } - - fn open_panel(&mut self, id: &str, window: &mut Window, cx: &mut Context) { - if let Err(error) = self - .dock - .update(cx, |dock, cx| dock.open_panel(id, window, cx)) - { - log::warn!("failed to open panel {id}: {error}"); - } - } - - pub fn render_titlebar(&self, cx: &App) -> Option { - let profile = Backend::global(cx) - .read(cx) - .current_user() - .map(|public_key| self.directory.read(cx).profile(&public_key, cx))?; - - Some( - self.render_user(&profile, self.scanning, cx) - .into_any_element(), - ) - } - - fn render_user(&self, profile: &Profile, scanning: bool, cx: &App) -> impl IntoElement { - let name = profile.name(); - let picture = profile.picture(); - let public_key = profile.public_key(); - let weak = self.weak.clone(); - let weak_for_open = self.weak.clone(); - let muted = cx.theme().colors.muted_foreground; - let dock = self.dock.clone(); - - let menu = Menu::new("user-menu") - .open(self.user_menu_open) - .on_change({ - let weak = weak_for_open.clone(); - move |open, _, cx| { - if let Err(error) = weak.update(cx, |this, cx| { - this.user_menu_open = open; - cx.notify(); - }) { - log::warn!("failed to update user menu: {error}"); - } - } - }) - .trigger({ - let name = name.clone(); - let picture = picture.clone(); - move |_, _| { - h_flex() - .gap_1() - .items_center() - .child( - Avatar::new(public_key) - .name(name.clone()) - .picture(picture.clone()), - ) - .child( - Icon::named(IconRole::ChevronDown) - .size(px(12.)) - .color(muted), - ) - .into_any_element() - } - }) - .items(move |_, _| { - let profile_weak = weak.clone(); - let relays_weak = weak.clone(); - - vec![ - MenuItem::new("View Profile").handler(move |window, cx| { - if let Err(error) = profile_weak.update(cx, |this, cx| { - this.open_panel("profile", window, cx); - }) { - log::warn!("failed to open profile: {error}"); - } - }), - MenuItem::new("View Relays").handler(move |window, cx| { - if let Err(error) = relays_weak.update(cx, |this, cx| { - this.open_panel("relays", window, cx); - }) { - log::warn!("failed to open relays: {error}"); - } - }), - MenuItem::separator(), - MenuItem::new("Exit") - .destructive(true) - .handler(|_, cx| identity::helpers::open_exit(cx)), - ] - }); - - h_flex().w_full().justify_between().child(menu).child( - h_flex() - .gap_1() - .child( - Button::new("rescan-repos") - .icon(Icon::named(IconRole::Loader)) - .variant(ButtonVariant::Ghost) - .loading(scanning) - .disabled(scanning) - .tooltip(Tooltip::text("Rescan for local repositories")) - .on_click(move |_, _, cx| { - let local_repos = LocalReposStore::global(cx); - local_repos.update(cx, |store, cx| store.rescan(cx)); - }), - ) - .child( - Button::new("add-repo") - .icon(Icon::named(IconRole::Plus)) - .variant(ButtonVariant::Ghost) - .tooltip(Tooltip::text("Create repository")) - .on_click({ - let dock = dock.clone(); - move |_, window, cx| { - dialogs::create::open(dock.clone(), window, cx); - } - }), - ), - ) - } - - /// Shown while no identity is signed in. - fn render_sign_in(&self, _cx: &App) -> impl IntoElement { - let weak = self.weak.clone(); - let import_weak = self.weak.clone(); - - v_flex() - .size_full() - .relative() - .child( - div().absolute().inset_0().child( - img(self.banner.clone()) - .size_full() - .object_fit(ObjectFit::Cover), - ), - ) - .child( - v_flex() - .size_full() - .justify_end() - .p_4() - .gap_4() - .child(img("backgrounds/headline.png").max_w_48()) - .child( - v_flex() - .gap_1() - .w_full() - .child(Button::new("onboarding").label("Join now").on_click( - move |_, window, cx| { - if let Err(error) = weak.update(cx, |this, cx| { - this.open_panel("welcome", window, cx); - identity::helpers::open_onboarding(cx); - }) { - log::warn!("failed to open onboarding: {error}"); - } - }, - )) - .child( - Button::new("import") - .label("Import identity") - .variant(ButtonVariant::Secondary) - .on_click(move |_, _, cx| { - if let Err(error) = import_weak - .update(cx, |_, cx| identity::helpers::open_import(cx)) - { - log::warn!("failed to open import: {error}"); - } - }), - ), - ), - ) - } -} - -fn slots(announcements: usize, local_repos: usize) -> Vec { - let mut slots = vec![ - SidebarSlot::Inbox, - SidebarSlot::Browse, - SidebarSlot::Search, - SidebarSlot::Header, - ]; - slots.extend((0..announcements).map(SidebarSlot::Repo)); - slots.extend((0..local_repos).map(SidebarSlot::Local)); - slots -} diff --git a/crates/signed_app/src/titlebar/helpers.rs b/crates/signed_app/src/titlebar/helpers.rs new file mode 100644 index 0000000..78adcec --- /dev/null +++ b/crates/signed_app/src/titlebar/helpers.rs @@ -0,0 +1,25 @@ +use gpui::{AnyElement, App, IntoElement}; +use gpui_native_kit::avatar::Avatar; +use gpui_native_kit::common::Sizable as _; +use signed_state::ResolvedLocalRepo; + +/// The bound owner's avatar, falling back to the path's pixel avatar when unowned. +pub(super) fn local_avatar( + entry: &ResolvedLocalRepo, + directory: &gpui::Entity, + cx: &App, +) -> AnyElement { + let Some(owner) = entry.nip34.as_ref().and_then(|binding| binding.owner) else { + return Avatar::new(entry.path.to_string_lossy()) + .small() + .into_any_element(); + }; + + let profile = directory.read(cx).profile(&owner, cx); + + Avatar::new(owner) + .name(profile.name()) + .picture(profile.picture()) + .small() + .into_any_element() +} diff --git a/crates/signed_app/src/titlebar/mod.rs b/crates/signed_app/src/titlebar/mod.rs new file mode 100644 index 0000000..9b9de31 --- /dev/null +++ b/crates/signed_app/src/titlebar/mod.rs @@ -0,0 +1,388 @@ +use std::sync::Arc; + +use gpui::{ + AnyElement, App, AppContext as _, Context, IntoElement, ParentElement as _, SharedString, + Styled as _, Subscription, WeakEntity, Window, px, +}; +use gpui_native_kit::avatar::Avatar; +use gpui_native_kit::button::{Button, ButtonVariant}; +use gpui_native_kit::common::{Sizable as _, h_flex}; +use gpui_native_kit::data::tabs::{Tab, Tabs, TabsVariant}; +use gpui_native_kit::icons::{Icon, IconRole}; +use gpui_native_kit::menu::{Menu, MenuItem}; +use gpui_native_kit::theme::ActiveTheme as _; +use gpui_native_kit::tooltip::Tooltip; +use helpers::local_avatar; +use metadata::{Profile, ProfileDirectory}; +use nostr::prelude::PublicKey; +use signed_core::Announcement; +use signed_state::{Backend, BackendEvent, LocalReposStore, RepoListStore, ResolvedLocalRepo}; + +use crate::repo::RepoDetailView; +use crate::repo::actions; +use crate::repo::dialogs; +use crate::shared::log_dropped; +use crate::shared::panels; +use crate::workspace::Workspace; +use crate::{identity, settings}; + +mod helpers; + +pub struct TitlebarView { + weak: WeakEntity, + workspace: WeakEntity, + scanning: bool, + /// User's announced repositories. + announcements: Arc>, + /// Local repositories found by the scan that are not announced yet. + local_repos: Arc>, + /// Profiles rendered by the titlebar tabs. + directory: gpui::Entity, + user_menu_open: bool, + _subscriptions: Vec, +} + +impl TitlebarView { + pub fn new(workspace: WeakEntity, cx: &mut Context) -> Self { + let backend = Backend::global(cx); + let repos = RepoListStore::global(cx); + let local = LocalReposStore::global(cx); + + let mut subscriptions = Vec::new(); + + subscriptions.push(cx.subscribe(&backend, |this, _backend, event, cx| { + let signer_changed = matches!(event, BackendEvent::SignerChanged); + let signer_required = matches!(event, BackendEvent::SignerRequired); + + if this.refresh(cx) || signer_changed || signer_required { + cx.notify(); + } + })); + + subscriptions.push(cx.observe(&repos, |this, _repos, cx| { + if this.refresh(cx) { + cx.notify(); + } + })); + + subscriptions.push(cx.observe(&local, |this, _local, cx| { + if this.refresh(cx) { + cx.notify(); + } + })); + + let mut this = Self { + weak: cx.entity().downgrade(), + workspace, + scanning: false, + announcements: Arc::new(Vec::new()), + local_repos: Arc::new(Vec::new()), + directory: ProfileDirectory::new(cx), + user_menu_open: false, + _subscriptions: subscriptions, + }; + this.refresh(cx); + this + } + + fn refresh(&mut self, cx: &mut Context) -> bool { + let backend = Backend::global(cx); + let user = backend.read(cx).current_user(); + + let (announcements, local_repos, scanning) = { + let repo_list = RepoListStore::global(cx).read(cx); + + let announcements = user + .as_ref() + .map(|user| repo_list.announcements_of(user)) + .unwrap_or_default(); + + let local = LocalReposStore::global(cx).read(cx); + let local_repos = + LocalReposStore::resolve(&local.repos, &repo_list.announcements, &announcements); + + (announcements, local_repos, local.scanning) + }; + + let announcements_changed = *self.announcements != announcements; + let local_changed = *self.local_repos != local_repos; + let scanning_changed = self.scanning != scanning; + + self.announcements = Arc::new(announcements); + self.local_repos = Arc::new(local_repos); + self.scanning = scanning; + + let mut profiles: Vec = user.into_iter().collect(); + let owners: Vec = self + .local_repos + .iter() + .filter_map(|entry| { + entry + .nip34 + .as_ref() + .and_then(|binding| binding.owner) + .filter(|owner| !profiles.contains(owner)) + }) + .collect(); + + profiles.extend(owners); + + self.directory.update(cx, |directory, cx| { + directory.track(profiles, cx); + }); + + announcements_changed || local_changed || scanning_changed + } + + pub fn render_tabs(&self, cx: &App) -> Option { + if Backend::global(cx).read(cx).current_user().is_none() { + return None; + } + + let announcements = self.announcements.clone(); + let local_repos = self.local_repos.clone(); + + if announcements.is_empty() && local_repos.is_empty() { + return None; + } + + let keys: Vec = announcements + .iter() + .map(announcement_key) + .chain(local_repos.iter().map(local_key)) + .collect(); + + let active = self + .workspace + .read_with(cx, |workspace, _| workspace.active_main_id().cloned()) + .ok() + .flatten(); + let selected = active + .as_ref() + .and_then(|id| keys.iter().position(|key| key == id)) + .unwrap_or(usize::MAX); + + let weak = self.weak.clone(); + let directory = self.directory.clone(); + + Some( + Tabs::new("signed-repo-tabs") + .variant(TabsVariant::Pill) + .overflow_scroll(true) + .selected(selected) + .tabs(move |_, cx| { + let mut tabs = Vec::with_capacity(announcements.len() + local_repos.len()); + + for announcement in announcements.iter() { + let profile = directory.read(cx).profile(&announcement.owner, cx); + let label = announcement + .name + .as_deref() + .map(SharedString::from) + .unwrap_or_else(|| SharedString::from(announcement.id.clone())); + tabs.push( + Tab::new(announcement_key(announcement), label).lead( + Avatar::new(format!("{}:{}", announcement.owner, announcement.id)) + .name(profile.name()) + .picture(profile.picture()) + .small(), + ), + ); + } + + for entry in local_repos.iter() { + tabs.push( + Tab::new(local_key(entry), entry.name()) + .lead(local_avatar(entry, &directory, cx)), + ); + } + + tabs + }) + .on_change(move |index, window, cx| { + log_dropped(weak.update(cx, |this, cx| this.activate(index, window, cx))); + }), + ) + } + + fn activate(&mut self, index: usize, window: &mut Window, cx: &mut Context) { + if let Some(announcement) = self.announcements.get(index) { + let addr = announcement.addr(); + actions::open_repo_panel(&self.workspace, &addr, Some(announcement), window, cx); + return; + } + + let Some(entry) = index + .checked_sub(self.announcements.len()) + .and_then(|local| self.local_repos.get(local)) + .cloned() + else { + return; + }; + self.open_local_entry(entry, window, cx); + } + + /// A local repository opens as the announced repository when its binding matches one. + fn open_local_entry( + &mut self, + entry: ResolvedLocalRepo, + window: &mut Window, + cx: &mut Context, + ) { + let ResolvedLocalRepo { + path, + nip34, + announcement, + } = entry; + + if let Some(announcement) = announcement { + let id = SharedString::from(format!("repo:{}", announcement.addr())); + let workspace = self.workspace.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, + ); + return; + } + + let id = SharedString::from(format!("repo-local:{}", path.display())); + let workspace = self.workspace.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, + ); + } + + pub fn render_user_menu(&self, cx: &App) -> Option { + let profile = Backend::global(cx) + .read(cx) + .current_user() + .map(|public_key| self.directory.read(cx).profile(&public_key, cx))?; + + Some(self.render_user(&profile, cx).into_any_element()) + } + + fn render_user(&self, profile: &Profile, cx: &App) -> impl IntoElement { + let name = profile.name(); + let picture = profile.picture(); + let public_key = profile.public_key(); + let weak = self.weak.clone(); + let muted = cx.theme().colors.muted_foreground; + + Menu::new("user-menu") + .open(self.user_menu_open) + .on_change({ + let weak = weak.clone(); + move |open, _, cx| { + log_dropped(weak.update(cx, |this, cx| { + this.user_menu_open = open; + cx.notify(); + })); + } + }) + .trigger({ + let name = name.clone(); + let picture = picture.clone(); + move |_, _| { + h_flex() + .gap_1() + .items_center() + .child( + Avatar::new(public_key) + .name(name.clone()) + .picture(picture.clone()), + ) + .child( + Icon::named(IconRole::ChevronDown) + .size(px(12.)) + .color(muted), + ) + .into_any_element() + } + }) + .items(|_, _| { + vec![ + MenuItem::new("Settings").handler(|_, cx| settings::open(cx)), + MenuItem::separator(), + MenuItem::new("Exit") + .destructive(true) + .handler(|_, cx| identity::helpers::open_exit(cx)), + ] + }) + } + + pub fn render_actions(&self, cx: &App) -> Option { + if Backend::global(cx).read(cx).current_user().is_none() { + return None; + } + + let workspace = self.workspace.clone(); + + Some( + h_flex() + .gap_1() + .child( + Button::new("rescan-repos") + .icon(Icon::named(IconRole::Loader)) + .variant(ButtonVariant::Ghost) + .loading(self.scanning) + .disabled(self.scanning) + .tooltip(Tooltip::text("Rescan for local repositories")) + .on_click(|_, _, cx| { + let local_repos = LocalReposStore::global(cx); + local_repos.update(cx, |store, cx| store.rescan(cx)); + }), + ) + .child( + Button::new("add-repo") + .icon(Icon::named(IconRole::Plus)) + .variant(ButtonVariant::Ghost) + .tooltip(Tooltip::text("Create repository")) + .on_click(move |_, window, cx| { + dialogs::create::open(workspace.clone(), window, cx); + }), + ) + .into_any_element(), + ) + } +} + +fn announcement_key(announcement: &Announcement) -> SharedString { + SharedString::from(format!("repo:{}", announcement.addr())) +} + +fn local_key(entry: &ResolvedLocalRepo) -> SharedString { + match entry.announcement.as_ref() { + Some(announcement) => announcement_key(announcement), + None => SharedString::from(format!("repo-local:{}", entry.path.display())), + } +} diff --git a/crates/signed_app/src/workspace.rs b/crates/signed_app/src/workspace.rs new file mode 100644 index 0000000..b38d53e --- /dev/null +++ b/crates/signed_app/src/workspace.rs @@ -0,0 +1,193 @@ +use std::collections::HashMap; +use std::sync::Arc; + +use gpui::{ + Context, IntoElement, ParentElement as _, Render, SharedString, Styled as _, Window, div, +}; +use gpui_native_kit::common::v_flex; +use gpui_native_kit::data::tabs::{Tab, Tabs, TabsVariant}; +use gpui_native_kit::layout::panel::{Panel, PanelView}; + +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, + main_views: HashMap>, + details: Vec<(SharedString, SharedString)>, + detail_views: HashMap>, + active_detail: Option, +} + +impl Workspace { + pub fn new() -> Self { + Self::default() + } + + pub fn active_main(&self) -> Option> { + 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 active_detail(&self) -> Option> { + 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, + cx: &mut Context, + ) { + if self.main.as_ref() != Some(&id) { + self.clear_details(); + } + self.main_views.insert(id.clone(), view); + self.main = Some(id); + cx.notify(); + } + + pub fn activate_main(&mut self, id: &SharedString, cx: &mut Context) { + 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) { + if self.detail_views.contains_key(id) { + self.active_detail = Some(id.clone()); + cx.notify(); + } + } + + pub fn show_detail( + &mut self, + id: SharedString, + label: SharedString, + view: Arc, + cx: &mut Context, + ) { + match self.details.iter_mut().find(|(open, _)| *open == id) { + Some((_, existing)) => *existing = label, + None => self.details.push((id.clone(), label)), + } + 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) { + let Some(index) = self.details.iter().position(|(open, _)| open == id) else { + return; + }; + self.close_detail_at(index, cx); + } + + pub fn clear(&mut self, cx: &mut Context) { + self.main = None; + 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) { + 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))) + .map(|(id, _)| id.clone()); + } + + cx.notify(); + } + + fn activate_detail_at(&mut self, index: usize, cx: &mut Context) { + let Some((id, _)) = self.details.get(index) else { + return; + }; + self.active_detail = Some(id.clone()); + cx.notify(); + } +} + +impl Panel for Workspace {} + +impl Render for Workspace { + fn render(&mut self, _window: &mut Window, cx: &mut Context) -> 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 = self.details.clone(); + let weak = cx.entity().downgrade(); + let close_weak = weak.clone(); + + let tabs = Tabs::new("signed-detail-tabs") + .variant(TabsVariant::Pill) + .overflow_scroll(true) + .selected(selected) + .tabs(move |_, _| { + details + .iter() + .map(|(id, label)| Tab::new(id.clone(), label.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); + })); + }); + + let body = self.active_detail().map(|view| view.view()); + + v_flex() + .size_full() + .gap_2() + .child(tabs) + .child(div().flex_1().min_h_0().w_full().children(body)) + } +}