Skip to content

Commit aa06a3d

Browse files
author
Benjamin Pasero
committed
editors - add label property to file inputs
1 parent 59aad0d commit aa06a3d

3 files changed

Lines changed: 21 additions & 14 deletions

File tree

src/vs/workbench/common/editor.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,10 +649,16 @@ export interface IModeSupport {
649649
export interface IFileEditorInput extends IEditorInput, IEncodingSupport, IModeSupport {
650650

651651
/**
652-
* Gets the resource this editor is about.
652+
* Gets the resource this file input is about.
653653
*/
654654
readonly resource: URI;
655655

656+
/**
657+
* Gets the label of the editor. In most cases this will
658+
* be identical to the resource.
659+
*/
660+
readonly label: URI;
661+
656662
/**
657663
* Sets the preferred label to use for this file input.
658664
*/

src/vs/workbench/common/editor/textResourceEditorInput.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export abstract class AbstractTextResourceEditorInput extends EditorInput {
2222

2323
private static readonly MEMOIZER = createMemoizer();
2424

25-
private label: URI;
25+
private _label: URI;
26+
get label(): URI { return this._label; }
2627

2728
constructor(
2829
public readonly resource: URI,
@@ -36,7 +37,7 @@ export abstract class AbstractTextResourceEditorInput extends EditorInput {
3637
) {
3738
super();
3839

39-
this.label = preferredLabel || resource;
40+
this._label = preferredLabel || resource;
4041

4142
this.registerListeners();
4243
}
@@ -50,7 +51,7 @@ export abstract class AbstractTextResourceEditorInput extends EditorInput {
5051
}
5152

5253
private onLabelEvent(scheme: string): void {
53-
if (scheme === this.label.scheme) {
54+
if (scheme === this._label.scheme) {
5455
this.updateLabel();
5556
}
5657
}
@@ -65,15 +66,15 @@ export abstract class AbstractTextResourceEditorInput extends EditorInput {
6566
}
6667

6768
setLabel(label: URI): void {
68-
if (!extUri.isEqual(label, this.label)) {
69-
this.label = label;
69+
if (!extUri.isEqual(label, this._label)) {
70+
this._label = label;
7071

7172
this.updateLabel();
7273
}
7374
}
7475

7576
getLabel(): URI {
76-
return this.label;
77+
return this._label;
7778
}
7879

7980
getName(): string {
@@ -82,7 +83,7 @@ export abstract class AbstractTextResourceEditorInput extends EditorInput {
8283

8384
@AbstractTextResourceEditorInput.MEMOIZER
8485
private get basename(): string {
85-
return this.labelService.getUriBasenameLabel(this.label);
86+
return this.labelService.getUriBasenameLabel(this._label);
8687
}
8788

8889
getDescription(verbosity: Verbosity = Verbosity.MEDIUM): string | undefined {
@@ -99,17 +100,17 @@ export abstract class AbstractTextResourceEditorInput extends EditorInput {
99100

100101
@AbstractTextResourceEditorInput.MEMOIZER
101102
private get shortDescription(): string {
102-
return this.labelService.getUriBasenameLabel(dirname(this.label));
103+
return this.labelService.getUriBasenameLabel(dirname(this._label));
103104
}
104105

105106
@AbstractTextResourceEditorInput.MEMOIZER
106107
private get mediumDescription(): string {
107-
return this.labelService.getUriLabel(dirname(this.label), { relative: true });
108+
return this.labelService.getUriLabel(dirname(this._label), { relative: true });
108109
}
109110

110111
@AbstractTextResourceEditorInput.MEMOIZER
111112
private get longDescription(): string {
112-
return this.labelService.getUriLabel(dirname(this.label));
113+
return this.labelService.getUriLabel(dirname(this._label));
113114
}
114115

115116
@AbstractTextResourceEditorInput.MEMOIZER
@@ -119,12 +120,12 @@ export abstract class AbstractTextResourceEditorInput extends EditorInput {
119120

120121
@AbstractTextResourceEditorInput.MEMOIZER
121122
private get mediumTitle(): string {
122-
return this.labelService.getUriLabel(this.label, { relative: true });
123+
return this.labelService.getUriLabel(this._label, { relative: true });
123124
}
124125

125126
@AbstractTextResourceEditorInput.MEMOIZER
126127
private get longTitle(): string {
127-
return this.labelService.getUriLabel(this.label);
128+
return this.labelService.getUriLabel(this._label);
128129
}
129130

130131
getTitle(verbosity: Verbosity): string {

src/vs/workbench/services/editor/test/browser/editorService.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ suite('EditorService', () => {
10841084
const editor = await service.openEditor(input1, { pinned: true });
10851085
await service.openEditor(input2, { pinned: true });
10861086

1087-
const whenClosed = service.whenClosed([input1, input2]);
1087+
const whenClosed = service.whenClosed([{ resource: input1.resource }, { resource: input2.resource }]);
10881088

10891089
editor?.group?.closeAllEditors();
10901090

0 commit comments

Comments
 (0)