Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

align how tasks are displayed as quick open items #7392

Merged
merged 1 commit into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

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)
RomanNikitenko marked this conversation as resolved.
Show resolved Hide resolved
- [task] `TaskAttachQuickOpenItem` class is removed.

## v0.16.0

Expand Down
174 changes: 110 additions & 64 deletions packages/task/src/browser/quick-open-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler {
@inject(PreferenceService)
protected readonly preferences: PreferenceService;

@inject(LabelProvider)
protected readonly labelProvider: LabelProvider;

/** Initialize this quick open model with the tasks. */
async init(): Promise<void> {
const recentTasks = this.taskService.recentTasks;
Expand Down Expand Up @@ -196,25 +199,37 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler {
attach(): void {
this.items = [];
this.actionProvider = undefined;

const isMulti: boolean = this.workspaceService.isMultiRootWorkspaceOpened;
this.taskService.getRunningTasks().then(tasks => {
if (!tasks.length) {
this.items.push(new QuickOpenItem({
label: 'No tasks found',
run: (_mode: QuickOpenMode): boolean => false
}));
}
for (const task of tasks) {
// can only attach to terminal processes, so only list those
if (task.terminalId) {
this.items.push(
new TaskAttachQuickOpenItem(
} else {
tasks.forEach((task: TaskInfo) => {
// can only attach to terminal processes, so only list those
if (task.terminalId) {
this.items.push(new RunningTaskQuickOpenItem(
task,
this.getRunningTaskLabel(task),
this.taskService
)
);
}
this.taskService,
this.taskNameResolver,
this.taskSourceResolver,
this.taskDefinitionRegistry,
this.labelProvider,
isMulti,
{
run: (mode: QuickOpenMode): boolean => {
if (mode !== QuickOpenMode.OPEN) {
return false;
}
this.taskService.attach(task.terminalId!, task.taskId);
return true;
}
},
));
}
});
}
this.quickOpenService.open(this, {
placeholder: 'Choose task to open',
Expand Down Expand Up @@ -543,30 +558,6 @@ export class ConfigureBuildOrTestTaskQuickOpenItem extends TaskRunQuickOpenItem
}
}

export class TaskAttachQuickOpenItem extends QuickOpenItem {

constructor(
protected readonly task: TaskInfo,
protected readonly taskLabel: string,
protected taskService: TaskService
) {
super();
}

getLabel(): string {
return this.taskLabel!;
}

run(mode: QuickOpenMode): boolean {
if (mode !== QuickOpenMode.OPEN) {
return false;
}
if (this.task.terminalId) {
this.taskService.attach(this.task.terminalId, this.task.taskId);
}
return true;
}
}
export class TaskConfigureQuickOpenItem extends QuickOpenGroupItem {

protected taskDefinitionRegistry: TaskDefinitionRegistry;
Expand Down Expand Up @@ -619,32 +610,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 +692,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 +764,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 +792,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 +834,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