diff --git a/packages/core/src/browser/quick-input/quick-input-service.ts b/packages/core/src/browser/quick-input/quick-input-service.ts index 111e48402a2e6..2fa70defe14ac 100644 --- a/packages/core/src/browser/quick-input/quick-input-service.ts +++ b/packages/core/src/browser/quick-input/quick-input-service.ts @@ -206,6 +206,10 @@ export interface QuickInputService { Promise<(O extends { canPickMany: true } ? T[] : T) | undefined>; showQuickPick(items: Array, options?: QuickPickOptions): Promise; hide(): void; + /** + * Provides raw access to the quick pick controller. + */ + createQuickPick(): QuickPick; } /** diff --git a/packages/monaco/src/browser/monaco-quick-input-service.ts b/packages/monaco/src/browser/monaco-quick-input-service.ts index 8a30933a366a9..ebfc11ec6029c 100644 --- a/packages/monaco/src/browser/monaco-quick-input-service.ts +++ b/packages/monaco/src/browser/monaco-quick-input-service.ts @@ -261,6 +261,12 @@ export class MonacoQuickInputService implements QuickInputService { return item; }); } + + createQuickPick(): QuickPick { + const quickPick = this.monacoService.createQuickPick>(); + return this.wrapQuickPick(quickPick); + } + wrapQuickPick(wrapped: monaco.quickInput.IQuickPick>): QuickPick { return new MonacoQuickPick(wrapped, this.keybindingRegistry); } diff --git a/packages/plugin-ext/src/common/plugin-api-rpc.ts b/packages/plugin-ext/src/common/plugin-api-rpc.ts index ee6afdc844a0b..432d437c5d01e 100644 --- a/packages/plugin-ext/src/common/plugin-api-rpc.ts +++ b/packages/plugin-ext/src/common/plugin-api-rpc.ts @@ -609,7 +609,6 @@ export interface QuickOpenMain { $hide(): void; $showInputBox(options: TransferInputBox, validateInput: boolean): Promise; - $showCustomQuickPick(options: TransferQuickPick): void; } export interface WorkspaceMain { diff --git a/packages/plugin-ext/src/main/browser/quick-open-main.ts b/packages/plugin-ext/src/main/browser/quick-open-main.ts index 2e6482e11eec6..5c2fd8d46213f 100644 --- a/packages/plugin-ext/src/main/browser/quick-open-main.ts +++ b/packages/plugin-ext/src/main/browser/quick-open-main.ts @@ -15,7 +15,7 @@ ********************************************************************************/ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { InputBoxOptions, QuickPickItem as QuickPickItemExt } from '@theia/plugin'; +import { InputBoxOptions } from '@theia/plugin'; import { interfaces } from '@theia/core/shared/inversify'; import { RPCProtocol } from '../../common/rpc-protocol'; import { @@ -23,15 +23,17 @@ import { QuickOpenMain, MAIN_RPC_CONTEXT, TransferInputBox, - TransferQuickPick, TransferQuickPickItems, TransferQuickInput, TransferQuickInputButton } from '../../common/plugin-api-rpc'; import { - InputOptions, PickOptions, QuickInputButton, QuickInputService, QuickPickItem, QuickPickValue + InputOptions, + PickOptions, + QuickInputButton, + QuickInputButtonHandle, + QuickInputService } from '@theia/core/lib/browser'; -import { QuickPickService } from '@theia/core/lib/common/quick-pick-service'; import { DisposableCollection, Disposable } from '@theia/core/lib/common/disposable'; import { CancellationToken } from '@theia/core/lib/common/cancellation'; import { MonacoQuickInputService } from '@theia/monaco/lib/browser/monaco-quick-input-service'; @@ -47,7 +49,6 @@ export interface QuickInputSession { export class QuickOpenMainImpl implements QuickOpenMain, Disposable { private quickInputService: QuickInputService; - private quickPickService: QuickPickService; private proxy: QuickOpenExt; private delegate: MonacoQuickInputService; private readonly items: Record(params: TransferQuickInput): Promise { const sessionId = params.id; - const session = this.sessions.get(sessionId); - // if (!session) { - // if (params.type === 'quickPick') { - // const quickPick = this.quickInputService.createQuickPick(); - // quickPick.onDidAccept(() => { - // this.proxy.$acceptOnDidAccept(sessionId); - // }); - // quickPick.onDidChangeActive((items: Array) => { - // this.proxy.$onDidChangeActive(sessionId, items.map(item => (item as TransferQuickPickItems).handle)); - // }); - // quickPick.onDidChangeSelection((items: Array) => { - // this.proxy.$onDidChangeSelection(sessionId, items.map(item => (item as TransferQuickPickItems).handle)); - // }); - // quickPick.onDidTriggerButton((button: QuickInputButtonHandle) => { - // this.proxy.$acceptOnDidTriggerButton(sessionId, button); - // }); - // quickPick.onDidChangeValue((value: string) => { - // this.proxy.$acceptDidChangeValue(sessionId, value); - // }); - // quickPick.onDidHide(() => { - // this.proxy.$acceptOnDidHide(sessionId); - // }); - // session = { - // input: quickPick, - // handlesToItems: new Map() - // }; - // } else { - // const inputBox = this.quickInputService.createInputBox(); - // inputBox.onDidAccept(() => { - // this.proxy.$acceptOnDidAccept(sessionId); - // }); - // inputBox.onDidTriggerButton((button: QuickInputButtonHandle) => { - // this.proxy.$acceptOnDidTriggerButton(sessionId, button); - // }); - // inputBox.onDidChangeValue((value: string) => { - // this.proxy.$acceptDidChangeValue(sessionId, value); - // }); - // inputBox.onDidHide(() => { - // this.proxy.$acceptOnDidHide(sessionId); - // }); - // session = { - // input: inputBox, - // handlesToItems: new Map() - // }; - // } - // } + let session = this.sessions.get(sessionId); + if (!session) { + if (params.type === 'quickPick') { + const quickPick = this.quickInputService.createQuickPick(); + quickPick.onDidAccept(() => { + this.proxy.$acceptOnDidAccept(sessionId); + }); + quickPick.onDidChangeActive((items: Array) => { + this.proxy.$onDidChangeActive(sessionId, items.map(item => (item as TransferQuickPickItems).handle)); + }); + quickPick.onDidChangeSelection((items: Array) => { + this.proxy.$onDidChangeSelection(sessionId, items.map(item => (item as TransferQuickPickItems).handle)); + }); + quickPick.onDidTriggerButton((button: QuickInputButtonHandle) => { + this.proxy.$acceptOnDidTriggerButton(sessionId, button); + }); + quickPick.onDidChangeValue((value: string) => { + this.proxy.$acceptDidChangeValue(sessionId, value); + }); + quickPick.onDidHide(() => { + this.proxy.$acceptOnDidHide(sessionId); + }); + session = { + input: quickPick, + handlesToItems: new Map() + }; + } else { + const inputBox = this.quickInputService.createInputBox(); + inputBox.onDidAccept(() => { + this.proxy.$acceptOnDidAccept(sessionId); + }); + inputBox.onDidTriggerButton((button: QuickInputButtonHandle) => { + this.proxy.$acceptOnDidTriggerButton(sessionId, button); + }); + inputBox.onDidChangeValue((value: string) => { + this.proxy.$acceptDidChangeValue(sessionId, value); + }); + inputBox.onDidHide(() => { + this.proxy.$acceptOnDidHide(sessionId); + }); + session = { + input: inputBox, + handlesToItems: new Map() + }; + } + this.sessions.set(sessionId, session); + } if (session) { const { input, handlesToItems } = session; for (const param in params) { @@ -297,47 +298,6 @@ export class QuickOpenMainImpl implements QuickOpenMain, Disposable { return Promise.resolve(undefined); } - async $showCustomQuickPick(options: TransferQuickPick): Promise { - const sessionId = options.id; - const toDispose = new DisposableCollection(); - - toDispose.push(this.quickPickService.onDidAccept(() => { - this.proxy.$acceptOnDidAccept(sessionId); - })); - toDispose.push(this.quickPickService.onDidChangeActive((e: { quickPick: any, activeItems: Array> }) => { - this.proxy.$onDidChangeActive(sessionId, e.activeItems.map(item => item.value!)); - })); - toDispose.push(this.quickPickService.onDidChangeSelection((e: { quickPick: any, selectedItems: Array> }) => { - this.proxy.$onDidChangeSelection(sessionId, e.selectedItems.map(item => item.value!)); - })); - toDispose.push(this.quickPickService.onDidChangeValue((e: { quickPick: any, filter: string }) => { - this.proxy.$acceptDidChangeValue(sessionId, e.filter); - })); - toDispose.push(this.quickPickService.onDidTriggerButton(button => { - this.proxy.$acceptOnDidTriggerButton(sessionId, button); - })); - toDispose.push(this.quickPickService.onDidHide(() => { - this.proxy.$acceptOnDidHide(sessionId); - if (!toDispose.disposed) { - toDispose.dispose(); - } - })); - this.toDispose.push(toDispose); - - this.quickPickService.show(this.convertToQuickPickItem(options.items), { - buttons: options.buttons ? this.convertToQuickInputButtons(options.buttons) : [], - placeholder: options.placeholder, - matchOnDescription: options.matchOnDescription, - step: options.step, - title: options.title, - totalSteps: options.totalSteps, - ignoreFocusOut: options.ignoreFocusOut, - value: options.value, - matchOnLabel: true, - runIfSingle: false, - }); - } - $hide(): void { this.delegate.hide(); } @@ -351,21 +311,6 @@ export class QuickOpenMainImpl implements QuickOpenMain, Disposable { return Promise.resolve(undefined); } - private convertToQuickPickItem(items: TransferQuickPickItems[] | undefined): Array { - const convertedItems: QuickPickValue[] = []; - if (items) { - for (const i of items) { - convertedItems.push({ - label: i.label, - description: i.description, - detail: i.detail, - value: i.handle - }); - } - } - return convertedItems; - } - private convertToQuickInputButtons(buttons: Array): Array { return buttons.map((button, i) => ({ iconPath: getIconUris(button.iconPath), diff --git a/packages/plugin-ext/src/plugin/quick-open.ts b/packages/plugin-ext/src/plugin/quick-open.ts index 8a91373630d6e..c4d900f7c167d 100644 --- a/packages/plugin-ext/src/plugin/quick-open.ts +++ b/packages/plugin-ext/src/plugin/quick-open.ts @@ -16,7 +16,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { QuickOpenExt, PLUGIN_RPC_CONTEXT as Ext, QuickOpenMain, TransferInputBox, Plugin, - Item, TransferQuickInputButton, TransferQuickPickItems, TransferQuickInput, TransferQuickPick + Item, TransferQuickInputButton, TransferQuickPickItems, TransferQuickInput } from '../common/plugin-api-rpc'; import * as theia from '@theia/plugin'; import { QuickPickItem, InputBoxOptions, InputBox, QuickPick, QuickInput } from '@theia/plugin'; @@ -178,10 +178,6 @@ export class QuickOpenExtImpl implements QuickOpenExt { return session; } - showCustomQuickPick(options: TransferQuickPick): void { - this.proxy.$showCustomQuickPick(options); - } - hide(): void { this.proxy.$hide(); } @@ -389,6 +385,7 @@ export class QuickInputExt implements QuickInput { this._fireHide(); this.disposableCollection.dispose(); this._onDidDispose(); + this.quickOpenMain.$dispose(this._id); } // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -616,6 +613,7 @@ export class QuickPickExt extends QuickInputExt i this._handlesToItems.set(i, item); this._itemsToHandles.set(item, i); }); + items.forEach((item, i) => Object.assign(item, { handle: i })); this.update({ items }); @@ -690,26 +688,4 @@ export class QuickPickExt extends QuickInputExt i this._selectedItems = items; this._onDidChangeSelectionEmitter.fire(items); } - - show(): void { - super.show(); - this.quickOpen.showCustomQuickPick({ - id: this._id, - title: this.title, - step: this.step, - totalSteps: this.totalSteps, - enabled: this.enabled, - busy: this.busy, - ignoreFocusOut: this.ignoreFocusOut, - value: this.value, - placeholder: this.placeholder, - buttons: this.buttons, - items: convertToTransferQuickPickItems(this.items), - canSelectMany: this.canSelectMany, - matchOnDescription: this.matchOnDescription, - matchOnDetail: this.matchOnDetail, - activeItems: this.activeItems, - selectedItems: this.selectedItems - }); - } }