Skip to content

Commit

Permalink
Showing 5 changed files with 98 additions and 76 deletions.
69 changes: 7 additions & 62 deletions packages/core/src/browser/quick-open/quick-open-service.ts
Original file line number Diff line number Diff line change
@@ -17,75 +17,20 @@
import { injectable } from 'inversify';
import { QuickOpenModel } from './quick-open-model';
import { MessageType } from '../../common/message-service-protocol';
import { HideReason } from '../../common/quick-pick-service';
import * as common from '../../common/quick-open-service';

export type QuickOpenOptions = Partial<QuickOpenOptions.Resolved>;
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 { }
hide(reason?: HideReason): void { }
open(model: QuickOpenModel, options?: common.QuickOpenOptions): void { }
hide(reason?: common.QuickOpenHideReason): void { }
showDecoration(type: MessageType): void { }
hideDecoration(): void { }
}
Original file line number Diff line number Diff line change
@@ -17,7 +17,8 @@
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, HideReason } from '../../common/quick-pick-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,7 +85,7 @@ export class QuickPickServiceImpl implements QuickPickService {
};
}

hide(reason?: HideReason): void {
hide(reason?: QuickOpenHideReason): void {
this.quickOpenService.hide(reason);
}

81 changes: 81 additions & 0 deletions packages/core/src/common/quick-open-service.ts
Original file line number Diff line number Diff line change
@@ -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<QuickOpenOptions.Resolved>;
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);
}
}
9 changes: 2 additions & 7 deletions packages/core/src/common/quick-pick-service.ts
Original file line number Diff line number Diff line change
@@ -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<T> = QuickPickValue<T> | QuickPickSeparator;

@@ -54,12 +55,6 @@ export interface QuickPickService {

show<T>(elements: QuickPickItem<T>[], options?: QuickPickOptions): Promise<T | undefined>;

hide(reason?: HideReason): void
hide(reason?: QuickOpenHideReason): void

}

export enum HideReason {
ELEMENT_SELECTED,
FOCUS_LOST,
CANCELED,
}
10 changes: 5 additions & 5 deletions packages/monaco/src/browser/monaco-quick-open-service.ts
Original file line number Diff line number Diff line change
@@ -24,7 +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 { HideReason } from '@theia/core/lib/common/quick-pick-service';
import { QuickOpenHideReason } from '@theia/core/lib/common/quick-open-service';

export interface MonacoQuickOpenControllerOpts extends monaco.quickOpen.IQuickOpenControllerOpts {
readonly prefix?: string;
@@ -72,16 +72,16 @@ export class MonacoQuickOpenService extends QuickOpenService {
this.internalOpen(new MonacoQuickOpenControllerOptsImpl(model, this.keybindingRegistry, options));
}

hide(reason?: HideReason): void {
hide(reason?: QuickOpenHideReason): void {
let hideReason: monaco.quickOpen.HideReason | undefined;
switch (reason) {
case HideReason.ELEMENT_SELECTED:
case QuickOpenHideReason.ELEMENT_SELECTED:
hideReason = monaco.quickOpen.HideReason.ELEMENT_SELECTED;
break;
case HideReason.FOCUS_LOST:
case QuickOpenHideReason.FOCUS_LOST:
hideReason = monaco.quickOpen.HideReason.FOCUS_LOST;
break;
case HideReason.CANCELED:
case QuickOpenHideReason.CANCELED:
hideReason = monaco.quickOpen.HideReason.CANCELED;
break;
}

0 comments on commit 2befdf4

Please sign in to comment.