@@ -394,6 +394,8 @@ abstract class AbstractTreeView extends Disposable implements ITreeView {
394
394
this . refresh ( ) ;
395
395
} else {
396
396
this . _dataProvider = undefined ;
397
+ this . treeDisposables . clear ( ) ;
398
+ this . activated = false ;
397
399
this . updateMessage ( ) ;
398
400
}
399
401
@@ -602,6 +604,7 @@ abstract class AbstractTreeView extends Disposable implements ITreeView {
602
604
}
603
605
}
604
606
607
+ protected activated : boolean = false ;
605
608
protected abstract activate ( ) : void ;
606
609
607
610
focus ( reveal : boolean = true , revealItem ?: ITreeItem ) : void {
@@ -637,19 +640,21 @@ abstract class AbstractTreeView extends Disposable implements ITreeView {
637
640
this . _register ( focusTracker . onDidBlur ( ( ) => this . focused = false ) ) ;
638
641
}
639
642
643
+ private readonly treeDisposables : DisposableStore = this . _register ( new DisposableStore ( ) ) ;
640
644
protected createTree ( ) {
645
+ this . treeDisposables . clear ( ) ;
641
646
const actionViewItemProvider = createActionViewItem . bind ( undefined , this . instantiationService ) ;
642
- const treeMenus = this . _register ( this . instantiationService . createInstance ( TreeMenus , this . id ) ) ;
643
- this . treeLabels = this . _register ( this . instantiationService . createInstance ( ResourceLabels , this ) ) ;
647
+ const treeMenus = this . treeDisposables . add ( this . instantiationService . createInstance ( TreeMenus , this . id ) ) ;
648
+ this . treeLabels = this . treeDisposables . add ( this . instantiationService . createInstance ( ResourceLabels , this ) ) ;
644
649
const dataSource = this . instantiationService . createInstance ( TreeDataSource , this , < T > ( task : Promise < T > ) => this . progressService . withProgress ( { location : this . id } , ( ) => task ) ) ;
645
650
const aligner = new Aligner ( this . themeService ) ;
646
- const checkboxStateHandler = this . _register ( new CheckboxStateHandler ( ) ) ;
651
+ const checkboxStateHandler = this . treeDisposables . add ( new CheckboxStateHandler ( ) ) ;
647
652
const renderer = this . instantiationService . createInstance ( TreeRenderer , this . id , treeMenus , this . treeLabels , actionViewItemProvider , aligner , checkboxStateHandler , ( ) => this . manuallyManageCheckboxes ) ;
648
- this . _register ( renderer . onDidChangeCheckboxState ( e => this . _onDidChangeCheckboxState . fire ( e ) ) ) ;
653
+ this . treeDisposables . add ( renderer . onDidChangeCheckboxState ( e => this . _onDidChangeCheckboxState . fire ( e ) ) ) ;
649
654
650
655
const widgetAriaLabel = this . _title ;
651
656
652
- this . tree = this . _register ( this . instantiationService . createInstance ( Tree , this . id , this . treeContainer ! , new TreeViewDelegate ( ) , [ renderer ] ,
657
+ this . tree = this . treeDisposables . add ( this . instantiationService . createInstance ( Tree , this . id , this . treeContainer ! , new TreeViewDelegate ( ) , [ renderer ] ,
653
658
dataSource , {
654
659
identityProvider : new TreeViewIdentityProvider ( ) ,
655
660
accessibilityProvider : {
@@ -698,6 +703,7 @@ abstract class AbstractTreeView extends Disposable implements ITreeView {
698
703
dnd : this . treeViewDnd ,
699
704
overrideStyles : getLocationBasedViewColors ( this . viewLocation ) . listOverrideStyles
700
705
} ) as WorkbenchAsyncDataTree < ITreeItem , ITreeItem , FuzzyScore > ) ;
706
+ this . treeDisposables . add ( this . tree ) ;
701
707
treeMenus . setContextKeyService ( this . tree . contextKeyService ) ;
702
708
aligner . tree = this . tree ;
703
709
const actionRunner = new MultipleSelectionActionRunner ( this . notificationService , ( ) => this . tree ! . getSelection ( ) ) ;
@@ -706,21 +712,21 @@ abstract class AbstractTreeView extends Disposable implements ITreeView {
706
712
this . tree . contextKeyService . createKey < boolean > ( this . id , true ) ;
707
713
const customTreeKey = RawCustomTreeViewContextKey . bindTo ( this . tree . contextKeyService ) ;
708
714
customTreeKey . set ( true ) ;
709
- this . _register ( this . tree . onContextMenu ( e => this . onContextMenu ( treeMenus , e , actionRunner ) ) ) ;
715
+ this . treeDisposables . add ( this . tree . onContextMenu ( e => this . onContextMenu ( treeMenus , e , actionRunner ) ) ) ;
710
716
711
- this . _register ( this . tree . onDidChangeSelection ( e => {
717
+ this . treeDisposables . add ( this . tree . onDidChangeSelection ( e => {
712
718
this . lastSelection = e . elements ;
713
719
this . lastActive = this . tree ?. getFocus ( ) [ 0 ] ?? this . lastActive ;
714
720
this . _onDidChangeSelectionAndFocus . fire ( { selection : this . lastSelection , focus : this . lastActive } ) ;
715
721
} ) ) ;
716
- this . _register ( this . tree . onDidChangeFocus ( e => {
722
+ this . treeDisposables . add ( this . tree . onDidChangeFocus ( e => {
717
723
if ( e . elements . length && ( e . elements [ 0 ] !== this . lastActive ) ) {
718
724
this . lastActive = e . elements [ 0 ] ;
719
725
this . lastSelection = this . tree ?. getSelection ( ) ?? this . lastSelection ;
720
726
this . _onDidChangeSelectionAndFocus . fire ( { selection : this . lastSelection , focus : this . lastActive } ) ;
721
727
}
722
728
} ) ) ;
723
- this . _register ( this . tree . onDidChangeCollapseState ( e => {
729
+ this . treeDisposables . add ( this . tree . onDidChangeCollapseState ( e => {
724
730
if ( ! e . node . element ) {
725
731
return ;
726
732
}
@@ -734,7 +740,7 @@ abstract class AbstractTreeView extends Disposable implements ITreeView {
734
740
} ) ) ;
735
741
this . tree . setInput ( this . root ) . then ( ( ) => this . updateContentAreas ( ) ) ;
736
742
737
- this . _register ( this . tree . onDidOpen ( async ( e ) => {
743
+ this . treeDisposables . add ( this . tree . onDidOpen ( async ( e ) => {
738
744
if ( ! e . browserEvent ) {
739
745
return ;
740
746
}
@@ -760,7 +766,7 @@ abstract class AbstractTreeView extends Disposable implements ITreeView {
760
766
}
761
767
} ) ) ;
762
768
763
- this . _register ( treeMenus . onDidChange ( ( changed ) => {
769
+ this . treeDisposables . add ( treeMenus . onDidChange ( ( changed ) => {
764
770
if ( this . tree ?. hasNode ( changed ) ) {
765
771
this . tree ?. rerender ( changed ) ;
766
772
}
@@ -1615,8 +1621,6 @@ class TreeMenus implements IDisposable {
1615
1621
1616
1622
export class CustomTreeView extends AbstractTreeView {
1617
1623
1618
- private activated : boolean = false ;
1619
-
1620
1624
constructor (
1621
1625
id : string ,
1622
1626
title : string ,
@@ -1670,8 +1674,6 @@ export class CustomTreeView extends AbstractTreeView {
1670
1674
1671
1675
export class TreeView extends AbstractTreeView {
1672
1676
1673
- private activated : boolean = false ;
1674
-
1675
1677
protected activate ( ) {
1676
1678
if ( ! this . activated ) {
1677
1679
this . createTree ( ) ;
0 commit comments