11using System ;
22using System . Linq ;
33using Octokit ;
4+ using Rackspace . Threading ;
45using UnityEditor ;
56using UnityEngine ;
67
@@ -21,6 +22,7 @@ class PublishView : Subview
2122 [ SerializeField ] private bool togglePrivate ;
2223
2324 [ NonSerialized ] private IApiClient client ;
25+ [ NonSerialized ] private bool isLoading ;
2426 [ NonSerialized ] private bool isBusy ;
2527 [ NonSerialized ] private string error ;
2628
@@ -63,6 +65,8 @@ private void PopulateView()
6365 {
6466 Logger . Trace ( "GetCurrentUser" ) ;
6567
68+ isLoading = true ;
69+
6670 Client . GetCurrentUser ( user => {
6771 if ( user == null )
6872 {
@@ -91,6 +95,8 @@ private void PopulateView()
9195
9296 owners = owners . Union ( organizationLogins ) . ToArray ( ) ;
9397 } ) ;
98+ } ) . Finally ( task => {
99+ isLoading = false ;
94100 } ) ;
95101 }
96102 else
@@ -127,111 +133,111 @@ public override void OnGUI()
127133
128134 GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
129135
130- GUILayout . BeginHorizontal ( ) ;
136+ EditorGUI . BeginDisabledGroup ( isLoading || isBusy ) ;
131137 {
132- GUILayout . BeginVertical ( ) ;
138+ GUILayout . BeginHorizontal ( ) ;
133139 {
134- GUILayout . Label ( "Owner" ) ;
140+ GUILayout . BeginVertical ( ) ;
141+ {
142+ GUILayout . Label ( "Owner" ) ;
135143
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 ( ) ;
141147
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 ( ) ;
148154
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 ( ) ;
155161 }
156- GUILayout . EndVertical ( ) ;
157- }
158- GUILayout . EndHorizontal ( ) ;
162+ GUILayout . EndHorizontal ( ) ;
159163
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 ) ;
165167
166- GUILayout . BeginVertical ( ) ;
167- {
168- GUILayout . BeginHorizontal ( ) ;
168+ GUILayout . BeginVertical ( ) ;
169169 {
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 ( ) ;
175175
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 ( ) ;
181183 }
182- GUILayout . EndHorizontal ( ) ;
183- }
184- GUILayout . EndVertical ( ) ;
185-
186-
187- GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
184+ GUILayout . EndVertical ( ) ; ;
188185
189- if ( error != null )
190- GUILayout . Label ( error , Styles . ErrorLabel ) ;
186+ GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
191187
192- GUILayout . FlexibleSpace ( ) ;
188+ if ( error != null )
189+ GUILayout . Label ( error , Styles . ErrorLabel ) ;
193190
194- GUILayout . BeginHorizontal ( ) ;
195- {
196191 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 ] ;
203192
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 ) )
208198 {
209- Logger . Trace ( "Create Repository Callback" ) ;
199+ isBusy = true ;
210200
211- if ( ex != null )
212- {
213- error = ex . Message ;
214- isBusy = false ;
215- return ;
216- }
201+ var organization = owners [ selectedOwner ] == username ? null : owners [ selectedOwner ] ;
217202
218- if ( repository == null )
203+ Client . CreateRepository ( new NewRepository ( repoName )
219204 {
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+ }
224216
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 ( ) ;
230231 }
231- GUI . enabled = true ;
232+ GUILayout . EndHorizontal ( ) ;
233+ GUILayout . Space ( 10 ) ;
232234 }
233- GUILayout . EndHorizontal ( ) ;
234- GUILayout . Space ( 10 ) ;
235+ EditorGUI . EndDisabledGroup ( ) ;
236+ }
237+
238+ private bool IsFormValid
239+ {
240+ get { return ! string . IsNullOrEmpty ( repoName ) ; }
235241 }
236242 }
237243}
0 commit comments