11using System ;
22using System . Linq ;
3+ using System . Threading . Tasks ;
34using Octokit ;
5+ using Rackspace . Threading ;
46using UnityEditor ;
57using UnityEngine ;
68
@@ -13,6 +15,10 @@ class PublishView : Subview
1315 private const string PublicRepoMessage = "Anyone can see this repository. You choose who can commit" ;
1416 private const string PublishViewCreateButton = "Publish" ;
1517 private const string OwnersDefaultText = "Select a user or org" ;
18+ private const string SelectedOwnerLabel = "Owner" ;
19+ private const string RepositoryNameLabel = "Repository Name" ;
20+ private const string DescriptionLabel = "Description" ;
21+ private const string CreatePrivateRepositoryLabel = "Create as a private repository" ;
1622
1723 [ SerializeField ] private string username ;
1824 [ SerializeField ] private string [ ] owners = { OwnersDefaultText } ;
@@ -60,37 +66,34 @@ private void PopulateView()
6066 try
6167 {
6268 var keychainConnections = Platform . Keychain . Connections ;
69+ //TODO: ONE_USER_LOGIN This assumes only ever one user can login
6370 if ( keychainConnections . Any ( ) )
6471 {
6572 Logger . Trace ( "GetCurrentUser" ) ;
6673
67- Client . GetCurrentUser ( user => {
68- if ( user == null )
74+ isBusy = true ;
75+
76+ Client . LoadKeychain ( hasKeys => {
77+ if ( ! hasKeys )
6978 {
7079 Logger . Warning ( "Unable to get current user" ) ;
80+ isBusy = false ;
7181 return ;
7282 }
7383
74- owners = owners . Union ( new [ ] { user . Login } ) . ToArray ( ) ;
75- username = user . Login ;
76-
77- Logger . Trace ( "GetOrganizations" ) ;
78-
79- Client . GetOrganizations ( organizations =>
80- {
81- if ( organizations == null )
82- {
83- Logger . Warning ( "Unable to get list of organizations" ) ;
84- return ;
85- }
84+ //TODO: ONE_USER_LOGIN This assumes only ever one user can login
85+ username = keychainConnections . First ( ) . Username ;
8686
87+ Client . GetOrganizations ( organizations => {
8788 Logger . Trace ( "Loaded {0} organizations" , organizations . Count ) ;
8889
8990 var organizationLogins = organizations
9091 . OrderBy ( organization => organization . Login )
9192 . Select ( organization => organization . Login ) ;
9293
93- owners = owners . Union ( organizationLogins ) . ToArray ( ) ;
94+ owners = new [ ] { username } . Union ( organizationLogins ) . ToArray ( ) ;
95+
96+ isBusy = false ;
9497 } ) ;
9598 } ) ;
9699 }
@@ -128,111 +131,111 @@ public override void OnGUI()
128131
129132 GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
130133
131- GUILayout . BeginHorizontal ( ) ;
134+ EditorGUI . BeginDisabledGroup ( isBusy ) ;
132135 {
133- GUILayout . BeginVertical ( ) ;
136+ GUILayout . BeginHorizontal ( ) ;
134137 {
135- GUILayout . Label ( "Owner" ) ;
138+ GUILayout . BeginVertical ( ) ;
139+ {
140+ GUILayout . Label ( SelectedOwnerLabel ) ;
136141
137- GUI . enabled = ! isBusy ;
138- selectedOwner = EditorGUILayout . Popup ( selectedOwner , owners ) ;
139- GUI . enabled = true ;
140- }
141- GUILayout . EndVertical ( ) ;
142+ selectedOwner = EditorGUILayout . Popup ( selectedOwner , owners ) ;
143+ }
144+ GUILayout . EndVertical ( ) ;
142145
143- GUILayout . BeginVertical ( GUILayout . Width ( 8 ) ) ;
144- {
145- GUILayout . Space ( 20 ) ;
146- GUILayout . Label ( "/" ) ;
147- }
148- GUILayout . EndVertical ( ) ;
146+ GUILayout . BeginVertical ( GUILayout . Width ( 8 ) ) ;
147+ {
148+ GUILayout . Space ( 20 ) ;
149+ GUILayout . Label ( "/" ) ;
150+ }
151+ GUILayout . EndVertical ( ) ;
149152
150- GUILayout . BeginVertical ( ) ;
151- {
152- GUILayout . Label ( "Repository Name" ) ;
153- GUI . enabled = ! isBusy ;
154- repoName = EditorGUILayout . TextField ( repoName ) ;
155- GUI . enabled = true ;
153+ GUILayout . BeginVertical ( ) ;
154+ {
155+ GUILayout . Label ( RepositoryNameLabel ) ;
156+ repoName = EditorGUILayout . TextField ( repoName ) ;
157+ }
158+ GUILayout . EndVertical ( ) ;
156159 }
157- GUILayout . EndVertical ( ) ;
158- }
159- GUILayout . EndHorizontal ( ) ;
160+ GUILayout . EndHorizontal ( ) ;
160161
161- GUILayout . Label ( "Description" ) ;
162- GUI . enabled = ! isBusy ;
163- repoDescription = EditorGUILayout . TextField ( repoDescription ) ;
164- GUI . enabled = true ;
165- GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
162+ GUILayout . Label ( DescriptionLabel ) ;
163+ repoDescription = EditorGUILayout . TextField ( repoDescription ) ;
164+ GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
166165
167- GUILayout . BeginVertical ( ) ;
168- {
169- GUILayout . BeginHorizontal ( ) ;
166+ GUILayout . BeginVertical ( ) ;
170167 {
171- GUI . enabled = ! isBusy ;
172- togglePrivate = GUILayout . Toggle ( togglePrivate , "Create as a private repository" ) ;
173- GUI . enabled = true ;
174- }
175- GUILayout . EndHorizontal ( ) ;
168+ GUILayout . BeginHorizontal ( ) ;
169+ {
170+ togglePrivate = GUILayout . Toggle ( togglePrivate , CreatePrivateRepositoryLabel ) ;
171+ }
172+ GUILayout . EndHorizontal ( ) ;
176173
177- GUILayout . BeginHorizontal ( ) ;
178- {
179- GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
180- var repoPrivacyExplanation = togglePrivate ? PrivateRepoMessage : PublicRepoMessage ;
181- GUILayout . Label ( repoPrivacyExplanation , Styles . LongMessageStyle ) ;
174+ GUILayout . BeginHorizontal ( ) ;
175+ {
176+ GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
177+ var repoPrivacyExplanation = togglePrivate ? PrivateRepoMessage : PublicRepoMessage ;
178+ GUILayout . Label ( repoPrivacyExplanation , Styles . LongMessageStyle ) ;
179+ }
180+ GUILayout . EndHorizontal ( ) ;
182181 }
183- GUILayout . EndHorizontal ( ) ;
184- }
185- GUILayout . EndVertical ( ) ;
186-
182+ GUILayout . EndVertical ( ) ; ;
187183
188- GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
184+ GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
189185
190- if ( error != null )
191- GUILayout . Label ( error , Styles . ErrorLabel ) ;
186+ if ( error != null )
187+ GUILayout . Label ( error , Styles . ErrorLabel ) ;
192188
193- GUILayout . FlexibleSpace ( ) ;
194-
195- GUILayout . BeginHorizontal ( ) ;
196- {
197189 GUILayout . FlexibleSpace ( ) ;
198- GUI . enabled = ! string . IsNullOrEmpty ( repoName ) && ! isBusy && selectedOwner != 0 ;
199- if ( GUILayout . Button ( PublishViewCreateButton ) )
200- {
201- isBusy = true ;
202-
203- var organization = owners [ selectedOwner ] == username ? null : owners [ selectedOwner ] ;
204190
205- Client . CreateRepository ( new NewRepository ( repoName )
206- {
207- Private = togglePrivate ,
208- } , ( repository , ex ) =>
191+ GUILayout . BeginHorizontal ( ) ;
192+ {
193+ GUILayout . FlexibleSpace ( ) ;
194+ EditorGUI . BeginDisabledGroup ( ! IsFormValid ) ;
195+ if ( GUILayout . Button ( PublishViewCreateButton ) )
209196 {
210- Logger . Trace ( "Create Repository Callback" ) ;
197+ isBusy = true ;
211198
212- if ( ex != null )
213- {
214- error = ex . Message ;
215- isBusy = false ;
216- return ;
217- }
199+ var organization = owners [ selectedOwner ] == username ? null : owners [ selectedOwner ] ;
218200
219- if ( repository == null )
201+ Client . CreateRepository ( new NewRepository ( repoName )
220202 {
221- Logger . Warning ( "Returned Repository is null" ) ;
222- isBusy = false ;
223- return ;
224- }
203+ Private = togglePrivate ,
204+ } , ( repository , ex ) =>
205+ {
206+ Logger . Trace ( "Create Repository Callback" ) ;
225207
226- GitClient . RemoteAdd ( "origin" , repository . CloneUrl )
227- . Then ( GitClient . Push ( "origin" , Repository . CurrentBranch . Value . Name ) )
228- . ThenInUI ( Parent . Finish )
229- . Start ( ) ;
230- } , organization ) ;
208+ if ( ex != null )
209+ {
210+ error = ex . Message ;
211+ isBusy = false ;
212+ return ;
213+ }
214+
215+ if ( repository == null )
216+ {
217+ Logger . Warning ( "Returned Repository is null" ) ;
218+ isBusy = false ;
219+ return ;
220+ }
221+
222+ GitClient . RemoteAdd ( "origin" , repository . CloneUrl )
223+ . Then ( GitClient . Push ( "origin" , Repository . CurrentBranch . Value . Name ) )
224+ . ThenInUI ( Finish )
225+ . Start ( ) ;
226+ } , organization ) ;
227+ }
228+ EditorGUI . EndDisabledGroup ( ) ;
231229 }
232- GUI . enabled = true ;
230+ GUILayout . EndHorizontal ( ) ;
231+ GUILayout . Space ( 10 ) ;
233232 }
234- GUILayout . EndHorizontal ( ) ;
235- GUILayout . Space ( 10 ) ;
233+ EditorGUI . EndDisabledGroup ( ) ;
234+ }
235+
236+ private bool IsFormValid
237+ {
238+ get { return ! string . IsNullOrEmpty ( repoName ) && ! isBusy && selectedOwner != 0 ; }
236239 }
237240 }
238241}
0 commit comments