diff --git a/src/DynamoCore/Configuration/PathManager.cs b/src/DynamoCore/Configuration/PathManager.cs index 15aaf3fcb5d..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 { @@ -93,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 != DynamoModel.StandardLibraryToken) : rootDirectories; } } //Todo in Dynamo 3.0, Add this to the IPathManager interface diff --git a/src/DynamoCore/Models/DynamoModel.cs b/src/DynamoCore/Models/DynamoModel.cs index b4b2f7cc98a..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,7 +727,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 { StandardLibraryToken, pathManager.UserDataDirectory }; + + if (!PreferenceSettings.CustomPackageFolders.Contains(StandardLibraryToken)) + { + PreferenceSettings.CustomPackageFolders.Insert(0, StandardLibraryToken); + } // 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 diff --git a/src/DynamoCoreWpf/Properties/Resources.Designer.cs b/src/DynamoCoreWpf/Properties/Resources.Designer.cs index 9d8429d2f7c..622d36be4fd 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.. /// @@ -3936,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 install location is the first path that is not the Standard Library location.. /// public static string PackagePathViewSummary2 { get { @@ -3944,6 +3953,15 @@ public static string PackagePathViewSummary2 { } } + /// + /// Looks up a localized string similar to Italicized locations 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 6cb33961a77..787c6183b8a 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 @@ -2354,4 +2350,15 @@ 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 + + + The default install location is the first path that is not the Standard Library location. + Package path management dialog content that displays the first non-standard library entry being the default save location. + + + Italicized locations 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 3c2e7642ee1..de173d33213 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 install location is the first path that is not the Standard Library location. + Package path management dialog content that displays the first non-standard library entry being the default save location. Manage Node and Package Paths @@ -2354,4 +2354,11 @@ 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 + + + Italicized locations 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 fc80f66f30f..6fd7f41b563 100644 --- a/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs @@ -1,13 +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 { /// @@ -34,7 +60,7 @@ public int SelectedIndex set { selectedIndex = value; - RaisePropertyChanged("SelectedIndex"); + RaisePropertyChanged(nameof(SelectedIndex)); RaiseCanExecuteChanged(); } } @@ -63,18 +89,21 @@ 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; 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); 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; @@ -86,13 +115,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; @@ -105,10 +134,15 @@ private void RaiseCanExecuteChanged() MovePathUpCommand.RaiseCanExecuteChanged(); AddPathCommand.RaiseCanExecuteChanged(); DeletePathCommand.RaiseCanExecuteChanged(); + UpdatePathCommand.RaiseCanExecuteChanged(); } private bool CanDelete(object param) { + if (RootLocations.IndexOf(Resources.PackagePathViewModel_Standard_Library) == SelectedIndex) + { + return false; + } return RootLocations.Count > 1; } @@ -122,6 +156,11 @@ private bool CanMoveDown(object param) return SelectedIndex < RootLocations.Count - 1; } + private bool CanUpdate(object param) + { + return RootLocations.IndexOf(Resources.PackagePathViewModel_Standard_Library) != SelectedIndex; + } + // The position of the selected entry must always be the first parameter. private void SwapPath(int x, int y) { @@ -184,12 +223,40 @@ 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(DynamoModel.StandardLibraryToken); + + if (index != -1) + { + RootLocations[index] = Resources.PackagePathViewModel_Standard_Library; + + if (setting is IDisablePackageLoadingPreferences disablePrefs) + { + DisableStandardLibrary = disablePrefs.DisableStandardLibrary; + } + } + } + + private List CommitRootLocations() + { + var rootLocations = new List(RootLocations); + var index = rootLocations.IndexOf(Resources.PackagePathViewModel_Standard_Library); + + if (index != -1) + { + rootLocations[index] = DynamoModel.StandardLibraryToken; + } + + return rootLocations; + } } } 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}"> - +