import * as vscode from 'vscode' ; import { FileBuilder } from '../fileBuilder' ; import { AZSymbolKind } from '../../symbollibraries/azSymbolKind' ; import { DevToolsExtensionContext } from '../../devToolsExtensionContext' ; export class ALSymbolsBasedWizard { protected _toolsExtensionContext : DevToolsExtensionContext ; constructor ( context ) { this . _toolsExtensionContext = context ; } protected async showNewDocument ( content , fileName ? , relativeFileDir ? ) { let autoGenerateFile = this . shouldAutoGenerateFiles ( ) ; if ( autoGenerateFile && fileName ) { this . showNewGeneratedFile ( content , fileName , relativeFileDir ) ; } else { FileBuilder . showNewUntitledDocument ( content ) ; } } private async showNewGeneratedFile ( content , fileName , relativeFileDir ) { let autoShowDocument = vscode . workspace . getConfiguration ( 'alOutline' ) . get < boolean > ( 'autoShowFiles' ) ; let filePath = await FileBuilder . generateObjectFileInRelativeDir ( content , fileName , relativeFileDir ) ; if ( ( filePath ) && ( autoShowDocument ) ) FileBuilder . showFile ( filePath ) ; } protected async getObjectId ( destPath , objectType , promptText , defaultObjectId ) { let uri ; let objectId = await this . _toolsExtensionContext . toolsLangServerClient . getNextObjectId ( destPath , objectType ) ; if ( objectId == 0 ) objectId = defaultObjectId ; if ( this . shouldPromptForObjectId ( ) ) { let objectIdString = await this . promptForObjectId ( promptText , objectId . toString ( ) ) ; if ( ! objectIdString ) return - 1 ; objectId = Number ( objectIdString ) ; if ( isNaN ( objectId ) ) return - 1 ; } return objectId ; } protected async getObjectName ( promptText , defaultObjectName ) { let objectName = defaultObjectName ; if ( this . shouldPromptForObjectName ( ) ) objectName = await this . promptForObjectName ( promptText , objectName ) ; if ( ! objectName ) return objectName ; if ( this . shouldStripCharacters ( ) ) objectName = FileBuilder . stripNonAlphaNumericCharacters ( objectName ) ; return objectName ; } protected async getRelativeFileDir ( objectType ) { let relativeFileDir = await FileBuilder . getPatternGeneratedRelativeFilePath ( objectType ) ; if ( this . shouldPromptForFileDir ( ) && this . shouldAutoGenerateFiles ( ) ) { relativeFileDir = await this . promptForFileDir ( 'Please specify a directory, relative to the root, to create the new file(s) in.' , relativeFileDir ) ; } return relativeFileDir ; } private promptForObjectId ( promptText , defaultObjectId ) { return vscode . window . showInputBox ( { value : defaultObjectId , prompt : promptText , validateInput : ( text ) : string | undefined => { let objectId = Number ( text ) ; if ( isNaN ( objectId ) ) { return 'Only numbers are allowed for object IDs.' ; } else { return undefined ; } } } ) ; } private promptForObjectName ( promptText , defaultObjectName ) { return vscode . window . showInputBox ( { value : defaultObjectName , prompt : promptText } ) ; } private promptForFileDir ( promptText , defaultFilePath ) { return vscode . window . showInputBox ( { value : defaultFilePath , prompt : promptText , ignoreFocusOut : true } ) ; } private getBoolSetting ( name ) { if ( vscode . workspace . getConfiguration ( 'alOutline' ) . get < boolean > ( name ) ) return true ; return false ; } private shouldPromptForObjectId ( ) { return this . getBoolSetting ( 'promptForObjectId' ) ; } private shouldPromptForObjectName ( ) { return this . getBoolSetting ( 'promptForObjectName' ) ; } private shouldPromptForFileDir ( ) { return this . getBoolSetting ( 'promptForFilePath' ) ; } private shouldStripCharacters ( ) { return this . getBoolSetting ( 'stripNonAlphanumericCharactersFromObjectNames' ) ; } protected shouldAutoGenerateFiles ( ) { return this . getBoolSetting ( 'autoGenerateFiles' ) ; } }