Fix window double borrows (#23739)
Fix bugs caused by the window context PR, where the window could be on the stack and is then requested from the App. This PR also adds derive macros for `AppContext` and `VisualContext` so that it's easy to define further contexts in API code, such as `editor::BlockContext`. Release Notes: - N/A
This commit is contained in:
parent
29bfb56739
commit
a7c549b85b
24 changed files with 465 additions and 297 deletions
|
@ -5607,36 +5607,6 @@ impl std::fmt::Debug for OpenPaths {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn activate_workspace_for_project(
|
||||
cx: &mut App,
|
||||
predicate: impl Fn(&Project, &App) -> bool + Send + 'static,
|
||||
) -> Option<WindowHandle<Workspace>> {
|
||||
for window in cx.windows() {
|
||||
let Some(workspace) = window.downcast::<Workspace>() else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let predicate = workspace
|
||||
.update(cx, |workspace, window, cx| {
|
||||
let project = workspace.project.read(cx);
|
||||
if predicate(project, cx) {
|
||||
window.activate_window();
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
.log_err()
|
||||
.unwrap_or(false);
|
||||
|
||||
if predicate {
|
||||
return Some(workspace);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub async fn last_opened_workspace_location() -> Option<SerializedWorkspaceLocation> {
|
||||
DB.last_workspace().await.log_err().flatten()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue