diff --git a/src/vs/platform/quickinput/common/quickInput.ts b/src/vs/platform/quickinput/common/quickInput.ts index 49c079ab126aa..0e877b51bf49b 100644 --- a/src/vs/platform/quickinput/common/quickInput.ts +++ b/src/vs/platform/quickinput/common/quickInput.ts @@ -51,6 +51,11 @@ export interface IPickOptions { */ canPickMany?: boolean; + /** + * a context key to set when this picker is active + */ + contextKey?: string; + /** * an optional property for the item to focus initially. */ @@ -104,6 +109,8 @@ export interface IQuickInput { enabled: boolean; + contextKey: string | undefined; + busy: boolean; ignoreFocusOut: boolean; diff --git a/src/vs/workbench/browser/parts/quickinput/quickInput.ts b/src/vs/workbench/browser/parts/quickinput/quickInput.ts index 50da9587f5af8..b668f260e620d 100644 --- a/src/vs/workbench/browser/parts/quickinput/quickInput.ts +++ b/src/vs/workbench/browser/parts/quickinput/quickInput.ts @@ -73,6 +73,7 @@ interface QuickInputUI { show(controller: QuickInput): void; setVisibilities(visibilities: Visibilities): void; setEnabled(enabled: boolean): void; + setContextKey(contextKey?: string): void; hide(): void; } @@ -94,6 +95,7 @@ class QuickInput implements IQuickInput { private _totalSteps: number; protected visible = false; private _enabled = true; + private _contextKey: string; private _busy = false; private _ignoreFocusOut = false; private _buttons: IQuickInputButton[] = []; @@ -148,6 +150,15 @@ class QuickInput implements IQuickInput { this.update(); } + get contextKey() { + return this._contextKey; + } + + set contextKey(contextKey: string) { + this._contextKey = contextKey; + this.update(); + } + get busy() { return this._busy; } @@ -249,6 +260,7 @@ class QuickInput implements IQuickInput { } this.ui.ignoreFocusOut = this.ignoreFocusOut; this.ui.setEnabled(this.enabled); + this.ui.setContextKey(this.contextKey); } private getTitle() { @@ -740,6 +752,7 @@ export class QuickInputService extends Component implements IQuickInputService { private enabled = true; private inQuickOpenWidgets: Record = {}; private inQuickOpenContext: IContextKey; + private contexts: { [id: string]: IContextKey; } = Object.create(null); private onDidAcceptEmitter = this._register(new Emitter()); private onDidTriggerButtonEmitter = this._register(new Emitter()); @@ -753,7 +766,7 @@ export class QuickInputService extends Component implements IQuickInputService { @IQuickOpenService private quickOpenService: IQuickOpenService, @IEditorGroupsService private editorGroupService: IEditorGroupsService, @IKeybindingService private keybindingService: IKeybindingService, - @IContextKeyService contextKeyService: IContextKeyService, + @IContextKeyService private contextKeyService: IContextKeyService, @IThemeService themeService: IThemeService ) { super(QuickInputService.ID, themeService); @@ -779,6 +792,36 @@ export class QuickInputService extends Component implements IQuickInputService { } } + private setContextKey(id?: string) { + let key: IContextKey; + if (id) { + key = this.contexts[id]; + if (!key) { + key = new RawContextKey(id, false) + .bindTo(this.contextKeyService); + this.contexts[id] = key; + } + } + + if (key && key.get()) { + return; // already active context + } + + this.resetContextKeys(); + + if (key) { + key.set(true); + } + } + + private resetContextKeys() { + for (const key in this.contexts) { + if (this.contexts[key].get()) { + this.contexts[key].reset(); + } + } + } + private create() { if (this.ui) { return; @@ -923,6 +966,7 @@ export class QuickInputService extends Component implements IQuickInputService { hide: () => this.hide(), setVisibilities: visibilities => this.setVisibilities(visibilities), setEnabled: enabled => this.setEnabled(enabled), + setContextKey: contextKey => this.setContextKey(contextKey), }; this.updateStyles(); } @@ -976,6 +1020,7 @@ export class QuickInputService extends Component implements IQuickInputService { input.ignoreFocusOut = options.ignoreFocusLost; input.matchOnDescription = options.matchOnDescription; input.matchOnDetail = options.matchOnDetail; + input.contextKey = options.contextKey; input.busy = true; TPromise.join([picks, options.activeItem]) .then(([items, activeItem]) => { @@ -1096,6 +1141,7 @@ export class QuickInputService extends Component implements IQuickInputService { backButton.tooltip = keybinding ? localize('quickInput.backWithKeybinding', "Back ({0})", keybinding.getLabel()) : localize('quickInput.back', "Back"); this.inQuickOpen('quickInput', true); + this.resetContextKeys(); this.ui.container.style.display = ''; this.updateLayout(); @@ -1136,6 +1182,7 @@ export class QuickInputService extends Component implements IQuickInputService { if (controller) { this.controller = null; this.inQuickOpen('quickInput', false); + this.resetContextKeys(); this.ui.container.style.display = 'none'; if (!focusLost) { this.editorGroupService.activeGroup.focus();