From efce38fce2a940a539ca1aa81f40f38c49085bc8 Mon Sep 17 00:00:00 2001 From: KCaverly Date: Tue, 31 Oct 2023 10:04:04 -0400 Subject: [PATCH] wip --- crates/gpui2/src/app/entity_map.rs | 5 +++++ crates/workspace2/src/pane.rs | 24 ++++++++++++--------- crates/workspace2/src/pane_group.rs | 16 +++++++------- crates/workspace2/src/persistence/model.rs | 11 ++++------ crates/workspace2/src/workspace_settings.rs | 2 +- 5 files changed, 32 insertions(+), 26 deletions(-) diff --git a/crates/gpui2/src/app/entity_map.rs b/crates/gpui2/src/app/entity_map.rs index bbeabd3e4f..8ceadfe73e 100644 --- a/crates/gpui2/src/app/entity_map.rs +++ b/crates/gpui2/src/app/entity_map.rs @@ -164,6 +164,11 @@ impl AnyModel { self.entity_id } + // todo!() added for populating `ProjectItemBuilders` in `load_path` method + pub fn type_id(&self) -> TypeId { + self.entity_type + } + pub fn downgrade(&self) -> AnyWeakModel { AnyWeakModel { entity_id: self.entity_id, diff --git a/crates/workspace2/src/pane.rs b/crates/workspace2/src/pane.rs index 22aa61e6cd..9325f58b37 100644 --- a/crates/workspace2/src/pane.rs +++ b/crates/workspace2/src/pane.rs @@ -18,7 +18,10 @@ use std::{ any::Any, cmp, fmt, mem, path::PathBuf, - sync::{atomic::AtomicUsize, Arc}, + sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, + }, }; #[derive(PartialEq, Clone, Copy, Deserialize, Debug)] @@ -168,7 +171,7 @@ pub struct Pane { // zoomed: bool, active_item_index: usize, // last_focused_view_by_item: HashMap, - // autoscroll: bool, + autoscroll: bool, nav_history: NavHistory, toolbar: View, // tab_bar_context_menu: TabBarContextMenu, @@ -327,7 +330,7 @@ impl Pane { // zoomed: false, active_item_index: 0, // last_focused_view_by_item: Default::default(), - // autoscroll: false, + autoscroll: false, nav_history: NavHistory(Arc::new(Mutex::new(NavHistoryState { mode: NavigationMode::Normal, backward_stack: Default::default(), @@ -607,9 +610,9 @@ impl Pane { cx.emit(Event::AddItem { item }); } - // pub fn items_len(&self) -> usize { - // self.items.len() - // } + pub fn items_len(&self) -> usize { + self.items.len() + } // pub fn items(&self) -> impl Iterator> + DoubleEndedIterator { // self.items.iter() @@ -621,9 +624,9 @@ impl Pane { // .filter_map(|item| item.as_any().clone().downcast()) // } - // pub fn active_item(&self) -> Option> { - // self.items.get(self.active_item_index).cloned() - // } + pub fn active_item(&self) -> Option> { + self.items.get(self.active_item_index).cloned() + } // pub fn pixel_position_of_cursor(&self, cx: &AppContext) -> Option { // self.items @@ -749,7 +752,8 @@ impl Pane { save_intent: SaveIntent, cx: &mut ViewContext, ) -> Task> { - self.close_items(cx, save_intent, move |view_id| view_id == item_id_to_close) + // self.close_items(cx, save_intent, move |view_id| view_id == item_id_to_close) + todo!() } // pub fn close_inactive_items( diff --git a/crates/workspace2/src/pane_group.rs b/crates/workspace2/src/pane_group.rs index f226f7fc43..964194ef22 100644 --- a/crates/workspace2/src/pane_group.rs +++ b/crates/workspace2/src/pane_group.rs @@ -2,7 +2,7 @@ use crate::{AppState, FollowerState, Pane, Workspace}; use anyhow::{anyhow, Result}; use call2::ActiveCall; use collections::HashMap; -use gpui2::{size, AnyElement, AnyView, Bounds, Handle, Pixels, Point, View, ViewContext}; +use gpui2::{size, AnyElement, AnyView, Bounds, Handle, Model, Pixels, Point, View, ViewContext}; use project2::Project; use serde::Deserialize; use std::{cell::RefCell, rc::Rc, sync::Arc}; @@ -91,10 +91,10 @@ impl PaneGroup { pub(crate) fn render( &self, - project: &Handle, + project: &Model, theme: &Theme, follower_states: &HashMap, FollowerState>, - active_call: Option<&Handle>, + active_call: Option<&Model>, active_pane: &View, zoomed: Option<&AnyView>, app_state: &Arc, @@ -120,7 +120,7 @@ impl PaneGroup { } } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, PartialEq)] pub(crate) enum Member { Axis(PaneAxis), Pane(View), @@ -153,11 +153,11 @@ impl Member { pub fn render( &self, - project: &Handle, + project: &Model, basis: usize, theme: &Theme, follower_states: &HashMap, FollowerState>, - active_call: Option<&Handle>, + active_call: Option<&Model>, active_pane: &View, zoomed: Option<&AnyView>, app_state: &Arc, @@ -470,11 +470,11 @@ impl PaneAxis { fn render( &self, - project: &Handle, + project: &Model, basis: usize, theme: &Theme, follower_states: &HashMap, FollowerState>, - active_call: Option<&Handle>, + active_call: Option<&Model>, active_pane: &View, zoomed: Option<&AnyView>, app_state: &Arc, diff --git a/crates/workspace2/src/persistence/model.rs b/crates/workspace2/src/persistence/model.rs index 8265848497..4323e6dae0 100644 --- a/crates/workspace2/src/persistence/model.rs +++ b/crates/workspace2/src/persistence/model.rs @@ -7,7 +7,7 @@ use db2::sqlez::{ bindable::{Bind, Column, StaticColumnCount}, statement::Statement, }; -use gpui2::{AsyncAppContext, AsyncWindowContext, Handle, Task, View, WeakView, WindowBounds}; +use gpui2::{AsyncAppContext, AsyncWindowContext, Model, Task, View, WeakView, WindowBounds}; use project2::Project; use std::{ path::{Path, PathBuf}, @@ -151,7 +151,7 @@ impl SerializedPaneGroup { #[async_recursion(?Send)] pub(crate) async fn deserialize( self, - project: &Handle, + project: &Model, workspace_id: WorkspaceId, workspace: &WeakView, cx: &mut AsyncWindowContext, @@ -200,10 +200,7 @@ impl SerializedPaneGroup { .await .log_err()?; - if pane - .read_with(cx, |pane, _| pane.items_len() != 0) - .log_err()? - { + if pane.update(cx, |pane, _| pane.items_len() != 0).log_err()? { let pane = pane.upgrade()?; Some((Member::Pane(pane.clone()), active.then(|| pane), new_items)) } else { @@ -231,7 +228,7 @@ impl SerializedPane { pub async fn deserialize_to( &self, - project: &Handle, + project: &Model, pane: &WeakView, workspace_id: WorkspaceId, workspace: &WeakView, diff --git a/crates/workspace2/src/workspace_settings.rs b/crates/workspace2/src/workspace_settings.rs index 5d158e5a05..4b93b705a3 100644 --- a/crates/workspace2/src/workspace_settings.rs +++ b/crates/workspace2/src/workspace_settings.rs @@ -49,7 +49,7 @@ impl Settings for WorkspaceSettings { fn load( default_value: &Self::FileContent, user_values: &[&Self::FileContent], - _: &gpui2::AppContext, + _: &mut gpui2::AppContext, ) -> anyhow::Result { Self::load_via_json_merge(default_value, user_values) }