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

Commit 88e8585

Browse files
Merge branch 'enhancements/history-detail-tree-view-rollup' into enhancements/removing-old-tree-code
2 parents eead5e4 + d6df408 commit 88e8585

File tree

7 files changed

+104
-24
lines changed

7 files changed

+104
-24
lines changed

src/GitHub.Api/Git/TreeData.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,19 @@ public struct GitStatusEntryTreeData : ITreeData
3030
public static GitStatusEntryTreeData Default = new GitStatusEntryTreeData(GitStatusEntry.Default);
3131

3232
public GitStatusEntry gitStatusEntry;
33+
public bool isLocked;
3334

34-
public GitStatusEntryTreeData(GitStatusEntry gitStatusEntry)
35+
public GitStatusEntryTreeData(GitStatusEntry gitStatusEntry, bool isLocked = false)
3536
{
37+
this.isLocked = isLocked;
3638
this.gitStatusEntry = gitStatusEntry;
3739
}
3840

3941
public string Path => gitStatusEntry.Path;
4042
public string ProjectPath => gitStatusEntry.ProjectPath;
4143
public bool IsActive => false;
4244
public GitStatusEntry GitStatusEntry => gitStatusEntry;
43-
4445
public GitFileStatus FileStatus => gitStatusEntry.Status;
46+
public bool IsLocked => isLocked;
4547
}
4648
}

src/GitHub.Api/UI/TreeBase.cs

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34

45
namespace GitHub.Unity
56
{
@@ -31,13 +32,14 @@ public void Load(IEnumerable<TData> treeDatas)
3132
{
3233
var collapsedFolders = new HashSet<string>(GetCollapsedFolders());
3334
var selectedNodePath = SelectedNodePath;
35+
var checkedFiles = new HashSet<string>(GetCheckedFiles());
3436

3537
Clear();
3638

3739
var displayRootLevel = DisplayRootNode ? 1 : 0;
3840

3941
var isSelected = IsSelectable && selectedNodePath != null && Title == selectedNodePath;
40-
AddNode(Title, Title, -1 + displayRootLevel, true, false, false, false, isSelected, null);
42+
AddNode(Title, Title, -1 + displayRootLevel, true, false, false, false, isSelected, false, null);
4143

4244
var hideChildren = false;
4345
var hideChildrenBelowLevel = 0;
@@ -70,6 +72,7 @@ public void Load(IEnumerable<TData> treeDatas)
7072
}
7173

7274
var isActive = false;
75+
var isChecked = false;
7376
var nodeIsCollapsed = false;
7477
TData? treeNodeTreeData = null;
7578

@@ -92,11 +95,42 @@ public void Load(IEnumerable<TData> treeDatas)
9295
{
9396
isActive = treeData.IsActive;
9497
treeNodeTreeData = treeData;
98+
isChecked = checkedFiles.Contains(nodePath);
9599
}
96100

97101
isSelected = selectedNodePath != null && nodePath == selectedNodePath;
98102
AddNode(nodePath, label, i + displayRootLevel, isFolder, isActive, nodeIsHidden,
99-
nodeIsCollapsed, isSelected, treeNodeTreeData);
103+
nodeIsCollapsed, isSelected, isChecked, treeNodeTreeData);
104+
}
105+
}
106+
}
107+
108+
if (IsCheckable && checkedFiles.Any())
109+
{
110+
for (var index = Nodes.Count - 1; index >= 0; index--)
111+
{
112+
var node = Nodes[index];
113+
if (node.Level >= 0 && node.IsFolder)
114+
{
115+
bool? anyChecked = null;
116+
bool? allChecked = null;
117+
118+
for (var i = index + 1; i < Nodes.Count; i++)
119+
{
120+
var nodeCompare = Nodes[i];
121+
if (nodeCompare.Level < node.Level + 1)
122+
{
123+
break;
124+
}
125+
126+
var nodeIsChecked = nodeCompare.CheckState == CheckState.Checked;
127+
allChecked = (allChecked ?? true) && nodeIsChecked;
128+
anyChecked = (anyChecked ?? false) || nodeIsChecked;
129+
}
130+
131+
node.CheckState = anyChecked.Value
132+
? (allChecked.Value ? CheckState.Checked : CheckState.Mixed)
133+
: CheckState.Empty;
100134
}
101135
}
102136
}
@@ -126,10 +160,9 @@ public void SetCheckStateOnAll(bool isChecked)
126160

