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
@@ -13,6 +14,10 @@ class PublishView : Subview
13
14
private const string PublicRepoMessage = "Anyone can see this repository. You choose who can commit" ;
14
15
private const string PublishViewCreateButton = "Publish" ;
15
16
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" ;
16
21
17
22
[ SerializeField ] private string username ;
18
23
[ SerializeField ] private string [ ] owners = { OwnersDefaultText } ;
@@ -64,10 +69,13 @@ private void PopulateView()
64
69
{
65
70
Logger . Trace ( "GetCurrentUser" ) ;
66
71
72
+ isBusy = true ;
73
+
67
74
Client . GetCurrentUser ( user => {
68
75
if ( user == null )
69
76
{
70
77
Logger . Warning ( "Unable to get current user" ) ;
78
+ isBusy = false ;
71
79
return ;
72
80
}
73
81
@@ -76,11 +84,11 @@ private void PopulateView()
76
84
77
85
Logger . Trace ( "GetOrganizations" ) ;
78
86
79
- Client . GetOrganizations ( organizations =>
80
- {
87
+ Client . GetOrganizations ( organizations => {
81
88
if ( organizations == null )
82
89
{
83
90
Logger . Warning ( "Unable to get list of organizations" ) ;
91
+ isBusy = false ;
84
92
return ;
85
93
}
86
94
@@ -91,6 +99,7 @@ private void PopulateView()
91
99
. Select ( organization => organization . Login ) ;
92
100
93
101
owners = owners . Union ( organizationLogins ) . ToArray ( ) ;
102
+ isBusy = false ;
94
103
} ) ;
95
104
} ) ;
96
105
}
@@ -128,111 +137,111 @@ public override void OnGUI()
128
137
129
138
GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
130
139
131
- GUILayout . BeginHorizontal ( ) ;
140
+ EditorGUI . BeginDisabledGroup ( isBusy ) ;
132
141
{
133
- GUILayout . BeginVertical ( ) ;
142
+ GUILayout . BeginHorizontal ( ) ;
134
143
{
135
- GUILayout . Label ( "Owner" ) ;
144
+ GUILayout . BeginVertical ( ) ;
145
+ {
146
+ GUILayout . Label ( SelectedOwnerLabel ) ;
136
147
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 ( ) ;
142
151
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 ( ) ;
149
158
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 ( ) ;
156
165
}
157
- GUILayout . EndVertical ( ) ;
158
- }
159
- GUILayout . EndHorizontal ( ) ;
166
+ GUILayout . EndHorizontal ( ) ;
160
167
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 ) ;
166
171
167
- GUILayout . BeginVertical ( ) ;
168
- {
169
- GUILayout . BeginHorizontal ( ) ;
172
+ GUILayout . BeginVertical ( ) ;
170
173
{
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 ( ) ;
176
179
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 ( ) ;
182
187
}
183
- GUILayout . EndHorizontal ( ) ;
184
- }
185
- GUILayout . EndVertical ( ) ;
188
+ GUILayout . EndVertical ( ) ; ;
186
189
190
+ GUILayout . Space ( Styles . PublishViewSpacingHeight ) ;
187
191
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 ) ;
192
194
193
- GUILayout . FlexibleSpace ( ) ;
194
-
195
- GUILayout . BeginHorizontal ( ) ;
196
- {
197
195
GUILayout . FlexibleSpace ( ) ;
198
- GUI . enabled = ! string . IsNullOrEmpty ( repoName ) && ! isBusy && selectedOwner != 0 ;
199
- if ( GUILayout . Button ( PublishViewCreateButton ) )
200
- {
201
- isBusy = true ;
202
196
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 ) )
209
202
{
210
- Logger . Trace ( "Create Repository Callback" ) ;
203
+ isBusy = true ;
211
204
212
- if ( ex != null )
213
- {
214
- error = ex . Message ;
215
- isBusy = false ;
216
- return ;
217
- }
205
+ var organization = owners [ selectedOwner ] == username ? null : owners [ selectedOwner ] ;
218
206
219
- if ( repository == null )
207
+ Client . CreateRepository ( new NewRepository ( repoName )
220
208
{
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" ) ;
225
213
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 ( ) ;
231
235
}
232
- GUI . enabled = true ;
236
+ GUILayout . EndHorizontal ( ) ;
237
+ GUILayout . Space ( 10 ) ;
233
238
}
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 ; }
236
245
}
237
246
}
238
247
}
0 commit comments