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

Dyn 5159 import export preferences #13301

Merged
merged 21 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from 10 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
25 changes: 25 additions & 0 deletions src/DynamoCore/Configuration/PreferenceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Xml;
using System.Xml.Serialization;
using Dynamo.Core;
Expand All @@ -14,6 +15,30 @@

namespace Dynamo.Configuration
{
static class ExtensionMethods
{
/// <summary>
/// Copy Properties from a PreferenceSettings instance to another
/// </summary>
/// <param name="source"></param>
/// <param name="destination"></param>
internal static void CopyProperties(this PreferenceSettings source, PreferenceSettings destination)
{
// Iterate the Properties of the destination instance and populate them from their source counterparts
PropertyInfo[] destinationProperties = destination.GetType().GetProperties();
QilongTang marked this conversation as resolved.
Show resolved Hide resolved

foreach (PropertyInfo destinationPi in destinationProperties)
{
PropertyInfo sourcePi = source.GetType().GetProperty(destinationPi.Name);

if (destinationPi.GetCustomAttributes(typeof(System.ObsoleteAttribute), true).Length == 0 && destinationPi.CanWrite)
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
{
destinationPi.SetValue(destination, sourcePi.GetValue(source, null), null);
}
}
}
}

/// <summary>
/// PreferenceSettings is a class for GUI to persist certain settings.
/// Upon running of the GUI, those settings that are persistent will be loaded
Expand Down
8 changes: 7 additions & 1 deletion src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2867,6 +2867,11 @@ public void ClearCurrentWorkspace()
OnWorkspaceCleared(CurrentWorkspace);
}

internal PreferenceSettings ImportPreferences(string newSettingsPath)
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
{
return PreferenceSettings.Load(newSettingsPath);
}

#endregion

#region private methods
Expand Down Expand Up @@ -3155,7 +3160,8 @@ private void OnWorkspacePropertyChanged(object sender, PropertyChangedEventArgs

if (args.PropertyName == "EnablePresetOptions")
OnPropertyChanged("EnablePresetOptions");
}
}

#endregion
}
}
4 changes: 4 additions & 0 deletions src/DynamoCoreWpf/DynamoCoreWpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,10 @@
<EmbeddedResource Include="Views\GuidedTour\HtmlPages\Resources\DynamoPackages_1_1.png" />
<Resource Include="UI\Images\default_info_16px.png" />
<Resource Include="UI\Images\clock-icon.png" />
<Resource Include="UI\Images\question-default-16px.png" />
<Resource Include="UI\Images\question-hover-16px.png" />
<Resource Include="UI\Images\info-default-16px.png" />
<Resource Include="UI\Images\info-hover-16px.png" />
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
<Resource Include="UI\Images\Pin_NoBackground_16px.png" />
<EmbeddedResource Include="Views\GuidedTour\HtmlPages\learnPackages.html" />
<Resource Include="UI\Images\info_2.png" />
Expand Down
72 changes: 72 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.Designer.cs

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

27 changes: 27 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3296,4 +3296,31 @@ You can manage this in Preferences -&gt; Security.</value>
<data name="PrePackagePublishTitle" xml:space="preserve">
<value>Package Upload Scan</value>
</data>
<data name="ImportPreferencesInfo" xml:space="preserve">
<value>Your custom settings can be imported here. It will be applied once Dynamo and any host program restarts</value>
<comment>Import Preferences Info.</comment>
</data>
<data name="ImportPreferencesText" xml:space="preserve">
<value>Import</value>
<comment>Import Preferences Text.</comment>
</data>
<data name="ExportPreferencesText" xml:space="preserve">
<value>Export</value>
<comment>Export Preferences Text.</comment>
</data>
<data name="ExportSettingsDialogTitle" xml:space="preserve">
<value>Select Folder to Export</value>
</data>
<data name="FileDialogImportSettingsFiles" xml:space="preserve">
<value>Settings Files ({0})|{0}</value>
</data>
<data name="ImportSettingsDialogTitle" xml:space="preserve">
<value>Import Settings</value>
</data>
<data name="ImportSettingsSuccessMessage" xml:space="preserve">
<value>Import Success</value>
</data>
<data name="ImportSettingsFailedMessage" xml:space="preserve">
<value>Import Failed</value>
</data>
</root>
27 changes: 27 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3283,4 +3283,31 @@ You can manage this in Preferences -&gt; Security.</value>
<data name="PrePackagePublishTitle" xml:space="preserve">
<value>Package Upload Scan</value>
</data>
<data name="ImportPreferencesInfo" xml:space="preserve">
<value>Your custom settings can be imported here. It will be applied once Dynamo and any host program restarts</value>
<comment>Import Preferences Info.</comment>
</data>
<data name="ImportPreferencesText" xml:space="preserve">
<value>Import</value>
<comment>Import Preferences Text.</comment>
</data>
<data name="ExportPreferencesText" xml:space="preserve">
<value>Export</value>
<comment>Export Preferences Text.</comment>
</data>
<data name="ExportSettingsDialogTitle" xml:space="preserve">
<value>Select Folder to Export</value>
</data>
<data name="FileDialogImportSettingsFiles" xml:space="preserve">
<value>Settings Files ({0})|{0}</value>
</data>
<data name="ImportSettingsDialogTitle" xml:space="preserve">
<value>Import Settings</value>
</data>
<data name="ImportSettingsSuccessMessage" xml:space="preserve">
<value>Import Success</value>
</data>
<data name="ImportSettingsFailedMessage" xml:space="preserve">
<value>Import Failed</value>
</data>
</root>
Binary file added src/DynamoCoreWpf/UI/Images/info-default-16px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/DynamoCoreWpf/UI/Images/info-hover-16px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/DynamoCoreWpf/UI/Images/question-hover-16px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<Color x:Key="Red500">#EB5555</Color>
<Color x:Key="Blue200">#9BD5EF</Color>
<Color x:Key="Blue300">#6AC0E7</Color>
<Color x:Key="Blue350">#6DD2FF</Color>
<Color x:Key="Blue400">#38ABDF</Color>
<Color x:Key="DarkBlue200">#BCD3EE</Color>
<Color x:Key="DefaultFontColor">#DCDCDC</Color>
Expand Down Expand Up @@ -182,5 +183,9 @@
<!-- Connector -->
<SolidColorBrush x:Key="ConnectorHoverStateColor" Color="#808080" />

