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..911f54c60763d 100644 --- a/packages/core/src/browser/quick-open/quick-open-service.ts +++ b/packages/core/src/browser/quick-open/quick-open-service.ts @@ -17,73 +17,20 @@ import { injectable } from 'inversify'; import { QuickOpenModel } from './quick-open-model'; import { MessageType } from '../../common/message-service-protocol'; +import * as common from '../../common/quick-open-service'; -export type QuickOpenOptions = Partial; -export namespace QuickOpenOptions { - export interface FuzzyMatchOptions { - /** - * Default: `false` - */ - enableSeparateSubstringMatching?: boolean - } - export interface Resolved { - readonly prefix: string; - readonly placeholder: string; - readonly ignoreFocusOut: boolean; - - readonly fuzzyMatchLabel: boolean | FuzzyMatchOptions; - readonly fuzzyMatchDetail: boolean | FuzzyMatchOptions; - readonly fuzzyMatchDescription: boolean | FuzzyMatchOptions; - readonly fuzzySort: boolean; - - /** The amount of first symbols to be ignored by quick open widget (e.g. don't affect matching). */ - readonly skipPrefix: number; - - /** - * Whether to display the items that don't have any highlight. - */ - readonly showItemsWithoutHighlight: boolean; - - /** - * `true` if the quick open widget provides a way for the user to securely enter a password. - * Otherwise, `false`. - */ - readonly password: boolean; - - selectIndex(lookFor: string): number; - - onClose(canceled: boolean): void; - } - export const defaultOptions: Resolved = Object.freeze({ - prefix: '', - placeholder: '', - ignoreFocusOut: false, - - fuzzyMatchLabel: false, - fuzzyMatchDetail: false, - fuzzyMatchDescription: false, - fuzzySort: false, - - skipPrefix: 0, - - showItemsWithoutHighlight: false, - password: false, - - onClose: () => { /* no-op*/ }, - - selectIndex: () => -1 - }); - export function resolve(options: QuickOpenOptions = {}, source: Resolved = defaultOptions): Resolved { - return Object.assign({}, source, options); - } -} +/** + * @deprecated import from `@theia/core/lib/common/quick-open-service` instead + */ +export { QuickOpenOptions } from '../../common/quick-open-service'; @injectable() export class QuickOpenService { /** * It should be implemented by an extension, e.g. by the monaco extension. */ - open(model: QuickOpenModel, options?: QuickOpenOptions): void { } + open(model: QuickOpenModel, options?: common.QuickOpenOptions): void { } + hide(reason?: common.QuickOpenHideReason): 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..8266d47120cbd 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 @@ -18,6 +18,7 @@ import { injectable, inject } from 'inversify'; import { QuickOpenItem, QuickOpenMode, QuickOpenGroupItem, QuickOpenItemOptions } from './quick-open-model'; import { QuickOpenService } from './quick-open-service'; import { QuickPickService, QuickPickOptions, QuickPickItem, QuickPickSeparator, QuickPickValue } from '../../common/quick-pick-service'; +import { QuickOpenHideReason } from '../../common/quick-open-service'; @injectable() export class QuickPickServiceImpl implements QuickPickService { @@ -84,4 +85,8 @@ export class QuickPickServiceImpl implements QuickPickService { }; } + hide(reason?: QuickOpenHideReason): void { + this.quickOpenService.hide(reason); + } + } diff --git a/packages/core/src/common/quick-open-service.ts b/packages/core/src/common/quick-open-service.ts new file mode 100644 index 0000000000000..0ded30f1e0ad2 --- /dev/null +++ b/packages/core/src/common/quick-open-service.ts @@ -0,0 +1,81 @@ +/******************************************************************************** + * Copyright (C) 2017 TypeFox 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 + ********************************************************************************/ + +export enum QuickOpenHideReason { + ELEMENT_SELECTED, + FOCUS_LOST, + CANCELED, +} + +export type QuickOpenOptions = Partial; +export namespace QuickOpenOptions { + export interface FuzzyMatchOptions { + /** + * Default: `false` + */ + enableSeparateSubstringMatching?: boolean + } + export interface Resolved { + readonly prefix: string; + readonly placeholder: string; + readonly ignoreFocusOut: boolean; + + readonly fuzzyMatchLabel: boolean | FuzzyMatchOptions; + readonly fuzzyMatchDetail: boolean | FuzzyMatchOptions; + readonly fuzzyMatchDescription: boolean | FuzzyMatchOptions; + readonly fuzzySort: boolean; + + /** The amount of first symbols to be ignored by quick open widget (e.g. don't affect matching). */ + readonly skipPrefix: number; + + /** + * Whether to display the items that don't have any highlight. + */ + readonly showItemsWithoutHighlight: boolean; + + /** + * `true` if the quick open widget provides a way for the user to securely enter a password. + * Otherwise, `false`. + */ + readonly password: boolean; + + selectIndex(lookFor: string): number; + + onClose(canceled: boolean): void; + } + export const defaultOptions: Resolved = Object.freeze({ + prefix: '', + placeholder: '', + ignoreFocusOut: false, + + fuzzyMatchLabel: false, + fuzzyMatchDetail: false, + fuzzyMatchDescription: false, + fuzzySort: false, + + skipPrefix: 0, + + showItemsWithoutHighlight: false, + password: false, + + onClose: () => { /* no-op*/ }, + + selectIndex: () => -1 + }); + export function resolve(options: QuickOpenOptions = {}, source: Resolved = defaultOptions): Resolved { + return Object.assign({}, source, options); + } +} diff --git a/packages/core/src/common/quick-pick-service.ts b/packages/core/src/common/quick-pick-service.ts index dbbdcf1b7af7c..6ea15b05b1df5 100644 --- a/packages/core/src/common/quick-pick-service.ts +++ b/packages/core/src/common/quick-pick-service.ts @@ -13,6 +13,7 @@ * * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ +import { QuickOpenHideReason } from './quick-open-service'; export type QuickPickItem = QuickPickValue | QuickPickSeparator; @@ -54,4 +55,6 @@ export interface QuickPickService { show(elements: QuickPickItem[], options?: QuickPickOptions): Promise; + hide(reason?: QuickOpenHideReason): 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..93c74700b8c41 100644 --- a/packages/monaco/src/browser/monaco-quick-open-service.ts +++ b/packages/monaco/src/browser/monaco-quick-open-service.ts @@ -24,6 +24,7 @@ import { import { KEY_CODE_MAP } from './monaco-keycode-map'; import { ContextKey } from '@theia/core/lib/browser/context-key-service'; import { MonacoContextKeyService } from './monaco-context-key-service'; +import { QuickOpenHideReason } from '@theia/core/lib/common/quick-open-service'; export interface MonacoQuickOpenControllerOpts extends monaco.quickOpen.IQuickOpenControllerOpts { readonly prefix?: string; @@ -71,6 +72,22 @@ export class MonacoQuickOpenService extends QuickOpenService { this.internalOpen(new MonacoQuickOpenControllerOptsImpl(model, this.keybindingRegistry, options)); } + hide(reason?: QuickOpenHideReason): void { + let hideReason: monaco.quickOpen.HideReason | undefined; + switch (reason) { + case QuickOpenHideReason.ELEMENT_SELECTED: + hideReason = monaco.quickOpen.HideReason.ELEMENT_SELECTED; + break; + case QuickOpenHideReason.FOCUS_LOST: + hideReason = monaco.quickOpen.HideReason.FOCUS_LOST; + break; + case QuickOpenHideReason.CANCELED: + hideReason = monaco.quickOpen.HideReason.CANCELED; + break; + } + this.widget.hide(hideReason); + } + 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..4f9161282a490 100644 --- a/packages/plugin-ext/src/api/plugin-api.ts +++ b/packages/plugin-ext/src/api/plugin-api.ts @@ -388,6 +388,7 @@ export interface QuickOpenMain { $setItems(items: PickOpenItem[]): Promise; $setError(error: Error): Promise; $input(options: theia.InputBoxOptions, validateInput: boolean): Promise; + $hide(): 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..39ede58e63c6b 100644 --- a/packages/plugin-ext/src/main/browser/quick-open-main.ts +++ b/packages/plugin-ext/src/main/browser/quick-open-main.ts @@ -110,4 +110,8 @@ export class QuickOpenMainImpl implements QuickOpenMain, QuickOpenModel { } } + $hide(): void { + this.delegate.hide(); + } + } diff --git a/packages/plugin-ext/src/plugin/quick-open.ts b/packages/plugin-ext/src/plugin/quick-open.ts index 21a7488733c13..207927eae930d 100644 --- a/packages/plugin-ext/src/plugin/quick-open.ts +++ b/packages/plugin-ext/src/plugin/quick-open.ts @@ -129,8 +129,11 @@ export class QuickOpenExtImpl implements QuickOpenExt { return hookCancellationToken(token, promise); } -} + hide(): void { + this.proxy.$hide(); + } +} /** * 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(); }