mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-27 02:48:34 +00:00
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:
commit
72692f1700
3 changed files with 34 additions and 14 deletions
|
@ -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(
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
|
|
|
@ -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>(())
|
||||
|
|
Loading…
Reference in a new issue