2
2
3
3
#if UNITY_EDITOR
4
4
using System ;
5
- using System . Collections ;
6
- using Unity . EditorCoroutines . Editor ;
7
5
using UnityEditor ;
8
- using UnityEditorInternal ;
9
6
using UnityEngine ;
10
7
11
8
namespace CandyCoded . GitStatus
@@ -14,24 +11,6 @@ namespace CandyCoded.GitStatus
14
11
public class GitStatusPanel : EditorWindow
15
12
{
16
13
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
-
35
14
[ MenuItem ( "Git/Git Status" ) ]
36
15
public static void ShowWindow ( )
37
16
{
@@ -40,123 +19,51 @@ public static void ShowWindow()
40
19
41
20
}
42
21
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
-
57
22
private void OnGUI ( )
58
23
{
59
24
60
25
GUILayout . Space ( 5 ) ;
61
26
62
- var selectedBranch = Array . IndexOf ( _branches , _branch ) ;
27
+ var selectedBranch = Array . IndexOf ( GitStatus . branches , GitStatus . branch ) ;
63
28
64
- selectedBranch = EditorGUILayout . Popup ( "Branch:" , selectedBranch , _branches ) ;
29
+ selectedBranch = EditorGUILayout . Popup ( "Branch:" , selectedBranch , GitStatus . branches ) ;
65
30
66
- if ( ! _branches [ selectedBranch ] . Equals ( _branch ) )
31
+ if ( ! GitStatus . branches [ selectedBranch ] . Equals ( GitStatus . branch ) )
67
32
{
68
33
69
- if ( _changedFiles ? . Length > 0 )
34
+ if ( GitStatus . changedFiles ? . Length > 0 )
70
35
{
71
36
72
37
EditorUtility . DisplayDialog (
73
38
"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. " +
75
40
"Commit, discard or stash before checking out a different branch." ,
76
41
"Ok" ) ;
77
42
78
43
}
79
44
else
80
45
{
81
46
82
- Git . CheckoutBranch ( _branches [ selectedBranch ] ) ;
83
-
84
- _branch = _branches [ selectedBranch ] ;
47
+ Git . CheckoutBranch ( GitStatus . branches [ selectedBranch ] ) ;
85
48
86
49
}
87
50
88
51
}
89
52
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 } ") ;
94
57
95
58
if ( GUILayout . Button ( "Refresh" ) )
96
59
{
97
60
98
- UpdateData ( ) ;
61
+ GitStatus . Update ( ) ;
99
62
100
63
}
101
64
102
65
}
103
66
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
-
160
67
}
161
68
162
69
}
0 commit comments