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

[Plugin-Api] Apply window.createInput() function #5108

Closed
wants to merge 1 commit into from
Closed
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
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 @@ -283,6 +283,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
9 changes: 7 additions & 2 deletions packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,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 @@ -346,6 +347,9 @@ export function createAPIFactory(
console.error('Progress location \'SourceControl\' is not supported.');
});
}
},
createInputBox(): theia.InputBox {
return quickOpenExt.createInputBox();
}
};

Expand Down Expand Up @@ -725,7 +729,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