Skip to content

Commit ef6abe4

Browse files
authored
Adopt editor resolver for Welcome/Walkthrough pages (microsoft#184770)
* Register walkthrough pages via editorResolverService * Clean up code
1 parent 7ff66b3 commit ef6abe4

File tree

4 files changed

+59
-15
lines changed

4 files changed

+59
-15
lines changed

src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.contribution.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { KeyCode } from 'vs/base/common/keyCodes';
1616
import { EditorPaneDescriptor, IEditorPaneRegistry } from 'vs/workbench/browser/editor';
1717
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
1818
import { IWalkthroughsService } from 'vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedService';
19-
import { GettingStartedInput } from 'vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedInput';
19+
import { GettingStartedEditorOptions, GettingStartedInput } from 'vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedInput';
2020
import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
2121
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
2222
import { ConfigurationScope, Extensions as ConfigurationExtensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
@@ -100,20 +100,22 @@ registerAction2(class extends Action2 {
100100
return;
101101
}
102102

103-
const gettingStartedInput = instantiationService.createInstance(GettingStartedInput, { selectedCategory: selectedCategory, selectedStep: selectedStep });
104103
// If it's the extension install page then lets replace it with the getting started page
105104
if (activeEditor instanceof ExtensionsInput) {
106105
const activeGroup = editorGroupsService.activeGroup;
107106
activeGroup.replaceEditors([{
108107
editor: activeEditor,
109-
replacement: gettingStartedInput
108+
replacement: instantiationService.createInstance(GettingStartedInput, { selectedCategory: selectedCategory, selectedStep: selectedStep })
110109
}]);
111110
} else if (!openedWalkthroughExists) {
112111
// else open respecting toSide
113-
editorService.openEditor(gettingStartedInput, { preserveFocus: toSide ?? false }, toSide ? SIDE_GROUP : undefined);
112+
editorService.openEditor({
113+
resource: GettingStartedInput.RESOURCE,
114+
options: <GettingStartedEditorOptions>{ selectedCategory: selectedCategory, selectedStep: selectedStep, preserveFocus: toSide ?? false }
115+
}, toSide ? SIDE_GROUP : undefined);
114116
}
115117
} else {
116-
editorService.openEditor(new GettingStartedInput({}), {});
118+
editorService.openEditor({ resource: GettingStartedInput.RESOURCE });
117119
}
118120
}
119121
});

src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedInput.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ import { EditorInput } from 'vs/workbench/common/editor/editorInput';
99
import { URI } from 'vs/base/common/uri';
1010
import { Schemas } from 'vs/base/common/network';
1111
import { IUntypedEditorInput } from 'vs/workbench/common/editor';
12+
import { IEditorOptions } from 'vs/platform/editor/common/editor';
1213

1314
export const gettingStartedInputTypeId = 'workbench.editors.gettingStartedInput';
1415

