Uncomment enough to register the panel

This commit is contained in:
Conrad Irwin 2023-11-15 16:44:21 -07:00
parent 793fa6e3a4
commit 7f70712dac
3 changed files with 3056 additions and 3032 deletions

View file

@ -118,19 +118,16 @@
// to: ChannelId,
// }
// actions!(
// collab_panel,
// [
// ToggleFocus,
// Remove,
// Secondary,
// CollapseSelectedChannel,
// ExpandSelectedChannel,
// StartMoveChannel,
// MoveSelected,
// InsertSpace,
// ]
// );
actions!(
ToggleFocus,
Remove,
Secondary,
CollapseSelectedChannel,
ExpandSelectedChannel,
StartMoveChannel,
MoveSelected,
InsertSpace,
);
// impl_actions!(
// collab_panel,
@ -158,8 +155,22 @@
// const COLLABORATION_PANEL_KEY: &'static str = "CollaborationPanel";
// pub fn init(cx: &mut AppContext) {
// settings::register::<panel_settings::CollaborationPanelSettings>(cx);
use std::sync::Arc;
use gpui::{
actions, div, AppContext, AsyncWindowContext, Div, EventEmitter, FocusHandle, ParentComponent,
Render, Task, View, ViewContext, VisualContext, WeakView,
};
use project::Fs;
use settings::Settings;
use workspace::{
dock::{DockPosition, Panel, PanelEvent},
Workspace,
};
use crate::CollaborationPanelSettings;
pub fn init(cx: &mut AppContext) {
// contact_finder::init(cx);
// channel_modal::init(cx);
// channel_view::init(cx);
@ -243,7 +254,7 @@
// }
// },
// );
// }
}
// #[derive(Debug)]
// pub enum ChannelEditingState {
@ -266,10 +277,10 @@
// }
// }
// pub struct CollabPanel {
// width: Option<f32>,
// fs: Arc<dyn Fs>,
// has_focus: bool,
pub struct CollabPanel {
width: Option<f32>,
fs: Arc<dyn Fs>,
focus_handle: FocusHandle,
// channel_clipboard: Option<ChannelMoveClipboard>,
// pending_serialization: Task<Option<()>>,
// context_menu: ViewHandle<ContextMenu>,
@ -288,9 +299,9 @@
// collapsed_sections: Vec<Section>,
// collapsed_channels: Vec<ChannelId>,
// drag_target_channel: ChannelDragTarget,
// workspace: WeakViewHandle<Workspace>,
_workspace: WeakView<Workspace>,
// context_menu_on_selected: bool,
// }
}
// #[derive(PartialEq, Eq)]
// enum ChannelDragTarget {
@ -369,9 +380,9 @@
// type Event = Event;
// }
// impl CollabPanel {
// pub fn new(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) -> ViewHandle<Self> {
// cx.add_view::<Self, _>(|cx| {
impl CollabPanel {
pub fn new(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) -> View<Self> {
cx.build_view(|cx| {
// let view_id = cx.view_id();
// let filter_editor = cx.add_view(|cx| {
@ -562,11 +573,11 @@
// }
// });
// let mut this = Self {
// width: None,
// has_focus: false,
let this = Self {
width: None,
focus_handle: cx.focus_handle(),
// channel_clipboard: None,
// fs: workspace.app_state().fs.clone(),
fs: workspace.app_state().fs.clone(),
// pending_serialization: Task::ready(None),
// context_menu: cx.add_view(|cx| ContextMenu::new(view_id, cx)),
// channel_name_editor,
@ -581,12 +592,12 @@
// match_candidates: Vec::default(),
// collapsed_sections: vec![Section::Offline],
// collapsed_channels: Vec::default(),
// workspace: workspace.weak_handle(),
_workspace: workspace.weak_handle(),
// client: workspace.app_state().client.clone(),
// context_menu_on_selected: true,
// drag_target_channel: ChannelDragTarget::None,
// list_state,
// };
};
// this.update_entries(false, cx);
@ -638,15 +649,16 @@
// },
// ));
// this
// })
// }
this
})
}
// pub fn load(
// workspace: WeakViewHandle<Workspace>,
// cx: AsyncAppContext,
// ) -> Task<Result<ViewHandle<Self>>> {
// cx.spawn(|mut cx| async move {
pub fn load(
workspace: WeakView<Workspace>,
cx: AsyncWindowContext,
) -> Task<anyhow::Result<View<Self>>> {
cx.spawn(|mut cx| async move {
// todo!()
// let serialized_panel = if let Some(panel) = cx
// .background()
// .spawn(async move { KEY_VALUE_STORE.read_kvp(COLLABORATION_PANEL_KEY) })
@ -665,8 +677,8 @@
// None
// };
// workspace.update(&mut cx, |workspace, cx| {
// let panel = CollabPanel::new(workspace, cx);
workspace.update(&mut cx, |workspace, cx| {
let panel = CollabPanel::new(workspace, cx);
// if let Some(serialized_panel) = serialized_panel {
// panel.update(cx, |panel, cx| {
// panel.width = serialized_panel.width;
@ -676,10 +688,10 @@
// cx.notify();
// });
// }
// panel
// })
// })
// }
panel
})
})
}
// fn serialize(&mut self, cx: &mut ViewContext<Self>) {
// let width = self.width;
@ -3233,7 +3245,7 @@
// let item = ClipboardItem::new(channel.link());
// cx.write_to_clipboard(item)
// }
// }
}
// fn render_tree_branch(
// branch_style: theme::TreeBranch,
@ -3280,6 +3292,14 @@
// .with_width(size.x())
// }
impl Render for CollabPanel {
type Element = Div<Self>;
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
div().child("COLLAB PANEL")
}
}
// impl View for CollabPanel {
// fn ui_name() -> &'static str {
// "CollabPanel"
@ -3379,59 +3399,62 @@
// }
// }
// impl Panel for CollabPanel {
// fn position(&self, cx: &gpui::WindowContext) -> DockPosition {
// settings::get::<CollaborationPanelSettings>(cx).dock
// }
impl EventEmitter<PanelEvent> for CollabPanel {}
// fn position_is_valid(&self, position: DockPosition) -> bool {
// matches!(position, DockPosition::Left | DockPosition::Right)
// }
impl Panel for CollabPanel {
fn position(&self, cx: &gpui::WindowContext) -> DockPosition {
CollaborationPanelSettings::get_global(cx).dock
}
// fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>) {
// settings::update_settings_file::<CollaborationPanelSettings>(
// self.fs.clone(),
// cx,
// move |settings| settings.dock = Some(position),
// );
// }
fn position_is_valid(&self, position: DockPosition) -> bool {
matches!(position, DockPosition::Left | DockPosition::Right)
}
// fn size(&self, cx: &gpui::WindowContext) -> f32 {
// self.width
// .unwrap_or_else(|| settings::get::<CollaborationPanelSettings>(cx).default_width)
// }
fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>) {
settings::update_settings_file::<CollaborationPanelSettings>(
self.fs.clone(),
cx,
move |settings| settings.dock = Some(position),
);
}
// fn set_size(&mut self, size: Option<f32>, cx: &mut ViewContext<Self>) {
// self.width = size;
fn size(&self, cx: &gpui::WindowContext) -> f32 {
self.width
.unwrap_or_else(|| CollaborationPanelSettings::get_global(cx).default_width)
}
fn set_size(&mut self, size: Option<f32>, cx: &mut ViewContext<Self>) {
self.width = size;
// todo!()
// self.serialize(cx);
// cx.notify();
// }
cx.notify();
}
// fn icon_path(&self, cx: &gpui::WindowContext) -> Option<&'static str> {
// settings::get::<CollaborationPanelSettings>(cx)
// .button
// .then(|| "icons/user_group_16.svg")
// }
fn icon_path(&self, cx: &gpui::WindowContext) -> Option<&'static str> {
CollaborationPanelSettings::get_global(cx)
.button
.then(|| "icons/user_group_16.svg")
}
// fn icon_tooltip(&self) -> (String, Option<Box<dyn gpui::Action>>) {
// (
// "Collaboration Panel".to_string(),
// Some(Box::new(ToggleFocus)),
// )
// }
fn icon_tooltip(&self) -> (String, Option<Box<dyn gpui::Action>>) {
(
"Collaboration Panel".to_string(),
Some(Box::new(ToggleFocus)),
)
}
// fn should_change_position_on_event(event: &Self::Event) -> bool {
// matches!(event, Event::DockPositionChanged)
// }
fn has_focus(&self, cx: &gpui::WindowContext) -> bool {
self.focus_handle.contains_focused(cx)
}
// fn has_focus(&self, _cx: &gpui::WindowContext) -> bool {
// self.has_focus
// }
fn persistent_name(&self) -> &'static str {
"Collab Panel"
}
// fn is_focus_event(event: &Self::Event) -> bool {
// matches!(event, Event::Focus)
// }
// }
fn focus_handle(&self, cx: &ui::prelude::WindowContext) -> gpui::FocusHandle {
self.focus_handle.clone()
}
}
// impl PartialEq for ListEntry {
// fn eq(&self, other: &Self) -> bool {

