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

Commit 8dab7ad

Browse files
Merge branch 'master' into fixes/tree-retains-checked-state
# Conflicts: # src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesTreeControl.cs
2 parents 1ca009a + a513bee commit 8dab7ad

File tree

7 files changed

+75
-30
lines changed

7 files changed

+75
-30
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/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/BranchesView.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ private void OnButtonBarGUI()
304304

305305
private void OnTreeGUI(Rect rect)
306306
{
307-
var initialRect = rect;
307+
var treeRenderRect = Rect.zero;
308308
if (treeLocals != null && treeRemotes != null)
309309
{
310310
treeLocals.FolderStyle = Styles.Foldout;
@@ -321,7 +321,7 @@ private void OnTreeGUI(Rect rect)
321321

322322
var treeHadFocus = treeLocals.SelectedNode != null;
323323

324-
rect = treeLocals.Render(initialRect, rect, scroll,
324+
treeRenderRect = treeLocals.Render(rect, scroll,
325325
node => { },
326326
node => {
327327
if (node.IsFolder)
@@ -350,10 +350,11 @@ private void OnTreeGUI(Rect rect)
350350

351351
treeHadFocus = treeRemotes.SelectedNode != null;
352352

353-
rect.y += Styles.TreePadding;
353+
treeRenderRect.y += Styles.TreePadding;
354354

355-
rect = treeRemotes.Render(initialRect, rect, scroll,
356-
node => { },
355+
var treeRemoteDisplayRect = new Rect(rect.x, treeRenderRect.y, rect.width, rect.height);
356+
treeRenderRect = treeRemotes.Render(treeRemoteDisplayRect, scroll,
357+
node => { },
357358
node => {
358359
if (node.IsFolder)
359360
return;
@@ -377,7 +378,7 @@ private void OnTreeGUI(Rect rect)
377378
Redraw();
378379
}
379380

380-
GUILayout.Space(rect.y - initialRect.y);
381+
GUILayout.Space(treeRenderRect.y - rect.y);
381382
}
382383

383384
private GenericMenu CreateContextMenuForLocalBranchNode(TreeNode node)

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

Lines changed: 22 additions & 3 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

156163
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,
@@ -166,8 +184,9 @@ protected override ChangesTreeNode CreateTreeNode(string path, string label, int
166184
IsCollapsed = isCollapsed,
167185
TreeIsCheckable = IsCheckable,
168186
CheckState = isChecked ? CheckState.Checked : CheckState.Empty,
169-
GitFileStatus = treeData.HasValue ? treeData.Value.FileStatus : GitFileStatus.None,
170-
ProjectPath = treeData.HasValue ? treeData.Value.ProjectPath : null
187+
GitFileStatus = gitFileStatus,
188+
ProjectPath = projectPath,
189+
IsLocked = isLocked
171190
};
172191

173192
if (isFolder && level >= 0)

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

Lines changed: 26 additions & 10 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 = "";
@@ -28,7 +29,9 @@ class ChangesView : Subview
2829
[SerializeField] private Vector2 scroll;
2930
[SerializeField] private CacheUpdateEvent lastCurrentBranchChangedEvent;
3031
[SerializeField] private CacheUpdateEvent lastStatusEntriesChangedEvent;
32+
[SerializeField] private CacheUpdateEvent lastLocksChangedEvent;
3133
[SerializeField] private ChangesTree treeChanges;
34+
[SerializeField] private HashSet<string> gitLocks;
3235
[SerializeField] private List<GitStatusEntry> gitStatusEntries;
3336
[SerializeField] private string changedFilesText = NoChangedFilesLabel;
3437

@@ -39,6 +42,7 @@ public override void OnEnable()
3942
AttachHandlers(Repository);
4043
Repository.CheckCurrentBranchChangedEvent(lastCurrentBranchChangedEvent);
4144
Repository.CheckStatusEntriesChangedEvent(lastStatusEntriesChangedEvent);
45+
Repository.CheckLocksChangedEvent(lastLocksChangedEvent);
4246
}
4347

4448
public override void OnDisable()
@@ -102,7 +106,6 @@ public override void OnSelectionChange()
102106

103107
private void OnTreeGUI(Rect rect)
104108
{
105-
var initialRect = rect;
106109
if (treeChanges != null)
107110
{
108111
treeChanges.FolderStyle = Styles.Foldout;
@@ -111,18 +114,16 @@ private void OnTreeGUI(Rect rect)
111114
treeChanges.FocusedTreeNodeStyle = Styles.FocusedTreeNode;
112115
treeChanges.FocusedActiveTreeNodeStyle = Styles.FocusedActiveTreeNode;
113116

114-
rect = treeChanges.Render(initialRect, rect, scroll,
117+
var treeRenderRect = treeChanges.Render(rect, scroll,
118+
node => { },
115119
node => { },
116-
node => {
117-
},
118-
node => {
119-
});
120+
node => { });
120121

121122
if (treeChanges.RequiresRepaint)
122123
Redraw();
123-
}
124124

125-
GUILayout.Space(rect.y - initialRect.y);
125+
GUILayout.Space(treeRenderRect.y - rect.y);
126+
}
126127
}
127128

128129
private void RepositoryOnStatusEntriesChanged(CacheUpdateEvent cacheUpdateEvent)
@@ -145,6 +146,16 @@ private void RepositoryOnCurrentBranchChanged(CacheUpdateEvent cacheUpdateEvent)
145146
}
146147
}
147148

149+
private void RepositoryOnLocksChanged(CacheUpdateEvent cacheUpdateEvent)
150+
{
151+
if (!lastLocksChangedEvent.Equals(cacheUpdateEvent))
152+
{
153+
lastLocksChangedEvent = cacheUpdateEvent;
154+
currentLocksHasUpdate = true;
155+
Redraw();
156+
}
157+
}
158+
148159
private void AttachHandlers(IRepository repository)
149160
{
150161
if (repository == null)
@@ -154,6 +165,7 @@ private void AttachHandlers(IRepository repository)
154165

155166
repository.CurrentBranchChanged += RepositoryOnCurrentBranchChanged;
156167
repository.StatusEntriesChanged += RepositoryOnStatusEntriesChanged;
168+
repository.LocksChanged += RepositoryOnLocksChanged;
157169
}
158170

159171
private void DetachHandlers(IRepository repository)
@@ -165,6 +177,7 @@ private void DetachHandlers(IRepository repository)
165177

166178
repository.CurrentBranchChanged -= RepositoryOnCurrentBranchChanged;
167179
repository.StatusEntriesChanged -= RepositoryOnStatusEntriesChanged;
180+
repository.LocksChanged -= RepositoryOnLocksChanged;
168181
}
169182

170183
private void MaybeUpdateData()
@@ -175,9 +188,12 @@ private void MaybeUpdateData()
175188
currentBranch = string.Format("[{0}]", Repository.CurrentBranchName);
176189
}
177190

