import * as vscode from 'vscode' ; import { DevToolsExtensionContext } from "../devToolsExtensionContext" ; import { SymbolsTreeProvider } from "../outlineview/symbolsTreeProvider" ; import { ALSymbolsBasedPageWizard } from '../objectwizards/symbolwizards/alSymbolsBasedPageWizard' ; import { ALSymbolsBasedReportWizard } from '../objectwizards/symbolwizards/alSymbolsBasedReportWizard' ; import { ALSymbolsBasedXmlPortWizard } from '../objectwizards/symbolwizards/alSymbolsBasedXmlPortWizard' ; import { ALSymbolsBasedQueryWizard } from '../objectwizards/symbolwizards/alSymbolsBasedQueryWizard' ; import { AZSymbolInformation } from '../symbollibraries/azSymbolInformation' ; export class ALOutlineService { context : DevToolsExtensionContext ; symbolsTreeProvider : SymbolsTreeProvider ; treeView : vscode . TreeView < AZSymbolInformation > ; protected _selectionChange : boolean ; protected _selectionChangedHandler : vscode . Disposable | undefined ; protected _followCursor : boolean ; constructor ( newContext ) { this . context = newContext ; this . _selectionChange = false ; this . _selectionChangedHandler = undefined ; this . _followCursor = ! ! this . context . vscodeExtensionContext . globalState . get < boolean > ( "azALDevTools.alOutlineFollowCursor" ) ; this . symbolsTreeProvider = new SymbolsTreeProvider ( this . context ) ; this . context . vscodeExtensionContext . subscriptions . push ( vscode . window . registerTreeDataProvider ( 'azALDevTools.SymbolsTreeProvider' , this . symbolsTreeProvider ) ) ; this . treeView = vscode . window . createTreeView < AZSymbolInformation > ( 'azALDevTools.SymbolsTreeProvider' , { treeDataProvider : this . symbolsTreeProvider } ) ; this . registerCommands ( ) ; this . setFollowCursor ( this . _followCursor ) ; } protected registerCommands ( ) { this . context . vscodeExtensionContext . subscriptions . push ( vscode . commands . registerCommand ( 'azALDevTools.alOutlineEnableFollowCursor' , ( ) => this . setFollowCursor ( true ) ) ) ; this . context . vscodeExtensionContext . subscriptions . push ( vscode . commands . registerCommand ( 'azALDevTools.alOutlineDisableFollowCursor' , ( ) => this . setFollowCursor ( false ) ) ) ; this . context . vscodeExtensionContext . subscriptions . push ( vscode . commands . registerCommand ( 'azALDevTools.refreshOutlineView' , ( ) => this . symbolsTreeProvider . refresh ( ) ) ) ; this . context . vscodeExtensionContext . subscriptions . push ( vscode . commands . registerCommand ( 'alOutline.createCardPage' , offset => { let builder = new ALSymbolsBasedPageWizard ( this . context ) ; builder . showPageWizard ( offset , 'Card' ) ; } ) ) ; this . context . vscodeExtensionContext . subscriptions . push ( vscode . commands . registerCommand ( 'alOutline.createListPage' , offset => { let builder = new ALSymbolsBasedPageWizard ( this . context ) ; builder . showPageWizard ( offset , 'List' ) ; } ) ) ; this . context . vscodeExtensionContext . subscriptions . push ( vscode . commands . registerCommand ( 'alOutline.createReport' , offset => { let builder = new ALSymbolsBasedReportWizard ( this . context ) ; builder . showReportWizard ( offset ) ; } ) ) ; this . context . vscodeExtensionContext . subscriptions . push ( vscode . commands . registerCommand ( 'alOutline.createXmlPort' , offset => { let builder = new ALSymbolsBasedXmlPortWizard ( this . context ) ; builder . showXmlPortWizard ( offset ) ; } ) ) ; this . context . vscodeExtensionContext . subscriptions . push ( vscode . commands . registerCommand ( 'alOutline.createQuery' , offset => { let builder = new ALSymbolsBasedQueryWizard ( this . context ) ; builder . showQueryWizard ( offset ) ; } ) ) ; this . context . vscodeExtensionContext . subscriptions . push ( vscode . commands . registerCommand ( 'alOutline.runPage' , offset => { this . context . objectRunner . runSymbolAsync ( offset ) ; } ) ) ; this . context . vscodeExtensionContext . subscriptions . push ( vscode . commands . registerCommand ( 'alOutline.runTable' , offset => { this . context . objectRunner . runSymbolAsync ( offset ) ; } ) ) ; this . context . vscodeExtensionContext . subscriptions . push ( vscode . commands . registerCommand ( 'alOutline.runReport' , offset => { this . context . objectRunner . runSymbolAsync ( offset ) ; } ) ) ; this . context . vscodeExtensionContext . subscriptions . push ( vscode . commands . registerCommand ( 'azALDevTools.selectDocumentText' , ( range ) => { if ( ( ! this . _selectionChange ) && ( vscode . window . activeTextEditor ) ) { let vscodeRange = new vscode . Range ( range . start . line , range . start . character , range . end . line , range . end . character ) ; vscode . window . activeTextEditor . revealRange ( vscodeRange , vscode . TextEditorRevealType . Default ) ; vscode . window . activeTextEditor . selection = new vscode . Selection ( vscodeRange . start , vscodeRange . end ) ; vscode . commands . executeCommand ( 'workbench.action.focusActiveEditorGroup' ) ; } } ) ) ; } setFollowCursor ( value ) { this . _followCursor = value ; if ( ( this . _followCursor ) && ( ! this . _selectionChangedHandler ) ) { this . _selectionChangedHandler = vscode . window . onDidChangeTextEditorSelection ( ( e ) => { this . onTextEditorSelectionChanged ( e ) ; } ) ; } else if ( ( ! this . _followCursor ) && ( this . _selectionChangedHandler ) ) { this . _selectionChangedHandler . dispose ( ) ; this . _selectionChangedHandler = undefined ; } vscode . commands . executeCommand ( 'setContext' , 'azALDevTools:alOutlineFollowCursor' , this . _followCursor ) ; this . context . vscodeExtensionContext . globalState . update ( "azALDevTools.alOutlineFollowCursor" , this . _followCursor ) ; } private async onTextEditorSelectionChanged ( e ) { if ( ( this . treeView . visible ) && ( e . selections . length > 0 ) ) { let symbol = this . symbolsTreeProvider . getSymbolAtPosition ( e . selections [ 0 ] . active ) ; if ( symbol ) { this . _selectionChange = true ; await this . treeView . reveal ( symbol , { select : true , focus : false , expand : false } ) ; this . _selectionChange = false ; } } } }