Added reload webviews command

Fixes #44068
This commit is contained in:
Matt Bierner 2018-02-20 15:35:53 -08:00
parent e05609d5ec
commit 58a169f3f5
4 changed files with 48 additions and 3 deletions

View file

@ -12,10 +12,12 @@ import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/wor
import { KEYBINDING_CONTEXT_WEBVIEWEDITOR_FIND_WIDGET_INPUT_FOCUSED, KEYBINDING_CONTEXT_WEBVIEWEDITOR_FOCUS, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE } from './webviewEditor';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { Registry } from 'vs/platform/registry/common/platform';
import { ShowWebViewEditorFindWidgetAction, ShowWebViewEditorFindTermCommand, HideWebViewEditorFindCommand, OpenWebviewDeveloperToolsAction } from './webviewCommands';
import { ShowWebViewEditorFindWidgetAction, ShowWebViewEditorFindTermCommand, HideWebViewEditorFindCommand, OpenWebviewDeveloperToolsAction, ReloadWebviewAction } from './webviewCommands';
const category = 'Webview';
const webviewDeveloperCategory = nls.localize('developer', "Developer");
const actionRegistry = <IWorkbenchActionRegistry>Registry.as(ActionExtensions.WorkbenchActions);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ShowWebViewEditorFindWidgetAction, ShowWebViewEditorFindWidgetAction.ID, ShowWebViewEditorFindWidgetAction.LABEL, {
@ -58,4 +60,9 @@ KeybindingsRegistry.registerCommandAndKeybindingRule(hideCommand.toCommandAndKey
actionRegistry.registerWorkbenchAction(
new SyncActionDescriptor(OpenWebviewDeveloperToolsAction, OpenWebviewDeveloperToolsAction.ID, OpenWebviewDeveloperToolsAction.LABEL),
'Webview Tools',
nls.localize('developer', "Developer"));
webviewDeveloperCategory);
actionRegistry.registerWorkbenchAction(
new SyncActionDescriptor(ReloadWebviewAction, ReloadWebviewAction.ID, ReloadWebviewAction.LABEL),
'Reload Webview',
webviewDeveloperCategory);

View file

@ -33,6 +33,7 @@ export class Webview {
private _webviewFindWidget: WebviewFindWidget;
private _findStarted: boolean = false;
private _contents: string = '';
constructor(
private readonly parent: HTMLElement,
@ -84,7 +85,6 @@ export class Webview {
const contents = this._webview.getWebContents();
this.registerFileProtocols(contents);
}));
}
@ -245,6 +245,7 @@ export class Webview {
}
set contents(value: string) {
this._contents = value;
this._send('content', {
contents: value,
options: this._options
@ -406,6 +407,10 @@ export class Webview {
public showPreviousFindTerm() {
this._webviewFindWidget.showPreviousFindTerm();
}
public reload() {
this.contents = this._contents;
}
}

View file

@ -106,4 +106,31 @@ export class OpenWebviewDeveloperToolsAction extends Action {
}
return null;
}
}
export class ReloadWebviewAction extends Action {
static readonly ID = 'workbench.action.webview.reloadWebviewAction';
static LABEL = nls.localize('refreshWebviewLabel', "Reload Webviews");
public constructor(
id: string,
label: string,
@IWorkbenchEditorService private readonly workbenchEditorService: IWorkbenchEditorService
) {
super(id, label);
}
public run(): TPromise<any> {
for (const webview of this.getVisibleWebviews()) {
webview.reload();
}
return null;
}
private getVisibleWebviews() {
return this.workbenchEditorService.getVisibleEditors()
.filter(c => c && (c as any).isWebviewEditor)
.map(e => e as WebviewEditor);
}
}

View file

@ -84,6 +84,12 @@ export abstract class WebviewEditor extends BaseWebviewEditor {
return true;
}
public reload() {
if (this._webview) {
this._webview.reload();
}
}
protected abstract createEditor(parent: Builder): void;
}