From b308dfe0d2a46f6d900b57cea83a5aa53b4e5ad1 Mon Sep 17 00:00:00 2001 From: Christof Marti Date: Fri, 15 Jun 2018 10:58:51 +0200 Subject: [PATCH] Enablement flag (#49340) --- .../browser/parts/quickinput/quickInput.ts | 35 ++++++++++++++----- .../browser/parts/quickinput/quickInputBox.ts | 4 +++ .../parts/quickinput/quickInputList.ts | 4 +++ 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/vs/workbench/browser/parts/quickinput/quickInput.ts b/src/vs/workbench/browser/parts/quickinput/quickInput.ts index 516a58f9f20..0fc3a84e941 100644 --- a/src/vs/workbench/browser/parts/quickinput/quickInput.ts +++ b/src/vs/workbench/browser/parts/quickinput/quickInput.ts @@ -36,7 +36,7 @@ import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorG import { IContextKeyService, RawContextKey, IContextKey } from 'vs/platform/contextkey/common/contextkey'; import { ICommandAndKeybindingRule, KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { inQuickOpenContext } from 'vs/workbench/browser/parts/quickopen/quickopen'; -import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar'; +import { ActionBar, ActionItem } from 'vs/base/browser/ui/actionbar/actionbar'; import { Action } from 'vs/base/common/actions'; import URI from 'vs/base/common/uri'; import { IdGenerator } from 'vs/base/common/idGenerator'; @@ -56,6 +56,7 @@ interface QuickInputUI { ignoreFocusOut: boolean; show(controller: QuickInput): void; setVisibilities(visibilities: Visibilities): void; + setEnabled(enabled: boolean): void; hide(): void; } @@ -96,7 +97,7 @@ class QuickInput implements IQuickInput { set enabled(enabled: boolean) { this._enabled = enabled; - this.update(); // TODO + this.update(); } get busy() { @@ -177,6 +178,7 @@ class QuickInput implements IQuickInput { return action; }), { icon: true, label: false }); } + this.ui.setEnabled(this.enabled); } public dispose(): void { @@ -574,7 +576,9 @@ export class QuickInputService extends Component implements IQuickInputService { private filterContainer: HTMLElement; private countContainer: HTMLElement; private okContainer: HTMLElement; + private ok: Button; private ui: QuickInputUI; + private enabled = true; private inQuickOpenWidgets: Record = {}; private inQuickOpenContext: IContextKey; private onDidAcceptEmitter = new Emitter(); @@ -651,11 +655,11 @@ export class QuickInputService extends Component implements IQuickInputService { this.toUnbind.push(attachBadgeStyler(count, this.themeService)); this.okContainer = dom.append(headerContainer, $('.quick-input-action')); - const ok = new Button(this.okContainer); - attachButtonStyler(ok, this.themeService); - ok.label = localize('ok', "OK"); - this.toUnbind.push(ok.onDidClick(e => { - this.onDidAcceptEmitter.fire(); // TODO: make single-select QuickPick exclusively use Accept? + this.ok = new Button(this.okContainer); + attachButtonStyler(this.ok, this.themeService); + this.ok.label = localize('ok', "OK"); + this.toUnbind.push(this.ok.onDidClick(e => { + this.onDidAcceptEmitter.fire(); })); const actionBar = new ActionBar(headerContainer); @@ -740,7 +744,8 @@ export class QuickInputService extends Component implements IQuickInputService { ignoreFocusOut: false, show: controller => this.show(controller), hide: () => this.hide(), - setVisibilities: visibilities => this.setVisibilities(visibilities) + setVisibilities: visibilities => this.setVisibilities(visibilities), + setEnabled: enabled => this.setEnabled(enabled), }; this.updateStyles(); } @@ -877,6 +882,7 @@ export class QuickInputService extends Component implements IQuickInputService { oldController.didHide(); } + this.setEnabled(true); this.ui.checkAll.checked = false; // this.ui.inputBox.value = ''; Avoid triggering an event. this.ui.inputBox.placeholder = ''; @@ -909,6 +915,19 @@ export class QuickInputService extends Component implements IQuickInputService { this.updateLayout(); // TODO } + private setEnabled(enabled: boolean) { + if (enabled !== this.enabled) { + this.enabled = enabled; + this.ui.checkAll.disabled = !enabled; + this.ui.inputBox.enabled = enabled; + for (const item of this.ui.actionBar.items) { + (item as ActionItem).getAction().enabled = enabled; + } + this.ok.enabled = enabled; + this.ui.list.enabled = enabled; + } + } + private hide(focusLost?: boolean) { const controller = this.controller; if (controller) { diff --git a/src/vs/workbench/browser/parts/quickinput/quickInputBox.ts b/src/vs/workbench/browser/parts/quickinput/quickInputBox.ts index e03a4d66cf8..a0dcdf10dca 100644 --- a/src/vs/workbench/browser/parts/quickinput/quickInputBox.ts +++ b/src/vs/workbench/browser/parts/quickinput/quickInputBox.ts @@ -83,6 +83,10 @@ export class QuickInputBox { this.inputBox.inputElement.type = password ? 'password' : 'text'; } + set enabled(enabled: boolean) { + this.inputBox.setEnabled(enabled); + } + showDecoration(decoration: Severity): void { if (decoration === Severity.Ignore) { this.inputBox.hideMessage(); diff --git a/src/vs/workbench/browser/parts/quickinput/quickInputList.ts b/src/vs/workbench/browser/parts/quickinput/quickInputList.ts index 4ccc0b8437d..96551bd6c5c 100644 --- a/src/vs/workbench/browser/parts/quickinput/quickInputList.ts +++ b/src/vs/workbench/browser/parts/quickinput/quickInputList.ts @@ -291,6 +291,10 @@ export class QuickInputList { .map(e => e.item); } + set enabled(value: boolean) { + this.list.getHTMLElement().style.pointerEvents = value ? null : 'none'; + } + focus(what: 'First' | 'Last' | 'Next' | 'Previous' | 'NextPage' | 'PreviousPage'): void { if (!this.list.length) { return; -- GitLab