Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [Plugin-API] complete QuickPick hide api #5766

Merged
merged 2 commits into from
Jul 26, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: [Plugin-API] complete QuickPick hide api
Signed-off-by: hacke2 <hacke2cn@gmail.com>
hacke2 committed Jul 23, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit ef47a35a93b893bd541667881872da5f64cdbfb7
2 changes: 2 additions & 0 deletions packages/core/src/browser/quick-open/quick-open-service.ts
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
import { injectable } from 'inversify';
import { QuickOpenModel } from './quick-open-model';
import { MessageType } from '../../common/message-service-protocol';
import { HideReason } from '../../common/quick-pick-service';
hacke2 marked this conversation as resolved.
Show resolved Hide resolved

export type QuickOpenOptions = Partial<QuickOpenOptions.Resolved>;
export namespace QuickOpenOptions {
@@ -84,6 +85,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
@@ -17,7 +17,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 { QuickPickService, QuickPickOptions, QuickPickItem, QuickPickSeparator, QuickPickValue, HideReason } from '../../common/quick-pick-service';

@injectable()
export class QuickPickServiceImpl implements QuickPickService {
@@ -84,4 +84,8 @@ export class QuickPickServiceImpl implements QuickPickService {
};
}

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

}
8 changes: 8 additions & 0 deletions packages/core/src/common/quick-pick-service.ts
Original file line number Diff line number Diff line change
@@ -54,4 +54,12 @@ export interface QuickPickService {

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

hide(reason?: HideReason): void

}

export enum HideReason {
hacke2 marked this conversation as resolved.
Show resolved Hide resolved
ELEMENT_SELECTED,
FOCUS_LOST,
CANCELED,
}
17 changes: 17 additions & 0 deletions packages/monaco/src/browser/monaco-quick-open-service.ts
Original file line number Diff line number Diff line change
@@ -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 { HideReason } from '@theia/core/lib/common/quick-pick-service';
hacke2 marked this conversation as resolved.
Show resolved Hide resolved

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?: HideReason): void {
let hideReason: monaco.quickOpen.HideReason | undefined;
switch (reason) {
case HideReason.ELEMENT_SELECTED:
hideReason = monaco.quickOpen.HideReason.ELEMENT_SELECTED;
break;
case HideReason.FOCUS_LOST:
hideReason = monaco.quickOpen.HideReason.FOCUS_LOST;
break;
case HideReason.CANCELED:
hideReason = monaco.quickOpen.HideReason.CANCELED;
break;
}
this.widget.hide(hideReason);
}

showDecoration(type: MessageType): void {
let decoration = monaco.MarkerSeverity.Info;
if (type === MessageType.Warning) {
1 change: 1 addition & 0 deletions packages/plugin-ext/src/api/plugin-api.ts
Original file line number Diff line number Diff line change
@@ -388,6 +388,7 @@ export interface QuickOpenMain {
$setItems(items: PickOpenItem[]): Promise<any>;
$setError(error: Error): Promise<any>;
$input(options: theia.InputBoxOptions, validateInput: boolean): Promise<string | undefined>;
$hide(): void;
}

export interface WorkspaceMain {
4 changes: 4 additions & 0 deletions packages/plugin-ext/src/main/browser/quick-open-main.ts
Original file line number Diff line number Diff line change
@@ -110,4 +110,8 @@ export class QuickOpenMainImpl implements QuickOpenMain, QuickOpenModel {
}
}

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

}
6 changes: 5 additions & 1 deletion packages/plugin-ext/src/plugin/quick-open.ts
Original file line number Diff line number Diff line change
@@ -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<T extends QuickPickItem> implements QuickPick<T> {
}

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