Skip to content

Commit 9f92d07

Browse files
authored
Merge pull request microsoft#272378 from mjbvz/dev/mjbvz/custom-editor-icons
Allow custom editors to set custom icons
2 parents 5493635 + 02a8519 commit 9f92d07

File tree

14 files changed

+70
-126
lines changed

14 files changed

+70
-126
lines changed

src/vs/base/browser/ui/iconLabel/iconlabel.css

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@
3333

3434
.monaco-icon-label-iconpath {
3535
width: 16px;
36-
height: 16px;
37-
padding-left: 2px;
38-
margin-top: 2px;
36+
height: 22px;
37+
margin-right: 6px;
3938
display: flex;
4039
}
4140

src/vs/workbench/api/browser/mainThreadCustomEditors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ class MainThreadCustomEditorModel extends ResourceWorkingCopy implements ICustom
671671
viewType: this.viewType,
672672
editorResource: this._editorResource,
673673
customTitle: primaryEditor.getCustomTitle(),
674+
iconPath: primaryEditor.iconPath,
674675
backupId: '',
675676
extension: primaryEditor.extension ? {
676677
id: primaryEditor.extension.id.value,

src/vs/workbench/api/browser/mainThreadWebviewPanels.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import { IStorageService } from '../../../platform/storage/common/storage.js';
1313
import { DiffEditorInput } from '../../common/editor/diffEditorInput.js';
1414
import { EditorInput } from '../../common/editor/editorInput.js';
1515
import { ExtensionKeyedWebviewOriginStore, WebviewOptions } from '../../contrib/webview/browser/webview.js';
16-
import { WebviewInput } from '../../contrib/webviewPanel/browser/webviewEditorInput.js';
17-
import { WebviewIcons } from '../../contrib/webviewPanel/browser/webviewIconManager.js';
16+
import { WebviewIcons, WebviewInput } from '../../contrib/webviewPanel/browser/webviewEditorInput.js';
1817
import { IWebViewShowOptions, IWebviewWorkbenchService } from '../../contrib/webviewPanel/browser/webviewWorkbenchService.js';
1918
import { editorGroupToColumn } from '../../services/editor/common/editorGroupColumn.js';
2019
import { GroupLocation, GroupsOrder, IEditorGroup, IEditorGroupsService, preferredSideBySideGroupDirection } from '../../services/editor/common/editorGroupsService.js';
@@ -171,7 +170,7 @@ export class MainThreadWebviewPanels extends Disposable implements extHostProtoc
171170
options: reviveWebviewOptions(initData.panelOptions),
172171
contentOptions: reviveWebviewContentOptions(initData.webviewOptions),
173172
extension
174-
}, this.webviewPanelViewType.fromExternal(viewType), initData.title, mainThreadShowOptions);
173+
}, this.webviewPanelViewType.fromExternal(viewType), initData.title, undefined, mainThreadShowOptions);
175174

176175
this.addWebviewInput(handle, webview, { serializeBuffersForPostMessage: initData.serializeBuffersForPostMessage });
177176
}

src/vs/workbench/browser/parts/editor/media/editortabscontrol.css

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@
3434
cursor: pointer;
3535
}
3636

