Skip to content

Commit

Permalink
[Plugin-Api] Apply window.createInput() function
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Vinokur <ivinokur@redhat.com>
  • Loading branch information
vinokurig authored and JPinkney committed Jun 4, 2019
1 parent 92cfe9a commit df80217
Show file tree
Hide file tree
Showing 8 changed files with 312 additions and 6 deletions.
7 changes: 7 additions & 0 deletions packages/core/src/browser/quick-open/quick-input-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { QuickOpenItem, QuickOpenMode } from './quick-open-model';
import { Deferred } from '../../common/promise-util';
import { MaybePromise } from '../../common/types';
import { MessageType } from '../../common/message-service-protocol';
import { Emitter, Event } from '../../common/event';

export interface QuickInputOptions {
/**
Expand Down Expand Up @@ -83,6 +84,7 @@ export class QuickInputService {
run: mode => {
if (!error && mode === QuickOpenMode.OPEN) {
result.resolve(currentText);
this.onDidAcceptEmitter.fire(undefined);
return true;
}
return false;
Expand All @@ -105,4 +107,9 @@ export class QuickInputService {
return prompt ? `${prompt} (${this.defaultPrompt})` : this.defaultPrompt;
}

readonly onDidAcceptEmitter: Emitter<void> = new Emitter();
get onDidAccept(): Event<void> {
return this.onDidAcceptEmitter.event;
}

}
1 change: 1 addition & 0 deletions packages/monaco/src/browser/monaco-quick-open-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class MonacoQuickOpenService extends QuickOpenService {
container.style.position = 'absolute';
container.style.top = '0px';
container.style.right = '50%';
container.style.zIndex = '1000000';
overlayWidgets.appendChild(container);
}

Expand Down
1 change: 1 addition & 0 deletions packages/plugin-ext/src/api/plugin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ export interface StatusBarMessageRegistryMain {
export interface QuickOpenExt {
$onItemSelected(handle: number): void;
$validateInput(input: string): PromiseLike<string | undefined> | undefined;
$acceptInput(): Promise<void>;
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-ext/src/main/browser/quick-open-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class QuickOpenMainImpl implements QuickOpenMain, QuickOpenModel {
this.proxy = rpc.getProxy(MAIN_RPC_CONTEXT.QUICK_OPEN_EXT);
this.delegate = container.get(MonacoQuickOpenService);
this.quickInput = container.get(QuickInputService);
this.quickInput.onDidAccept(() => this.proxy.$acceptInput());
}

private cleanUp() {
Expand Down
13 changes: 9 additions & 4 deletions packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ import {
ColorPresentation,
OperatingSystem,
WebviewPanelTargetArea,
FileSystemError
FileSystemError,
QuickInputButtons
} from './types-impl';
import { SymbolKind } from '../api/model';
import { EditorsAndDocumentsExtImpl } from './editors-and-documents';
Expand Down Expand Up @@ -211,7 +212,7 @@ export function createAPIFactory(
},
registerDiffInformationCommand(command: string, callback: (diff: LineChange[], ...args: any[]) => any, thisArg?: any): Disposable {
// Dummy implementation.
return new Disposable(() => {});
return new Disposable(() => { });
}
};

Expand Down Expand Up @@ -368,7 +369,10 @@ export function createAPIFactory(
return decorationsExt.registerDecorationProvider(provider);
},
registerUriHandler(handler: theia.UriHandler): theia.Disposable {
return new Disposable(() => {});
return new Disposable(() => { });
},
createInputBox(): theia.InputBox {
return quickOpenExt.createInputBox();
}
};

Expand Down Expand Up @@ -771,7 +775,8 @@ export function createAPIFactory(
FoldingRangeKind,
OperatingSystem,
WebviewPanelTargetArea,
FileSystemError
FileSystemError,
QuickInputButtons
};
};
}
Expand Down
90 changes: 88 additions & 2 deletions packages/plugin-ext/src/plugin/quick-open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { QuickOpenExt, PLUGIN_RPC_CONTEXT as Ext, QuickOpenMain, PickOpenItem } from '../api/plugin-api';
import { QuickPickOptions, QuickPickItem, InputBoxOptions } from '@theia/plugin';
import { QuickPickOptions, QuickPickItem, InputBoxOptions, InputBox, QuickInputButton, QuickPick } from '@theia/plugin';
import { CancellationToken } from '@theia/core/lib/common/cancellation';
import { RPCProtocol } from '../api/rpc-protocol';
import { anyPromise } from '../api/async-util';
import { hookCancellationToken } from '../api/async-util';
import { Emitter, Event } from '@theia/core/lib/common/event';
import { QuickPick, QuickInputButton } from '@theia/plugin';
import { DisposableCollection } from '@theia/core/lib/common/disposable';

export type Item = string | QuickPickItem;
Expand All @@ -29,9 +28,11 @@ export class QuickOpenExtImpl implements QuickOpenExt {
private proxy: QuickOpenMain;
private selectItemHandler: undefined | ((handle: number) => void);
private validateInputHandler: undefined | ((input: string) => string | PromiseLike<string | undefined> | undefined);
private onDidAcceptInputEmitter: Emitter<void>;

constructor(rpc: RPCProtocol) {
this.proxy = rpc.getProxy(Ext.QUICK_OPEN_MAIN);
this.onDidAcceptInputEmitter = new Emitter();
}
$onItemSelected(handle: number): void {
if (this.selectItemHandler) {
Expand Down Expand Up @@ -129,6 +130,91 @@ export class QuickOpenExtImpl implements QuickOpenExt {
return hookCancellationToken(token, promise);
}

createInputBox(): InputBox {
return new InputBoxExt(this, this.onDidAcceptInputEmitter);
}

async $acceptInput(): Promise<void> {
this.onDidAcceptInputEmitter.fire(undefined);
}

}

/**
* Base implementation of {@link InputBox} that uses {@link QuickOpenExt}.
* Missing functionality is going to be implemented in the scope of https://github.com/theia-ide/theia/issues/5109
*/
export class InputBoxExt implements InputBox {

busy: boolean;
buttons: ReadonlyArray<QuickInputButton>;
enabled: boolean;
ignoreFocusOut: boolean;
password: boolean;
placeholder: string | undefined;
prompt: string | undefined;
step: number | undefined;
title: string | undefined;
totalSteps: number | undefined;
validationMessage: string | undefined;
value: string;

private readonly disposables: DisposableCollection;
private readonly onDidChangeValueEmitter: Emitter<string>;
private readonly onDidHideEmitter: Emitter<void>;
private readonly onDidTriggerButtonEmitter: Emitter<QuickInputButton>;

constructor(readonly quickOpen: QuickOpenExtImpl, readonly onDidAcceptEmitter: Emitter<void>) {
this.disposables = new DisposableCollection();
this.disposables.push(this.onDidChangeValueEmitter = new Emitter());
this.disposables.push(this.onDidHideEmitter = new Emitter());
this.disposables.push(this.onDidTriggerButtonEmitter = new Emitter());
}

get onDidChangeValue(): Event<string> {
return this.onDidChangeValueEmitter.event;
}

get onDidAccept(): Event<void> {
return this.onDidAcceptEmitter.event;
}

get onDidHide(): Event<void> {
return this.onDidHideEmitter.event;
}

get onDidTriggerButton(): Event<QuickInputButton> {
return this.onDidTriggerButtonEmitter.event;
}

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

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

show(): void {
const update = (value: string) => {
this.onDidChangeValueEmitter.fire(value);
if (this.validationMessage && this.validationMessage.length > 0) {
return this.validationMessage;
}
};
this.quickOpen.showInput({
password: this.password,
placeHolder: this.placeholder,
prompt: this.prompt,
value: this.value,
ignoreFocusOut: this.ignoreFocusOut,
validateInput(value: string): string | undefined {
if (value.length > 0) {
return update(value);
}
}
});
}
}

/**
Expand Down
9 changes: 9 additions & 0 deletions packages/plugin-ext/src/plugin/types-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,15 @@ export enum FileChangeType {
Deleted = 3,
}

export interface QuickInputButton {
readonly iconPath: ThemeIcon;
readonly tooltip?: string | undefined;
}

export class QuickInputButtons {
static readonly Back: QuickInputButton;
}

export class FileSystemError extends Error {

static FileExists(messageOrUri?: string | URI): FileSystemError {
Expand Down
Loading

0 comments on commit df80217

Please sign in to comment.