Merge pull request #622 from zed-industries/guest-settings-file

Open settings file in new window if current window isn't local
This commit is contained in:
Max Brunsfeld 2022-03-14 17:19:11 -07:00 committed by GitHub
commit 72692f1700
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 14 deletions

View file

@ -3699,7 +3699,7 @@ impl Project {
let buffer_handle = this.read_with(&cx, |this, _| {
this.opened_buffers
.get(&buffer_id)
.map(|buffer| buffer.upgrade(&cx).unwrap())
.and_then(|buffer| buffer.upgrade(&cx))
.ok_or_else(|| anyhow!("unknown buffer id {}", buffer_id))
})?;
let request = T::from_proto(

View file

@ -609,9 +609,13 @@ impl Workspace {
}
});
let weak_self = cx.weak_handle();
cx.emit_global(WorkspaceCreated(weak_self.clone()));
Workspace {
modal: None,
weak_self: cx.weak_handle(),
weak_self,
center: PaneGroup::new(pane.clone()),
panes: vec![pane.clone()],
active_pane: pane.clone(),
@ -1523,7 +1527,7 @@ pub fn open_paths(
}
let workspace = existing.unwrap_or_else(|| {
let (_, workspace) = cx.add_window((app_state.build_window_options)(), |cx| {
cx.add_window((app_state.build_window_options)(), |cx| {
let project = Project::local(
app_state.client.clone(),
app_state.user_store.clone(),
@ -1532,9 +1536,8 @@ pub fn open_paths(
cx,
);
(app_state.build_workspace)(project, &app_state, cx)
});
cx.emit_global(WorkspaceCreated(workspace.downgrade()));
workspace
})
.1
});
let task = workspace.update(cx, |workspace, cx| workspace.open_paths(abs_paths, cx));
@ -1569,11 +1572,10 @@ pub fn join_project(
)
.await?;
Ok(cx.update(|cx| {
let (_, workspace) = cx.add_window((app_state.build_window_options)(), |cx| {
cx.add_window((app_state.build_window_options)(), |cx| {
(app_state.build_workspace)(project, &app_state, cx)
});
cx.emit_global(WorkspaceCreated(workspace.downgrade()));
workspace
})
.1
}))
})
}
@ -1589,6 +1591,5 @@ fn open_new(app_state: &Arc<AppState>, cx: &mut MutableAppContext) {
);
(app_state.build_workspace)(project, &app_state, cx)
});
cx.emit_global(WorkspaceCreated(workspace.downgrade()));
cx.dispatch_action(window_id, vec![workspace.id()], &OpenNew(app_state.clone()));
}

View file

@ -52,17 +52,36 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::MutableAppContext) {
});
cx.add_action({
let fs = app_state.fs.clone();
let app_state = app_state.clone();
move |_: &mut Workspace, _: &OpenSettings, cx: &mut ViewContext<Workspace>| {
let fs = fs.clone();
let app_state = app_state.clone();
cx.spawn(move |workspace, mut cx| async move {
let fs = &app_state.fs;
if !fs.is_file(&SETTINGS_PATH).await {
fs.create_dir(&ROOT_PATH).await?;
fs.create_file(&SETTINGS_PATH, Default::default()).await?;
}
workspace
.update(&mut cx, |workspace, cx| {
workspace.open_paths(&[SETTINGS_PATH.clone()], cx)
if workspace.project().read(cx).is_local() {
workspace.open_paths(&[SETTINGS_PATH.clone()], cx)
} else {
let (_, workspace) =
cx.add_window((app_state.build_window_options)(), |cx| {
let project = Project::local(
app_state.client.clone(),
app_state.user_store.clone(),
app_state.languages.clone(),
app_state.fs.clone(),
cx,
);
(app_state.build_workspace)(project, &app_state, cx)
});
workspace.update(cx, |workspace, cx| {
workspace.open_paths(&[SETTINGS_PATH.clone()], cx)
})
}
})
.await;
Ok::<_, anyhow::Error>(())