Add global events to MutableAppContext and raise global event when new workspace is created

This commit is contained in:
Keith Simmons 2022-03-10 20:03:01 -08:00
parent b62daebde1
commit 81fc812221
2 changed files with 95 additions and 19 deletions

View file

@ -1511,6 +1511,8 @@ fn open(action: &Open, cx: &mut MutableAppContext) {
.detach();
}
pub struct WorkspaceBuilt(WeakViewHandle<Workspace>);
pub fn open_paths(
abs_paths: &[PathBuf],
app_state: &Arc<AppState>,
@ -1537,7 +1539,7 @@ pub fn open_paths(
}
let workspace = existing.unwrap_or_else(|| {
cx.add_window((app_state.build_window_options)(), |cx| {
let (_, workspace) = cx.add_window((app_state.build_window_options)(), |cx| {
let project = Project::local(
app_state.client.clone(),
app_state.user_store.clone(),
@ -1546,8 +1548,9 @@ pub fn open_paths(
cx,
);
(app_state.build_workspace)(project, &app_state, cx)
})
.1
});
cx.emit_global(WorkspaceBuilt(workspace.downgrade()));
workspace
});
let task = workspace.update(cx, |workspace, cx| workspace.open_paths(abs_paths, cx));
@ -1581,12 +1584,13 @@ pub fn join_project(
&mut cx,
)
.await?;
let (_, workspace) = cx.update(|cx| {
cx.add_window((app_state.build_window_options)(), |cx| {
Ok(cx.update(|cx| {
let (_, workspace) = cx.add_window((app_state.build_window_options)(), |cx| {
(app_state.build_workspace)(project, &app_state, cx)
})
});
Ok(workspace)
});
cx.emit_global(WorkspaceBuilt(workspace.downgrade()));
workspace
}))
})
}
@ -1601,5 +1605,6 @@ fn open_new(app_state: &Arc<AppState>, cx: &mut MutableAppContext) {
);
(app_state.build_workspace)(project, &app_state, cx)
});
cx.emit_global(WorkspaceBuilt(workspace.downgrade()));
cx.dispatch_action(window_id, vec![workspace.id()], &OpenNew(app_state.clone()));
}