@@ -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
@@ -234,16 +234,6 @@ private void DetachHandlers(IRepository repository)
234234 repository . OnRepositoryInfoChanged -= RefreshOnMainThread ;
235235 }
236236
237-
238- private void SwitchView ( Subview from , Subview to )
239- {
240- GUI . FocusControl ( null ) ;
241- if ( from != null )
242- from . OnDisable ( ) ;
243- to . OnEnable ( ) ;
244- Refresh ( ) ;
245- }
246-
247237 private void DoHeaderGUI ( )
248238 {
249239 GUILayout . BeginHorizontal ( Styles . HeaderBoxStyle ) ;
@@ -274,26 +264,25 @@ private void DoToolbarGUI()
274264 // Subtabs & toolbar
275265 Rect mainNavRect = EditorGUILayout . BeginHorizontal ( EditorStyles . toolbar ) ;
276266 {
277- SubTab tab = activeTab ;
267+ SubTab changeTab = activeTab ;
278268 EditorGUI . BeginChangeCheck ( ) ;
279269 {
280270 if ( HasRepository )
281271 {
282- tab = TabButton ( SubTab . Changes , ChangesTitle , tab ) ;
283- tab = TabButton ( SubTab . History , HistoryTitle , tab ) ;
284- tab = TabButton ( SubTab . Branches , BranchesTitle , tab ) ;
272+ changeTab = TabButton ( SubTab . Changes , ChangesTitle , changeTab ) ;
273+ changeTab = TabButton ( SubTab . History , HistoryTitle , changeTab ) ;
274+ changeTab = TabButton ( SubTab . Branches , BranchesTitle , changeTab ) ;
285275 }
286276 else
287277 {
288- tab = TabButton ( SubTab . History , HistoryTitle , tab ) ;
278+ changeTab = TabButton ( SubTab . History , HistoryTitle , changeTab ) ;
289279 }
290- tab = TabButton ( SubTab . Settings , SettingsTitle , tab ) ;
280+ changeTab = TabButton ( SubTab . Settings , SettingsTitle , changeTab ) ;
291281 }
282+
292283 if ( EditorGUI . EndChangeCheck ( ) )
293284 {
294- var from = ActiveTab ;
295- activeTab = tab ;
296- SwitchView ( from , ActiveTab ) ;
285+ SetActiveTab ( changeTab ) ;
297286 }
298287
299288 GUILayout . FlexibleSpace ( ) ;
@@ -304,6 +293,28 @@ private void DoToolbarGUI()
304293 EditorGUILayout . EndHorizontal ( ) ;
305294 }
306295
296+ private void SetActiveTab ( SubTab changeTab )
297+ {
298+ if ( changeTab != activeTab )
299+ {
300+ var fromView = ActiveView ;
301+ activeTab = changeTab ;
302+ SwitchView ( fromView , ActiveView ) ;
303+ }
304+ }
305+
306+ private void SwitchView ( Subview fromView , Subview toView )
307+ {
308+ GUI . FocusControl ( null ) ;
309+
310+ if ( fromView != null )
311+ fromView . OnDisable ( ) ;
312+
313+ toView . OnEnable ( ) ;
314+
315+ Refresh ( ) ;
316+ }
317+
307318 private void DoAccountDropdown ( )
308319 {
309320 GenericMenu accountMenu = new GenericMenu ( ) ;
@@ -365,27 +376,27 @@ private static SubTab TabButton(SubTab tab, string title, SubTab activeTab)
365376 return GUILayout . Toggle ( activeTab == tab , title , EditorStyles . toolbarButton ) ? tab : activeTab ;
366377 }
367378
368- public HistoryView HistoryTab
379+ public HistoryView HistoryView
369380 {
370- get { return historyTab ; }
381+ get { return historyView ; }
371382 }
372383
373- public ChangesView ChangesTab
384+ public ChangesView ChangesView
374385 {
375- get { return changesTab ; }
386+ get { return changesView ; }
376387 }
377388
378- public BranchesView BranchesTab
389+ public BranchesView BranchesView
379390 {
380- get { return branchesTab ; }
391+ get { return branchesView ; }
381392 }
382393
383- public SettingsView SettingsTab
394+ public SettingsView SettingsView
384395 {
385- get { return settingsTab ; }
396+ get { return settingsView ; }
386397 }
387398
388- private Subview ActiveTab
399+ private Subview ActiveView
389400 {
390401 get
391402 {
@@ -398,14 +409,14 @@ private Subview ToView(SubTab tab)
398409 switch ( tab )
399410 {
400411 case SubTab . History :
401- return historyTab ;
412+ return historyView ;
402413 case SubTab . Changes :
403- return changesTab ;
414+ return changesView ;
404415 case SubTab . Branches :
405- return branchesTab ;
416+ return branchesView ;
406417 case SubTab . Settings :
407418 default :
408- return settingsTab ;
419+ return settingsView ;
409420 }
410421 }
411422
0 commit comments