diff --git a/packages/core/src/browser/quick-open/quick-open-model.ts b/packages/core/src/browser/quick-open/quick-open-model.ts index 7b66e1046d456..716a8d7d34bd0 100644 --- a/packages/core/src/browser/quick-open/quick-open-model.ts +++ b/packages/core/src/browser/quick-open/quick-open-model.ts @@ -29,6 +29,12 @@ export enum QuickOpenMode { OPEN_IN_BACKGROUND } +export enum HideReason { + ELEMENT_SELECTED, + FOCUS_LOST, + CANCELED, +} + export interface QuickOpenItemOptions { tooltip?: string; label?: string; diff --git a/packages/core/src/browser/quick-open/quick-open-service.ts b/packages/core/src/browser/quick-open/quick-open-service.ts index 61f68b2928e44..d2700fefd35b5 100644 --- a/packages/core/src/browser/quick-open/quick-open-service.ts +++ b/packages/core/src/browser/quick-open/quick-open-service.ts @@ -15,7 +15,7 @@ ********************************************************************************/ import { injectable } from 'inversify'; -import { QuickOpenModel } from './quick-open-model'; +import { QuickOpenModel, HideReason } from './quick-open-model'; import { MessageType } from '../../common/message-service-protocol'; export type QuickOpenOptions = Partial; @@ -84,6 +84,7 @@ export class QuickOpenService { * It should be implemented by an extension, e.g. by the monaco extension. */ open(model: QuickOpenModel, options?: QuickOpenOptions): void { } + hide(reason?: HideReason): void { } showDecoration(type: MessageType): void { } hideDecoration(): void { } } diff --git a/packages/core/src/browser/quick-open/quick-pick-service-impl.ts b/packages/core/src/browser/quick-open/quick-pick-service-impl.ts index de4f8ea87c32c..0f787ca679a22 100644 --- a/packages/core/src/browser/quick-open/quick-pick-service-impl.ts +++ b/packages/core/src/browser/quick-open/quick-pick-service-impl.ts @@ -15,7 +15,7 @@ ********************************************************************************/ import { injectable, inject } from 'inversify'; -import { QuickOpenItem, QuickOpenMode, QuickOpenGroupItem, QuickOpenItemOptions } from './quick-open-model'; +import { QuickOpenItem, QuickOpenMode, QuickOpenGroupItem, QuickOpenItemOptions, HideReason } from './quick-open-model'; import { QuickOpenService } from './quick-open-service'; import { QuickPickService, QuickPickOptions, QuickPickItem, QuickPickSeparator, QuickPickValue } from '../../common/quick-pick-service'; @@ -84,4 +84,8 @@ export class QuickPickServiceImpl implements QuickPickService { }; } + hide(reason?: HideReason): void { + this.quickOpenService.hide(reason); + } + } diff --git a/packages/core/src/common/quick-pick-service.ts b/packages/core/src/common/quick-pick-service.ts index dbbdcf1b7af7c..1ea74bcfd4765 100644 --- a/packages/core/src/common/quick-pick-service.ts +++ b/packages/core/src/common/quick-pick-service.ts @@ -14,6 +14,8 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ +import { HideReason } from '../browser'; + export type QuickPickItem = QuickPickValue | QuickPickSeparator; export interface QuickPickSeparator { @@ -54,4 +56,6 @@ export interface QuickPickService { show(elements: QuickPickItem[], options?: QuickPickOptions): Promise; + hide(reason?: HideReason): void + } diff --git a/packages/monaco/src/browser/monaco-quick-open-service.ts b/packages/monaco/src/browser/monaco-quick-open-service.ts index 554b65fdb31d4..83481da435a02 100644 --- a/packages/monaco/src/browser/monaco-quick-open-service.ts +++ b/packages/monaco/src/browser/monaco-quick-open-service.ts @@ -18,7 +18,7 @@ import { injectable, inject, postConstruct } from 'inversify'; import { MessageType } from '@theia/core/lib/common/message-service-protocol'; import { QuickOpenService, QuickOpenModel, QuickOpenOptions, QuickOpenItem, QuickOpenGroupItem, - QuickOpenMode, KeySequence, QuickOpenActionProvider, QuickOpenAction, ResolvedKeybinding, + QuickOpenMode, HideReason, KeySequence, QuickOpenActionProvider, QuickOpenAction, ResolvedKeybinding, KeyCode, Key, KeybindingRegistry } from '@theia/core/lib/browser'; import { KEY_CODE_MAP } from './monaco-keycode-map'; @@ -71,6 +71,13 @@ export class MonacoQuickOpenService extends QuickOpenService { this.internalOpen(new MonacoQuickOpenControllerOptsImpl(model, this.keybindingRegistry, options)); } + hide(reason?: HideReason): void { + const hideReason = reason === HideReason.ELEMENT_SELECTED ? monaco.quickOpen.HideReason.ELEMENT_SELECTED : + reason === HideReason.FOCUS_LOST ? monaco.quickOpen.HideReason.FOCUS_LOST : + monaco.quickOpen.HideReason.CANCELED; + this.widget.hide(reason ? hideReason : undefined); + } + showDecoration(type: MessageType): void { let decoration = monaco.MarkerSeverity.Info; if (type === MessageType.Warning) { diff --git a/packages/plugin-ext/src/api/plugin-api.ts b/packages/plugin-ext/src/api/plugin-api.ts index cc3771e05d407..f8619c9e0ef81 100644 --- a/packages/plugin-ext/src/api/plugin-api.ts +++ b/packages/plugin-ext/src/api/plugin-api.ts @@ -267,6 +267,12 @@ export interface PickOpenItem { picked?: boolean; } +export enum HideReason { + ELEMENT_SELECTED, + FOCUS_LOST, + CANCELED, +} + export enum MainMessageType { Error, Warning, @@ -388,6 +394,7 @@ export interface QuickOpenMain { $setItems(items: PickOpenItem[]): Promise; $setError(error: Error): Promise; $input(options: theia.InputBoxOptions, validateInput: boolean): Promise; + $hide(reason?: HideReason): 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 e1f82a3e04ce1..79dd183cce7a0 100644 --- a/packages/plugin-ext/src/main/browser/quick-open-main.ts +++ b/packages/plugin-ext/src/main/browser/quick-open-main.ts @@ -16,7 +16,7 @@ import { InputBoxOptions } from '@theia/plugin'; import { interfaces } from 'inversify'; -import { QuickOpenModel, QuickOpenItem, QuickOpenMode } from '@theia/core/lib/browser/quick-open/quick-open-model'; +import { QuickOpenModel, QuickOpenItem, QuickOpenMode, HideReason } from '@theia/core/lib/browser/quick-open/quick-open-model'; import { RPCProtocol } from '../../api/rpc-protocol'; import { QuickOpenExt, QuickOpenMain, MAIN_RPC_CONTEXT, PickOptions, PickOpenItem } from '../../api/plugin-api'; import { MonacoQuickOpenService } from '@theia/monaco/lib/browser/monaco-quick-open-service'; @@ -110,4 +110,8 @@ export class QuickOpenMainImpl implements QuickOpenMain, QuickOpenModel { } } + $hide(reason?: HideReason): void { + this.delegate.hide(reason); + } + } diff --git a/packages/plugin-ext/src/plugin/quick-open.ts b/packages/plugin-ext/src/plugin/quick-open.ts index 21a7488733c13..094b9e00f216f 100644 --- a/packages/plugin-ext/src/plugin/quick-open.ts +++ b/packages/plugin-ext/src/plugin/quick-open.ts @@ -13,7 +13,7 @@ * * 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 { QuickOpenExt, PLUGIN_RPC_CONTEXT as Ext, QuickOpenMain, PickOpenItem, HideReason } from '../api/plugin-api'; import { QuickPickOptions, QuickPickItem, InputBoxOptions } from '@theia/plugin'; import { CancellationToken } from '@theia/core/lib/common/cancellation'; import { RPCProtocol } from '../api/rpc-protocol'; @@ -129,8 +129,11 @@ export class QuickOpenExtImpl implements QuickOpenExt { return hookCancellationToken(token, promise); } -} + hide(reason?: HideReason): void { + this.proxy.$hide(reason); + } +} /** * Base implementation of {@link QuickPick} that uses {@link QuickOpenExt}. * Missing functionality is going to be implemented in the scope of https://github.com/theia-ide/theia/issues/5059 @@ -231,6 +234,7 @@ export class QuickPickExt implements QuickPick { } hide(): void { + this.quickOpen.hide(); this.dispose(); }