@ -2,6 +2,7 @@ import type {
CancellationToken ,
ConfigurationChangeEvent ,
Event ,
TreeCheckboxChangeEvent ,
TreeDataProvider ,
TreeItem ,
TreeView ,
@ -312,6 +313,7 @@ export abstract class ViewBase<
this . tree ,
this . tree . onDidChangeSelection ( debounce ( this . onSelectionChanged , 250 ) , this ) ,
this . tree . onDidChangeVisibility ( debounce ( this . onVisibilityChanged , 250 ) , this ) ,
this . tree . onDidChangeCheckboxState ( this . onCheckboxStateChanged , this ) ,
this . tree . onDidCollapseElement ( this . onElementCollapsed , this ) ,
this . tree . onDidExpandElement ( this . onElementExpanded , this ) ,
) ;
@ -364,6 +366,17 @@ export abstract class ViewBase<
this . _onDidChangeNodeCollapsibleState . fire ( { . . . e , state : TreeItemCollapsibleState.Expanded } ) ;
}
protected onCheckboxStateChanged ( e : TreeCheckboxChangeEvent < ViewNode > ) {
for ( const [ node , state ] of e . items ) {
if ( node . id == null ) {
debugger ;
throw new Error ( 'Id is required for checkboxes' ) ;
}
node . storeState ( 'checked' , state , true ) ;
}
}
protected onSelectionChanged ( e : TreeViewSelectionChangeEvent < ViewNode > ) {
this . _onDidChangeSelection . fire ( e ) ;
}
@ -653,39 +666,54 @@ export abstract class ViewBase<
}
export class ViewNodeState implements Disposable {
private _state : Map < string , Map < string , unknown > > | undefined ;
private _store : Map < string , Map < string , unknown > > | undefined ;
private _stickyStore : Map < string , Map < string , unknown > > | undefined ;
dispose() {
this . reset ( ) ;
this . _stickyStore ? . clear ( ) ;
this . _stickyStore = undefined ;
}
reset() {
this . _stat e ? . clear ( ) ;
this . _stat e = undefined ;
this . _stor e ? . clear ( ) ;
this . _stor e = undefined ;
}
deleteState ( id : string , key? : string ) : void {
if ( key == null ) {
this . _state ? . delete ( id ) ;
this . _store ? . delete ( id ) ;
this . _stickyStore ? . delete ( id ) ;
} else {
this . _state ? . get ( id ) ? . delete ( key ) ;
this . _store ? . get ( id ) ? . delete ( key ) ;
this . _stickyStore ? . get ( id ) ? . delete ( key ) ;
}
}
getState < T > ( id : string , key : string ) : T | undefined {
return this . _state ? . get ( id ) ? . get ( key ) as T | undefined ;
return ( this . _stickyStore ?an>. ge t ( id ) ? . get ( key ) ? ? this . _stor e? . get ( id ) ? . get ( key ) ) as T | undefined ;
}
storeState < T > ( id : string , key : string , value : T ) : void {
if ( this . _state == null ) {
this . _state = new Map ( ) ;
storeState < T > ( id : string , key : string , value : T , sticky? : boolean ) : void {
let store ;
if ( sticky ) {
if ( this . _stickyStore == null ) {
this . _stickyStore = new Map ( ) ;
}
store = this . _stickyStore ;
} else {
if ( this . _store == null ) {
this . _store = new Map ( ) ;
}
store = this . _store ;
}
const state = this . _state . get ( id ) ;
const state = stor e. get ( id ) ;
if ( state != null ) {
state . set ( key , value ) ;
} else {
this . _state . set ( id , new Map ( [ [ key , value ] ] ) ) ;
stor e. set ( id , new Map ( [ [ key , value ] ] ) ) ;
}
}
}