forked from DynamoDS/Dynamo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStartPage.xaml.cs
More file actions
773 lines (646 loc) · 28.2 KB
/
StartPage.xaml.cs
File metadata and controls
773 lines (646 loc) · 28.2 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
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Dynamo.Configuration;
using Dynamo.Logging;
using Dynamo.Utilities;
using Dynamo.ViewModels;
using Dynamo.Wpf.Properties;
using Newtonsoft.Json;
using NotificationObject = Dynamo.Core.NotificationObject;
namespace Dynamo.UI.Controls
{
/// <summary>
/// This class represents the unified data class that is bound to all the
/// list boxes on the StartPageView. The bound data item can be handled in
/// different ways depending on their ClickAction and ContextData properties.
/// See "Action" enumeration below for more details of each item sub-type.
/// </summary>
///
public class StartPageListItem : NotificationObject
{
private ImageSource icon = null;
public enum Action
{
/// <summary>
/// Indicates a regular command should be invoked if the list view
/// item corresponding to this StartPageListItem is clicked. The
/// meaning of ContextData will be interpreted in StartPageViewModel
/// and corresponding action taken as a result.
/// </summary>
RegularCommand,
/// <summary>
/// Indicates that the StartPageListItem carries a file path. When
/// clicked, StartPageViewModel issues a file open command to open
/// the file path indicated by ContextData property.
/// </summary>
FilePath,
/// <summary>
/// Indicates that the StartPageListItem points to an external URL.
/// When the list view item corresponding to this StartPageListItem
/// is clicked, StartPageViewModel brings up the default browser and
/// navigate to the URL indicated by ContextData property.
/// </summary>
ExternalUrl
}
protected internal StartPageListItem(string caption)
{
this.Caption = caption;
}
protected internal StartPageListItem(string caption, string iconPath)
{
this.Caption = caption;
this.icon = LoadBitmapImage(iconPath);
}
#region Public Class Properties
public string Caption { get; private set; }
public string SubScript { get; set; }
public string ToolTip { get; set; }
public string DateModified { get; set; }
public string Description { get; internal set; }
public string Thumbnail { get; set; }
public string Author { get; internal set; }
public string ContextData { get; set; }
public Action ClickAction { get; set; }
public ImageSource Icon
{
get { return this.icon; }
}
// Extended (derived) class properties.
public Visibility IconVisibility
{
get { return ((icon == null) ? Visibility.Collapsed : Visibility.Visible); }
}
#endregion
#region Private Class Helper Methods
protected BitmapImage LoadBitmapImage(string iconPath)
{
var format = @"pack://application:,,,/DynamoCoreWpf;component/UI/Images/StartPage/{0}";
iconPath = string.Format(format, iconPath);
return new BitmapImage(new Uri(iconPath, UriKind.Absolute));
}
#endregion
}
public class StartPageViewModel : ViewModelBase
{
// Static lists that gets created only during creation.
List<StartPageListItem> fileOperations = new List<StartPageListItem>();
List<StartPageListItem> communityLinks = new List<StartPageListItem>();
List<StartPageListItem> references = new List<StartPageListItem>();
List<StartPageListItem> contributeLinks = new List<StartPageListItem>();
string sampleFolderPath = null;
string sampleDatasetsPath = null;
// Dynamic lists that update views on the fly.
ObservableCollection<SampleFileEntry> sampleFiles = null;
ObservableCollection<StartPageListItem> recentFiles = null;
ObservableCollection<StartPageListItem> backupFiles = null;
internal readonly DynamoViewModel DynamoViewModel;
private readonly bool isFirstRun;
internal StartPageViewModel(DynamoViewModel dynamoViewModel, bool isFirstRun)
{
this.DynamoViewModel = dynamoViewModel;
this.isFirstRun = isFirstRun;
this.recentFiles = new ObservableCollection<StartPageListItem>();
this.sampleFiles = new ObservableCollection<SampleFileEntry>();
this.backupFiles = new ObservableCollection<StartPageListItem>();
#region File Operations
fileOperations.Add(new StartPageListItem(Resources.StartPageNewFile, "icon-new.png")
{
ContextData = ButtonNames.NewWorkspace,
ClickAction = StartPageListItem.Action.RegularCommand
});
fileOperations.Add(new StartPageListItem(Resources.StartPageNewCustomNode, "icon-customnode.png")
{
ContextData = ButtonNames.NewCustomNodeWorkspace,
ClickAction = StartPageListItem.Action.RegularCommand
});
fileOperations.Add(new StartPageListItem(Resources.StartPageOpenFile, "icon-open.png")
{
ContextData = ButtonNames.OpenWorkspace,
ClickAction = StartPageListItem.Action.RegularCommand
});
#endregion
#region Community Links
communityLinks.Add(new StartPageListItem(Resources.StartPageDiscussionForum, "icon-discussion.png")
{
ContextData = Configurations.DynamoBimForum,
ClickAction = StartPageListItem.Action.ExternalUrl
});
communityLinks.Add(new StartPageListItem(
string.Format(Resources.StartPageVisitWebsite, dynamoViewModel.BrandingResourceProvider.ProductName),
"icon-dynamobim.png")
{
ContextData = Configurations.DynamoSiteLink,
ClickAction = StartPageListItem.Action.ExternalUrl
});
#endregion
#region Reference List
references.Add(new StartPageListItem(Resources.StartPageDynamoPrimer, "icon-reference.png")
{
ContextData = Configurations.DynamoPrimer,
ClickAction = StartPageListItem.Action.ExternalUrl
});
references.Add(new StartPageListItem(Resources.StartPageVideoTutorials, "icon-video.png")
{
ContextData = Configurations.DynamoVideoTutorials,
ClickAction = StartPageListItem.Action.ExternalUrl
});
references.Add(new StartPageListItem(Resources.StartPageDynamoDictionary, "icon-dictionary.png")
{
ContextData = Configurations.DynamoDictionary,
ClickAction = StartPageListItem.Action.ExternalUrl
});
#endregion
#region Contribution Links
contributeLinks.Add(new StartPageListItem(Resources.StartPageGithubRepository, "icon-github.png")
{
ContextData = Configurations.GitHubDynamoLink,
ClickAction = StartPageListItem.Action.ExternalUrl
});
contributeLinks.Add(new StartPageListItem(Resources.StartPageSendIssues, "icon-issues.png")
{
ContextData = Configurations.GitHubBugReportingLink + "?template=issue.yml",
ClickAction = StartPageListItem.Action.ExternalUrl
});
#endregion
var dvm = this.DynamoViewModel;
RefreshRecentFileList(dvm.RecentFiles, true);
RefreshBackupFileList(dvm.Model.PreferenceSettings.BackupFiles);
dvm.RecentFiles.CollectionChanged += OnRecentFilesChanged;
}
internal void WalkDirectoryTree(System.IO.DirectoryInfo root, SampleFileEntry rootProperty)
{
try
{
// First try to get all the sub-directories before the files themselves.
System.IO.DirectoryInfo[] directories = root.GetDirectories();
if (null != directories && (directories.Length > 0))
{
foreach (System.IO.DirectoryInfo directory in directories)
{
//Make sure the folder's name is not "backup"
if (!directory.Name.Equals(Configurations.BackupFolderName))
{
// Recursive call for each subdirectory.
SampleFileEntry sampleFileEntry =
new SampleFileEntry(directory.Name, directory.FullName);
WalkDirectoryTree(directory, sampleFileEntry);
rootProperty.AddChildSampleFile(sampleFileEntry);
}
}
}
// Secondly, process all the files directly under this folder
System.IO.FileInfo[] dynamoFiles = null;
dynamoFiles = root.GetFiles("*.dyn", System.IO.SearchOption.TopDirectoryOnly);
if (null != dynamoFiles && (dynamoFiles.Length > 0))
{
foreach (System.IO.FileInfo file in dynamoFiles)
{
if (sampleFolderPath == null)
{
sampleFolderPath = Path.GetDirectoryName(file.FullName);
SetSampleDatasetsPath();
}
// Add each file under the root directory property list.
var properties = GetFileProperties(file.FullName);
rootProperty.AddChildSampleFile(new SampleFileEntry(
file.Name,
file.FullName,
properties.thumbnail,
properties.author,
properties.description,
properties.date));
}
}
}
catch (Exception ex)
{
// Perhaps some permission problems?
DynamoViewModel.Model.Logger.Log("Error loading sample file: " + ex.StackTrace);
}
}
/// <summary>
/// Sets the sampleDatasetsPath based on the value of sampleFolderPath
/// </summary>
private void SetSampleDatasetsPath()
{
try
{
var directoryInfo = new DirectoryInfo(sampleFolderPath);
// Traverse the directory tree upwards to locate the "samples" folder
while (directoryInfo != null && directoryInfo.Name != "samples")
{
directoryInfo = directoryInfo.Parent;
}
if (directoryInfo != null && directoryInfo.Name == "samples")
{
var datasetsPath = Path.Combine(directoryInfo.FullName, "Data");
if (Directory.Exists(datasetsPath))
{
sampleDatasetsPath = datasetsPath;
}
else
{
DynamoViewModel.Model.Logger.Log("Error, Dataset folder not found.");
}
}
}
catch (Exception ex)
{
DynamoViewModel.Model.Logger.Log("Error loading Dataset folder: " + ex.Message);
}
}
internal void HandleListItemClicked(StartPageListItem clicked)
{
if (clicked != null)
{
switch (clicked.ClickAction)
{
case StartPageListItem.Action.RegularCommand:
HandleRegularCommand(clicked);
break;
case StartPageListItem.Action.FilePath:
HandleFilePath(clicked);
break;
case StartPageListItem.Action.ExternalUrl:
HandleExternalUrl(clicked);
break;
}
}
}
public bool IsFirstRun { get { return isFirstRun; } }
public string SampleFolderPath
{
get { return this.sampleFolderPath; }
}
public string SampleDatasetsPath
{
get { return this.sampleDatasetsPath; }
}
#region Public Class Properties (Static Lists)
public IEnumerable<StartPageListItem> FileOperations
{
get { return this.fileOperations; }
}
public IEnumerable<StartPageListItem> CommunityLinks
{
get { return this.communityLinks; }
}
public IEnumerable<StartPageListItem> References
{
get { return this.references; }
}
public IEnumerable<StartPageListItem> ContributeLinks
{
get { return this.contributeLinks; }
}
#endregion
#region Public Class Properties (Dynamic Lists)
public ObservableCollection<StartPageListItem> RecentFiles
{
get { return this.recentFiles; }
}
public ObservableCollection<StartPageListItem> BackupFiles
{
get { return this.backupFiles; }
}
#endregion
public ObservableCollection<SampleFileEntry> SampleFiles
{
get { return this.sampleFiles; }
}
public string BackupTitle
{
get
{
if (StabilityUtils.IsLastShutdownClean
|| DynamoViewModel.Model.PreferenceSettings.BackupFiles.Count == 0)
{
return Dynamo.Wpf.Properties.Resources.StartPageBackupNoCrash;
}
else
{
return Dynamo.Wpf.Properties.Resources.StartPageBackupOnCrash;
}
}
}
#region Private Class Event Handlers
private void OnRecentFilesChanged(object sender, NotifyCollectionChangedEventArgs e)
{
//when we are just moving existing files, no need to refresh the complete list
if (e.Action == NotifyCollectionChangedAction.Move)
{
recentFiles.Move(e.OldStartingIndex, e.NewStartingIndex);
}
else if (e.Action == NotifyCollectionChangedAction.Add)
{
var newItems = e.NewItems?.Cast<string>();
if (newItems != null)
{
RefreshRecentFileList(newItems);
}
}
else if (e.Action == NotifyCollectionChangedAction.Remove)
{
recentFiles.RemoveRange(e.OldStartingIndex, recentFiles.Count - e.OldStartingIndex);
}
else
{
RefreshRecentFileList(sender as IEnumerable<string>, true);
}
}
#endregion
#region Private Class Helper Methods
private void RefreshRecentFileList(IEnumerable<string> filePaths, bool fullRefresh = false)
{
RefreshFileList(recentFiles, filePaths, fullRefresh);
}
private void RefreshBackupFileList(IEnumerable<string> filePaths)
{
RefreshFileList(backupFiles, filePaths, true);
}
/// <summary>
/// Refreshes the list of files in the specified collection. If fullRefresh is true,
/// discards the current list and regenerates all file items based on the provided file paths.
/// </summary>
/// <param name="files">Files currently in the recent files list</param>
/// <param name="filePaths">New files path which will be used to update the current list</param>
/// <param name="fullRefresh">If true, will discard the current list and regenerate all file items based on the provided file paths</param>
private void RefreshFileList(ObservableCollection<StartPageListItem> files,
IEnumerable<string> filePaths, bool fullRefresh = false)
{
if (fullRefresh)
{
files.Clear();
}
foreach (var filePath in filePaths.Where(x => x != null))
{
try
{
// Skip files which were moved or deleted (consistent with Revit behavior)
if (!DynamoUtilities.PathHelper.IsValidPath(filePath)) continue;
var extension = Path.GetExtension(filePath).ToUpper();
// If not extension specified and code reach here, this means this is still a valid file
// only without file type. Otherwise, simply take extension substring skipping the 'dot'.
var subScript = extension.StartsWith(".") ? extension.Substring(1) : "";
var caption = Path.GetFileNameWithoutExtension(filePath);
// deserializes the file only once
var properties = GetFileProperties(filePath);
var startItem = new StartPageListItem(caption)
{
ContextData = filePath,
ToolTip = filePath,
SubScript = subScript,
Description = properties.description,
Thumbnail = properties.thumbnail,
Author = properties.author,
DateModified = properties.date,
ClickAction = StartPageListItem.Action.FilePath,
};
if (fullRefresh)
{
files.Add(startItem);
}
else
{
files.Insert(0, startItem);
}
}
catch (ArgumentException ex)
{
DynamoViewModel.Model.Logger.Log("File path is not valid: " + ex.StackTrace);
}
catch (Exception ex)
{
DynamoViewModel.Model.Logger.Log("Error loading the file: " + ex.StackTrace);
}
}
}
private Dictionary<string, object> DeserializeJsonFile(string filePath)
{
if (DynamoUtilities.PathHelper.isValidJson(filePath, out string jsonString, out Exception ex))
{
return JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonString);
}
else
{
if(ex is JsonReaderException)
{
DynamoViewModel.Model.Logger.Log("File is not a valid json format.");
}
else
{
DynamoViewModel.Model.Logger.Log("File is not valid: " + ex.StackTrace);
}
return null;
}
}
private const string BASE64PREFIX = "data:image/png;base64,";
private string GetGraphThumbnail(Dictionary<string, object> jsonObject)
{
jsonObject.TryGetValue("Thumbnail", out object thumbnail);
if (string.IsNullOrEmpty(thumbnail as string)) return string.Empty;
var base64 = String.Format("{0}{1}", BASE64PREFIX, thumbnail as string);
return base64;
}
private string GetGraphDescription(Dictionary<string, object> jsonObject)
{
jsonObject.TryGetValue("Description", out object description);
return description as string;
}
private string GetGraphAuthor(Dictionary<string, object> jsonObject)
{
jsonObject.TryGetValue("Author", out object author);
return author as string;
}
private void HandleRegularCommand(StartPageListItem item)
{
var dvm = this.DynamoViewModel;
switch (item.ContextData)
{
case ButtonNames.NewWorkspace:
dvm.NewHomeWorkspaceCommand.Execute(null);
break;
case ButtonNames.OpenWorkspace:
dvm.ShowOpenDialogAndOpenResultCommand.Execute(null);
break;
case ButtonNames.NewCustomNodeWorkspace:
dvm.ShowNewFunctionDialogCommand.Execute(null);
break;
default:
throw new ArgumentException(
string.Format("Invalid command: {0}", item.ContextData));
}
}
private void HandleFilePath(StartPageListItem item)
{
var path = item.ContextData;
this.DynamoViewModel.OpenCommand.Execute(path);
}
private void HandleExternalUrl(StartPageListItem item)
{
System.Diagnostics.Process.Start(new ProcessStartInfo(item.ContextData) { UseShellExecute = true });
}
/// <summary>
/// Attempts to deserialize a dynamo graph file and extract metadata from it
/// </summary>
/// <param name="filePath">The file path to the dynamo file</param>
/// <returns></returns>
internal (string description, string thumbnail, string author, string date) GetFileProperties(string filePath)
{
if (!filePath.ToLower().EndsWith(".dyn") && !filePath.ToLower().EndsWith(".dyf")) return (null, null, null, null);
try
{
var jsonObject = DeserializeJsonFile(filePath);
var description = jsonObject != null ? GetGraphDescription(jsonObject) : string.Empty;
var thumbnail = jsonObject != null ? GetGraphThumbnail(jsonObject) : string.Empty;
var author = jsonObject != null ? GetGraphAuthor(jsonObject) : Resources.DynamoXmlFileFormat;
var date = DynamoUtilities.PathHelper.GetDateModified(filePath);
return (description, thumbnail, author, date);
}
catch (Exception ex)
{
DynamoViewModel.Model.Logger.Log("Error deserializing dynamo graph file: " + ex.StackTrace);
return (null, null, null, null);
}
}
#endregion
}
struct ButtonNames
{
public const string NewWorkspace = "NewWorkspace";
public const string NewCustomNodeWorkspace = "NewCustomNodeWorkspace";
public const string OpenWorkspace = "OpenWorkspace";
}
public partial class StartPageView : UserControl
{
private DynamoViewModel dynamoViewModel;
/// <summary>
/// Constructor
/// </summary>
public StartPageView()
{
InitializeComponent();
if (StabilityUtils.IsLastShutdownClean)
{
backupFilesList.Visibility = Visibility.Collapsed;
}
this.Loaded += OnStartPageLoaded;
}
#region Private Class Event Handlers
private void OnStartPageLoaded(object sender, RoutedEventArgs e)
{
var startPageViewModel = this.DataContext as StartPageViewModel;
this.dynamoViewModel = startPageViewModel.DynamoViewModel;
this.filesListBox.ItemsSource = startPageViewModel.FileOperations;
this.askListBox.ItemsSource = startPageViewModel.CommunityLinks;
this.referenceListBox.ItemsSource = startPageViewModel.References;
this.codeListBox.ItemsSource = startPageViewModel.ContributeLinks;
this.recentListBox.ItemsSource = startPageViewModel.RecentFiles;
this.sampleFileTreeView.ItemsSource = startPageViewModel.SampleFiles;
this.backupFilesList.ItemsSource = startPageViewModel.BackupFiles;
var id = Wpf.Interfaces.ResourceNames.StartPage.Image;
StartPageLogo.Source = dynamoViewModel.BrandingResourceProvider.GetImageSource(id);
}
private void OnItemSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e == null || (e.AddedItems == null) || (e.AddedItems.Count <= 0))
return;
var selected = e.AddedItems[0] as StartPageListItem;
var startPageViewModel = this.DataContext as StartPageViewModel;
startPageViewModel.HandleListItemClicked(selected);
// Clear list box selection so that the same item, when
// clicked, still triggers "selection changed" notification.
var listBox = sender as ListBox;
listBox.SelectedIndex = -1;
}
private void OnSampleFileSelected(object sender, RoutedEventArgs e)
{
var dp = e.OriginalSource as DependencyObject;
var treeViewItem = WpfUtilities.FindUpVisualTree<TreeViewItem>(dp) as TreeViewItem;
if (sampleFileTreeView.SelectedItem != null)
treeViewItem.IsExpanded = !treeViewItem.IsExpanded;
var filePath = (sampleFileTreeView.SelectedItem as SampleFileEntry).FilePath;
if (string.IsNullOrEmpty(filePath))
return;
if (!Path.GetExtension(filePath).Equals(".dyn"))
return;
var dvm = this.dynamoViewModel;
if (dvm.OpenCommand.CanExecute(filePath))
dvm.OpenCommand.Execute(filePath);
}
private void ShowSamplesInFolder(object sender, MouseButtonEventArgs e)
{
var startPageViewModel = this.DataContext as StartPageViewModel;
Process.Start(new ProcessStartInfo("explorer.exe", "/select,"
+ startPageViewModel.SampleFolderPath)
{ UseShellExecute = true });
}
private void ShowBackupFilesInFolder(object sender, MouseButtonEventArgs e)
{
var startPageViewModel = this.DataContext as StartPageViewModel;
Process.Start(new ProcessStartInfo("explorer.exe", dynamoViewModel.Model.PathManager.BackupDirectory) { UseShellExecute = true });
}
private void StartPage_OnDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
// Note that you can have more than one file.
var homespace = dynamoViewModel.HomeSpace;
if (homespace.HasUnsavedChanges &&
!dynamoViewModel.AskUserToSaveWorkspaceOrCancel(homespace))
{
return;
}
var files = e.Data.GetData(DataFormats.FileDrop) as string[];
if (files != null && (files.Length > 0))
{
if (dynamoViewModel.OpenCommand.CanExecute(files[0]))
{
dynamoViewModel.OpenCommand.Execute(files[0]);
e.Handled = true;
}
}
}
}
#endregion
}
public class SampleFileEntry : StartPageListItem
{
List<SampleFileEntry> childSampleFiles = null;
public SampleFileEntry(string name, string path)
: base(name)
{
this.FileName = name;
this.FilePath = path;
}
public SampleFileEntry(string name, string path, string thumbnail, string author, string description, string dateModified)
: base(name)
{
this.FileName = name;
this.FilePath = path;
this.Thumbnail = thumbnail;
this.Author = author;
this.Description = description;
this.DateModified = dateModified;
}
public void AddChildSampleFile(SampleFileEntry childSampleFile)
{
if (null == childSampleFiles)
childSampleFiles = new List<SampleFileEntry>();
childSampleFiles.Add(childSampleFile);
}
public string FileName { get; private set; }
public string FilePath { get; private set; }
public IEnumerable<SampleFileEntry> Children { get { return childSampleFiles; } }
}
}