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

Commit e659480

Browse files
authored
Merge pull request #87 from github-for-unity/fixes/refactor-view
Refactoring BaseWindow and Subview to better handle initialization
2 parents 9c57623 + e280096 commit e659480

File tree

12 files changed

+167
-153
lines changed

12 files changed

+167
-153
lines changed

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,13 @@ public void Dispose()
234234
public CancellationToken CancellationToken { get { return TaskManager.Token; } }
235235
public ITaskManager TaskManager { get; protected set; }
236236
public IGitClient GitClient { get; protected set; }
237-
238-
239-
protected TaskScheduler UIScheduler { get; private set; }
240-
protected SynchronizationContext SynchronizationContext { get; private set; }
241-
protected IRepositoryManager RepositoryManager { get { return repositoryManager; } }
242-
243237
public ISettings LocalSettings { get; protected set; }
244238
public ISettings SystemSettings { get; protected set; }
245239
public ISettings UserSettings { get; protected set; }
246240
public IUsageTracker UsageTracker { get; protected set; }
241+
242+
protected TaskScheduler UIScheduler { get; private set; }
243+
protected SynchronizationContext SynchronizationContext { get; private set; }
244+
protected IRepositoryManager RepositoryManager { get { return repositoryManager; } }
247245
}
248246
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public ApplicationManager(IMainThreadSynchronizationContext synchronizationConte
2323

2424
protected override void SetupMetrics()
2525
{
26+
2627
new ActionTask(CancellationToken,
2728
() => SetupMetrics(Environment.UnityVersion, ApplicationCache.Instance.FirstRun))
2829
{ Affinity = TaskAffinity.UI }
@@ -33,7 +34,7 @@ protected override void InitializeUI()
3334
{
3435
Logger.Trace("Restarted {0}", Environment.Repository);
3536
ProjectWindowInterface.Initialize(Environment.Repository);
36-
var view = Window.GetView();
37+
var view = Window.GetWindow();
3738
if (view != null)
3839
view.Initialize(this);
3940
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ namespace GitHub.Unity
1111
[InitializeOnLoad]
1212
class EntryPoint : ScriptableObject
1313
{
14-
private static ApplicationManager appManager;
15-
1614
// this may run on the loader thread if it's an appdomain restart
1715
static EntryPoint()
1816
{
@@ -69,6 +67,7 @@ private static bool ServerCertificateValidationCallback(object sender, X509Certi
6967
return true;
7068
}
7169

70+
private static ApplicationManager appManager;
7271
public static IApplicationManager ApplicationManager
7372
{
7473
get

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ public override void InitializeView(IView parent)
6161
need2fa = busy = false;
6262
}
6363

64-
public override void OnShow()
64+
public override void OnEnable()
6565
{
66-
base.OnShow();
66+
base.OnEnable();
6767
}
6868

69-
public override void OnHide()
69+
public override void OnDisable()
7070
{
71-
base.OnHide();
71+
base.OnDisable();
7272
}
7373

7474
public override void OnGUI()

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

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,45 +27,45 @@ public static IView Open(Action<bool> onClose = null)
2727
return authWindow;
2828
}
2929

30-
public override void OnGUI()
30+
public override void Initialize(IApplicationManager applicationManager)
3131
{
32+
base.Initialize(applicationManager);
3233
if (authView == null)
33-
{
34-
CreateViews();
35-
}
36-
authView.OnGUI();
37-
}
38-
39-
public override void Refresh()
40-
{
41-
authView.Refresh();
34+
authView = new AuthenticationView();
35+
authView.InitializeView(this);
4236
}
4337

4438
public override void OnEnable()
4539
{
40+
base.OnEnable();
41+
4642
// Set window title
4743
titleContent = new GUIContent(Title, Styles.SmallLogo);
44+
authView.OnEnable();
45+
}
4846

49-
Utility.UnregisterReadyCallback(CreateViews);
50-
Utility.RegisterReadyCallback(CreateViews);
51-
52-
Utility.UnregisterReadyCallback(ShowActiveView);
53-
Utility.RegisterReadyCallback(ShowActiveView);
47+
public override void OnDisable()
48+
{
49+
base.OnDisable();
50+
authView.OnDisable();
5451
}
5552

56-
private void CreateViews()
53+
public override void OnUI()
5754
{
58-
if (authView == null)
59-
authView = new AuthenticationView();
55+
base.OnUI();
56+
authView.OnGUI();
57+
}
6058

61-
Initialize(EntryPoint.ApplicationManager);
62-
authView.InitializeView(this);
59+
public override void Refresh()
60+
{
61+
base.Refresh();
62+
authView.Refresh();
6363
}
6464

65-
private void ShowActiveView()
65+
public override void OnSelectionChange()
6666
{
67-
authView.OnShow();
68-
Refresh();
67+
base.OnSelectionChange();
68+
authView.OnSelectionChange();
6969
}
7070

7171
public override void Finish(bool result)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ public override void InitializeView(IView parent)
4444
targetMode = mode;
4545
}
4646

47-
public override void OnShow()
47+
public override void OnEnable()
4848
{
49-
base.OnShow();
49+
base.OnEnable();
5050
if (Repository != null)
5151
{
5252
Repository.OnLocalBranchListChanged += RunRefreshEmbeddedOnMainThread;
@@ -55,9 +55,9 @@ public override void OnShow()
5555
}
5656
}
5757

58-
public override void OnHide()
58+
public override void OnDisable()
5959
{
60-
base.OnHide();
60+
base.OnDisable();
6161
if (Repository != null)
6262
{
6363
Repository.OnLocalBranchListChanged -= RunRefreshEmbeddedOnMainThread;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public override void InitializeView(IView parent)
3333
tree.InitializeView(this);
3434
}
3535

36-
public override void OnShow()
36+
public override void OnEnable()
3737
{
38-
base.OnShow();
38+
base.OnEnable();
3939
if (Repository == null)
4040
return;
4141

@@ -44,9 +44,9 @@ public override void OnShow()
4444
Repository.Refresh();
4545
}
4646

47-
public override void OnHide()
47+
public override void OnDisable()
4848
{
49-
base.OnHide();
49+
base.OnDisable();
5050
if (Repository == null)
5151
return;
5252
Repository.OnRepositoryChanged -= RunStatusUpdateOnMainThread;

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,14 @@ class HistoryView : Subview
5959
[SerializeField] private List<GitLogEntry> history = new List<GitLogEntry>();
6060
[SerializeField] private bool isBusy;
6161

62-
public override void Initialize(IApplicationManager applicationManager)
62+
public override void InitializeView(IView parent)
6363
{
64-
base.Initialize(applicationManager);
64+
base.InitializeView(parent);
65+
6566
if (Manager != null)
6667
{
6768
UpdateLog();
6869
}
69-
}
70-
71-
public override void InitializeView(IView parent)
72-
{
73-
Logger.Trace("InitializeView(IView)");
74-
base.InitializeView(parent);
7570

7671
lastWidth = Position.width;
7772
selectionIndex = newSelectionIndex = -1;
@@ -86,9 +81,9 @@ public override void InitializeView(IView parent)
8681
}
8782
}
8883

89-
public override void OnShow()
84+
public override void OnEnable()
9085
{
91-
base.OnShow();
86+
base.OnEnable();
9287
if (Repository != null)
9388
{
9489
Repository.OnCommitChanged += UpdateLogOnMainThread;
@@ -97,9 +92,9 @@ public override void OnShow()
9792
UpdateLog();
9893
}
9994

100-
public override void OnHide()
95+
public override void OnDisable()
10196
{
102-
base.OnHide();
97+
base.OnDisable();
10398
if (Repository != null)
10499
{
105100
Repository.OnCommitChanged -= UpdateLogOnMainThread;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ namespace GitHub.Unity
55
{
66
interface IView
77
{
8-
void Initialize(IApplicationManager applicationManager);
8+
void OnEnable();
9+
void OnDisable();
910
void Refresh();
1011
void Redraw();
1112
Rect Position { get; }

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ private void Repository_OnActiveRemoteChanged(string remote)
119119
repositoryRemoteUrl = currentRemote.Value.Url;
120120
}
121121

122-
public override void OnShow()
122+
public override void OnEnable()
123123
{
124-
base.OnShow();
124+
base.OnEnable();
125125
if (Repository == null)
126126
return;
127127

@@ -140,9 +140,9 @@ public override void OnShow()
140140
gitEmail = Repository.User.Email;
141141
}
142142

143-
public override void OnHide()
143+
public override void OnDisable()
144144
{
145-
base.OnHide();
145+
base.OnDisable();
146146
}
147147

148148
private void RunLocksUpdateOnMainThread(IEnumerable<GitLock> locks)

0 commit comments

Comments
 (0)