import * as vscode from 'vscode' ; import { DevToolsExtensionContext } from '../../devToolsExtensionContext' ; import { ALSyntaxWriter } from '../../allanguage/alSyntaxWriter' ; import { AZSymbolKind } from '../../symbollibraries/azSymbolKind' ; import { AZSymbolInformation } from '../../symbollibraries/azSymbolInformation' ; import { ALBaseAddFieldsCodeCommand } from './alBaseAddFieldsCodeCommand' ; import { AZDocumentSymbolsLibrary } from '../../symbollibraries/azDocumentSymbolsLibrary' ; import { ToolsGetPageDetailsRequest } from '../../langserver/symbolsinformation/toolsGetPageDetailsRequest' ; import { TableFieldInformation } from '../../symbolsinformation/tableFieldInformation' ; import { TableFieldsSelector } from './tableFieldsSelector' ; export class ALAddPageFieldsCodeCommand extends ALBaseAddFieldsCodeCommand { constructor ( context ) { super ( context , 'AddPageFields' , 'AZDevTools.ALAddPageFieldsCodeCommand' ) ; } collectCodeActions ( docSymbols , symbol , document , range , diagnostics , actions ) { if ( ( symbol ) && ( ( symbol . kind == AZSymbolKind . PageGroup ) || ( symbol . kind == AZSymbolKind . PageRepeater ) || ( symbol . kind == AZSymbolKind . PageArea ) || ( symbol . kind == AZSymbolKind . ControlAddChange ) || ( symbol . kind == AZSymbolKind . PageField ) || ( symbol . kind == AZSymbolKind . PageUserControl ) ) ) { let action = new vscode . CodeAction ( "Add multiple fields (AZ AL Dev Tools)" , vscode . CodeActionKind . QuickFix ) ; action . command = { command : this . name , title : 'Add multiple fields...' , arguments : [ docSymbols , document , range ] } ; actions . push ( action ) ; } } protected async runAsync ( docSymbols , document , range ) { let symbol = this . _toolsExtensionContext . activeDocumentSymbols . findSymbolInRange ( range ) ; if ( ! symbol ) return ; let config = vscode . workspace . getConfiguration ( 'alOutline' , document . uri ) ; let parentKind = [ AZSymbolKind . PageObject , AZSymbolKind . PageExtensionObject ] ; let pageSymbol = symbol . findParentByKindList ( parentKind ) ; let isFieldSymbol = ( ( symbol . kind == AZSymbolKind . PageField ) || ( symbol . kind == AZSymbolKind . PageUserControl ) ) ; let addToolTips = ! ! config . get < boolean > ( 'addToolTipsToPageFields' ) ; let useTableFieldCaptionsInApi = ! ! config . get < boolean > ( 'useTableFieldCaptionsInApiFields' ) ; let reuseToolTips = ! config . get < boolean > ( 'doNotReuseToolTipsFromOtherPages' ) ; let toolTipsSource = config . get < string [ ] > ( 'reuseToolTipsFromDependencies' ) ; if ( ( ! pageSymbol ) || ( ( ! isFieldSymbol ) && ( ! symbol . contentRange ) ) || ( ( isFieldSymbol ) && ( ! symbol . range ) ) || ( ( ! pageSymbol . source ) && ( ! pageSymbol . extends ) ) ) return ; let isApiPage = ( ( ! ! pageSymbol . subtype ) && ( pageSymbol . subtype . toLowerCase ( ) == 'api' ) ) ; let pageName = ( pageSymbol . kind == AZSymbolKind . PageExtensionObject ) ? pageSymbol . extends : pageSymbol . name ; if ( ! pageName ) return ; let response = await this . _toolsExtensionContext . toolsLangServerClient . getPageDetails ( new ToolsGetPageDetailsRequest ( document . uri . fsPath , pageName , false , true , reuseToolTips , toolTipsSource ) ) ; if ( ( ! response ) || ( ! response . symbol ) || ( ! response . symbol . availableTableFields ) ) return ; let fieldNames = response . symbol . availableTableFields ; let fieldsSelector = new TableFieldsSelector ( this . _toolsExtensionContext ) ; let selectedFields = await fieldsSelector . selectFields ( 'Select table fields' , fieldNames ) ; if ( ! selectedFields ) return ; let indent = 0 ; let fieldsContainer = symbol ; if ( isFieldSymbol ) fieldsContainer = symbol . parent ; if ( ( fieldsContainer ) && ( fieldsContainer . contentRange ) ) indent = fieldsContainer . contentRange . start . character + 3 ; else if ( symbol . range ) indent = symbol . range . start . character + 3 ; let writer = new ALSyntaxWriter ( document . uri ) ; writer . setIndent ( indent ) ; for ( let i = 0 ; i < selectedFields . length ; i ++ ) { if ( isApiPage ) writer . writeApiPageField ( selectedFields [ i ] . name ! , selectedFields [ i ] . caption , selectedFields [ i ] . captionLabel ?. comment , useTableFieldCaptionsInApi ) ; else writer . writePageField ( selectedFields [ i ] . name ! , selectedFields [ i ] . caption , selectedFields [ i ] . captionLabel ?. comment , selectedFields [ i ] . description , addToolTips , selectedFields [ i ] . toolTips ) ; } let source = writer . toString ( ) ; await this . insertSymbolContentAsync ( symbol , source ) ; } }