This repository was archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathSampleViewModels.cs
More file actions
455 lines (381 loc) · 12.3 KB
/
Copy pathSampleViewModels.cs
File metadata and controls
455 lines (381 loc) · 12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Reactive;
using System.Threading.Tasks;
using System.Windows.Input;
using GitHub.Extensions;
using GitHub.Models;
using GitHub.Primitives;
using GitHub.UI;
using GitHub.Validation;
using GitHub.ViewModels;
using GitHub.ViewModels.Dialog;
using GitHub.ViewModels.TeamExplorer;
using GitHub.VisualStudio.TeamExplorer.Connect;
using GitHub.VisualStudio.TeamExplorer.Home;
using ReactiveUI;
namespace GitHub.SampleData
{
[ExcludeFromCodeCoverage]
public class RepositoryCreationViewModelDesigner : ViewModelBase, IRepositoryCreationViewModel
{
public RepositoryCreationViewModelDesigner()
{
RepositoryName = "Hello-World";
Description = "A description";
KeepPrivate = true;
CanKeepPrivate = true;
Accounts = new ReactiveList<IAccount>
{
new AccountDesigner { Login = "shana" },
new AccountDesigner { Login = "GitHub", IsUser = false }
};
SelectedAccount = Accounts[0];
GitIgnoreTemplates = new ReactiveList<GitIgnoreItem>
{
GitIgnoreItem.Create("VisualStudio"),
GitIgnoreItem.Create("Wap"),
GitIgnoreItem.Create("WordPress")
};
SelectedGitIgnoreTemplate = GitIgnoreTemplates[0];
Licenses = new ReactiveList<LicenseItem>
{
new LicenseItem("agpl-3.0", "GNU Affero GPL v3.0"),
new LicenseItem("apache-2.0", "Apache License 2.0"),
new LicenseItem("artistic-2.0", "Artistic License 2.0"),
new LicenseItem("mit", "MIT License")
};
SelectedLicense = Licenses[0];
}
public string Title { get { return "Create a GitHub Repository"; } } // TODO: this needs to be contextual
public IReadOnlyList<IAccount> Accounts
{
get;
set;
}
public string BaseRepositoryPath
{
get;
set;
}
public ReactivePropertyValidator<string> BaseRepositoryPathValidator
{
get;
private set;
}
public ICommand BrowseForDirectory
{
get;
private set;
}
public bool CanKeepPrivate
{
get;
private set;
}
public IReactiveCommand<Unit> CreateRepository
{
get;
private set;
}
public string Description
{
get;
set;
}
public bool IsCreating
{
get;
private set;
}
public bool KeepPrivate
{
get;
set;
}
public string RepositoryName
{
get;
set;
}
public ReactivePropertyValidator<string> RepositoryNameValidator
{
get;
private set;
}
public ICommand Reset
{
get;
private set;
}
public string SafeRepositoryName
{
get;
private set;
}
public ReactivePropertyValidator<string> SafeRepositoryNameWarningValidator
{
get;
private set;
}
public IAccount SelectedAccount
{
get;
set;
}
public bool ShowUpgradePlanWarning
{
get;
private set;
}
public bool ShowUpgradeToMicroPlanWarning
{
get;
private set;
}
public ICommand UpgradeAccountPlan
{
get;
private set;
}
public IReadOnlyList<GitIgnoreItem> GitIgnoreTemplates
{
get; private set;
}
public IReadOnlyList<LicenseItem> Licenses
{
get; private set;
}
public GitIgnoreItem SelectedGitIgnoreTemplate
{
get;
set;
}
public LicenseItem SelectedLicense
{
get;
set;
}
public IObservable<object> Done { get; }
public Task InitializeAsync(IConnection connection) => Task.CompletedTask;
}
[ExcludeFromCodeCoverage]
public sealed class RepositoryPublishViewModelDesigner : RepositoryCreationViewModelDesigner, IRepositoryPublishViewModel
{
class Conn : IConnection
{
public HostAddress HostAddress { get; set; }
public string Username { get; set; }
public ObservableCollection<ILocalRepositoryModel> Repositories { get; set; }
public Octokit.User User => null;
public bool IsLoggedIn => true;
public bool IsLoggingIn => false;
public Exception ConnectionError => null;
event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
{
add { }
remove { }
}
}
public RepositoryPublishViewModelDesigner()
{
Connections = new ObservableCollectionEx<IConnection>
{
new Conn() { HostAddress = new HostAddress() },
new Conn() { HostAddress = HostAddress.Create("ghe.io") }
};
SelectedConnection = Connections[0];
}
public bool IsBusy { get; set; }
public bool IsHostComboBoxVisible
{
get
{
return true;
}
}
public IReactiveCommand<ProgressState> PublishRepository
{
get;
private set;
}
public IReadOnlyObservableCollection<IConnection> Connections
{
get;
private set;
}
public IConnection SelectedConnection
{
get; set;
}
}
[ExcludeFromCodeCoverage]
public static class RepositoryModelDesigner
{
public static IRemoteRepositoryModel Create(string name = null, string owner = null)
{
name = name ?? "octocat";
owner = owner ?? "github";
return new RemoteRepositoryModel(0, name, new UriString("http://github.com/" + name + "/" + owner), false, false, new AccountDesigner() { Login = owner }, null);
}
}
public class RepositoryCloneViewModelDesigner : ViewModelBase, IRepositoryCloneViewModel
{
public RepositoryCloneViewModelDesigner()
{
Repositories = new ObservableCollection<IRemoteRepositoryModel>
{
RepositoryModelDesigner.Create("encourage", "haacked"),
RepositoryModelDesigner.Create("haacked.com", "haacked"),
RepositoryModelDesigner.Create("octokit.net", "octokit"),
RepositoryModelDesigner.Create("octokit.rb", "octokit"),
RepositoryModelDesigner.Create("octokit.objc", "octokit"),
RepositoryModelDesigner.Create("windows", "github"),
RepositoryModelDesigner.Create("mac", "github"),
RepositoryModelDesigner.Create("github", "github")
};
BrowseForDirectory = ReactiveCommand.Create();
BaseRepositoryPathValidator = ReactivePropertyValidator.ForObservable(this.WhenAny(x => x.BaseRepositoryPath, x => x.Value))
.IfNullOrEmpty("Please enter a repository path")
.IfTrue(x => x.Length > 200, "Path too long")
.IfContainsInvalidPathChars("Path contains invalid characters")
.IfPathNotRooted("Please enter a valid path");
}
public IReactiveCommand<object> CloneCommand
{
get;
private set;
}
public IRepositoryModel SelectedRepository { get; set; }
public ObservableCollection<IRemoteRepositoryModel> Repositories
{
get;
private set;
}
public bool FilterTextIsEnabled
{
get;
private set;
}
public string FilterText { get; set; }
public string Title { get { return "Clone a GitHub Repository"; } }
public IReactiveCommand<IReadOnlyList<IRemoteRepositoryModel>> LoadRepositoriesCommand
{
get;
private set;
}
public bool LoadingFailed
{
get { return false; }
}
public bool NoRepositoriesFound
{
get;
set;
}
public ICommand BrowseForDirectory
{
get;
private set;
}
public string BaseRepositoryPath
{
get;
set;
}
public bool CanClone
{
get;
private set;
}
public ReactivePropertyValidator<string> BaseRepositoryPathValidator
{
get;
private set;
}
public IObservable<object> Done { get; }
public Task InitializeAsync(IConnection connection) => Task.CompletedTask;
}
public class GitHubHomeSectionDesigner : IGitHubHomeSection
{
public GitHubHomeSectionDesigner()
{
Icon = Octicon.repo;
RepoName = "octokit";
RepoUrl = "https://github.com/octokit/something-really-long-here-to-check-for-trimming";
IsLoggedIn = false;
}
public Octicon Icon
{
get;
private set;
}
public bool IsLoggedIn
{
get;
private set;
}
public string RepoName
{
get;
set;
}
public string RepoUrl
{
get;
set;
}
public void Login()
{
}
public ICommand OpenOnGitHub { get; }
}
public class GitHubConnectSectionDesigner : IGitHubConnectSection
{
public GitHubConnectSectionDesigner()
{
Repositories = new ObservableCollection<ILocalRepositoryModel>();
Repositories.Add(new LocalRepositoryModel("octokit", new UriString("https://github.com/octokit/octokit.net"), @"C:\Users\user\Source\Repos\octokit.net", new GitServiceDesigner()));
Repositories.Add(new LocalRepositoryModel("cefsharp", new UriString("https://github.com/cefsharp/cefsharp"), @"C:\Users\user\Source\Repos\cefsharp", new GitServiceDesigner()));
Repositories.Add(new LocalRepositoryModel("git-lfs", new UriString("https://github.com/github/git-lfs"), @"C:\Users\user\Source\Repos\git-lfs", new GitServiceDesigner()));
Repositories.Add(new LocalRepositoryModel("another octokit", new UriString("https://github.com/octokit/octokit.net"), @"C:\Users\user\Source\Repos\another-octokit.net", new GitServiceDesigner()));
Repositories.Add(new LocalRepositoryModel("some cefsharp", new UriString("https://github.com/cefsharp/cefsharp"), @"C:\Users\user\Source\Repos\something-else", new GitServiceDesigner()));
Repositories.Add(new LocalRepositoryModel("even more git-lfs", new UriString("https://github.com/github/git-lfs"), @"C:\Users\user\Source\Repos\A different path", new GitServiceDesigner()));
}
public ObservableCollection<ILocalRepositoryModel> Repositories
{
get; set;
}
public void DoCreate()
{
}
public void SignOut()
{
}
public void Login()
{
}
public void Retry()
{
}
public bool OpenRepository()
{
return true;
}
public string ErrorMessage { get; set; }
public IConnection SectionConnection { get; }
public bool IsLoggingIn { get; set; }
public bool ShowLogin { get; set; }
public bool ShowLogout { get; set; }
public bool ShowRetry { get; set; }
public ICommand Clone { get; }
}
public class InfoPanelDesigner
{
public string Message => "This is an informational message for the [info panel](link) to test things in design mode.";
public MessageType MessageType => MessageType.Information;
}
}