Toggle tasks modal in task::Rerun, when no tasks have been scheduled (#11059)

Currently, when no tasks have been scheduled, the `task::Rerun` action
does nothing.
This PR adds a fallback, so when no tasks have been scheduled so far the
`task::Rerun` action toggles the tasks modal

https://github.com/zed-industries/zed/assets/471335/72f7a71e-cfa8-49db-a295-fb05b2e7c905

Release Notes:

- Improved the `task::Rerun` action to toggle the tasks modal when no
tasks have been scheduled so far
This commit is contained in:
Tim Masliuchenko 2024-04-26 16:56:34 +01:00 committed by GitHub
parent 8006f69513
commit 1af1a9e8b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -66,6 +66,8 @@ pub fn init(cx: &mut AppContext) {
cx,
);
}
} else {
toggle_modal(workspace, cx);
};
});
},
@ -76,17 +78,19 @@ pub fn init(cx: &mut AppContext) {
fn spawn_task_or_modal(workspace: &mut Workspace, action: &Spawn, cx: &mut ViewContext<Workspace>) {
match &action.task_name {
Some(name) => spawn_task_with_name(name.clone(), cx),
None => {
let inventory = workspace.project().read(cx).task_inventory().clone();
let workspace_handle = workspace.weak_handle();
let task_context = task_context(workspace, cx);
workspace.toggle_modal(cx, |cx| {
TasksModal::new(inventory, task_context, workspace_handle, cx)
})
}
None => toggle_modal(workspace, cx),
}
}
fn toggle_modal(workspace: &mut Workspace, cx: &mut ViewContext<'_, Workspace>) {
let inventory = workspace.project().read(cx).task_inventory().clone();
let workspace_handle = workspace.weak_handle();
let task_context = task_context(workspace, cx);
workspace.toggle_modal(cx, |cx| {
TasksModal::new(inventory, task_context, workspace_handle, cx)
})
}
fn spawn_task_with_name(name: String, cx: &mut ViewContext<Workspace>) {
cx.spawn(|workspace, mut cx| async move {
let did_spawn = workspace