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

Commit 8baa257

Browse files
Merge branch 'enhancements/initialize-view' into fixes/initialize-view-with-configuration
2 parents faed518 + df2e7ee commit 8baa257

File tree

4 files changed

+152
-75
lines changed

4 files changed

+152
-75
lines changed

src/UnityExtension/Assets/Editor/GitHub.Unity/GitHub.Unity.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
<Compile Include="UI\IView.cs" />
103103
<Compile Include="UI\LoadingView.cs" />
104104
<Compile Include="UI\PublishView.cs" />
105+
<Compile Include="UI\InitProjectView.cs" />
105106
<Compile Include="UI\GitPathView.cs" />
106107
<Compile Include="UI\SettingsView.cs" />
107108
<Compile Include="UI\Subview.cs" />

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

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ class HistoryView : Subview
2828
private const string PushConfirmCancel = "Cancel";
2929
private const string CommitDetailsTitle = "Commit details";
3030
private const string ClearSelectionButton = "×";
31-
private const string NoRepoTitle = "No Git repository found for this project";
32-
private const string NoRepoDescription = "Initialize a Git repository to track changes and collaborate with others.";
3331
private const string PublishButton = "Publish";
3432
private const string FetchActionTitle = "Fetch Changes";
3533
private const string FetchButtonText = "Fetch";
@@ -116,12 +114,6 @@ public override void OnSelectionChange()
116114

117115
public override void OnGUI()
118116
{
119-
if (!HasRepository)
120-
{
121-
DoOfferToInitializeRepositoryGUI();
122-
return;
123-
}
124-
125117
OnEmbeddedGUI();
126118
}
127119

@@ -223,66 +215,6 @@ private void MaybeUpdateData()
223215
}
224216
}
225217