16+
export interface GettingStartedEditorOptions extends IEditorOptions {
17+
selectedCategory?: string; selectedStep?: string; showTelemetryNotice?: boolean;
18+
}
19+
1520
export class GettingStartedInput extends EditorInput {
1621

1722
static readonly ID = gettingStartedInputTypeId;
@@ -21,6 +26,16 @@ export class GettingStartedInput extends EditorInput {
2126
return GettingStartedInput.ID;
2227
}
2328

29+
override toUntyped(): IUntypedEditorInput {
30+
return {
31+
resource: GettingStartedInput.RESOURCE,
32+
options: {
33+
override: GettingStartedInput.ID,
34+
pinned: false
35+
}
36+
};
37+
}
38+
2439
get resource(): URI | undefined {
2540
return GettingStartedInput.RESOURCE;
2641
}
@@ -37,7 +52,7 @@ export class GettingStartedInput extends EditorInput {
3752
}
3853

3954
constructor(
40-
options: { selectedCategory?: string; selectedStep?: string; showTelemetryNotice?: boolean }
55+
options: GettingStartedEditorOptions
4156
) {
4257
super();
4358
this.selectedCategory = options.selectedCategory;

src/vs/workbench/contrib/welcomeGettingStarted/browser/startupPage.ts

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { IFileService } from 'vs/platform/files/common/files';
1818
import { joinPath } from 'vs/base/common/resources';
1919
import { IEditorOptions } from 'vs/platform/editor/common/editor';
2020
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
21-
import { GettingStartedInput, gettingStartedInputTypeId } from 'vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedInput';
21+
import { GettingStartedEditorOptions, GettingStartedInput, gettingStartedInputTypeId } from 'vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedInput';
2222
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
2323
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
2424
import { getTelemetryLevel } from 'vs/platform/telemetry/common/telemetryUtils';
@@ -27,6 +27,7 @@ import { IProductService } from 'vs/platform/product/common/productService';
2727
import { ILogService } from 'vs/platform/log/common/log';
2828
import { INotificationService } from 'vs/platform/notification/common/notification';
2929
import { localize } from 'vs/nls';
30+
import { IEditorResolverService, RegisteredEditorPriority } from 'vs/workbench/services/editor/common/editorResolverService';
3031

3132
export const restoreWalkthroughsConfigurationKey = 'workbench.welcomePage.restorableWalkthroughs';
3233
export type RestoreWalkthroughsConfigurationValue = { folder: string; category?: string; step?: string };
@@ -51,9 +52,34 @@ export class StartupPageContribution implements IWorkbenchContribution {
5152
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
5253
@IStorageService private readonly storageService: IStorageService,
5354
@ILogService private readonly logService: ILogService,
54-
@INotificationService private readonly notificationService: INotificationService
55+
@INotificationService private readonly notificationService: INotificationService,
56+
@IEditorResolverService editorResolverService: IEditorResolverService
5557
) {
5658
this.run().then(undefined, onUnexpectedError);
59+
60+
editorResolverService.registerEditor(
61+
`${GettingStartedInput.RESOURCE.scheme}:/**`,
62+
{
63+
id: GettingStartedInput.ID,
64+
label: localize('welcome.displayName', "Welcome Page"),
65+
priority: RegisteredEditorPriority.builtin,
66+
},
67+
{
68+
singlePerResource: false,
69+
canSupportResource: uri => uri.scheme === GettingStartedInput.RESOURCE.scheme,
70+
},
71+
{
72+
createEditorInput: ({ resource, options }) => {
73+
return {
74+
editor: this.instantiationService.createInstance(GettingStartedInput, options as GettingStartedEditorOptions),
75+
options: {
76+
...options,
77+
pinned: false
78+
}
79+
};
80+
}
81+
}
82+
);
5783
}
5884

5985
private async run() {
@@ -114,11 +140,10 @@ export class StartupPageContribution implements IWorkbenchContribution {
114140
const restoreData: RestoreWalkthroughsConfigurationValue = JSON.parse(toRestore);
115141
const currentWorkspace = this.contextService.getWorkspace();
116142
if (restoreData.folder === currentWorkspace.folders[0].uri.toString() || restoreData.folder === UNKNOWN_EMPTY_WINDOW_WORKSPACE.id) {
117-
this.editorService.openEditor(
118-
this.instantiationService.createInstance(
119-
GettingStartedInput,
120-
{ selectedCategory: restoreData.category, selectedStep: restoreData.step }),
121-
{ pinned: false });
143+
this.editorService.openEditor({
144+
resource: GettingStartedInput.RESOURCE,
145+
options: <GettingStartedEditorOptions>{ selectedCategory: restoreData.category, selectedStep: restoreData.step, pinned: false },
146+
});
122147
this.storageService.remove(restoreWalkthroughsConfigurationKey, StorageScope.PROFILE);
123148
return true;
124149
}
@@ -165,7 +190,10 @@ export class StartupPageContribution implements IWorkbenchContribution {
165190

166191
const options: IEditorOptions = editor ? { pinned: false, index: 0 } : { pinned: false };
167192
if (startupEditorTypeID === gettingStartedInputTypeId) {
168-
this.editorService.openEditor(this.instantiationService.createInstance(GettingStartedInput, { showTelemetryNotice }), options);
193+
this.editorService.openEditor({
194+
resource: GettingStartedInput.RESOURCE,
195+
options: <GettingStartedEditorOptions>{ showTelemetryNotice, ...options },
196+
});
169197
}
170198
}
171199
}

src/vs/workbench/services/editor/common/editorResolverService.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ export function globMatchesResource(globPattern: string | glob.IRelativePattern,
204204
Schemas.extension,
205205
Schemas.webviewPanel,
206206
Schemas.vscodeWorkspaceTrust,
207-
Schemas.walkThrough,
208207
Schemas.vscodeSettings
209208
]);
210209
// We want to say that the above schemes match no glob patterns

0 commit comments

Comments
 (0)