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

Commit 7a5abbd

Browse files
Merge branch 'master' into fixes/repository-refactor
2 parents c4aeec6 + d4c5ec9 commit 7a5abbd

File tree

10 files changed

+172
-127
lines changed

10 files changed

+172
-127
lines changed

build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh -eux
1+
#!/bin/sh -eu
22
Configuration="dev"
33
if [ $# -gt 0 ]; then
44
Configuration=$1
@@ -32,7 +32,7 @@ else
3232
nuget restore GitHub.Unity.sln
3333
fi
3434

35-
xbuild GitHub.Unity.sln /verbosity:normal /property:Configuration=$Configuration /target:$Target || true
35+
xbuild GitHub.Unity.sln /verbosity:minimal /property:Configuration=$Configuration /target:$Target || true
3636

3737
rm -f unity/PackageProject/Assets/Plugins/GitHub/Editor/deleteme*
3838
rm -f unity/PackageProject/Assets/Plugins/GitHub/Editor/deleteme*

common/SolutionInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
namespace System
3232
{
3333
internal static class AssemblyVersionInformation {
34-
internal const string Version = "0.21.0";
34+
internal const string Version = "0.22.0";
3535
}
3636
}

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public ApplicationManagerBase(SynchronizationContext synchronizationContext)
1717
{
1818
SynchronizationContext = synchronizationContext;
1919
SynchronizationContext.SetSynchronizationContext(SynchronizationContext);
20-
ThreadingHelper.SetMainThread();
20+
ThreadingHelper.SetUIThread();
2121
UIScheduler = TaskScheduler.FromCurrentSynchronizationContext();
2222
ThreadingHelper.MainThreadScheduler = UIScheduler;
2323
TaskManager = new TaskManager(UIScheduler);

src/GitHub.Api/Threading/ThreadingHelper.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ static class ThreadingHelper
1010
public static TaskScheduler MainThreadScheduler { get; set; }
1111

1212
public static int MainThread { get; set; }
13-
public static bool InMainThread { get { return MainThread == 0 || Thread.CurrentThread.ManagedThreadId == MainThread; } }
13+
static bool InMainThread { get { return MainThread == 0 || Thread.CurrentThread.ManagedThreadId == MainThread; } }
1414

15-
public static void SetMainThread()
15+
public static void SetUIThread()
1616
{
1717
MainThread = Thread.CurrentThread.ManagedThreadId;
1818
}
1919

20-
public static bool InUIThread => (!Guard.InUnitTestRunner && InMainThread) || !(Guard.InUnitTestRunner);
20+
public static bool InUIThread => InMainThread || Guard.InUnitTestRunner;
2121

2222
/// <summary>
2323
/// Switch to the UI thread
@@ -97,7 +97,7 @@ public bool IsCompleted
9797
{
9898
get
9999
{
100-
return (this.scheduler == TaskManager.Instance.UIScheduler && InMainThread) || (this.scheduler != TaskManager.Instance.UIScheduler && !InMainThread);
100+
return (this.scheduler == TaskManager.Instance.UIScheduler && InUIThread) || (this.scheduler != TaskManager.Instance.UIScheduler && !InUIThread);
101101
}
102102
}
103103

src/UnityExtension/Assets/Editor/GitHub.Unity/EntryPoint.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ private static void Initialize()
3737

3838
if (ApplicationCache.Instance.FirstRun)
3939
{
40-
Debug.Log("Initialized GitHub for Unity version " + ApplicationInfo.Version);
41-
4240
var oldLogPath = logPath.Parent.Combine(logPath.FileNameWithoutExtension + "-old" + logPath.ExtensionWithDot);
4341
try
4442
{
@@ -53,8 +51,9 @@ private static void Initialize()
5351
Logging.Error(ex, "Error rotating log files");
5452
}
5553

56-
Debug.Log("Initialized GitHub for Unity log file: " + logPath);
54+
Debug.LogFormat("Initialized GitHub for Unity version {0}{1}Log file: {2}", ApplicationInfo.Version, Environment.NewLine, logPath);
5755
}
56+
5857
Logging.LogAdapter = new FileLogAdapter(logPath);
5958
Logging.Info("Initializing GitHub for Unity version " + ApplicationInfo.Version);
6059

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\UserSettingsView.cs" />
106107
<Compile Include="UI\GitPathView.cs" />
107108
<Compile Include="UI\SettingsView.cs" />

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

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,15 @@ public virtual void Initialize(IApplicationManager applicationManager)
1717
Logger.Trace("Initialize ApplicationManager:{0} Initialized:{1}", applicationManager, initialized);
1818
}
1919

20-
public void InitializeWindow(IApplicationManager applicationManager)
20+
public void InitializeWindow(IApplicationManager applicationManager, bool requiresRedraw = true)
2121
{
22-
if (inLayout)
23-
{
24-
initializeWasCalled = true;
25-
cachedManager = applicationManager;
26-
return;
27-
}
28-
22+
initialized = true;
23+
initializeWasCalled = true;
2924
Manager = applicationManager;
3025
cachedRepository = Environment.Repository;
31-
initialized = true;
3226
Initialize(applicationManager);
33-
OnRepositoryChanged(null);
34-
Redraw();
27+
if (requiresRedraw)
28+
Redraw();
3529
}
3630

3731
public virtual void Redraw()
@@ -51,14 +45,14 @@ public virtual void Awake()
5145
{
5246
Logger.Trace("Awake Initialized:{0}", initialized);
5347
if (!initialized)
54-
InitializeWindow(EntryPoint.ApplicationManager);
48+
InitializeWindow(EntryPoint.ApplicationManager, false);
5549
}
5650

5751
public virtual void OnEnable()
5852
{
5953
Logger.Trace("OnEnable Initialized:{0}", initialized);
6054
if (!initialized)
61-
InitializeWindow(EntryPoint.ApplicationManager);
55+
InitializeWindow(EntryPoint.ApplicationManager, false);
6256
}
6357

6458
public virtual void OnDisable()
@@ -81,8 +75,9 @@ private void OnGUI()
8175
{
8276
if (Event.current.type == EventType.layout)
8377
{
84-
if (cachedRepository != Environment.Repository)
78+
if (cachedRepository != Environment.Repository || initializeWasCalled)
8579
{
80+
initializeWasCalled = false;
8681
OnRepositoryChanged(cachedRepository);
8782
cachedRepository = Environment.Repository;
8883
}
@@ -95,11 +90,6 @@ private void OnGUI()
9590
if (Event.current.type == EventType.repaint)
9691
{
9792
inLayout = false;
98-
if (initializeWasCalled)
99-
{
100-
initializeWasCalled = false;
101-
InitializeWindow(cachedManager);
102-
}
10393
}
10494
}
10595

@@ -113,7 +103,7 @@ public virtual void OnSelectionChange()
113103
public IApplicationManager Manager { get; private set; }
114104
public abstract bool IsBusy { get; }
115105
public IRepository Repository { get { return inLayout ? cachedRepository : Environment.Repository; } }
116-
public bool HasRepository { get { return Environment.RepositoryPath != null; } }
106+
public bool HasRepository { get { return Repository != null; } }
117107

118108
protected ITaskManager TaskManager { get { return Manager.TaskManager; } }
119109
protected IGitClient GitClient { get { return Manager.GitClient; } }

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 void OnGUI()
34+
{
35+
var headerRect = EditorGUILayout.BeginHorizontal(Styles.HeaderBoxStyle);
36+
{
37+
GUILayout.Space(5);
38+
GUILayout.BeginVertical(GUILayout.Width(16));
39+
{
40+
GUILayout.Space(5);
41+
42+
var iconRect = GUILayoutUtility.GetRect(new GUIContent(Styles.BigLogo), GUIStyle.none, GUILayout.Height(20), GUILayout.Width(20));
43+
iconRect.y = headerRect.center.y - (iconRect.height / 2);
44+
GUI.DrawTexture(iconRect, Styles.BigLogo, ScaleMode.ScaleToFit);
45+
46+
GUILayout.Space(5);
47+
}
48+
GUILayout.EndVertical();
49+
50+
GUILayout.Space(5);
51+
52+
GUILayout.BeginVertical();
53+
{
54+
var headerContent = new GUIContent(NoRepoTitle);
55+
var headerTitleRect = GUILayoutUtility.GetRect(headerContent, Styles.HeaderTitleStyle);
56+
headerTitleRect.y = headerRect.center.y - (headerTitleRect.height / 2);
57+
58+
GUI.Label(headerTitleRect, headerContent, Styles.HeaderTitleStyle);
59+
}
60+
GUILayout.EndVertical();
61+
}
62+
EditorGUILayout.EndHorizontal();
63+
64+
GUILayout.BeginVertical(Styles.GenericBoxStyle);
65+
{
66+
GUILayout.FlexibleSpace();
67+
68+
GUILayout.Label(NoRepoDescription, Styles.CenteredLabel);
69+
70+
GUILayout.BeginHorizontal();
71+
GUILayout.FlexibleSpace();
72+
73+
EditorGUI.BeginDisabledGroup(isBusy);
74+
{
75+
if (GUILayout.Button(Localization.InitializeRepositoryButtonText, "Button"))
76+
{
77+
isBusy = true;
78+
Manager.InitializeRepository()
79+
.FinallyInUI(() => isBusy = false)
80+
.Start();
81+
}
82+
}
83+
EditorGUI.EndDisabledGroup();
84+
85+
GUILayout.FlexibleSpace();
86+
GUILayout.EndHorizontal();
87+
88+
GUILayout.FlexibleSpace();
89+
}
90+
GUILayout.EndVertical();
91+
}
92+
93+
private void MaybeUpdateData()
94+
{
95+
isPublished = Repository != null && Repository.CurrentRemote.HasValue;
96+
}
97+
98+
public override bool IsBusy
99+
{
100+
get { return isBusy; }
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)