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

Commit e280096

Browse files
committed
Make the view methods more consistent, and make sure all windows call into them
Use OnEnable/OnDisable instead of OnShow/OnHide, it's more consistent with Unity's naming and our own window class. AuthenticationView was missing some calls from the window, fixicate.
1 parent dc885e3 commit e280096

File tree

9 files changed

+66
-80
lines changed

9 files changed

+66
-80
lines changed

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 OnUI()
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ public override void InitializeView(IView parent)
8181
}
8282
}
8383

84-
public override void OnShow()
84+
public override void OnEnable()
8585
{
86-
base.OnShow();
86+
base.OnEnable();
8787
if (Repository != null)
8888
{
8989
Repository.OnCommitChanged += UpdateLogOnMainThread;
@@ -92,9 +92,9 @@ public override void OnShow()
9292
UpdateLog();
9393
}
9494

95-
public override void OnHide()
95+
public override void OnDisable()
9696
{
97-
base.OnHide();
97+
base.OnDisable();
9898
if (Repository != null)
9999
{
100100
Repository.OnCommitChanged -= UpdateLogOnMainThread;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ namespace GitHub.Unity
55
{
66
interface IView
77
{
8+
void OnEnable();
9+
void OnDisable();
810
void Refresh();
911
void Redraw();
1012
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)

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ public virtual void OnSelectionChange()
112112
protected IEnvironment Environment { get { return Manager.Environment; } }
113113
protected IPlatform Platform { get { return Manager.Platform; } }
114114

115-
116115
private ILogging logger;
117116
protected ILogging Logger
118117
{
@@ -144,21 +143,13 @@ public virtual void InitializeView(IView parent)
144143
Parent = parent;
145144
}
146145

147-
public virtual void OnShow()
148-
{
149-
}
150-
151-
public virtual void OnHide()
152-
{
153-
}
154-
155-
public virtual void OnUpdate()
146+
public virtual void OnEnable()
156147
{}
157148

158-
public virtual void OnGUI()
149+
public virtual void OnDisable()
159150
{}
160151

161-
public virtual void OnDestroy()
152+
public virtual void OnGUI()
162153
{}
163154

164155
public virtual void OnSelectionChange()

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

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,30 @@ public override void OnEnable()
8383

8484
// Set window title
8585
titleContent = new GUIContent(Title, Styles.SmallLogo);
86-
}
8786

88-
public override void Refresh()
89-
{
90-
base.Refresh();
9187
if (ActiveTab != null)
92-
ActiveTab.Refresh();
88+
ActiveTab.OnEnable();
9389
}
9490

9591
public override void OnDisable()
9692
{
9793
base.OnDisable();
94+
if (ActiveTab != null)
95+
ActiveTab.OnDisable();
96+
}
9897

98+
public override void OnSelectionChange()
99+
{
100+
base.OnSelectionChange();
99101
if (ActiveTab != null)
100-
ActiveTab.OnHide();
102+
ActiveTab.OnSelectionChange();
103+
}
104+
105+
public override void Refresh()
106+
{
107+
base.Refresh();
108+
if (ActiveTab != null)
109+
ActiveTab.Refresh();
101110
}
102111

103112
public override void OnUI()
@@ -131,28 +140,12 @@ public override void Update()
131140
}
132141
}
133142

134-
public override void OnSelectionChange()
135-
{
136-
base.OnSelectionChange();
137-
if (ActiveTab != null)
138-
ActiveTab.OnSelectionChange();
139-
}
140-
141-
private void ShowActiveView()
142-
{
143-
if (Repository == null)
144-
return;
145-
146-
if (ActiveTab != null)
147-
ActiveTab.OnShow();
148-
Refresh();
149-
}
150-
151143
private void SwitchView(Subview from, Subview to)
152144
{
153145
GUI.FocusControl(null);
154-
from.OnHide();
155-
to.OnShow();
146+
if (from != null)
147+
from.OnDisable();
148+
to.OnEnable();
156149
Refresh();
157150
}
158151

0 commit comments

Comments
 (0)