WIP
This commit is contained in:
parent
b7712c2f4b
commit
77e3c7f8ee
2 changed files with 83 additions and 79 deletions
|
@ -576,7 +576,7 @@ impl Item for Editor {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tab_content<T: 'static>(&self, detail: Option<usize>, cx: &AppContext) -> AnyElement<T> {
|
fn tab_content<T: 'static>(&self, detail: Option<usize>, cx: &AppContext) -> AnyElement<T> {
|
||||||
todo!();
|
AnyElement::new(gpui::ParentElement::child(gpui::div(), "HEY"))
|
||||||
|
|
||||||
// Flex::row()
|
// Flex::row()
|
||||||
// .with_child(Label::new(self.title(cx).to_string(), style.label.clone()).into_any())
|
// .with_child(Label::new(self.title(cx).to_string(), style.label.clone()).into_any())
|
||||||
|
|
|
@ -15,7 +15,6 @@ use gpui2::{
|
||||||
AnyElement, AnyView, AppContext, Entity, EntityId, EventEmitter, FocusHandle, HighlightStyle,
|
AnyElement, AnyView, AppContext, Entity, EntityId, EventEmitter, FocusHandle, HighlightStyle,
|
||||||
Model, Pixels, Point, Render, SharedString, Task, View, ViewContext, WeakView, WindowContext,
|
Model, Pixels, Point, Render, SharedString, Task, View, ViewContext, WeakView, WindowContext,
|
||||||
};
|
};
|
||||||
use parking_lot::Mutex;
|
|
||||||
use project2::{Project, ProjectEntryId, ProjectPath};
|
use project2::{Project, ProjectEntryId, ProjectPath};
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -23,8 +22,10 @@ use settings2::Settings;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::{
|
use std::{
|
||||||
any::{Any, TypeId},
|
any::{Any, TypeId},
|
||||||
|
cell::RefCell,
|
||||||
ops::Range,
|
ops::Range,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
|
rc::Rc,
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{AtomicBool, Ordering},
|
atomic::{AtomicBool, Ordering},
|
||||||
Arc,
|
Arc,
|
||||||
|
@ -412,91 +413,94 @@ impl<T: Item> ItemHandle for View<T> {
|
||||||
.is_none()
|
.is_none()
|
||||||
{
|
{
|
||||||
let mut pending_autosave = DelayedDebouncedEditAction::new();
|
let mut pending_autosave = DelayedDebouncedEditAction::new();
|
||||||
let pending_update = Arc::new(Mutex::new(None));
|
let pending_update = Rc::new(RefCell::new(None));
|
||||||
let pending_update_scheduled = Arc::new(AtomicBool::new(false));
|
let pending_update_scheduled = Arc::new(AtomicBool::new(false));
|
||||||
|
|
||||||
let event_subscription = Some(cx.subscribe(self, move |workspace, item, event, cx| {
|
let mut event_subscription =
|
||||||
let pane = if let Some(pane) = workspace
|
Some(cx.subscribe(self, move |workspace, item, event, cx| {
|
||||||
.panes_by_item
|
let pane = if let Some(pane) = workspace
|
||||||
.get(&item.id())
|
.panes_by_item
|
||||||
.and_then(|pane| pane.upgrade())
|
.get(&item.id())
|
||||||
{
|
.and_then(|pane| pane.upgrade())
|
||||||
pane
|
|
||||||
} else {
|
|
||||||
log::error!("unexpected item event after pane was dropped");
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(item) = item.to_followable_item_handle(cx) {
|
|
||||||
let _is_project_item = item.is_project_item(cx);
|
|
||||||
let leader_id = workspace.leader_for_pane(&pane);
|
|
||||||
|
|
||||||
if leader_id.is_some() && item.should_unfollow_on_event(event, cx) {
|
|
||||||
workspace.unfollow(&pane, cx);
|
|
||||||
}
|
|
||||||
|
|
||||||
if item.add_event_to_update_proto(event, &mut *pending_update.lock(), cx)
|
|
||||||
&& !pending_update_scheduled.load(Ordering::SeqCst)
|
|
||||||
{
|
{
|
||||||
pending_update_scheduled.store(true, Ordering::SeqCst);
|
pane
|
||||||
todo!("replace with on_next_frame?");
|
} else {
|
||||||
// cx.after_window_update({
|
log::error!("unexpected item event after pane was dropped");
|
||||||
// let pending_update = pending_update.clone();
|
return;
|
||||||
// let pending_update_scheduled = pending_update_scheduled.clone();
|
};
|
||||||
// move |this, cx| {
|
|
||||||
// pending_update_scheduled.store(false, Ordering::SeqCst);
|
|
||||||
// this.update_followers(
|
|
||||||
// is_project_item,
|
|
||||||
// proto::update_followers::Variant::UpdateView(
|
|
||||||
// proto::UpdateView {
|
|
||||||
// id: item
|
|
||||||
// .remote_id(&this.app_state.client, cx)
|
|
||||||
// .map(|id| id.to_proto()),
|
|
||||||
// variant: pending_update.borrow_mut().take(),
|
|
||||||
// leader_id,
|
|
||||||
// },
|
|
||||||
// ),
|
|
||||||
// cx,
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for item_event in T::to_item_events(event).into_iter() {
|
if let Some(item) = item.to_followable_item_handle(cx) {
|
||||||
match item_event {
|
let is_project_item = item.is_project_item(cx);
|
||||||
ItemEvent::CloseItem => {
|
let leader_id = workspace.leader_for_pane(&pane);
|
||||||
pane.update(cx, |pane, cx| {
|
|
||||||
pane.close_item_by_id(item.id(), crate::SaveIntent::Close, cx)
|
if leader_id.is_some() && item.should_unfollow_on_event(event, cx) {
|
||||||
})
|
workspace.unfollow(&pane, cx);
|
||||||
.detach_and_log_err(cx);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemEvent::UpdateTab => {
|
if item.add_event_to_update_proto(
|
||||||
pane.update(cx, |_, cx| {
|
event,
|
||||||
cx.emit(pane::Event::ChangeItemTitle);
|
&mut *pending_update.borrow_mut(),
|
||||||
cx.notify();
|
cx,
|
||||||
|
) && !pending_update_scheduled.load(Ordering::SeqCst)
|
||||||
|
{
|
||||||
|
pending_update_scheduled.store(true, Ordering::SeqCst);
|
||||||
|
cx.on_next_frame({
|
||||||
|
let pending_update = pending_update.clone();
|
||||||
|
let pending_update_scheduled = pending_update_scheduled.clone();
|
||||||
|
move |this, cx| {
|
||||||
|
pending_update_scheduled.store(false, Ordering::SeqCst);
|
||||||
|
this.update_followers(
|
||||||
|
is_project_item,
|
||||||
|
proto::update_followers::Variant::UpdateView(
|
||||||
|
proto::UpdateView {
|
||||||
|
id: item
|
||||||
|
.remote_id(&this.app_state.client, cx)
|
||||||
|
.map(|id| id.to_proto()),
|
||||||
|
variant: pending_update.borrow_mut().take(),
|
||||||
|
leader_id,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ItemEvent::Edit => {
|
for item_event in T::to_item_events(event).into_iter() {
|
||||||
let autosave = WorkspaceSettings::get_global(cx).autosave;
|
match item_event {
|
||||||
if let AutosaveSetting::AfterDelay { milliseconds } = autosave {
|
ItemEvent::CloseItem => {
|
||||||
let delay = Duration::from_millis(milliseconds);
|
pane.update(cx, |pane, cx| {
|
||||||
let item = item.clone();
|
pane.close_item_by_id(item.id(), crate::SaveIntent::Close, cx)
|
||||||
pending_autosave.fire_new(delay, cx, move |workspace, cx| {
|
})
|
||||||
Pane::autosave_item(&item, workspace.project().clone(), cx)
|
.detach_and_log_err(cx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemEvent::UpdateTab => {
|
||||||
|
pane.update(cx, |_, cx| {
|
||||||
|
cx.emit(pane::Event::ChangeItemTitle);
|
||||||
|
cx.notify();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ItemEvent::Edit => {
|
||||||
|
let autosave = WorkspaceSettings::get_global(cx).autosave;
|
||||||
|
if let AutosaveSetting::AfterDelay { milliseconds } = autosave {
|
||||||
|
let delay = Duration::from_millis(milliseconds);
|
||||||
|
let item = item.clone();
|
||||||
|
pending_autosave.fire_new(delay, cx, move |workspace, cx| {
|
||||||
|
Pane::autosave_item(&item, workspace.project().clone(), cx)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}));
|
||||||
}));
|
|
||||||
|
|
||||||
todo!("observe focus");
|
// todo!()
|
||||||
// cx.observe_focus(self, move |workspace, item, focused, cx| {
|
// cx.observe_focus(self, move |workspace, item, focused, cx| {
|
||||||
// if !focused
|
// if !focused
|
||||||
// && WorkspaceSettings::get_global(cx).autosave == AutosaveSetting::OnFocusChange
|
// && WorkspaceSettings::get_global(cx).autosave == AutosaveSetting::OnFocusChange
|
||||||
|
@ -507,12 +511,12 @@ impl<T: Item> ItemHandle for View<T> {
|
||||||
// })
|
// })
|
||||||
// .detach();
|
// .detach();
|
||||||
|
|
||||||
// let item_id = self.id();
|
let item_id = self.id();
|
||||||
// cx.observe_release(self, move |workspace, _, _| {
|
cx.observe_release(self, move |workspace, _, _| {
|
||||||
// workspace.panes_by_item.remove(&item_id);
|
workspace.panes_by_item.remove(&item_id);
|
||||||
// event_subscription.take();
|
event_subscription.take();
|
||||||
// })
|
})
|
||||||
// .detach();
|
.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
cx.defer(|workspace, cx| {
|
cx.defer(|workspace, cx| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue