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

compare untitled files: title (fix #92556)

上级 955ff025
......@@ -24,11 +24,23 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { withNullAsUndefined } from 'vs/base/common/types';
export interface IResourceLabelProps {
resource?: URI;
resource?: URI | { master?: URI, detail?: URI };
name?: string | string[];
description?: string;
}
function toResource(props: IResourceLabelProps | undefined): URI | undefined {
if (!props || !props.resource) {
return undefined;
}
if (URI.isUri(props.resource)) {
return props.resource;
}
return props.resource.master;
}
export interface IResourceLabelOptions extends IIconLabelValueOptions {
fileKind?: FileKind;
fileDecorations?: { colors: boolean, badges: boolean };
......@@ -289,11 +301,16 @@ class ResourceLabelWidget extends IconLabel {
}
notifyFileDecorationsChanges(e: IResourceDecorationChangeEvent): void {
if (!this.options || !this.label || !this.label.resource) {
if (!this.options) {
return;
}
if (this.options.fileDecorations && e.affectsResource(this.label.resource)) {
const resource = toResource(this.label);
if (!resource) {
return;
}
if (this.options.fileDecorations && e.affectsResource(resource)) {
this.render(false);
}
}
......@@ -311,13 +328,13 @@ class ResourceLabelWidget extends IconLabel {
}
notifyFormattersChange(scheme: string): void {
if (this.label?.resource?.scheme === scheme) {
if (toResource(this.label)?.scheme === scheme) {
this.render(false);
}
}
notifyUntitledLabelChange(resource: URI): void {
if (isEqual(resource, this.label?.resource)) {
if (isEqual(resource, toResource(this.label))) {
this.render(false);
}
}
......@@ -347,7 +364,10 @@ class ResourceLabelWidget extends IconLabel {
}
setResource(label: IResourceLabelProps, options: IResourceLabelOptions = Object.create(null)): void {
if (label.resource?.scheme === Schemas.untitled) {
const resource = toResource(this.label);
const isMasterDetail = this.label?.resource && !URI.isUri(this.label.resource);
if (!isMasterDetail && resource?.scheme === Schemas.untitled) {
// Untitled labels are very dynamic because they may change
// whenever the content changes (unless a path is associated).
// As such we always ask the actual editor for it's name and
......@@ -355,7 +375,11 @@ class ResourceLabelWidget extends IconLabel {
// provided. If they are not provided from the label we got
// we assume that the client does not want to display them
// and as such do not override.
const untitledModel = this.textFileService.untitled.get(label.resource);
//
// We do not touch the label if it represents a master-detail
// because in that case we expect it to carry a proper label
// and description.
const untitledModel = this.textFileService.untitled.get(resource);
if (untitledModel && !untitledModel.hasAssociatedFilePath) {
if (typeof label.name === 'string') {
label.name = untitledModel.name;
......@@ -415,7 +439,7 @@ class ResourceLabelWidget extends IconLabel {
}
private hasPathLabelChanged(newLabel: IResourceLabelProps, newOptions?: IResourceLabelOptions): boolean {
const newResource = newLabel ? newLabel.resource : undefined;
const newResource = toResource(newLabel);
return !!newResource && this.computedPathLabel !== this.labelService.getUriLabel(newResource);
}
......@@ -444,7 +468,8 @@ class ResourceLabelWidget extends IconLabel {
}
if (this.label) {
const detectedModeId = this.label.resource ? withNullAsUndefined(detectModeId(this.modelService, this.modeService, this.label.resource)) : undefined;
const resource = toResource(this.label);
const detectedModeId = resource ? withNullAsUndefined(detectModeId(this.modelService, this.modeService, resource)) : undefined;
if (this.lastKnownDetectedModeId !== detectedModeId) {
clearIconCache = true;
this.lastKnownDetectedModeId = detectedModeId;
......@@ -470,7 +495,7 @@ class ResourceLabelWidget extends IconLabel {
domId: this.options?.domId
};
const resource = this.label.resource;
const resource = toResource(this.label);
const label = this.label.name;
if (this.options && typeof this.options.title === 'string') {
......
......@@ -260,9 +260,6 @@ export class NoTabsTitleControl extends TitleControl {
this.updateEditorDirty(editor);
// Editor Label
const resource = toResource(editor, { supportSideBySide: SideBySideEditor.MASTER });
const name = editor.getName();
const { labelFormat } = this.accessor.partOptions;
let description: string;
if (this.breadcrumbsControl && !this.breadcrumbsControl.isHidden()) {
......@@ -278,7 +275,19 @@ export class NoTabsTitleControl extends TitleControl {
title = ''; // dont repeat what is already shown
}
editorLabel.setResource({ name, description, resource }, { title: typeof title === 'string' ? title : undefined, italic: !isEditorPinned, extraClasses: ['no-tabs', 'title-label'] });
editorLabel.setResource(
{
resource: toResource(editor, { supportSideBySide: SideBySideEditor.BOTH }),
name: editor.getName(),
description
},
{
title,
italic: !isEditorPinned,
extraClasses: ['no-tabs', 'title-label']
}
);
if (isGroupActive) {
editorLabel.element.style.color = this.getColor(TAB_ACTIVE_FOREGROUND) || '';
} else {
......
......@@ -963,10 +963,13 @@ export class TabsTitleControl extends TitleControl {
tabContainer.title = title;
// Label
const resource = toResource(editor, { supportSideBySide: SideBySideEditor.MASTER });
tabLabelWidget.setResource({ name, description, resource }, { title, extraClasses: ['tab-label'], italic: !this.group.isPinned(editor) });
tabLabelWidget.setResource(
{ name, description, resource: toResource(editor, { supportSideBySide: SideBySideEditor.BOTH }) },
{ title, extraClasses: ['tab-label'], italic: !this.group.isPinned(editor) }
);
// Tests helper
const resource = toResource(editor, { supportSideBySide: SideBySideEditor.MASTER });
if (resource) {
tabContainer.setAttribute('data-resource-name', basenameOrAuthority(resource));
} else {
......
......@@ -1319,7 +1319,8 @@ export interface IEditorPartOptionsChangeEvent {
export enum SideBySideEditor {
MASTER = 1,
DETAILS = 2
DETAILS = 2,
BOTH = 3
}
export interface IResourceOptions {
......@@ -1327,12 +1328,22 @@ export interface IResourceOptions {
filterByScheme?: string | string[];
}
export function toResource(editor: IEditorInput | undefined, options?: IResourceOptions): URI | undefined {
export function toResource(editor: IEditorInput | undefined): URI | undefined;
export function toResource(editor: IEditorInput | undefined, options: IResourceOptions & { supportSideBySide?: SideBySideEditor.MASTER | SideBySideEditor.DETAILS }): URI | undefined;
export function toResource(editor: IEditorInput | undefined, options: IResourceOptions & { supportSideBySide: SideBySideEditor.BOTH }): URI | { master?: URI, detail?: URI } | undefined;
export function toResource(editor: IEditorInput | undefined, options?: IResourceOptions): URI | { master?: URI, detail?: URI } | undefined {
if (!editor) {
return undefined;
}
if (options?.supportSideBySide && editor instanceof SideBySideEditorInput) {
if (options?.supportSideBySide === SideBySideEditor.BOTH) {
return {
master: toResource(editor.master, { filterByScheme: options.filterByScheme }),
detail: toResource(editor.details, { filterByScheme: options.filterByScheme })
};
}
editor = options.supportSideBySide === SideBySideEditor.MASTER ? editor.master : editor.details;
}
......@@ -1341,12 +1352,14 @@ export function toResource(editor: IEditorInput | undefined, options?: IResource
return resource;
}
if (Array.isArray(options.filterByScheme) && options.filterByScheme.some(scheme => resource.scheme === scheme)) {
return resource;
}
if (options.filterByScheme === resource.scheme) {
return resource;
if (Array.isArray(options.filterByScheme)) {
if (options.filterByScheme.some(scheme => resource.scheme === scheme)) {
return resource;
}
} else {
if (options.filterByScheme === resource.scheme) {
return resource;
}
}
return undefined;
......
......@@ -592,7 +592,7 @@ class OpenEditorRenderer implements IListRenderer<OpenEditor, IOpenEditorTemplat
templateData.actionRunner.editor = openedEditor;
editor.isDirty() && !editor.isSaving() ? dom.addClass(templateData.container, 'dirty') : dom.removeClass(templateData.container, 'dirty');
templateData.root.setResource({
resource: toResource(editor, { supportSideBySide: SideBySideEditor.MASTER }),
resource: toResource(editor, { supportSideBySide: SideBySideEditor.BOTH }),
name: editor.getName(),
description: editor.getDescription(Verbosity.MEDIUM)
}, {
......
......@@ -251,10 +251,10 @@ export class NativeWindow extends Disposable {
const file = toResource(this.editorService.activeEditor, { supportSideBySide: SideBySideEditor.MASTER, filterByScheme: Schemas.file });
// Represented Filename
this.updateRepresentedFilename(file ? file.fsPath : undefined);
this.updateRepresentedFilename(file?.fsPath);
// Custom title menu
this.provideCustomTitleContextMenu(file ? file.fsPath : undefined);
this.provideCustomTitleContextMenu(file?.fsPath);
}));
}
......
......@@ -35,6 +35,8 @@ suite('Workbench editor', () => {
assert.equal(toResource(untitled)!.toString(), untitled.resource.toString());
assert.equal(toResource(untitled, { supportSideBySide: SideBySideEditor.MASTER })!.toString(), untitled.resource.toString());
assert.equal(toResource(untitled, { supportSideBySide: SideBySideEditor.DETAILS })!.toString(), untitled.resource.toString());
assert.equal(toResource(untitled, { supportSideBySide: SideBySideEditor.BOTH })!.toString(), untitled.resource.toString());
assert.equal(toResource(untitled, { filterByScheme: Schemas.untitled })!.toString(), untitled.resource.toString());
assert.equal(toResource(untitled, { filterByScheme: [Schemas.file, Schemas.untitled] })!.toString(), untitled.resource.toString());
assert.ok(!toResource(untitled, { filterByScheme: Schemas.file }));
......@@ -43,6 +45,8 @@ suite('Workbench editor', () => {
assert.equal(toResource(file)!.toString(), file.resource.toString());
assert.equal(toResource(file, { supportSideBySide: SideBySideEditor.MASTER })!.toString(), file.resource.toString());
assert.equal(toResource(file, { supportSideBySide: SideBySideEditor.DETAILS })!.toString(), file.resource.toString());
assert.equal(toResource(file, { supportSideBySide: SideBySideEditor.BOTH })!.toString(), file.resource.toString());
assert.equal(toResource(file, { filterByScheme: Schemas.file })!.toString(), file.resource.toString());
assert.equal(toResource(file, { filterByScheme: [Schemas.file, Schemas.untitled] })!.toString(), file.resource.toString());
assert.ok(!toResource(file, { filterByScheme: Schemas.untitled }));
......@@ -52,8 +56,20 @@ suite('Workbench editor', () => {
assert.ok(!toResource(diffEditorInput));
assert.ok(!toResource(diffEditorInput, { filterByScheme: Schemas.file }));
assert.equal(toResource(file, { supportSideBySide: SideBySideEditor.MASTER })!.toString(), file.resource.toString());
assert.equal(toResource(file, { supportSideBySide: SideBySideEditor.MASTER, filterByScheme: Schemas.file })!.toString(), file.resource.toString());
assert.equal(toResource(file, { supportSideBySide: SideBySideEditor.MASTER, filterByScheme: [Schemas.file, Schemas.untitled] })!.toString(), file.resource.toString());
assert.equal(toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.MASTER })!.toString(), file.resource.toString());
assert.equal(toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.MASTER, filterByScheme: Schemas.file })!.toString(), file.resource.toString());
assert.equal(toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.MASTER, filterByScheme: [Schemas.file, Schemas.untitled] })!.toString(), file.resource.toString());
assert.equal(toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.DETAILS })!.toString(), untitled.resource.toString());
assert.equal(toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.DETAILS, filterByScheme: Schemas.untitled })!.toString(), untitled.resource.toString());
assert.equal(toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.DETAILS, filterByScheme: [Schemas.file, Schemas.untitled] })!.toString(), untitled.resource.toString());
assert.equal((toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.BOTH }) as { master: URI, detail: URI }).master.toString(), file.resource.toString());
assert.equal((toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.BOTH, filterByScheme: Schemas.file }) as { master: URI, detail: URI }).master.toString(), file.resource.toString());
assert.equal((toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.BOTH, filterByScheme: [Schemas.file, Schemas.untitled] }) as { master: URI, detail: URI }).master.toString(), file.resource.toString());
assert.equal((toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.BOTH }) as { master: URI, detail: URI }).detail.toString(), untitled.resource.toString());
assert.equal((toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.BOTH, filterByScheme: Schemas.untitled }) as { master: URI, detail: URI }).detail.toString(), untitled.resource.toString());
assert.equal((toResource(diffEditorInput, { supportSideBySide: SideBySideEditor.BOTH, filterByScheme: [Schemas.file, Schemas.untitled] }) as { master: URI, detail: URI }).detail.toString(), untitled.resource.toString());
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册