Strict Null Checks, Builder Removal, Formatting (#4849)

* remove builder; more null checks

* null checks

* formatting

* wip

* fix dropdown themeing

* formatting

* formatting

* fix tests

* update what files are checked

* add code to help refresh bad nodes
This commit is contained in:
Anthony Dresser
2019-04-08 13:27:41 -07:00
committed by GitHub
parent 01784dd186
commit 22ec1d5f0a
57 changed files with 177 additions and 206 deletions

View File

@@ -5,7 +5,6 @@
import 'vs/css!vs/base/browser/ui/actionbar/actionbar';
import { Builder, $ } from 'sql/base/browser/builder';
import { IAction, IActionRunner, ActionRunner } from 'vs/base/common/actions';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
@@ -35,21 +34,22 @@ export class ActionBar extends ActionRunner implements IActionRunner {
// Items
private _items: IActionItem[];
private _focusedItem: number;
private _focusedItem?: number;
private _focusTracker: DOM.IFocusTracker;
// Elements
private _domNode: HTMLElement;
private _actionsList: HTMLElement;
constructor(container: HTMLElement | Builder, options: IActionBarOptions = defaultOptions) {
constructor(container: HTMLElement, options: IActionBarOptions = defaultOptions) {
super();
this._options = options;
this._context = options.context;
this._toDispose = [];
this._actionRunner = this._options.actionRunner;
if (!this._actionRunner) {
if (this._options.actionRunner) {
this._actionRunner = this._options.actionRunner;
} else {
this._actionRunner = new ActionRunner();
this._toDispose.push(this._actionRunner);
}
@@ -71,7 +71,7 @@ export class ActionBar extends ActionRunner implements IActionRunner {
this._domNode.className += ' vertical';
}
$(this._domNode).on(DOM.EventType.KEY_DOWN, (e: KeyboardEvent) => {
this._register(DOM.addDisposableListener(this._domNode, DOM.EventType.KEY_DOWN, (e: KeyboardEvent) => {
let event = new StandardKeyboardEvent(e);
let eventHandled = true;
@@ -91,15 +91,15 @@ export class ActionBar extends ActionRunner implements IActionRunner {
event.preventDefault();
event.stopPropagation();
}
});
}));
// Prevent native context menu on actions
$(this._domNode).on(DOM.EventType.CONTEXT_MENU, (e: Event) => {
this._register(DOM.addDisposableListener(this._domNode, DOM.EventType.CONTEXT_MENU, (e: Event) => {
e.preventDefault();
e.stopPropagation();
});
}));
$(this._domNode).on(DOM.EventType.KEY_UP, (e: KeyboardEvent) => {
this._register(DOM.addDisposableListener(this._domNode, DOM.EventType.KEY_UP, (e: KeyboardEvent) => {
let event = new StandardKeyboardEvent(e);
// Run action on Enter/Space
@@ -113,9 +113,9 @@ export class ActionBar extends ActionRunner implements IActionRunner {
else if (event.equals(KeyCode.Tab) || event.equals(KeyMod.Shift | KeyCode.Tab)) {
this.updateFocusedItem();
}
});
}));
this._focusTracker = DOM.trackFocus(this._domNode);
this._focusTracker = this._register(DOM.trackFocus(this._domNode));
this._focusTracker.onDidBlur(() => {
if (document.activeElement === this._domNode || !DOM.isAncestor(document.activeElement, this._domNode)) {
@@ -136,7 +136,7 @@ export class ActionBar extends ActionRunner implements IActionRunner {
this._domNode.appendChild(this._actionsList);
((container instanceof Builder) ? container.getHTMLElement() : container).appendChild(this._domNode);
container.appendChild(this._domNode);
}
public setAriaLabel(label: string): void {
@@ -183,8 +183,8 @@ export class ActionBar extends ActionRunner implements IActionRunner {
}
}
public getContainer(): Builder {
return $(this._domNode);
public getContainer(): HTMLElement {
return this._domNode;
}
/**
@@ -216,7 +216,7 @@ export class ActionBar extends ActionRunner implements IActionRunner {
actionItemElement.className = 'action-item';
actionItemElement.setAttribute('role', 'presentation');
let item: IActionItem = null;
let item: IActionItem | undefined = undefined;
if (this._options.actionItemProvider) {
item = this._options.actionItemProvider(action);
@@ -251,7 +251,7 @@ export class ActionBar extends ActionRunner implements IActionRunner {
public clear(): void {
// Do not dispose action items if they were provided from outside
this._items = this._options.actionItemProvider ? [] : lifecycle.dispose(this._items);
$(this._actionsList).empty();
DOM.clearNode(this._actionsList);
}
public length(): number {
@@ -364,19 +364,12 @@ export class ActionBar extends ActionRunner implements IActionRunner {
}
public dispose(): void {
if (this._items !== null) {
lifecycle.dispose(this._items);
}
this._items = null;
if (this._focusTracker) {
this._focusTracker.dispose();
this._focusTracker = null;
}
lifecycle.dispose(this._items);
this._items = [];
this._toDispose = lifecycle.dispose(this._toDispose);
this.getContainer().destroy();
this._domNode.remove();
super.dispose();
}

View File

@@ -3,18 +3,14 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import 'vs/css!./media/taskbar';
import 'vs/css!./media/icons';
import 'vs/css!sql/media/icons/common-icons';
import { ActionBar } from './actionbar';
import { Builder, $ } from 'sql/base/browser/builder';
import { Action, IActionRunner, IAction } from 'vs/base/common/actions';
import { ActionsOrientation } from 'vs/base/browser/ui/actionbar/actionbar';
import { IContextMenuProvider } from 'vs/base/browser/ui/dropdown/dropdown';
import { IToolBarOptions } from 'vs/base/browser/ui/toolbar/toolbar';
/**
@@ -37,21 +33,19 @@ export interface ITaskbarContent {
export class Taskbar {
private options: IToolBarOptions;
private actionBar: ActionBar;
private lookupKeybindings: boolean;
constructor(container: HTMLElement, contextMenuProvider: IContextMenuProvider, options: IToolBarOptions = { orientation: ActionsOrientation.HORIZONTAL }) {
constructor(container: HTMLElement, options: IToolBarOptions = { orientation: ActionsOrientation.HORIZONTAL }) {
this.options = options;
this.lookupKeybindings = typeof this.options.getKeyBinding === 'function' && typeof this.options.getKeyBinding === 'function';
let element = document.createElement('div');
element.className = 'monaco-toolbar carbon-taskbar';
container.appendChild(element);
this.actionBar = new ActionBar($(element), {
this.actionBar = new ActionBar(element, {
orientation: options.orientation,
ariaLabel: options.ariaLabel,
actionItemProvider: (action: Action) => {
return options.actionItemProvider ? options.actionItemProvider(action) : null;
return options.actionItemProvider ? options.actionItemProvider(action) : undefined;
}
});
}
@@ -98,7 +92,7 @@ export class Taskbar {
this.actionBar.context = context;
}
public getContainer(): Builder {
public getContainer(): HTMLElement {
return this.actionBar.getContainer();
}
@@ -131,8 +125,9 @@ export class Taskbar {
}
private getKeybindingLabel(action: IAction): string {
const key = this.lookupKeybindings ? this.options.getKeyBinding(action) : void 0;
return key ? key.getLabel() : '';
const key = this.options.getKeyBinding ? this.options.getKeyBinding(action) : undefined;
const label = key ? key.getLabel() : undefined;
return label || '';
}
public addAction(primaryAction: IAction): void {