44 *--------------------------------------------------------------------------------------------*/
55
66import * as vscode from 'vscode' ;
7+ import { CallsDirection , CallsModel } from './model' ;
78import { DataProvider } from './provider' ;
8- import { CallsModel , CallsDirection } from './model' ;
99
1010export function register ( disposables : vscode . Disposable [ ] ) {
1111
1212 const viewId = 'calls-view.tree' ;
1313 const provider = new DataProvider ( ) ;
1414
15- const view = vscode . window . createTreeView ( viewId , {
16- treeDataProvider : provider ,
17- showCollapseAll : true
18- } ) ;
19-
15+ const view = vscode . window . createTreeView ( viewId , { treeDataProvider : provider } ) ;
2016
2117 let callsDirection = CallsDirection . Outgoing ;
2218 vscode . commands . executeCommand ( 'setContext' , 'calls-view.mode' , 'showOutgoing' ) ;
2319
24- const setDirectionToOutgoing = ( ) => {
25- if ( callsDirection !== CallsDirection . Outgoing ) {
26- callsDirection = CallsDirection . Outgoing ;
27- vscode . commands . executeCommand ( 'setContext' , 'calls-view.mode' , 'showOutgoing' ) ;
28- refresh ( ) ;
29- }
30- }
31-
32- const setDirectionToIncoming = ( ) => {
33- if ( callsDirection !== CallsDirection . Incoming ) {
34- callsDirection = CallsDirection . Incoming ;
35- vscode . commands . executeCommand ( 'setContext' , 'calls-view.mode' , 'showIncoming' ) ;
36- refresh ( ) ;
37- }
38- }
39-
40- const refresh = ( ) => {
41- const { model } = provider ;
42- if ( model ) {
43- updateModel ( model . changeDirection ( ) ) ;
44- } else {
45- showCallHierarchy ( ) ;
20+ const setModeCommand = ( direction : CallsDirection ) => {
21+ if ( callsDirection !== direction ) {
22+ callsDirection = direction ;
23+ vscode . commands . executeCommand ( 'setContext' , 'calls-view.mode' , direction === CallsDirection . Incoming ? 'showIncoming' : 'showOutgoing' ) ;
24+ if ( provider . model ) {
25+ updateModel ( provider . model . changeDirection ( ) ) ;
26+ } else {
27+ showCommand ( ) ;
28+ }
4629 }
4730 }
4831
4932 const updateModel = async ( model : CallsModel | undefined ) => {
5033
5134 vscode . commands . executeCommand ( 'setContext' , 'calls-view.hasResults' , Boolean ( model ) ) ;
52-
35+ view . message = '' ;
5336 provider . model = model ;
5437 updateTitle ( ) ;
5538 if ( model ) {
@@ -61,17 +44,17 @@ export function register(disposables: vscode.Disposable[]) {
6144 const updateTitle = ( ) => {
6245 if ( provider . model ) {
6346 if ( provider . model . direction === CallsDirection . Outgoing ) {
64- view . title = `Calls From ` ;
47+ view . title = `Call Hierarchy - Calls ` ;
6548 } else {
66- view . title = `Callers Of ` ;
49+ view . title = `Call Hierarchy - Callers ` ;
6750 }
6851
6952 } else {
70- view . title = 'Calls '
53+ view . title = 'Call Hierarchy '
7154 }
7255 }
7356
74- const showCallHierarchy = async ( uri ?: vscode . Uri , position ?: vscode . Position ) => {
57+ const showCommand = async ( uri ?: vscode . Uri , position ?: vscode . Position ) => {
7558 let model : CallsModel | undefined ;
7659 if ( uri instanceof vscode . Uri && position instanceof vscode . Position ) {
7760 model = new CallsModel ( uri , position , callsDirection ) ;
@@ -83,11 +66,16 @@ export function register(disposables: vscode.Disposable[]) {
8366 updateModel ( model ) ;
8467 }
8568
69+ const clearCommand = ( ) => {
70+ updateModel ( undefined ) ;
71+ view . message = `To populate this view, open an editor and run the 'Show Call Hierarchy'-command.` ;
72+ } ;
73+
8674 disposables . push (
8775 view ,
88- vscode . commands . registerCommand ( 'calls-view.show' , showCallHierarchy ) ,
89- vscode . commands . registerCommand ( 'calls-view.show.outgoing' , setDirectionToOutgoing ) ,
90- vscode . commands . registerCommand ( 'calls-view.show.incoming' , setDirectionToIncoming ) ,
91- vscode . commands . registerCommand ( 'calls-view.clear' , ( ) => updateModel ( undefined ) )
76+ vscode . commands . registerCommand ( 'calls-view.show' , showCommand ) ,
77+ vscode . commands . registerCommand ( 'calls-view.show.outgoing' , ( ) => setModeCommand ( CallsDirection . Outgoing ) ) ,
78+ vscode . commands . registerCommand ( 'calls-view.show.incoming' , ( ) => setModeCommand ( CallsDirection . Incoming ) ) ,
79+ vscode . commands . registerCommand ( 'calls-view.clear' , clearCommand )
9280 ) ;
9381}
0 commit comments