1
1
using System ;
2
2
using System . Linq ;
3
+ using System . Threading . Tasks ;
3
4
using Octokit ;
5
+ using Rackspace . Threading ;
4
6
using UnityEditor ;
5
7
using UnityEngine ;
6
8
@@ -13,6 +15,10 @@ class PublishView : Subview
13
15
private const string PublicRepoMessage = "Anyone can see this repository. You choose who can commit" ;
14
16
private const string PublishViewCreateButton = "Publish" ;
15
17
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" ;
16
22
17
23
[ SerializeField ] private string username ;
18
24
[ SerializeField ] private string [ ] owners = { OwnersDefaultText } ;
@@ -60,37 +66,34 @@ private void PopulateView()
60
66
try
61
67
{
62
68
var keychainConnections = Platform . Keychain . Connections ;
69
+ //TODO: ONE_USER_LOGIN This assumes only ever one user can login
63
70
if ( keychainConnections . Any ( ) )
64
71
{
65
72
Logger . Trace ( "GetCurrentUser" ) ;
66
73
67
- Client . GetCurrentUser ( user => {
68
- if ( user == null )
74
+ isBusy = true ;
75
+
76
+ Client . LoadKeychain ( hasKeys => {
77
+ if ( ! hasKeys )
69
78
{
70
79
Logger . Warning ( "Unable to get current user" ) ;
80
+ isBusy = false ;
71
81
return ;
72
82
}
73
83
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 ;
86
86
87
+ Client . GetOrganizations ( organizations => {
87
88
Logger . Trace ( "Loaded {0} organizations" , organizations . Count ) ;
88
89
89
90
var organizationLogins = organizations
90
91
. OrderBy ( organization => organization . Login )
91
92
. Select ( organization => organization . Login ) ;
92
93
93
- owners = owners . Union ( organizationLogins ) . ToArray ( ) ;
94
+ owners = new [ ] { username } . Union ( organizationLogins ) . ToArray ( ) ;
95
+
96
+ isBusy = false ;
94
97
} ) ;
95
98
} ) ;
96
99
}
@@ -128,111 +131,111 @@ public override void OnGUI()
128
131
129
132
GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
130
133
131
- GUILayout . BeginHorizontal ( ) ;
134
+ EditorGUI . BeginDisabledGroup ( isBusy ) ;
132
135
{
133
- GUILayout . BeginVertical ( ) ;
136
+ GUILayout . BeginHorizontal ( ) ;
134
137
{
135
- GUILayout . Label ( "Owner" ) ;
138
+ GUILayout . BeginVertical ( ) ;
139
+ {
140
+ GUILayout . Label ( SelectedOwnerLabel ) ;
136
141
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 ( ) ;
142
145
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 ( ) ;
149
152
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 ( ) ;
156
159
}
157
- GUILayout . EndVertical ( ) ;
158
- }
159
- GUILayout . EndHorizontal ( ) ;
160
+ GUILayout . EndHorizontal ( ) ;
160
161
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 ) ;
166
165
167
- GUILayout . BeginVertical ( ) ;
168
- {
169
- GUILayout . BeginHorizontal ( ) ;
166
+ GUILayout . BeginVertical ( ) ;
170
167
{
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 ( ) ;
176
173
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 ( ) ;
182
181
}
183
- GUILayout . EndHorizontal ( ) ;
184
- }
185
- GUILayout . EndVertical ( ) ;
186
-
182
+ GUILayout . EndVertical ( ) ; ;
187
183
188
- GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
184
+ GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
189
185
190
- if ( error != null )
191
- GUILayout . Label ( error , Styles . ErrorLabel ) ;
186
+ if ( error != null )
187
+ GUILayout . Label ( error , Styles . ErrorLabel ) ;
192
188
193
- GUILayout . FlexibleSpace ( ) ;
194
-
195
- GUILayout . BeginHorizontal ( ) ;
196
- {
197
189
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 ] ;
204
190
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 ) )
209
196
{
210
- Logger . Trace ( "Create Repository Callback" ) ;
197
+ isBusy = true ;
211
198
212
- if ( ex != null )
213
- {
214
- error = ex . Message ;
215
- isBusy = false ;
216
- return ;
217
- }
199
+ var organization = owners [ selectedOwner ] == username ? null : owners [ selectedOwner ] ;
218
200
219
- if ( repository == null )
201
+ Client . CreateRepository ( new NewRepository ( repoName )
220
202
{
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" ) ;
225
207
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 ( ) ;
231
229
}
232
- GUI . enabled = true ;
230
+ GUILayout . EndHorizontal ( ) ;
231
+ GUILayout . Space ( 10 ) ;
233
232
}
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 ; }
236
239
}
237
240
}
238
241
}
0 commit comments