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

Add ability to configure task #4714

Merged
merged 1 commit into from
Apr 3, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## v0.6.0

- [filesystem] added the menu item `Upload Files...` to easily upload files into a workspace
- [task] added support to configure tasks
- [workspace] allow creation of files and folders using recursive paths

Breaking changes:
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/browser/quick-open/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
********************************************************************************/

export * from './quick-open-model';
export * from './quick-open-action-provider';
export * from './quick-open-service';
export * from './quick-pick-service';
export * from './quick-input-service';
Expand Down
100 changes: 100 additions & 0 deletions packages/core/src/browser/quick-open/quick-open-action-provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/********************************************************************************
* Copyright (C) 2019 Red Hat, Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { Disposable } from '../../common/disposable';
import { injectable } from 'inversify';
import { QuickOpenItem } from './quick-open-model';

export interface QuickOpenActionProvider {
hasActions(item: QuickOpenItem): boolean;
getActions(item: QuickOpenItem): Promise<QuickOpenAction[]>;
}

export interface QuickOpenActionOptions {
id: string;
label?: string;
tooltip?: string;
class?: string | undefined;
enabled?: boolean;
checked?: boolean;
radio?: boolean;
}

export interface QuickOpenAction extends QuickOpenActionOptions, Disposable {
run(item?: QuickOpenItem): PromiseLike<void>;
}

@injectable()
export abstract class QuickOpenBaseAction implements QuickOpenAction {
constructor(protected options: QuickOpenActionOptions) {
}

get id(): string {
return this.options.id;
}

get label(): string {
return this.options.label || '';
}

set label(value: string) {
this.options.label = value;
}

get tooltip(): string {
return this.options.tooltip || '';
}

set tooltip(value: string) {
this.options.tooltip = value;
}

get class(): string | undefined {
return this.options.class || '';
}

set class(value: string | undefined) {
this.options.class = value;
}

get enabled(): boolean {
return this.options.enabled || true;
}

set enabled(value: boolean) {
this.options.enabled = value;
}

get checked(): boolean {
return this.options.checked || false;
}

set checked(value: boolean) {
this.options.checked = value;
}

get radio(): boolean {
return this.options.radio || false;
}

set radio(value: boolean) {
this.options.radio = value;
}

abstract run(item?: QuickOpenItem): PromiseLike<void>;

dispose(): void { }
}
3 changes: 2 additions & 1 deletion packages/core/src/browser/quick-open/quick-open-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import URI from '../../common/uri';
import { Keybinding } from '../keybinding';
import { QuickOpenActionProvider } from './quick-open-action-provider';

export interface Highlight {
start: number
Expand Down Expand Up @@ -105,5 +106,5 @@ export class QuickOpenGroupItem<T extends QuickOpenGroupItemOptions = QuickOpenG
}

export interface QuickOpenModel {
onType(lookFor: string, acceptor: (items: QuickOpenItem[]) => void): void;
onType(lookFor: string, acceptor: (items: QuickOpenItem[], actionProvider?: QuickOpenActionProvider) => void): void;
}
81 changes: 75 additions & 6 deletions packages/monaco/src/browser/monaco-quick-open-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import { injectable, inject, postConstruct } from 'inversify';
import { MessageType } from '@theia/core/lib/common/message-service-protocol';
import {
QuickOpenService, QuickOpenModel, QuickOpenOptions,
QuickOpenItem, QuickOpenGroupItem, QuickOpenMode, KeySequence
QuickOpenService, QuickOpenModel, QuickOpenOptions, QuickOpenItem,
QuickOpenGroupItem, QuickOpenMode, KeySequence, QuickOpenActionProvider, QuickOpenAction
} from '@theia/core/lib/browser';
import { KEY_CODE_MAP } from './monaco-keycode-map';
import { ContextKey } from '@theia/core/lib/browser/context-key-service';
Expand Down Expand Up @@ -215,7 +215,7 @@ export class MonacoQuickOpenControllerOptsImpl implements MonacoQuickOpenControl
this.options.onClose(cancelled);
}

private toOpenModel(lookFor: string, items: QuickOpenItem[]): monaco.quickOpen.QuickOpenModel {
private toOpenModel(lookFor: string, items: QuickOpenItem[], actionProvider?: QuickOpenActionProvider): monaco.quickOpen.QuickOpenModel {
const entries: monaco.quickOpen.QuickOpenEntry[] = [];
for (const item of items) {
const entry = this.createEntry(item, lookFor);
Expand All @@ -226,16 +226,16 @@ export class MonacoQuickOpenControllerOptsImpl implements MonacoQuickOpenControl
if (this.options.fuzzySort) {
entries.sort((a, b) => monaco.quickOpen.compareEntries(a, b, lookFor));
}
return new monaco.quickOpen.QuickOpenModel(entries);
return new monaco.quickOpen.QuickOpenModel(entries, actionProvider ? new MonacoQuickOpenActionProvider(actionProvider) : undefined);
}

getModel(lookFor: string): monaco.quickOpen.QuickOpenModel {
throw new Error('getModel not supported!');
}

onType(lookFor: string, acceptor: (model: monaco.quickOpen.QuickOpenModel) => void): void {
this.model.onType(lookFor, items => {
const result = this.toOpenModel(lookFor, items);
this.model.onType(lookFor, (items, actionProvider) => {
const result = this.toOpenModel(lookFor, items, actionProvider);
acceptor(result);
});
}
Expand Down Expand Up @@ -408,3 +408,72 @@ export class QuickOpenEntryGroup extends monaco.quickOpen.QuickOpenEntryGroup {
}

}

export class MonacoQuickOpenAction implements monaco.quickOpen.IAction {
constructor(public readonly action: QuickOpenAction) { }

get id(): string {
return this.action.id;
}

get label(): string {
return this.action.label || '';
}

get tooltip(): string {
return this.action.tooltip || '';
}

get class(): string | undefined {
return this.action.class;
}

get enabled(): boolean {
return this.action.enabled || true;
}

get checked(): boolean {
return this.action.checked || false;
}

get radio(): boolean {
return this.action.radio || false;
}

// tslint:disable-next-line:no-any
run(entry: QuickOpenEntry | QuickOpenEntryGroup): PromiseLike<any> {
return this.action.run(entry.item);
}

dispose(): void {
this.action.dispose();
}
}

export class MonacoQuickOpenActionProvider implements monaco.quickOpen.IActionProvider {
constructor(public readonly provider: QuickOpenActionProvider) { }

// tslint:disable-next-line:no-any
hasActions(element: any, entry: QuickOpenEntry | QuickOpenEntryGroup): boolean {
return this.provider.hasActions(entry.item);
}

// tslint:disable-next-line:no-any
async getActions(element: any, entry: QuickOpenEntry | QuickOpenEntryGroup): monaco.Promise<monaco.quickOpen.IAction[]> {
const actions = await this.provider.getActions(entry.item);
const monacoActions = actions.map(action => new MonacoQuickOpenAction(action));
return monaco.Promise.wrap(monacoActions);
}

hasSecondaryActions(): boolean {
return false;
}

getSecondaryActions(): monaco.Promise<monaco.quickOpen.IAction[]> {
return monaco.Promise.wrap([]);
}

getActionItem() {
return undefined;
}
}
22 changes: 21 additions & 1 deletion packages/monaco/src/typings/monaco/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,28 @@ declare module monaco.quickOpen {
setShowBorder(showBorder: boolean): void;
getEntry(): QuickOpenEntry | undefined;
}

export interface IAction extends IDisposable {
id: string;
label: string;
tooltip: string;
class: string | undefined;
enabled: boolean;
checked: boolean;
radio: boolean;
run(event?: any): PromiseLike<any>;
}

export interface IActionProvider {
hasActions(element: any, item: any): boolean;
getActions(element: any, item: any): monaco.Promise<IAction[]>;
hasSecondaryActions(element: any, item: any): boolean;
getSecondaryActions(element: any, item: any): monaco.Promise<IAction[]>;
getActionItem(element: any, item: any, action: IAction): any;
}

export class QuickOpenModel implements IModel<QuickOpenEntry>, IDataSource<QuickOpenEntry>, IFilter<QuickOpenEntry>, IRunner<QuickOpenEntry> {
constructor(entries?: QuickOpenEntry[] /*, actionProvider?: IActionProvider */);
constructor(entries?: QuickOpenEntry[], actionProvider?: IActionProvider);
addEntries(entries: QuickOpenEntry[]): void;
entries: QuickOpenEntry[];
dataSource: IDataSource<QuickOpenEntry>;
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-ext/src/plugin/tasks/task-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export class TaskProviderAdapter {
return Promise.resolve(undefined);
}
const id = ObjectIdentifier.of(task);
const item = this.cache.get(id);
const cached = this.cache.get(id);
const item = cached ? cached : Converter.toTask(task);
if (!item) {
return Promise.resolve(undefined);
}
Expand Down
Loading