178-
if (currentStatusEntriesHasUpdate)
191+
if (currentStatusEntriesHasUpdate || currentLocksHasUpdate)
179192
{
180193
currentStatusEntriesHasUpdate = false;
194+
currentLocksHasUpdate = false;
195+
196+
gitLocks = new HashSet<string>(Repository.CurrentLocks.Select(gitLock => gitLock.Path));
181197
gitStatusEntries = Repository.CurrentChanges.Where(x => x.Status != GitFileStatus.Ignored).ToList();
182198

183199
changedFilesText = gitStatusEntries.Count == 0
@@ -203,7 +219,7 @@ private void BuildTree()
203219
TreeOnEnable();
204220
}
205221

206-
treeChanges.Load(gitStatusEntries.Select(entry => new GitStatusEntryTreeData(entry)));
222+
treeChanges.Load(gitStatusEntries.Select(entry => new GitStatusEntryTreeData(entry, gitLocks.Contains(entry.Path))));
207223
Redraw();
208224
}
209225

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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public abstract class Tree<TNode, TData>: TreeBase<TNode, TData>
3535
public bool IsInitialized { get { return Nodes != null && Nodes.Count > 0 && !String.IsNullOrEmpty(Nodes[0].Path); } }
3636
public bool RequiresRepaint { get; private set; }
3737

38-
public Rect Render(Rect containingRect, Rect rect, Vector2 scroll, Action<TNode> singleClick = null, Action<TNode> doubleClick = null, Action<TNode> rightClick = null)
38+
public Rect Render(Rect treeDisplayRect, Vector2 scroll, Action<TNode> singleClick = null, Action<TNode> doubleClick = null, Action<TNode> rightClick = null)
3939
{
4040
if (Selection.activeObject != selectionObject)
4141
{
@@ -46,7 +46,7 @@ public Rect Render(Rect containingRect, Rect rect, Vector2 scroll, Action<TNode>
4646
var treeHasFocus = GUIUtility.keyboardControl == controlId;
4747

4848
if (!Nodes.Any())
49-
return new Rect(0f, rect.y, 0f, 0f);
49+
return new Rect(treeDisplayRect.x, treeDisplayRect.y, 0f, 0f);
5050

5151
var treeNodeStyle = TreeNodeStyle;
5252
var activeTreeNodeStyle = ActiveTreeNodeStyle;
@@ -68,10 +68,10 @@ public Rect Render(Rect containingRect, Rect rect, Vector2 scroll, Action<TNode>
6868
}
6969

7070
var startDisplay = scroll.y;
71-
var endDisplay = scroll.y + containingRect.height;
71+
var endDisplay = scroll.y + treeDisplayRect.height;
7272

7373
RequiresRepaint = false;
74-
rect = new Rect(0f, rect.y, rect.width, ItemHeight);
74+
var rect = new Rect(treeDisplayRect.x, treeDisplayRect.y, treeDisplayRect.width, ItemHeight);
7575

7676
var level = 0;
7777

@@ -137,6 +137,7 @@ public Rect Render(Rect containingRect, Rect rect, Vector2 scroll, Action<TNode>
137137
Unindent();
138138
}
139139
}
140+
140141
level = node.Level;
141142

142143
if (!node.IsHidden)

0 commit comments

Comments
 (0)