Restore auto-save on focus change, re-enable workspace tests
This commit is contained in:
parent
c63ca09eed
commit
a003a91212
13 changed files with 1350 additions and 1304 deletions
|
@ -2,8 +2,8 @@ use crate::{
|
||||||
div, Action, AnyView, AnyWindowHandle, AppCell, AppContext, AsyncAppContext,
|
div, Action, AnyView, AnyWindowHandle, AppCell, AppContext, AsyncAppContext,
|
||||||
BackgroundExecutor, Context, Div, Entity, EventEmitter, ForegroundExecutor, InputEvent,
|
BackgroundExecutor, Context, Div, Entity, EventEmitter, ForegroundExecutor, InputEvent,
|
||||||
KeyDownEvent, Keystroke, Model, ModelContext, Render, Result, Task, TestDispatcher,
|
KeyDownEvent, Keystroke, Model, ModelContext, Render, Result, Task, TestDispatcher,
|
||||||
TestPlatform, TestWindow, View, ViewContext, VisualContext, WindowContext, WindowHandle,
|
TestPlatform, TestWindow, TestWindowHandlers, View, ViewContext, VisualContext, WindowContext,
|
||||||
WindowOptions,
|
WindowHandle, WindowOptions,
|
||||||
};
|
};
|
||||||
use anyhow::{anyhow, bail};
|
use anyhow::{anyhow, bail};
|
||||||
use futures::{Stream, StreamExt};
|
use futures::{Stream, StreamExt};
|
||||||
|
@ -509,6 +509,39 @@ impl<'a> VisualTestContext<'a> {
|
||||||
pub fn simulate_input(&mut self, input: &str) {
|
pub fn simulate_input(&mut self, input: &str) {
|
||||||
self.cx.simulate_input(self.window, input)
|
self.cx.simulate_input(self.window, input)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn simulate_activation(&mut self) {
|
||||||
|
self.simulate_window_events(&mut |handlers| {
|
||||||
|
handlers
|
||||||
|
.active_status_change
|
||||||
|
.iter_mut()
|
||||||
|
.for_each(|f| f(true));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn simulate_deactivation(&mut self) {
|
||||||
|
self.simulate_window_events(&mut |handlers| {
|
||||||
|
handlers
|
||||||
|
.active_status_change
|
||||||
|
.iter_mut()
|
||||||
|
.for_each(|f| f(false));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn simulate_window_events(&mut self, f: &mut dyn FnMut(&mut TestWindowHandlers)) {
|
||||||
|
let handlers = self
|
||||||
|
.cx
|
||||||
|
.update_window(self.window, |_, cx| {
|
||||||
|
cx.window
|
||||||
|
.platform_window
|
||||||
|
.as_test()
|
||||||
|
.unwrap()
|
||||||
|
.handlers
|
||||||
|
.clone()
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
f(&mut *handlers.lock());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Context for VisualTestContext<'a> {
|
impl<'a> Context for VisualTestContext<'a> {
|
||||||
|
|
|
@ -158,6 +158,11 @@ pub(crate) trait PlatformWindow {
|
||||||
fn draw(&self, scene: Scene);
|
fn draw(&self, scene: Scene);
|
||||||
|
|
||||||
fn sprite_atlas(&self) -> Arc<dyn PlatformAtlas>;
|
fn sprite_atlas(&self) -> Arc<dyn PlatformAtlas>;
|
||||||
|
|
||||||
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
|
fn as_test(&self) -> Option<&TestWindow> {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait PlatformDispatcher: Send + Sync {
|
pub trait PlatformDispatcher: Send + Sync {
|
||||||
|
|
|
@ -189,13 +189,9 @@ impl Platform for TestPlatform {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_become_active(&self, _callback: Box<dyn FnMut()>) {
|
fn on_become_active(&self, _callback: Box<dyn FnMut()>) {}
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn on_resign_active(&self, _callback: Box<dyn FnMut()>) {
|
fn on_resign_active(&self, _callback: Box<dyn FnMut()>) {}
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn on_quit(&self, _callback: Box<dyn FnMut()>) {}
|
fn on_quit(&self, _callback: Box<dyn FnMut()>) {}
|
||||||
|
|
||||||
|
|
|
@ -11,11 +11,11 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct Handlers {
|
pub(crate) struct TestWindowHandlers {
|
||||||
active_status_change: Vec<Box<dyn FnMut(bool)>>,
|
pub(crate) active_status_change: Vec<Box<dyn FnMut(bool)>>,
|
||||||
input: Vec<Box<dyn FnMut(crate::InputEvent) -> bool>>,
|
pub(crate) input: Vec<Box<dyn FnMut(crate::InputEvent) -> bool>>,
|
||||||
moved: Vec<Box<dyn FnMut()>>,
|
pub(crate) moved: Vec<Box<dyn FnMut()>>,
|
||||||
resize: Vec<Box<dyn FnMut(Size<Pixels>, f32)>>,
|
pub(crate) resize: Vec<Box<dyn FnMut(Size<Pixels>, f32)>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TestWindow {
|
pub struct TestWindow {
|
||||||
|
@ -23,7 +23,7 @@ pub struct TestWindow {
|
||||||
current_scene: Mutex<Option<Scene>>,
|
current_scene: Mutex<Option<Scene>>,
|
||||||
display: Rc<dyn PlatformDisplay>,
|
display: Rc<dyn PlatformDisplay>,
|
||||||
pub(crate) input_handler: Option<Arc<Mutex<Box<dyn PlatformInputHandler>>>>,
|
pub(crate) input_handler: Option<Arc<Mutex<Box<dyn PlatformInputHandler>>>>,
|
||||||
handlers: Mutex<Handlers>,
|
pub(crate) handlers: Arc<Mutex<TestWindowHandlers>>,
|
||||||
platform: Weak<TestPlatform>,
|
platform: Weak<TestPlatform>,
|
||||||
sprite_atlas: Arc<dyn PlatformAtlas>,
|
sprite_atlas: Arc<dyn PlatformAtlas>,
|
||||||
}
|
}
|
||||||
|
@ -167,6 +167,10 @@ impl PlatformWindow for TestWindow {
|
||||||
fn sprite_atlas(&self) -> sync::Arc<dyn crate::PlatformAtlas> {
|
fn sprite_atlas(&self) -> sync::Arc<dyn crate::PlatformAtlas> {
|
||||||
self.sprite_atlas.clone()
|
self.sprite_atlas.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn as_test(&self) -> Option<&TestWindow> {
|
||||||
|
Some(self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TestAtlasState {
|
pub struct TestAtlasState {
|
||||||
|
|
|
@ -10,29 +10,29 @@ doctest = false
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
test-support = [
|
test-support = [
|
||||||
"call2/test-support",
|
"call/test-support",
|
||||||
"client2/test-support",
|
"client/test-support",
|
||||||
"project2/test-support",
|
"project/test-support",
|
||||||
"settings2/test-support",
|
"settings/test-support",
|
||||||
"gpui/test-support",
|
"gpui/test-support",
|
||||||
"fs2/test-support"
|
"fs/test-support"
|
||||||
]
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
db2 = { path = "../db2" }
|
db = { path = "../db2", package = "db2" }
|
||||||
client2 = { path = "../client2" }
|
client = { path = "../client2", package = "client2" }
|
||||||
collections = { path = "../collections" }
|
collections = { path = "../collections" }
|
||||||
# context_menu = { path = "../context_menu" }
|
# context_menu = { path = "../context_menu" }
|
||||||
fs2 = { path = "../fs2" }
|
fs = { path = "../fs2", package = "fs2" }
|
||||||
gpui = { package = "gpui2", path = "../gpui2" }
|
gpui = { package = "gpui2", path = "../gpui2" }
|
||||||
install_cli2 = { path = "../install_cli2" }
|
install_cli = { path = "../install_cli2", package = "install_cli2" }
|
||||||
language2 = { path = "../language2" }
|
language = { path = "../language2", package = "language2" }
|
||||||
#menu = { path = "../menu" }
|
#menu = { path = "../menu" }
|
||||||
node_runtime = { path = "../node_runtime" }
|
node_runtime = { path = "../node_runtime" }
|
||||||
project2 = { path = "../project2" }
|
project = { path = "../project2", package = "project2" }
|
||||||
settings2 = { path = "../settings2" }
|
settings = { path = "../settings2", package = "settings2" }
|
||||||
terminal2 = { path = "../terminal2" }
|
terminal = { path = "../terminal2", package = "terminal2" }
|
||||||
theme2 = { path = "../theme2" }
|
theme = { path = "../theme2", package = "theme2" }
|
||||||
util = { path = "../util" }
|
util = { path = "../util" }
|
||||||
ui = { package = "ui2", path = "../ui2" }
|
ui = { package = "ui2", path = "../ui2" }
|
||||||
|
|
||||||
|
@ -54,13 +54,13 @@ smallvec.workspace = true
|
||||||
uuid.workspace = true
|
uuid.workspace = true
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
call2 = { path = "../call2", features = ["test-support"] }
|
call = { path = "../call2", package = "call2", features = ["test-support"] }
|
||||||
client2 = { path = "../client2", features = ["test-support"] }
|
client = { path = "../client2", package = "client2", features = ["test-support"] }
|
||||||
gpui = { package = "gpui2", path = "../gpui2", features = ["test-support"] }
|
gpui = { path = "../gpui2", package = "gpui2", features = ["test-support"] }
|
||||||
project2 = { path = "../project2", features = ["test-support"] }
|
project = { path = "../project2", package = "project2", features = ["test-support"] }
|
||||||
settings2 = { path = "../settings2", features = ["test-support"] }
|
settings = { path = "../settings2", package = "settings2", features = ["test-support"] }
|
||||||
fs2 = { path = "../fs2", features = ["test-support"] }
|
fs = { path = "../fs2", package = "fs2", features = ["test-support"] }
|
||||||
db2 = { path = "../db2", features = ["test-support"] }
|
db = { path = "../db2", package = "db2", features = ["test-support"] }
|
||||||
|
|
||||||
indoc.workspace = true
|
indoc.workspace = true
|
||||||
env_logger.workspace = true
|
env_logger.workspace = true
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
||||||
ViewId, Workspace, WorkspaceId,
|
ViewId, Workspace, WorkspaceId,
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use client2::{
|
use client::{
|
||||||
proto::{self, PeerId},
|
proto::{self, PeerId},
|
||||||
Client,
|
Client,
|
||||||
};
|
};
|
||||||
|
@ -16,10 +16,10 @@ use gpui::{
|
||||||
HighlightStyle, Model, Pixels, Point, SharedString, Task, View, ViewContext, WeakView,
|
HighlightStyle, Model, Pixels, Point, SharedString, Task, View, ViewContext, WeakView,
|
||||||
WindowContext,
|
WindowContext,
|
||||||
};
|
};
|
||||||
use project2::{Project, ProjectEntryId, ProjectPath};
|
use project::{Project, ProjectEntryId, ProjectPath};
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use settings2::Settings;
|
use settings::Settings;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::{
|
use std::{
|
||||||
any::{Any, TypeId},
|
any::{Any, TypeId},
|
||||||
|
@ -33,7 +33,7 @@ use std::{
|
||||||
},
|
},
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
use theme2::Theme;
|
use theme::Theme;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct ItemSettings {
|
pub struct ItemSettings {
|
||||||
|
@ -110,7 +110,7 @@ pub trait Item: FocusableView + EventEmitter<ItemEvent> {
|
||||||
fn for_each_project_item(
|
fn for_each_project_item(
|
||||||
&self,
|
&self,
|
||||||
_: &AppContext,
|
_: &AppContext,
|
||||||
_: &mut dyn FnMut(EntityId, &dyn project2::Item),
|
_: &mut dyn FnMut(EntityId, &dyn project::Item),
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
fn is_singleton(&self, _cx: &AppContext) -> bool {
|
fn is_singleton(&self, _cx: &AppContext) -> bool {
|
||||||
|
@ -222,7 +222,7 @@ pub trait ItemHandle: 'static + Send {
|
||||||
fn for_each_project_item(
|
fn for_each_project_item(
|
||||||
&self,
|
&self,
|
||||||
_: &AppContext,
|
_: &AppContext,
|
||||||
_: &mut dyn FnMut(EntityId, &dyn project2::Item),
|
_: &mut dyn FnMut(EntityId, &dyn project::Item),
|
||||||
);
|
);
|
||||||
fn is_singleton(&self, cx: &AppContext) -> bool;
|
fn is_singleton(&self, cx: &AppContext) -> bool;
|
||||||
fn boxed_clone(&self) -> Box<dyn ItemHandle>;
|
fn boxed_clone(&self) -> Box<dyn ItemHandle>;
|
||||||
|
@ -347,7 +347,7 @@ impl<T: Item> ItemHandle for View<T> {
|
||||||
fn for_each_project_item(
|
fn for_each_project_item(
|
||||||
&self,
|
&self,
|
||||||
cx: &AppContext,
|
cx: &AppContext,
|
||||||
f: &mut dyn FnMut(EntityId, &dyn project2::Item),
|
f: &mut dyn FnMut(EntityId, &dyn project::Item),
|
||||||
) {
|
) {
|
||||||
self.read(cx).for_each_project_item(cx, f)
|
self.read(cx).for_each_project_item(cx, f)
|
||||||
}
|
}
|
||||||
|
@ -375,6 +375,7 @@ impl<T: Item> ItemHandle for View<T> {
|
||||||
pane: View<Pane>,
|
pane: View<Pane>,
|
||||||
cx: &mut ViewContext<Workspace>,
|
cx: &mut ViewContext<Workspace>,
|
||||||
) {
|
) {
|
||||||
|
let weak_item = self.downgrade();
|
||||||
let history = pane.read(cx).nav_history_for_item(self);
|
let history = pane.read(cx).nav_history_for_item(self);
|
||||||
self.update(cx, |this, cx| {
|
self.update(cx, |this, cx| {
|
||||||
this.set_nav_history(history, cx);
|
this.set_nav_history(history, cx);
|
||||||
|
@ -491,16 +492,15 @@ impl<T: Item> ItemHandle for View<T> {
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// todo!()
|
cx.on_blur(&self.focus_handle(cx), move |workspace, cx| {
|
||||||
// cx.observe_focus(self, move |workspace, item, focused, cx| {
|
if WorkspaceSettings::get_global(cx).autosave == AutosaveSetting::OnFocusChange {
|
||||||
// if !focused
|
if let Some(item) = weak_item.upgrade() {
|
||||||
// && WorkspaceSettings::get_global(cx).autosave == AutosaveSetting::OnFocusChange
|
Pane::autosave_item(&item, workspace.project.clone(), cx)
|
||||||
// {
|
.detach_and_log_err(cx);
|
||||||
// Pane::autosave_item(&item, workspace.project.clone(), cx)
|
}
|
||||||
// .detach_and_log_err(cx);
|
}
|
||||||
// }
|
})
|
||||||
// })
|
.detach();
|
||||||
// .detach();
|
|
||||||
|
|
||||||
let item_id = self.item_id();
|
let item_id = self.item_id();
|
||||||
cx.observe_release(self, move |workspace, _, _| {
|
cx.observe_release(self, move |workspace, _, _| {
|
||||||
|
@ -640,7 +640,7 @@ impl<T: Item> WeakItemHandle for WeakView<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ProjectItem: Item {
|
pub trait ProjectItem: Item {
|
||||||
type Item: project2::Item;
|
type Item: project::Item;
|
||||||
|
|
||||||
fn for_project_item(
|
fn for_project_item(
|
||||||
project: Model<Project>,
|
project: Model<Project>,
|
||||||
|
@ -759,300 +759,310 @@ impl<T: FollowableItem> FollowableItemHandle for View<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
// pub mod test {
|
pub mod test {
|
||||||
// use super::{Item, ItemEvent};
|
use super::{Item, ItemEvent};
|
||||||
// use crate::{ItemId, ItemNavHistory, Pane, Workspace, WorkspaceId};
|
use crate::{ItemId, ItemNavHistory, Pane, Workspace, WorkspaceId};
|
||||||
// use gpui::{
|
use gpui::{
|
||||||
// elements::Empty, AnyElement, AppContext, Element, Entity, Model, Task, View,
|
AnyElement, AppContext, Context as _, Div, EntityId, EventEmitter, FocusableView,
|
||||||
// ViewContext, View, WeakViewHandle,
|
IntoElement, Model, Render, SharedString, Task, View, ViewContext, VisualContext, WeakView,
|
||||||
// };
|
};
|
||||||
// use project2::{Project, ProjectEntryId, ProjectPath, WorktreeId};
|
use project::{Project, ProjectEntryId, ProjectPath, WorktreeId};
|
||||||
// use smallvec::SmallVec;
|
use std::{any::Any, cell::Cell, path::Path};
|
||||||
// use std::{any::Any, borrow::Cow, cell::Cell, path::Path};
|
|
||||||
|
|
||||||
// pub struct TestProjectItem {
|
pub struct TestProjectItem {
|
||||||
// pub entry_id: Option<ProjectEntryId>,
|
pub entry_id: Option<ProjectEntryId>,
|
||||||
// pub project_path: Option<ProjectPath>,
|
pub project_path: Option<ProjectPath>,
|
||||||
// }
|
}
|
||||||
|
|
||||||
// pub struct TestItem {
|
pub struct TestItem {
|
||||||
// pub workspace_id: WorkspaceId,
|
pub workspace_id: WorkspaceId,
|
||||||
// pub state: String,
|
pub state: String,
|
||||||
// pub label: String,
|
pub label: String,
|
||||||
// pub save_count: usize,
|
pub save_count: usize,
|
||||||
// pub save_as_count: usize,
|
pub save_as_count: usize,
|
||||||
// pub reload_count: usize,
|
pub reload_count: usize,
|
||||||
// pub is_dirty: bool,
|
pub is_dirty: bool,
|
||||||
// pub is_singleton: bool,
|
pub is_singleton: bool,
|
||||||
// pub has_conflict: bool,
|
pub has_conflict: bool,
|
||||||
// pub project_items: Vec<Model<TestProjectItem>>,
|
pub project_items: Vec<Model<TestProjectItem>>,
|
||||||
// pub nav_history: Option<ItemNavHistory>,
|
pub nav_history: Option<ItemNavHistory>,
|
||||||
// pub tab_descriptions: Option<Vec<&'static str>>,
|
pub tab_descriptions: Option<Vec<&'static str>>,
|
||||||
// pub tab_detail: Cell<Option<usize>>,
|
pub tab_detail: Cell<Option<usize>>,
|
||||||
// }
|
focus_handle: gpui::FocusHandle,
|
||||||
|
}
|
||||||
|
|
||||||
// impl Entity for TestProjectItem {
|
impl project::Item for TestProjectItem {
|
||||||
// type Event = ();
|
fn entry_id(&self, _: &AppContext) -> Option<ProjectEntryId> {
|
||||||
// }
|
self.entry_id
|
||||||
|
}
|
||||||
|
|
||||||
// impl project2::Item for TestProjectItem {
|
fn project_path(&self, _: &AppContext) -> Option<ProjectPath> {
|
||||||
// fn entry_id(&self, _: &AppContext) -> Option<ProjectEntryId> {
|
self.project_path.clone()
|
||||||
// self.entry_id
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// fn project_path(&self, _: &AppContext) -> Option<ProjectPath> {
|
pub enum TestItemEvent {
|
||||||
// self.project_path.clone()
|
Edit,
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// pub enum TestItemEvent {
|
// impl Clone for TestItem {
|
||||||
// Edit,
|
// fn clone(&self) -> Self {
|
||||||
// }
|
// Self {
|
||||||
|
// state: self.state.clone(),
|
||||||
|
// label: self.label.clone(),
|
||||||
|
// save_count: self.save_count,
|
||||||
|
// save_as_count: self.save_as_count,
|
||||||
|
// reload_count: self.reload_count,
|
||||||
|
// is_dirty: self.is_dirty,
|
||||||
|
// is_singleton: self.is_singleton,
|
||||||
|
// has_conflict: self.has_conflict,
|
||||||
|
// project_items: self.project_items.clone(),
|
||||||
|
// nav_history: None,
|
||||||
|
// tab_descriptions: None,
|
||||||
|
// tab_detail: Default::default(),
|
||||||
|
// workspace_id: self.workspace_id,
|
||||||
|
// focus_handle: self.focus_handle.clone(),
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// impl Clone for TestItem {
|
impl TestProjectItem {
|
||||||
// fn clone(&self) -> Self {
|
pub fn new(id: u64, path: &str, cx: &mut AppContext) -> Model<Self> {
|
||||||
// Self {
|
let entry_id = Some(ProjectEntryId::from_proto(id));
|
||||||
// state: self.state.clone(),
|
let project_path = Some(ProjectPath {
|
||||||
// label: self.label.clone(),
|
worktree_id: WorktreeId::from_usize(0),
|
||||||
// save_count: self.save_count,
|
path: Path::new(path).into(),
|
||||||
// save_as_count: self.save_as_count,
|
});
|
||||||
// reload_count: self.reload_count,
|
cx.build_model(|_| Self {
|
||||||
// is_dirty: self.is_dirty,
|
entry_id,
|
||||||
// is_singleton: self.is_singleton,
|
project_path,
|
||||||
// has_conflict: self.has_conflict,
|
})
|
||||||
// project_items: self.project_items.clone(),
|
}
|
||||||
// nav_history: None,
|
|
||||||
// tab_descriptions: None,
|
|
||||||
// tab_detail: Default::default(),
|
|
||||||
// workspace_id: self.workspace_id,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// impl TestProjectItem {
|
pub fn new_untitled(cx: &mut AppContext) -> Model<Self> {
|
||||||
// pub fn new(id: u64, path: &str, cx: &mut AppContext) -> Model<Self> {
|
cx.build_model(|_| Self {
|
||||||
// let entry_id = Some(ProjectEntryId::from_proto(id));
|
project_path: None,
|
||||||
// let project_path = Some(ProjectPath {
|
entry_id: None,
|
||||||
// worktree_id: WorktreeId::from_usize(0),
|
})
|
||||||
// path: Path::new(path).into(),
|
}
|
||||||
// });
|
}
|
||||||
// cx.add_model(|_| Self {
|
|
||||||
// entry_id,
|
|
||||||
// project_path,
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn new_untitled(cx: &mut AppContext) -> Model<Self> {
|
impl TestItem {
|
||||||
// cx.add_model(|_| Self {
|
pub fn new(cx: &mut ViewContext<Self>) -> Self {
|
||||||
// project_path: None,
|
Self {
|
||||||
// entry_id: None,
|
state: String::new(),
|
||||||
// })
|
label: String::new(),
|
||||||
// }
|
save_count: 0,
|
||||||
// }
|
save_as_count: 0,
|
||||||
|
reload_count: 0,
|
||||||
|
is_dirty: false,
|
||||||
|
has_conflict: false,
|
||||||
|
project_items: Vec::new(),
|
||||||
|
is_singleton: true,
|
||||||
|
nav_history: None,
|
||||||
|
tab_descriptions: None,
|
||||||
|
tab_detail: Default::default(),
|
||||||
|
workspace_id: 0,
|
||||||
|
focus_handle: cx.focus_handle(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// impl TestItem {
|
pub fn new_deserialized(id: WorkspaceId, cx: &mut ViewContext<Self>) -> Self {
|
||||||
// pub fn new() -> Self {
|
let mut this = Self::new(cx);
|
||||||
// Self {
|
this.workspace_id = id;
|
||||||
// state: String::new(),
|
this
|
||||||
// label: String::new(),
|
}
|
||||||
// save_count: 0,
|
|
||||||
// save_as_count: 0,
|
|
||||||
// reload_count: 0,
|
|
||||||
// is_dirty: false,
|
|
||||||
// has_conflict: false,
|
|
||||||
// project_items: Vec::new(),
|
|
||||||
// is_singleton: true,
|
|
||||||
// nav_history: None,
|
|
||||||
// tab_descriptions: None,
|
|
||||||
// tab_detail: Default::default(),
|
|
||||||
// workspace_id: 0,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn new_deserialized(id: WorkspaceId) -> Self {
|
pub fn with_label(mut self, state: &str) -> Self {
|
||||||
// let mut this = Self::new();
|
self.label = state.to_string();
|
||||||
// this.workspace_id = id;
|
self
|
||||||
// this
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn with_label(mut self, state: &str) -> Self {
|
pub fn with_singleton(mut self, singleton: bool) -> Self {
|
||||||
// self.label = state.to_string();
|
self.is_singleton = singleton;
|
||||||
// self
|
self
|
||||||
// }
|
}
|
||||||
|
|
||||||
// pub fn with_singleton(mut self, singleton: bool) -> Self {
|
pub fn with_dirty(mut self, dirty: bool) -> Self {
|
||||||
// self.is_singleton = singleton;
|
self.is_dirty = dirty;
|
||||||
// self
|
self
|
||||||
// }
|
}
|
||||||
|
|
||||||
// pub fn with_dirty(mut self, dirty: bool) -> Self {
|
pub fn with_conflict(mut self, has_conflict: bool) -> Self {
|
||||||
// self.is_dirty = dirty;
|
self.has_conflict = has_conflict;
|
||||||
// self
|
self
|
||||||
// }
|
}
|
||||||
|
|
||||||
// pub fn with_conflict(mut self, has_conflict: bool) -> Self {
|
pub fn with_project_items(mut self, items: &[Model<TestProjectItem>]) -> Self {
|
||||||
// self.has_conflict = has_conflict;
|
self.project_items.clear();
|
||||||
// self
|
self.project_items.extend(items.iter().cloned());
|
||||||
// }
|
self
|
||||||
|
}
|
||||||
|
|
||||||
// pub fn with_project_items(mut self, items: &[Model<TestProjectItem>]) -> Self {
|
pub fn set_state(&mut self, state: String, cx: &mut ViewContext<Self>) {
|
||||||
// self.project_items.clear();
|
self.push_to_nav_history(cx);
|
||||||
// self.project_items.extend(items.iter().cloned());
|
self.state = state;
|
||||||
// self
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn set_state(&mut self, state: String, cx: &mut ViewContext<Self>) {
|
fn push_to_nav_history(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
// self.push_to_nav_history(cx);
|
if let Some(history) = &mut self.nav_history {
|
||||||
// self.state = state;
|
history.push(Some(Box::new(self.state.clone())), cx);
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// fn push_to_nav_history(&mut self, cx: &mut ViewContext<Self>) {
|
impl Render for TestItem {
|
||||||
// if let Some(history) = &mut self.nav_history {
|
type Element = Div;
|
||||||
// history.push(Some(Box::new(self.state.clone())), cx);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// impl Entity for TestItem {
|
fn render(&mut self, _: &mut ViewContext<Self>) -> Self::Element {
|
||||||
// type Event = TestItemEvent;
|
gpui::div()
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// impl View for TestItem {
|
impl EventEmitter<ItemEvent> for TestItem {}
|
||||||
// fn ui_name() -> &'static str {
|
|
||||||
// "TestItem"
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
|
impl FocusableView for TestItem {
|
||||||
// Empty::new().into_any()
|
fn focus_handle(&self, cx: &AppContext) -> gpui::FocusHandle {
|
||||||
// }
|
self.focus_handle.clone()
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// impl Item for TestItem {
|
impl Item for TestItem {
|
||||||
// fn tab_description(&self, detail: usize, _: &AppContext) -> Option<Cow<str>> {
|
fn tab_description(&self, detail: usize, _: &AppContext) -> Option<SharedString> {
|
||||||
// self.tab_descriptions.as_ref().and_then(|descriptions| {
|
self.tab_descriptions.as_ref().and_then(|descriptions| {
|
||||||
// let description = *descriptions.get(detail).or_else(|| descriptions.last())?;
|
let description = *descriptions.get(detail).or_else(|| descriptions.last())?;
|
||||||
// Some(description.into())
|
Some(description.into())
|
||||||
// })
|
})
|
||||||
// }
|
}
|
||||||
|
|
||||||
// fn tab_content<V: 'static>(
|
fn tab_content(
|
||||||
// &self,
|
&self,
|
||||||
// detail: Option<usize>,
|
detail: Option<usize>,
|
||||||
// _: &theme2::Tab,
|
cx: &ui::prelude::WindowContext,
|
||||||
// _: &AppContext,
|
) -> AnyElement {
|
||||||
// ) -> AnyElement<V> {
|
self.tab_detail.set(detail);
|
||||||
// self.tab_detail.set(detail);
|
gpui::div().into_any_element()
|
||||||
// Empty::new().into_any()
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// fn for_each_project_item(
|
fn for_each_project_item(
|
||||||
// &self,
|
&self,
|
||||||
// cx: &AppContext,
|
cx: &AppContext,
|
||||||
// f: &mut dyn FnMut(usize, &dyn project2::Item),
|
f: &mut dyn FnMut(EntityId, &dyn project::Item),
|
||||||
// ) {
|
) {
|
||||||
// self.project_items
|
self.project_items
|
||||||
// .iter()
|
.iter()
|
||||||
// .for_each(|item| f(item.id(), item.read(cx)))
|
.for_each(|item| f(item.entity_id(), item.read(cx)))
|
||||||
// }
|
}
|
||||||
|
|
||||||
// fn is_singleton(&self, _: &AppContext) -> bool {
|
fn is_singleton(&self, _: &AppContext) -> bool {
|
||||||
// self.is_singleton
|
self.is_singleton
|
||||||
// }
|
}
|
||||||
|
|
||||||
// fn set_nav_history(&mut self, history: ItemNavHistory, _: &mut ViewContext<Self>) {
|
fn set_nav_history(&mut self, history: ItemNavHistory, _: &mut ViewContext<Self>) {
|
||||||
// self.nav_history = Some(history);
|
self.nav_history = Some(history);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// fn navigate(&mut self, state: Box<dyn Any>, _: &mut ViewContext<Self>) -> bool {
|
fn navigate(&mut self, state: Box<dyn Any>, _: &mut ViewContext<Self>) -> bool {
|
||||||
// let state = *state.downcast::<String>().unwrap_or_default();
|
let state = *state.downcast::<String>().unwrap_or_default();
|
||||||
// if state != self.state {
|
if state != self.state {
|
||||||
// self.state = state;
|
self.state = state;
|
||||||
// true
|
true
|
||||||
// } else {
|
} else {
|
||||||
// false
|
false
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// fn deactivated(&mut self, cx: &mut ViewContext<Self>) {
|
fn deactivated(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
// self.push_to_nav_history(cx);
|
self.push_to_nav_history(cx);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// fn clone_on_split(
|
fn clone_on_split(
|
||||||
// &self,
|
&self,
|
||||||
// _workspace_id: WorkspaceId,
|
_workspace_id: WorkspaceId,
|
||||||
// _: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
// ) -> Option<Self>
|
) -> Option<View<Self>>
|
||||||
// where
|
where
|
||||||
// Self: Sized,
|
Self: Sized,
|
||||||
// {
|
{
|
||||||
// Some(self.clone())
|
Some(cx.build_view(|cx| Self {
|
||||||
// }
|
state: self.state.clone(),
|
||||||
|
label: self.label.clone(),
|
||||||
|
save_count: self.save_count,
|
||||||
|
save_as_count: self.save_as_count,
|
||||||
|
reload_count: self.reload_count,
|
||||||
|
is_dirty: self.is_dirty,
|
||||||
|
is_singleton: self.is_singleton,
|
||||||
|
has_conflict: self.has_conflict,
|
||||||
|
project_items: self.project_items.clone(),
|
||||||
|
nav_history: None,
|
||||||
|
tab_descriptions: None,
|
||||||
|
tab_detail: Default::default(),
|
||||||
|
workspace_id: self.workspace_id,
|
||||||
|
focus_handle: cx.focus_handle(),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
// fn is_dirty(&self, _: &AppContext) -> bool {
|
fn is_dirty(&self, _: &AppContext) -> bool {
|
||||||
// self.is_dirty
|
self.is_dirty
|
||||||
// }
|
}
|
||||||
|
|
||||||
// fn has_conflict(&self, _: &AppContext) -> bool {
|
fn has_conflict(&self, _: &AppContext) -> bool {
|
||||||
// self.has_conflict
|
self.has_conflict
|
||||||
// }
|
}
|
||||||
|
|
||||||
// fn can_save(&self, cx: &AppContext) -> bool {
|
fn can_save(&self, cx: &AppContext) -> bool {
|
||||||
// !self.project_items.is_empty()
|
!self.project_items.is_empty()
|
||||||
// && self
|
&& self
|
||||||
// .project_items
|
.project_items
|
||||||
// .iter()
|
.iter()
|
||||||
// .all(|item| item.read(cx).entry_id.is_some())
|
.all(|item| item.read(cx).entry_id.is_some())
|
||||||
// }
|
}
|
||||||
|
|
||||||
// fn save(
|
fn save(
|
||||||
// &mut self,
|
&mut self,
|
||||||
// _: Model<Project>,
|
_: Model<Project>,
|
||||||
// _: &mut ViewContext<Self>,
|
_: &mut ViewContext<Self>,
|
||||||
// ) -> Task<anyhow::Result<()>> {
|
) -> Task<anyhow::Result<()>> {
|
||||||
// self.save_count += 1;
|
self.save_count += 1;
|
||||||
// self.is_dirty = false;
|
self.is_dirty = false;
|
||||||
// Task::ready(Ok(()))
|
Task::ready(Ok(()))
|
||||||
// }
|
}
|
||||||
|
|
||||||
// fn save_as(
|
fn save_as(
|
||||||
// &mut self,
|
&mut self,
|
||||||
// _: Model<Project>,
|
_: Model<Project>,
|
||||||
// _: std::path::PathBuf,
|
_: std::path::PathBuf,
|
||||||
// _: &mut ViewContext<Self>,
|
_: &mut ViewContext<Self>,
|
||||||
// ) -> Task<anyhow::Result<()>> {
|
) -> Task<anyhow::Result<()>> {
|
||||||
// self.save_as_count += 1;
|
self.save_as_count += 1;
|
||||||
// self.is_dirty = false;
|
self.is_dirty = false;
|
||||||
// Task::ready(Ok(()))
|
Task::ready(Ok(()))
|
||||||
// }
|
}
|
||||||
|
|
||||||
// fn reload(
|
fn reload(
|
||||||
// &mut self,
|
&mut self,
|
||||||
// _: Model<Project>,
|
_: Model<Project>,
|
||||||
// _: &mut ViewContext<Self>,
|
_: &mut ViewContext<Self>,
|
||||||
// ) -> Task<anyhow::Result<()>> {
|
) -> Task<anyhow::Result<()>> {
|
||||||
// self.reload_count += 1;
|
self.reload_count += 1;
|
||||||
// self.is_dirty = false;
|
self.is_dirty = false;
|
||||||
// Task::ready(Ok(()))
|
Task::ready(Ok(()))
|
||||||
// }
|
}
|
||||||
|
|
||||||
// fn to_item_events(_: &Self::Event) -> SmallVec<[ItemEvent; 2]> {
|
fn serialized_item_kind() -> Option<&'static str> {
|
||||||
// [ItemEvent::UpdateTab, ItemEvent::Edit].into()
|
Some("TestItem")
|
||||||
// }
|
}
|
||||||
|
|
||||||
// fn serialized_item_kind() -> Option<&'static str> {
|
fn deserialize(
|
||||||
// Some("TestItem")
|
_project: Model<Project>,
|
||||||
// }
|
_workspace: WeakView<Workspace>,
|
||||||
|
workspace_id: WorkspaceId,
|
||||||
// fn deserialize(
|
_item_id: ItemId,
|
||||||
// _project: Model<Project>,
|
cx: &mut ViewContext<Pane>,
|
||||||
// _workspace: WeakViewHandle<Workspace>,
|
) -> Task<anyhow::Result<View<Self>>> {
|
||||||
// workspace_id: WorkspaceId,
|
let view = cx.build_view(|cx| Self::new_deserialized(workspace_id, cx));
|
||||||
// _item_id: ItemId,
|
Task::Ready(Some(anyhow::Ok(view)))
|
||||||
// cx: &mut ViewContext<Pane>,
|
}
|
||||||
// ) -> Task<anyhow::Result<View<Self>>> {
|
}
|
||||||
// let view = cx.add_view(|_cx| Self::new_deserialized(workspace_id));
|
}
|
||||||
// Task::Ready(Some(anyhow::Ok(view)))
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
|
@ -12,9 +12,9 @@ use gpui::{
|
||||||
ViewContext, VisualContext, WeakView, WindowContext,
|
ViewContext, VisualContext, WeakView, WindowContext,
|
||||||
};
|
};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use project2::{Project, ProjectEntryId, ProjectPath};
|
use project::{Project, ProjectEntryId, ProjectPath};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use settings2::Settings;
|
use settings::Settings;
|
||||||
use std::{
|
use std::{
|
||||||
any::Any,
|
any::Any,
|
||||||
cmp, fmt, mem,
|
cmp, fmt, mem,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::{AppState, FollowerState, Pane, Workspace};
|
use crate::{AppState, FollowerState, Pane, Workspace};
|
||||||
use anyhow::{anyhow, bail, Result};
|
use anyhow::{anyhow, bail, Result};
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
use db2::sqlez::{
|
use db::sqlez::{
|
||||||
bindable::{Bind, Column, StaticColumnCount},
|
bindable::{Bind, Column, StaticColumnCount},
|
||||||
statement::Statement,
|
statement::Statement,
|
||||||
};
|
};
|
||||||
|
@ -9,7 +9,7 @@ use gpui::{
|
||||||
point, size, AnyWeakView, Bounds, Div, IntoElement, Model, Pixels, Point, View, ViewContext,
|
point, size, AnyWeakView, Bounds, Div, IntoElement, Model, Pixels, Point, View, ViewContext,
|
||||||
};
|
};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use project2::Project;
|
use project::Project;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use ui::prelude::*;
|
use ui::prelude::*;
|
||||||
|
|
|
@ -5,7 +5,7 @@ pub mod model;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use anyhow::{anyhow, bail, Context, Result};
|
use anyhow::{anyhow, bail, Context, Result};
|
||||||
use db2::{define_connection, query, sqlez::connection::Connection, sqlez_macros::sql};
|
use db::{define_connection, query, sqlez::connection::Connection, sqlez_macros::sql};
|
||||||
use gpui::WindowBounds;
|
use gpui::WindowBounds;
|
||||||
|
|
||||||
use util::{unzip_option, ResultExt};
|
use util::{unzip_option, ResultExt};
|
||||||
|
@ -552,7 +552,7 @@ impl WorkspaceDb {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use db2::open_test_db;
|
use db::open_test_db;
|
||||||
use gpui;
|
use gpui;
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
|
|
|
@ -3,12 +3,12 @@ use crate::{
|
||||||
};
|
};
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use async_recursion::async_recursion;
|
use async_recursion::async_recursion;
|
||||||
use db2::sqlez::{
|
use db::sqlez::{
|
||||||
bindable::{Bind, Column, StaticColumnCount},
|
bindable::{Bind, Column, StaticColumnCount},
|
||||||
statement::Statement,
|
statement::Statement,
|
||||||
};
|
};
|
||||||
use gpui::{AsyncWindowContext, Model, Task, View, WeakView, WindowBounds};
|
use gpui::{AsyncWindowContext, Model, Task, View, WeakView, WindowBounds};
|
||||||
use project2::Project;
|
use project::Project;
|
||||||
use std::{
|
use std::{
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
|
|
|
@ -4,7 +4,7 @@ use gpui::{
|
||||||
AnyView, AppContext, EventEmitter, Subscription, Task, View, ViewContext, WeakView,
|
AnyView, AppContext, EventEmitter, Subscription, Task, View, ViewContext, WeakView,
|
||||||
WindowContext,
|
WindowContext,
|
||||||
};
|
};
|
||||||
use project2::search::SearchQuery;
|
use project::search::SearchQuery;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
item::{Item, WeakItemHandle},
|
item::{Item, WeakItemHandle},
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use settings2::Settings;
|
use settings::Settings;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct WorkspaceSettings {
|
pub struct WorkspaceSettings {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue