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

Commit 1b17338

Browse files
Displaying the new Tree control
1 parent bc4947c commit 1b17338

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

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

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ class ChangesView : Subview
2525
[SerializeField] private string commitBody = "";
2626
[SerializeField] private string commitMessage = "";
2727
[SerializeField] private string currentBranch = "[unknown]";
28-
[SerializeField] private Vector2 horizontalScroll;
28+
[SerializeField] private Vector2 scroll;
2929
[SerializeField] private CacheUpdateEvent lastCurrentBranchChangedEvent;
3030
[SerializeField] private CacheUpdateEvent lastStatusChangedEvent;
31+
[SerializeField] private Tree treeChanges = new Tree();
32+
[SerializeField] private List<GitStatusEntry> gitStatusEntries;
3133

3234
public override void OnEnable()
3335
{
@@ -83,15 +85,48 @@ public override void OnGUI()
8385
}
8486
GUILayout.EndHorizontal();
8587

86-
horizontalScroll = GUILayout.BeginScrollView(horizontalScroll);
88+
var rect = GUILayoutUtility.GetLastRect();
89+
scroll = GUILayout.BeginScrollView(scroll);
8790
{
91+
OnTreeGUI(new Rect(0f, 0f, Position.width, Position.height - rect.height + Styles.CommitAreaPadding));
8892
}
8993
GUILayout.EndScrollView();
9094

9195
// Do the commit details area
9296
OnCommitDetailsAreaGUI();
9397
}
9498

99+
private void OnTreeGUI(Rect rect)
100+
{
101+
var initialRect = rect;
102+
103+
if (treeChanges.FolderStyle == null)
104+
{
105+
treeChanges.FolderStyle = Styles.Foldout;
106+
treeChanges.TreeNodeStyle = Styles.TreeNode;
107+
treeChanges.ActiveTreeNodeStyle = Styles.TreeNodeActive;
108+
}
109+
110+
var treeHadFocus = treeChanges.SelectedNode != null;
111+
112+
rect = treeChanges.Render(rect, scroll,
113+
node => { },
114+
node => {
115+
},
116+
node => {
117+
});
118+
119+
if (treeHadFocus && treeChanges.SelectedNode == null)
120+
treeChanges.Focus();
121+
else if (!treeHadFocus && treeChanges.SelectedNode != null)
122+
treeChanges.Blur();
123+
124+
if (treeChanges.RequiresRepaint)
125+
Redraw();
126+
127+
GUILayout.Space(rect.y - initialRect.y);
128+
}
129+
95130
private void RepositoryOnStatusChanged(CacheUpdateEvent cacheUpdateEvent)
96131
{
97132
if (!lastStatusChangedEvent.Equals(cacheUpdateEvent))
@@ -145,9 +180,23 @@ private void MaybeUpdateData()
145180
if (currentStatusHasUpdate)
146181
{
147182
currentStatusHasUpdate = false;
183+
gitStatusEntries = Repository.CurrentStatus.Entries;
184+
185+
BuildTree();
148186
}
149187
}
150188

189+
private void BuildTree()
190+
{
191+
treeChanges = new Tree();
192+
treeChanges.ActiveNodeIcon = Styles.ActiveBranchIcon;
193+
treeChanges.NodeIcon = Styles.BranchIcon;
194+
treeChanges.FolderIcon = Styles.FolderIcon;
195+
196+
treeChanges.Load(gitStatusEntries.Select(entry => new GitStatusEntryTreeData(entry)).Cast<ITreeData>(), "Changes");
197+
Redraw();
198+
}
199+
151200
private void OnCommitDetailsAreaGUI()
152201
{
153202
GUILayout.BeginHorizontal();

0 commit comments

Comments
 (0)