提交 3e8954af 编写于 作者: C Christof Marti

Do not open Welcome page on reload (fixes #30997)

上级 a8d0740c
......@@ -7,10 +7,11 @@
import { localize } from 'vs/nls';
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { Registry } from 'vs/platform/registry/common/platform';
import { WelcomePageContribution, WelcomePageAction } from 'vs/workbench/parts/welcome/page/electron-browser/welcomePage';
import { WelcomePageContribution, WelcomePageAction, WelcomeInputFactory } from 'vs/workbench/parts/welcome/page/electron-browser/welcomePage';
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actionRegistry';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from 'vs/platform/configuration/common/configurationRegistry';
import { IEditorRegistry, Extensions as EditorExtensions } from 'vs/workbench/common/editor';
Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration)
.registerConfiguration({
......@@ -37,3 +38,5 @@ Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench)
Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions)
.registerWorkbenchAction(new SyncActionDescriptor(WelcomePageAction, WelcomePageAction.ID, WelcomePageAction.LABEL), 'Help: Welcome', localize('help', "Help"));
Registry.as<IEditorRegistry>(EditorExtensions.Editors).registerEditorInputFactory(WelcomeInputFactory.ID, WelcomeInputFactory);
......@@ -30,7 +30,7 @@ import { IMessageService, Severity, CloseAction } from 'vs/platform/message/comm
import { getInstalledExtensions, IExtensionStatus, onExtensionChanged, isKeymapExtension } from 'vs/workbench/parts/extensions/electron-browser/extensionsUtils';
import { IExtensionEnablementService, IExtensionManagementService, IExtensionGalleryService, IExtensionTipsService } from 'vs/platform/extensionManagement/common/extensionManagement';
import { used } from 'vs/workbench/parts/welcome/page/electron-browser/vs_code_welcome_page';
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
import { ILifecycleService, StartupKind } from 'vs/platform/lifecycle/common/lifecycle';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { tildify } from 'vs/base/common/labels';
import { isLinux } from 'vs/base/common/platform';
......@@ -40,6 +40,7 @@ import { getExtraColor } from 'vs/workbench/parts/welcome/walkThrough/node/walkT
import { IExtensionsWorkbenchService } from 'vs/workbench/parts/extensions/common/extensions';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { IWorkspaceIdentifier, getWorkspaceLabel, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier } from "vs/platform/workspaces/common/workspaces";
import { IEditorInputFactory, EditorInput } from 'vs/workbench/common/editor';
used();
......@@ -56,18 +57,21 @@ export class WelcomePageContribution implements IWorkbenchContribution {
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@IBackupFileService backupFileService: IBackupFileService,
@ITelemetryService telemetryService: ITelemetryService,
@ILifecycleService lifecycleService: ILifecycleService,
@IStorageService storageService: IStorageService
) {
const enabled = isWelcomePageEnabled(configurationService);
if (enabled) {
if (enabled && lifecycleService.startupKind !== StartupKind.ReloadedWindow) {
TPromise.join([
backupFileService.hasBackups(),
partService.joinCreation()
]).then(([hasBackups]) => {
const activeInput = editorService.getActiveEditorInput();
if (!activeInput && !hasBackups) {
instantiationService.createInstance(WelcomePage);
return instantiationService.createInstance(WelcomePage)
.openEditor();
}
return undefined;
}).then(null, onUnexpectedError);
}
}
......@@ -102,8 +106,9 @@ export class WelcomePageAction extends Action {
}
public run(): TPromise<void> {
this.instantiationService.createInstance(WelcomePage);
return null;
return this.instantiationService.createInstance(WelcomePage)
.openEditor()
.then(() => undefined);
}
}
......@@ -161,10 +166,14 @@ const keymapStrings: Strings = {
extensionNotFound: localize('welcomePage.keymapNotFound', "The {0} keyboard shortcuts with id {1} could not be found."),
};
const welcomeInputTypeId = 'workbench.editors.welcomePageInput';
class WelcomePage {
private disposables: IDisposable[] = [];
readonly editorInput: WalkThroughInput;
constructor(
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IInstantiationService private instantiationService: IInstantiationService,
......@@ -185,20 +194,25 @@ class WelcomePage {
@ITelemetryService private telemetryService: ITelemetryService
) {
this.disposables.push(lifecycleService.onShutdown(() => this.dispose()));
this.create();
}
private create() {
const recentlyOpened = this.windowService.getRecentlyOpened();
const installedExtensions = this.instantiationService.invokeFunction(getInstalledExtensions);
const uri = URI.parse(require.toUrl('./vs_code_welcome_page'))
const resource = URI.parse(require.toUrl('./vs_code_welcome_page'))
.with({
scheme: Schemas.walkThrough,
query: JSON.stringify({ moduleId: 'vs/workbench/parts/welcome/page/electron-browser/vs_code_welcome_page' })
});
const input = this.instantiationService.createInstance(WalkThroughInput, localize('welcome.title', "Welcome"), '', uri, telemetryFrom, container => this.onReady(container, recentlyOpened, installedExtensions));
this.editorService.openEditor(input, { pinned: true }, Position.ONE)
.then(null, onUnexpectedError);
this.editorInput = this.instantiationService.createInstance(WalkThroughInput, {
typeId: welcomeInputTypeId,
name: localize('welcome.title', "Welcome"),
resource,
telemetryFrom,
onReady: container => this.onReady(container, recentlyOpened, installedExtensions)
});
}
public openEditor() {
return this.editorService.openEditor(this.editorInput, { pinned: true }, Position.ONE);
}
private onReady(container: HTMLElement, recentlyOpened: TPromise<{ files: string[]; workspaces: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier)[]; }>, installedExtensions: TPromise<IExtensionStatus[]>): void {
......@@ -473,6 +487,21 @@ class WelcomePage {
}
}
export class WelcomeInputFactory implements IEditorInputFactory {
static ID = welcomeInputTypeId;
public serialize(editorInput: EditorInput): string {
return '{}';
}
public deserialize(instantiationService: IInstantiationService, serializedEditorInput: string): WalkThroughInput {
return instantiationService.createInstance(WelcomePage)
.editorInput;
}
}
// theming
const buttonBackground = registerColor('welcomePage.buttonBackground', { dark: null, light: null, hc: null }, localize('welcomePage.buttonBackground', 'Background color for the buttons on the Welcome page.'));
......
......@@ -11,8 +11,18 @@ import { Action } from 'vs/base/common/actions';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { TPromise } from 'vs/base/common/winjs.base';
import URI from 'vs/base/common/uri';
import { WalkThroughInput } from 'vs/workbench/parts/welcome/walkThrough/node/walkThroughInput';
import { WalkThroughInput, WalkThroughInputOptions } from 'vs/workbench/parts/welcome/walkThrough/node/walkThroughInput';
import { Schemas } from 'vs/base/common/network';
import { IEditorInputFactory, EditorInput } from 'vs/workbench/common/editor';
const typeId = 'workbench.editors.walkThroughInput';
const inputOptions: WalkThroughInputOptions = {
typeId,
name: localize('editorWalkThrough.title', "Interactive Playground"),
resource: URI.parse(require.toUrl('./vs_code_editor_walkthrough.md'))
.with({ scheme: Schemas.walkThrough }),
telemetryFrom: 'walkThrough'
};
export class EditorWalkThroughAction extends Action {
......@@ -29,10 +39,21 @@ export class EditorWalkThroughAction extends Action {
}
public run(): TPromise<void> {
const uri = URI.parse(require.toUrl('./vs_code_editor_walkthrough.md'))
.with({ scheme: Schemas.walkThrough });
const input = this.instantiationService.createInstance(WalkThroughInput, localize('editorWalkThrough.title', "Interactive Playground"), '', uri, /* telemetryFrom */ null, /* onReady */ null);
const input = this.instantiationService.createInstance(WalkThroughInput, inputOptions);
return this.editorService.openEditor(input, { pinned: true }, Position.ONE)
.then(() => void (0));
}
}
\ No newline at end of file
}
export class EditorWalkThroughInputFactory implements IEditorInputFactory {
static ID = typeId;
public serialize(editorInput: EditorInput): string {
return '{}';
}
public deserialize(instantiationService: IInstantiationService, serializedEditorInput: string): WalkThroughInput {
return instantiationService.createInstance(WalkThroughInput, inputOptions);
}
}
......@@ -9,7 +9,7 @@ import { WalkThroughInput } from 'vs/workbench/parts/welcome/walkThrough/node/wa
import { WalkThroughPart, WALK_THROUGH_FOCUS } from 'vs/workbench/parts/welcome/walkThrough/electron-browser/walkThroughPart';
import { WalkThroughArrowUpAction, WalkThroughArrowDownAction, WalkThroughPageUpAction, WalkThroughPageDownAction } from 'vs/workbench/parts/welcome/walkThrough/electron-browser/walkThroughActions';
import { WalkThroughContentProvider, WalkThroughSnippetContentProvider } from 'vs/workbench/parts/welcome/walkThrough/node/walkThroughContentProvider';
import { EditorWalkThroughAction } from 'vs/workbench/parts/welcome/walkThrough/electron-browser/editor/editorWalkThrough';
import { EditorWalkThroughAction, EditorWalkThroughInputFactory } from 'vs/workbench/parts/welcome/walkThrough/electron-browser/editor/editorWalkThrough';
import { Registry } from 'vs/platform/registry/common/platform';
import { EditorDescriptor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { IEditorRegistry, Extensions as EditorExtensions } from 'vs/workbench/common/editor';
......@@ -33,6 +33,8 @@ Registry.as<IWorkbenchActionRegistry>(Extensions.WorkbenchActions)
new SyncActionDescriptor(EditorWalkThroughAction, EditorWalkThroughAction.ID, EditorWalkThroughAction.LABEL),
'Help: Interactive Playground', localize('help', "Help"));
Registry.as<IEditorRegistry>(EditorExtensions.Editors).registerEditorInputFactory(EditorWalkThroughInputFactory.ID, EditorWalkThroughInputFactory);
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench)
.registerWorkbenchContribution(WalkThroughContentProvider);
......
......@@ -40,9 +40,16 @@ export class WalkThroughModel extends EditorModel {
}
}
export class WalkThroughInput extends EditorInput {
export interface WalkThroughInputOptions {
readonly typeId: string;
readonly name: string;
readonly description?: string;
readonly resource: URI;
readonly telemetryFrom: string;
readonly onReady?: (container: HTMLElement) => void;
}
static ID: string = 'workbench.editors.walkThroughInput';
export class WalkThroughInput extends EditorInput {
private disposables: IDisposable[] = [];
......@@ -53,11 +60,7 @@ export class WalkThroughInput extends EditorInput {
private maxBottomScroll = 0;
constructor(
private name: string,
private description: string,
private resource: URI,
private telemetryFrom: string,
public readonly onReady: (container: HTMLElement) => void,
private options: WalkThroughInputOptions,
@ITelemetryService private telemetryService: ITelemetryService,
@ILifecycleService lifecycleService: ILifecycleService,
@ITextModelService private textModelResolverService: ITextModelService
......@@ -67,36 +70,40 @@ export class WalkThroughInput extends EditorInput {
}
getResource(): URI {
return this.resource;
return this.options.resource;
}
getTypeId(): string {
return WalkThroughInput.ID;
return this.options.typeId;
}
getName(): string {
return this.name;
return this.options.name;
}
getDescription(): string {
return this.description;
return this.options.description || '';
}
getTelemetryFrom(): string {
return this.telemetryFrom || 'walkThrough';
return this.options.telemetryFrom;
}
getTelemetryDescriptor(): object {
const descriptor = super.getTelemetryDescriptor();
descriptor['target'] = this.getTelemetryFrom();
descriptor['resource'] = telemetryURIDescriptor(this.resource);
descriptor['resource'] = telemetryURIDescriptor(this.options.resource);
return descriptor;
}
get onReady() {
return this.options.onReady;
}
resolve(refresh?: boolean): TPromise<WalkThroughModel> {
if (!this.promise) {
this.resolveTelemetry();
this.promise = this.textModelResolverService.createModelReference(this.resource)
this.promise = this.textModelResolverService.createModelReference(this.options.resource)
.then(ref => {
if (strings.endsWith(this.getResource().path, '.html')) {
return new WalkThroughModel(ref, []);
......@@ -106,7 +113,7 @@ export class WalkThroughInput extends EditorInput {
let i = 0;
const renderer = new marked.Renderer();
renderer.code = (code, lang) => {
const resource = this.resource.with({ scheme: Schemas.walkThroughSnippet, fragment: `${i++}.${lang}` });
const resource = this.options.resource.with({ scheme: Schemas.walkThroughSnippet, fragment: `${i++}.${lang}` });
snippets.push(this.textModelResolverService.createModelReference(resource));
return '';
};
......@@ -131,7 +138,7 @@ export class WalkThroughInput extends EditorInput {
let otherResourceEditorInput = <WalkThroughInput>otherInput;
// Compare by properties
return otherResourceEditorInput.resource.toString() === this.resource.toString();
return otherResourceEditorInput.options.resource.toString() === this.options.resource.toString();
}
return false;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册