Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DYN-7330 Add a button to show Sample Graph folder and Sample Dataset #15449

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions src/DynamoCoreWpf/Controls/StartPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public class StartPageViewModel : ViewModelBase
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;
Expand Down Expand Up @@ -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);
Expand All @@ -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.
Expand All @@ -270,6 +272,37 @@ internal void WalkDirectoryTree(System.IO.DirectoryInfo root, SampleFileEntry ro
}
}

/// <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;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, we open a default page when dataset folder does not exist, or nothing happens?

Copy link
Contributor Author

@ivaylo-matov ivaylo-matov Aug 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will falling back on root or desktop be sufficient? Any other suggestions?

}
}
catch (Exception ex)
{
DynamoViewModel.Model.Logger.Log("Error loading Dataset folder: " + ex.Message);
}
}

internal void HandleListItemClicked(StartPageListItem clicked)
{
if (clicked != null)
Expand Down Expand Up @@ -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<StartPageListItem> FileOperations
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/DynamoCoreWpf/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.StartPageListItem>
Dynamo.UI.Controls.StartPageViewModel.SampleFiles.get -> System.Collections.ObjectModel.ObservableCollection<Dynamo.UI.Controls.SampleFileEntry>
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
Expand Down Expand Up @@ -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<string> requestOpenFile, System.Action requestNewWorkspace, System.Action requestOpenWorkspace, System.Action requestNewCustomNodeWorkspace, System.Action requestApplicationLoaded, System.Action<string> requestShowGuidedTour, System.Action requestShowSampleFilesInFolder, System.Action requestShowBackupFilesInFolder, System.Action requestShowTemplate, System.Action<string> requestSaveSettings) -> void
Dynamo.UI.Views.ScriptHomeObject.ScriptHomeObject(System.Action<string> requestOpenFile, System.Action requestNewWorkspace, System.Action requestOpenWorkspace, System.Action requestNewCustomNodeWorkspace, System.Action requestApplicationLoaded, System.Action<string> requestShowGuidedTour, System.Action requestShowSampleFilesInFolder, System.Action requestShowSampleDatasetsInFolder, System.Action requestShowBackupFilesInFolder, System.Action requestShowTemplate, System.Action<string> 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
Expand Down
5 changes: 3 additions & 2 deletions src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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<string>();
Expand All @@ -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)
Expand Down
29 changes: 26 additions & 3 deletions src/DynamoCoreWpf/Views/HomePage/HomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> RequestSaveSettings;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -202,6 +203,7 @@ private async void UserControl_Loaded(object sender, System.Windows.RoutedEventA
RequestApplicationLoaded,
RequestShowGuidedTour,
RequestShowSampleFilesInFolder,
RequestShowSampleDatasetsInFolder,
RequestShowBackupFilesInFolder,
RequestShowTemplate,
RequestSaveSettings));
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -728,6 +744,7 @@ public class ScriptHomeObject
readonly Action RequestApplicationLoaded;
readonly Action<string> RequestShowGuidedTour;
readonly Action RequestShowSampleFilesInFolder;
readonly Action RequestShowSampleDatasetsInFolder;
readonly Action RequestShowBackupFilesInFolder;
readonly Action RequestShowTemplate;
readonly Action<string> RequestSaveSettings;
Expand All @@ -739,6 +756,7 @@ public ScriptHomeObject(Action<string> requestOpenFile,
Action requestApplicationLoaded,
Action<string> requestShowGuidedTour,
Action requestShowSampleFilesInFolder,
Action requestShowSampleDatasetsInFolder,
Action requestShowBackupFilesInFolder,
Action requestShowTemplate,
Action<string> requestSaveSettings)
Expand All @@ -750,6 +768,7 @@ public ScriptHomeObject(Action<string> requestOpenFile,
RequestApplicationLoaded = requestApplicationLoaded;
RequestShowGuidedTour = requestShowGuidedTour;
RequestShowSampleFilesInFolder = requestShowSampleFilesInFolder;
RequestShowSampleDatasetsInFolder = requestShowSampleDatasetsInFolder;
RequestShowBackupFilesInFolder = requestShowBackupFilesInFolder;
RequestShowTemplate = requestShowTemplate;
RequestSaveSettings = requestSaveSettings;
Expand Down Expand Up @@ -785,11 +804,15 @@ public void ShowSampleFilesInFolder()
RequestShowSampleFilesInFolder();
}
[DynamoJSInvokable]
public void ShowSampleDatasetsInFolder()
{
RequestShowSampleDatasetsInFolder();
}
[DynamoJSInvokable]
public void ShowBackupFilesInFolder()
{
RequestShowBackupFilesInFolder();
}

[DynamoJSInvokable]
public void ShowTempalte()
{
Expand Down
1 change: 1 addition & 0 deletions test/DynamoCoreWpfTests/HomePageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading