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

Commit e09591e

Browse files
Merge branch 'master' into fixes/window-update-loop
2 parents 65bffae + 3b8c39c commit e09591e

File tree

1 file changed

+65
-54
lines changed
  • src/UnityExtension/Assets/Editor/GitHub.Unity/UI

1 file changed

+65
-54
lines changed

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

Lines changed: 65 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ class Window : BaseWindow
2626
[NonSerialized] private double notificationClearTime = -1;
2727

2828
[SerializeField] private SubTab activeTab = SubTab.History;
29-
[SerializeField] private BranchesView branchesTab = new BranchesView();
30-
[SerializeField] private ChangesView changesTab = new ChangesView();
31-
[SerializeField] private HistoryView historyTab = new HistoryView();
32-
[SerializeField] private SettingsView settingsTab = new SettingsView();
29+
[SerializeField] private BranchesView branchesView = new BranchesView();
30+
[SerializeField] private ChangesView changesView = new ChangesView();
31+
[SerializeField] private HistoryView historyView = new HistoryView();
32+
[SerializeField] private SettingsView settingsView = new SettingsView();
3333

3434
[SerializeField] private string repoBranch;
3535
[SerializeField] private string repoUrl;
@@ -71,10 +71,10 @@ public override void Initialize(IApplicationManager applicationManager)
7171
{
7272
base.Initialize(applicationManager);
7373

74-
HistoryTab.InitializeView(this);
75-
ChangesTab.InitializeView(this);
76-
BranchesTab.InitializeView(this);
77-
SettingsTab.InitializeView(this);
74+
HistoryView.InitializeView(this);
75+
ChangesView.InitializeView(this);
76+
BranchesView.InitializeView(this);
77+
SettingsView.InitializeView(this);
7878
}
7979

8080
public override void OnEnable()
@@ -88,15 +88,15 @@ public override void OnEnable()
8888
// Set window title
8989
titleContent = new GUIContent(Title, Styles.SmallLogo);
9090

91-
if (ActiveTab != null)
92-
ActiveTab.OnEnable();
91+
if (ActiveView != null)
92+
ActiveView.OnEnable();
9393
}
9494

9595
public override void OnDisable()
9696
{
9797
base.OnDisable();
98-
if (ActiveTab != null)
99-
ActiveTab.OnDisable();
98+
if (ActiveView != null)
99+
ActiveView.OnDisable();
100100
}
101101

102102
public override void OnDataUpdate()
@@ -117,8 +117,8 @@ public override void OnDataUpdate()
117117
}
118118
}
119119

120-
if (ActiveTab != null)
121-
ActiveTab.OnDataUpdate();
120+
if (ActiveView != null)
121+
ActiveView.OnDataUpdate();
122122
}
123123

124124
public override void OnRepositoryChanged(IRepository oldRepository)
@@ -128,22 +128,22 @@ public override void OnRepositoryChanged(IRepository oldRepository)
128128
DetachHandlers(oldRepository);
129129
AttachHandlers(Repository);
130130

131-
if (ActiveTab != null)
132-
ActiveTab.OnRepositoryChanged(oldRepository);
131+
if (ActiveView != null)
132+
ActiveView.OnRepositoryChanged(oldRepository);
133133
}
134134

135135
public override void OnSelectionChange()
136136
{
137137
base.OnSelectionChange();
138-
if (ActiveTab != null)
139-
ActiveTab.OnSelectionChange();
138+
if (ActiveView != null)
139+
ActiveView.OnSelectionChange();
140140
}
141141

142142
public override void Refresh()
143143
{
144144
base.Refresh();
145-
if (ActiveTab != null)
146-
ActiveTab.Refresh();
145+
if (ActiveView != null)
146+
ActiveView.Refresh();
147147
Repaint();
148148
}
149149

@@ -159,9 +159,9 @@ public override void OnUI()
159159
DoToolbarGUI();
160160

161161
// GUI for the active tab
162-
if (ActiveTab != null)
162+
if (ActiveView != null)
163163
{
164-
ActiveTab.OnGUI();
164+
ActiveView.OnGUI();
165165
}
166166
}
167167

@@ -238,16 +238,6 @@ private void DetachHandlers(IRepository repository)
238238
repository.OnRepositoryInfoChanged -= RefreshOnMainThread;
239239
}
240240

