提交 b7932c78 编写于 作者: M Matt Bierner

Strict null work on panels

上级 72dbd895
......@@ -71,7 +71,7 @@ export const DataTransfers = {
TEXT: 'text/plain'
};
export function applyDragImage(event: DragEvent, label: string, clazz: string): void {
export function applyDragImage(event: DragEvent, label: string | null, clazz: string): void {
const dragImage = document.createElement('div');
dragImage.className = clazz;
dragImage.textContent = label;
......
......@@ -386,10 +386,10 @@ class ResourceLabelWidget extends IconLabel {
}
if (this.label) {
const configuredLangId = getConfiguredLangId(this.modelService, this.label.resource);
const configuredLangId = this.label.resource ? getConfiguredLangId(this.modelService, this.label.resource) : null;
if (this.lastKnownConfiguredLangId !== configuredLangId) {
clearIconCache = true;
this.lastKnownConfiguredLangId = configuredLangId;
this.lastKnownConfiguredLangId = configuredLangId || undefined;
}
}
......
......@@ -112,7 +112,7 @@ export class CompositeBar extends Widget implements ICompositeBar {
if (this.compositeTransfer.hasData(DraggedCompositeIdentifier.prototype)) {
EventHelper.stop(e, true);
const draggedCompositeId = this.compositeTransfer.getData(DraggedCompositeIdentifier.prototype)[0].id;
const draggedCompositeId = this.compositeTransfer.getData(DraggedCompositeIdentifier.prototype)![0].id;
this.compositeTransfer.clearData(DraggedCompositeIdentifier.prototype);
const targetItem = this.model.visibleItems[this.model.visibleItems.length - 1];
......@@ -507,7 +507,7 @@ class CompositeBarModel {
return this.items.filter(item => item.visible && item.pinned);
}
private createCompositeBarItem(id: string, name: string, order: number, pinned: boolean, visible: boolean): ICompositeBarModelItem {
private createCompositeBarItem(id: string, name: string, order: number | undefined, pinned: boolean, visible: boolean): ICompositeBarModelItem {
const options = this.options;
return {
id, name, pinned, order, visible,
......@@ -521,7 +521,7 @@ class CompositeBarModel {
};
}
add(id: string, name: string, order: number): boolean {
add(id: string, name: string, order: number | undefined): boolean {
const item = this.findItem(id);
if (item) {
let changed = false;
......
......@@ -57,13 +57,11 @@ export class ActivityAction extends Action {
private _onDidChangeBadge = new Emitter<this>();
get onDidChangeBadge(): Event<this> { return this._onDidChangeBadge.event; }
private badge: IBadge;
private badge?: IBadge;
private clazz: string | undefined;
constructor(private _activity: IActivity) {
super(_activity.id, _activity.name, _activity.cssClass);
this.badge = null;
}
get activity(): IActivity {
......@@ -87,7 +85,7 @@ export class ActivityAction extends Action {
}
}
getBadge(): IBadge {
getBadge(): IBadge | undefined {
return this.badge;
}
......@@ -95,7 +93,7 @@ export class ActivityAction extends Action {
return this.clazz;
}
setBadge(badge: IBadge, clazz?: string): void {
setBadge(badge: IBadge | undefined, clazz?: string): void {
this.badge = badge;
this.clazz = clazz;
this._onDidChangeBadge.fire(this);
......@@ -207,10 +205,10 @@ export class ActivityActionItem extends BaseActionItem {
}));
// Label
this.label = dom.append(this.element, dom.$('a'));
this.label = dom.append(this.element!, dom.$('a'));
// Badge
this.badge = dom.append(this.element, dom.$('.badge'));
this.badge = dom.append(this.element!, dom.$('.badge'));
this.badgeContent = dom.append(this.badge, dom.$('.badge-content'));
dom.hide(this.badge);
......@@ -373,7 +371,7 @@ export class CompositeOverflowActivityActionItem extends ActivityActionItem {
this.actions = this.getActions();
this.contextMenuService.showContextMenu({
getAnchor: () => this.element,
getAnchor: () => this.element!,
getActions: () => this.actions,
onHide: () => dispose(this.actions)
});
......@@ -385,7 +383,7 @@ export class CompositeOverflowActivityActionItem extends ActivityActionItem {
action.radio = this.getActiveCompositeId() === action.id;
const badge = this.getBadge(composite.id);
let suffix: string | number;
let suffix: string | number | undefined;
if (badge instanceof NumberBadge) {
suffix = badge.number;
} else if (badge instanceof TextBadge) {
......@@ -434,7 +432,7 @@ export class CompositeActionItem extends ActivityActionItem {
private static manageExtensionAction: ManageExtensionAction;
private compositeActivity: IActivity;
private compositeActivity: IActivity | null;
private compositeTransfer: LocalSelectionTransfer<DraggedCompositeIdentifier>;
constructor(
......@@ -463,7 +461,7 @@ export class CompositeActionItem extends ActivityActionItem {
protected get activity(): IActivity {
if (!this.compositeActivity) {
let activityName: string;
const keybinding = this.getKeybindingLabel(this.compositeActivityAction.activity.keybindingId);
const keybinding = typeof this.compositeActivityAction.activity.keybindingId === 'string' ? this.getKeybindingLabel(this.compositeActivityAction.activity.keybindingId) : null;
if (keybinding) {
activityName = nls.localize('titleKeybinding', "{0} ({1})", this.compositeActivityAction.activity.name, keybinding);
} else {
......@@ -480,7 +478,7 @@ export class CompositeActionItem extends ActivityActionItem {
return this.compositeActivity;
}
private getKeybindingLabel(id: string): string {
private getKeybindingLabel(id: string): string | null {
const kb = this.keybindingService.lookupKeybinding(id);
if (kb) {
return kb.getLabel();
......@@ -503,7 +501,7 @@ export class CompositeActionItem extends ActivityActionItem {
// Allow to drag
this._register(dom.addDisposableListener(this.container, dom.EventType.DRAG_START, (e: DragEvent) => {
e.dataTransfer.effectAllowed = 'move';
e.dataTransfer!.effectAllowed = 'move';
// Registe as dragged to local transfer
this.compositeTransfer.setData([new DraggedCompositeIdentifier(this.activity.id)], DraggedCompositeIdentifier.prototype);
......@@ -516,7 +514,7 @@ export class CompositeActionItem extends ActivityActionItem {
this._register(new DragAndDropObserver(this.container, {
onDragEnter: e => {
if (this.compositeTransfer.hasData(DraggedCompositeIdentifier.prototype) && this.compositeTransfer.getData(DraggedCompositeIdentifier.prototype)[0].id !== this.activity.id) {
if (this.compositeTransfer.hasData(DraggedCompositeIdentifier.prototype) && this.compositeTransfer.getData(DraggedCompositeIdentifier.prototype)![0].id !== this.activity.id) {
this.updateFromDragging(container, true);
}
},
......@@ -539,7 +537,7 @@ export class CompositeActionItem extends ActivityActionItem {
dom.EventHelper.stop(e, true);
if (this.compositeTransfer.hasData(DraggedCompositeIdentifier.prototype)) {
const draggedCompositeId = this.compositeTransfer.getData(DraggedCompositeIdentifier.prototype)[0].id;
const draggedCompositeId = this.compositeTransfer.getData(DraggedCompositeIdentifier.prototype)![0].id;
if (draggedCompositeId !== this.activity.id) {
this.updateFromDragging(container, false);
this.compositeTransfer.clearData(DraggedCompositeIdentifier.prototype);
......@@ -617,6 +615,10 @@ export class CompositeActionItem extends ActivityActionItem {
}
protected updateEnabled(): void {
if (!this.element) {
return;
}
if (this.getAction().enabled) {
dom.removeClass(this.element, 'disabled');
} else {
......@@ -636,12 +638,12 @@ export class CompositeActionItem extends ActivityActionItem {
export class ToggleCompositePinnedAction extends Action {
constructor(
private activity: IActivity,
private activity: IActivity | undefined,
private compositeBar: ICompositeBar
) {
super('show.toggleCompositePinned', activity ? activity.name : nls.localize('toggle', "Toggle View Pinned"));
this.checked = this.activity && this.compositeBar.isPinned(this.activity.id);
this.checked = !!this.activity && this.compositeBar.isPinned(this.activity.id);
}
run(context: string): Promise<any> {
......
......@@ -50,7 +50,7 @@ export abstract class TitleControl extends Themable {
protected readonly groupTransfer = LocalSelectionTransfer.getInstance<DraggedEditorGroupIdentifier>();
protected readonly editorTransfer = LocalSelectionTransfer.getInstance<DraggedEditorIdentifier>();
protected breadcrumbsControl: BreadcrumbsControl;
protected breadcrumbsControl?: BreadcrumbsControl;
private currentPrimaryEditorActionIds: string[] = [];
private currentSecondaryEditorActionIds: string[] = [];
......@@ -154,18 +154,18 @@ export abstract class TitleControl extends Themable {
}));
}
private actionItemProvider(action: Action): IActionItem {
private actionItemProvider(action: Action): IActionItem | null {
const activeControl = this.group.activeControl;
// Check Active Editor
let actionItem: IActionItem;
let actionItem: IActionItem | null = null;
if (activeControl instanceof BaseEditor) {
actionItem = activeControl.getActionItem(action);
}
// Check extensions
if (!actionItem) {
actionItem = createActionItem(action, this.keybindingService, this.notificationService, this.contextMenuService);
actionItem = createActionItem(action, this.keybindingService, this.notificationService, this.contextMenuService) || null;
}
return actionItem;
......@@ -253,11 +253,11 @@ export abstract class TitleControl extends Themable {
// Set editor group as transfer
this.groupTransfer.setData([new DraggedEditorGroupIdentifier(this.group.id)], DraggedEditorGroupIdentifier.prototype);
e.dataTransfer.effectAllowed = 'copyMove';
e.dataTransfer!.effectAllowed = 'copyMove';
// If tabs are disabled, treat dragging as if an editor tab was dragged
if (!this.accessor.partOptions.showTabs) {
const resource = toResource(this.group.activeEditor, { supportSideBySide: true });
const resource = this.group.activeEditor ? toResource(this.group.activeEditor, { supportSideBySide: true }) : null;
if (resource) {
this.instantiationService.invokeFunction(fillResourceDataTransfers, [resource], e);
}
......@@ -316,10 +316,10 @@ export abstract class TitleControl extends Themable {
return this.keybindingService.lookupKeybinding(action.id);
}
protected getKeybindingLabel(action: IAction): string {
protected getKeybindingLabel(action: IAction): string | undefined {
const keybinding = this.getKeybinding(action);
return keybinding ? keybinding.getLabel() : undefined;
return keybinding ? keybinding.getLabel() || undefined : undefined;
}
abstract openEditor(editor: IEditorInput): void;
......
......@@ -41,7 +41,7 @@ export const PanelFocusContext = new RawContextKey<boolean>('panelFocus', false)
interface ICachedPanel {
id: string;
pinned: boolean;
order: number;
order?: number;
visible: boolean;
}
......@@ -243,7 +243,7 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService, IS
getPanels(): PanelDescriptor[] {
return Registry.as<PanelRegistry>(PanelExtensions.Panels).getPanels()
.sort((v1, v2) => v1.order - v2.order);
.sort((v1, v2) => typeof v1.order === 'number' && typeof v2.order === 'number' ? v1.order - v2.order : NaN);
}
getPinnedPanels(): PanelDescriptor[] {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册