提交 163a59ed 编写于 作者: M Matt Bierner

Strict null check toolbar

上级 dec6a8ba
......@@ -67,6 +67,7 @@
"./vs/base/browser/ui/selectBox/selectBoxNative.ts",
"./vs/base/browser/ui/splitview/panelview.ts",
"./vs/base/browser/ui/splitview/splitview.ts",
"./vs/base/browser/ui/toolbar/toolbar.ts",
"./vs/base/browser/ui/tree/abstractTree.ts",
"./vs/base/browser/ui/tree/asyncDataTree.ts",
"./vs/base/browser/ui/tree/indexTree.ts",
......
......@@ -363,7 +363,7 @@ export interface ActionTrigger {
}
export interface IActionItemProvider {
(action: IAction): IActionItem;
(action: IAction): IActionItem | null;
}
export interface IActionBarOptions {
......@@ -577,11 +577,11 @@ export class ActionBar extends Disposable implements IActionRunner {
this.items.forEach(i => i.setActionContext(context));
}
get actionRunner(): IActionRunner | undefined {
get actionRunner(): IActionRunner {
return this._actionRunner;
}
set actionRunner(actionRunner: IActionRunner | undefined) {
set actionRunner(actionRunner: IActionRunner) {
if (actionRunner) {
this._actionRunner = actionRunner;
this.items.forEach(item => item.actionRunner = actionRunner);
......
......@@ -270,14 +270,14 @@ export class DropdownMenuActionItem extends BaseActionItem {
private menuActionsOrProvider: any;
private dropdownMenu: DropdownMenu;
private contextMenuProvider: IContextMenuProvider;
private actionItemProvider: IActionItemProvider;
private keybindings: (action: IAction) => ResolvedKeybinding;
private actionItemProvider?: IActionItemProvider;
private keybindings?: (action: IAction) => ResolvedKeybinding;
private clazz: string;
private anchorAlignmentProvider: (() => AnchorAlignment) | undefined;
constructor(action: IAction, menuActions: IAction[], contextMenuProvider: IContextMenuProvider, actionItemProvider: IActionItemProvider, actionRunner: IActionRunner, keybindings: (action: IAction) => ResolvedKeybinding, clazz: string, anchorAlignmentProvider?: () => AnchorAlignment);
constructor(action: IAction, actionProvider: IActionProvider, contextMenuProvider: IContextMenuProvider, actionItemProvider: IActionItemProvider, actionRunner: IActionRunner, keybindings: (action: IAction) => ResolvedKeybinding, clazz: string, anchorAlignmentProvider?: () => AnchorAlignment);
constructor(action: IAction, menuActionsOrProvider: any, contextMenuProvider: IContextMenuProvider, actionItemProvider: IActionItemProvider, actionRunner: IActionRunner, keybindings: (action: IAction) => ResolvedKeybinding, clazz: string, anchorAlignmentProvider?: () => AnchorAlignment) {
constructor(action: IAction, menuActions: IAction[], contextMenuProvider: IContextMenuProvider, actionItemProvider: IActionItemProvider | undefined, actionRunner: IActionRunner, keybindings: ((action: IAction) => ResolvedKeybinding) | undefined, clazz: string, anchorAlignmentProvider?: () => AnchorAlignment);
constructor(action: IAction, actionProvider: IActionProvider, contextMenuProvider: IContextMenuProvider, actionItemProvider: IActionItemProvider | undefined, actionRunner: IActionRunner, keybindings: (action: IAction) => ResolvedKeybinding, clazz: string, anchorAlignmentProvider?: () => AnchorAlignment);
constructor(action: IAction, menuActionsOrProvider: any, contextMenuProvider: IContextMenuProvider, actionItemProvider: IActionItemProvider | undefined, actionRunner: IActionRunner, keybindings: (action: IAction) => ResolvedKeybinding, clazz: string, anchorAlignmentProvider?: () => AnchorAlignment) {
super(null, action);
this.menuActionsOrProvider = menuActionsOrProvider;
......
......@@ -31,7 +31,7 @@ export class ToolBar extends Disposable {
private options: IToolBarOptions;
private actionBar: ActionBar;
private toggleMenuAction: ToggleMenuAction;
private toggleMenuActionItem: DropdownMenuActionItem;
private toggleMenuActionItem?: DropdownMenuActionItem;
private hasSecondaryActions: boolean;
private lookupKeybindings: boolean;
......@@ -72,9 +72,9 @@ export class ToolBar extends Disposable {
'toolbar-toggle-more',
this.options.anchorAlignmentProvider
);
this.toggleMenuActionItem.setActionContext(this.actionBar.context);
this.toggleMenuActionItem!.setActionContext(this.actionBar.context);
return this.toggleMenuActionItem;
return this.toggleMenuActionItem || null;
}
return options.actionItemProvider ? options.actionItemProvider(action) : null;
......@@ -118,8 +118,8 @@ export class ToolBar extends Disposable {
let primaryActionsToSet = primaryActions ? primaryActions.slice(0) : [];
// Inject additional action to open secondary actions if present
this.hasSecondaryActions = secondaryActions && secondaryActions.length > 0;
if (this.hasSecondaryActions) {
this.hasSecondaryActions = !!(secondaryActions && secondaryActions.length > 0);
if (this.hasSecondaryActions && secondaryActions) {
this.toggleMenuAction.menuActions = secondaryActions.slice(0);
primaryActionsToSet.push(this.toggleMenuAction);
}
......@@ -132,10 +132,10 @@ export class ToolBar extends Disposable {
};
}
private getKeybindingLabel(action: IAction): string {
const key = this.lookupKeybindings ? this.options.getKeyBinding(action) : void 0;
private getKeybindingLabel(action: IAction): string | undefined {
const key = this.lookupKeybindings && this.options.getKeyBinding ? this.options.getKeyBinding(action) : void 0;
return key ? key.getLabel() : void 0;
return (key && key.getLabel()) || void 0;
}
addPrimaryAction(primaryAction: IAction): () => void {
......@@ -173,7 +173,7 @@ class ToggleMenuAction extends Action {
constructor(toggleDropdownMenu: () => void, title?: string) {
title = title || nls.localize('moreActions', "More Actions...");
super(ToggleMenuAction.ID, title, null, true);
super(ToggleMenuAction.ID, title, void 0, true);
this.toggleDropdownMenu = toggleDropdownMenu;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册