226-
private void DoOfferToInitializeRepositoryGUI()
227-
{
228-
var headerRect = EditorGUILayout.BeginHorizontal(Styles.HeaderBoxStyle);
229-
{
230-
GUILayout.Space(5);
231-
GUILayout.BeginVertical(GUILayout.Width(16));
232-
{
233-
GUILayout.Space(5);
234-
235-
var iconRect = GUILayoutUtility.GetRect(new GUIContent(Styles.BigLogo), GUIStyle.none, GUILayout.Height(20), GUILayout.Width(20));
236-
iconRect.y = headerRect.center.y - (iconRect.height / 2);
237-
GUI.DrawTexture(iconRect, Styles.BigLogo, ScaleMode.ScaleToFit);
238-
239-
GUILayout.Space(5);
240-
}
241-
GUILayout.EndVertical();
242-
243-
GUILayout.Space(5);
244-
245-
GUILayout.BeginVertical();
246-
{
247-
var headerContent = new GUIContent(NoRepoTitle);
248-
var headerTitleRect = GUILayoutUtility.GetRect(headerContent, Styles.HeaderTitleStyle);
249-
headerTitleRect.y = headerRect.center.y - (headerTitleRect.height / 2);
250-
251-
GUI.Label(headerTitleRect, headerContent, Styles.HeaderTitleStyle);
252-
}
253-
GUILayout.EndVertical();
254-
}
255-
EditorGUILayout.EndHorizontal();
256-
257-
GUILayout.BeginVertical(Styles.GenericBoxStyle);
258-
{
259-
GUILayout.FlexibleSpace();
260-
261-
GUILayout.Label(NoRepoDescription, Styles.CenteredLabel);
262-
263-
GUILayout.BeginHorizontal();
264-
GUILayout.FlexibleSpace();
265-
266-
EditorGUI.BeginDisabledGroup(isBusy);
267-
{
268-
if (GUILayout.Button(Localization.InitializeRepositoryButtonText, "Button"))
269-
{
270-
isBusy = true;
271-
Manager.InitializeRepository()
272-
.FinallyInUI(() => isBusy = false)
273-
.Start();
274-
}
275-
}
276-
EditorGUI.EndDisabledGroup();
277-
278-
GUILayout.FlexibleSpace();
279-
GUILayout.EndHorizontal();
280-
281-
GUILayout.FlexibleSpace();
282-
}
283-
GUILayout.EndVertical();
284-
}
285-
286218
public void OnEmbeddedGUI()
287219
{
288220
// History toolbar
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#pragma warning disable 649
2+
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using UnityEditor;
7+
using UnityEngine;
8+
using Object = UnityEngine.Object;
9+
10+
namespace GitHub.Unity
11+
{
12+
[Serializable]
13+
class InitProjectView : Subview
14+
{
15+
private const string NoRepoTitle = "No Git repository found for this project";
16+
private const string NoRepoDescription = "Initialize a Git repository to track changes and collaborate with others.";
17+
18+
[SerializeField] private bool isBusy;
19+
[SerializeField] private bool isPublished;
20+
21+
public override void OnDataUpdate()
22+
{
23+
base.OnDataUpdate();
24+
MaybeUpdateData();
25+
}
26+
27+
public override void OnRepositoryChanged(IRepository oldRepository)
28+
{
29+
base.OnRepositoryChanged(oldRepository);
30+
Refresh();
31+
}
32+
33+
public override bool IsBusy
34+
{
35+
get { return isBusy; }
36+
}
37+
38+
public override void OnGUI()
39+
{
40+
var headerRect = EditorGUILayout.BeginHorizontal(Styles.HeaderBoxStyle);
41+
{
42+
GUILayout.Space(5);
43+
GUILayout.BeginVertical(GUILayout.Width(16));
44+
{
45+
GUILayout.Space(5);
46+
47+
var iconRect = GUILayoutUtility.GetRect(new GUIContent(Styles.BigLogo), GUIStyle.none, GUILayout.Height(20), GUILayout.Width(20));
48+
iconRect.y = headerRect.center.y - (iconRect.height / 2);
49+
GUI.DrawTexture(iconRect, Styles.BigLogo, ScaleMode.ScaleToFit);
50+
51+
GUILayout.Space(5);
52+
}
53+
GUILayout.EndVertical();
54+
55+
GUILayout.Space(5);
56+
57+
GUILayout.BeginVertical();
58+
{
59+
var headerContent = new GUIContent(NoRepoTitle);
60+
var headerTitleRect = GUILayoutUtility.GetRect(headerContent, Styles.HeaderTitleStyle);
61+
headerTitleRect.y = headerRect.center.y - (headerTitleRect.height / 2);
62+
63+
GUI.Label(headerTitleRect, headerContent, Styles.HeaderTitleStyle);
64+
}
65+
GUILayout.EndVertical();
66+
}
67+
EditorGUILayout.EndHorizontal();
68+
69+
GUILayout.BeginVertical(Styles.GenericBoxStyle);
70+
{
71+
GUILayout.FlexibleSpace();
72+
73+
GUILayout.Label(NoRepoDescription, Styles.CenteredLabel);
74+
75+
GUILayout.BeginHorizontal();
76+
GUILayout.FlexibleSpace();
77+
78+
EditorGUI.BeginDisabledGroup(isBusy);
79+
{
80+
if (GUILayout.Button(Localization.InitializeRepositoryButtonText, "Button"))
81+
{
82+
isBusy = true;
83+
Manager.InitializeRepository()
84+
.FinallyInUI(() => isBusy = false)
85+
.Start();
86+
}
87+
}
88+
EditorGUI.EndDisabledGroup();
89+
90+
GUILayout.FlexibleSpace();
91+
GUILayout.EndHorizontal();
92+
93+
GUILayout.FlexibleSpace();
94+
}
95+
GUILayout.EndVertical();
96+
}
97+
98+
private void MaybeUpdateData()
99+
{
100+
isPublished = Repository != null && Repository.CurrentRemote.HasValue;
101+
}
102+
}
103+
}

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

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Window : BaseWindow
1414
private const string Title = "GitHub";
1515
private const string LaunchMenu = "Window/GitHub";
1616
private const string BadNotificationDelayError = "A delay of {0} is shorter than the default delay and thus would get pre-empted.";
17+
private const string InitializeTitle = "Initialize";
1718
private const string HistoryTitle = "History";
1819
private const string ChangesTitle = "Changes";
1920
private const string BranchesTitle = "Branches";
@@ -24,8 +25,10 @@ class Window : BaseWindow
2425
private const string Window_RepoBranchTooltip = "Active branch";
2526

2627
[NonSerialized] private double notificationClearTime = -1;
28+
[SerializeField] private SubTab? nextTab;
2729

2830
[SerializeField] private SubTab activeTab = SubTab.History;
31+
[SerializeField] private InitProjectView initProjectView = new InitProjectView();
2932
[SerializeField] private BranchesView branchesView = new BranchesView();
3033
[SerializeField] private ChangesView changesView = new ChangesView();
3134
[SerializeField] private HistoryView historyView = new HistoryView();
@@ -75,6 +78,7 @@ public override void Initialize(IApplicationManager applicationManager)
7578
ChangesView.InitializeView(this);
7679
BranchesView.InitializeView(this);
7780
SettingsView.InitializeView(this);
81+
InitProjectView.InitializeView(this);
7882
}
7983