127161
protected abstract IEnumerable<string> GetCollapsedFolders();
128162

129-
protected void AddNode(string path, string label, int level, bool isFolder, bool isActive, bool isHidden,
130-
bool isCollapsed, bool isSelected, TData? treeData)
163+
protected void AddNode(string path, string label, int level, bool isFolder, bool isActive, bool isHidden, bool isCollapsed, bool isSelected, bool isChecked, TData? treeData)
131164
{
132-
var node = CreateTreeNode(path, label, level, isFolder, isActive, isHidden, isCollapsed, treeData);
165+
var node = CreateTreeNode(path, label, level, isFolder, isActive, isHidden, isCollapsed, isChecked, treeData);
133166

134167
SetNodeIcon(node);
135168
Nodes.Add(node);
@@ -151,8 +184,7 @@ protected void Clear()
151184

152185
protected abstract void AddCheckedNode(TNode node);
153186

154-
protected abstract TNode CreateTreeNode(string path, string label, int level, bool isFolder, bool isActive,
155-
bool isHidden, bool isCollapsed, TData? treeData);
187+
protected abstract TNode CreateTreeNode(string path, string label, int level, bool isFolder, bool isActive, bool isHidden, bool isCollapsed, bool isChecked, TData? treeData);
156188

157189
protected abstract void OnClear();
158190

src/UnityExtension/Assets/Editor/GitHub.Unity/ApplicationCache.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ protected ManagedCacheBase(bool invalidOnFirstRun)
133133
public void ValidateData()
134134
{
135135
var initialized = ValidateInitialized();
136-
if (!initialized)
136+
if (initialized)
137137
{
138138
if (DateTimeOffset.Now - LastUpdatedAt > DataTimeout)
139139
{
@@ -145,8 +145,8 @@ public void ValidateData()
145145

146146
private bool ValidateInitialized()
147147
{
148-
var notInitialized = ApplicationCache.Instance.FirstRunAt > InitializedAt;
149-
if (notInitialized)
148+
var isInitialized = IsInitialized;
149+
if (!isInitialized)
150150
{
151151
Logger.Trace("Not Initialized");
152152

@@ -156,7 +156,7 @@ private bool ValidateInitialized()
156156
}
157157
}
158158

159-
return notInitialized;
159+
return isInitialized;
160160
}
161161

162162
public void InvalidateData()
@@ -167,7 +167,7 @@ public void InvalidateData()
167167

168168
protected void SaveData(DateTimeOffset now, bool isUpdated)
169169
{
170-
if (InitializedAt == DateTimeOffset.MinValue)
170+
if (!IsInitialized)
171171
{
172172
InitializedAt = now;
173173
}
@@ -196,6 +196,11 @@ protected void SaveData(DateTimeOffset now, bool isUpdated)
196196
public abstract string LastVerifiedAtString { get; protected set; }
197197
public abstract string InitializedAtString { get; protected set; }
198198

199+
public bool IsInitialized
200+
{
201+
get { return ApplicationCache.Instance.FirstRunAt <= InitializedAt; }
202+
}
203+
199204
public DateTimeOffset LastUpdatedAt
200205
{
201206
get

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class ChangesTreeNode : TreeNode
1414
{
1515
public string projectPath;
1616
public GitFileStatus gitFileStatus;
17+
public bool isLocked;
1718

1819
public string ProjectPath
1920
{
@@ -26,6 +27,12 @@ public GitFileStatus GitFileStatus
2627
get { return gitFileStatus; }
2728
set { gitFileStatus = value; }
2829
}
30+
31+
public bool IsLocked
32+
{
33+
get { return isLocked; }
34+
set { isLocked = value; }
35+
}
2936
}
3037

3138
[Serializable]
@@ -150,11 +157,22 @@ protected Texture GetNodeIconBadge(ChangesTreeNode node)
150157
}
151158

152159
var gitFileStatus = node.GitFileStatus;
153-
return Styles.GetFileStatusIcon(gitFileStatus, false);
160+
return Styles.GetFileStatusIcon(gitFileStatus, node.IsLocked);
154161
}
155162

156-
protected override ChangesTreeNode CreateTreeNode(string path, string label, int level, bool isFolder, bool isActive, bool isHidden, bool isCollapsed, GitStatusEntryTreeData? treeData)
163+
protected override ChangesTreeNode CreateTreeNode(string path, string label, int level, bool isFolder, bool isActive, bool isHidden, bool isCollapsed, bool isChecked, GitStatusEntryTreeData? treeData)
157164
{
165+
var gitFileStatus = GitFileStatus.None;
166+
var projectPath = (string) null;
167+
var isLocked = false;
168+
169+
if (treeData.HasValue)
170+
{
171+
isLocked = treeData.Value.IsLocked;
172+
gitFileStatus = treeData.Value.FileStatus;
173+
projectPath = treeData.Value.ProjectPath;
174+
}
175+
158176
var node = new ChangesTreeNode
159177
{
160178
Path = path,
@@ -165,11 +183,13 @@ protected override ChangesTreeNode CreateTreeNode(string path, string label, int
165183
IsHidden = isHidden,
166184
IsCollapsed = isCollapsed,
167185
TreeIsCheckable = IsCheckable,
168-
GitFileStatus = treeData.HasValue ? treeData.Value.FileStatus : GitFileStatus.None,
169-
ProjectPath = treeData.HasValue ? treeData.Value.ProjectPath : null
186+
CheckState = isChecked ? CheckState.Checked : CheckState.Empty,
187+
GitFileStatus = gitFileStatus,
188+
ProjectPath = projectPath,
189+
IsLocked = isLocked
170190
};
171191

172-
if (isFolder)
192+
if (isFolder && level >= 0)
173193
{
174194
folders.Add(node.Path, node);
175195
}

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class ChangesView : Subview
2020

2121
[NonSerialized] private bool currentBranchHasUpdate;
2222
[NonSerialized] private bool currentStatusEntriesHasUpdate;
23+
[NonSerialized] private bool currentLocksHasUpdate;
2324
[NonSerialized] private bool isBusy;
2425

2526
[SerializeField] private string commitBody = "";
@@ -29,12 +30,14 @@ class ChangesView : Subview
2930
[SerializeField] private Vector2 treeScroll;
3031
[SerializeField] private ChangesTree treeChanges;
3132

33+
[SerializeField] private HashSet<string> gitLocks;
3234
[SerializeField] private List<GitStatusEntry> gitStatusEntries;
3335

3436
[SerializeField] private string changedFilesText = NoChangedFilesLabel;
3537

3638
[SerializeField] private CacheUpdateEvent lastCurrentBranchChangedEvent;
3739
[SerializeField] private CacheUpdateEvent lastStatusEntriesChangedEvent;
40+
[SerializeField] private CacheUpdateEvent lastLocksChangedEvent;
3841

3942
public override void OnEnable()
4043
{
@@ -43,6 +46,7 @@ public override void OnEnable()
4346
AttachHandlers(Repository);
4447
Repository.CheckCurrentBranchChangedEvent(lastCurrentBranchChangedEvent);
4548
Repository.CheckStatusEntriesChangedEvent(lastStatusEntriesChangedEvent);
49+
Repository.CheckLocksChangedEvent(lastLocksChangedEvent);
4650
}
4751

4852
public override void OnDisable()
@@ -146,6 +150,16 @@ private void RepositoryOnCurrentBranchChanged(CacheUpdateEvent cacheUpdateEvent)
146150
}
147151
}
148152

153+
private void RepositoryOnLocksChanged(CacheUpdateEvent cacheUpdateEvent)
154+
{
155+
if (!lastLocksChangedEvent.Equals(cacheUpdateEvent))
156+
{
157+
lastLocksChangedEvent = cacheUpdateEvent;
158+
currentLocksHasUpdate = true;
159+
Redraw();
160+
}
161+
}
162+
149163
private void AttachHandlers(IRepository repository)
150164
{
151165
if (repository == null)
@@ -155,6 +169,7 @@ private void AttachHandlers(IRepository repository)
155169

156170
repository.CurrentBranchChanged += RepositoryOnCurrentBranchChanged;
157171
repository.StatusEntriesChanged += RepositoryOnStatusEntriesChanged;
172+
repository.LocksChanged += RepositoryOnLocksChanged;
158173
}
159174

160175
private void DetachHandlers(IRepository repository)
@@ -166,6 +181,7 @@ private void DetachHandlers(IRepository repository)
166181

167182
repository.CurrentBranchChanged -= RepositoryOnCurrentBranchChanged;
168183
repository.StatusEntriesChanged -= RepositoryOnStatusEntriesChanged;
184+
repository.LocksChanged -= RepositoryOnLocksChanged;
169185
}
170186

171187
private void MaybeUpdateData()
@@ -176,9 +192,12 @@ private void MaybeUpdateData()
176192
currentBranch = string.Format("[{0}]", Repository.CurrentBranchName);
177193
}
178194

179-
if (currentStatusEntriesHasUpdate)
195+
if (currentStatusEntriesHasUpdate || currentLocksHasUpdate)
180196
{
181197
currentStatusEntriesHasUpdate = false;
198+
currentLocksHasUpdate = false;
199+
200+
gitLocks = new HashSet<string>(Repository.CurrentLocks.Select(gitLock => gitLock.Path));
182201
gitStatusEntries = Repository.CurrentChanges.Where(x => x.Status != GitFileStatus.Ignored).ToList();
183202

184203
changedFilesText = gitStatusEntries.Count == 0
@@ -204,7 +223,7 @@ private void BuildTree()
204223
TreeOnEnable();
205224
}
206225

207-
treeChanges.Load(gitStatusEntries.Select(entry => new GitStatusEntryTreeData(entry)));
226+
treeChanges.Load(gitStatusEntries.Select(entry => new GitStatusEntryTreeData(entry, gitLocks.Contains(entry.Path))));
208227
Redraw();
209228
}
210229

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ private void MaybeUpdateData()
185185
{
186186
currentLocksHasUpdate = false;
187187
var repositoryCurrentLocks = Repository.CurrentLocks;
188+
lockedFileSelection = -1;
188189
lockedFiles = repositoryCurrentLocks != null
189190
? repositoryCurrentLocks.ToList()
190191
: new List<GitLock>();

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ protected Texture GetNodeIcon(TreeNode node)
633633
return nodeIcon;
634634
}
635635

636-
protected override TreeNode CreateTreeNode(string path, string label, int level, bool isFolder, bool isActive, bool isHidden, bool isCollapsed, GitBranchTreeData? treeData)
636+
protected override TreeNode CreateTreeNode(string path, string label, int level, bool isFolder, bool isActive, bool isHidden, bool isCollapsed, bool isChecked, GitBranchTreeData? treeData)
637637
{
638638
var node = new TreeNode {
639639
Path = path,
@@ -643,10 +643,11 @@ protected override TreeNode CreateTreeNode(string path, string label, int level,
643643
IsActive = isActive,
644644
IsHidden = isHidden,
645645
IsCollapsed = isCollapsed,
646-
TreeIsCheckable = IsCheckable
646+
TreeIsCheckable = IsCheckable,
647+
CheckState = isChecked ? CheckState.Checked: CheckState.Empty
647648
};
648649

649-
if (isFolder)
650+
if (isFolder && level >= 0)
650651
{
651652
folders.Add(node.Path, node);
652653
}

0 commit comments

Comments
 (0)