37-
.monaco-workbench .part.editor > .content .editor-group-container > .title .monaco-icon-label::before {
38-
height: var(--editor-group-tab-height); /* tweak the icon size of the editor labels when icons are enabled */
37+
.monaco-workbench .part.editor > .content .editor-group-container > .title .monaco-icon-label {
38+
&::before,
39+
& > .monaco-icon-label-iconpath {
40+
height: var(--editor-group-tab-height); /* tweak the icon size of the editor labels when icons are enabled */
41+
}
3942
}
4043

4144
.monaco-workbench .part.editor > .content .editor-group-container > .title.breadcrumbs .monaco-icon-label::after,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export abstract class EditorInput extends AbstractEditorInput {
183183
* Returns the icon which represents this editor input.
184184
* If undefined, the default icon will be used.
185185
*/
186-
getIcon(): ThemeIcon | undefined {
186+
getIcon(): ThemeIcon | URI | undefined {
187187
return undefined;
188188
}
189189

src/vs/workbench/contrib/customEditor/browser/customEditorInput.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,14 @@ import { IEditorGroupsService } from '../../../services/editor/common/editorGrou
3232
import { IFilesConfigurationService } from '../../../services/filesConfiguration/common/filesConfigurationService.js';
3333
import { IWorkbenchLayoutService } from '../../../services/layout/browser/layoutService.js';
3434
import { IUntitledTextEditorService } from '../../../services/untitled/common/untitledTextEditorService.js';
35+
import { IThemeService } from '../../../../platform/theme/common/themeService.js';
36+
import { WebviewIcons } from '../../webviewPanel/browser/webviewEditorInput.js';
3537

3638
interface CustomEditorInputInitInfo {
3739
readonly resource: URI;
3840
readonly viewType: string;
3941
readonly customTitle: string | undefined;
42+
readonly iconPath: WebviewIcons | undefined;
4043
}
4144

4245
export class CustomEditorInput extends LazilyResolvedWebviewEditorInput {
@@ -87,6 +90,7 @@ export class CustomEditorInput extends LazilyResolvedWebviewEditorInput {
8790
init: CustomEditorInputInitInfo,
8891
webview: IOverlayWebview,
8992
options: { startsDirty?: boolean; backupId?: string; untitledDocumentData?: VSBuffer; readonly oldResource?: URI },
93+
@IThemeService themeService: IThemeService,
9094
@IWebviewWorkbenchService webviewWorkbenchService: IWebviewWorkbenchService,
9195
@IInstantiationService private readonly instantiationService: IInstantiationService,
9296
@ILabelService private readonly labelService: ILabelService,
@@ -99,7 +103,7 @@ export class CustomEditorInput extends LazilyResolvedWebviewEditorInput {
99103
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
100104
@ICustomEditorLabelService private readonly customEditorLabelService: ICustomEditorLabelService,
101105
) {
102-
super({ providedId: init.viewType, viewType: init.viewType, name: '' }, webview, webviewWorkbenchService);
106+
super({ providedId: init.viewType, viewType: init.viewType, name: '', iconPath: init.iconPath }, webview, themeService, webviewWorkbenchService);
103107
this._editorResource = init.resource;
104108
this.oldResource = options.oldResource;
105109
this._defaultDirtyState = options.startsDirty;
@@ -290,7 +294,7 @@ export class CustomEditorInput extends LazilyResolvedWebviewEditorInput {
290294

291295
public override copy(): EditorInput {
292296
return CustomEditorInput.create(this.instantiationService,
293-
{ resource: this.resource, viewType: this.viewType, customTitle: this._customTitle },
297+
{ resource: this.resource, viewType: this.viewType, customTitle: this._customTitle, iconPath: this.iconPath, },
294298
this.group,
295299
this.webview.options);
296300
}

src/vs/workbench/contrib/customEditor/browser/customEditorInputFactory.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface CustomDocumentBackupData extends IWorkingCopyBackupMeta {
2525
readonly editorResource: UriComponents;
2626

2727
readonly customTitle: string | undefined;
28+
readonly iconPath: { dark: UriComponents; light: UriComponents } | undefined;
2829

2930
backupId: string;
3031

@@ -99,6 +100,7 @@ export class CustomEditorInputSerializer extends WebviewEditorInputSerializer {
99100
resource: data.editorResource,
100101
viewType: data.viewType,
101102
customTitle: data.title,
103+
iconPath: data.iconPath,
102104
}, webview, { startsDirty: data.dirty, backupId: data.backupId });
103105
if (typeof data.group === 'number') {
104106
customInput.updateGroup(data.group);
@@ -199,6 +201,9 @@ export class ComplexCustomWorkingCopyEditorHandler extends Disposable implements
199201
resource: URI.revive(backupData.editorResource),
200202
viewType: backupData.viewType,
201203
customTitle: backupData.customTitle,
204+
iconPath: backupData.iconPath
205+
? { dark: URI.revive(backupData.iconPath.dark), light: URI.revive(backupData.iconPath.light) }
206+
: undefined
202207
}, webview, { backupId: backupData.backupId });
203208
editor.updateGroup(0);
204209
return editor;

src/vs/workbench/contrib/customEditor/browser/customEditors.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ
138138
},
139139
{
140140
createEditorInput: ({ resource }, group) => {
141-
return { editor: CustomEditorInput.create(this.instantiationService, { resource, viewType: contributedEditor.id, customTitle: undefined }, group.id) };
141+
return { editor: CustomEditorInput.create(this.instantiationService, { resource, viewType: contributedEditor.id, customTitle: undefined, iconPath: undefined }, group.id) };
142142
},
143143
createUntitledEditorInput: ({ resource }, group) => {
144-
return { editor: CustomEditorInput.create(this.instantiationService, { resource: resource ?? URI.from({ scheme: Schemas.untitled, authority: `Untitled-${this._untitledCounter++}` }), viewType: contributedEditor.id, customTitle: undefined }, group.id) };
144+
return { editor: CustomEditorInput.create(this.instantiationService, { resource: resource ?? URI.from({ scheme: Schemas.untitled, authority: `Untitled-${this._untitledCounter++}` }), viewType: contributedEditor.id, customTitle: undefined, iconPath: undefined }, group.id) };
145145
},
146146
createDiffEditorInput: (diffEditorInput, group) => {
147147
return { editor: this.createDiffEditorInput(diffEditorInput, contributedEditor.id, group) };
@@ -157,8 +157,8 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ
157157
editorID: string,
158158
group: IEditorGroup
159159
): DiffEditorInput {
160-
const modifiedOverride = CustomEditorInput.create(this.instantiationService, { resource: assertReturnsDefined(editor.modified.resource), viewType: editorID, customTitle: undefined }, group.id, { customClasses: 'modified' });
161-
const originalOverride = CustomEditorInput.create(this.instantiationService, { resource: assertReturnsDefined(editor.original.resource), viewType: editorID, customTitle: undefined }, group.id, { customClasses: 'original' });
160+
const modifiedOverride = CustomEditorInput.create(this.instantiationService, { resource: assertReturnsDefined(editor.modified.resource), viewType: editorID, customTitle: undefined, iconPath: undefined }, group.id, { customClasses: 'modified' });
161+
const originalOverride = CustomEditorInput.create(this.instantiationService, { resource: assertReturnsDefined(editor.original.resource), viewType: editorID, customTitle: undefined, iconPath: undefined }, group.id, { customClasses: 'original' });
162162
return this.instantiationService.createInstance(DiffEditorInput, editor.label, editor.description, originalOverride, modifiedOverride, true);
163163
}
164164

@@ -259,7 +259,7 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ
259259
let replacement: EditorInput | IResourceEditorInput;
260260
if (possibleEditors.defaultEditor) {
261261
const viewType = possibleEditors.defaultEditor.id;
262-
replacement = CustomEditorInput.create(this.instantiationService, { resource: newResource, viewType, customTitle: undefined }, group);
262+
replacement = CustomEditorInput.create(this.instantiationService, { resource: newResource, viewType, customTitle: undefined, iconPath: undefined }, group);
263263
} else {
264264
replacement = { resource: newResource, options: { override: DEFAULT_EDITOR_ASSOCIATION.id } };
265265
}

src/vs/workbench/contrib/search/browser/anythingQuickAccess.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ export class AnythingQuickAccessProvider extends PickerQuickAccessProvider<IAnyt
992992
let description: string | undefined = undefined;
993993
let isDirty: boolean | undefined = undefined;
994994
let extraClasses: string[];
995-
let icon: ThemeIcon | undefined = undefined;
995+
let icon: ThemeIcon | URI | undefined = undefined;
996996

997997
if (isEditorInput(resourceOrEditor)) {
998998
resource = EditorResourceAccessor.getOriginalUri(resourceOrEditor);

src/vs/workbench/contrib/update/browser/releaseNotesEditor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export class ReleaseNotesManager extends Disposable {
119119
},
120120
'releaseNotes',
121121
title,
122+
undefined,
122123
{ group: ACTIVE_GROUP, preserveFocus: false });
123124

124125
const disposables = new DisposableStore();

0 commit comments

Comments
 (0)