11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT license.
33
4- import { ExtensionContext , TextEditor , TreeView , TreeViewVisibilityChangeEvent , Uri , window } from "vscode" ;
4+ import { Disposable , ExtensionContext , TextEditor , TreeView , TreeViewVisibilityChangeEvent , Uri , window } from "vscode" ;
55import { Jdtls } from "../java/jdtls" ;
66import { INodeData } from "../java/nodeData" ;
77import { Settings } from "../settings" ;
88import { DataNode } from "./dataNode" ;
99import { DependencyDataProvider } from "./dependencyDataProvider" ;
1010import { ExplorerNode } from "./explorerNode" ;
1111
12- export class DependencyExplorer {
12+ export class DependencyExplorer implements Disposable {
1313
1414 private _dependencyViewer : TreeView < ExplorerNode > ;
1515
1616 private _dataProvider : DependencyDataProvider ;
1717
18- private _selectionWhenHidden : DataNode ;
19-
2018 constructor ( public readonly context : ExtensionContext ) {
2119 this . _dataProvider = new DependencyDataProvider ( context ) ;
2220 this . _dependencyViewer = window . createTreeView ( "javaDependencyExplorer" , { treeDataProvider : this . _dataProvider , showCollapseAll : true } ) ;
2321
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+ ) ;
4245 }
4346
4447 public dispose ( ) : void {
48+ if ( this . _dependencyViewer ) {
49+ this . _dependencyViewer . dispose ( ) ;
50+ }
4551 }
4652
4753 public async reveal ( uri : Uri ) : Promise < void > {
@@ -53,8 +59,6 @@ export class DependencyExplorer {
5359
5460 if ( this . _dependencyViewer . visible ) {
5561 this . _dependencyViewer . reveal ( node ) ;
56- } else {
57- this . _selectionWhenHidden = node ;
5862 }
5963 }
6064}
0 commit comments