mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-06 10:42:08 +00:00
WIP
This commit is contained in:
parent
3740c9d852
commit
2e2825ae98
3 changed files with 48 additions and 16 deletions
|
@ -26,7 +26,6 @@ use std::{
|
||||||
};
|
};
|
||||||
use util::http::{self, HttpClient};
|
use util::http::{self, HttpClient};
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct App(Arc<Mutex<AppContext>>);
|
pub struct App(Arc<Mutex<AppContext>>);
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
|
@ -83,15 +82,49 @@ impl App {
|
||||||
where
|
where
|
||||||
F: 'static + FnOnce(&mut MainThread<AppContext>),
|
F: 'static + FnOnce(&mut MainThread<AppContext>),
|
||||||
{
|
{
|
||||||
let this = self.clone();
|
let this = self.0.clone();
|
||||||
let platform = self.0.lock().platform.clone();
|
let platform = self.0.lock().platform.clone();
|
||||||
platform.borrow_on_main_thread().run(Box::new(move || {
|
platform.borrow_on_main_thread().run(Box::new(move || {
|
||||||
let cx = &mut *this.0.lock();
|
let cx = &mut *this.lock();
|
||||||
let cx = unsafe { mem::transmute::<&mut AppContext, &mut MainThread<AppContext>>(cx) };
|
let cx = unsafe { mem::transmute::<&mut AppContext, &mut MainThread<AppContext>>(cx) };
|
||||||
on_finish_launching(cx);
|
on_finish_launching(cx);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn on_open_urls<F>(&self, mut callback: F) -> &Self
|
||||||
|
where
|
||||||
|
F: 'static + FnMut(Vec<String>, &mut AppContext),
|
||||||
|
{
|
||||||
|
let this = Arc::downgrade(&self.0);
|
||||||
|
self.0
|
||||||
|
.lock()
|
||||||
|
.platform
|
||||||
|
.borrow_on_main_thread()
|
||||||
|
.on_open_urls(Box::new(move |urls| {
|
||||||
|
if let Some(app) = this.upgrade() {
|
||||||
|
callback(urls, &mut app.lock());
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn on_reopen<F>(&self, mut callback: F) -> &Self
|
||||||
|
where
|
||||||
|
F: 'static + FnMut(&mut AppContext),
|
||||||
|
{
|
||||||
|
let this = Arc::downgrade(&self.0);
|
||||||
|
self.0
|
||||||
|
.lock()
|
||||||
|
.platform
|
||||||
|
.borrow_on_main_thread()
|
||||||
|
.on_reopen(Box::new(move || {
|
||||||
|
if let Some(app) = this.upgrade() {
|
||||||
|
callback(&mut app.lock());
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn executor(&self) -> Executor {
|
pub fn executor(&self) -> Executor {
|
||||||
self.0.lock().executor.clone()
|
self.0.lock().executor.clone()
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ use settings2::{default_settings, handle_settings_file_changes, watch_config_fil
|
||||||
use simplelog::ConfigBuilder;
|
use simplelog::ConfigBuilder;
|
||||||
use smol::process::Command;
|
use smol::process::Command;
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
|
||||||
env,
|
env,
|
||||||
fs::OpenOptions,
|
fs::OpenOptions,
|
||||||
io::IsTerminal,
|
io::IsTerminal,
|
||||||
|
@ -78,15 +77,15 @@ fn main() {
|
||||||
let callback_listener = listener.clone();
|
let callback_listener = listener.clone();
|
||||||
app.on_open_urls(move |urls, _| callback_listener.open_urls(urls))
|
app.on_open_urls(move |urls, _| callback_listener.open_urls(urls))
|
||||||
.on_reopen(move |cx| {
|
.on_reopen(move |cx| {
|
||||||
if cx.has_global::<Weak<AppState>>() {
|
// todo!("workspace")
|
||||||
if let Some(app_state) = cx.global::<Weak<AppState>>().upgrade() {
|
// if cx.has_global::<Weak<AppState>>() {
|
||||||
// todo!("workspace")
|
// if let Some(app_state) = cx.global::<Weak<AppState>>().upgrade() {
|
||||||
// workspace::open_new(&app_state, cx, |workspace, cx| {
|
// workspace::open_new(&app_state, cx, |workspace, cx| {
|
||||||
// Editor::new_file(workspace, &Default::default(), cx)
|
// Editor::new_file(workspace, &Default::default(), cx)
|
||||||
// })
|
// })
|
||||||
// .detach();
|
// .detach();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
});
|
});
|
||||||
|
|
||||||
app.run(move |cx| {
|
app.run(move |cx| {
|
||||||
|
|
|
@ -48,12 +48,12 @@ pub struct AppState;
|
||||||
|
|
||||||
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>,
|
||||||
mut cx: AsyncAppContext,
|
mut _cx: AsyncAppContext,
|
||||||
) {
|
) {
|
||||||
if let Some(request) = requests.next().await {
|
if let Some(request) = requests.next().await {
|
||||||
match request {
|
match request {
|
||||||
CliRequest::Open { paths, wait } => {
|
CliRequest::Open { paths: _, wait: _ } => {
|
||||||
// let mut caret_positions = HashMap::new();
|
// let mut caret_positions = HashMap::new();
|
||||||
|
|
||||||
// let paths = if paths.is_empty() {
|
// let paths = if paths.is_empty() {
|
||||||
|
|
Loading…
Reference in a new issue