Skip to content

Commit

Permalink
DYN-3572 std.lib should be visible in manage node and package path UI (
Browse files Browse the repository at this point in the history
…#11622)

* Refactor Package Loader

* Revert unneeded change

* Add some tests

* Add standard library token to startup code.

* Add/update tests.

* Make internal and add prop for token.

* Add UI support.

* Disable delete and edit for standard library.

* Move UI string to resources.

* Add token prop

* Fix tests.

* Add more filtering

* Update tests

* Revert changes

* Revert debug changes

* Update defaults

* Add more tests

* Add more tests

* Refactor

* Update test

* Consolidate the use of the StandardLibraryToken Prop.

* Refresh dialog

* Update wording

* More resource tweaks

* Final resource tweaks!
  • Loading branch information
sm6srw authored Apr 23, 2021
1 parent 097a8bb commit 0c7e3bf
Show file tree
Hide file tree
Showing 11 changed files with 278 additions and 33 deletions.
3 changes: 2 additions & 1 deletion src/DynamoCore/Configuration/PathManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Dynamo.Interfaces;
using Dynamo.Properties;
using DynamoUtilities;
using Dynamo.Models;

namespace Dynamo.Core
{
Expand Down Expand Up @@ -93,7 +94,7 @@ class PathManager : IPathManager

private IEnumerable<string> 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
Expand Down
10 changes: 9 additions & 1 deletion src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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%";

/// <summary>
/// Default constructor for DynamoModel
/// </summary>
Expand Down Expand Up @@ -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<string> { pathManager.UserDataDirectory };
PreferenceSettings.CustomPackageFolders = new List<string> { 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
Expand Down
20 changes: 19 additions & 1 deletion src/DynamoCoreWpf/Properties/Resources.Designer.cs

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

17 changes: 12 additions & 5 deletions src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1559,10 +1559,6 @@ Next assemblies were loaded several times:
<value>Add paths to make nodes and packages show up in the library.</value>
<comment>Package path management dialog content</comment>
</data>
<data name="PackagePathViewSummary2" xml:space="preserve">
<value>Top path is the default save location.</value>
<comment>Package path management dialog content that describes about the first entry being the default save location.</comment>
</data>
<data name="PackagePathViewTitle" xml:space="preserve">
<value>Manage Node and Package Paths</value>
<comment>Package path management dialog title</comment>
Expand Down Expand Up @@ -2354,4 +2350,15 @@ Uninstall the following packages: {0}?</value>
<data name="MessageSamePackageDiffVersInStdLib" xml:space="preserve">
<value>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.</value>
</data>
</root>
<data name="PackagePathViewModel_Standard_Library" xml:space="preserve">
<value>Standard Library</value>
</data>
<data name="PackagePathViewSummary2" xml:space="preserve">
<value>The default install location is the first path that is not the Standard Library location.</value>
<comment>Package path management dialog content that displays the first non-standard library entry being the default save location.</comment>
</data>
<data name="PackagePathViewSummary3" xml:space="preserve">
<value>Italicized locations are disabled.</value>
<comment>Italic locations are disabled. This can currently only be the standard library.</comment>
</data>
</root>
13 changes: 10 additions & 3 deletions src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1906,8 +1906,8 @@ Do you want to install the latest Dynamo update?</value>
<comment>Package path management dialog content</comment>
</data>
<data name="PackagePathViewSummary2" xml:space="preserve">
<value>Top path is the default save location.</value>
<comment>Package path management dialog content that describes about the first entry being the default save location.</comment>
<value>The default install location is the first path that is not the Standard Library location.</value>
<comment>Package path management dialog content that displays the first non-standard library entry being the default save location.</comment>
</data>
<data name="PackagePathViewTitle" xml:space="preserve">
<value>Manage Node and Package Paths</value>
Expand Down Expand Up @@ -2354,4 +2354,11 @@ Uninstall the following packages: {0}?</value>
<data name="MessageSamePackageDiffVersInStdLib" xml:space="preserve">
<value>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.</value>
</data>
</root>
<data name="PackagePathViewModel_Standard_Library" xml:space="preserve">
<value>Standard Library</value>
</data>
<data name="PackagePathViewSummary3" xml:space="preserve">
<value>Italicized locations are disabled.</value>
<comment>Italic locations are disabled. This can currently only be the standard library.</comment>
</data>
</root>
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
Expand All @@ -34,7 +60,7 @@ public int SelectedIndex
set
{
selectedIndex = value;
RaisePropertyChanged("SelectedIndex");
RaisePropertyChanged(nameof(SelectedIndex));
RaiseCanExecuteChanged();
}
}
Expand Down Expand Up @@ -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<string>(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;
Expand All @@ -86,13 +115,13 @@ public PackagePathViewModel(PackageLoader loader, LoadPackageParams loadParams,
public PackagePathViewModel(IPreferences setting)
{

RootLocations = new ObservableCollection<string>(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;
Expand All @@ -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;
}

Expand All @@ -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)
{
Expand Down Expand Up @@ -184,12 +223,40 @@ private void RemovePathAt(int index)

private void CommitChanges(object param)
{
setting.CustomPackageFolders = new List<string>(RootLocations);
setting.CustomPackageFolders = CommitRootLocations();
if (this.packageLoader != null)
{
this.packageLoader.LoadCustomNodesAndPackages(loadPackageParams, customNodeManager);
}
}

private void InitializeRootLocations()
{
RootLocations = new ObservableCollection<string>(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<string> CommitRootLocations()
{
var rootLocations = new List<string>(RootLocations);
var index = rootLocations.IndexOf(Resources.PackagePathViewModel_Standard_Library);

if (index != -1)
{
rootLocations[index] = DynamoModel.StandardLibraryToken;
}

return rootLocations;
}
}
}
12 changes: 9 additions & 3 deletions src/DynamoCoreWpf/Views/PackageManager/PackagePathView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}">

<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ui:SharedResourceDictionary Source="{x:Static ui:SharedDictionaryManager.DynamoModernDictionaryUri}" />
</ResourceDictionary.MergedDictionaries>

<ViewModels:PathEnabledConverter x:Key="PathEnabledConverter" />
<Style x:Key="PathListBoxStyle"
TargetType="ListBox">
<Setter Property="SnapsToDevicePixels"
Expand Down Expand Up @@ -88,7 +88,6 @@
Background="Transparent">
<ContentPresenter />
</Border>

<ControlTemplate.Triggers>
<Trigger Property="IsSelected"
Value="True">
Expand All @@ -107,6 +106,10 @@
Property="Background"
Value="#666666" />
</MultiTrigger>
<DataTrigger Binding="{Binding Converter={StaticResource PathEnabledConverter}, ConverterParameter={x:Static ViewModels:PackagePathViewModel.DisableStandardLibrary}, UpdateSourceTrigger=PropertyChanged}" Value="False">
<Setter Property="FontStyle"
Value="Italic" />
</DataTrigger>
</ControlTemplate.Triggers>

</ControlTemplate>
Expand Down Expand Up @@ -141,6 +144,9 @@
<TextBlock TextWrapping="Wrap"
FontStyle="Italic"
Text="{x:Static p:Resources.PackagePathViewSummary2}" />
<TextBlock TextWrapping="Wrap"
FontStyle="Italic"
Text="{x:Static p:Resources.PackagePathViewSummary3}" />
</StackPanel>

<TextBlock Grid.Row="1"
Expand Down
Loading

0 comments on commit 0c7e3bf

Please sign in to comment.