Reduce usage of postCommand in markdown preview

This commit is contained in:
Matt Bierner 2018-09-21 13:23:48 -07:00
parent 47ec1a664e
commit 7185906189
9 changed files with 15 additions and 29 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -57,7 +57,7 @@ export class CspAlerter {
notification.setAttribute('role', 'button');
notification.setAttribute('aria-label', strings.cspAlertMessageLabel);
notification.onclick = () => {
this.messaging!.postCommand('markdown.showPreviewSecuritySelector', [settings.source]);
this.messaging!.postMessage('markdown.showPreviewSecuritySelector', [settings.source]);
};
document.body.appendChild(notification);
}

View file

@ -30,7 +30,7 @@ export class StyleLoadingMonitor {
}
this.finishedLoading = true;
if (this.poster) {
this.poster.postCommand('_markdown.onPreviewStyleLoadError', [this.unloadedStyles]);
this.poster.postMessage('previewStyleLoadError', { unloadedStyles: this.unloadedStyles });
}
});
}
@ -38,7 +38,7 @@ export class StyleLoadingMonitor {
public setPoster(poster: MessagePoster): void {
this.poster = poster;
if (this.finishedLoading) {
poster.postCommand('_markdown.onPreviewStyleLoadError', [this.unloadedStyles]);
poster.postMessage('previewStyleLoadError', { unloadedStyles: this.unloadedStyles });
}
}
}

View file

@ -11,7 +11,6 @@ export interface MessagePoster {
*/
postMessage(type: string, body: object): void;
/**
* Post a command to be executed to the markdown extension
*/

View file

@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
export { OpenDocumentLinkCommand } from './openDocumentLink';
export { OnPreviewStyleLoadErrorCommand } from './onPreviewStyleLoadError';
export { ShowPreviewCommand, ShowPreviewToSideCommand, ShowLockedPreviewToSideCommand } from './showPreview';
export { ShowSourceCommand } from './showSource';
export { RefreshPreviewCommand } from './refreshPreview';

View file

@ -1,18 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
import * as vscode from 'vscode';
import { Command } from '../commandManager';
export class OnPreviewStyleLoadErrorCommand implements Command {
public readonly id = '_markdown.onPreviewStyleLoadError';
public execute(resources: string[]) {
vscode.window.showWarningMessage(localize('onPreviewStyleLoadError', "Could not load 'markdown.styles': {0}", resources.join(', ')));
}
}

View file

@ -56,7 +56,6 @@ export function activate(context: vscode.ExtensionContext) {
commandManager.register(new commands.RefreshPreviewCommand(previewManager));
commandManager.register(new commands.MoveCursorToPositionCommand());
commandManager.register(new commands.ShowPreviewSecuritySelectorCommand(previewSecuritySelector, previewManager));
commandManager.register(new commands.OnPreviewStyleLoadErrorCommand());
commandManager.register(new commands.OpenDocumentLinkCommand(engine));
commandManager.register(new commands.ToggleLockCommand(previewManager));

View file

@ -140,6 +140,13 @@ export class MarkdownPreview {
this.onDidClickPreview(e.body.line);
break;
case 'showPreviewSecuritySelector':
vscode.commands.executeCommand('markdown.showPreviewSecuritySelector', e.body.source);
break;
case 'previewStyleLoadError':
vscode.window.showWarningMessage(localize('onPreviewStyleLoadError', "Could not load 'markdown.styles': {0}", e.body.unloadedStyles.join(', ')));
break;
}
}, null, this.disposables);