11using System ;
22using System . Linq ;
33using Octokit ;
4+ using Rackspace . Threading ;
45using UnityEditor ;
56using UnityEngine ;
67
@@ -13,6 +14,10 @@ class PublishView : Subview
1314 private const string PublicRepoMessage = "Anyone can see this repository. You choose who can commit" ;
1415 private const string PublishViewCreateButton = "Publish" ;
1516 private const string OwnersDefaultText = "Select a user or org" ;
17+ private const string SelectedOwnerLabel = "Owner" ;
18+ private const string RepositoryNameLabel = "Repository Name" ;
19+ private const string DescriptionLabel = "Description" ;
20+ private const string CreatePrivateRepositoryLabel = "Create as a private repository" ;
1621
1722 [ SerializeField ] private string username ;
1823 [ SerializeField ] private string [ ] owners = { OwnersDefaultText } ;
@@ -64,10 +69,13 @@ private void PopulateView()
6469 {
6570 Logger . Trace ( "GetCurrentUser" ) ;
6671
72+ isBusy = true ;
73+
6774 Client . GetCurrentUser ( user => {
6875 if ( user == null )
6976 {
7077 Logger . Warning ( "Unable to get current user" ) ;
78+ isBusy = false ;
7179 return ;
7280 }
7381
@@ -76,11 +84,11 @@ private void PopulateView()
7684
7785 Logger . Trace ( "GetOrganizations" ) ;
7886
79- Client . GetOrganizations ( organizations =>
80- {
87+ Client . GetOrganizations ( organizations => {
8188 if ( organizations == null )
8289 {
8390 Logger . Warning ( "Unable to get list of organizations" ) ;
91+ isBusy = false ;
8492 return ;
8593 }
8694
@@ -91,6 +99,7 @@ private void PopulateView()
9199 . Select ( organization => organization . Login ) ;
92100
93101 owners = owners . Union ( organizationLogins ) . ToArray ( ) ;
102+ isBusy = false ;
94103 } ) ;
95104 } ) ;
96105 }
@@ -128,111 +137,111 @@ public override void OnGUI()
128137
129138 GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
130139
131- GUILayout . BeginHorizontal ( ) ;
140+ EditorGUI . BeginDisabledGroup ( isBusy ) ;
132141 {
133- GUILayout . BeginVertical ( ) ;
142+ GUILayout . BeginHorizontal ( ) ;
134143 {
135- GUILayout . Label ( "Owner" ) ;
144+ GUILayout . BeginVertical ( ) ;
145+ {
146+ GUILayout . Label ( SelectedOwnerLabel ) ;
136147
137- GUI . enabled = ! isBusy ;
138- selectedOwner = EditorGUILayout . Popup ( selectedOwner , owners ) ;
139- GUI . enabled = true ;
140- }
141- GUILayout . EndVertical ( ) ;
148+ selectedOwner = EditorGUILayout . Popup ( selectedOwner , owners ) ;
149+ }
150+ GUILayout . EndVertical ( ) ;
142151
143- GUILayout . BeginVertical ( GUILayout . Width ( 8 ) ) ;
144- {
145- GUILayout . Space ( 20 ) ;
146- GUILayout . Label ( "/" ) ;
147- }
148- GUILayout . EndVertical ( ) ;
152+ GUILayout . BeginVertical ( GUILayout . Width ( 8 ) ) ;
153+ {
154+ GUILayout . Space ( 20 ) ;
155+ GUILayout . Label ( "/" ) ;
156+ }
157+ GUILayout . EndVertical ( ) ;
149158
150- GUILayout . BeginVertical ( ) ;
151- {
152- GUILayout . Label ( "Repository Name" ) ;
153- GUI . enabled = ! isBusy ;
154- repoName = EditorGUILayout . TextField ( repoName ) ;
155- GUI . enabled = true ;
159+ GUILayout . BeginVertical ( ) ;
160+ {
161+ GUILayout . Label ( RepositoryNameLabel ) ;
162+ repoName = EditorGUILayout . TextField ( repoName ) ;
163+ }
164+ GUILayout . EndVertical ( ) ;
156165 }
157- GUILayout . EndVertical ( ) ;
158- }
159- GUILayout . EndHorizontal ( ) ;
166+ GUILayout . EndHorizontal ( ) ;
160167
161- GUILayout . Label ( "Description" ) ;
162- GUI . enabled = ! isBusy ;
163- repoDescription = EditorGUILayout . TextField ( repoDescription ) ;
164- GUI . enabled = true ;
165- GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
168+ GUILayout . Label ( DescriptionLabel ) ;
169+ repoDescription = EditorGUILayout . TextField ( repoDescription ) ;
170+ GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
166171
167- GUILayout . BeginVertical ( ) ;
168- {
169- GUILayout . BeginHorizontal ( ) ;
172+ GUILayout . BeginVertical ( ) ;
170173 {
171- GUI . enabled = ! isBusy ;
172- togglePrivate = GUILayout . Toggle ( togglePrivate , "Create as a private repository" ) ;
173- GUI . enabled = true ;
174- }
175- GUILayout . EndHorizontal ( ) ;
174+ GUILayout . BeginHorizontal ( ) ;
175+ {
176+ togglePrivate = GUILayout . Toggle ( togglePrivate , CreatePrivateRepositoryLabel ) ;
177+ }
178+ GUILayout . EndHorizontal ( ) ;
176179
177- GUILayout . BeginHorizontal ( ) ;
178- {
179- GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
180- var repoPrivacyExplanation = togglePrivate ? PrivateRepoMessage : PublicRepoMessage ;
181- GUILayout . Label ( repoPrivacyExplanation , Styles . LongMessageStyle ) ;
180+ GUILayout . BeginHorizontal ( ) ;
181+ {
182+ GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
183+ var repoPrivacyExplanation = togglePrivate ? PrivateRepoMessage : PublicRepoMessage ;
184+ GUILayout . Label ( repoPrivacyExplanation , Styles . LongMessageStyle ) ;
185+ }
186+ GUILayout . EndHorizontal ( ) ;
182187 }
183- GUILayout . EndHorizontal ( ) ;
184- }
185- GUILayout . EndVertical ( ) ;
188+ GUILayout . EndVertical ( ) ; ;
186189
190+ GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
187191
188- GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
189-
190- if ( error != null )
191- GUILayout . Label ( error , Styles . ErrorLabel ) ;
192+ if ( error != null )
193+ GUILayout . Label ( error , Styles . ErrorLabel ) ;
192194
193- GUILayout . FlexibleSpace ( ) ;
194-
195- GUILayout . BeginHorizontal ( ) ;
196- {
197195 GUILayout . FlexibleSpace ( ) ;
198- GUI . enabled = ! string . IsNullOrEmpty ( repoName ) && ! isBusy && selectedOwner != 0 ;
199- if ( GUILayout . Button ( PublishViewCreateButton ) )
200- {
201- isBusy = true ;
202196
203- var organization = owners [ selectedOwner ] == username ? null : owners [ selectedOwner ] ;
204-
205- Client . CreateRepository ( new NewRepository ( repoName )
206- {
207- Private = togglePrivate ,
208- } , ( repository , ex ) =>
197+ GUILayout . BeginHorizontal ( ) ;
198+ {
199+ GUILayout . FlexibleSpace ( ) ;
200+ EditorGUI . BeginDisabledGroup ( ! IsFormValid ) ;
201+ if ( GUILayout . Button ( PublishViewCreateButton ) )
209202 {
210- Logger . Trace ( "Create Repository Callback" ) ;
203+ isBusy = true ;
211204
212- if ( ex != null )
213- {
214- error = ex . Message ;
215- isBusy = false ;
216- return ;
217- }
205+ var organization = owners [ selectedOwner ] == username ? null : owners [ selectedOwner ] ;
218206
219- if ( repository == null )
207+ Client . CreateRepository ( new NewRepository ( repoName )
220208 {
221- Logger . Warning ( "Returned Repository is null" ) ;
222- isBusy = false ;
223- return ;
224- }
209+ Private = togglePrivate ,
210+ } , ( repository , ex ) =>
211+ {
212+ Logger . Trace ( "Create Repository Callback" ) ;
225213
226- GitClient . RemoteAdd ( "origin" , repository . CloneUrl )
227- . Then ( GitClient . Push ( "origin" , Repository . CurrentBranch . Value . Name ) )
228- . ThenInUI ( Parent . Finish )
229- . Start ( ) ;
230- } , organization ) ;
214+ if ( ex != null )
215+ {
216+ error = ex . Message ;
217+ isBusy = false ;
218+ return ;
219+ }
220+
221+ if ( repository == null )
222+ {
223+ Logger . Warning ( "Returned Repository is null" ) ;
224+ isBusy = false ;
225+ return ;
226+ }
227+
228+ GitClient . RemoteAdd ( "origin" , repository . CloneUrl )
229+ . Then ( GitClient . Push ( "origin" , Repository . CurrentBranch . Value . Name ) )
230+ . ThenInUI ( Finish )
231+ . Start ( ) ;
232+ } , organization ) ;
233+ }
234+ EditorGUI . EndDisabledGroup ( ) ;
231235 }
232- GUI . enabled = true ;
236+ GUILayout . EndHorizontal ( ) ;
237+ GUILayout . Space ( 10 ) ;
233238 }
234- GUILayout . EndHorizontal ( ) ;
235- GUILayout . Space ( 10 ) ;
239+ EditorGUI . EndDisabledGroup ( ) ;
240+ }
241+
242+ private bool IsFormValid
243+ {
244+ get { return ! string . IsNullOrEmpty ( repoName ) && ! isBusy && selectedOwner != 0 ; }
236245 }
237246 }
238247}
0 commit comments