import * as vscode from 'vscode' ; import { Utility } from '../misc/utility' ; /**
 * A Webview that serves as base class for other views like the MemoryDumpView or the
 * ZxNextSpritesView.
 */ export class BaseView { public static staticViewClasses : Array < any > ; protected static staticViews : Array < BaseView > ; /**
     * Initializes the static variables.
     * Called at launchRequest.
     */ public static staticInit ( ) { BaseView . staticViewClasses = new Array < any > ( ) ; BaseView . staticViews = new Array < BaseView > ( ) ; } /**
     * Is called when a register was changed manually.
     * Used to update the register colors in the memory views.
     */ public static async staticCallUpdateRegisterChanged ( ) { for ( const view of BaseView . staticViews ) { await view . updateRegisterChanged ( ) ; } } param reason public static async staticCallUpdateFunctions ( reason ? ) { for ( const viewClass of BaseView . staticViewClasses ) { await viewClass . staticUpdate ( reason ) ; } for ( const view of BaseView . staticViews ) { await view . update ( reason ) ; } } /**
     * Updates all views but without getting values from the
     * Remote.
     */ protected static staticCallUpdateWithoutRemote ( ) { for ( const view of BaseView . staticViews ) { view . updateWithoutRemote ( ) ; } } /**
     * Closes all opened views.
     * Is called when the debugger closes.
     */ public static staticCloseAll ( ) { const views = BaseView . staticViews . map ( view => view ) ; for ( const view of views ) { view . vscodePanel . dispose ( ) ; view . vscodePanel = undefined as any ; } BaseView . staticViews . length = 0 ; } param viewClass return public static staticGetAllViews ( viewClass ) { const views = BaseView . staticViews . filter ( view => view instanceof viewClass ) ; return views ; } /**
     * Calls the registers function (debug adapter) to inform about
     * a change. I.e. the user changed a memory value.
     * The DebugAdapter/vscode uses this to update e.g. the WATCHes.
     */ public static sendChangeEvent = ( ) => { } ; param func public static onChange ( func ) { this . sendChangeEvent = func ; } protected vscodePanel : vscode . WebviewPanel ; param addToStaticViews constructor ( addToStaticViews = true ) { if ( addToStaticViews ) BaseView . staticViews . push ( this ) ; this . vscodePanel = vscode . window . createWebviewPanel ( '' , '' , { preserveFocus : true , viewColumn : vscode . ViewColumn . Nine } , { enableScripts : true , enableFindWidget : true , retainContextWhenHidden : true } ) ; this . vscodePanel . webview . onDidReceiveMessage ( async ( message ) => { await this . webViewMessageReceived ( message ) ; } ) ; this . vscodePanel . onDidDispose ( ( ) => { this . disposeView ( ) ; } ) ; } /**
     * Dispose the view (called e.g. on close).
     * Use this to clean up additional stuff.
     * Normally not required.
     */ public disposeView ( ) { const index = BaseView . staticViews . indexOf ( this ) ; if ( index >= 0 ) { BaseView . staticViews . splice ( index , 1 ) ; } this . vscodePanel = undefined as any ; } param message protected async webViewMessageReceived ( message ) { Utility . assert ( false ) ; } param message param baseView protected sendMessageToWebView ( message , baseView = this ) { baseView . vscodePanel . webview . postMessage ( message ) ; } /**
     * View is informed that a register has changed (manually).
     */ public async updateRegisterChanged ( ) { } param reason public async update ( reason ? ) { } /**
     * Updates the html. E.g. after the change of a value.
     * Without getting the memory from the Remote.
     */ protected updateWithoutRemote ( ) { } /**
     * Put webview to the foreground.
     */ public reveal ( ) { this . vscodePanel . reveal ( ) ; } }