Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 1b64ba3

Browse files
Merge branch 'enhancements/tree-view-checked-state' into enhancements/changes-tree-view
2 parents 3e7861a + 43f4d1e commit 1b64ba3

File tree

2 files changed

+33
-19
lines changed

2 files changed

+33
-19
lines changed

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public override void InitializeView(IView parent)
5959
targetMode = mode;
6060
}
6161

62-
6362
public override void OnEnable()
6463
{
6564
base.OnEnable();

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/TreeControl.cs

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
using System;
2-
using System.Collections;
32
using System.Collections.Generic;
43
using System.Linq;
54
using UnityEditor;
65
using UnityEngine;
7-
using UnityEngine.Profiling;
86

97
namespace GitHub.Unity
108
{
@@ -168,7 +166,7 @@ public Rect Render(Rect containingRect, Rect rect, Vector2 scroll, Action<TreeNo
168166
}
169167
else if (renderResult == TreeNodeRenderResult.CheckChange)
170168
{
171-
ToggleNodeCheck(0, titleNode);
169+
ToggleNodeChecked(0, titleNode);
172170
}
173171

174172
RequiresRepaint = HandleInput(rect, titleNode, 0);
@@ -201,7 +199,7 @@ public Rect Render(Rect containingRect, Rect rect, Vector2 scroll, Action<TreeNo
201199
}
202200
else if (renderResult == TreeNodeRenderResult.CheckChange)
203201
{
204-
ToggleNodeCheck(i, node);
202+
ToggleNodeChecked(i, node);
205203
}
206204

207205
if (node.Level < level)
@@ -258,7 +256,7 @@ public void Blur()
258256
RequiresRepaint = true;
259257
}
260258

261-
private void ToggleNodeCheck(int idx, TreeNode node)
259+
private void ToggleNodeChecked(int idx, TreeNode node)
262260
{
263261
var isChecked = false;
264262

@@ -277,25 +275,40 @@ private void ToggleNodeCheck(int idx, TreeNode node)
277275

278276
if (node.IsFolder)
279277
{
280-
278+
ToggleChildrenChecked(idx, node, isChecked);
281279
}
282280

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+
}
284301
}
285302

286-
private void ToggleParentFolders(int idx, TreeNode node, bool isChecked)
303+
private void ToggleParentFoldersChecked(int idx, TreeNode node, bool isChecked)
287304
{
288305
while (true)
289306
{
290307
if (node.Level > 0)
291308
{
292-
Debug.Log("ToggleParentFolders");
293-
294309
var siblingsInSameState = true;
295310
var firstSiblingIndex = idx;
296311

297-
Debug.LogFormat("Ripple CheckState index:{0} level:{1}", idx, node.Level);
298-
299312
for (var i = idx - 1; i > 0 && node.Level <= nodes[i].Level; i--)
300313
{
301314
if (node.Level < nodes[i].Level)
@@ -305,16 +318,15 @@ private void ToggleParentFolders(int idx, TreeNode node, bool isChecked)
305318

306319
firstSiblingIndex = i;
307320
var siblingIsChecked = nodes[i].CheckState == CheckState.Checked;
308-
Debug.LogFormat("Previous Sibling - idx:{0} name:{1} checked:{2}", i, nodes[i].Path, siblingIsChecked);
309321

310322
if (isChecked != siblingIsChecked)
311323
{
312324
siblingsInSameState = false;
313-
//break;
325+
break;
314326
}
315327
}
316328

317-
//if (siblingsInSameState)
329+
if (siblingsInSameState)
318330
{
319331
for (var i = idx + 1; i < nodes.Count && node.Level <= nodes[i].Level; i++)
320332
{
@@ -324,12 +336,15 @@ private void ToggleParentFolders(int idx, TreeNode node, bool isChecked)
324336
}
325337

326338
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+
}
328345
}
329346
}
330347

331-
Debug.LogFormat("Siblings in same state = {0}", siblingsInSameState);
332-
333348
var parentIndex = firstSiblingIndex - 1;
334349
var parentNode = nodes[parentIndex];
335350
if (siblingsInSameState)

0 commit comments

Comments
 (0)