A game about forced loneliness, made by TACStudios
1using System;
2using System.Collections.Generic;
3using System.Linq;
4
5using UnityEditor;
6using UnityEditor.IMGUI.Controls;
7
8using PlasticGui;
9
10namespace Unity.PlasticSCM.Editor.UI.Tree
11{
12 internal class TreeViewSessionState
13 {
14 internal static void Save(
15 TreeView treeView,
16 string uncheckedKey)
17 {
18 var rows = treeView.GetRows();
19
20 if (!rows.Any())
21 return;
22
23 List<string> uncheckedRows = new List<string>();
24
25 for (int i = 0; i < rows.Count; i++)
26 {
27 bool? isChecked = CheckableItems.GetIsCheckedValue(
28 rows[i].GetPlasticTreeNode());
29
30 if (!isChecked.HasValue)
31 continue;
32
33 if (string.IsNullOrEmpty(rows[i].displayName))
34 continue;
35
36 if (!isChecked.Value)
37 uncheckedRows.Add(rows[i].displayName);
38 }
39
40 SessionState.SetString(uncheckedKey, string.Join(":", uncheckedRows));
41 }
42
43 internal static void Restore(
44 TreeView treeView,
45 string uncheckedKey)
46 {
47 var rows = treeView.GetRows();
48
49 if (!rows.Any())
50 return;
51
52 string uncheckedRows = SessionState.GetString(
53 uncheckedKey, string.Empty);
54
55 if (string.IsNullOrEmpty(uncheckedRows))
56 return;
57
58 string[] uncheckedArray = uncheckedRows.Split(':');
59
60 for (int i = 0; i < rows.Count; i++)
61 {
62 if (string.IsNullOrEmpty(rows[i].displayName))
63 continue;
64
65 if (uncheckedArray.Contains(rows[i].displayName))
66 {
67 CheckableItems.SetCheckedValue(
68 rows[i].GetPlasticTreeNode(), false);
69 continue;
70 }
71
72 CheckableItems.SetCheckedValue(
73 rows[i].GetPlasticTreeNode(), true);
74 }
75
76 // Clear session state after the every update
77 SessionState.EraseString(uncheckedKey);
78 }
79 }
80}