8084
public override void OnEnable()
@@ -158,6 +162,12 @@ public override void OnUI()
158162

159163
DoToolbarGUI();
160164

165+
if (nextTab.HasValue)
166+
{
167+
SetActiveTab(nextTab.Value);
168+
nextTab = null;
169+
}
170+
161171
// GUI for the active tab
162172
if (ActiveView != null)
163173
{
@@ -189,6 +199,15 @@ private bool MaybeUpdateData(out string repoRemote)
189199
bool repoDataChanged = false;
190200
if (Repository != null)
191201
{
202+
if (activeTab == SubTab.InitProject)
203+
{
204+
if (!nextTab.HasValue || nextTab.Value == SubTab.InitProject)
205+
{
206+
nextTab = SubTab.History;
207+
repoDataChanged = true;
208+
}
209+
}
210+
192211
var currentBranchString = (Repository.CurrentBranch.HasValue ? Repository.CurrentBranch.Value.Name : null);
193212
if (repoBranch != currentBranchString)
194213
{
@@ -206,8 +225,17 @@ private bool MaybeUpdateData(out string repoRemote)
206225
if (Repository.CurrentRemote.HasValue)
207226
repoRemote = Repository.CurrentRemote.Value.Name;
208227
}
209-
else if (!HasRepository)
228+
else
210229
{
230+
if (!(activeTab == SubTab.InitProject || activeTab == SubTab.Settings))
231+
{
232+
if (!nextTab.HasValue || nextTab.Value != SubTab.InitProject)
233+
{
234+
nextTab = SubTab.InitProject;
235+
repoDataChanged = true;
236+
}
237+
}
238+
211239
if (repoBranch != null)
212240
{
213241
repoBranch = null;
@@ -237,7 +265,6 @@ private void DetachHandlers(IRepository repository)
237265
return;
238266
repository.OnRepositoryInfoChanged -= RefreshOnMainThread;
239267
}
240-
241268
private void DoHeaderGUI()
242269
{
243270
GUILayout.BeginHorizontal(Styles.HeaderBoxStyle);
@@ -279,14 +306,14 @@ private void DoToolbarGUI()
279306
}
280307
else
281308
{
282-
changeTab = TabButton(SubTab.History, HistoryTitle, changeTab);
309+
changeTab = TabButton(SubTab.InitProject, InitializeTitle, changeTab);
283310
}
284311
changeTab = TabButton(SubTab.Settings, SettingsTitle, changeTab);
285312
}
286313

287314
if (EditorGUI.EndChangeCheck())
288315
{
289-
SetActiveTab(changeTab);
316+
nextTab = changeTab;
290317
}
291318

292319
GUILayout.FlexibleSpace();
@@ -400,9 +427,9 @@ public SettingsView SettingsView
400427
get { return settingsView; }
401428
}
402429

403-
public override bool IsBusy
430+
public InitProjectView InitProjectView
404431
{
405-
get { return false; }
432+
get { return initProjectView; }
406433
}
407434

408435
private Subview ActiveView
@@ -417,20 +444,34 @@ private Subview ToView(SubTab tab)
417444
{
418445
switch (tab)
419446
{
447+
case SubTab.InitProject:
448+
return initProjectView;
449+
420450
case SubTab.History:
421451
return historyView;
452+
422453
case SubTab.Changes:
423454
return changesView;
455+
424456
case SubTab.Branches:
425457
return branchesView;
458+
426459
case SubTab.Settings:
427-
default:
428460
return settingsView;
461+
462+
default:
463+
throw new ArgumentOutOfRangeException();
464+
}
465+
466+
public override bool IsBusy
467+
{
468+
get { return false; }
429469
}
430470
}
431471

432472
private enum SubTab
433473
{
474+
InitProject,
434475
History,
435476
Changes,
436477
Branches,

0 commit comments

Comments
 (0)