Skip to content

Commit

Permalink
customnode preview item added
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
dnenov committed Oct 18, 2023
1 parent 0f281ab commit e2cd0aa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Dynamo.PackageManager.UI
{
public enum DependencyType
{
CustomNode, Assembly, File, Folder
CustomNode, Assembly, File, Folder, CustomNodePreview
}

public class PackageItemRootViewModel : PackageItemViewModel
Expand All @@ -32,8 +32,8 @@ public class PackageItemRootViewModel : PackageItemViewModel
/// </summary>
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)
Expand Down Expand Up @@ -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<PackageItemRootViewModel> items)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,8 @@ public List<CustomNodeDefinition> CustomNodeDefinitions
}
}

private Dictionary<string, string> CustomDyfFilepaths { get; set; } = new Dictionary<string, string>();

public List<PackageAssembly> Assemblies { get; set; }

/// <summary>
Expand Down Expand Up @@ -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();

Expand All @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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");
}
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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))
{
Expand Down

0 comments on commit e2cd0aa

Please sign in to comment.