Skip to content

Commit

Permalink
Adopt editor resolver for Welcome/Walkthrough pages (#184770)
Browse files Browse the repository at this point in the history
* Register walkthrough pages via editorResolverService

* Clean up code
  • Loading branch information
bhavyaus committed Jun 11, 2023
1 parent 7ff66b3 commit ef6abe4
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 15 deletions.
Expand Up @@ -16,7 +16,7 @@ import { KeyCode } from 'vs/base/common/keyCodes';
import { EditorPaneDescriptor, IEditorPaneRegistry } from 'vs/workbench/browser/editor';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { IWalkthroughsService } from 'vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedService';
import { GettingStartedInput } from 'vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedInput';
import { GettingStartedEditorOptions, GettingStartedInput } from 'vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedInput';
import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { ConfigurationScope, Extensions as ConfigurationExtensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
Expand Down Expand Up @@ -100,20 +100,22 @@ registerAction2(class extends Action2 {
return;
}

const gettingStartedInput = instantiationService.createInstance(GettingStartedInput, { selectedCategory: selectedCategory, selectedStep: selectedStep });
// If it's the extension install page then lets replace it with the getting started page
if (activeEditor instanceof ExtensionsInput) {
const activeGroup = editorGroupsService.activeGroup;
activeGroup.replaceEditors([{
editor: activeEditor,
replacement: gettingStartedInput
replacement: instantiationService.createInstance(GettingStartedInput, { selectedCategory: selectedCategory, selectedStep: selectedStep })
}]);
} else if (!openedWalkthroughExists) {
// else open respecting toSide
editorService.openEditor(gettingStartedInput, { preserveFocus: toSide ?? false }, toSide ? SIDE_GROUP : undefined);
editorService.openEditor({
resource: GettingStartedInput.RESOURCE,
options: <GettingStartedEditorOptions>{ selectedCategory: selectedCategory, selectedStep: selectedStep, preserveFocus: toSide ?? false }
}, toSide ? SIDE_GROUP : undefined);
}
} else {
editorService.openEditor(new GettingStartedInput({}), {});
editorService.openEditor({ resource: GettingStartedInput.RESOURCE });
}
}
});
Expand Down
Expand Up @@ -9,9 +9,14 @@ import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { URI } from 'vs/base/common/uri';
import { Schemas } from 'vs/base/common/network';
import { IUntypedEditorInput } from 'vs/workbench/common/editor';
import { IEditorOptions } from 'vs/platform/editor/common/editor';

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

export interface GettingStartedEditorOptions extends IEditorOptions {
selectedCategory?: string; selectedStep?: string; showTelemetryNotice?: boolean;
}

export class GettingStartedInput extends EditorInput {

static readonly ID = gettingStartedInputTypeId;
Expand All @@ -21,6 +26,16 @@ export class GettingStartedInput extends EditorInput {
return GettingStartedInput.ID;
}

override toUntyped(): IUntypedEditorInput {
return {
resource: GettingStartedInput.RESOURCE,
options: {
override: GettingStartedInput.ID,
pinned: false
}
};
}

get resource(): URI | undefined {
return GettingStartedInput.RESOURCE;
}
Expand All @@ -37,7 +52,7 @@ export class GettingStartedInput extends EditorInput {
}

constructor(
options: { selectedCategory?: string; selectedStep?: string; showTelemetryNotice?: boolean }
options: GettingStartedEditorOptions
) {
super();
this.selectedCategory = options.selectedCategory;
Expand Down
Expand Up @@ -18,7 +18,7 @@ import { IFileService } from 'vs/platform/files/common/files';
import { joinPath } from 'vs/base/common/resources';
import { IEditorOptions } from 'vs/platform/editor/common/editor';
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
import { GettingStartedInput, gettingStartedInputTypeId } from 'vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedInput';
import { GettingStartedEditorOptions, GettingStartedInput, gettingStartedInputTypeId } from 'vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedInput';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
import { getTelemetryLevel } from 'vs/platform/telemetry/common/telemetryUtils';
Expand All @@ -27,6 +27,7 @@ import { IProductService } from 'vs/platform/product/common/productService';
import { ILogService } from 'vs/platform/log/common/log';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { localize } from 'vs/nls';
import { IEditorResolverService, RegisteredEditorPriority } from 'vs/workbench/services/editor/common/editorResolverService';

export const restoreWalkthroughsConfigurationKey = 'workbench.welcomePage.restorableWalkthroughs';
export type RestoreWalkthroughsConfigurationValue = { folder: string; category?: string; step?: string };
Expand All @@ -51,9 +52,34 @@ export class StartupPageContribution implements IWorkbenchContribution {
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
@IStorageService private readonly storageService: IStorageService,
@ILogService private readonly logService: ILogService,
@INotificationService private readonly notificationService: INotificationService
@INotificationService private readonly notificationService: INotificationService,
@IEditorResolverService editorResolverService: IEditorResolverService
) {
this.run().then(undefined, onUnexpectedError);

editorResolverService.registerEditor(
`${GettingStartedInput.RESOURCE.scheme}:/**`,
{
id: GettingStartedInput.ID,
label: localize('welcome.displayName', "Welcome Page"),
priority: RegisteredEditorPriority.builtin,
},
{
singlePerResource: false,
canSupportResource: uri => uri.scheme === GettingStartedInput.RESOURCE.scheme,
},
{
createEditorInput: ({ resource, options }) => {
return {
editor: this.instantiationService.createInstance(GettingStartedInput, options as GettingStartedEditorOptions),
options: {
...options,
pinned: false
}
};
}
}
);
}

private async run() {
Expand Down Expand Up @@ -114,11 +140,10 @@ export class StartupPageContribution implements IWorkbenchContribution {
const restoreData: RestoreWalkthroughsConfigurationValue = JSON.parse(toRestore);
const currentWorkspace = this.contextService.getWorkspace();
if (restoreData.folder === currentWorkspace.folders[0].uri.toString() || restoreData.folder === UNKNOWN_EMPTY_WINDOW_WORKSPACE.id) {
this.editorService.openEditor(
this.instantiationService.createInstance(
GettingStartedInput,
{ selectedCategory: restoreData.category, selectedStep: restoreData.step }),
{ pinned: false });
this.editorService.openEditor({
resource: GettingStartedInput.RESOURCE,
options: <GettingStartedEditorOptions>{ selectedCategory: restoreData.category, selectedStep: restoreData.step, pinned: false },
});
this.storageService.remove(restoreWalkthroughsConfigurationKey, StorageScope.PROFILE);
return true;
}
Expand Down Expand Up @@ -165,7 +190,10 @@ export class StartupPageContribution implements IWorkbenchContribution {

const options: IEditorOptions = editor ? { pinned: false, index: 0 } : { pinned: false };
if (startupEditorTypeID === gettingStartedInputTypeId) {
this.editorService.openEditor(this.instantiationService.createInstance(GettingStartedInput, { showTelemetryNotice }), options);
this.editorService.openEditor({
resource: GettingStartedInput.RESOURCE,
options: <GettingStartedEditorOptions>{ showTelemetryNotice, ...options },
});
}
}
}
Expand Down
Expand Up @@ -204,7 +204,6 @@ export function globMatchesResource(globPattern: string | glob.IRelativePattern,
Schemas.extension,
Schemas.webviewPanel,
Schemas.vscodeWorkspaceTrust,
Schemas.walkThrough,
Schemas.vscodeSettings
]);
// We want to say that the above schemes match no glob patterns
Expand Down

0 comments on commit ef6abe4

Please sign in to comment.