wip

KCaverly created

Change summary

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(-)

Detailed changes

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,

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<usize, AnyWeakViewHandle>,
-    //     autoscroll: bool,
+    autoscroll: bool,
     nav_history: NavHistory,
     toolbar: View<Toolbar>,
     //     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<Item = &Box<dyn ItemHandle>> + DoubleEndedIterator {
     //         self.items.iter()
@@ -621,9 +624,9 @@ impl Pane {
     //             .filter_map(|item| item.as_any().clone().downcast())
     //     }
 
-    //     pub fn active_item(&self) -> Option<Box<dyn ItemHandle>> {
-    //         self.items.get(self.active_item_index).cloned()
-    //     }
+    pub fn active_item(&self) -> Option<Box<dyn ItemHandle>> {
+        self.items.get(self.active_item_index).cloned()
+    }
 
     //     pub fn pixel_position_of_cursor(&self, cx: &AppContext) -> Option<Vector2F> {
     //         self.items
@@ -749,7 +752,8 @@ impl Pane {
         save_intent: SaveIntent,
         cx: &mut ViewContext<Self>,
     ) -> Task<Result<()>> {
-        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(

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>,
+        project: &Model<Project>,
         theme: &Theme,
         follower_states: &HashMap<View<Pane>, FollowerState>,
-        active_call: Option<&Handle<ActiveCall>>,
+        active_call: Option<&Model<ActiveCall>>,
         active_pane: &View<Pane>,
         zoomed: Option<&AnyView>,
         app_state: &Arc<AppState>,
@@ -120,7 +120,7 @@ impl PaneGroup {
     }
 }
 
-#[derive(Clone, Debug, PartialEq)]
+#[derive(Clone, PartialEq)]
 pub(crate) enum Member {
     Axis(PaneAxis),
     Pane(View<Pane>),
@@ -153,11 +153,11 @@ impl Member {
 
     pub fn render(
         &self,
-        project: &Handle<Project>,
+        project: &Model<Project>,
         basis: usize,
         theme: &Theme,
         follower_states: &HashMap<View<Pane>, FollowerState>,
-        active_call: Option<&Handle<ActiveCall>>,
+        active_call: Option<&Model<ActiveCall>>,
         active_pane: &View<Pane>,
         zoomed: Option<&AnyView>,
         app_state: &Arc<AppState>,
@@ -470,11 +470,11 @@ impl PaneAxis {
 
     fn render(
         &self,
-        project: &Handle<Project>,
+        project: &Model<Project>,
         basis: usize,
         theme: &Theme,
         follower_states: &HashMap<View<Pane>, FollowerState>,
-        active_call: Option<&Handle<ActiveCall>>,
+        active_call: Option<&Model<ActiveCall>>,
         active_pane: &View<Pane>,
         zoomed: Option<&AnyView>,
         app_state: &Arc<AppState>,

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>,
+        project: &Model<Project>,
         workspace_id: WorkspaceId,
         workspace: &WeakView<Workspace>,
         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>,
+        project: &Model<Project>,
         pane: &WeakView<Pane>,
         workspace_id: WorkspaceId,
         workspace: &WeakView<Workspace>,

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> {
         Self::load_via_json_merge(default_value, user_values)
     }