View file

@ -9,6 +9,7 @@ mod panel_settings;
use std::sync::Arc;
pub use collab_panel::CollabPanel;
pub use collab_titlebar_item::CollabTitlebarItem;
use gpui::AppContext;
pub use panel_settings::{
@ -29,7 +30,7 @@ pub fn init(_app_state: &Arc<AppState>, cx: &mut AppContext) {
// vcs_menu::init(cx);
collab_titlebar_item::init(cx);
// collab_panel::init(cx);
collab_panel::init(cx);
// chat_panel::init(cx);
// notifications::init(&app_state, cx);

View file

@ -383,8 +383,8 @@ pub fn initialize_workspace(
let project_panel = ProjectPanel::load(workspace_handle.clone(), cx.clone());
// let terminal_panel = TerminalPanel::load(workspace_handle.clone(), cx.clone());
// let assistant_panel = AssistantPanel::load(workspace_handle.clone(), cx.clone());
// let channels_panel =
// collab_ui::collab_panel::CollabPanel::load(workspace_handle.clone(), cx.clone());
let channels_panel =
collab_ui::collab_panel::CollabPanel::load(workspace_handle.clone(), cx.clone());
// let chat_panel =
// collab_ui::chat_panel::ChatPanel::load(workspace_handle.clone(), cx.clone());
// let notification_panel = collab_ui::notification_panel::NotificationPanel::load(
@ -395,16 +395,16 @@ pub fn initialize_workspace(
project_panel,
// terminal_panel,
// assistant_panel,
// channels_panel,
channels_panel,
// chat_panel,
// notification_panel,
) = futures::try_join!(
project_panel,
// terminal_panel,
// assistant_panel,
// channels_panel,
channels_panel,
// chat_panel,
// notification_panel,
// notification_panel,/
)?;
workspace_handle.update(&mut cx, |workspace, cx| {
@ -412,7 +412,7 @@ pub fn initialize_workspace(
workspace.add_panel(project_panel, cx);
// workspace.add_panel(terminal_panel, cx);
// workspace.add_panel(assistant_panel, cx);
// workspace.add_panel(channels_panel, cx);
workspace.add_panel(channels_panel, cx);
// workspace.add_panel(chat_panel, cx);
// workspace.add_panel(notification_panel, cx);