|
36 | 36 | class Program |
37 | 37 | { |
38 | 38 | [Signal("validationStarted")] |
| 39 | + [Signal("examplesLoaded")] |
39 | 40 | [Signal("updateAvailable", NetVariantType.String)] |
40 | 41 | public class AppModel : IDisposable |
41 | 42 | { |
@@ -245,6 +246,23 @@ public List<Issue> DotnetIssues |
245 | 246 | set => this.SetProperty(ref _dotnetIssues, value); |
246 | 247 | } |
247 | 248 |
|
| 249 | + // exposes examples to QML |
| 250 | + private List<Example> _examples = new List<Example>(); |
| 251 | + [NotifySignal] |
| 252 | + public List<Example> Examples |
| 253 | + { |
| 254 | + get => _examples; |
| 255 | + set => this.SetProperty(ref _examples, value); |
| 256 | + } |
| 257 | + |
| 258 | + // loads examples from disk |
| 259 | + public class DiskExample |
| 260 | + { |
| 261 | + public string Filename { get; set; } |
| 262 | + public string Title { get; set; } |
| 263 | + public string Description { get; set; } |
| 264 | + } |
| 265 | + |
248 | 266 | private bool _javaValidationCrashed; |
249 | 267 | [NotifySignal] |
250 | 268 | public bool JavaValidationCrashed |
@@ -378,6 +396,33 @@ public int LinePosition |
378 | 396 | } |
379 | 397 | } |
380 | 398 |
|
| 399 | + public class Example |
| 400 | + { |
| 401 | + private string _filepath; |
| 402 | + [NotifySignal] |
| 403 | + public string Filepath |
| 404 | + { |
| 405 | + get => _filepath; |
| 406 | + set => this.SetProperty(ref _filepath, value); |
| 407 | + } |
| 408 | + |
| 409 | + private string _title; |
| 410 | + [NotifySignal] |
| 411 | + public string Title |
| 412 | + { |
| 413 | + get => _title; |
| 414 | + set => this.SetProperty(ref _title, value); |
| 415 | + } |
| 416 | + |
| 417 | + private string _description; |
| 418 | + [NotifySignal] |
| 419 | + public string Description |
| 420 | + { |
| 421 | + get => _description; |
| 422 | + set => this.SetProperty(ref _description, value); |
| 423 | + } |
| 424 | + } |
| 425 | + |
381 | 426 | private class MarkdownIssue |
382 | 427 | { |
383 | 428 | public string Severity; |
@@ -987,6 +1032,27 @@ public async void StartValidation() |
987 | 1032 | } |
988 | 1033 | } |
989 | 1034 |
|
| 1035 | + // load examples. This should be done syncronously: https://ux.stackexchange.com/q/138673/108628 |
| 1036 | + // but if it can be made quicker, then even better |
| 1037 | + public void LoadExamples() |
| 1038 | + { |
| 1039 | + JArray jsonExamples = JArray.Parse(File.ReadAllText(Path.Combine(AppModel.Extensions.GetApplicationLocation(), "assets", "examples", "metadata.json"))); |
| 1040 | + |
| 1041 | + Examples = new List<Example>(); |
| 1042 | + foreach (JToken jsonExample in jsonExamples) |
| 1043 | + { |
| 1044 | + var diskExample = jsonExample.ToObject<DiskExample>(); |
| 1045 | + var example = new Example { |
| 1046 | + Filepath = $"file://{Path.Combine(AppModel.Extensions.GetApplicationLocation(), "assets", "examples", diskExample.Filename)}", |
| 1047 | + Title = diskExample.Title, |
| 1048 | + Description = diskExample.Description, |
| 1049 | + |
| 1050 | + }; |
| 1051 | + Examples.Add(example); |
| 1052 | + } |
| 1053 | + this.ActivateSignal("examplesLoaded"); |
| 1054 | + } |
| 1055 | + |
990 | 1056 | public void CancelValidation() |
991 | 1057 | { |
992 | 1058 | // Signal the CancellationToken in the tasks that we want to cancel. |
@@ -1215,6 +1281,12 @@ static int Main(string[] args) |
1215 | 1281 | // instance. |
1216 | 1282 | cliParser.Process(); |
1217 | 1283 |
|
| 1284 | + // do this async |
| 1285 | + Stopwatch sw = Stopwatch.StartNew(); |
| 1286 | + AppModel.Instance.LoadExamples(); |
| 1287 | + sw.Stop(); |
| 1288 | + Console.WriteLine("LoadExamples time taken: {0}ms", sw.Elapsed.TotalMilliseconds); |
| 1289 | + |
1218 | 1290 | AppModel.Instance.CheckForUpdates(); |
1219 | 1291 |
|
1220 | 1292 | return app.Exec(); |
|
0 commit comments