@@ -28,8 +28,8 @@ public abstract class Tree: ITree
28
28
29
29
[ SerializeField ] private List < TreeNode > nodes = new List < TreeNode > ( ) ;
30
30
[ SerializeField ] private TreeNode selectedNode = null ;
31
- [ SerializeField ] private TreeNode activeNode = null ;
32
31
[ SerializeField ] private TreeNodeDictionary folders = new TreeNodeDictionary ( ) ;
32
+ [ SerializeField ] private TreeNodeDictionary checkedFileNodes = new TreeNodeDictionary ( ) ;
33
33
34
34
[ NonSerialized ] private Stack < bool > indents = new Stack < bool > ( ) ;
35
35
[ NonSerialized ] private Action < TreeNode > rightClickNextRender ;
@@ -100,11 +100,6 @@ public void AddNode(string path, string label, int level, bool isFolder, bool is
100
100
SetNodeIcon ( node ) ;
101
101
nodes . Add ( node ) ;
102
102
103
- if ( isActive )
104
- {
105
- activeNode = node ;
106
- }
107
-
108
103
if ( isSelected )
109
104
{
110
105
SelectedNode = node ;
@@ -119,14 +114,19 @@ public void AddNode(string path, string label, int level, bool isFolder, bool is
119
114
public void Clear ( )
120
115
{
121
116
folders . Clear ( ) ;
117
+ checkedFileNodes . Clear ( ) ;
122
118
nodes . Clear ( ) ;
123
119
SelectedNode = null ;
124
120
}
125
121
126
- public HashSet < string > GetCollapsedFolders ( )
122
+ public IEnumerable < string > GetCollapsedFolders ( )
127
123
{
128
- var collapsedFoldersEnumerable = folders . Where ( pair => pair . Value . IsCollapsed ) . Select ( pair => pair . Key ) ;
129
- return new HashSet < string > ( collapsedFoldersEnumerable ) ;
124
+ return folders . Where ( pair => pair . Value . IsCollapsed ) . Select ( pair => pair . Key ) ;
125
+ }
126
+
127
+ public IEnumerable < string > GetCheckedFiles ( )
128
+ {
129
+ return checkedFileNodes . Where ( pair => pair . Value . CheckState == CheckState . Checked ) . Select ( pair => pair . Key ) ;
130
130
}
131
131
132
132
public Rect Render ( Rect containingRect , Rect rect , Vector2 scroll , Action < TreeNode > singleClick = null , Action < TreeNode > doubleClick = null , Action < TreeNode > rightClick = null )
@@ -277,6 +277,13 @@ private void ToggleNodeChecked(int idx, TreeNode node)
277
277
{
278
278
ToggleChildrenChecked ( idx , node , isChecked ) ;
279
279
}
280
+ else
281
+ {
282
+ if ( isChecked )
283
+ {
284
+ checkedFileNodes . Add ( node . Path , node ) ;
285
+ }
286
+ }
280
287
281
288
ToggleParentFoldersChecked ( idx , node , isChecked ) ;
282
289
}
@@ -297,6 +304,13 @@ private void ToggleChildrenChecked(int idx, TreeNode node, bool isChecked)
297
304
{
298
305
ToggleChildrenChecked ( i , childNode , isChecked ) ;
299
306
}
307
+ else
308
+ {
309
+ if ( isChecked )
310
+ {
311
+ checkedFileNodes . Add ( node . Path , node ) ;
312
+ }
313
+ }
300
314
}
301
315
}
302
316
@@ -392,13 +406,13 @@ private void ToggleNodeVisibility(int idx, TreeNode node)
392
406
393
407
private bool HandleInput ( Rect rect , TreeNode currentNode , int index , Action < TreeNode > singleClick = null , Action < TreeNode > doubleClick = null , Action < TreeNode > rightClick = null )
394
408
{
395
- bool selectionChanged = false ;
409
+ var requiresRepaint = false ;
396
410
var clickRect = new Rect ( 0f , rect . y , rect . width , rect . height ) ;
397
411
if ( Event . current . type == EventType . MouseDown && clickRect . Contains ( Event . current . mousePosition ) )
398
412
{
399
413
Event . current . Use ( ) ;
400
414
SelectedNode = currentNode ;
401
- selectionChanged = true ;
415
+ requiresRepaint = true ;
402
416
var clickCount = Event . current . clickCount ;
403
417
var mouseButton = Event . current . button ;
404
418
@@ -424,41 +438,50 @@ private bool HandleInput(Rect rect, TreeNode currentNode, int index, Action<Tree
424
438
int directionX = Event . current . keyCode == KeyCode . LeftArrow ? - 1 : Event . current . keyCode == KeyCode . RightArrow ? 1 : 0 ;
425
439
if ( directionY != 0 || directionX != 0 )
426
440
{
441
+ Event . current . Use ( ) ;
442
+
427
443
if ( directionY > 0 )
428
444
{
429
- selectionChanged = SelectNext ( index , false ) != index ;
445
+ requiresRepaint = SelectNext ( index , false ) != index ;
430
446
}
431
447
else if ( directionY < 0 )
432
448
{
433
- selectionChanged = SelectPrevious ( index , false ) != index ;
449
+ requiresRepaint = SelectPrevious ( index , false ) != index ;
434
450
}
435
451
else if ( directionX > 0 )
436
452
{
437
453
if ( currentNode . IsFolder && currentNode . IsCollapsed )
438
454
{
439
455
ToggleNodeVisibility ( index , currentNode ) ;
440
- Event . current . Use ( ) ;
441
456
}
442
457
else
443
458
{
444
- selectionChanged = SelectNext ( index , true ) != index ;
459
+ requiresRepaint = SelectNext ( index , true ) != index ;
445
460
}
446
461
}
447
462
else if ( directionX < 0 )
448
463
{
449
464
if ( currentNode . IsFolder && ! currentNode . IsCollapsed )
450
465
{
451
466
ToggleNodeVisibility ( index , currentNode ) ;
452
- Event . current . Use ( ) ;
453
467
}
454
468
else
455
469
{
456
- selectionChanged = SelectPrevious ( index , true ) != index ;
470
+ requiresRepaint = SelectPrevious ( index , true ) != index ;
457
471
}
458
472
}
459
473
}
474
+
475
+ if ( IsCheckable && Event . current . keyCode == KeyCode . Space )
476
+ {
477
+ Event . current . Use ( ) ;
478
+
479
+ ToggleNodeChecked ( index , currentNode ) ;
480
+ requiresRepaint = true ;
481
+ }
460
482
}
461
- return selectionChanged ;
483
+
484
+ return requiresRepaint ;
462
485
}
463
486
464
487
private int SelectNext ( int index , bool foldersOnly )
0 commit comments