/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IThemeService } from 'vs/platform/theme/common/themeService'; import { BaseWebviewEditor } from 'vs/workbench/browser/parts/editor/webviewEditor'; import { IStorageService } from 'vs/platform/storage/common/storage'; import { IContextKey, RawContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { Webview } from './webview'; import { Builder } from 'vs/base/browser/builder'; import { Dimension } from 'vs/workbench/services/part/common/partService'; /** A context key that is set when a webview editor has focus. */ export const KEYBINDING_CONTEXT_WEBVIEWEDITOR_FOCUS = new RawContextKey('webviewEditorFocus', false); /** A context key that is set when the find widget find input in webview editor webview is focused. */ export const KEYBINDING_CONTEXT_WEBVIEWEDITOR_FIND_WIDGET_INPUT_FOCUSED = new RawContextKey('webviewEditorFindWidgetInputFocused', false); /** 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('webviewFindWidgetVisible', false); /** * This class is only intended to be subclassed and not instantiated. */ export abstract class WebviewEditor extends BaseWebviewEditor { protected _webviewFocusContextKey: IContextKey; protected _webview: Webview; protected content: HTMLElement; protected contextKey: IContextKey; protected findWidgetVisible: IContextKey; protected findInputFocusContextKey: IContextKey; constructor( id: string, telemetryService: ITelemetryService, themeService: IThemeService, storageService: IStorageService, contextKeyService: IContextKeyService, ) { super(id, telemetryService, themeService, storageService); if (contextKeyService) { this.contextKey = KEYBINDING_CONTEXT_WEBVIEWEDITOR_FOCUS.bindTo(contextKeyService); this.findInputFocusContextKey = KEYBINDING_CONTEXT_WEBVIEWEDITOR_FIND_WIDGET_INPUT_FOCUSED.bindTo(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 showNextFindTerm() { if (this._webview) { this._webview.showNextFindTerm(); } } public showPreviousFindTerm() { if (this._webview) { this._webview.showPreviousFindTerm(); } } public get isWebviewEditor() { return true; } public reload() { if (this._webview) { this._webview.reload(); } } public layout(dimension: Dimension): void { if (this._webview) { this._webview.layout(); } } public focus(): void { if (this._webview) { this._webview.focus(); } } protected abstract createEditor(parent: Builder): void; }