22
33#if UNITY_EDITOR
44using System ;
5- using System . Collections ;
6- using Unity . EditorCoroutines . Editor ;
75using UnityEditor ;
8- using UnityEditorInternal ;
96using UnityEngine ;
107
118namespace CandyCoded . GitStatus
@@ -14,24 +11,6 @@ namespace CandyCoded.GitStatus
1411 public class GitStatusPanel : EditorWindow
1512 {
1613
17- private readonly EditorWaitForSeconds _delayBetweenUpdates = new EditorWaitForSeconds ( 60 ) ;
18-
19- private string _branch ;
20-
21- private string [ ] _branches ;
22-
23- private string [ ] _changedFiles ;
24-
25- private string [ ] _untrackedFiles ;
26-
27- private string [ ] _lockedFiles ;
28-
29- private DateTime _lastUpdated ;
30-
31- private EditorCoroutine _coroutine ;
32-
33- private bool _isEditorFocused ;
34-
3514 [ MenuItem ( "Git/Git Status" ) ]
3615 public static void ShowWindow ( )
3716 {
@@ -40,123 +19,51 @@ public static void ShowWindow()
4019
4120 }
4221
43- private void Update ( )
44- {
45-
46- if ( InternalEditorUtility . isApplicationActive && ! _isEditorFocused )
47- {
48-
49- UpdateData ( ) ;
50-
51- }
52-
53- _isEditorFocused = InternalEditorUtility . isApplicationActive ;
54-
55- }
56-
5722 private void OnGUI ( )
5823 {
5924
6025 GUILayout . Space ( 5 ) ;
6126
62- var selectedBranch = Array . IndexOf ( _branches , _branch ) ;
27+ var selectedBranch = Array . IndexOf ( GitStatus . branches , GitStatus . branch ) ;
6328
64- selectedBranch = EditorGUILayout . Popup ( "Branch:" , selectedBranch , _branches ) ;
29+ selectedBranch = EditorGUILayout . Popup ( "Branch:" , selectedBranch , GitStatus . branches ) ;
6530
66- if ( ! _branches [ selectedBranch ] . Equals ( _branch ) )
31+ if ( ! GitStatus . branches [ selectedBranch ] . Equals ( GitStatus . branch ) )
6732 {
6833
69- if ( _changedFiles ? . Length > 0 )
34+ if ( GitStatus . changedFiles ? . Length > 0 )
7035 {
7136
7237 EditorUtility . DisplayDialog (
7338 "Unable to checkout branch" ,
74- $ "Unable to checkout { _branches [ selectedBranch ] } as with { _changedFiles ? . Length } changes. " +
39+ $ "Unable to checkout { GitStatus . branches [ selectedBranch ] } as with { GitStatus . changedFiles ? . Length } changes. " +
7540 "Commit, discard or stash before checking out a different branch." ,
7641 "Ok" ) ;
7742
7843 }
7944 else
8045 {
8146
82- Git . CheckoutBranch ( _branches [ selectedBranch ] ) ;
83-
84- _branch = _branches [ selectedBranch ] ;
47+ Git . CheckoutBranch ( GitStatus . branches [ selectedBranch ] ) ;
8548
8649 }
8750
8851 }
8952
90- GUILayout . Label ( $ "Number of Changes: { _changedFiles ? . Length } ") ;
91- GUILayout . Label ( $ "Untracked Files: { _untrackedFiles ? . Length } ") ;
92- GUILayout . Label ( $ "Locked Files: { _lockedFiles ? . Length } ") ;
93- GUILayout . Label ( $ "Last Updated: { _lastUpdated } ") ;
53+ GUILayout . Label ( $ "Number of Changes: { GitStatus . changedFiles ? . Length } ") ;
54+ GUILayout . Label ( $ "Untracked Files: { GitStatus . untrackedFiles ? . Length } ") ;
55+ GUILayout . Label ( $ "Locked Files: { GitStatus . lockedFiles ? . Length } ") ;
56+ GUILayout . Label ( $ "Last Updated: { GitStatus . lastUpdated } ") ;
9457
9558 if ( GUILayout . Button ( "Refresh" ) )
9659 {
9760
98- UpdateData ( ) ;
61+ GitStatus . Update ( ) ;
9962
10063 }
10164
10265 }
10366
104- private void UpdateData ( )
105- {
106-
107- _branch = Git . Branch ( ) ;
108-
109- _branches = Git . Branches ( ) ;
110-
111- _changedFiles = Git . ChangedFiles ( ) ;
112-
113- _untrackedFiles = Git . UntrackedFiles ( ) ;
114-
115- _lockedFiles = Git . LockedFiles ( ) ;
116-
117- _lastUpdated = DateTime . Now ;
118-
119- Repaint ( ) ;
120-
121- }
122-
123- private IEnumerator UpdateCoroutine ( )
124- {
125-
126- while ( true )
127- {
128-
129- UpdateData ( ) ;
130-
131- yield return _delayBetweenUpdates ;
132-
133- }
134-
135- }
136-
137- private void OnEnable ( )
138- {
139-
140- _coroutine = EditorCoroutineUtility . StartCoroutine ( UpdateCoroutine ( ) , this ) ;
141-
142- }
143-
144- private void OnDisable ( )
145- {
146-
147- EditorCoroutineUtility . StopCoroutine ( _coroutine ) ;
148-
149- _coroutine = null ;
150-
151- }
152-
153- private void OnFocus ( )
154- {
155-
156- UpdateData ( ) ;
157-
158- }
159-
16067 }
16168
16269}
0 commit comments