wip
This commit is contained in:
parent
5550e80c4e
commit
68a1c7ce4c
5 changed files with 110 additions and 111 deletions
|
@ -120,7 +120,7 @@ type FrameCallback = Box<dyn FnOnce(&mut WindowContext) + Send>;
|
||||||
type Handler = Box<dyn FnMut(&mut AppContext) -> bool + Send + 'static>;
|
type Handler = Box<dyn FnMut(&mut AppContext) -> bool + Send + 'static>;
|
||||||
type Listener = Box<dyn FnMut(&dyn Any, &mut AppContext) -> bool + Send + 'static>;
|
type Listener = Box<dyn FnMut(&dyn Any, &mut AppContext) -> bool + Send + 'static>;
|
||||||
type QuitHandler = Box<dyn FnMut(&mut AppContext) -> BoxFuture<'static, ()> + Send + 'static>;
|
type QuitHandler = Box<dyn FnMut(&mut AppContext) -> BoxFuture<'static, ()> + Send + 'static>;
|
||||||
type ReleaseListener = Box<dyn FnMut(&mut dyn Any, &mut AppContext) + Send + 'static>;
|
type ReleaseListener = Box<dyn FnOnce(&mut dyn Any, &mut AppContext) + Send + 'static>;
|
||||||
|
|
||||||
pub struct AppContext {
|
pub struct AppContext {
|
||||||
this: Weak<Mutex<AppContext>>,
|
this: Weak<Mutex<AppContext>>,
|
||||||
|
@ -408,7 +408,7 @@ impl AppContext {
|
||||||
for (entity_id, mut entity) in dropped {
|
for (entity_id, mut entity) in dropped {
|
||||||
self.observers.remove(&entity_id);
|
self.observers.remove(&entity_id);
|
||||||
self.event_listeners.remove(&entity_id);
|
self.event_listeners.remove(&entity_id);
|
||||||
for mut release_callback in self.release_listeners.remove(&entity_id) {
|
for release_callback in self.release_listeners.remove(&entity_id) {
|
||||||
release_callback(&mut entity, self);
|
release_callback(&mut entity, self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -697,7 +697,7 @@ impl AppContext {
|
||||||
pub fn observe_release<E, T>(
|
pub fn observe_release<E, T>(
|
||||||
&mut self,
|
&mut self,
|
||||||
handle: &E,
|
handle: &E,
|
||||||
mut on_release: impl FnMut(&mut T, &mut AppContext) + Send + 'static,
|
on_release: impl FnOnce(&mut T, &mut AppContext) + Send + 'static,
|
||||||
) -> Subscription
|
) -> Subscription
|
||||||
where
|
where
|
||||||
E: Entity<T>,
|
E: Entity<T>,
|
||||||
|
|
|
@ -393,18 +393,18 @@ impl Bind for WindowBounds {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
todo!()
|
|
||||||
// statement.bind(
|
// statement.bind(
|
||||||
// ®ion.map(|region| {
|
// ®ion.map(|region| {
|
||||||
// (
|
// (
|
||||||
// region.min_x(),
|
// region.origin.x,
|
||||||
// region.min_y(),
|
// region.origin.y,
|
||||||
// region.width(),
|
// region.size.width,
|
||||||
// region.height(),
|
// region.size.height,
|
||||||
// )
|
// )
|
||||||
// }),
|
// }),
|
||||||
// next_index,
|
// next_index,
|
||||||
// )
|
// )
|
||||||
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1675,7 +1675,7 @@ impl<'a, 'w, V: 'static> ViewContext<'a, 'w, V> {
|
||||||
|
|
||||||
pub fn on_release(
|
pub fn on_release(
|
||||||
&mut self,
|
&mut self,
|
||||||
mut on_release: impl FnMut(&mut V, &mut WindowContext) + Send + 'static,
|
on_release: impl FnOnce(&mut V, &mut WindowContext) + Send + 'static,
|
||||||
) -> Subscription {
|
) -> Subscription {
|
||||||
let window_handle = self.window.handle;
|
let window_handle = self.window.handle;
|
||||||
self.app.release_listeners.insert(
|
self.app.release_listeners.insert(
|
||||||
|
|
|
@ -255,7 +255,7 @@ pub trait ItemHandle: 'static + Send {
|
||||||
fn on_release(
|
fn on_release(
|
||||||
&mut self,
|
&mut self,
|
||||||
cx: &mut AppContext,
|
cx: &mut AppContext,
|
||||||
callback: Box<dyn FnMut(&mut AppContext) + Send>,
|
callback: Box<dyn FnOnce(&mut AppContext) + Send>,
|
||||||
) -> gpui2::Subscription;
|
) -> gpui2::Subscription;
|
||||||
fn to_searchable_item_handle(&self, cx: &AppContext) -> Option<Box<dyn SearchableItemHandle>>;
|
fn to_searchable_item_handle(&self, cx: &AppContext) -> Option<Box<dyn SearchableItemHandle>>;
|
||||||
fn breadcrumb_location(&self, cx: &AppContext) -> ToolbarItemLocation;
|
fn breadcrumb_location(&self, cx: &AppContext) -> ToolbarItemLocation;
|
||||||
|
@ -573,7 +573,7 @@ impl<T: Item> ItemHandle for View<T> {
|
||||||
fn on_release(
|
fn on_release(
|
||||||
&mut self,
|
&mut self,
|
||||||
cx: &mut AppContext,
|
cx: &mut AppContext,
|
||||||
mut callback: Box<dyn FnMut(&mut AppContext) + Send>,
|
callback: Box<dyn FnOnce(&mut AppContext) + Send>,
|
||||||
) -> gpui2::Subscription {
|
) -> gpui2::Subscription {
|
||||||
cx.observe_release(self, move |_, cx| callback(cx))
|
cx.observe_release(self, move |_, cx| callback(cx))
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,8 @@ mod only_instance;
|
||||||
mod open_listener;
|
mod open_listener;
|
||||||
|
|
||||||
pub use assets::*;
|
pub use assets::*;
|
||||||
use client2::{Client, UserStore};
|
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
use gpui2::{AsyncAppContext, Model};
|
use gpui2::{AsyncAppContext, Point};
|
||||||
pub use only_instance::*;
|
pub use only_instance::*;
|
||||||
pub use open_listener::*;
|
pub use open_listener::*;
|
||||||
|
|
||||||
|
@ -21,6 +20,7 @@ use futures::{
|
||||||
};
|
};
|
||||||
use std::{path::Path, sync::Arc, thread, time::Duration};
|
use std::{path::Path, sync::Arc, thread, time::Duration};
|
||||||
use util::{paths::PathLikeWithPosition, ResultExt};
|
use util::{paths::PathLikeWithPosition, ResultExt};
|
||||||
|
use workspace2::AppState;
|
||||||
|
|
||||||
pub fn connect_to_cli(
|
pub fn connect_to_cli(
|
||||||
server_name: &str,
|
server_name: &str,
|
||||||
|
@ -51,11 +51,6 @@ pub fn connect_to_cli(
|
||||||
Ok((async_request_rx, response_tx))
|
Ok((async_request_rx, response_tx))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AppState {
|
|
||||||
pub client: Arc<Client>,
|
|
||||||
pub user_store: Model<UserStore>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn handle_cli_connection(
|
pub async fn handle_cli_connection(
|
||||||
(mut requests, responses): (mpsc::Receiver<CliRequest>, IpcSender<CliResponse>),
|
(mut requests, responses): (mpsc::Receiver<CliRequest>, IpcSender<CliResponse>),
|
||||||
app_state: Arc<AppState>,
|
app_state: Arc<AppState>,
|
||||||
|
@ -96,21 +91,22 @@ pub async fn handle_cli_connection(
|
||||||
}
|
}
|
||||||
Some(path)
|
Some(path)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect::<Vec<_>>()
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut errored = false;
|
let mut errored = false;
|
||||||
|
|
||||||
match cx
|
if let Some(open_paths_task) = cx
|
||||||
.update(|cx| workspace2::open_paths(&paths, &app_state, None, cx))
|
.update(|cx| workspace2::open_paths(&paths, &app_state, None, cx))
|
||||||
.await
|
.log_err()
|
||||||
{
|
{
|
||||||
|
match open_paths_task.await {
|
||||||
Ok((workspace, items)) => {
|
Ok((workspace, items)) => {
|
||||||
let mut item_release_futures = Vec::new();
|
let mut item_release_futures = Vec::new();
|
||||||
|
|
||||||
for (item, path) in items.into_iter().zip(&paths) {
|
for (item, path) in items.into_iter().zip(&paths) {
|
||||||
match item {
|
match item {
|
||||||
Some(Ok(item)) => {
|
Some(Ok(mut item)) => {
|
||||||
if let Some(point) = caret_positions.remove(path) {
|
if let Some(point) = caret_positions.remove(path) {
|
||||||
todo!()
|
todo!()
|
||||||
// if let Some(active_editor) = item.downcast::<Editor>() {
|
// if let Some(active_editor) = item.downcast::<Editor>() {
|
||||||
|
@ -133,7 +129,7 @@ pub async fn handle_cli_connection(
|
||||||
}
|
}
|
||||||
|
|
||||||
let released = oneshot::channel();
|
let released = oneshot::channel();
|
||||||
cx.update(|cx| {
|
cx.update(move |cx| {
|
||||||
item.on_release(
|
item.on_release(
|
||||||
cx,
|
cx,
|
||||||
Box::new(move |_| {
|
Box::new(move |_| {
|
||||||
|
@ -147,7 +143,10 @@ pub async fn handle_cli_connection(
|
||||||
Some(Err(err)) => {
|
Some(Err(err)) => {
|
||||||
responses
|
responses
|
||||||
.send(CliResponse::Stderr {
|
.send(CliResponse::Stderr {
|
||||||
message: format!("error opening {:?}: {}", path, err),
|
message: format!(
|
||||||
|
"error opening {:?}: {}",
|
||||||
|
path, err
|
||||||
|
),
|
||||||
})
|
})
|
||||||
.log_err();
|
.log_err();
|
||||||
errored = true;
|
errored = true;
|
||||||
|
@ -157,22 +156,21 @@ pub async fn handle_cli_connection(
|
||||||
}
|
}
|
||||||
|
|
||||||
if wait {
|
if wait {
|
||||||
let executor = cx.executor();
|
let executor = cx.executor().clone();
|
||||||
let wait = async move {
|
let wait = async move {
|
||||||
if paths.is_empty() {
|
if paths.is_empty() {
|
||||||
let (done_tx, done_rx) = oneshot::channel();
|
let (done_tx, done_rx) = oneshot::channel();
|
||||||
if let Some(workspace) = workspace.upgrade(&cx) {
|
let _subscription =
|
||||||
let _subscription = cx.update(|cx| {
|
cx.update_window_root(&workspace, move |_, cx| {
|
||||||
cx.observe_release(&workspace, move |_, _| {
|
cx.on_release(|_, _| {
|
||||||
let _ = done_tx.send(());
|
let _ = done_tx.send(());
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
drop(workspace);
|
drop(workspace);
|
||||||
let _ = done_rx.await;
|
let _ = done_rx.await;
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
let _ =
|
let _ = futures::future::try_join_all(item_release_futures)
|
||||||
futures::future::try_join_all(item_release_futures).await;
|
.await;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
.fuse();
|
.fuse();
|
||||||
|
@ -212,3 +210,4 @@ pub async fn handle_cli_connection(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue