diff --git a/src/DynamoCoreWpf/Controls/StartPage.xaml.cs b/src/DynamoCoreWpf/Controls/StartPage.xaml.cs index b539922593b..ca92535604d 100644 --- a/src/DynamoCoreWpf/Controls/StartPage.xaml.cs +++ b/src/DynamoCoreWpf/Controls/StartPage.xaml.cs @@ -113,6 +113,7 @@ public class StartPageViewModel : ViewModelBase List references = new List(); List contributeLinks = new List(); string sampleFolderPath = null; + string sampleDatasetsPath = null; // Dynamic lists that update views on the fly. ObservableCollection sampleFiles = null; @@ -228,7 +229,7 @@ internal void WalkDirectoryTree(System.IO.DirectoryInfo root, SampleFileEntry ro //Make sure the folder's name is not "backup" if (!directory.Name.Equals(Configurations.BackupFolderName)) { - // Resursive call for each subdirectory. + // Recursive call for each subdirectory. SampleFileEntry sampleFileEntry = new SampleFileEntry(directory.Name, directory.FullName); WalkDirectoryTree(directory, sampleFileEntry); @@ -248,6 +249,7 @@ internal void WalkDirectoryTree(System.IO.DirectoryInfo root, SampleFileEntry ro if (sampleFolderPath == null) { sampleFolderPath = Path.GetDirectoryName(file.FullName); + SetSampleDatasetsPath(); } // Add each file under the root directory property list. @@ -270,6 +272,37 @@ internal void WalkDirectoryTree(System.IO.DirectoryInfo root, SampleFileEntry ro } } + /// + /// Sets the sampleDatasetsPath based on the value of sampleFolderPath + /// + 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; + } + } + } + catch (Exception ex) + { + DynamoViewModel.Model.Logger.Log("Error loading Dataset folder: " + ex.Message); + } + } + internal void HandleListItemClicked(StartPageListItem clicked) { if (clicked != null) @@ -298,6 +331,11 @@ public string SampleFolderPath get { return this.sampleFolderPath; } } + public string SampleDatasetsPath + { + get { return this.sampleDatasetsPath; } + } + #region Public Class Properties (Static Lists) public IEnumerable FileOperations @@ -529,7 +567,6 @@ private void HandleExternalUrl(StartPageListItem item) DynamoViewModel.Model.Logger.Log("Error deserializing dynamo graph file: " + ex.StackTrace); return (null, null, null, null); } - } #endregion diff --git a/src/DynamoCoreWpf/DynamoCoreWpf.csproj b/src/DynamoCoreWpf/DynamoCoreWpf.csproj index 598494a5acf..b2f3f177db0 100644 --- a/src/DynamoCoreWpf/DynamoCoreWpf.csproj +++ b/src/DynamoCoreWpf/DynamoCoreWpf.csproj @@ -59,7 +59,7 @@ - 1.0.17 + 1.0.18 DynamoHome diff --git a/src/DynamoCoreWpf/PublicAPI.Unshipped.txt b/src/DynamoCoreWpf/PublicAPI.Unshipped.txt index 2cb587f4f03..04b01bff6ef 100644 --- a/src/DynamoCoreWpf/PublicAPI.Unshipped.txt +++ b/src/DynamoCoreWpf/PublicAPI.Unshipped.txt @@ -1494,6 +1494,7 @@ Dynamo.UI.Controls.StartPageViewModel.RecentFiles.get -> System.Collections.Obje Dynamo.UI.Controls.StartPageViewModel.References.get -> System.Collections.Generic.IEnumerable Dynamo.UI.Controls.StartPageViewModel.SampleFiles.get -> System.Collections.ObjectModel.ObservableCollection Dynamo.UI.Controls.StartPageViewModel.SampleFolderPath.get -> string +Dynamo.UI.Controls.StartPageViewModel.SampleDatasetsPath.get -> string Dynamo.UI.Controls.StateChangedEventHandler Dynamo.UI.Controls.ToolTipWindow Dynamo.UI.Controls.ToolTipWindow.CopyIconMouseClick(object sender, System.Windows.Input.MouseButtonEventArgs e) -> void @@ -1592,9 +1593,10 @@ Dynamo.UI.Views.ScriptHomeObject.NewWorkspace() -> void Dynamo.UI.Views.ScriptHomeObject.OpenFile(string path) -> void Dynamo.UI.Views.ScriptHomeObject.OpenWorkspace() -> void Dynamo.UI.Views.ScriptHomeObject.SaveSettings(string settings) -> void -Dynamo.UI.Views.ScriptHomeObject.ScriptHomeObject(System.Action requestOpenFile, System.Action requestNewWorkspace, System.Action requestOpenWorkspace, System.Action requestNewCustomNodeWorkspace, System.Action requestApplicationLoaded, System.Action requestShowGuidedTour, System.Action requestShowSampleFilesInFolder, System.Action requestShowBackupFilesInFolder, System.Action requestShowTemplate, System.Action requestSaveSettings) -> void +Dynamo.UI.Views.ScriptHomeObject.ScriptHomeObject(System.Action requestOpenFile, System.Action requestNewWorkspace, System.Action requestOpenWorkspace, System.Action requestNewCustomNodeWorkspace, System.Action requestApplicationLoaded, System.Action requestShowGuidedTour, System.Action requestShowSampleFilesInFolder, System.Action requestShowSampleDatasetsInFolder, System.Action requestShowBackupFilesInFolder, System.Action requestShowTemplate, System.Action requestSaveSettings) -> void Dynamo.UI.Views.ScriptHomeObject.ShowBackupFilesInFolder() -> void Dynamo.UI.Views.ScriptHomeObject.ShowSampleFilesInFolder() -> void +Dynamo.UI.Views.ScriptHomeObject.ShowSampleDatasetsInFolder() -> void Dynamo.UI.Views.ScriptHomeObject.ShowTempalte() -> void Dynamo.UI.Views.ScriptHomeObject.StartGuidedTour(string path) -> void Dynamo.UI.Views.ScriptObject diff --git a/src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs b/src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs index 26692f390e7..b18a6a0c09b 100644 --- a/src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs +++ b/src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs @@ -2067,7 +2067,7 @@ private void RemoveHomePage() // the key press event is being intercepted before it can get to // the active workspace. This code simply grabs the key presses and - // passes it to thecurrent workspace + // passes it to the current workspace private void DynamoView_KeyDown(object sender, KeyEventArgs e) { Analytics.TrackActivityStatus(HeartBeatType.User.ToString()); @@ -2187,6 +2187,7 @@ private void DeleteState_Click(object sender, RoutedEventArgs e) private void LoadSamplesMenu() { var samplesDirectory = dynamoViewModel.Model.PathManager.SamplesDirectory; + if (Directory.Exists(samplesDirectory)) { var sampleFiles = new System.Collections.Generic.List(); @@ -2209,7 +2210,7 @@ private void LoadSamplesMenu() } } - // handle top-level dirs, TODO - factor out to a seperate function, make recusive + // handle top-level dirs, TODO - factor out to a separate function, make recursive if (dirPaths.Any()) { foreach (string dirPath in dirPaths) diff --git a/src/DynamoCoreWpf/Views/HomePage/HomePage.xaml.cs b/src/DynamoCoreWpf/Views/HomePage/HomePage.xaml.cs index cc57b5cadac..906f6c5761f 100644 --- a/src/DynamoCoreWpf/Views/HomePage/HomePage.xaml.cs +++ b/src/DynamoCoreWpf/Views/HomePage/HomePage.xaml.cs @@ -54,6 +54,7 @@ public partial class HomePage : UserControl, IDisposable internal Action RequestNewCustomNodeWorkspace; internal Action RequestApplicationLoaded; internal Action RequestShowSampleFilesInFolder; + internal Action RequestShowSampleDatasetsInFolder; internal Action RequestShowBackupFilesInFolder; internal Action RequestShowTemplate; internal Action RequestSaveSettings; @@ -87,13 +88,13 @@ public HomePage() RequestOpenWorkspace = OpenWorkspace; RequestNewCustomNodeWorkspace = NewCustomNodeWorkspace; RequestShowSampleFilesInFolder = ShowSampleFilesInFolder; + RequestShowSampleDatasetsInFolder = ShowSampleDatasetsInFolder; RequestShowBackupFilesInFolder = ShowBackupFilesInFolder; RequestShowTemplate = OpenTemplate; RequestApplicationLoaded = ApplicationLoaded; RequestSaveSettings = SaveSettings; DataContextChanged += OnDataContextChanged; - } private void InitializeGuideTourItems() @@ -169,7 +170,7 @@ private async void UserControl_Loaded(object sender, System.Windows.RoutedEventA this.dynWebView.CoreWebView2.Settings.AreDevToolsEnabled = true; this.dynWebView.CoreWebView2.NewWindowRequested += CoreWebView2_NewWindowRequested; - // Load the embeded resources + // Load the embedded resources var assembly = Assembly.GetExecutingAssembly(); htmlString = PathHelper.LoadEmbeddedResourceAsString(htmlEmbeddedFile, assembly); @@ -202,6 +203,7 @@ private async void UserControl_Loaded(object sender, System.Windows.RoutedEventA RequestApplicationLoaded, RequestShowGuidedTour, RequestShowSampleFilesInFolder, + RequestShowSampleDatasetsInFolder, RequestShowBackupFilesInFolder, RequestShowTemplate, RequestSaveSettings)); @@ -617,7 +619,21 @@ internal void ShowSampleFilesInFolder() + this.startPage.SampleFolderPath) { UseShellExecute = true }); Logging.Analytics.TrackEvent(Logging.Actions.Show, Logging.Categories.DynamoHomeOperations, "Sample Files"); + } + + internal void ShowSampleDatasetsInFolder() + { + if (this.startPage == null) return; + if (DynamoModel.IsTestMode) + { + TestHook?.Invoke(string.Empty); + return; + } + Process.Start(new ProcessStartInfo("explorer.exe", /*"/select,"*/ + /*+ */this.startPage.SampleDatasetsPath) + { UseShellExecute = true }); + Logging.Analytics.TrackEvent(Logging.Actions.Show, Logging.Categories.DynamoHomeOperations, "Dataset Files"); } internal void ShowBackupFilesInFolder() @@ -728,6 +744,7 @@ public class ScriptHomeObject readonly Action RequestApplicationLoaded; readonly Action RequestShowGuidedTour; readonly Action RequestShowSampleFilesInFolder; + readonly Action RequestShowSampleDatasetsInFolder; readonly Action RequestShowBackupFilesInFolder; readonly Action RequestShowTemplate; readonly Action RequestSaveSettings; @@ -739,6 +756,7 @@ public ScriptHomeObject(Action requestOpenFile, Action requestApplicationLoaded, Action requestShowGuidedTour, Action requestShowSampleFilesInFolder, + Action requestShowSampleDatasetsInFolder, Action requestShowBackupFilesInFolder, Action requestShowTemplate, Action requestSaveSettings) @@ -750,6 +768,7 @@ public ScriptHomeObject(Action requestOpenFile, RequestApplicationLoaded = requestApplicationLoaded; RequestShowGuidedTour = requestShowGuidedTour; RequestShowSampleFilesInFolder = requestShowSampleFilesInFolder; + RequestShowSampleDatasetsInFolder = requestShowSampleDatasetsInFolder; RequestShowBackupFilesInFolder = requestShowBackupFilesInFolder; RequestShowTemplate = requestShowTemplate; RequestSaveSettings = requestSaveSettings; @@ -785,11 +804,15 @@ public void ShowSampleFilesInFolder() RequestShowSampleFilesInFolder(); } [DynamoJSInvokable] + public void ShowSampleDatasetsInFolder() + { + RequestShowSampleDatasetsInFolder(); + } + [DynamoJSInvokable] public void ShowBackupFilesInFolder() { RequestShowBackupFilesInFolder(); } - [DynamoJSInvokable] public void ShowTempalte() { diff --git a/test/DynamoCoreWpfTests/HomePageTests.cs b/test/DynamoCoreWpfTests/HomePageTests.cs index e9f36cf1409..5d396e05ac1 100644 --- a/test/DynamoCoreWpfTests/HomePageTests.cs +++ b/test/DynamoCoreWpfTests/HomePageTests.cs @@ -50,6 +50,7 @@ public void ActionDelegates_ShouldBeProperlySetAfterConstruction() Assert.IsNotNull(homePage.RequestNewCustomNodeWorkspace); Assert.IsNotNull(homePage.RequestApplicationLoaded); Assert.IsNotNull(homePage.RequestShowSampleFilesInFolder); + Assert.IsNotNull(homePage.RequestShowSampleDatasetsInFolder); Assert.IsNotNull(homePage.RequestShowBackupFilesInFolder); Assert.IsNotNull(homePage.RequestShowTemplate); }