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

Pm - files and folders counter - UI improvements #15359

Merged
Merged
Show file tree
Hide file tree
Changes from 15 commits
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
28 changes: 23 additions & 5 deletions src/DynamoCore/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/DynamoCore/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,12 @@ Parameter name: {0}</value>
<value>The current user, '{0}', is not a maintainer of the package '{1}'.</value>
<comment>{0} = user name (i.e. 'DynamoTeam'), {1} = package name (i.e. 'Clockwork for Dynamo 1.x')</comment>
</data>
<data name="PackageManagerPackagePreviewCounter" xml:space="preserve">
<value>{0} files and {1} folders will be created.</value>
</data>
<data name="PackageManagerPackageSelectCounter" xml:space="preserve">
<value>{0} files and {1} folders loaded.</value>
</data>
<data name="DuplicatedOlderPackage" xml:space="preserve">
<value>An older version of the package called {0} version {2} was found at {1} with version {3}. The older version has been ignored.</value>
</data>
Expand Down Expand Up @@ -914,4 +920,4 @@ This package likely contains an assembly that is blocked. You will need to load
<data name="InputNodeRenameHint" xml:space="preserve">
<value>default input name, rename me!</value>
</data>
</root>
</root>
8 changes: 7 additions & 1 deletion src/DynamoCore/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,12 @@ Parameter name: {0}</value>
<value>The current user, '{0}', is not a maintainer of the package '{1}'.</value>
<comment>{0} = user name (i.e. 'DynamoTeam'), {1} = package name (i.e. 'Clockwork for Dynamo 1.x')</comment>
</data>
<data name="PackageManagerPackagePreviewCounter" xml:space="preserve">
<value>{0} files and {1} folders will be created.</value>
</data>
<data name="PackageManagerPackageSelectCounter" xml:space="preserve">
<value>{0} files and {1} folders loaded.</value>
</data>
<data name="DuplicatedOlderPackage" xml:space="preserve">
<value>An older version of the package called {0} version {2} was found at {1} with version {3}. The older version has been ignored.</value>
</data>
Expand Down Expand Up @@ -917,4 +923,4 @@ This package likely contains an assembly that is blocked. You will need to load
<data name="InputNodeRenameHint" xml:space="preserve">
<value>default input name, rename me!</value>
</data>
</root>
</root>
2 changes: 2 additions & 0 deletions src/DynamoCore/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2894,6 +2894,8 @@ static Dynamo.Properties.Resources.OutputPortAlternativeName.get -> string
static Dynamo.Properties.Resources.PackageEmpty.get -> string
static Dynamo.Properties.Resources.PackageLoadFailureForBlockedAssembly.get -> string
static Dynamo.Properties.Resources.PackageManagerPackageAlreadyExists.get -> string
static Dynamo.Properties.Resources.PackageManagerPackagePreviewCounter.get -> string
static Dynamo.Properties.Resources.PackageManagerPackageSelectCounter.get -> string
static Dynamo.Properties.Resources.PackageManagerUserIsNotAMaintainer.get -> string
static Dynamo.Properties.Resources.PackageStateError.get -> string
static Dynamo.Properties.Resources.PackageStateErrorTooltip.get -> string
Expand Down
6 changes: 6 additions & 0 deletions src/DynamoCoreWpf/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,10 @@ Dynamo.PackageManager.UI.PackageNameLengthValidationRule
Dynamo.PackageManager.UI.PackageNameLengthValidationRule.PackageNameLengthValidationRule() -> void
Dynamo.PackageManager.UI.PublishPackagePreviewPage
Dynamo.PackageManager.UI.PublishPackagePreviewPage.Dispose() -> void
Dynamo.PackageManager.UI.PublishPackagePreviewPage.FilesAndFoldersCounterPreview.get -> string
Dynamo.PackageManager.UI.PublishPackagePreviewPage.FilesAndFoldersCounterPreview.set -> void
Dynamo.PackageManager.UI.PublishPackagePreviewPage.InitializeComponent() -> void
Dynamo.PackageManager.UI.PublishPackagePreviewPage.PropertyChanged -> System.ComponentModel.PropertyChangedEventHandler
Dynamo.PackageManager.UI.PublishPackagePreviewPage.PublishPackagePreviewPage() -> void
Dynamo.PackageManager.UI.PublishPackagePublishPage
Dynamo.PackageManager.UI.PublishPackagePublishPage.Dispose() -> void
Expand All @@ -1260,6 +1263,8 @@ Dynamo.PackageManager.UI.PublishPackageSelectPage
Dynamo.PackageManager.UI.PublishPackageSelectPage.AllItemsSelected.get -> bool
Dynamo.PackageManager.UI.PublishPackageSelectPage.AllItemsSelected.set -> void
Dynamo.PackageManager.UI.PublishPackageSelectPage.Dispose() -> void
Dynamo.PackageManager.UI.PublishPackageSelectPage.FilesAndFoldersCounterPreview.get -> string
Dynamo.PackageManager.UI.PublishPackageSelectPage.FilesAndFoldersCounterPreview.set -> void
Dynamo.PackageManager.UI.PublishPackageSelectPage.InitializeComponent() -> void
Dynamo.PackageManager.UI.PublishPackageSelectPage.ItemSelection.get -> System.Collections.ObjectModel.ObservableCollection<Dynamo.PackageManager.UI.PackageItemRootViewModel>
Dynamo.PackageManager.UI.PublishPackageSelectPage.ItemSelection.set -> void
Expand Down Expand Up @@ -5619,6 +5624,7 @@ virtual Dynamo.Controls.IntegerDisplay.Convert(object value, System.Type targetT
virtual Dynamo.Controls.IntegerDisplay.ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object
virtual Dynamo.PackageManager.PackageManagerSearchViewModel.OnRequestShowFileDialog(object sender, Dynamo.ViewModels.PackagePathEventArgs e) -> void
virtual Dynamo.PackageManager.PublishPackageViewModel.OnRequestShowFileDialog(object sender, Dynamo.ViewModels.PackagePathEventArgs e) -> void
virtual Dynamo.PackageManager.UI.PublishPackagePreviewPage.RaisePropertyChanged(string propertyName) -> void
virtual Dynamo.PackageManager.UI.PublishPackageSelectPage.RaisePropertyChanged(string propertyName) -> void
virtual Dynamo.PackageManager.ViewModels.PackageManagerSearchElementViewModel.OnRequestShowFileDialog(object sender, Dynamo.ViewModels.PackagePathEventArgs e) -> void
virtual Dynamo.UI.Controls.CodeCompletionEditor.OnCommitChange() -> void
Expand Down
130 changes: 104 additions & 26 deletions src/DynamoCoreWpf/ViewModels/PackageManager/PublishPackageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Forms;
Expand Down Expand Up @@ -1052,7 +1051,12 @@ private bool IsDuplicateFile(PackageItemRootViewModel item1, PackageItemRootView
}
}

private List<PackageItemRootViewModel> BindParentToChild(Dictionary<string, PackageItemRootViewModel> items)
/// <summary>
/// Attempts to recreate the file/folder content structure
/// </summary>
/// <param name="items">A dictionary of the content items</param>
/// <returns></returns>
internal List<PackageItemRootViewModel> BindParentToChild(Dictionary<string, PackageItemRootViewModel> items)
Copy link
Contributor

@reddyashish reddyashish Jul 11, 2024

Choose a reason for hiding this comment

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

The same file changes are also present in #15360

{
foreach (var parent in items)
{
Expand Down Expand Up @@ -1082,25 +1086,61 @@ private List<PackageItemRootViewModel> GetRootItems(Dictionary<string, PackageIt
{
var rootItems = items.Values.Where(x => !x.isChild).ToList();
if (!rootItems.Any()) return rootItems;
var packageSourceDir = CurrentPackageDirectory ??= GetLongestCommonPrefix(items.Keys.ToArray());

var root = new PackageItemRootViewModel(packageSourceDir);
var updatedItems = new List<PackageItemRootViewModel>();
//check each root item and create any missing connections
var roots = new List<PackageItemRootViewModel>();

if (CurrentPackageDirectory != null)
{
roots.Add(new PackageItemRootViewModel(CurrentPackageDirectory));
}
else
{
var commonPaths = GetCommonPaths(items.Keys.ToArray());
if (commonPaths == null) return null;

// Add a new root item for each common path found
commonPaths.ForEach(p => roots.Add(new PackageItemRootViewModel(p)));
}

// Check each root item and create any missing connections
foreach (var item in rootItems)
{
bool itemAssigned = false;
var itemDir = new DirectoryInfo(item.DirectoryName);
if (!itemDir.Parent.FullName.Equals(packageSourceDir))

foreach (var root in roots)
{
root.AddChildRecursively(item);
var rootDir = new DirectoryInfo(root.DirectoryName);

if (itemDir.FullName.StartsWith(rootDir.FullName, StringComparison.OrdinalIgnoreCase))
{
if (itemDir.Parent.FullName.Equals(rootDir.FullName))
{
root.ChildItems.Add(item);
}
else
{
root.AddChildRecursively(item);
}
itemAssigned = true;
break;
}
}
else

// If the item does not belong to any existing root, create a new root for it
if (!itemAssigned)
{
root.ChildItems.Add(item);
var newRoot = new PackageItemRootViewModel(item.DirectoryName);
newRoot.ChildItems.Add(item);
roots.Add(newRoot);
}
}
return root.ChildItems.ToList();
}

// Collect all child items from all roots
var allChildItems = roots.SelectMany(r => r.ChildItems).ToList();

return allChildItems;
}

/// <summary>
/// Test if path2 is subpath of path1
Expand Down Expand Up @@ -1132,22 +1172,56 @@ internal bool IsSubPathOfDeep(PackageItemRootViewModel path1, PackageItemRootVie
/// <summary>
/// Utility method to get the common file path, this may fail for files with the same partial name.
/// </summary>
/// <param name="s">A collection of filepaths</param>
/// <param name="paths">A collection of file paths</param>
/// <returns></returns>
internal string GetLongestCommonPrefix(string[] s)
internal List<string> GetCommonPaths(string[] paths)
{
int k = s[0].Length;
for (int i = 1; i < s.Length; i++)
if (paths == null || paths.Length == 0)
return new List<string>();

// Group paths by their root (drive letter)
var groupedPaths = paths.GroupBy(p => Path.GetPathRoot(p)).ToList();
List<string> commonPaths = new List<string>();

foreach (var group in groupedPaths)
{
k = Math.Min(k, s[i].Length);
for (int j = 0; j < k; j++)
if (s[i][j] != s[0][j])
var pathArray = group.ToArray();
if (pathArray.Length == 1)
{
commonPaths.Add(Path.GetDirectoryName(pathArray[0]));
continue;
}

var k = pathArray[0].Length;
for (var i = 1; i < pathArray.Length; i++)
{
k = Math.Min(k, pathArray[i].Length);
for (var j = 0; j < k; j++)
{
k = j;
break;
if (pathArray[i][j] != pathArray[0][j])
{
k = j;
break;
}
}
}

var commonPrefix = pathArray[0].Substring(0, k);
var commonDir = Path.GetDirectoryName(commonPrefix);

if (string.IsNullOrEmpty(commonDir))
{
// Special case for the root directory
commonDir = Path.GetPathRoot(commonPrefix);
}

if (!string.IsNullOrEmpty(commonDir))
{
commonPaths.Add(commonDir);
}
}
return Path.GetDirectoryName(s[0].Substring(0, k));

return commonPaths.Distinct().ToList();
}

/// <summary>
Expand Down Expand Up @@ -1897,7 +1971,7 @@ private void SelectDirectoryAndAddFilesRecursively()
}

/// <summary>
/// Combines adding files from single file prompt and files in folders propt
/// Combines adding files from single file prompt and files in folders prompt
/// </summary>
/// <param name="filePaths"></param>
internal void AddAllFilesAfterSelection(List<string> filePaths, string rootFolder = null)
Expand Down Expand Up @@ -2033,7 +2107,10 @@ private void RemoveSingleItem(PackageItemRootViewModel vm, DependencyType fileTy
CustomNodeDefinitions.Remove(CustomNodeDefinitions
.First(x => x.DisplayName == fileName));

CustomDyfFilepaths.Remove(fileName + ".dyf");
var keyToRemove = CustomDyfFilepaths.Keys
.FirstOrDefault(k => Path.GetFileNameWithoutExtension(k) == fileName);

if(keyToRemove != null) CustomDyfFilepaths.Remove(keyToRemove);
}
else
{
Expand Down Expand Up @@ -2665,6 +2742,7 @@ private void PreviewPackageBuild()
}
}

// Removes duplicate file names, retaining only the first encounter file path for each unique file name
files = files.GroupBy(file => Path.GetFileName(file), StringComparer.OrdinalIgnoreCase)
.Select(group => group.First())
.ToList();
Expand Down Expand Up @@ -2735,12 +2813,12 @@ internal PackageItemRootViewModel GetPreBuildRootItemViewModel(string publishPat
var doc = new PackageItemRootViewModel(new FileInfo(Path.Combine(docDir, fileName)));
docItemPreview.AddChildRecursively(doc);
}
else if (file.EndsWith(".dyf"))
else if (file.ToLower().EndsWith(".dyf"))
{
var dyfPreview = new PackageItemRootViewModel(fileName, Path.Combine(dyfDir, fileName));
dyfItemPreview.AddChildRecursively(dyfPreview);
}
else if (file.EndsWith(".dll") || PackageDirectoryBuilder.IsXmlDocFile(file, files) || PackageDirectoryBuilder.IsDynamoCustomizationFile(file, files))
else if (file.ToLower().EndsWith(".dll") || PackageDirectoryBuilder.IsXmlDocFile(file, files) || PackageDirectoryBuilder.IsDynamoCustomizationFile(file, files))
{
// Assemblies carry the information if they are NodeLibrary or not
if(Assemblies.Any(x => x.Name.Equals(Path.GetFileNameWithoutExtension(fileName))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ internal void LoadEvents()

var uploadType = PublishPackageViewModel.UploadType;
var publishedFiles = PackageItemRootViewModel.GetFiles(PublishPackageViewModel.PackageContents.ToList());
var count = publishedFiles.Count(x => x.DependencyType != DependencyType.Folder);
var count = publishedFiles.Count(x => x.DependencyType != DependencyType.Folder
|| x.DependencyType != DependencyType.CustomNodePreview);
var message = uploadType.Equals(PackageUploadHandle.UploadType.Local) ?
Dynamo.Wpf.Properties.Resources.PackageManagerFinishedPackageFilesPublishedMessage :
Dynamo.Wpf.Properties.Resources.PackageManagerFinishedPackageFilesUploadedMessage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
xmlns:packagemanager="clr-namespace:Dynamo.PackageManager"
d:DesignHeight="450" d:DesignWidth="800"
UseLayoutRounding="True"
x:Name="PreviewPackagePage"
Title="PublishPackagePreviewPage">
<Page.Resources>
<ResourceDictionary>
Expand Down Expand Up @@ -316,13 +317,24 @@
<RowDefinition Height="28px" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>


<!-- Info text -->
<TextBlock
Margin="5 5 20 5"
HorizontalAlignment="Left"
FontFamily="{StaticResource ArtifaktElementRegular}"
FontSize="10"
Foreground="#F5F5F5"
DataContext="{Binding ElementName=PreviewPackagePage}"
Text="{Binding FilesAndFoldersCounterPreview, UpdateSourceTrigger=PropertyChanged}"/>

<local:CustomBrowserControl x:Name="customBrowserControl"
Grid.Column="0"
Grid.Row="1"
Loaded="customBrowserControl_Loaded"
Root="{Binding PreviewPackageContents, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}"
DisableRemove="True"/>
Grid.Column="0"
Grid.Row="1"
Loaded="customBrowserControl_Loaded"
Root="{Binding PreviewPackageContents, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}"
DisableRemove="True"/>

<!--Files-->
<DataGrid x:Name="rootContentsDataGrid"
Expand Down
Loading
Loading