1
1
using System ;
2
- using System . Collections ;
3
2
using System . Collections . Generic ;
4
3
using System . Linq ;
5
4
using UnityEditor ;
6
5
using UnityEngine ;
7
- using UnityEngine . Profiling ;
8
6
9
7
namespace GitHub . Unity
10
8
{
@@ -168,7 +166,7 @@ public Rect Render(Rect containingRect, Rect rect, Vector2 scroll, Action<TreeNo
168
166
}
169
167
else if ( renderResult == TreeNodeRenderResult . CheckChange )
170
168
{
171
- ToggleNodeCheck ( 0 , titleNode ) ;
169
+ ToggleNodeChecked ( 0 , titleNode ) ;
172
170
}
173
171
174
172
RequiresRepaint = HandleInput ( rect , titleNode , 0 ) ;
@@ -201,7 +199,7 @@ public Rect Render(Rect containingRect, Rect rect, Vector2 scroll, Action<TreeNo
201
199
}
202
200
else if ( renderResult == TreeNodeRenderResult . CheckChange )
203
201
{
204
- ToggleNodeCheck ( i , node ) ;
202
+ ToggleNodeChecked ( i , node ) ;
205
203
}
206
204
207
205
if ( node . Level < level )
@@ -258,7 +256,7 @@ public void Blur()
258
256
RequiresRepaint = true ;
259
257
}
260
258
261
- private void ToggleNodeCheck ( int idx , TreeNode node )
259
+ private void ToggleNodeChecked ( int idx , TreeNode node )
262
260
{
263
261
var isChecked = false ;
264
262
@@ -277,25 +275,40 @@ private void ToggleNodeCheck(int idx, TreeNode node)
277
275
278
276
if ( node . IsFolder )
279
277
{
280
-
278
+ ToggleChildrenChecked ( idx , node , isChecked ) ;
281
279
}
282
280
283
- ToggleParentFolders ( idx , node , isChecked ) ;
281
+ ToggleParentFoldersChecked ( idx , node , isChecked ) ;
282
+ }
283
+
284
+ private void ToggleChildrenChecked ( int idx , TreeNode node , bool isChecked )
285
+ {
286
+ for ( var i = idx + 1 ; i < nodes . Count && node . Level <= nodes [ i ] . Level ; i ++ )
287
+ {
288
+ var childNode = nodes [ i ] ;
289
+ if ( node . Level == childNode . Level )
290
+ {
291
+ continue ;
292
+ }
293
+
294
+ childNode . CheckState = isChecked ? CheckState . Checked : CheckState . Empty ;
295
+
296
+ if ( childNode . IsFolder )
297
+ {
298
+ ToggleChildrenChecked ( i , childNode , isChecked ) ;
299
+ }
300
+ }
284
301
}
285
302
286
- private void ToggleParentFolders ( int idx , TreeNode node , bool isChecked )
303
+ private void ToggleParentFoldersChecked ( int idx , TreeNode node , bool isChecked )
287
304
{
288
305
while ( true )
289
306
{
290
307
if ( node . Level > 0 )
291
308
{
292
- Debug . Log ( "ToggleParentFolders" ) ;
293
-
294
309
var siblingsInSameState = true ;
295
310
var firstSiblingIndex = idx ;
296
311
297
- Debug . LogFormat ( "Ripple CheckState index:{0} level:{1}" , idx , node . Level ) ;
298
-
299
312
for ( var i = idx - 1 ; i > 0 && node . Level <= nodes [ i ] . Level ; i -- )
300
313
{
301
314
if ( node . Level < nodes [ i ] . Level )
@@ -305,16 +318,15 @@ private void ToggleParentFolders(int idx, TreeNode node, bool isChecked)
305
318
306
319
firstSiblingIndex = i ;
307
320
var siblingIsChecked = nodes [ i ] . CheckState == CheckState . Checked ;
308
- Debug . LogFormat ( "Previous Sibling - idx:{0} name:{1} checked:{2}" , i , nodes [ i ] . Path , siblingIsChecked ) ;
309
321
310
322
if ( isChecked != siblingIsChecked )
311
323
{
312
324
siblingsInSameState = false ;
313
- // break;
325
+ break ;
314
326
}
315
327
}
316
328
317
- // if (siblingsInSameState)
329
+ if ( siblingsInSameState )
318
330
{
319
331
for ( var i = idx + 1 ; i < nodes . Count && node . Level <= nodes [ i ] . Level ; i ++ )
320
332
{
@@ -324,12 +336,15 @@ private void ToggleParentFolders(int idx, TreeNode node, bool isChecked)
324
336
}
325
337
326
338
var siblingIsChecked = nodes [ i ] . CheckState == CheckState . Checked ;
327
- Debug . LogFormat ( "Next Siblings - idx:{0} name:{1} checked:{2}" , i , nodes [ i ] . Path , siblingIsChecked ) ;
339
+
340
+ if ( isChecked != siblingIsChecked )
341
+ {
342
+ siblingsInSameState = false ;
343
+ break ;
344
+ }
328
345
}
329
346
}
330
347
331
- Debug . LogFormat ( "Siblings in same state = {0}" , siblingsInSameState ) ;
332
-
333
348
var parentIndex = firstSiblingIndex - 1 ;
334
349
var parentNode = nodes [ parentIndex ] ;
335
350
if ( siblingsInSameState )
0 commit comments