add workspace
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
mod views;
|
mod views;
|
||||||
mod workspace;
|
mod workspace;
|
||||||
|
|
||||||
pub use views::RepoListView;
|
pub use views::{RepoListView, SidebarPanel};
|
||||||
pub use workspace::Workspace;
|
pub use workspace::Workspace;
|
||||||
|
|
||||||
use gpui::{App, AppContext, Entity, Window};
|
use gpui::{App, AppContext, Entity, Window};
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
mod repo_list;
|
mod repo_list;
|
||||||
|
mod sidebar;
|
||||||
|
|
||||||
pub use repo_list::RepoListView;
|
pub use repo_list::RepoListView;
|
||||||
|
pub use sidebar::SidebarPanel;
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
use gpui::prelude::*;
|
use gpui::prelude::*;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AnyElement, App, Context, Entity, Render, SharedString, Subscription, Window, div, px,
|
AnyElement, App, Context, Entity, EventEmitter, FocusHandle, Focusable, Render, SharedString,
|
||||||
uniform_list,
|
Subscription, Window, div, px, uniform_list,
|
||||||
};
|
};
|
||||||
|
use gpui_component::dock::{Panel, PanelEvent};
|
||||||
use gpui_component::{ActiveTheme, StyledExt};
|
use gpui_component::{ActiveTheme, StyledExt};
|
||||||
use signed_core::Announcement;
|
use signed_core::Announcement;
|
||||||
use signed_state::{ProfileStore, RepoListStore};
|
use signed_state::{ProfileStore, RepoListStore};
|
||||||
@@ -10,6 +11,7 @@ use signed_state::{ProfileStore, RepoListStore};
|
|||||||
/// Browse all announced repositories (works anonymously).
|
/// Browse all announced repositories (works anonymously).
|
||||||
pub struct RepoListView {
|
pub struct RepoListView {
|
||||||
store: Entity<RepoListStore>,
|
store: Entity<RepoListStore>,
|
||||||
|
focus_handle: FocusHandle,
|
||||||
_subscription: Subscription,
|
_subscription: Subscription,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,11 +22,30 @@ impl RepoListView {
|
|||||||
|
|
||||||
Self {
|
Self {
|
||||||
store,
|
store,
|
||||||
|
focus_handle: cx.focus_handle(),
|
||||||
_subscription: subscription,
|
_subscription: subscription,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Panel for RepoListView {
|
||||||
|
fn panel_name(&self) -> &'static str {
|
||||||
|
"repo_list"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn title(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
"Explore"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EventEmitter<PanelEvent> for RepoListView {}
|
||||||
|
|
||||||
|
impl Focusable for RepoListView {
|
||||||
|
fn focus_handle(&self, _cx: &App) -> FocusHandle {
|
||||||
|
self.focus_handle.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn render_card(announcement: &Announcement, cx: &mut App) -> AnyElement {
|
fn render_card(announcement: &Announcement, cx: &mut App) -> AnyElement {
|
||||||
let name = announcement
|
let name = announcement
|
||||||
.name
|
.name
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use gpui::prelude::*;
|
||||||
|
use gpui::{App, Context, EventEmitter, FocusHandle, Focusable, Render, WeakEntity, Window};
|
||||||
|
use gpui_component::button::Button;
|
||||||
|
use gpui_component::dock::{DockArea, DockPlacement, Panel, PanelEvent};
|
||||||
|
use gpui_component::v_flex;
|
||||||
|
|
||||||
|
use crate::views::RepoListView;
|
||||||
|
|
||||||
|
/// Left-dock panel with navigation entries. Entries open content panels in
|
||||||
|
/// the dock area.
|
||||||
|
pub struct SidebarPanel {
|
||||||
|
focus_handle: FocusHandle,
|
||||||
|
dock_area: WeakEntity<DockArea>,
|
||||||
|
explore: Option<WeakEntity<RepoListView>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SidebarPanel {
|
||||||
|
pub fn new(dock_area: WeakEntity<DockArea>, cx: &mut Context<Self>) -> Self {
|
||||||
|
Self {
|
||||||
|
focus_handle: cx.focus_handle(),
|
||||||
|
dock_area,
|
||||||
|
explore: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Open the Explore (repository list) panel in the center of the dock
|
||||||
|
/// area. No-op if it's already open.
|
||||||
|
pub fn open_explore(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
if self.explore.as_ref().and_then(WeakEntity::upgrade).is_some() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let panel = cx.new(|cx| RepoListView::new(window, cx));
|
||||||
|
self.explore = Some(panel.downgrade());
|
||||||
|
|
||||||
|
self.dock_area
|
||||||
|
.update(cx, |dock_area, cx| {
|
||||||
|
dock_area.add_panel(Arc::new(panel), DockPlacement::Center, None, window, cx);
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Panel for SidebarPanel {
|
||||||
|
fn panel_name(&self) -> &'static str {
|
||||||
|
"sidebar"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn title(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
"Navigation"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn closable(&self, _cx: &App) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EventEmitter<PanelEvent> for SidebarPanel {}
|
||||||
|
|
||||||
|
impl Focusable for SidebarPanel {
|
||||||
|
fn focus_handle(&self, _cx: &App) -> FocusHandle {
|
||||||
|
self.focus_handle.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for SidebarPanel {
|
||||||
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
v_flex().gap_2().p_2().child(
|
||||||
|
Button::new("explore")
|
||||||
|
.label("Explore")
|
||||||
|
.w_full()
|
||||||
|
.on_click(cx.listener(|this, _, window, cx| this.open_explore(window, cx))),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
use gpui::prelude::*;
|
use gpui::prelude::*;
|
||||||
use gpui::{AnyView, Context, Render, SharedString, Subscription, Window, div, px};
|
use gpui::{Context, Entity, Render, SharedString, Subscription, Window, div, px};
|
||||||
use gpui_component::{ActiveTheme, StyledExt};
|
use gpui_component::dock::{DockArea, DockItem};
|
||||||
|
use gpui_component::{ActiveTheme, Root, StyledExt, TitleBar, v_flex};
|
||||||
use signed_state::{Backend, BackendEvent};
|
use signed_state::{Backend, BackendEvent};
|
||||||
|
|
||||||
use crate::views::RepoListView;
|
use crate::views::SidebarPanel;
|
||||||
|
|
||||||
/// Root view of the app: header, active screen, status bar.
|
/// Root view of the app: title bar, dock area, status bar.
|
||||||
pub struct Workspace {
|
pub struct Workspace {
|
||||||
active_screen: AnyView,
|
dock: Entity<DockArea>,
|
||||||
status: SharedString,
|
status: SharedString,
|
||||||
_subscription: Subscription,
|
_subscription: Subscription,
|
||||||
}
|
}
|
||||||
@@ -15,11 +16,34 @@ pub struct Workspace {
|
|||||||
impl Workspace {
|
impl Workspace {
|
||||||
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
let backend = Backend::global(cx);
|
let backend = Backend::global(cx);
|
||||||
let repo_list = cx.new(|cx| RepoListView::new(window, cx));
|
let dock = cx.new(|cx| DockArea::new("dock", Some(1), window, cx));
|
||||||
|
|
||||||
|
let weak_dock = dock.downgrade();
|
||||||
|
let sidebar = cx.new(|cx| SidebarPanel::new(weak_dock.clone(), cx));
|
||||||
|
|
||||||
|
dock.update(cx, |dock_area, cx| {
|
||||||
|
dock_area.set_left_dock(
|
||||||
|
DockItem::tab(sidebar.clone(), &weak_dock, window, cx),
|
||||||
|
Some(px(240.)),
|
||||||
|
true,
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
sidebar.update(cx, |sidebar, cx| sidebar.open_explore(window, cx));
|
||||||
|
|
||||||
let connected = backend.read(cx).is_connected();
|
let connected = backend.read(cx).is_connected();
|
||||||
let sync_progress = backend.read(cx).sync_progress();
|
let sync_progress = backend.read(cx).sync_progress();
|
||||||
|
|
||||||
|
let status = if let Some((total, current)) = sync_progress {
|
||||||
|
format!("Syncing repositories... {current}/{total}").into()
|
||||||
|
} else if connected {
|
||||||
|
"Connected".into()
|
||||||
|
} else {
|
||||||
|
"Connecting...".into()
|
||||||
|
};
|
||||||
|
|
||||||
let subscription = cx.subscribe(&backend, |this, _backend, event, cx| {
|
let subscription = cx.subscribe(&backend, |this, _backend, event, cx| {
|
||||||
match event {
|
match event {
|
||||||
BackendEvent::Connected => this.status = "Connected".into(),
|
BackendEvent::Connected => this.status = "Connected".into(),
|
||||||
@@ -34,41 +58,30 @@ impl Workspace {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
active_screen: repo_list.into(),
|
dock,
|
||||||
status: if let Some((total, current)) = sync_progress {
|
status,
|
||||||
format!("Syncing repositories... {current}/{total}").into()
|
|
||||||
} else if connected {
|
|
||||||
"Connected".into()
|
|
||||||
} else {
|
|
||||||
"Connecting...".into()
|
|
||||||
},
|
|
||||||
_subscription: subscription,
|
_subscription: subscription,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Render for Workspace {
|
impl Render for Workspace {
|
||||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
let dialog_layer = Root::render_dialog_layer(window, cx);
|
||||||
|
let notification_layer = Root::render_notification_layer(window, cx);
|
||||||
|
|
||||||
div()
|
div()
|
||||||
|
.id("workspace")
|
||||||
.v_flex()
|
.v_flex()
|
||||||
.size_full()
|
.size_full()
|
||||||
.bg(cx.theme().background)
|
|
||||||
.text_color(cx.theme().foreground)
|
|
||||||
.child(
|
.child(
|
||||||
div()
|
v_flex()
|
||||||
.h_flex()
|
.size_full()
|
||||||
.px_4()
|
// Title Bar
|
||||||
.py_2()
|
.child(TitleBar::new())
|
||||||
.border_b(px(1.))
|
// Dock Area
|
||||||
.border_color(cx.theme().border)
|
.child(self.dock.clone())
|
||||||
.child(div().text_lg().font_semibold().child("Signed")),
|
// Status Bar
|
||||||
)
|
|
||||||
.child(
|
|
||||||
div()
|
|
||||||
.flex_1()
|
|
||||||
.overflow_hidden()
|
|
||||||
.child(self.active_screen.clone()),
|
|
||||||
)
|
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.h_flex()
|
.h_flex()
|
||||||
@@ -82,6 +95,11 @@ impl Render for Workspace {
|
|||||||
.text_color(cx.theme().muted_foreground)
|
.text_color(cx.theme().muted_foreground)
|
||||||
.child(self.status.clone()),
|
.child(self.status.clone()),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
// Notifications
|
||||||
|
.children(notification_layer)
|
||||||
|
// Modals
|
||||||
|
.children(dialog_layer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user