提交 6685f2d2 编写于 作者: M Matt Bierner

Convert `toResource` to return undefined instead of null

上级 a65adc6f
......@@ -350,7 +350,7 @@ class ResourceLabelWidget extends IconLabel {
setEditor(editor: IEditorInput, options?: IResourceLabelOptions): void {
this.setResource({
resource: withNullAsUndefined(toResource(editor, { supportSideBySide: SideBySideEditor.MASTER })),
resource: toResource(editor, { supportSideBySide: SideBySideEditor.MASTER }),
name: withNullAsUndefined(editor.getName()),
description: withNullAsUndefined(editor.getDescription())
}, options);
......
......@@ -51,7 +51,7 @@ export class EditorPickerEntry extends QuickOpenEntryGroup {
}
getResource() {
return withNullAsUndefined(toResource(this.editor, { supportSideBySide: SideBySideEditor.MASTER }));
return toResource(this.editor, { supportSideBySide: SideBySideEditor.MASTER });
}
getAriaLabel(): string {
......
......@@ -39,7 +39,7 @@ import { Themable } from 'vs/workbench/common/theme';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { AnchorAlignment } from 'vs/base/browser/ui/contextview/contextview';
import { IFileService } from 'vs/platform/files/common/files';
import { withNullAsUndefined } from 'vs/base/common/types';
import { withNullAsUndefined, withUndefinedAsNull } from 'vs/base/common/types';
import { ILabelService } from 'vs/platform/label/common/label';
export interface IToolbarActions {
......@@ -221,7 +221,7 @@ export abstract class TitleControl extends Themable {
this.editorToolBarMenuDisposables = dispose(this.editorToolBarMenuDisposables);
// Update the resource context
this.resourceContext.set(this.group.activeEditor ? toResource(this.group.activeEditor, { supportSideBySide: SideBySideEditor.MASTER }) : null);
this.resourceContext.set(this.group.activeEditor ? withUndefinedAsNull(toResource(this.group.activeEditor, { supportSideBySide: SideBySideEditor.MASTER })) : null);
// Editor actions require the editor control to be there, so we retrieve it via service
const activeControl = this.group.activeControl;
......@@ -288,7 +288,7 @@ export abstract class TitleControl extends Themable {
// Update the resource context
const currentContext = this.resourceContext.get();
this.resourceContext.set(toResource(editor, { supportSideBySide: SideBySideEditor.MASTER }));
this.resourceContext.set(withUndefinedAsNull(toResource(editor, { supportSideBySide: SideBySideEditor.MASTER })));
// Find target anchor
let anchor: HTMLElement | { x: number, y: number } = node;
......
......@@ -5,7 +5,7 @@
import { Event, Emitter } from 'vs/base/common/event';
import { assign } from 'vs/base/common/objects';
import { isUndefinedOrNull, withUndefinedAsNull } from 'vs/base/common/types';
import { isUndefinedOrNull } from 'vs/base/common/types';
import { URI } from 'vs/base/common/uri';
import { IDisposable, Disposable } from 'vs/base/common/lifecycle';
import { IEditor as ICodeEditor, IEditorViewState, ScrollType, IDiffEditor } from 'vs/editor/common/editorCommon';
......@@ -1002,9 +1002,9 @@ export interface IResourceOptions {
filterByScheme?: string | string[];
}
export function toResource(editor: IEditorInput | null | undefined, options?: IResourceOptions): URI | null {
export function toResource(editor: IEditorInput | undefined, options?: IResourceOptions): URI | undefined {
if (!editor) {
return null;
return undefined;
}
if (options && options.supportSideBySide && editor instanceof SideBySideEditorInput) {
......@@ -1013,7 +1013,7 @@ export function toResource(editor: IEditorInput | null | undefined, options?: IR
const resource = editor.getResource();
if (!resource || !options || !options.filterByScheme) {
return withUndefinedAsNull(resource);
return resource;
}
if (Array.isArray(options.filterByScheme) && options.filterByScheme.some(scheme => resource.scheme === scheme)) {
......@@ -1024,7 +1024,7 @@ export function toResource(editor: IEditorInput | null | undefined, options?: IR
return resource;
}
return null;
return undefined;
}
export const enum CloseDirection {
......
......@@ -43,6 +43,7 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { UNTITLED_WORKSPACE_NAME } from 'vs/platform/workspaces/common/workspaces';
import { withUndefinedAsNull } from 'vs/base/common/types';
// Commands
......@@ -349,7 +350,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
}
});
let globalResourceToCompare: URI | null;
let globalResourceToCompare: URI | undefined;
let resourceSelectedForCompareContext: IContextKey<boolean>;
CommandsRegistry.registerCommand({
id: SELECT_FOR_COMPARE_COMMAND_ID,
......@@ -524,9 +525,9 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
const editorService = accessor.get(IEditorService);
let resource: URI | null = null;
if (resourceOrObject && 'from' in resourceOrObject && resourceOrObject.from === 'menu') {
resource = toResource(editorService.activeEditor);
resource = withUndefinedAsNull(toResource(editorService.activeEditor));
} else {
resource = getResourceForCommand(resourceOrObject, accessor.get(IListService), editorService);
resource = withUndefinedAsNull(getResourceForCommand(resourceOrObject, accessor.get(IListService), editorService));
}
return save(resource, true, undefined, editorService, accessor.get(IFileService), accessor.get(IUntitledEditorService), accessor.get(ITextFileService), accessor.get(IEditorGroupsService), accessor.get(IWorkbenchEnvironmentService));
......
......@@ -14,7 +14,7 @@ import { coalesce } from 'vs/base/common/arrays';
// Commands can get exeucted from a command pallete, from a context menu or from some list using a keybinding
// To cover all these cases we need to properly compute the resource on which the command is being executed
export function getResourceForCommand(resource: URI | object | undefined, listService: IListService, editorService: IEditorService): URI | null {
export function getResourceForCommand(resource: URI | object | undefined, listService: IListService, editorService: IEditorService): URI | undefined {
if (URI.isUri(resource)) {
return resource;
}
......@@ -41,7 +41,7 @@ export function getResourceForCommand(resource: URI | object | undefined, listSe
}
}
return editorService.activeEditor ? toResource(editorService.activeEditor, { supportSideBySide: SideBySideEditor.MASTER }) : null;
return editorService.activeEditor ? toResource(editorService.activeEditor, { supportSideBySide: SideBySideEditor.MASTER }) : undefined;
}
export function getMultiSelectedResources(resource: URI | object | undefined, listService: IListService, editorService: IEditorService): Array<URI> {
......
......@@ -41,7 +41,7 @@ import { IDragAndDropData, DataTransfers } from 'vs/base/browser/dnd';
import { memoize } from 'vs/base/common/decorators';
import { ElementsDragAndDropData, DesktopDragAndDropData } from 'vs/base/browser/ui/list/listView';
import { URI } from 'vs/base/common/uri';
import { withNullAsUndefined } from 'vs/base/common/types';
import { withNullAsUndefined, withUndefinedAsNull } from 'vs/base/common/types';
const $ = dom.$;
......@@ -245,7 +245,7 @@ export class OpenEditorsView extends ViewletPanel {
const element = e.elements.length ? e.elements[0] : undefined;
if (element instanceof OpenEditor) {
this.dirtyEditorFocusedContext.set(this.textFileService.isDirty(withNullAsUndefined(element.getResource())));
this.resourceContext.set(element.getResource());
this.resourceContext.set(withUndefinedAsNull(element.getResource()));
} else if (!!element) {
this.groupFocusedContext.set(true);
}
......
......@@ -258,7 +258,7 @@ export class OpenEditor implements IEditorIdentifier {
return this.editor.isDirty();
}
public getResource(): URI | null {
public getResource(): URI | undefined {
return toResource(this.editor, { supportSideBySide: SideBySideEditor.MASTER });
}
}
......@@ -958,7 +958,7 @@ export class HistoryService extends Disposable implements IHistoryService {
getLastActiveFile(filterByScheme: string): URI | undefined {
const history = this.getHistory();
for (const input of history) {
let resource: URI | null;
let resource: URI | undefined;
if (input instanceof EditorInput) {
resource = toResource(input, { filterByScheme });
} else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册