Skip to content

Commit

Permalink
align how tasks are displayed as quick open items
Browse files Browse the repository at this point in the history
- In a multi root workspace, detected tasks are displayed in different
ways across `Run task`, `Restart running task`, `Terminate task`,
and `Show running tasks`. This change aligns the display of the task
quick open items.
- fixed #6821

Signed-off-by: Liang Huang <lhuang4@ualberta.ca>
  • Loading branch information
elaihau committed Mar 22, 2020
1 parent ae5591e commit 789245b
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 29 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

## v0.16.0

Expand Down
111 changes: 83 additions & 28 deletions packages/task/src/browser/quick-open-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,32 +619,56 @@ 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<void> {
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',
run: (): boolean => false,
}));
} 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({
Expand Down Expand Up @@ -677,40 +701,64 @@ 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<void> {
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',
run: (): boolean => false,
}));
} 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);
Expand All @@ -725,7 +773,7 @@ export class TaskRunningQuickOpen implements QuickOpenModel {
}
}

export class TaskRestartRunningQuickOpenItem extends QuickOpenItem {
export class RunningTaskQuickOpenItem extends QuickOpenItem {

constructor(
protected readonly taskInfo: TaskInfo,
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -796,15 +843,23 @@ export class TaskRestartRunningQuickOpen implements QuickOpenModel {
}));
} else {
runningTasks.forEach((task: TaskInfo) => {
items.push(new TaskRestartRunningQuickOpenItem(
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.restartTask(task);
return true;
}
},
));
});
}
Expand Down

0 comments on commit 789245b

Please sign in to comment.