Skip to content

Commit

Permalink
QuickInput/InputBox API`s enhancements
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Vinokur <ivinokur@redhat.com>
  • Loading branch information
vinokurig committed Aug 6, 2019
1 parent 412f832 commit 73ec17c
Show file tree
Hide file tree
Showing 16 changed files with 412 additions and 260 deletions.
21 changes: 5 additions & 16 deletions packages/core/src/browser/keybinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { ContributionProvider } from '../common/contribution-provider';
import { ILogger } from '../common/logger';
import { StatusBarAlignment, StatusBar } from './status-bar/status-bar';
import { ContextKeyService } from './context-key-service';
import * as common from '../common/keybinding';

export enum KeybindingScope {
DEFAULT,
Expand Down Expand Up @@ -60,22 +61,10 @@ export namespace Keybinding {
}
}

export interface Keybinding {
/** Command identifier, this needs to be a unique string. */
command: string;
/** Keybinding string as defined in packages/keymaps/README.md. */
keybinding: string;
/**
* The optional keybinding context where this binding belongs to.
* If not specified, then this keybinding context belongs to the NOOP
* keybinding context.
*/
context?: string;
/**
* https://code.visualstudio.com/docs/getstarted/keybindings#_when-clause-contexts
*/
when?: string;
}
/**
* @deprecated import from `@theia/core/lib/common/keybinding` instead
*/
export type Keybinding = common.Keybinding;

export interface ResolvedKeybinding extends Keybinding {
/**
Expand Down
16 changes: 9 additions & 7 deletions packages/core/src/browser/quick-open/quick-input-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import { Deferred } from '../../common/promise-util';
import { MaybePromise } from '../../common/types';
import { MessageType } from '../../common/message-service-protocol';
import { Emitter, Event } from '../../common/event';
import { QuickTitleBar, QuickInputTitleButton } from './quick-title-bar';
import { QuickTitleBar } from './quick-title-bar';
import { QuickTitleButton } from '../../common/quick-open-model';

export interface QuickInputOptions {

Expand Down Expand Up @@ -53,7 +54,7 @@ export interface QuickInputOptions {
/**
* Buttons that are displayed on the title panel
*/
buttons?: ReadonlyArray<QuickInputTitleButton>
buttons?: ReadonlyArray<QuickTitleButton>

/**
* Text for when there is a problem with the current input value
Expand Down Expand Up @@ -119,10 +120,6 @@ export class QuickInputService {
let currentText = '';
const validateInput = options && options.validateInput;

if (options && this.quickTitleBar.shouldShowTitleBar(options.title, options.step)) {
this.quickTitleBar.attachTitleBar(this.quickOpenService.widgetNode, options.title, options.step, options.totalSteps, options.buttons);
}

this.quickOpenService.open({
onType: async (lookFor, acceptor) => {
this.onDidChangeValueEmitter.fire(lookFor);
Expand Down Expand Up @@ -159,10 +156,15 @@ export class QuickInputService {
this.quickTitleBar.hide();
}
});

if (options && this.quickTitleBar.shouldShowTitleBar(options.title, options.step)) {
this.quickTitleBar.attachTitleBar(this.quickOpenService.widgetNode, options.title, options.step, options.totalSteps, options.buttons);
}

return result.promise;
}

refresh() {
refresh(): void {
this.quickOpenService.refresh();
}

Expand Down
38 changes: 17 additions & 21 deletions packages/core/src/browser/quick-open/quick-open-action-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,24 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { Disposable } from '../../common/disposable';
import { injectable } from 'inversify';
import { QuickOpenItem } from './quick-open-model';

export interface QuickOpenActionProvider {
hasActions(item: QuickOpenItem): boolean;
getActions(item: QuickOpenItem): Promise<QuickOpenAction[]>;
}

export interface QuickOpenActionOptions {
id: string;
label?: string;
tooltip?: string;
class?: string | undefined;
enabled?: boolean;
checked?: boolean;
radio?: boolean;
}

export interface QuickOpenAction extends QuickOpenActionOptions, Disposable {
run(item?: QuickOpenItem): PromiseLike<void>;
}
import { QuickOpenItem } from '../../common/quick-open-model';
import * as common from '../../common/quick-open-model';

/**
* @deprecated import from `@theia/core/lib/common/quick-open-model` instead
*/
export type QuickOpenActionProvider = common.QuickOpenActionProvider;

/**
* @deprecated import from `@theia/core/lib/common/quick-open-model` instead
*/
export type QuickOpenActionOptions = common.QuickOpenActionOptions;

/**
* @deprecated import from `@theia/core/lib/common/quick-open-model` instead
*/
export type QuickOpenAction = common.QuickOpenAction;

@injectable()
export abstract class QuickOpenBaseAction implements QuickOpenAction {
Expand Down
120 changes: 26 additions & 94 deletions packages/core/src/browser/quick-open/quick-open-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,97 +14,29 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import URI from '../../common/uri';
import { Keybinding } from '../keybinding';
import { QuickOpenActionProvider } from './quick-open-action-provider';

export interface Highlight {
start: number
end: number
}

export enum QuickOpenMode {
PREVIEW,
OPEN,
OPEN_IN_BACKGROUND
}

export interface QuickOpenItemOptions {
tooltip?: string;
label?: string;
labelHighlights?: Highlight[];
description?: string;
descriptionHighlights?: Highlight[];
detail?: string;
detailHighlights?: Highlight[];
hidden?: boolean;
uri?: URI;
iconClass?: string;
keybinding?: Keybinding;
run?(mode: QuickOpenMode): boolean;
}
export interface QuickOpenGroupItemOptions extends QuickOpenItemOptions {
groupLabel?: string;
showBorder?: boolean;
}

export class QuickOpenItem<T extends QuickOpenItemOptions = QuickOpenItemOptions> {

constructor(
protected options: T = {} as T
) { }

getTooltip(): string | undefined {
return this.options.tooltip || this.getLabel();
}
getLabel(): string | undefined {
return this.options.label;
}
getLabelHighlights(): Highlight[] {
return this.options.labelHighlights || [];
}
getDescription(): string | undefined {
return this.options.description;
}
getDescriptionHighlights(): Highlight[] | undefined {
return this.options.descriptionHighlights;
}
getDetail(): string | undefined {
return this.options.detail;
}
getDetailHighlights(): Highlight[] | undefined {
return this.options.detailHighlights;
}
isHidden(): boolean {
return this.options.hidden || false;
}
getUri(): URI | undefined {
return this.options.uri;
}
getIconClass(): string | undefined {
return this.options.iconClass;
}
getKeybinding(): Keybinding | undefined {
return this.options.keybinding;
}
run(mode: QuickOpenMode): boolean {
if (!this.options.run) {
return false;
}
return this.options.run(mode);
}
}

export class QuickOpenGroupItem<T extends QuickOpenGroupItemOptions = QuickOpenGroupItemOptions> extends QuickOpenItem<T> {

getGroupLabel(): string | undefined {
return this.options.groupLabel;
}
showBorder(): boolean {
return this.options.showBorder || false;
}
}

export interface QuickOpenModel {
onType(lookFor: string, acceptor: (items: QuickOpenItem[], actionProvider?: QuickOpenActionProvider) => void): void;
}
import * as common from '../../common/quick-open-model';

/**
* @deprecated import from `@theia/core/lib/common/quick-open-model` instead
*/
export type Highlight = common.Highlight;

/**
* @deprecated import from `@theia/core/lib/common/quick-open-model` instead
*/
export type QuickOpenItemOptions = common.QuickOpenItemOptions;

/**
* @deprecated import from `@theia/core/lib/common/quick-open-model` instead
*/
export type QuickOpenGroupItemOptions = common.QuickOpenGroupItemOptions;

/**
* @deprecated import from `@theia/core/lib/common/quick-open-model` instead
*/
export { QuickOpenItem, QuickOpenGroupItem, QuickOpenMode } from '../../common/quick-open-model';

/**
* @deprecated import from `@theia/core/lib/common/quick-open-model` instead
*/
export type QuickOpenModel = common.QuickOpenModel;
32 changes: 23 additions & 9 deletions packages/core/src/browser/quick-open/quick-pick-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,27 @@ export class QuickPickServiceImpl implements QuickPickService {
@inject(QuickOpenService)
protected readonly quickOpenService: QuickOpenService;

private items: QuickOpenItem[] = [];

show(elements: string[], options?: QuickPickOptions): Promise<string | undefined>;
show<T>(elements: QuickPickItem<T>[], options?: QuickPickOptions): Promise<T | undefined>;
async show(elements: (string | QuickPickItem<Object>)[], options?: QuickPickOptions): Promise<Object | undefined> {
return new Promise<Object | undefined>(resolve => {
const items = this.toItems(elements, resolve);
if (items.length === 1) {
items[0].run(QuickOpenMode.OPEN);
this.items = this.toItems(elements, resolve);
if (this.items.length === 1) {
this.items[0].run(QuickOpenMode.OPEN);
return;
}
if (options && this.quickTitleBar.shouldShowTitleBar(options.title, options.step)) {
this.quickTitleBar.attachTitleBar(this.quickOpenService.widgetNode, options.title, options.step, options.totalSteps, options.buttons);
}
const prefix = options && options.value ? options.value : '';
let savedValue: string;
this.quickOpenService.open({
onType: (_, acceptor) => {
acceptor(items);
this.onDidChangeActiveItemsEmitter.fire(items);
onType: (value, acceptor) => {
acceptor(this.items);
if (savedValue !== value) {
this.onDidChangeValueEmitter.fire(value);
this.onDidChangeActiveItemsEmitter.fire(this.items);
savedValue = value;
}
}
}, Object.assign({
onClose: () => {
Expand All @@ -58,6 +62,9 @@ export class QuickPickServiceImpl implements QuickPickService {
fuzzyMatchDescription: true,
prefix
}, options));
if (options && this.quickTitleBar.shouldShowTitleBar(options.title, options.step)) {
this.quickTitleBar.attachTitleBar(this.quickOpenService.widgetNode, options.title, options.step, options.totalSteps, options.buttons);
}
});
}
protected toItems(elements: (string | QuickPickItem<Object>)[], resolve: (element: Object) => void): QuickOpenItem[] {
Expand Down Expand Up @@ -110,4 +117,11 @@ export class QuickPickServiceImpl implements QuickPickService {
private readonly onDidChangeActiveItemsEmitter: Emitter<QuickOpenItem<QuickOpenItemOptions>[]> = new Emitter<QuickOpenItem<QuickOpenItemOptions>[]>();
readonly onDidChangeActiveItems: Event<QuickOpenItem<QuickOpenItemOptions>[]> = this.onDidChangeActiveItemsEmitter.event;

private readonly onDidChangeValueEmitter: Emitter<string> = new Emitter();
readonly onDidChangeValue: Event<string> = this.onDidChangeValueEmitter.event;

setItems(items: QuickOpenItem[]): void {
this.items = items;
this.quickOpenService.refresh();
}
}
Loading

0 comments on commit 73ec17c

Please sign in to comment.