This commit is contained in:
KCaverly 2023-10-31 11:32:56 -04:00
parent 5550e80c4e
commit 68a1c7ce4c
5 changed files with 110 additions and 111 deletions

View file

@ -120,7 +120,7 @@ type FrameCallback = Box<dyn FnOnce(&mut WindowContext) + Send>;
type Handler = Box<dyn FnMut(&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 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 {
this: Weak<Mutex<AppContext>>,
@ -408,7 +408,7 @@ impl AppContext {
for (entity_id, mut entity) in dropped {
self.observers.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);
}
}
@ -697,7 +697,7 @@ impl AppContext {
pub fn observe_release<E, T>(
&mut self,
handle: &E,
mut on_release: impl FnMut(&mut T, &mut AppContext) + Send + 'static,
on_release: impl FnOnce(&mut T, &mut AppContext) + Send + 'static,
) -> Subscription
where
E: Entity<T>,

View file

@ -393,18 +393,18 @@ impl Bind for WindowBounds {
}
};
todo!()
// statement.bind(
// &region.map(|region| {
// (
// region.min_x(),
// region.min_y(),
// region.width(),
// region.height(),
// region.origin.x,
// region.origin.y,
// region.size.width,
// region.size.height,
// )
// }),
// next_index,
// )
todo!()
}
}

View file

@ -1675,7 +1675,7 @@ impl<'a, 'w, V: 'static> ViewContext<'a, 'w, V> {
pub fn on_release(
&mut self,
mut on_release: impl FnMut(&mut V, &mut WindowContext) + Send + 'static,
on_release: impl FnOnce(&mut V, &mut WindowContext) + Send + 'static,
) -> Subscription {
let window_handle = self.window.handle;
self.app.release_listeners.insert(

View file

@ -255,7 +255,7 @@ pub trait ItemHandle: 'static + Send {
fn on_release(
&mut self,
cx: &mut AppContext,
callback: Box<dyn FnMut(&mut AppContext) + Send>,
callback: Box<dyn FnOnce(&mut AppContext) + Send>,
) -> gpui2::Subscription;
fn to_searchable_item_handle(&self, cx: &AppContext) -> Option<Box<dyn SearchableItemHandle>>;
fn breadcrumb_location(&self, cx: &AppContext) -> ToolbarItemLocation;
@ -573,7 +573,7 @@ impl<T: Item> ItemHandle for View<T> {
fn on_release(
&mut self,
cx: &mut AppContext,
mut callback: Box<dyn FnMut(&mut AppContext) + Send>,
callback: Box<dyn FnOnce(&mut AppContext) + Send>,
) -> gpui2::Subscription {
cx.observe_release(self, move |_, cx| callback(cx))
}

View file

@ -4,9 +4,8 @@ mod only_instance;
mod open_listener;
pub use assets::*;
use client2::{Client, UserStore};
use collections::HashMap;
use gpui2::{AsyncAppContext, Model};
use gpui2::{AsyncAppContext, Point};
pub use only_instance::*;
pub use open_listener::*;
@ -21,6 +20,7 @@ use futures::{
};
use std::{path::Path, sync::Arc, thread, time::Duration};
use util::{paths::PathLikeWithPosition, ResultExt};
use workspace2::AppState;
pub fn connect_to_cli(
server_name: &str,
@ -51,11 +51,6 @@ pub fn connect_to_cli(
Ok((async_request_rx, response_tx))
}
pub struct AppState {
pub client: Arc<Client>,
pub user_store: Model<UserStore>,
}
pub async fn handle_cli_connection(
(mut requests, responses): (mpsc::Receiver<CliRequest>, IpcSender<CliResponse>),
app_state: Arc<AppState>,
@ -96,21 +91,22 @@ pub async fn handle_cli_connection(
}
Some(path)
})
.collect()
.collect::<Vec<_>>()
};
let mut errored = false;
match cx
if let Some(open_paths_task) = cx
.update(|cx| workspace2::open_paths(&paths, &app_state, None, cx))
.await
.log_err()
{
match open_paths_task.await {
Ok((workspace, items)) => {
let mut item_release_futures = Vec::new();
for (item, path) in items.into_iter().zip(&paths) {
match item {
Some(Ok(item)) => {
Some(Ok(mut item)) => {
if let Some(point) = caret_positions.remove(path) {
todo!()
// if let Some(active_editor) = item.downcast::<Editor>() {
@ -133,7 +129,7 @@ pub async fn handle_cli_connection(
}
let released = oneshot::channel();
cx.update(|cx| {
cx.update(move |cx| {
item.on_release(
cx,
Box::new(move |_| {
@ -147,7 +143,10 @@ pub async fn handle_cli_connection(
Some(Err(err)) => {
responses
.send(CliResponse::Stderr {
message: format!("error opening {:?}: {}", path, err),
message: format!(
"error opening {:?}: {}",
path, err
),
})
.log_err();
errored = true;
@ -157,22 +156,21 @@ pub async fn handle_cli_connection(
}
if wait {
let executor = cx.executor();
let executor = cx.executor().clone();
let wait = async move {
if paths.is_empty() {
let (done_tx, done_rx) = oneshot::channel();
if let Some(workspace) = workspace.upgrade(&cx) {
let _subscription = cx.update(|cx| {
cx.observe_release(&workspace, move |_, _| {
let _subscription =
cx.update_window_root(&workspace, move |_, cx| {
cx.on_release(|_, _| {
let _ = done_tx.send(());
})
});
drop(workspace);
let _ = done_rx.await;
}
} else {
let _ =
futures::future::try_join_all(item_release_futures).await;
let _ = futures::future::try_join_all(item_release_futures)
.await;
};
}
.fuse();
@ -212,3 +210,4 @@ pub async fn handle_cli_connection(
}
}
}
}