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

Commit 565b080

Browse files
committed
Add a nice background when views are empty, and add a busy state to the changes view
1 parent 6718467 commit 565b080

File tree

7 files changed

+100
-45
lines changed

7 files changed

+100
-45
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public virtual void OnDataUpdate()
6565
public virtual void OnRepositoryChanged(IRepository oldRepository)
6666
{}
6767

68+
public virtual void DoEmptyGUI()
69+
{}
70+
6871
// OnGUI calls this everytime, so override it to render as you would OnGUI
6972
public virtual void OnUI() {}
7073

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

Lines changed: 58 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class ChangesView : Subview
3939
[SerializeField] private CacheUpdateEvent lastCurrentBranchChangedEvent;
4040
[SerializeField] private CacheUpdateEvent lastStatusEntriesChangedEvent;
4141
[SerializeField] private CacheUpdateEvent lastLocksChangedEvent;
42+
[SerializeField] private bool isBusy;
4243

4344
public override void OnEnable()
4445
{
@@ -76,43 +77,23 @@ public override void OnDataUpdate()
7677

7778
public override void OnGUI()
7879
{
79-
GUILayout.BeginHorizontal();
80+
DoButtonBarGUI();
81+
if (gitStatusEntries.Count == 0)
8082
{
81-
EditorGUI.BeginDisabledGroup(gitStatusEntries == null || !gitStatusEntries.Any());
82-
{
83-
if (GUILayout.Button(SelectAllButton, EditorStyles.miniButtonLeft))
84-
{
85-
SelectAll();
86-
}
87-
88-
if (GUILayout.Button(SelectNoneButton, EditorStyles.miniButtonRight))
89-
{
90-
SelectNone();
91-
}
92-
}
93-
EditorGUI.EndDisabledGroup();
94-
95-
GUILayout.FlexibleSpace();
96-
97-
GUILayout.Label(changedFilesText, EditorStyles.miniLabel);
83+
GUILayout.BeginVertical(Styles.CommitFileAreaStyle);
84+
DoEmptyGUI();
85+
GUILayout.EndVertical();
9886
}
99-
GUILayout.EndHorizontal();
100-
101-
var rect = GUILayoutUtility.GetLastRect();
102-
GUILayout.BeginHorizontal();
103-
GUILayout.BeginVertical(Styles.CommitFileAreaStyle);
87+
else
10488
{
105-
treeScroll = GUILayout.BeginScrollView(treeScroll);
106-
{
107-
OnTreeGUI(new Rect(0f, 0f, Position.width, Position.height - rect.height + Styles.CommitAreaPadding));
108-
}
109-
GUILayout.EndScrollView();
89+
EditorGUI.BeginDisabledGroup(isBusy);
90+
DoChangesTreeGUI();
91+
EditorGUI.EndDisabledGroup();
11092
}
111-
GUILayout.EndVertical();
112-
GUILayout.EndHorizontal();
113-
93+
EditorGUI.BeginDisabledGroup(isBusy);
11494
// Do the commit details area
11595
OnCommitDetailsAreaGUI();
96+
EditorGUI.EndDisabledGroup();
11697
}
11798

11899
public override void OnSelectionChange()
@@ -135,6 +116,47 @@ public override void OnFocusChanged()
135116
}
136117
}
137118

119+
private void DoChangesTreeGUI()
120+
{
121+
var rect = GUILayoutUtility.GetLastRect();
122+
GUILayout.BeginHorizontal();
123+
GUILayout.BeginVertical(Styles.CommitFileAreaStyle);
124+
{
125+
treeScroll = GUILayout.BeginScrollView(treeScroll);
126+
{
127+
OnTreeGUI(new Rect(0f, 0f, Position.width, Position.height - rect.height + Styles.CommitAreaPadding));
128+
}
129+
GUILayout.EndScrollView();
130+
}
131+
GUILayout.EndVertical();
132+
GUILayout.EndHorizontal();
133+
}
134+
135+
private void DoButtonBarGUI()
136+
{
137+
GUILayout.BeginHorizontal();
138+
{
139+
EditorGUI.BeginDisabledGroup(gitStatusEntries == null || gitStatusEntries.Count == 0);
140+
{
141+
if (GUILayout.Button(SelectAllButton, EditorStyles.miniButtonLeft))
142+
{
143+
SelectAll();
144+
}
145+
146+
if (GUILayout.Button(SelectNoneButton, EditorStyles.miniButtonRight))
147+
{
148+
SelectNone();
149+
}
150+
}
151+
EditorGUI.EndDisabledGroup();
152+
153+
GUILayout.FlexibleSpace();
154+
155+
GUILayout.Label(changedFilesText, EditorStyles.miniLabel);
156+
}
157+
GUILayout.EndHorizontal();
158+
}
159+
138160
private void OnTreeGUI(Rect rect)
139161
{
140162
if (treeChanges != null)
@@ -376,5 +398,10 @@ private void Commit()
376398
}
377399
}).Start();
378400
}
401+
402+
public override bool IsBusy
403+
{
404+
get { return isBusy || base.IsBusy; }
405+
}
379406
}
380407
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace GitHub.Unity
55
{
6-
interface IView
6+
interface IView : ICanRenderEmpty
77
{
88
void OnEnable();
99
void OnDisable();
@@ -20,4 +20,9 @@ interface IView
2020
bool IsBusy { get; }
2121
bool HasFocus { get; }
2222
}
23+
24+
interface ICanRenderEmpty
25+
{
26+
void DoEmptyGUI();
27+
}
2328
}

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,7 @@ public override void OnGUI()
4646
GUILayout.FlexibleSpace();
4747
GUILayout.Space(-140);
4848

