'use strict' ; import * as util from '../common' ; import * as vscode from 'vscode' ; import * as path from 'path' ; class PersistentStateBase < T > { private key : string ; private defaultvalue : T ; private state ? : vscode . Memento ; private curvalue : T ; constructor ( key , defaultValue , state ? ) { this . key = key ; this . defaultvalue = defaultValue ; this . state = state ; this . curvalue = defaultValue ; } public get Value ( ) : T { return this . state ? this . state . get < T > ( this . key , this . defaultvalue ) : this . curvalue ; } public set Value ( newValue ) { if ( this . state ) { this . state . update ( this . key , newValue ) ; } this . curvalue = newValue ; } public get DefaultValue ( ) : T { return this . defaultvalue ; } public setDefault ( ) { if ( this . state ) { this . state . update ( this . key , this . defaultvalue ) ; } this . curvalue = this . defaultvalue ; } } export class PersistentState < T > extends PersistentStateBase < T > { constructor ( key , defaultValue ) { super ( key , defaultValue , util . extensionContext ? util . extensionContext . globalState : undefined ) ; } } export class PersistentWorkspaceState < T > extends PersistentStateBase < T > { constructor ( key , defaultValue ) { super ( key , defaultValue , util . extensionContext ? util . extensionContext . workspaceState : undefined ) ; } } export class PersistentFolderState < T > extends PersistentWorkspaceState < T > { constructor ( key , defaultValue , folder ) { const old_key = key + ( folder ? `-${ path . basename ( folder . uri . fsPath ) }` : "-untitled" ) ; let old_val ; if ( util . extensionContext ) { old_val = util . extensionContext . workspaceState . get ( old_key ) ; if ( old_val !== undefined ) { util . extensionContext . workspaceState . update ( old_key , undefined ) ; } } const newKey = key + ( folder ? `-${ folder . uri . fsPath }` : "-untitled" ) ; super ( newKey , defaultValue ) ; if ( old_val !== undefined ) { this . Value = old_val ; } } }