Skip to content

Commit

Permalink
fix: [Plugin-API] complete QuickPick hide api
Browse files Browse the repository at this point in the history
Signed-off-by: hacke2 <[email protected]>
  • Loading branch information
hacke2 committed Jul 22, 2019
1 parent 3587c23 commit bc3e5a8
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 6 deletions.
6 changes: 6 additions & 0 deletions packages/core/src/browser/quick-open/quick-open-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/browser/quick-open/quick-open-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<QuickOpenOptions.Resolved>;
Expand Down Expand Up @@ -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 { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -84,4 +84,8 @@ export class QuickPickServiceImpl implements QuickPickService {
};
}

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

}
4 changes: 4 additions & 0 deletions packages/core/src/common/quick-pick-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = QuickPickValue<T> | QuickPickSeparator;

export interface QuickPickSeparator {
Expand Down Expand Up @@ -54,4 +56,6 @@ export interface QuickPickService {

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

hide(reason?: HideReason): void

}
9 changes: 8 additions & 1 deletion packages/monaco/src/browser/monaco-quick-open-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions packages/plugin-ext/src/api/plugin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ export interface PickOpenItem {
picked?: boolean;
}

export enum HideReason {
ELEMENT_SELECTED,
FOCUS_LOST,
CANCELED,
}

export enum MainMessageType {
Error,
Warning,
Expand Down Expand Up @@ -388,6 +394,7 @@ export interface QuickOpenMain {
$setItems(items: PickOpenItem[]): Promise<any>;
$setError(error: Error): Promise<any>;
$input(options: theia.InputBoxOptions, validateInput: boolean): Promise<string | undefined>;
$hide(reason?: HideReason): void;
}

export interface WorkspaceMain {
Expand Down
6 changes: 5 additions & 1 deletion packages/plugin-ext/src/main/browser/quick-open-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -110,4 +110,8 @@ export class QuickOpenMainImpl implements QuickOpenMain, QuickOpenModel {
}
}

$hide(reason?: HideReason): void {
this.delegate.hide(reason);
}

}
8 changes: 6 additions & 2 deletions packages/plugin-ext/src/plugin/quick-open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -231,6 +234,7 @@ export class QuickPickExt<T extends QuickPickItem> implements QuickPick<T> {
}

hide(): void {
this.quickOpen.hide();
this.dispose();
}

Expand Down

0 comments on commit bc3e5a8

Please sign in to comment.