49-
GUILayout.BeginHorizontal();
50-
{
51-
GUILayout.FlexibleSpace();
52-
GUILayout.Label(Styles.EmptyStateInit, GUILayout.MaxWidth(265), GUILayout.MaxHeight(136));
53-
GUILayout.FlexibleSpace();
54-
}
55-
GUILayout.EndHorizontal();
49+
DoEmptyGUI();
5650

5751
GUILayout.Label(NoRepoTitle, Styles.BoldCenteredLabel);
5852
GUILayout.Space(4);

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class LocksControl
5757
[SerializeField] public GitLockEntryDictionary assets = new GitLockEntryDictionary();
5858
[SerializeField] public GitStatusDictionary gitStatusDictionary = new GitStatusDictionary();
5959
[SerializeField] private GitLockEntry selectedEntry;
60+
public bool IsEmpty { get { return gitLockEntries.Count == 0; } }
6061

6162
public GitLockEntry SelectedEntry
6263
{
@@ -423,15 +424,17 @@ public override void OnGUI()
423424

424425
EditorGUI.BeginDisabledGroup(IsBusy);
425426

426-
if (locksControl != null)
427+
if (locksControl != null && !locksControl.IsEmpty)
427428
{
428429
var lockControlRect = new Rect(rect.x, rect.y, Position.width, Position.height - rect.height);
429430

430431
var requiresRepaint = locksControl.Render(lockControlRect,
431-
entry => {
432+
entry =>
433+
{
432434
},
433-
entry => { },
434-
entry => {
435+
entry => { },
436+
entry =>
437+
{
435438
var menu = new GenericMenu();
436439
if (entry.Owner.Name == currentUsername)
437440
{
@@ -444,6 +447,10 @@ public override void OnGUI()
444447
if (requiresRepaint)
445448
Redraw();
446449
}
450+
else
451+
{
452+
DoEmptyGUI();
453+
}
447454

448455
EditorGUI.EndDisabledGroup();
449456
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ public virtual void Finish(bool result)
4545
Parent.Finish(result);
4646
}
4747

48+
public void DoEmptyGUI()
49+
{
50+
Parent.DoEmptyGUI();
51+
}
52+
4853
protected IView Parent { get; private set; }
4954
public IApplicationManager Manager { get { return Parent.Manager; } }
5055
public IRepository Repository { get { return Parent.Repository; } }

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace GitHub.Unity
77
{
88
[Serializable]
9-
class Window : BaseWindow
9+
class Window : BaseWindow, ICanRenderEmpty
1010
{
1111
private const float DefaultNotificationTimeout = 4f;
1212
private const string Title = "GitHub";
@@ -185,7 +185,6 @@ public override void Refresh()
185185
Repaint();
186186
}
187187

188-
189188
public override void OnUI()
190189
{
191190
base.OnUI();
@@ -547,6 +546,21 @@ private void DoActionbarGUI()
547546
EditorGUILayout.EndHorizontal();
548547
}
549548

549+
public override void DoEmptyGUI()
550+
{
551+
GUILayout.BeginVertical();
552+
GUILayout.FlexibleSpace();
553+
GUILayout.BeginHorizontal();
554+
{
555+
GUILayout.FlexibleSpace();
556+
GUILayout.Label(Styles.EmptyStateInit, GUILayout.MaxWidth(265), GUILayout.MaxHeight(136));
557+
GUILayout.FlexibleSpace();
558+
}
559+
GUILayout.EndHorizontal();
560+
GUILayout.FlexibleSpace();
561+
GUILayout.EndVertical();
562+
}
563+
550564
private void Pull()
551565
{
552566
if (hasItemsToCommit)

0 commit comments

Comments
 (0)