From e2cd0aa60e0f5a9d50cdebcbc42a088402b9c1b7 Mon Sep 17 00:00:00 2001 From: Deyan Nenov Date: Wed, 18 Oct 2023 18:51:30 +0100 Subject: [PATCH] customnode preview item added - we need the ability to display custom nodes as file with file paths during package creation. CustomDefinition does not have the attributes to address that, so we are adding a new 'preview' item type to server the purpose --- .../PackageManager/PackageItemRootViewModel.cs | 16 ++++++++++++---- .../PackageManager/PublishPackageViewModel.cs | 18 ++++++++++-------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/DynamoCoreWpf/ViewModels/PackageManager/PackageItemRootViewModel.cs b/src/DynamoCoreWpf/ViewModels/PackageManager/PackageItemRootViewModel.cs index 00c984784a7..999c89f1e2c 100644 --- a/src/DynamoCoreWpf/ViewModels/PackageManager/PackageItemRootViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/PackageManager/PackageItemRootViewModel.cs @@ -9,7 +9,7 @@ namespace Dynamo.PackageManager.UI { public enum DependencyType { - CustomNode, Assembly, File, Folder + CustomNode, Assembly, File, Folder, CustomNodePreview } public class PackageItemRootViewModel : PackageItemViewModel @@ -32,8 +32,8 @@ public class PackageItemRootViewModel : PackageItemViewModel /// public string FilePath { get; } public string DirectoryName { get; private set; } - public bool IsAssemblyContainer { get; private set; } public string PathName { get; private set; } + internal bool isChild; public PackageItemRootViewModel(CustomNodeDefinition def) @@ -71,12 +71,20 @@ public PackageItemRootViewModel(System.IO.FileInfo fileInfo) this.isChild = true; } - public PackageItemRootViewModel(string folderName, bool assemblyContainer = false) + public PackageItemRootViewModel(string folderName) { this.DependencyType = DependencyType.Folder; this.DisplayName = Path.GetFileName(folderName); this.DirectoryName = folderName; - this.IsAssemblyContainer = assemblyContainer; + } + + public PackageItemRootViewModel(string fileName, string filePath) + { + this.DependencyType = DependencyType.CustomNodePreview; + this.DisplayName = fileName; + this.FilePath = filePath; + this.DirectoryName = Path.GetDirectoryName(filePath); + this.isChild = true; } internal void AddChildren(List items) diff --git a/src/DynamoCoreWpf/ViewModels/PackageManager/PublishPackageViewModel.cs b/src/DynamoCoreWpf/ViewModels/PackageManager/PublishPackageViewModel.cs index 6bff6e0da81..48530b47807 100644 --- a/src/DynamoCoreWpf/ViewModels/PackageManager/PublishPackageViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/PackageManager/PublishPackageViewModel.cs @@ -659,6 +659,8 @@ public List CustomNodeDefinitions } } + private Dictionary CustomDyfFilepaths { get; set; } = new Dictionary(); + public List Assemblies { get; set; } /// @@ -824,6 +826,7 @@ private void RefreshPackageContents() .Select(def => new PackageItemRootViewModel(def)) .Concat(Assemblies.Select((pa) => new PackageItemRootViewModel(pa))) .Concat(AdditionalFiles.Select((s) => new PackageItemRootViewModel(new FileInfo(s)))) + .Concat(CustomDyfFilepaths.Select((s) => new PackageItemRootViewModel((string)s.Key, (string)s.Value))) .ToList() .ToObservableCollection(); @@ -840,11 +843,10 @@ private void RefreshPackageContents() { if (!items.ContainsKey(item.DirectoryName)) { - // Custom nodes don't have folders? + // Custom nodes don't have folders, we have introduced CustomNodePreview item instead if (item.DependencyType.Equals(DependencyType.CustomNode)) continue; if (items.Values.Any(x => IsDuplicateFile(x, item))) continue; - var assemblyContainer = item.DependencyType.Equals(DependencyType.Assembly); - var root = new PackageItemRootViewModel(item.DirectoryName, assemblyContainer); + var root = new PackageItemRootViewModel(item.DirectoryName); root.ChildItems.Add(item); items[item.DirectoryName] = root; @@ -873,6 +875,7 @@ private bool IsDuplicateFile(PackageItemRootViewModel item1, PackageItemRootView return item1.ChildItems.Any(x => IsDuplicateFile(x, item2)); case DependencyType.File: case DependencyType.Assembly: + case DependencyType.CustomNodePreview: return item1.FilePath.Equals(item2.FilePath); case DependencyType.CustomNode: default: @@ -1626,6 +1629,7 @@ private void AddCustomNodeFile(string filename) && CustomNodeDefinitions.All(x => x.FunctionId != funcDef.FunctionId)) { CustomNodeDefinitions.Add(funcDef); + CustomDyfFilepaths.TryAdd(Path.GetFileName(filename), filename); RaisePropertyChanged("PackageContents"); } } @@ -2076,7 +2080,7 @@ private void PreviewPackageBuild() if (PackageContents?.Count == 0) return; - var publishPath = !String.IsNullOrEmpty(rootFolder) ? rootFolder : PackageContents.First(x => !x.IsAssemblyContainer).DirectoryName; + var publishPath = !String.IsNullOrEmpty(rootFolder) ? rootFolder : new FileInfo("Publish Path").FullName; if (string.IsNullOrEmpty(publishPath)) return; @@ -2175,10 +2179,8 @@ internal PackageItemRootViewModel GetPreBuildRootItemViewModel(string publishPat } else if (file.EndsWith(".dyf")) { - // Get the custom definition from the CustomNodeDefinition collection - var customNodeDefinition = CustomNodeDefinitions.FirstOrDefault(x => x.DisplayName.Equals(Path.GetFileNameWithoutExtension(fileName))); - if (customNodeDefinition == null) continue; - var dyf = new PackageItemRootViewModel(customNodeDefinition); + var dyfPreview = new PackageItemRootViewModel(fileName, Path.Combine(dyfDir, fileName)); + dyfItemPreview.AddChild(dyfPreview); } else if (file.EndsWith(".dll") || PackageDirectoryBuilder.IsXmlDocFile(file, files) || PackageDirectoryBuilder.IsDynamoCustomizationFile(file, files)) {