diff --git a/src/tsconfig.strictNullChecks.json b/src/tsconfig.strictNullChecks.json index 90a539dde0e17d9c522c2acef60311c414bde062..ab8e5b60a0810c4182f9d8191873ac1432b97f8d 100644 --- a/src/tsconfig.strictNullChecks.json +++ b/src/tsconfig.strictNullChecks.json @@ -22,6 +22,7 @@ "./vs/base/browser/keyboardEvent.ts", "./vs/base/browser/mouseEvent.ts", "./vs/base/browser/touch.ts", + "./vs/base/browser/ui/actionbar/actionbar.ts", "./vs/base/browser/ui/aria/aria.ts", "./vs/base/browser/ui/breadcrumbs/breadcrumbsWidget.ts", "./vs/base/browser/ui/button/button.ts", diff --git a/src/vs/base/browser/ui/actionbar/actionbar.ts b/src/vs/base/browser/ui/actionbar/actionbar.ts index f9538a497edd1dfaf148389a38707f291d09a310..163cdd0574e70156b3e111f80c9a08a7eb2272e2 100644 --- a/src/vs/base/browser/ui/actionbar/actionbar.ts +++ b/src/vs/base/browser/ui/actionbar/actionbar.ts @@ -18,7 +18,7 @@ import { IContextViewProvider } from 'vs/base/browser/ui/contextview/contextview import { Event, Emitter } from 'vs/base/common/event'; export interface IActionItem { - actionRunner: IActionRunner; + actionRunner?: IActionRunner; setActionContext(context: any): void; render(element: HTMLElement): void; isEnabled(): boolean; @@ -34,7 +34,7 @@ export interface IBaseActionItemOptions { export class BaseActionItem extends Disposable implements IActionItem { - element: HTMLElement; + element?: HTMLElement; _context: any; _action: IAction; @@ -118,7 +118,7 @@ export class BaseActionItem extends Disposable implements IActionItem { DOM.EventHelper.stop(e, true); // do not run when dragging is on because that would disable it } - if (this._action.enabled && e.button === 0) { + if (this._action.enabled && e.button === 0 && this.element) { DOM.addClass(this.element, 'active'); } })); @@ -145,9 +145,9 @@ export class BaseActionItem extends Disposable implements IActionItem { })); [DOM.EventType.MOUSE_UP, DOM.EventType.MOUSE_OUT].forEach(event => { - this._register(DOM.addDisposableListener(this.element, event, e => { + this._register(DOM.addDisposableListener(this.element!, event, e => { DOM.EventHelper.stop(e); - DOM.removeClass(this.element, 'active'); + DOM.removeClass(this.element!, 'active'); })); }); } @@ -206,7 +206,7 @@ export class BaseActionItem extends Disposable implements IActionItem { dispose(): void { if (this.element) { DOM.removeNode(this.element); - this.element = null; + this.element = undefined; } super.dispose(); @@ -236,7 +236,7 @@ export class ActionItem extends BaseActionItem { protected label: HTMLElement; protected options: IActionItemOptions; - private cssClass: string; + private cssClass?: string; constructor(context: any, action: IAction, options: IActionItemOptions = {}) { super(context, action, options); @@ -250,7 +250,9 @@ export class ActionItem extends BaseActionItem { render(container: HTMLElement): void { super.render(container); - this.label = DOM.append(this.element, DOM.$('a.action-label')); + if (this.element) { + this.label = DOM.append(this.element, DOM.$('a.action-label')); + } if (this._action.id === Separator.ID) { this.label.setAttribute('role', 'presentation'); // A separator is a presentation item } else { @@ -261,7 +263,7 @@ export class ActionItem extends BaseActionItem { } } - if (this.options.label && this.options.keybinding) { + if (this.options.label && this.options.keybinding && this.element) { DOM.append(this.element, DOM.$('span.keybinding')).textContent = this.options.keybinding; } @@ -324,12 +326,16 @@ export class ActionItem extends BaseActionItem { updateEnabled(): void { if (this.getAction().enabled) { this.label.removeAttribute('aria-disabled'); - DOM.removeClass(this.element, 'disabled'); + if (this.element) { + DOM.removeClass(this.element, 'disabled'); + } DOM.removeClass(this.label, 'disabled'); this.label.tabIndex = 0; } else { this.label.setAttribute('aria-disabled', 'true'); - DOM.addClass(this.element, 'disabled'); + if (this.element) { + DOM.addClass(this.element, 'disabled'); + } DOM.addClass(this.label, 'disabled'); DOM.removeTabIndexAndUpdateFocus(this.label); } @@ -387,12 +393,12 @@ export class ActionBar extends Disposable implements IActionRunner { options: IActionBarOptions; - private _actionRunner: IActionRunner; + private _actionRunner?: IActionRunner; private _context: any; // Items items: IActionItem[]; - protected focusedItem: number; + protected focusedItem?: number; private focusTracker: DOM.IFocusTracker; // Elements @@ -495,7 +501,7 @@ export class ActionBar extends Disposable implements IActionRunner { // Run action on Enter/Space if (this.isTriggerKeyEvent(event)) { - if (!this.options.triggerKeys.keyDown) { + if (this.options.triggerKeys && !this.options.triggerKeys.keyDown) { this.doTrigger(event); } @@ -570,11 +576,11 @@ export class ActionBar extends Disposable implements IActionRunner { this.items.forEach(i => i.setActionContext(context)); } - get actionRunner(): IActionRunner { + get actionRunner(): IActionRunner | undefined { return this._actionRunner; } - set actionRunner(actionRunner: IActionRunner) { + set actionRunner(actionRunner: IActionRunner | undefined) { if (actionRunner) { this._actionRunner = actionRunner; this.items.forEach(item => item.actionRunner = actionRunner); @@ -628,7 +634,10 @@ export class ActionBar extends Disposable implements IActionRunner { getWidth(index: number): number { if (index >= 0 && index < this.actionsList.children.length) { - return this.actionsList.children.item(index).clientWidth; + const item = this.actionsList.children.item(index); + if (item) { + return item.clientWidth; + } } return 0; @@ -636,7 +645,10 @@ export class ActionBar extends Disposable implements IActionRunner { getHeight(index: number): number { if (index >= 0 && index < this.actionsList.children.length) { - return this.actionsList.children.item(index).clientHeight; + const item = this.actionsList.children.item(index); + if (item) { + return item.clientHeight; + } } return 0; @@ -765,14 +777,15 @@ export class ActionBar extends Disposable implements IActionRunner { } run(action: IAction, context?: any): Thenable { - return this._actionRunner.run(action, context); + if (this._actionRunner) { + return this._actionRunner.run(action, context); + } + return Promise.resolve(void 0); } dispose(): void { - if (this.items !== null) { - dispose(this.items); - } - this.items = null; + dispose(this.items); + this.items = []; DOM.removeNode(this.getContainer()); @@ -786,7 +799,7 @@ export class SelectActionItem extends BaseActionItem { constructor(ctx: any, action: IAction, options: string[], selected: number, contextViewProvider: IContextViewProvider, selectBoxOptions?: ISelectBoxOptions) { super(ctx, action); - this.selectBox = new SelectBox(options, selected, contextViewProvider, null, selectBoxOptions); + this.selectBox = new SelectBox(options, selected, contextViewProvider, undefined, selectBoxOptions); this._register(this.selectBox); this.registerListeners();