提交 a73d87ac 编写于 作者: B Benjamin Pasero

editor - getName() is required

上级 929fab18
......@@ -367,7 +367,7 @@ class ResourceLabelWidget extends IconLabel {
setEditor(editor: IEditorInput, options?: IResourceLabelOptions): void {
this.setResource({
resource: toResource(editor, { supportSideBySide: SideBySideEditor.MASTER }),
name: withNullAsUndefined(editor.getName()),
name: editor.getName(),
description: editor.getDescription(options ? options.descriptionVerbosity : undefined)
}, options);
}
......
......@@ -56,7 +56,7 @@ export abstract class BaseBinaryResourceEditor extends BaseEditor {
this.callbacks = callbacks;
}
getTitle() {
getTitle(): string {
return this.input ? this.input.getName() : nls.localize('binaryEditor', "Binary Viewer");
}
......
......@@ -1262,7 +1262,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
await this.openEditor(editor);
const editorResource = toResource(editor, { supportSideBySide: SideBySideEditor.MASTER });
const res = await this.fileDialogService.showSaveConfirm(editorResource ? [editorResource] : editor.getName()!);
const res = await this.fileDialogService.showSaveConfirm(editorResource ? [editorResource] : editor.getName());
// It could be that the editor saved meanwhile, so we check again
// to see if anything needs to happen before closing for good.
......
......@@ -18,7 +18,6 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { toResource, SideBySideEditor, IEditorInput } from 'vs/workbench/common/editor';
import { compareItemsByScore, scoreItem, ScorerCache, prepareQuery } from 'vs/base/parts/quickopen/common/quickOpenScorer';
import { CancellationToken } from 'vs/base/common/cancellation';
import { withNullAsUndefined } from 'vs/base/common/types';
export class EditorPickerEntry extends QuickOpenEntryGroup {
......@@ -38,8 +37,8 @@ export class EditorPickerEntry extends QuickOpenEntryGroup {
};
}
getLabel() {
return withNullAsUndefined(this.editor.getName());
getLabel(): string {
return this.editor.getName();
}
getIcon(): string {
......
......@@ -248,7 +248,7 @@ export class NoTabsTitleControl extends TitleControl {
// Editor Label
const resource = toResource(editor, { supportSideBySide: SideBySideEditor.MASTER });
const name = editor.getName() || '';
const name = editor.getName();
const { labelFormat } = this.accessor.partOptions;
let description: string;
......
......@@ -65,7 +65,7 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
return new EditorMemento(this.getId(), key, Object.create(null), limit, editorGroupService); // do not persist in storage as diff editors are never persisted
}
getTitle(): string | undefined {
getTitle(): string {
if (this.input) {
return this.input.getName();
}
......@@ -219,7 +219,7 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
protected getAriaLabel(): string {
let ariaLabel: string;
const inputName = this.input && this.input.getName();
const inputName = this.input?.getName();
if (this.isReadOnly()) {
ariaLabel = inputName ? nls.localize('readonlyEditorWithInputAriaLabel', "{0}. Readonly text compare editor.", inputName) : nls.localize('readonlyEditorAriaLabel', "Readonly text compare editor.");
} else {
......
......@@ -287,7 +287,7 @@ export abstract class TitleControl extends Themable {
label = localize('draggedEditorGroup', "{0} (+{1})", label, this.group.count - 1);
}
applyDragImage(e, withUndefinedAsNull(label), 'monaco-editor-group-drag-image');
applyDragImage(e, label, 'monaco-editor-group-drag-image');
}
}));
......
......@@ -724,7 +724,7 @@ export class EditorHistoryEntryGroup extends QuickOpenEntryGroup {
export class EditorHistoryEntry extends EditorQuickOpenEntry {
private input: IEditorInput | IResourceInput;
private resource: URI | undefined;
private label: string | undefined;
private label: string;
private description?: string;
private dirty: boolean;
......@@ -745,7 +745,7 @@ export class EditorHistoryEntry extends EditorQuickOpenEntry {
if (input instanceof EditorInput) {
this.resource = resourceForEditorHistory(input, fileService);
this.label = types.withNullAsUndefined(input.getName());
this.label = input.getName();
this.description = input.getDescription();
this.dirty = input.isDirty();
} else {
......@@ -765,7 +765,7 @@ export class EditorHistoryEntry extends EditorQuickOpenEntry {
return this.dirty ? 'dirty' : '';
}
getLabel(): string | undefined {
getLabel(): string {
return this.label;
}
......
......@@ -294,7 +294,7 @@ export interface IEditorInput extends IDisposable {
/**
* Returns the display name of this input.
*/
getName(): string | undefined;
getName(): string;
/**
* Returns the display description of this input.
......@@ -360,8 +360,8 @@ export abstract class EditorInput extends Disposable implements IEditorInput {
* Returns the name of this input that can be shown to the user. Examples include showing the name of the input
* above the editor area when the input is shown.
*/
getName(): string | undefined {
return undefined;
getName(): string {
return `Editor ${this.getTypeId()}`;
}
/**
......@@ -376,7 +376,7 @@ export abstract class EditorInput extends Disposable implements IEditorInput {
* Returns the title of this input that can be shown to the user. Examples include showing the title of
* the input above the editor area as hover over the input label.
*/
getTitle(verbosity?: Verbosity): string | undefined {
getTitle(verbosity?: Verbosity): string {
return this.getName();
}
......
......@@ -7,7 +7,7 @@ import { EditorModel } from 'vs/workbench/common/editor';
import { URI } from 'vs/base/common/uri';
import { IFileService } from 'vs/platform/files/common/files';
import { Schemas } from 'vs/base/common/network';
import { DataUri, basename } from 'vs/base/common/resources';
import { DataUri } from 'vs/base/common/resources';
import { MIME_BINARY } from 'vs/base/common/mime';
/**
......@@ -20,7 +20,7 @@ export class BinaryEditorModel extends EditorModel {
constructor(
public readonly resource: URI,
private readonly name: string | undefined,
private readonly name: string,
@IFileService private readonly fileService: IFileService
) {
super();
......@@ -46,7 +46,7 @@ export class BinaryEditorModel extends EditorModel {
* The name of the binary resource.
*/
getName(): string {
return this.name || basename(this.resource);
return this.name;
}
/**
......
......@@ -7,7 +7,7 @@ import { EditorInput } from 'vs/workbench/common/editor';
import { URI } from 'vs/base/common/uri';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { BinaryEditorModel } from 'vs/workbench/common/editor/binaryEditorModel';
import { DataUri } from 'vs/base/common/resources';
import { DataUri, basename } from 'vs/base/common/resources';
/**
* An editor input to present data URIs in a binary editor. Data URIs have the form of:
......@@ -17,25 +17,31 @@ export class DataUriEditorInput extends EditorInput {
static readonly ID: string = 'workbench.editors.dataUriEditorInput';
private readonly name: string;
private readonly description: string | undefined;
constructor(
private readonly name: string | undefined,
private readonly description: string | undefined,
name: string | undefined,
description: string | undefined,
private readonly resource: URI,
@IInstantiationService private readonly instantiationService: IInstantiationService
) {
super();
if (!this.name || !this.description) {
if (!name || !description) {
const metadata = DataUri.parseMetaData(this.resource);
if (!this.name) {
this.name = metadata.get(DataUri.META_DATA_LABEL);
if (!name) {
name = metadata.get(DataUri.META_DATA_LABEL) || basename(resource);
}
if (!this.description) {
this.description = metadata.get(DataUri.META_DATA_DESCRIPTION);
if (!description) {
description = metadata.get(DataUri.META_DATA_DESCRIPTION);
}
}
this.name = name;
this.description = description;
}
getResource(): URI {
......@@ -46,7 +52,7 @@ export class DataUriEditorInput extends EditorInput {
return DataUriEditorInput.ID;
}
getName(): string | undefined {
getName(): string {
return this.name;
}
......
......@@ -18,7 +18,13 @@ export class DiffEditorInput extends SideBySideEditorInput {
private cachedModel: DiffEditorModel | null = null;
constructor(name: string, description: string | undefined, original: EditorInput, modified: EditorInput, private readonly forceOpenAsBinary?: boolean) {
constructor(
name: string,
description: string | undefined,
original: EditorInput,
modified: EditorInput,
private readonly forceOpenAsBinary?: boolean
) {
super(name, description, original, modified);
}
......
......@@ -109,7 +109,7 @@ export class UntitledTextEditorInput extends EditorInput implements IEncodingSup
return this.labelService.getUriLabel(this.resource);
}
getTitle(verbosity: Verbosity): string | undefined {
getTitle(verbosity: Verbosity): string {
if (!this.hasAssociatedFilePath) {
return this.getName();
}
......@@ -122,8 +122,6 @@ export class UntitledTextEditorInput extends EditorInput implements IEncodingSup
case Verbosity.LONG:
return this.longTitle;
}
return undefined;
}
isDirty(): boolean {
......
......@@ -51,7 +51,7 @@ export class BinaryFileEditor extends BaseBinaryResourceEditor {
}
}
getTitle(): string | undefined {
getTitle(): string {
return this.input ? this.input.getName() : nls.localize('binaryFileEditor', "Binary File Viewer");
}
}
......@@ -39,7 +39,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, withUndefinedAsNull } from 'vs/base/common/types';
import { withUndefinedAsNull } from 'vs/base/common/types';
import { isWeb } from 'vs/base/common/platform';
import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService';
......@@ -619,13 +619,13 @@ class OpenEditorsDragAndDrop implements IListDragAndDrop<OpenEditor | IEditorGro
return null;
}
getDragLabel?(elements: (OpenEditor | IEditorGroup)[]): string | undefined {
getDragLabel?(elements: (OpenEditor | IEditorGroup)[]): string {
if (elements.length > 1) {
return String(elements.length);
}
const element = elements[0];
return element instanceof OpenEditor ? withNullAsUndefined(element.editor.getName()) : element.label;
return element instanceof OpenEditor ? element.editor.getName() : element.label;
}
onDragStart(data: IDragAndDropData, originalEvent: DragEvent): void {
......
......@@ -101,7 +101,7 @@ export class WebviewInput extends EditorInput {
return this._name;
}
public getTitle(_verbosity?: Verbosity) {
public getTitle(_verbosity?: Verbosity): string {
return this.getName();
}
......
......@@ -623,7 +623,7 @@ export class EditorService extends Disposable implements EditorServiceImpl {
// Data URI
else if (resource.scheme === Schemas.data) {
input = instantiationService.createInstance(DataUriEditorInput, label, description, resource);
input = instantiationService.createInstance(DataUriEditorInput, label || basename(resource), description, resource);
}
// Resource
......
......@@ -484,8 +484,8 @@ export class HistoryService extends Disposable implements IHistoryService {
private handleEditorEventInHistory(editor?: IBaseEditor): void {
const input = editor?.input;
// Ensure we have at least a name to show and not configured to exclude input
if (!input || !input.getName() || !this.include(input)) {
// Ensure we have not configured to exclude input
if (!input || !this.include(input)) {
return;
}
......
......@@ -21,7 +21,7 @@ export class PreferencesEditorInput extends SideBySideEditorInput {
return PreferencesEditorInput.ID;
}
getTitle(verbosity: Verbosity): string | undefined {
getTitle(verbosity: Verbosity): string {
return this.master.getTitle(verbosity);
}
}
......
......@@ -31,4 +31,4 @@ suite('DataUriEditorInput', () => {
assert.equal(model.getMime(), 'image/png');
});
});
});
\ No newline at end of file
});
......@@ -22,7 +22,7 @@ suite('Workbench editor input', () => {
assert(input.matches(input));
assert(!input.matches(otherInput));
assert(!input.matches(null));
assert(!input.getName());
assert(input.getName());
input.onDispose(() => {
assert(true);
......@@ -84,4 +84,4 @@ suite('Workbench editor input', () => {
otherInput.dispose();
assert.equal(counter, 2);
});
});
\ No newline at end of file
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册