'use strict' ; import * as vscode from 'vscode' ; import { ExtensionUtil } from '../util/ExtensionUtil' ; import { ExtensionCommands } from '../../ExtensionCommands' ; export class TemporaryCommandRegistry { public static instance ( ) { return this . _instance ; } private static _instance : TemporaryCommandRegistry = new TemporaryCommandRegistry ( ) ; private delayedCommandsToExecute : Set < string > ; private tempCommands : vscode . Disposable [ ] ; private delayExecution : boolean ; private alternativeCommand : string ; private constructor ( ) { } public createTempCommands ( delayExecution , alternativeCommand ? ) { const commands = ExtensionUtil . getPackageJSON ( ) . actualActivationEvents . onCommand ; this . tempCommands = [ ] ; this . delayedCommandsToExecute = new Set < string > ( ) ; this . delayExecution = delayExecution ; this . alternativeCommand = alternativeCommand ; commands . forEach ( ( command ) => { this . registerTempCommand ( command ) ; } ) ; } public restoreCommands ( ) { this . tempCommands . forEach ( ( command ) => { command . dispose ( ) ; } ) ; this . tempCommands = [ ] ; } public async executeStoredCommands ( ) { for ( const command of this . delayedCommandsToExecute ) { await vscode . commands . executeCommand ( command ) ; } this . delayedCommandsToExecute . clear ( ) ; } private registerTempCommand ( command ) { if ( command !== ExtensionCommands . OPEN_PRE_REQ_PAGE && command !== ExtensionCommands . OPEN_RELEASE_NOTES && command !== ExtensionCommands . DELETE_ENVIRONMENT && command !== ExtensionCommands . TEARDOWN_FABRIC ) { const disposableCommand = vscode . commands . registerCommand ( command , async ( ) => { if ( this . delayExecution ) { this . delayedCommandsToExecute . add ( command ) ; } else { await vscode . commands . executeCommand ( this . alternativeCommand ) ; } } ) ; this . tempCommands . push ( disposableCommand ) ; } } }