241-
242-
private void SwitchView(Subview from, Subview to)
243-
{
244-
GUI.FocusControl(null);
245-
if (from != null)
246-
from.OnDisable();
247-
to.OnEnable();
248-
Refresh();
249-
}
250-
251241
private void DoHeaderGUI()
252242
{
253243
GUILayout.BeginHorizontal(Styles.HeaderBoxStyle);
@@ -278,26 +268,25 @@ private void DoToolbarGUI()
278268
// Subtabs & toolbar
279269
Rect mainNavRect = EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
280270
{
281-
SubTab tab = activeTab;
271+
SubTab changeTab = activeTab;
282272
EditorGUI.BeginChangeCheck();
283273
{
284274
if (HasRepository)
285275
{
286-
tab = TabButton(SubTab.Changes, ChangesTitle, tab);
287-
tab = TabButton(SubTab.History, HistoryTitle, tab);
288-
tab = TabButton(SubTab.Branches, BranchesTitle, tab);
276+
changeTab = TabButton(SubTab.Changes, ChangesTitle, changeTab);
277+
changeTab = TabButton(SubTab.History, HistoryTitle, changeTab);
278+
changeTab = TabButton(SubTab.Branches, BranchesTitle, changeTab);
289279
}
290280
else
291281
{
292-
tab = TabButton(SubTab.History, HistoryTitle, tab);
282+
changeTab = TabButton(SubTab.History, HistoryTitle, changeTab);
293283
}
294-
tab = TabButton(SubTab.Settings, SettingsTitle, tab);
284+
changeTab = TabButton(SubTab.Settings, SettingsTitle, changeTab);
295285
}
286+
296287
if (EditorGUI.EndChangeCheck())
297288
{
298-
var from = ActiveTab;
299-
activeTab = tab;
300-
SwitchView(from, ActiveTab);
289+
SetActiveTab(changeTab);
301290
}
302291

303292
GUILayout.FlexibleSpace();
@@ -308,6 +297,28 @@ private void DoToolbarGUI()
308297
EditorGUILayout.EndHorizontal();
309298
}
310299

300+
private void SetActiveTab(SubTab changeTab)
301+
{
302+
if (changeTab != activeTab)
303+
{
304+
var fromView = ActiveView;
305+
activeTab = changeTab;
306+
SwitchView(fromView, ActiveView);
307+
}
308+
}
309+
310+
private void SwitchView(Subview fromView, Subview toView)
311+
{
312+
GUI.FocusControl(null);
313+
314+
if (fromView != null)
315+
fromView.OnDisable();
316+
317+
toView.OnEnable();
318+
319+
Refresh();
320+
}
321+
311322
private void DoAccountDropdown()
312323
{
313324
GenericMenu accountMenu = new GenericMenu();
@@ -369,27 +380,27 @@ private static SubTab TabButton(SubTab tab, string title, SubTab activeTab)
369380
return GUILayout.Toggle(activeTab == tab, title, EditorStyles.toolbarButton) ? tab : activeTab;
370381
}
371382

372-
public HistoryView HistoryTab
383+
public HistoryView HistoryView
373384
{
374-
get { return historyTab; }
385+
get { return historyView; }
375386
}
376387

377-
public ChangesView ChangesTab
388+
public ChangesView ChangesView
378389
{
379-
get { return changesTab; }
390+
get { return changesView; }
380391
}
381392

382-
public BranchesView BranchesTab
393+
public BranchesView BranchesView
383394
{
384-
get { return branchesTab; }
395+
get { return branchesView; }
385396
}
386397

387-
public SettingsView SettingsTab
398+
public SettingsView SettingsView
388399
{
389-
get { return settingsTab; }
400+
get { return settingsView; }
390401
}
391402

392-
private Subview ActiveTab
403+
private Subview ActiveView
393404
{
394405
get
395406
{
@@ -402,14 +413,14 @@ private Subview ToView(SubTab tab)
402413
switch (tab)
403414
{
404415
case SubTab.History:
405-
return historyTab;
416+
return historyView;
406417
case SubTab.Changes:
407-
return changesTab;
418+
return changesView;
408419
case SubTab.Branches:
409-
return branchesTab;
420+
return branchesView;
410421
case SubTab.Settings:
411422
default:
412-
return settingsTab;
423+
return settingsView;
413424
}
414425
}
415426

0 commit comments

Comments
 (0)