提交 09905893 编写于 作者: M Matt Bierner

Removing the baseWebviewEditor class

This base class is no longer needed now that the html preview has been removed
上级 9061cad5
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Dimension } from 'vs/base/browser/dom';
import { IContextKey, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { WebviewElement } from './webviewElement';
import { IStorageService } from 'vs/platform/storage/common/storage';
/** A context key that is set when the find widget in a webview is visible. */
export const KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE = new RawContextKey<boolean>('webviewFindWidgetVisible', false);
/**
* This class is only intended to be subclassed and not instantiated.
*/
export abstract class BaseWebviewEditor extends BaseEditor {
protected _webview: WebviewElement | undefined;
protected findWidgetVisible: IContextKey<boolean>;
constructor(
id: string,
telemetryService: ITelemetryService,
themeService: IThemeService,
contextKeyService: IContextKeyService,
storageService: IStorageService
) {
super(id, telemetryService, themeService, storageService);
if (contextKeyService) {
this.findWidgetVisible = KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE.bindTo(contextKeyService);
}
}
public showFind() {
if (this._webview) {
this._webview.showFind();
this.findWidgetVisible.set(true);
}
}
public hideFind() {
this.findWidgetVisible.reset();
if (this._webview) {
this._webview.hideFind();
}
}
public get isWebviewEditor() {
return true;
}
public reload() {
this.withWebviewElement(webview => webview.reload());
}
public layout(dimension: Dimension): void {
this.withWebviewElement(webview => webview.layout());
}
public focus(): void {
this.withWebviewElement(webview => webview.focus());
}
public selectAll(): void {
this.withWebviewElement(webview => webview.selectAll());
}
public copy(): void {
this.withWebviewElement(webview => webview.copy());
}
public paste(): void {
this.withWebviewElement(webview => webview.paste());
}
public cut(): void {
this.withWebviewElement(webview => webview.cut());
}
public undo(): void {
this.withWebviewElement(webview => webview.undo());
}
public redo(): void {
this.withWebviewElement(webview => webview.redo());
}
private withWebviewElement(f: (element: WebviewElement) => void): void {
if (this._webview) {
f(this._webview);
}
}
}
......@@ -15,9 +15,8 @@ import { EditorDescriptor, Extensions as EditorExtensions, IEditorRegistry } fro
import { Extensions as ActionExtensions, IWorkbenchActionRegistry } from 'vs/workbench/common/actions';
import { Extensions as EditorInputExtensions, IEditorInputFactoryRegistry } from 'vs/workbench/common/editor';
import { WebviewEditorInputFactory } from 'vs/workbench/contrib/webview/electron-browser/webviewEditorInputFactory';
import { KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE } from './baseWebviewEditor';
import { HideWebViewEditorFindCommand, OpenWebviewDeveloperToolsAction, ReloadWebviewAction, ShowWebViewEditorFindWidgetCommand, SelectAllWebviewEditorCommand, CopyWebviewEditorCommand, PasteWebviewEditorCommand, CutWebviewEditorCommand, UndoWebviewEditorCommand, RedoWebviewEditorCommand } from './webviewCommands';
import { WebviewEditor } from './webviewEditor';
import { WebviewEditor, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE } from './webviewEditor';
import { WebviewEditorInput } from './webviewEditorInput';
import { IWebviewEditorService, WebviewEditorService } from './webviewEditorService';
import { InputFocusedContextKey } from 'vs/platform/contextkey/common/contextkeys';
......
......@@ -8,7 +8,7 @@ import { Command } from 'vs/editor/browser/editorExtensions';
import * as nls from 'vs/nls';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { BaseWebviewEditor } from './baseWebviewEditor';
import { WebviewEditor } from 'vs/workbench/contrib/webview/electron-browser/webviewEditor';
export class ShowWebViewEditorFindWidgetCommand extends Command {
public static readonly ID = 'editor.action.webvieweditor.showFind';
......@@ -143,13 +143,13 @@ export class ReloadWebviewAction extends Action {
private getVisibleWebviews() {
return this.editorService.visibleControls
.filter(control => control && (control as BaseWebviewEditor).isWebviewEditor)
.map(control => control as BaseWebviewEditor);
.filter(control => control && (control as WebviewEditor).isWebviewEditor)
.map(control => control as WebviewEditor);
}
}
function getActiveWebviewEditor(accessor: ServicesAccessor): BaseWebviewEditor | null {
function getActiveWebviewEditor(accessor: ServicesAccessor): WebviewEditor | null {
const editorService = accessor.get(IEditorService);
const activeControl = editorService.activeControl as BaseWebviewEditor;
const activeControl = editorService.activeControl as WebviewEditor;
return activeControl.isWebviewEditor ? activeControl : null;
}
\ No newline at end of file
......@@ -6,24 +6,31 @@
import * as DOM from 'vs/base/browser/dom';
import { CancellationToken } from 'vs/base/common/cancellation';
import { Emitter, Event } from 'vs/base/common/event';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IContextKey, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IWindowService } from 'vs/platform/windows/common/windows';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { EditorOptions } from 'vs/workbench/common/editor';
import { WebviewEditorInput } from 'vs/workbench/contrib/webview/electron-browser/webviewEditorInput';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IPartService, Parts } from 'vs/workbench/services/part/common/partService';
import { BaseWebviewEditor, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE } from './baseWebviewEditor';
import { WebviewElement } from './webviewElement';
import { IWindowService } from 'vs/platform/windows/common/windows';
import { IStorageService } from 'vs/platform/storage/common/storage';
export class WebviewEditor extends BaseWebviewEditor {
/** A context key that is set when the find widget in a webview is visible. */
export const KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE = new RawContextKey<boolean>('webviewFindWidgetVisible', false);
export class WebviewEditor extends BaseEditor {
protected _webview: WebviewElement | undefined;
protected findWidgetVisible: IContextKey<boolean>;
public static readonly ID = 'WebviewEditor';
......@@ -50,7 +57,10 @@ export class WebviewEditor extends BaseWebviewEditor {
@IWindowService private readonly _windowService: IWindowService,
@IStorageService storageService: IStorageService
) {
super(WebviewEditor.ID, telemetryService, themeService, _contextKeyService, storageService);
super(WebviewEditor.ID, telemetryService, themeService, storageService);
if (_contextKeyService) {
this.findWidgetVisible = KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE.bindTo(_contextKeyService);
}
}
protected createEditor(parent: HTMLElement): void {
......@@ -73,27 +83,6 @@ export class WebviewEditor extends BaseWebviewEditor {
}
}
public layout(dimension: DOM.Dimension): void {
if (this._webview) {
this.doUpdateContainer();
}
super.layout(dimension);
}
public focus() {
super.focus();
if (this._onFocusWindowHandler) {
return;
}
// Make sure we restore focus when switching back to a VS Code window
this._onFocusWindowHandler = this._windowService.onDidChangeFocus(focused => {
if (focused && this._editorService.activeControl === this) {
this.focus();
}
});
}
public dispose(): void {
this.pendingMessages = [];
......@@ -122,6 +111,78 @@ export class WebviewEditor extends BaseWebviewEditor {
this.pendingMessages.push(data);
}
}
public showFind() {
if (this._webview) {
this._webview.showFind();
this.findWidgetVisible.set(true);
}
}
public hideFind() {
this.findWidgetVisible.reset();
if (this._webview) {
this._webview.hideFind();
}
}
public get isWebviewEditor() {
return true;
}
public reload() {
this.withWebviewElement(webview => webview.reload());
}
public layout(_dimension: DOM.Dimension): void {
this.withWebviewElement(webview => {
this.doUpdateContainer();
webview.layout();
});
}
public focus(): void {
super.focus();
if (!this._onFocusWindowHandler) {
// Make sure we restore focus when switching back to a VS Code window
this._onFocusWindowHandler = this._windowService.onDidChangeFocus(focused => {
if (focused && this._editorService.activeControl === this) {
this.focus();
}
});
}
this.withWebviewElement(webview => webview.focus());
}
public selectAll(): void {
this.withWebviewElement(webview => webview.selectAll());
}
public copy(): void {
this.withWebviewElement(webview => webview.copy());
}
public paste(): void {
this.withWebviewElement(webview => webview.paste());
}
public cut(): void {
this.withWebviewElement(webview => webview.cut());
}
public undo(): void {
this.withWebviewElement(webview => webview.undo());
}
public redo(): void {
this.withWebviewElement(webview => webview.redo());
}
private withWebviewElement(f: (element: WebviewElement) => void): void {
if (this._webview) {
f(this._webview);
}
}
protected setEditorVisible(visible: boolean, group: IEditorGroup): void {
if (this.input && this.input instanceof WebviewEditorInput) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册