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
Show file tree
Hide file tree
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
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
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Up @@ -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
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-ext/src/api/plugin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
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
Expand Up @@ -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
Expand Up @@ -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
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