提交 8ef8adb3 编写于 作者: C Christof Marti

Add WalkThroughContentProvider

上级 c9c2454e
......@@ -12,6 +12,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { TPromise } from 'vs/base/common/winjs.base';
import URI from 'vs/base/common/uri';
import { WalkThroughInput } from 'vs/workbench/parts/walkThrough/common/walkThroughInput';
import { WALK_THROUGH_SCHEME } from 'vs/workbench/parts/walkThrough/electron-browser/walkThroughContentProvider';
export class EditorWalkThroughAction extends Action {
......@@ -28,7 +29,8 @@ export class EditorWalkThroughAction extends Action {
}
public run(): TPromise<void> {
const uri = URI.parse(require.toUrl('./editorWalkThrough.md'));
const uri = URI.parse(require.toUrl('./editorWalkThrough.md'))
.with({ scheme: WALK_THROUGH_SCHEME });
const input = this.instantiationService.createInstance(WalkThroughInput, localize('editorWalkThrough.title', "Editor Walk-Through"), '', uri, null);
return this.editorService.openEditor(input, { pinned: true }, Position.ONE)
.then(() => void (0));
......
......@@ -7,6 +7,7 @@
import { localize } from 'vs/nls';
import { WalkThroughInput } from 'vs/workbench/parts/walkThrough/common/walkThroughInput';
import { WalkThroughPart } from 'vs/workbench/parts/walkThrough/electron-browser/walkThroughPart';
import { WalkThroughContentProvider } from 'vs/workbench/parts/walkThrough/electron-browser/walkThroughContentProvider';
import { EditorWalkThroughAction } from 'vs/workbench/parts/walkThrough/electron-browser/editor/editorWalkThrough';
import { Registry } from 'vs/platform/platform';
import { EditorDescriptor } from 'vs/workbench/browser/parts/editor/baseEditor';
......@@ -14,6 +15,7 @@ import { IEditorRegistry, Extensions as EditorExtensions } from 'vs/workbench/co
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actionRegistry';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
(<IEditorRegistry>Registry.as(EditorExtensions.Editors)).registerEditor(new EditorDescriptor(WalkThroughPart.ID,
localize('walkThrough.editor.label', "Walk-Through"),
......@@ -23,3 +25,6 @@ import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
Registry.as<IWorkbenchActionRegistry>(Extensions.WorkbenchActions)
.registerWorkbenchAction(new SyncActionDescriptor(EditorWalkThroughAction, EditorWalkThroughAction.ID, EditorWalkThroughAction.LABEL), 'Help: Editor Walk-Through', localize('help', "Help"));
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench)
.registerWorkbenchContribution(WalkThroughContentProvider);
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { TPromise } from 'vs/base/common/winjs.base';
import URI from 'vs/base/common/uri';
import { ITextModelResolverService, ITextModelContentProvider } from 'vs/editor/common/services/resolverService';
import { IModelService } from 'vs/editor/common/services/modelService';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IModel } from 'vs/editor/common/editorCommon';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
export const WALK_THROUGH_SCHEME = 'walkThrough';
export class WalkThroughContentProvider implements ITextModelContentProvider, IWorkbenchContribution {
constructor(
@ITextModelResolverService private textModelResolverService: ITextModelResolverService,
@ITextFileService private textFileService: ITextFileService,
@IModeService private modeService: IModeService,
@IModelService private modelService: IModelService,
) {
this.textModelResolverService.registerTextModelContentProvider(WALK_THROUGH_SCHEME, this);
}
public provideTextContent(resource: URI): TPromise<IModel> {
return this.textFileService.resolveTextContent(URI.file(resource.fsPath)).then(content => {
let codeEditorModel = this.modelService.getModel(resource);
if (!codeEditorModel) {
codeEditorModel = this.modelService.createModel(content.value, this.modeService.getOrCreateModeByFilenameOrFirstLine(resource.fsPath), resource);
} else {
codeEditorModel.setValueFromRawText(content.value);
}
return codeEditorModel;
});
}
public getId(): string {
return 'vs.walkThroughContentProvider';
}
}
\ No newline at end of file
......@@ -120,10 +120,13 @@ export class WalkThroughPart extends BaseEditor {
const folder = new TPromise<string>((c, e) => mkdirp(folderName, null, err => err ? e(err) : c(folderName)));
return super.setInput(input, options)
.then(() => this.fileService.resolveContent(input.getResource(), { acceptTextOnly: true }))
.then(content => {
.then(() => {
return input.resolve(true);
})
.then(model => {
const content = model.textEditorModel.getLinesContent().join('\n');
if (strings.endsWith(input.getResource().path, '.html')) {
this.content.innerHTML = content.value;
this.content.innerHTML = content;
this.decorateContent();
if (input.onReady) {
input.onReady(this.content);
......@@ -148,7 +151,7 @@ export class WalkThroughPart extends BaseEditor {
return `<div id=${id} class="walkThroughEditorContainer" ></div>`;
};
this.content.classList.add('walkThroughContent'); // only for markdown files
const markdown = this.expandMacros(content.value);
const markdown = this.expandMacros(content);
this.content.innerHTML = marked(markdown, { renderer });
// TODO: also create jsconfig.json and tsconfig.json
......@@ -209,7 +212,7 @@ export class WalkThroughPart extends BaseEditor {
const keybinding = this.keybindingService.lookupKeybindings(kb)[0];
const shortcut = keybinding ? this.keybindingService.getLabelFor(keybinding) : UNBOUND_COMMAND;
return `<span class="shortcut">${shortcut}</span>`;
})
});
}
private decorateContent() {
......
......@@ -22,6 +22,7 @@ import { IConfigurationEditingService, ConfigurationTarget } from 'vs/workbench/
import { localize } from 'vs/nls';
import { Action } from 'vs/base/common/actions';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { WALK_THROUGH_SCHEME } from 'vs/workbench/parts/walkThrough/electron-browser/walkThroughContentProvider';
const enabledKey = 'workbench.welcome.enabled';
......@@ -83,7 +84,8 @@ class WelcomePage {
private create() {
const recentlyOpened = this.windowService.getRecentlyOpen();
const uri = URI.parse(require.toUrl('./welcomePage.html'));
const uri = URI.parse(require.toUrl('./welcomePage.html'))
.with({ scheme: WALK_THROUGH_SCHEME });
const input = this.instantiationService.createInstance(WalkThroughInput, localize('welcome.title', "Welcome"), '', uri, container => this.onReady(container, recentlyOpened));
this.editorService.openEditor(input, { pinned: true }, Position.ONE)
.then(null, onUnexpectedError);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册