From 1af1a9e8b330bced049d82aad39500353062974f Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Fri, 26 Apr 2024 16:56:34 +0100 Subject: [PATCH] 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 --- crates/tasks_ui/src/lib.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/crates/tasks_ui/src/lib.rs b/crates/tasks_ui/src/lib.rs index 4898c8af0d98692d9dc1e3bad2f20a36c03dab7f..2b11fba49aa4b1489465cdb971a8c6d9273de78b 100644 --- a/crates/tasks_ui/src/lib.rs +++ b/crates/tasks_ui/src/lib.rs @@ -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) { 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) { cx.spawn(|workspace, mut cx| async move { let did_spawn = workspace