From f8d6ec9ae41d9b239860985c12deb2533a6cb63a Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Fri, 16 Apr 2021 10:04:30 -0400 Subject: [PATCH 01/25] Refactor Package Loader --- src/DynamoPackages/PackageLoader.cs | 41 +++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/src/DynamoPackages/PackageLoader.cs b/src/DynamoPackages/PackageLoader.cs index a1559fcc360..c61cd76775d 100644 --- a/src/DynamoPackages/PackageLoader.cs +++ b/src/DynamoPackages/PackageLoader.cs @@ -75,15 +75,17 @@ public IEnumerable RequestedExtensions /// /// Returns the default package directory where new packages will be installed - /// The default package directory is currently the second entry in the list + /// This is the first non standard library directory /// The first entry is the standard library. /// /// Returns the path to the DefaultPackagesDirectory if found - or null if something has gone wrong. public string DefaultPackagesDirectory { - get { return packagesDirectories.Count > 1 ? packagesDirectories[1] : null; } + get { return defaultPackagesDirectoryIndex != -1 ? packagesDirectories[defaultPackagesDirectoryIndex] : null; } } + private int defaultPackagesDirectoryIndex = -1; + private readonly List packagesDirectoriesToVerifyCertificates = new List(); private string stdLibDirectory = null; @@ -108,6 +110,10 @@ internal string StandardLibraryDirectory } } } + + // Token representing the standard library directory + public static readonly string StandardLibraryToken = @"%StandardLibrary%"; + public PackageLoader(string overridePackageDirectory) : this(new[] { overridePackageDirectory }) { @@ -120,9 +126,10 @@ public PackageLoader(string overridePackageDirectory) /// internal PackageLoader(IEnumerable packagesDirectories, string stdLibDirectory) { - InitPackageLoader(packagesDirectories, stdLibDirectory); //override the property. this.StandardLibraryDirectory = stdLibDirectory; + + InitPackageLoader(packagesDirectories, stdLibDirectory); } public PackageLoader(IEnumerable packagesDirectories) @@ -148,10 +155,34 @@ private void InitPackageLoader(IEnumerable packagesDirectories, string s { if (packagesDirectories == null) throw new ArgumentNullException("packagesDirectories"); - - this.packagesDirectories.Add(stdLibDirectory); + this.packagesDirectories.AddRange(packagesDirectories); + // Setup standard library + var standardLibraryIndex = this.packagesDirectories.IndexOf(StandardLibraryToken); + if (standardLibraryIndex == -1) + { + // No standard library in list + // Add standard library first + this.packagesDirectories.Insert(0, stdLibDirectory); + } + else + { + // Replace token with runtime library location + this.packagesDirectories[standardLibraryIndex] = stdLibDirectory; + } + + // Setup Default Package Directory + if (standardLibraryIndex == -1) + { + defaultPackagesDirectoryIndex = this.packagesDirectories.Count > 1 ? 1 : -1; + } + else + { + var safeIndex = this.packagesDirectories.Count > 1 ? 1 : -1; + defaultPackagesDirectoryIndex = standardLibraryIndex == 1 ? 0 : safeIndex; + } + var error = PathHelper.CreateFolderIfNotExist(DefaultPackagesDirectory); if (error != null) From 12f46b44e9e136fc8de718692d2fcbb1e9ed845b Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Fri, 16 Apr 2021 10:16:11 -0400 Subject: [PATCH 02/25] Revert unneeded change --- src/DynamoPackages/PackageLoader.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/DynamoPackages/PackageLoader.cs b/src/DynamoPackages/PackageLoader.cs index c61cd76775d..1ae08b0de68 100644 --- a/src/DynamoPackages/PackageLoader.cs +++ b/src/DynamoPackages/PackageLoader.cs @@ -126,12 +126,12 @@ public PackageLoader(string overridePackageDirectory) /// internal PackageLoader(IEnumerable packagesDirectories, string stdLibDirectory) { + InitPackageLoader(packagesDirectories, stdLibDirectory); + //override the property. this.StandardLibraryDirectory = stdLibDirectory; - - InitPackageLoader(packagesDirectories, stdLibDirectory); } - + public PackageLoader(IEnumerable packagesDirectories) { InitPackageLoader(packagesDirectories, StandardLibraryDirectory); From 272d703ee9ed77ebadb8860c7a340c28574746f4 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Fri, 16 Apr 2021 10:44:04 -0400 Subject: [PATCH 03/25] Add some tests --- .../PackageManagerTests/PackageLoaderTests.cs | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/test/Libraries/PackageManagerTests/PackageLoaderTests.cs b/test/Libraries/PackageManagerTests/PackageLoaderTests.cs index 9cc26577830..42f4b83bc6d 100644 --- a/test/Libraries/PackageManagerTests/PackageLoaderTests.cs +++ b/test/Libraries/PackageManagerTests/PackageLoaderTests.cs @@ -629,10 +629,10 @@ public void ScanPackageDirectoryWithCheckingCertificatesEnabledWillLoadPackageWi Assert.IsTrue(entries.Any(x => x.FullName == "SignedPackage.SignedPackage.SignedPackage.Hello")); } - //signedpackge generated from internal repo at SignedDynamoTestingPackages + //signedpackage generated from internal repo at SignedDynamoTestingPackages [Test] - public void HasValidStandardLibraryPath() + public void HasValidStandardLibraryAndDefaultPackagesPath() { // Arrange var loader = new PackageLoader(new[] { PackagesDirectory }, new[] { PackagesDirectorySigned }); @@ -641,10 +641,46 @@ public void HasValidStandardLibraryPath() // Act var standardDirectory = loader.StandardLibraryDirectory; + var defaultDirectory = loader.DefaultPackagesDirectory; // Assert Assert.IsNotNullOrEmpty(standardDirectory); Assert.AreEqual(standardDirectory, directory); + Assert.AreNotEqual(defaultDirectory, directory); + } + [Test] + public void HasValidStandardLibraryAndDefaultPackagesPathWhenStandardLibraryTokenIsAddedFirst() + { + // Arrange + var loader = new PackageLoader(new[] { PackageLoader.StandardLibraryToken, PackagesDirectory }, new[] { PackagesDirectorySigned }); + var directory = Path.Combine(Path.GetDirectoryName(Assembly.GetAssembly(loader.GetType()).Location), + @"Standard Library", @"Packages"); + + // Act + var standardDirectory = loader.StandardLibraryDirectory; + var defaultDirectory = loader.DefaultPackagesDirectory; + + // Assert + Assert.IsNotNullOrEmpty(standardDirectory); + Assert.AreEqual(standardDirectory, directory); + Assert.AreNotEqual(defaultDirectory, directory); + } + [Test] + public void HasValidStandardLibraryAndDefaultPackagesPathWhenStandardLibraryTokenIsAddedLast() + { + // Arrange + var loader = new PackageLoader(new[] { PackagesDirectory, PackageLoader.StandardLibraryToken }, new[] { PackagesDirectorySigned }); + var directory = Path.Combine(Path.GetDirectoryName(Assembly.GetAssembly(loader.GetType()).Location), + @"Standard Library", @"Packages"); + + // Act + var standardDirectory = loader.StandardLibraryDirectory; + var defaultDirectory = loader.DefaultPackagesDirectory; + + // Assert + Assert.IsNotNullOrEmpty(standardDirectory); + Assert.AreEqual(standardDirectory, directory); + Assert.AreNotEqual(defaultDirectory, directory); } [Test] public void PackageInStandardLibLocationIsLoaded() From f37b52ba54774fdfbf5c25e4ec6614787a5a3ce6 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Fri, 16 Apr 2021 14:14:42 -0400 Subject: [PATCH 04/25] Add standard library token to startup code. --- src/DynamoCore/Models/DynamoModel.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/DynamoCore/Models/DynamoModel.cs b/src/DynamoCore/Models/DynamoModel.cs index b4b2f7cc98a..b6a9e68cfc9 100644 --- a/src/DynamoCore/Models/DynamoModel.cs +++ b/src/DynamoCore/Models/DynamoModel.cs @@ -724,7 +724,12 @@ protected DynamoModel(IStartConfiguration config) // is no additional location specified. Otherwise, update pathManager.PackageDirectories to include // PackageFolders if (PreferenceSettings.CustomPackageFolders.Count == 0) - PreferenceSettings.CustomPackageFolders = new List { pathManager.UserDataDirectory }; + PreferenceSettings.CustomPackageFolders = new List { @"%StandardLibrary%", pathManager.UserDataDirectory }; + + if (!PreferenceSettings.CustomPackageFolders.Contains(@"%StandardLibrary%")) + { + PreferenceSettings.CustomPackageFolders.Insert(0, @"%StandardLibrary%"); + } // Make sure that the default package folder is added in the list if custom packages folder. var userDataFolder = pathManager.GetUserDataFolder(); // Get the default user data path From a15f651e9f69a4d1500dbe412fdaf915656e885f Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Fri, 16 Apr 2021 14:15:05 -0400 Subject: [PATCH 05/25] Add/update tests. --- test/DynamoCoreTests/DSLibraryTest.cs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/test/DynamoCoreTests/DSLibraryTest.cs b/test/DynamoCoreTests/DSLibraryTest.cs index 9f42dd13379..554b90fab51 100644 --- a/test/DynamoCoreTests/DSLibraryTest.cs +++ b/test/DynamoCoreTests/DSLibraryTest.cs @@ -239,15 +239,15 @@ public void TestAddStandardLibraryPath() List customPackageFolders = CurrentDynamoModel.PreferenceSettings.CustomPackageFolders; // Test that the default number of folders is correct - Assert.IsTrue(customPackageFolders.Count == 2); + Assert.IsTrue(customPackageFolders.Count == 3); // Test that the path is added as expected CurrentDynamoModel.AddPackagePath(TestDirectory, ""); - Assert.IsTrue(customPackageFolders.Count == 3); + Assert.IsTrue(customPackageFolders.Count == 4); // Test that the path is not duplicated CurrentDynamoModel.AddPackagePath(TestDirectory, ""); - Assert.IsTrue(customPackageFolders.Count == 3); + Assert.IsTrue(customPackageFolders.Count == 4); } [Test] @@ -258,7 +258,7 @@ public void TestAddDllLibraryPath() List customPackageFolders = CurrentDynamoModel.PreferenceSettings.CustomPackageFolders; // Test that the default number of folders is correct - Assert.IsTrue(customPackageFolders.Count == 2); + Assert.IsTrue(customPackageFolders.Count == 3); string filename = @"DLL.dll"; string packagePath = Path.Combine(TestDirectory, @"pkgs\Custom Rounding\extra"); @@ -266,15 +266,28 @@ public void TestAddDllLibraryPath() // Test that the full file path is added as expected CurrentDynamoModel.AddPackagePath(packagePath, filename); - Assert.IsTrue(customPackageFolders.Count == 3); + Assert.IsTrue(customPackageFolders.Count == 4); int count = customPackageFolders.Where(s => s == libraryPath).Count(); Assert.IsTrue(count == 1); // Test that the full file path is not duplicated CurrentDynamoModel.AddPackagePath(packagePath, filename); - Assert.IsTrue(customPackageFolders.Count == 3); + Assert.IsTrue(customPackageFolders.Count == 4); count = customPackageFolders.Where(s => s == libraryPath).Count(); Assert.IsTrue(count == 1); } + [Test] + [Category("UnitTests")] + public void TestStandardLibraryTokenIsFirstInList() + { + // Get the default custom package folders + List customPackageFolders = CurrentDynamoModel.PreferenceSettings.CustomPackageFolders; + + // Test that the default number of folders is correct + Assert.IsTrue(customPackageFolders.Count == 3); + + // Check that standard library token is first + Assert.AreEqual(@"%StandardLibrary%", customPackageFolders[0]); + } } } From 7d3927e95891023867cc9b722f4943f128375ca8 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Mon, 19 Apr 2021 09:43:09 -0400 Subject: [PATCH 06/25] Make internal and add prop for token. --- src/DynamoCore/Models/DynamoModel.cs | 9 ++++++--- src/DynamoPackages/PackageLoader.cs | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/DynamoCore/Models/DynamoModel.cs b/src/DynamoCore/Models/DynamoModel.cs index b6a9e68cfc9..10fb869f25b 100644 --- a/src/DynamoCore/Models/DynamoModel.cs +++ b/src/DynamoCore/Models/DynamoModel.cs @@ -586,6 +586,9 @@ public static DynamoModel Start(IStartConfiguration configuration) return new DynamoModel(configuration); } + // Token representing the standard library directory + internal static readonly string StandardLibraryToken = @"%StandardLibrary%"; + /// /// Default constructor for DynamoModel /// @@ -724,11 +727,11 @@ protected DynamoModel(IStartConfiguration config) // is no additional location specified. Otherwise, update pathManager.PackageDirectories to include // PackageFolders if (PreferenceSettings.CustomPackageFolders.Count == 0) - PreferenceSettings.CustomPackageFolders = new List { @"%StandardLibrary%", pathManager.UserDataDirectory }; + PreferenceSettings.CustomPackageFolders = new List { StandardLibraryToken, pathManager.UserDataDirectory }; - if (!PreferenceSettings.CustomPackageFolders.Contains(@"%StandardLibrary%")) + if (!PreferenceSettings.CustomPackageFolders.Contains(StandardLibraryToken)) { - PreferenceSettings.CustomPackageFolders.Insert(0, @"%StandardLibrary%"); + PreferenceSettings.CustomPackageFolders.Insert(0, StandardLibraryToken); } // Make sure that the default package folder is added in the list if custom packages folder. diff --git a/src/DynamoPackages/PackageLoader.cs b/src/DynamoPackages/PackageLoader.cs index 1ae08b0de68..b9210f16f9e 100644 --- a/src/DynamoPackages/PackageLoader.cs +++ b/src/DynamoPackages/PackageLoader.cs @@ -112,7 +112,7 @@ internal string StandardLibraryDirectory } // Token representing the standard library directory - public static readonly string StandardLibraryToken = @"%StandardLibrary%"; + internal static readonly string StandardLibraryToken = @"%StandardLibrary%"; public PackageLoader(string overridePackageDirectory) : this(new[] { overridePackageDirectory }) From d6bd0fa1ccf8a92c35c2f21ffa9083cf2bf5ea90 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Mon, 19 Apr 2021 10:14:10 -0400 Subject: [PATCH 07/25] Add UI support. --- .../PackageManager/PackagePathViewModel.cs | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs b/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs index fc80f66f30f..724e62d2b8e 100644 --- a/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs @@ -68,7 +68,8 @@ public PackagePathViewModel(PackageLoader loader, LoadPackageParams loadParams, this.packageLoader = loader; this.loadPackageParams = loadParams; this.customNodeManager = customNodeManager; - RootLocations = new ObservableCollection(setting.CustomPackageFolders); + + InitializeRootLocations(); AddPathCommand = new DelegateCommand(p => InsertPath()); DeletePathCommand = new DelegateCommand(p => RemovePathAt((int) p), CanDelete); @@ -184,12 +185,35 @@ private void RemovePathAt(int index) private void CommitChanges(object param) { - setting.CustomPackageFolders = new List(RootLocations); + setting.CustomPackageFolders = CommitRootLocations(); if (this.packageLoader != null) { this.packageLoader.LoadCustomNodesAndPackages(loadPackageParams, customNodeManager); } } + private void InitializeRootLocations() + { + RootLocations = new ObservableCollection(setting.CustomPackageFolders); + var index = RootLocations.IndexOf(@"%StandardLibrary%"); + + if (index != -1) + { + RootLocations[index] = "Standard Library"; + } + } + + private List CommitRootLocations() + { + var rootLocations = new List(RootLocations); + var index = rootLocations.IndexOf("Standard Library"); + + if (index != -1) + { + rootLocations[index] = @"%StandardLibrary%"; + } + + return rootLocations; + } } } From 6fc15670e8cfe8f25c650c77294649d7b5e6ed8b Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Mon, 19 Apr 2021 10:37:28 -0400 Subject: [PATCH 08/25] Disable delete and edit for standard library. --- .../PackageManager/PackagePathViewModel.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs b/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs index 724e62d2b8e..e5035b76f4d 100644 --- a/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs @@ -75,7 +75,7 @@ public PackagePathViewModel(PackageLoader loader, LoadPackageParams loadParams, DeletePathCommand = new DelegateCommand(p => RemovePathAt((int) p), CanDelete); MovePathUpCommand = new DelegateCommand(p => SwapPath((int) p, ((int) p) - 1), CanMoveUp); MovePathDownCommand = new DelegateCommand(p => SwapPath((int) p, ((int) p) + 1), CanMoveDown); - UpdatePathCommand = new DelegateCommand(p => UpdatePathAt((int) p)); + UpdatePathCommand = new DelegateCommand(p => UpdatePathAt((int) p), CanUpdate); SaveSettingCommand = new DelegateCommand(CommitChanges); SelectedIndex = 0; @@ -87,13 +87,13 @@ public PackagePathViewModel(PackageLoader loader, LoadPackageParams loadParams, public PackagePathViewModel(IPreferences setting) { - RootLocations = new ObservableCollection(setting.CustomPackageFolders); + InitializeRootLocations(); AddPathCommand = new DelegateCommand(p => InsertPath()); DeletePathCommand = new DelegateCommand(p => RemovePathAt((int)p), CanDelete); MovePathUpCommand = new DelegateCommand(p => SwapPath((int)p, ((int)p) - 1), CanMoveUp); MovePathDownCommand = new DelegateCommand(p => SwapPath((int)p, ((int)p) + 1), CanMoveDown); - UpdatePathCommand = new DelegateCommand(p => UpdatePathAt((int)p)); + UpdatePathCommand = new DelegateCommand(p => UpdatePathAt((int)p), CanUpdate); SaveSettingCommand = new DelegateCommand(CommitChanges); SelectedIndex = 0; @@ -106,10 +106,15 @@ private void RaiseCanExecuteChanged() MovePathUpCommand.RaiseCanExecuteChanged(); AddPathCommand.RaiseCanExecuteChanged(); DeletePathCommand.RaiseCanExecuteChanged(); + UpdatePathCommand.RaiseCanExecuteChanged(); } private bool CanDelete(object param) { + if (RootLocations.IndexOf("Standard Library") == SelectedIndex) + { + return false; + } return RootLocations.Count > 1; } @@ -123,6 +128,11 @@ private bool CanMoveDown(object param) return SelectedIndex < RootLocations.Count - 1; } + private bool CanUpdate(object param) + { + return RootLocations.IndexOf("Standard Library") != SelectedIndex; + } + // The position of the selected entry must always be the first parameter. private void SwapPath(int x, int y) { From cedafdeec336bbf2eb4e7277f1c8fba297ff8022 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Mon, 19 Apr 2021 10:51:40 -0400 Subject: [PATCH 09/25] Move UI string to resources. --- src/DynamoCoreWpf/Properties/Resources.Designer.cs | 9 +++++++++ src/DynamoCoreWpf/Properties/Resources.en-US.resx | 3 +++ src/DynamoCoreWpf/Properties/Resources.resx | 3 +++ .../ViewModels/PackageManager/PackagePathViewModel.cs | 9 +++++---- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/DynamoCoreWpf/Properties/Resources.Designer.cs b/src/DynamoCoreWpf/Properties/Resources.Designer.cs index 9d8429d2f7c..e848a6a2435 100644 --- a/src/DynamoCoreWpf/Properties/Resources.Designer.cs +++ b/src/DynamoCoreWpf/Properties/Resources.Designer.cs @@ -3926,6 +3926,15 @@ public static string PackagePathViewHeading { } } + /// + /// Looks up a localized string similar to Standard Library. + /// + public static string PackagePathViewModel_Standard_Library { + get { + return ResourceManager.GetString("PackagePathViewModel_Standard_Library", resourceCulture); + } + } + /// /// Looks up a localized string similar to Add paths to make nodes and packages show up in the library.. /// diff --git a/src/DynamoCoreWpf/Properties/Resources.en-US.resx b/src/DynamoCoreWpf/Properties/Resources.en-US.resx index 6cb33961a77..3b66664020e 100644 --- a/src/DynamoCoreWpf/Properties/Resources.en-US.resx +++ b/src/DynamoCoreWpf/Properties/Resources.en-US.resx @@ -2354,4 +2354,7 @@ Uninstall the following packages: {0}? A different version of the package {1} is already installed as part of the Standard Library. {0} cannot override packages in the Standard Library location. + + Standard Library + diff --git a/src/DynamoCoreWpf/Properties/Resources.resx b/src/DynamoCoreWpf/Properties/Resources.resx index 3c2e7642ee1..0e309a75bc2 100644 --- a/src/DynamoCoreWpf/Properties/Resources.resx +++ b/src/DynamoCoreWpf/Properties/Resources.resx @@ -2354,4 +2354,7 @@ Uninstall the following packages: {0}? A different version of the package {1} is already installed as part of the Standard Library. {0} cannot override packages in the Standard Library location. + + Standard Library + diff --git a/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs b/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs index e5035b76f4d..0a8c3fb6f11 100644 --- a/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs @@ -4,6 +4,7 @@ using Dynamo.Core; using Dynamo.Interfaces; using Dynamo.PackageManager; +using Dynamo.Wpf.Properties; using DelegateCommand = Dynamo.UI.Commands.DelegateCommand; namespace Dynamo.ViewModels @@ -111,7 +112,7 @@ private void RaiseCanExecuteChanged() private bool CanDelete(object param) { - if (RootLocations.IndexOf("Standard Library") == SelectedIndex) + if (RootLocations.IndexOf(Resources.PackagePathViewModel_Standard_Library) == SelectedIndex) { return false; } @@ -130,7 +131,7 @@ private bool CanMoveDown(object param) private bool CanUpdate(object param) { - return RootLocations.IndexOf("Standard Library") != SelectedIndex; + return RootLocations.IndexOf(Resources.PackagePathViewModel_Standard_Library) != SelectedIndex; } // The position of the selected entry must always be the first parameter. @@ -209,14 +210,14 @@ private void InitializeRootLocations() if (index != -1) { - RootLocations[index] = "Standard Library"; + RootLocations[index] = Resources.PackagePathViewModel_Standard_Library; } } private List CommitRootLocations() { var rootLocations = new List(RootLocations); - var index = rootLocations.IndexOf("Standard Library"); + var index = rootLocations.IndexOf(Resources.PackagePathViewModel_Standard_Library); if (index != -1) { From fce87f8eb3c28ee58d4459dd48b753811acde889 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Mon, 19 Apr 2021 10:55:46 -0400 Subject: [PATCH 10/25] Add token prop --- .../ViewModels/PackageManager/PackagePathViewModel.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs b/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs index 0a8c3fb6f11..c6834f87fcd 100644 --- a/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs @@ -49,6 +49,9 @@ public virtual void OnRequestShowFileDialog(object sender, PackagePathEventArgs } } + // Token representing the standard library directory + private static readonly string StandardLibraryToken = @"%StandardLibrary%"; + private IPreferences setting { get { return loadPackageParams.Preferences; } @@ -206,7 +209,7 @@ private void CommitChanges(object param) private void InitializeRootLocations() { RootLocations = new ObservableCollection(setting.CustomPackageFolders); - var index = RootLocations.IndexOf(@"%StandardLibrary%"); + var index = RootLocations.IndexOf(StandardLibraryToken); if (index != -1) { @@ -221,7 +224,7 @@ private List CommitRootLocations() if (index != -1) { - rootLocations[index] = @"%StandardLibrary%"; + rootLocations[index] = StandardLibraryToken; } return rootLocations; From b9817b4723581d65be7058f252907112aa5e32f6 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Mon, 19 Apr 2021 16:18:10 -0400 Subject: [PATCH 11/25] Fix tests. --- src/DynamoCore/Configuration/PathManager.cs | 5 +++-- test/DynamoCoreTests/DSEvaluationUnitTestBase.cs | 3 ++- test/DynamoCoreWpfTests/SerializationTests.cs | 4 ++-- test/Libraries/DynamoPythonTests/PythonEditTests.cs | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/DynamoCore/Configuration/PathManager.cs b/src/DynamoCore/Configuration/PathManager.cs index 15aaf3fcb5d..27930da6297 100644 --- a/src/DynamoCore/Configuration/PathManager.cs +++ b/src/DynamoCore/Configuration/PathManager.cs @@ -87,6 +87,7 @@ class PathManager : IPathManager private readonly HashSet extensionsDirectories; private readonly HashSet viewExtensionsDirectories; + private static readonly string StandardLibraryToken = @"%StandardLibrary%"; #endregion internal IPreferences Preferences { get; set; } @@ -129,7 +130,7 @@ public string CommonDataDirectory public string DefaultUserDefinitions { - get { return TransformPath(RootDirectories.First(), DefinitionsDirectoryName); } + get { return TransformPath(RootDirectories.First(path => path != StandardLibraryToken), DefinitionsDirectoryName); } } public IEnumerable DefinitionDirectories @@ -149,7 +150,7 @@ public string LogDirectory public string DefaultPackagesDirectory { - get { return TransformPath(RootDirectories.First(), PackagesDirectoryName); } + get { return TransformPath(RootDirectories.First(path => path != StandardLibraryToken), PackagesDirectoryName); } } public IEnumerable PackagesDirectories diff --git a/test/DynamoCoreTests/DSEvaluationUnitTestBase.cs b/test/DynamoCoreTests/DSEvaluationUnitTestBase.cs index e63b0dc7953..e8fb7f1a6ff 100644 --- a/test/DynamoCoreTests/DSEvaluationUnitTestBase.cs +++ b/test/DynamoCoreTests/DSEvaluationUnitTestBase.cs @@ -341,7 +341,8 @@ protected void AssertPreviewCount(string guid, int count) var data = mirror.GetData(); Assert.IsTrue(data.IsCollection, "preview data is not a list"); - Assert.AreEqual(count, data.GetElements().ToList().Count); + var c = data.GetElements().ToList().Count; + Assert.AreEqual(count, c); } protected object GetPreviewValueAtIndex(string guid, int index) diff --git a/test/DynamoCoreWpfTests/SerializationTests.cs b/test/DynamoCoreWpfTests/SerializationTests.cs index e8051ea4c55..f5710cdf051 100644 --- a/test/DynamoCoreWpfTests/SerializationTests.cs +++ b/test/DynamoCoreWpfTests/SerializationTests.cs @@ -978,7 +978,7 @@ public void NewCustomNodeSaveAndLoadPt1() new ConnectorModel(numberNode.OutPorts.FirstOrDefault(), outnode2.InPorts.FirstOrDefault(), Guid.NewGuid()); - var savePath = Path.Combine(this.ViewModel.Model.PathManager.DefinitionDirectories.FirstOrDefault(), "NewCustomNodeSaveAndLoad.dyf"); + var savePath = Path.Combine(this.ViewModel.Model.PathManager.DefaultUserDefinitions, "NewCustomNodeSaveAndLoad.dyf"); //save it to the definitions folder so it gets loaded at startup. ws.Save(savePath); @@ -1004,7 +1004,7 @@ public void NewCustomNodeSaveAndLoadPt2() Assert.NotNull(nodeingraph); Assert.IsTrue(nodeingraph.State == ElementState.Active); //remove custom node from definitions folder - var savePath = Path.Combine(this.ViewModel.Model.PathManager.DefinitionDirectories.FirstOrDefault(), "NewCustomNodeSaveAndLoad.dyf"); + var savePath = Path.Combine(this.ViewModel.Model.PathManager.DefaultUserDefinitions, "NewCustomNodeSaveAndLoad.dyf"); File.Delete(savePath); } diff --git a/test/Libraries/DynamoPythonTests/PythonEditTests.cs b/test/Libraries/DynamoPythonTests/PythonEditTests.cs index a555d08ea7b..d3f62f59be4 100644 --- a/test/Libraries/DynamoPythonTests/PythonEditTests.cs +++ b/test/Libraries/DynamoPythonTests/PythonEditTests.cs @@ -510,7 +510,7 @@ public void Python_CanReferenceDynamoServicesExecutionSession() count++; Assert.AreEqual(count, (GetModel().CurrentWorkspace as HomeWorkspaceModel).EvaluationCount); - AssertPreviewCount(guid, 2); + AssertPreviewCount(guid, 3); } } From b21cceddf81bb678a33bcb59a071b8b64a9a3cb4 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Tue, 20 Apr 2021 09:20:51 -0400 Subject: [PATCH 12/25] Add more filtering --- src/DynamoCore/Configuration/PathManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DynamoCore/Configuration/PathManager.cs b/src/DynamoCore/Configuration/PathManager.cs index 27930da6297..b72e2fbe567 100644 --- a/src/DynamoCore/Configuration/PathManager.cs +++ b/src/DynamoCore/Configuration/PathManager.cs @@ -135,7 +135,7 @@ public string DefaultUserDefinitions public IEnumerable DefinitionDirectories { - get { return RootDirectories.Select(path => TransformPath(path, DefinitionsDirectoryName)); } + get { return RootDirectories.Select(path => TransformPath(path, DefinitionsDirectoryName)).Where(path => path != StandardLibraryToken); } } public string CommonDefinitions @@ -155,7 +155,7 @@ public string DefaultPackagesDirectory public IEnumerable PackagesDirectories { - get { return RootDirectories.Select(path => TransformPath(path, PackagesDirectoryName)); } + get { return RootDirectories.Select(path => TransformPath(path, PackagesDirectoryName)).Where(path => path != StandardLibraryToken); } } public IEnumerable ExtensionsDirectories From e091bd3c05e680278587bc0d7c999d09cd07fb37 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Tue, 20 Apr 2021 09:21:08 -0400 Subject: [PATCH 13/25] Update tests --- test/DynamoCoreWpfTests/SerializationTests.cs | 4 ++-- test/Libraries/DynamoPythonTests/PythonEditTests.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/DynamoCoreWpfTests/SerializationTests.cs b/test/DynamoCoreWpfTests/SerializationTests.cs index f5710cdf051..9400a68127e 100644 --- a/test/DynamoCoreWpfTests/SerializationTests.cs +++ b/test/DynamoCoreWpfTests/SerializationTests.cs @@ -978,7 +978,7 @@ public void NewCustomNodeSaveAndLoadPt1() new ConnectorModel(numberNode.OutPorts.FirstOrDefault(), outnode2.InPorts.FirstOrDefault(), Guid.NewGuid()); - var savePath = Path.Combine(this.ViewModel.Model.PathManager.DefaultUserDefinitions, "NewCustomNodeSaveAndLoad.dyf"); + var savePath = Path.Combine(this.ViewModel.Model.PathManager.DefinitionDirectories.First(), "NewCustomNodeSaveAndLoad.dyf"); //save it to the definitions folder so it gets loaded at startup. ws.Save(savePath); @@ -1004,7 +1004,7 @@ public void NewCustomNodeSaveAndLoadPt2() Assert.NotNull(nodeingraph); Assert.IsTrue(nodeingraph.State == ElementState.Active); //remove custom node from definitions folder - var savePath = Path.Combine(this.ViewModel.Model.PathManager.DefaultUserDefinitions, "NewCustomNodeSaveAndLoad.dyf"); + var savePath = Path.Combine(this.ViewModel.Model.PathManager.DefinitionDirectories.First(), "NewCustomNodeSaveAndLoad.dyf"); File.Delete(savePath); } diff --git a/test/Libraries/DynamoPythonTests/PythonEditTests.cs b/test/Libraries/DynamoPythonTests/PythonEditTests.cs index d3f62f59be4..a555d08ea7b 100644 --- a/test/Libraries/DynamoPythonTests/PythonEditTests.cs +++ b/test/Libraries/DynamoPythonTests/PythonEditTests.cs @@ -510,7 +510,7 @@ public void Python_CanReferenceDynamoServicesExecutionSession() count++; Assert.AreEqual(count, (GetModel().CurrentWorkspace as HomeWorkspaceModel).EvaluationCount); - AssertPreviewCount(guid, 3); + AssertPreviewCount(guid, 2); } } From f39bdd98403ea291ed45480d4b6d84881226210e Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Tue, 20 Apr 2021 09:28:28 -0400 Subject: [PATCH 14/25] Revert changes --- test/DynamoCoreWpfTests/SerializationTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/DynamoCoreWpfTests/SerializationTests.cs b/test/DynamoCoreWpfTests/SerializationTests.cs index 9400a68127e..e8051ea4c55 100644 --- a/test/DynamoCoreWpfTests/SerializationTests.cs +++ b/test/DynamoCoreWpfTests/SerializationTests.cs @@ -978,7 +978,7 @@ public void NewCustomNodeSaveAndLoadPt1() new ConnectorModel(numberNode.OutPorts.FirstOrDefault(), outnode2.InPorts.FirstOrDefault(), Guid.NewGuid()); - var savePath = Path.Combine(this.ViewModel.Model.PathManager.DefinitionDirectories.First(), "NewCustomNodeSaveAndLoad.dyf"); + var savePath = Path.Combine(this.ViewModel.Model.PathManager.DefinitionDirectories.FirstOrDefault(), "NewCustomNodeSaveAndLoad.dyf"); //save it to the definitions folder so it gets loaded at startup. ws.Save(savePath); @@ -1004,7 +1004,7 @@ public void NewCustomNodeSaveAndLoadPt2() Assert.NotNull(nodeingraph); Assert.IsTrue(nodeingraph.State == ElementState.Active); //remove custom node from definitions folder - var savePath = Path.Combine(this.ViewModel.Model.PathManager.DefinitionDirectories.First(), "NewCustomNodeSaveAndLoad.dyf"); + var savePath = Path.Combine(this.ViewModel.Model.PathManager.DefinitionDirectories.FirstOrDefault(), "NewCustomNodeSaveAndLoad.dyf"); File.Delete(savePath); } From af16ce730c61af3bd419feb78519180024a305de Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Tue, 20 Apr 2021 09:32:32 -0400 Subject: [PATCH 15/25] Revert debug changes --- test/DynamoCoreTests/DSEvaluationUnitTestBase.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/DynamoCoreTests/DSEvaluationUnitTestBase.cs b/test/DynamoCoreTests/DSEvaluationUnitTestBase.cs index e8fb7f1a6ff..e63b0dc7953 100644 --- a/test/DynamoCoreTests/DSEvaluationUnitTestBase.cs +++ b/test/DynamoCoreTests/DSEvaluationUnitTestBase.cs @@ -341,8 +341,7 @@ protected void AssertPreviewCount(string guid, int count) var data = mirror.GetData(); Assert.IsTrue(data.IsCollection, "preview data is not a list"); - var c = data.GetElements().ToList().Count; - Assert.AreEqual(count, c); + Assert.AreEqual(count, data.GetElements().ToList().Count); } protected object GetPreviewValueAtIndex(string guid, int index) From f31582f15d80f811d7068edd6656fed62965a1ee Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Tue, 20 Apr 2021 10:06:49 -0400 Subject: [PATCH 16/25] Update defaults --- src/DynamoCore/Configuration/PathManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DynamoCore/Configuration/PathManager.cs b/src/DynamoCore/Configuration/PathManager.cs index b72e2fbe567..2f91daed3a7 100644 --- a/src/DynamoCore/Configuration/PathManager.cs +++ b/src/DynamoCore/Configuration/PathManager.cs @@ -360,7 +360,7 @@ internal PathManager(PathManagerParams pathManagerParams) var galleryDirectory = GetGalleryDirectory(commonDataDir); galleryFilePath = Path.Combine(galleryDirectory, GalleryContentsFileName); - rootDirectories = new List { userDataDir }; + rootDirectories = new List { StandardLibraryToken, userDataDir }; nodeDirectories = new HashSet { From 35bc71925dc3d0d22ca642aea95fbe9f81372c1a Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Tue, 20 Apr 2021 10:07:01 -0400 Subject: [PATCH 17/25] Add more tests --- .../PackageManagerTests/PackageLoaderTests.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/Libraries/PackageManagerTests/PackageLoaderTests.cs b/test/Libraries/PackageManagerTests/PackageLoaderTests.cs index 42f4b83bc6d..b2f63a46ae4 100644 --- a/test/Libraries/PackageManagerTests/PackageLoaderTests.cs +++ b/test/Libraries/PackageManagerTests/PackageLoaderTests.cs @@ -868,6 +868,25 @@ public void PackageLoaderLoadOldPackage() Assert.IsNull(loader.LocalPackages.FirstOrDefault(package => package.Description == @"Old package")); } + [Test] + public void StandardLibraryIsNotExposedInPathManager() + { + // Arrange + var pathManager = CurrentDynamoModel.PathManager; + + // Act + var defaultPackageDirectory = pathManager.DefaultPackagesDirectory; + var packageDirectories = pathManager.PackagesDirectories; + var defaultUserDefinitions = pathManager.DefaultUserDefinitions; + var userDefinitions = pathManager.DefinitionDirectories; + + // Assert + Assert.AreNotEqual(@"%StandardLibrary%", defaultPackageDirectory); + Assert.IsFalse(packageDirectories.Contains(@"%StandardLibrary%")); + Assert.AreNotEqual(@"%StandardLibrary%", defaultUserDefinitions); + Assert.IsFalse(userDefinitions.Contains(@"%StandardLibrary%")); + } + [Test] public void IsUnderPackageControlIsCorrectForValidFunctionDefinition() { From 496ac140145ca9733314681dcb19df5556a6bffd Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Tue, 20 Apr 2021 10:24:01 -0400 Subject: [PATCH 18/25] Add more tests --- test/DynamoCoreWpfTests/PackagePathTests.cs | 30 +++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/DynamoCoreWpfTests/PackagePathTests.cs b/test/DynamoCoreWpfTests/PackagePathTests.cs index 2a03b8fca62..f8b8b96cf06 100644 --- a/test/DynamoCoreWpfTests/PackagePathTests.cs +++ b/test/DynamoCoreWpfTests/PackagePathTests.cs @@ -69,6 +69,36 @@ public void ReorderingPathsTest() Assert.AreEqual(@"C:\", vm.RootLocations[2]); } + [Test] + public void CannotDeleteStandardLibraryPath() + { + var setting = new PreferenceSettings + { + CustomPackageFolders = { @"%StandardLibrary%", @"C:\" } + }; + + + var vm = CreatePackagePathViewModel(setting); + + Assert.AreEqual(2, vm.RootLocations.Count); + Assert.IsFalse(vm.DeletePathCommand.CanExecute(null)); + } + + [Test] + public void CannotUpdateStandardLibraryPath() + { + var setting = new PreferenceSettings + { + CustomPackageFolders = { @"%StandardLibrary%", @"C:\" } + }; + + + var vm = CreatePackagePathViewModel(setting); + + Assert.AreEqual(2, vm.RootLocations.Count); + Assert.IsFalse(vm.UpdatePathCommand.CanExecute(null)); + } + [Test] public void AddRemovePathsTest() { From 91c928655991a680788d6152d29c5d58b7483ac6 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Tue, 20 Apr 2021 10:37:27 -0400 Subject: [PATCH 19/25] Refactor --- src/DynamoCore/Configuration/PathManager.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/DynamoCore/Configuration/PathManager.cs b/src/DynamoCore/Configuration/PathManager.cs index 2f91daed3a7..dacf41e39b5 100644 --- a/src/DynamoCore/Configuration/PathManager.cs +++ b/src/DynamoCore/Configuration/PathManager.cs @@ -94,7 +94,7 @@ class PathManager : IPathManager private IEnumerable RootDirectories { - get { return Preferences != null ? Preferences.CustomPackageFolders : rootDirectories; } + get { return Preferences != null ? Preferences.CustomPackageFolders.Where(path => path != StandardLibraryToken) : rootDirectories; } } //Todo in Dynamo 3.0, Add this to the IPathManager interface @@ -130,12 +130,12 @@ public string CommonDataDirectory public string DefaultUserDefinitions { - get { return TransformPath(RootDirectories.First(path => path != StandardLibraryToken), DefinitionsDirectoryName); } + get { return TransformPath(RootDirectories.First(), DefinitionsDirectoryName); } } public IEnumerable DefinitionDirectories { - get { return RootDirectories.Select(path => TransformPath(path, DefinitionsDirectoryName)).Where(path => path != StandardLibraryToken); } + get { return RootDirectories.Select(path => TransformPath(path, DefinitionsDirectoryName)); } } public string CommonDefinitions @@ -150,12 +150,12 @@ public string LogDirectory public string DefaultPackagesDirectory { - get { return TransformPath(RootDirectories.First(path => path != StandardLibraryToken), PackagesDirectoryName); } + get { return TransformPath(RootDirectories.First(), PackagesDirectoryName); } } public IEnumerable PackagesDirectories { - get { return RootDirectories.Select(path => TransformPath(path, PackagesDirectoryName)).Where(path => path != StandardLibraryToken); } + get { return RootDirectories.Select(path => TransformPath(path, PackagesDirectoryName)); } } public IEnumerable ExtensionsDirectories @@ -360,7 +360,7 @@ internal PathManager(PathManagerParams pathManagerParams) var galleryDirectory = GetGalleryDirectory(commonDataDir); galleryFilePath = Path.Combine(galleryDirectory, GalleryContentsFileName); - rootDirectories = new List { StandardLibraryToken, userDataDir }; + rootDirectories = new List { userDataDir }; nodeDirectories = new HashSet { From 0d841321c66644912b9e3270e2282f372d9b0968 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Tue, 20 Apr 2021 10:37:41 -0400 Subject: [PATCH 20/25] Update test --- test/Libraries/PackageManagerTests/PackageLoaderTests.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/Libraries/PackageManagerTests/PackageLoaderTests.cs b/test/Libraries/PackageManagerTests/PackageLoaderTests.cs index b2f63a46ae4..520a656ee80 100644 --- a/test/Libraries/PackageManagerTests/PackageLoaderTests.cs +++ b/test/Libraries/PackageManagerTests/PackageLoaderTests.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using System.Reflection; +using System.Runtime.Remoting; using Dynamo.Configuration; using Dynamo.Extensions; using Dynamo.Graph.Nodes; @@ -882,8 +883,10 @@ public void StandardLibraryIsNotExposedInPathManager() // Assert Assert.AreNotEqual(@"%StandardLibrary%", defaultPackageDirectory); + Assert.AreEqual(2, packageDirectories.Count()); Assert.IsFalse(packageDirectories.Contains(@"%StandardLibrary%")); Assert.AreNotEqual(@"%StandardLibrary%", defaultUserDefinitions); + Assert.AreEqual(2, userDefinitions.Count()); Assert.IsFalse(userDefinitions.Contains(@"%StandardLibrary%")); } From fb7caa92111f25ab0315fa6201b587feb8c549ac Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Wed, 21 Apr 2021 09:51:21 -0400 Subject: [PATCH 21/25] Consolidate the use of the StandardLibraryToken Prop. --- src/DynamoCore/Configuration/PathManager.cs | 4 ++-- .../ViewModels/PackageManager/PackagePathViewModel.cs | 8 +++----- src/DynamoPackages/PackageLoader.cs | 6 ++---- test/Libraries/PackageManagerTests/PackageLoaderTests.cs | 5 +++-- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/DynamoCore/Configuration/PathManager.cs b/src/DynamoCore/Configuration/PathManager.cs index dacf41e39b5..62b13da03a4 100644 --- a/src/DynamoCore/Configuration/PathManager.cs +++ b/src/DynamoCore/Configuration/PathManager.cs @@ -11,6 +11,7 @@ using Dynamo.Interfaces; using Dynamo.Properties; using DynamoUtilities; +using Dynamo.Models; namespace Dynamo.Core { @@ -87,14 +88,13 @@ class PathManager : IPathManager private readonly HashSet extensionsDirectories; private readonly HashSet viewExtensionsDirectories; - private static readonly string StandardLibraryToken = @"%StandardLibrary%"; #endregion internal IPreferences Preferences { get; set; } private IEnumerable RootDirectories { - get { return Preferences != null ? Preferences.CustomPackageFolders.Where(path => path != StandardLibraryToken) : rootDirectories; } + get { return Preferences != null ? Preferences.CustomPackageFolders.Where(path => path != DynamoModel.StandardLibraryToken) : rootDirectories; } } //Todo in Dynamo 3.0, Add this to the IPathManager interface diff --git a/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs b/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs index c6834f87fcd..c99bc9318e2 100644 --- a/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs @@ -6,6 +6,7 @@ using Dynamo.PackageManager; using Dynamo.Wpf.Properties; using DelegateCommand = Dynamo.UI.Commands.DelegateCommand; +using Dynamo.Models; namespace Dynamo.ViewModels { @@ -49,9 +50,6 @@ public virtual void OnRequestShowFileDialog(object sender, PackagePathEventArgs } } - // Token representing the standard library directory - private static readonly string StandardLibraryToken = @"%StandardLibrary%"; - private IPreferences setting { get { return loadPackageParams.Preferences; } @@ -209,7 +207,7 @@ private void CommitChanges(object param) private void InitializeRootLocations() { RootLocations = new ObservableCollection(setting.CustomPackageFolders); - var index = RootLocations.IndexOf(StandardLibraryToken); + var index = RootLocations.IndexOf(DynamoModel.StandardLibraryToken); if (index != -1) { @@ -224,7 +222,7 @@ private List CommitRootLocations() if (index != -1) { - rootLocations[index] = StandardLibraryToken; + rootLocations[index] = DynamoModel.StandardLibraryToken; } return rootLocations; diff --git a/src/DynamoPackages/PackageLoader.cs b/src/DynamoPackages/PackageLoader.cs index b9210f16f9e..88508e3aee1 100644 --- a/src/DynamoPackages/PackageLoader.cs +++ b/src/DynamoPackages/PackageLoader.cs @@ -12,6 +12,7 @@ using Dynamo.Utilities; using DynamoPackages.Properties; using DynamoUtilities; +using Dynamo.Models; namespace Dynamo.PackageManager { @@ -111,9 +112,6 @@ internal string StandardLibraryDirectory } } - // Token representing the standard library directory - internal static readonly string StandardLibraryToken = @"%StandardLibrary%"; - public PackageLoader(string overridePackageDirectory) : this(new[] { overridePackageDirectory }) { @@ -159,7 +157,7 @@ private void InitPackageLoader(IEnumerable packagesDirectories, string s this.packagesDirectories.AddRange(packagesDirectories); // Setup standard library - var standardLibraryIndex = this.packagesDirectories.IndexOf(StandardLibraryToken); + var standardLibraryIndex = this.packagesDirectories.IndexOf(DynamoModel.StandardLibraryToken); if (standardLibraryIndex == -1) { // No standard library in list diff --git a/test/Libraries/PackageManagerTests/PackageLoaderTests.cs b/test/Libraries/PackageManagerTests/PackageLoaderTests.cs index 520a656ee80..6373a4318b8 100644 --- a/test/Libraries/PackageManagerTests/PackageLoaderTests.cs +++ b/test/Libraries/PackageManagerTests/PackageLoaderTests.cs @@ -10,6 +10,7 @@ using Dynamo.Graph.Nodes.CustomNodes; using Dynamo.Graph.Workspaces; using Dynamo.Search.SearchElements; +using Dynamo.Models; using Moq; using NUnit.Framework; @@ -653,7 +654,7 @@ public void HasValidStandardLibraryAndDefaultPackagesPath() public void HasValidStandardLibraryAndDefaultPackagesPathWhenStandardLibraryTokenIsAddedFirst() { // Arrange - var loader = new PackageLoader(new[] { PackageLoader.StandardLibraryToken, PackagesDirectory }, new[] { PackagesDirectorySigned }); + var loader = new PackageLoader(new[] { DynamoModel.StandardLibraryToken, PackagesDirectory }, new[] { PackagesDirectorySigned }); var directory = Path.Combine(Path.GetDirectoryName(Assembly.GetAssembly(loader.GetType()).Location), @"Standard Library", @"Packages"); @@ -670,7 +671,7 @@ public void HasValidStandardLibraryAndDefaultPackagesPathWhenStandardLibraryToke public void HasValidStandardLibraryAndDefaultPackagesPathWhenStandardLibraryTokenIsAddedLast() { // Arrange - var loader = new PackageLoader(new[] { PackagesDirectory, PackageLoader.StandardLibraryToken }, new[] { PackagesDirectorySigned }); + var loader = new PackageLoader(new[] { PackagesDirectory, DynamoModel.StandardLibraryToken }, new[] { PackagesDirectorySigned }); var directory = Path.Combine(Path.GetDirectoryName(Assembly.GetAssembly(loader.GetType()).Location), @"Standard Library", @"Packages"); From 9de327903fc8ca1753cec295ace6999d670573e0 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Thu, 22 Apr 2021 16:58:22 -0400 Subject: [PATCH 22/25] Refresh dialog --- .../Properties/Resources.Designer.cs | 11 ++++++- .../Properties/Resources.en-US.resx | 14 +++++--- src/DynamoCoreWpf/Properties/Resources.resx | 10 ++++-- .../PackageManager/PackagePathViewModel.cs | 33 ++++++++++++++++++- .../Views/PackageManager/PackagePathView.xaml | 12 +++++-- 5 files changed, 67 insertions(+), 13 deletions(-) diff --git a/src/DynamoCoreWpf/Properties/Resources.Designer.cs b/src/DynamoCoreWpf/Properties/Resources.Designer.cs index e848a6a2435..53f169675ae 100644 --- a/src/DynamoCoreWpf/Properties/Resources.Designer.cs +++ b/src/DynamoCoreWpf/Properties/Resources.Designer.cs @@ -3945,7 +3945,7 @@ public static string PackagePathViewSummary1 { } /// - /// Looks up a localized string similar to Top path is the default save location.. + /// Looks up a localized string similar to The default save location is the first path that is not the Standard Library location. /// public static string PackagePathViewSummary2 { get { @@ -3953,6 +3953,15 @@ public static string PackagePathViewSummary2 { } } + /// + /// Looks up a localized string similar to Locations in italic are disabled. + /// + public static string PackagePathViewSummary3 { + get { + return ResourceManager.GetString("PackagePathViewSummary3", resourceCulture); + } + } + /// /// Looks up a localized string similar to Manage Node and Package Paths. /// diff --git a/src/DynamoCoreWpf/Properties/Resources.en-US.resx b/src/DynamoCoreWpf/Properties/Resources.en-US.resx index 3b66664020e..ca3a389882e 100644 --- a/src/DynamoCoreWpf/Properties/Resources.en-US.resx +++ b/src/DynamoCoreWpf/Properties/Resources.en-US.resx @@ -1559,10 +1559,6 @@ Next assemblies were loaded several times: Add paths to make nodes and packages show up in the library. Package path management dialog content - - Top path is the default save location. - Package path management dialog content that describes about the first entry being the default save location. - Manage Node and Package Paths Package path management dialog title @@ -2357,4 +2353,12 @@ Uninstall the following packages: {0}? Standard Library - + + The default save location is the first path that is not the Standard Library location + Package path management dialog content that describes about the first non standard libary entry being the default save location. + + + Locations in italic are disabled + Italic locations are disabled. This can currently only be the standard library. + + \ No newline at end of file diff --git a/src/DynamoCoreWpf/Properties/Resources.resx b/src/DynamoCoreWpf/Properties/Resources.resx index 0e309a75bc2..5080a89eba8 100644 --- a/src/DynamoCoreWpf/Properties/Resources.resx +++ b/src/DynamoCoreWpf/Properties/Resources.resx @@ -1906,8 +1906,8 @@ Do you want to install the latest Dynamo update? Package path management dialog content - Top path is the default save location. - Package path management dialog content that describes about the first entry being the default save location. + The default save location is the first path that is not the Standard Library location + Package path management dialog content that describes about the first non standard libary entry being the default save location. Manage Node and Package Paths @@ -2357,4 +2357,8 @@ Uninstall the following packages: {0}? Standard Library - + + Locations in italic are disabled + Italic locations are disabled. This can currently only be the standard library. + + \ No newline at end of file diff --git a/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs b/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs index c99bc9318e2..6fd7f41b563 100644 --- a/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs @@ -1,15 +1,39 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Windows.Controls; using Dynamo.Core; using Dynamo.Interfaces; using Dynamo.PackageManager; using Dynamo.Wpf.Properties; using DelegateCommand = Dynamo.UI.Commands.DelegateCommand; using Dynamo.Models; +using System.Windows.Data; namespace Dynamo.ViewModels { + public sealed class PathEnabledConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + if (value != null && parameter != null) + { + var disableStandardLibrary = (bool)parameter; + if (disableStandardLibrary) + { + var path = value as string; + return String.CompareOrdinal(path, Resources.PackagePathViewModel_Standard_Library) != 0; + } + } + return true; + } + + public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + throw new NotSupportedException(); + } + } + public class PackagePathEventArgs : EventArgs { /// @@ -36,7 +60,7 @@ public int SelectedIndex set { selectedIndex = value; - RaisePropertyChanged("SelectedIndex"); + RaisePropertyChanged(nameof(SelectedIndex)); RaiseCanExecuteChanged(); } } @@ -65,6 +89,8 @@ private IPreferences setting public DelegateCommand UpdatePathCommand { get; private set; } public DelegateCommand SaveSettingCommand { get; private set; } + public static bool DisableStandardLibrary = false; + public PackagePathViewModel(PackageLoader loader, LoadPackageParams loadParams, CustomNodeManager customNodeManager) { this.packageLoader = loader; @@ -212,6 +238,11 @@ private void InitializeRootLocations() if (index != -1) { RootLocations[index] = Resources.PackagePathViewModel_Standard_Library; + + if (setting is IDisablePackageLoadingPreferences disablePrefs) + { + DisableStandardLibrary = disablePrefs.DisableStandardLibrary; + } } } diff --git a/src/DynamoCoreWpf/Views/PackageManager/PackagePathView.xaml b/src/DynamoCoreWpf/Views/PackageManager/PackagePathView.xaml index befb6579e60..44d9952d76e 100644 --- a/src/DynamoCoreWpf/Views/PackageManager/PackagePathView.xaml +++ b/src/DynamoCoreWpf/Views/PackageManager/PackagePathView.xaml @@ -17,14 +17,14 @@ d:DesignWidth="300" Background="#515151" Style="{DynamicResource DynamoWindowStyle}" - d:DataContext="{d:DesignInstance ViewModels:InstalledPackagesViewModel, IsDesignTimeCreatable=False}"> + d:DataContext="{d:DesignInstance ViewModels:PackagePathViewModel, IsDesignTimeCreatable=False}"> - +