<!-- Modal Pattern -->
<!-- Modal Pattern -->

<!-- TextBlock Link -->
<SolidColorBrush x:Key="TextBlockLinkForegroundColor" Color="{StaticResource Blue350}" />

</ResourceDictionary>
19 changes: 19 additions & 0 deletions src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5444,4 +5444,23 @@
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>

<!-- TextBlock as a Link -->
<Style x:Key="TextBlockLink" TargetType="TextBlock">
<Setter Property="Foreground" Value="{StaticResource TextBlockLinkForegroundColor}" />
<Setter Property="Cursor" Value="Hand" />
</Style>

<!-- Common Question Icon -->
<Style x:Key="QuestionIcon" TargetType="{x:Type Image}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="False">
<Setter Property="Source" Value="pack://application:,,,/DynamoCoreWpf;component/UI/Images/info-default-16px.png" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Source" Value="pack://application:,,,/DynamoCoreWpf;component/UI/Images/info-hover-16px.png" />
</Trigger>
</Style.Triggers>
</Style>

</ResourceDictionary>
12 changes: 11 additions & 1 deletion src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3064,6 +3064,16 @@ public bool PerformShutdownSequence(ShutdownParams shutdownParams)
return true;
}

/// <summary>
/// Import Preferences
/// </summary>
/// <param name="path">Path from the xml settings file to be imported</param>
/// <returns>A PreferencesSettings instance from the selected path</returns>
public PreferenceSettings ImportPreferences(string path)
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
{
return model.ImportPreferences(path);
}

/// <summary>
/// Ask the user if they want to save any unsaved changes.
/// </summary>
Expand Down Expand Up @@ -3095,7 +3105,7 @@ private bool AskUserToSaveWorkspacesOrCancel(bool allowCancel = true)
return false;
}
return true;
}
}

#endregion
}
Expand Down
37 changes: 37 additions & 0 deletions src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,43 @@ private void AddPythonEnginesOptions()
/// </summary>
public TrustedPathViewModel TrustedPathsViewModel { get; set; }

/// <summary>
/// Import Settings
/// </summary>
/// <param name="filePath"></param>
public void importSettings(string filePath)
{
PreferenceSettings newPreferences = dynamoViewModel.ImportPreferences(filePath);
newPreferences.CopyProperties(preferenceSettings);
QilongTang marked this conversation as resolved.
Show resolved Hide resolved

// Explicit copy
preferenceSettings.SetTrustWarningsDisabled(newPreferences.DisableTrustWarnings);
preferenceSettings.SetTrustedLocations(newPreferences.TrustedLocations);
TrustedPathsViewModel?.InitializeTrustedLocations();

// Set the not explicit Binding
runSettingsIsChecked = preferenceSettings.DefaultRunType;
var engine = PythonEnginesList.FirstOrDefault(x => x.Equals(preferenceSettings.DefaultPythonEngine));
SelectedPythonEngine = string.IsNullOrEmpty(engine) ? Res.DefaultPythonEngineNone : preferenceSettings.DefaultPythonEngine;
dynamoViewModel.RenderPackageFactoryViewModel.MaxTessellationDivisions = preferenceSettings.RenderPrecision;
dynamoViewModel.RenderPackageFactoryViewModel.ShowEdges = preferenceSettings.ShowEdges;
PackagePathsForInstall = null;
PackagePathsViewModel?.InitializeRootLocations();

dynamoViewModel.IsShowingConnectors = preferenceSettings.ShowConnector;
dynamoViewModel.IsShowingConnectorTooltip = preferenceSettings.ShowConnectorToolTip;
foreach (Wpf.ViewModels.Watch3D.DefaultWatch3DViewModel item in dynamoViewModel.Watch3DViewModels)
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
{
Interfaces.BackgroundPreviewActiveState preferenceItem = preferenceSettings.BackgroundPreviews.Where(i => i.Name == item.PreferenceWatchName).FirstOrDefault();
if (preferenceItem != null)
{
item.Active = preferenceItem.IsActive;
}
}

RaisePropertyChanged(string.Empty);
}

/// <summary>
/// The PreferencesViewModel constructor basically initialize all the ItemsSource for the corresponding ComboBox in the View (PreferencesView.xaml)
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/DynamoCoreWpf/ViewModels/Menu/TrustedPathViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ private void CommitChanges(object param)
internal void InitializeTrustedLocations()
{
TrustedLocations = new ObservableCollection<string>(settings?.TrustedLocations ?? new List<string>());
RaisePropertyChanged(string.Empty);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ internal void InitializeRootLocations()
{
RootLocations[index] = Resources.PackagePathViewModel_BuiltInPackages;
}
RaisePropertyChanged(string.Empty);
}

private List<string> CommitRootLocations()
Expand Down
Loading