1
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Licensed under the MIT license.
3
3
4
- import { ExtensionContext , TextEditor , TreeView , TreeViewVisibilityChangeEvent , Uri , window } from "vscode" ;
4
+ import { Disposable , ExtensionContext , TextEditor , TreeView , TreeViewVisibilityChangeEvent , Uri , window } from "vscode" ;
5
5
import { Jdtls } from "../java/jdtls" ;
6
6
import { INodeData } from "../java/nodeData" ;
7
7
import { Settings } from "../settings" ;
8
8
import { DataNode } from "./dataNode" ;
9
9
import { DependencyDataProvider } from "./dependencyDataProvider" ;
10
10
import { ExplorerNode } from "./explorerNode" ;
11
11
12
- export class DependencyExplorer {
12
+ export class DependencyExplorer implements Disposable {
13
13
14
14
private _dependencyViewer : TreeView < ExplorerNode > ;
15
15
16
16
private _dataProvider : DependencyDataProvider ;
17
17
18
- private _selectionWhenHidden : DataNode ;
19
-
20
18
constructor ( public readonly context : ExtensionContext ) {
21
19
this . _dataProvider = new DependencyDataProvider ( context ) ;
22
20
this . _dependencyViewer = window . createTreeView ( "javaDependencyExplorer" , { treeDataProvider : this . _dataProvider , showCollapseAll : true } ) ;
23
21
24
- window . onDidChangeActiveTextEditor ( ( textEditor : TextEditor ) => {
25
- if ( textEditor && textEditor . document && Settings . syncWithFolderExplorer ( ) ) {
26
- this . reveal ( textEditor . document . uri ) ;
27
- }
28
- } ) ;
29
-
30
- this . _dependencyViewer . onDidChangeVisibility ( ( e : TreeViewVisibilityChangeEvent ) => {
31
- if ( e . visible && this . _selectionWhenHidden ) {
32
- this . _dependencyViewer . reveal ( this . _selectionWhenHidden ) ;
33
- this . _selectionWhenHidden = undefined ;
34
- }
35
- } ) ;
36
-
37
- this . _dataProvider . onDidChangeTreeData ( ( ) => {
38
- if ( window . activeTextEditor && Settings . syncWithFolderExplorer ( ) ) {
39
- this . reveal ( window . activeTextEditor . document . uri ) ;
40
- }
41
- } ) ;
22
+ context . subscriptions . push (
23
+ window . onDidChangeActiveTextEditor ( ( textEditor : TextEditor ) => {
24
+ if ( this . _dependencyViewer . visible && textEditor && textEditor . document && Settings . syncWithFolderExplorer ( ) ) {
25
+ this . reveal ( textEditor . document . uri ) ;
26
+ }
27
+ } ) ,
28
+ ) ;
29
+
30
+ context . subscriptions . push (
31
+ this . _dependencyViewer . onDidChangeVisibility ( ( e : TreeViewVisibilityChangeEvent ) => {
32
+ if ( e . visible && window . activeTextEditor && Settings . syncWithFolderExplorer ( ) ) {
33
+ this . reveal ( window . activeTextEditor . document . uri ) ;
34
+ }
35
+ } ) ,
36
+ ) ;
37
+
38
+ context . subscriptions . push (
39
+ this . _dataProvider . onDidChangeTreeData ( ( ) => {
40
+ if ( window . activeTextEditor && Settings . syncWithFolderExplorer ( ) ) {
41
+ this . reveal ( window . activeTextEditor . document . uri ) ;
42
+ }
43
+ } ) ,
44
+ ) ;
42
45
}
43
46
44
47
public dispose ( ) : void {
48
+ if ( this . _dependencyViewer ) {
49
+ this . _dependencyViewer . dispose ( ) ;
50
+ }
45
51
}
46
52
47
53
public async reveal ( uri : Uri ) : Promise < void > {
@@ -53,8 +59,6 @@ export class DependencyExplorer {
53
59
54
60
if ( this . _dependencyViewer . visible ) {
55
61
this . _dependencyViewer . reveal ( node ) ;
56
- } else {
57
- this . _selectionWhenHidden = node ;
58
62
}
59
63
}
60
64
}
0 commit comments