tasks.rs

 1use project::TaskSourceKind;
 2use task::{ResolvedTask, TaskContext, TaskTemplate};
 3use ui::ViewContext;
 4
 5use crate::Workspace;
 6
 7pub fn schedule_task(
 8    workspace: &Workspace,
 9    task_source_kind: TaskSourceKind,
10    task_to_resolve: &TaskTemplate,
11    task_cx: &TaskContext,
12    omit_history: bool,
13    cx: &mut ViewContext<'_, Workspace>,
14) {
15    if let Some(spawn_in_terminal) =
16        task_to_resolve.resolve_task(&task_source_kind.to_id_base(), task_cx)
17    {
18        schedule_resolved_task(
19            workspace,
20            task_source_kind,
21            spawn_in_terminal,
22            omit_history,
23            cx,
24        );
25    }
26}
27
28pub fn schedule_resolved_task(
29    workspace: &Workspace,
30    task_source_kind: TaskSourceKind,
31    mut resolved_task: ResolvedTask,
32    omit_history: bool,
33    cx: &mut ViewContext<'_, Workspace>,
34) {
35    if let Some(spawn_in_terminal) = resolved_task.resolved.take() {
36        if !omit_history {
37            resolved_task.resolved = Some(spawn_in_terminal.clone());
38            workspace.project().update(cx, |project, cx| {
39                if let Some(task_inventory) =
40                    project.task_store().read(cx).task_inventory().cloned()
41                {
42                    task_inventory.update(cx, |inventory, _| {
43                        inventory.task_scheduled(task_source_kind, resolved_task);
44                    })
45                }
46            });
47        }
48        cx.emit(crate::Event::SpawnTask(Box::new(spawn_in_terminal)));
49    }
50}