1
1
using System ;
2
2
using System . Linq ;
3
3
using Octokit ;
4
+ using Rackspace . Threading ;
4
5
using UnityEditor ;
5
6
using UnityEngine ;
6
7
@@ -21,6 +22,7 @@ class PublishView : Subview
21
22
[ SerializeField ] private bool togglePrivate ;
22
23
23
24
[ NonSerialized ] private IApiClient client ;
25
+ [ NonSerialized ] private bool isLoading ;
24
26
[ NonSerialized ] private bool isBusy ;
25
27
[ NonSerialized ] private string error ;
26
28
@@ -63,6 +65,8 @@ private void PopulateView()
63
65
{
64
66
Logger . Trace ( "GetCurrentUser" ) ;
65
67
68
+ isLoading = true ;
69
+
66
70
Client . GetCurrentUser ( user => {
67
71
if ( user == null )
68
72
{
@@ -91,6 +95,8 @@ private void PopulateView()
91
95
92
96
owners = owners . Union ( organizationLogins ) . ToArray ( ) ;
93
97
} ) ;
98
+ } ) . Finally ( task => {
99
+ isLoading = false ;
94
100
} ) ;
95
101
}
96
102
else
@@ -127,111 +133,111 @@ public override void OnGUI()
127
133
128
134
GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
129
135
130
- GUILayout . BeginHorizontal ( ) ;
136
+ EditorGUI . BeginDisabledGroup ( isLoading || isBusy ) ;
131
137
{
132
- GUILayout . BeginVertical ( ) ;
138
+ GUILayout . BeginHorizontal ( ) ;
133
139
{
134
- GUILayout . Label ( "Owner" ) ;
140
+ GUILayout . BeginVertical ( ) ;
141
+ {
142
+ GUILayout . Label ( "Owner" ) ;
135
143
136
- GUI . enabled = ! isBusy ;
137
- selectedOwner = EditorGUILayout . Popup ( 0 , owners ) ;
138
- GUI . enabled = true ;
139
- }
140
- GUILayout . EndVertical ( ) ;
144
+ selectedOwner = EditorGUILayout . Popup ( 0 , owners ) ;
145
+ }
146
+ GUILayout . EndVertical ( ) ;
141
147
142
- GUILayout . BeginVertical ( GUILayout . Width ( 8 ) ) ;
143
- {
144
- GUILayout . Space ( 20 ) ;
145
- GUILayout . Label ( "/" ) ;
146
- }
147
- GUILayout . EndVertical ( ) ;
148
+ GUILayout . BeginVertical ( GUILayout . Width ( 8 ) ) ;
149
+ {
150
+ GUILayout . Space ( 20 ) ;
151
+ GUILayout . Label ( "/" ) ;
152
+ }
153
+ GUILayout . EndVertical ( ) ;
148
154
149
- GUILayout . BeginVertical ( ) ;
150
- {
151
- GUILayout . Label ( "Repository Name" ) ;
152
- GUI . enabled = ! isBusy ;
153
- repoName = EditorGUILayout . TextField ( repoName ) ;
154
- GUI . enabled = true ;
155
+ GUILayout . BeginVertical ( ) ;
156
+ {
157
+ GUILayout . Label ( "Repository Name" ) ;
158
+ repoName = EditorGUILayout . TextField ( repoName ) ;
159
+ }
160
+ GUILayout . EndVertical ( ) ;
155
161
}
156
- GUILayout . EndVertical ( ) ;
157
- }
158
- GUILayout . EndHorizontal ( ) ;
162
+ GUILayout . EndHorizontal ( ) ;
159
163
160
- GUILayout . Label ( "Description" ) ;
161
- GUI . enabled = ! isBusy ;
162
- repoDescription = EditorGUILayout . TextField ( repoDescription ) ;
163
- GUI . enabled = true ;
164
- GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
164
+ GUILayout . Label ( "Description" ) ;
165
+ repoDescription = EditorGUILayout . TextField ( repoDescription ) ;
166
+ GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
165
167
166
- GUILayout . BeginVertical ( ) ;
167
- {
168
- GUILayout . BeginHorizontal ( ) ;
168
+ GUILayout . BeginVertical ( ) ;
169
169
{
170
- GUI . enabled = ! isBusy ;
171
- togglePrivate = GUILayout . Toggle ( togglePrivate , "Create as a private repository" ) ;
172
- GUI . enabled = true ;
173
- }
174
- GUILayout . EndHorizontal ( ) ;
170
+ GUILayout . BeginHorizontal ( ) ;
171
+ {
172
+ togglePrivate = GUILayout . Toggle ( togglePrivate , "Create as a private repository" ) ;
173
+ }
174
+ GUILayout . EndHorizontal ( ) ;
175
175
176
- GUILayout . BeginHorizontal ( ) ;
177
- {
178
- GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
179
- var repoPrivacyExplanation = togglePrivate ? PrivateRepoMessage : PublicRepoMessage ;
180
- GUILayout . Label ( repoPrivacyExplanation , Styles . LongMessageStyle ) ;
176
+ GUILayout . BeginHorizontal ( ) ;
177
+ {
178
+ GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
179
+ var repoPrivacyExplanation = togglePrivate ? PrivateRepoMessage : PublicRepoMessage ;
180
+ GUILayout . Label ( repoPrivacyExplanation , Styles . LongMessageStyle ) ;
181
+ }
182
+ GUILayout . EndHorizontal ( ) ;
181
183
}
182
- GUILayout . EndHorizontal ( ) ;
183
- }
184
- GUILayout . EndVertical ( ) ;
185
-
186
-
187
- GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
184
+ GUILayout . EndVertical ( ) ; ;
188
185
189
- if ( error != null )
190
- GUILayout . Label ( error , Styles . ErrorLabel ) ;
186
+ GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
191
187
192
- GUILayout . FlexibleSpace ( ) ;
188
+ if ( error != null )
189
+ GUILayout . Label ( error , Styles . ErrorLabel ) ;
193
190
194
- GUILayout . BeginHorizontal ( ) ;
195
- {
196
191
GUILayout . FlexibleSpace ( ) ;
197
- GUI . enabled = ! string . IsNullOrEmpty ( repoName ) && ! isBusy ;
198
- if ( GUILayout . Button ( PublishViewCreateButton ) )
199
- {
200
- isBusy = true ;
201
-
202
- var organization = owners [ selectedOwner ] == username ? null : owners [ selectedOwner ] ;
203
192
204
- Client . CreateRepository ( new NewRepository ( repoName )
205
- {
206
- Private = togglePrivate ,
207
- } , ( repository , ex ) =>
193
+ GUILayout . BeginHorizontal ( ) ;
194
+ {
195
+ GUILayout . FlexibleSpace ( ) ;
196
+ EditorGUI . BeginDisabledGroup ( ! IsFormValid ) ;
197
+ if ( GUILayout . Button ( PublishViewCreateButton ) )
208
198
{
209
- Logger . Trace ( "Create Repository Callback" ) ;
199
+ isBusy = true ;
210
200
211
- if ( ex != null )
212
- {
213
- error = ex . Message ;
214
- isBusy = false ;
215
- return ;
216
- }
201
+ var organization = owners [ selectedOwner ] == username ? null : owners [ selectedOwner ] ;
217
202
218
- if ( repository == null )
203
+ Client . CreateRepository ( new NewRepository ( repoName )
219
204
{
220
- Logger . Warning ( "Returned Repository is null" ) ;
221
- isBusy = false ;
222
- return ;
223
- }
205
+ Private = togglePrivate ,
206
+ } , ( repository , ex ) =>
207
+ {
208
+ Logger . Trace ( "Create Repository Callback" ) ;
209
+
210
+ if ( ex != null )
211
+ {
212
+ error = ex . Message ;
213
+ isBusy = false ;
214
+ return ;
215
+ }
224
216
225
- GitClient . RemoteAdd ( "origin" , repository . CloneUrl )
226
- . Then ( GitClient . Push ( "origin" , Repository . CurrentBranch . Value . Name ) )
227
- . ThenInUI ( Parent . Finish )
228
- . Start ( ) ;
229
- } , organization ) ;
217
+ if ( repository == null )
218
+ {
219
+ Logger . Warning ( "Returned Repository is null" ) ;
220
+ isBusy = false ;
221
+ return ;
222
+ }
223
+
224
+ GitClient . RemoteAdd ( "origin" , repository . CloneUrl )
225
+ . Then ( GitClient . Push ( "origin" , Repository . CurrentBranch . Value . Name ) )
226
+ . ThenInUI ( Parent . Finish )
227
+ . Start ( ) ;
228
+ } , organization ) ;
229
+ }
230
+ EditorGUI . EndDisabledGroup ( ) ;
230
231
}
231
- GUI . enabled = true ;
232
+ GUILayout . EndHorizontal ( ) ;
233
+ GUILayout . Space ( 10 ) ;
232
234
}
233
- GUILayout . EndHorizontal ( ) ;
234
- GUILayout . Space ( 10 ) ;
235
+ EditorGUI . EndDisabledGroup ( ) ;
236
+ }
237
+
238
+ private bool IsFormValid
239
+ {
240
+ get { return ! string . IsNullOrEmpty ( repoName ) ; }
235
241
}
236
242
}
237
243
}
0 commit comments