diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a121be14d657..73f2d3c394393 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,10 @@ Breaking changes: -- [scm][git] the History view (GitHistoryWidget) has moved from the git package to a new package, scm-extra, and +- [scm][git] the History view (GitHistoryWidget) has moved from the git package to a new package, scm-extra, and renamed to ScmHistoryWidget. GitNavigableListWidget has also moved. CSS classes have been moved renamed accordingly. [6381](https://github.com/eclipse-theia/theia/pull/6381) +- [task] `TaskRestartRunningQuickOpenItem` class is renamed into `RunningTaskQuickOpenItem`. [7392](https://github.com/eclipse-theia/theia/pull/7392) ## v0.16.0 diff --git a/packages/task/src/browser/quick-open-task.ts b/packages/task/src/browser/quick-open-task.ts index 2e472fb5899a1..b82f97e00d694 100644 --- a/packages/task/src/browser/quick-open-task.ts +++ b/packages/task/src/browser/quick-open-task.ts @@ -619,15 +619,31 @@ export class TaskConfigureQuickOpenItem extends QuickOpenGroupItem { @injectable() export class TaskTerminateQuickOpen implements QuickOpenModel { + @inject(LabelProvider) + protected readonly labelProvider: LabelProvider; + @inject(QuickOpenService) protected readonly quickOpenService: QuickOpenService; + @inject(TaskDefinitionRegistry) + protected readonly taskDefinitionRegistry: TaskDefinitionRegistry; + + @inject(TaskNameResolver) + protected readonly taskNameResolver: TaskNameResolver; + + @inject(TaskSourceResolver) + protected readonly taskSourceResolver: TaskSourceResolver; + @inject(TaskService) protected readonly taskService: TaskService; + @inject(WorkspaceService) + protected readonly workspaceService: WorkspaceService; + async onType(_lookFor: string, acceptor: (items: QuickOpenItem[]) => void): Promise { const items: QuickOpenItem[] = []; const runningTasks: TaskInfo[] = await this.taskService.getRunningTasks(); + const isMulti: boolean = this.workspaceService.isMultiRootWorkspaceOpened; if (runningTasks.length <= 0) { items.push(new QuickOpenItem({ label: 'No task is currently running', @@ -635,16 +651,24 @@ export class TaskTerminateQuickOpen implements QuickOpenModel { })); } else { runningTasks.forEach((task: TaskInfo) => { - items.push(new QuickOpenItem({ - label: task.config.label, - run: (mode: QuickOpenMode): boolean => { - if (mode !== QuickOpenMode.OPEN) { - return false; + items.push(new RunningTaskQuickOpenItem( + task, + this.taskService, + this.taskNameResolver, + this.taskSourceResolver, + this.taskDefinitionRegistry, + this.labelProvider, + isMulti, + { + run: (mode: QuickOpenMode): boolean => { + if (mode !== QuickOpenMode.OPEN) { + return false; + } + this.taskService.kill(task.taskId); + return true; } - this.taskService.kill(task.taskId); - return true; - } - })); + }, + )); }); if (runningTasks.length > 1) { items.push(new QuickOpenItem({ @@ -677,18 +701,34 @@ export class TaskTerminateQuickOpen implements QuickOpenModel { @injectable() export class TaskRunningQuickOpen implements QuickOpenModel { + @inject(LabelProvider) + protected readonly labelProvider: LabelProvider; + @inject(QuickOpenService) protected readonly quickOpenService: QuickOpenService; + @inject(TaskDefinitionRegistry) + protected readonly taskDefinitionRegistry: TaskDefinitionRegistry; + + @inject(TaskNameResolver) + protected readonly taskNameResolver: TaskNameResolver; + + @inject(TaskSourceResolver) + protected readonly taskSourceResolver: TaskSourceResolver; + @inject(TaskService) protected readonly taskService: TaskService; + @inject(WorkspaceService) + protected readonly workspaceService: WorkspaceService; + @inject(TerminalService) protected readonly terminalService: TerminalService; async onType(_lookFor: string, acceptor: (items: QuickOpenItem[]) => void): Promise { const items: QuickOpenItem[] = []; const runningTasks: TaskInfo[] = await this.taskService.getRunningTasks(); + const isMulti: boolean = this.workspaceService.isMultiRootWorkspaceOpened; if (runningTasks.length <= 0) { items.push(new QuickOpenItem({ label: 'No task is currently running', @@ -696,21 +736,29 @@ export class TaskRunningQuickOpen implements QuickOpenModel { })); } else { runningTasks.forEach((task: TaskInfo) => { - items.push(new QuickOpenItem({ - label: task.config.label, - run: (mode: QuickOpenMode): boolean => { - if (mode !== QuickOpenMode.OPEN) { - return false; - } - if (task.terminalId) { - const terminal = this.terminalService.getById('terminal-' + task.terminalId); - if (terminal) { - this.terminalService.open(terminal); + items.push(new RunningTaskQuickOpenItem( + task, + this.taskService, + this.taskNameResolver, + this.taskSourceResolver, + this.taskDefinitionRegistry, + this.labelProvider, + isMulti, + { + run: (mode: QuickOpenMode): boolean => { + if (mode !== QuickOpenMode.OPEN) { + return false; } + if (task.terminalId) { + const terminal = this.terminalService.getById('terminal-' + task.terminalId); + if (terminal) { + this.terminalService.open(terminal); + } + } + return true; } - return true; - } - })); + }, + )); }); } acceptor(items); @@ -725,7 +773,7 @@ export class TaskRunningQuickOpen implements QuickOpenModel { } } -export class TaskRestartRunningQuickOpenItem extends QuickOpenItem { +export class RunningTaskQuickOpenItem extends QuickOpenItem { constructor( protected readonly taskInfo: TaskInfo, @@ -753,11 +801,10 @@ export class TaskRestartRunningQuickOpenItem extends QuickOpenItem { } run(mode: QuickOpenMode): boolean { - if (mode !== QuickOpenMode.OPEN) { + if (mode !== QuickOpenMode.OPEN || !this.options.run) { return false; } - this.taskService.restartTask(this.taskInfo); - return true; + return this.options.run(mode); } } @@ -796,7 +843,7 @@ export class TaskRestartRunningQuickOpen implements QuickOpenModel { })); } else { runningTasks.forEach((task: TaskInfo) => { - items.push(new TaskRestartRunningQuickOpenItem( + items.push(new RunningTaskQuickOpenItem( task, this.taskService, this.taskNameResolver, @@ -804,7 +851,15 @@ export class TaskRestartRunningQuickOpen implements QuickOpenModel { this.taskDefinitionRegistry, this.labelProvider, isMulti, - {}, + { + run: (mode: QuickOpenMode): boolean => { + if (mode !== QuickOpenMode.OPEN) { + return false; + } + this.taskService.restartTask(task); + return true; + } + }, )); }); }