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

Commit a513bee

Browse files
Merge pull request #532 from github-for-unity/fixes/changes-view-lock-icons
Functionality to use lock data in ChangesTreeView Icons
2 parents f91c428 + f828fa3 commit a513bee

File tree

4 files changed

+48
-7
lines changed

4 files changed

+48
-7
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/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, 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,8 +183,9 @@ 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+
GitFileStatus = gitFileStatus,
187+
ProjectPath = projectPath,
188+
IsLocked = isLocked
170189
};
171190

172191
if (isFolder)

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 = "";
@@ -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()
@@ -142,6 +146,16 @@ private void RepositoryOnCurrentBranchChanged(CacheUpdateEvent cacheUpdateEvent)
142146
}
143147
}
144148

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

152166
repository.CurrentBranchChanged += RepositoryOnCurrentBranchChanged;
153167
repository.StatusEntriesChanged += RepositoryOnStatusEntriesChanged;
168+
repository.LocksChanged += RepositoryOnLocksChanged;
154169
}
155170

156171
private void DetachHandlers(IRepository repository)
@@ -162,6 +177,7 @@ private void DetachHandlers(IRepository repository)
162177

163178
repository.CurrentBranchChanged -= RepositoryOnCurrentBranchChanged;
164179
repository.StatusEntriesChanged -= RepositoryOnStatusEntriesChanged;
180+
repository.LocksChanged -= RepositoryOnLocksChanged;
165181
}
166182

167183
private void MaybeUpdateData()
@@ -172,9 +188,12 @@ private void MaybeUpdateData()
172188
currentBranch = string.Format("[{0}]", Repository.CurrentBranchName);
173189
}
174190

175-
if (currentStatusEntriesHasUpdate)
191+
if (currentStatusEntriesHasUpdate || currentLocksHasUpdate)
176192
{
177193
currentStatusEntriesHasUpdate = false;
194+
currentLocksHasUpdate = false;
195+
196+
gitLocks = new HashSet<string>(Repository.CurrentLocks.Select(gitLock => gitLock.Path));
178197
gitStatusEntries = Repository.CurrentChanges.Where(x => x.Status != GitFileStatus.Ignored).ToList();
179198

180199
changedFilesText = gitStatusEntries.Count == 0
@@ -200,7 +219,7 @@ private void BuildTree()
200219
TreeOnEnable();
201220
}
202221

203-
treeChanges.Load(gitStatusEntries.Select(entry => new GitStatusEntryTreeData(entry)));
222+
treeChanges.Load(gitStatusEntries.Select(entry => new GitStatusEntryTreeData(entry, gitLocks.Contains(entry.Path))));
204223
Redraw();
205224
}
206225

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>();

0 commit comments

Comments
 (0)