Skip to content

Commit

Permalink
Revert "homepage preferences (DynamoDS#15139)"
Browse files Browse the repository at this point in the history
This reverts commit 534f6cf.
  • Loading branch information
reddyashish committed Apr 16, 2024
1 parent 86b63ab commit b72cb2f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 149 deletions.
15 changes: 0 additions & 15 deletions src/DynamoCore/Configuration/PreferenceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,21 +395,6 @@ public bool IsBackgroundPreviewActive
/// </summary>
public bool UseHardwareAcceleration { get; set; }

/// <summary>
/// Persistence for Dynamo HomePage
/// </summary>
[XmlIgnore]
internal Dictionary<string, object> HomePageSettings { get; set; }

/// <summary>
/// A helper intermediary string to allow the serialization of the HomePageSettings dictionary
/// </summary>
public string HomePageSettingsSerialized
{
get => Newtonsoft.Json.JsonConvert.SerializeObject(HomePageSettings);
set => HomePageSettings = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>>(value);
}

#endregion

#region Dynamo application settings
Expand Down
6 changes: 2 additions & 4 deletions src/DynamoCore/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
abstract Dynamo.Extensions.LinterExtensionBase.Name.get -> string
abstract Dynamo.Extensions.LinterExtensionBase.Name.get -> string
abstract Dynamo.Extensions.LinterExtensionBase.Shutdown() -> void
abstract Dynamo.Extensions.LinterExtensionBase.UniqueId.get -> string
abstract Dynamo.Graph.ModelBase.DeserializeCore(System.Xml.XmlElement nodeElement, Dynamo.Graph.SaveContext context) -> void
Expand Down Expand Up @@ -177,8 +177,6 @@ Dynamo.Configuration.PreferenceSettings.HideAutocompleteMethodOptions.get -> boo
Dynamo.Configuration.PreferenceSettings.HideAutocompleteMethodOptions.set -> void
Dynamo.Configuration.PreferenceSettings.HideNodesBelowSpecificConfidenceLevel.get -> bool
Dynamo.Configuration.PreferenceSettings.HideNodesBelowSpecificConfidenceLevel.set -> void
Dynamo.Configuration.PreferenceSettings.HomePageSettingsSerialized.get -> string
Dynamo.Configuration.PreferenceSettings.HomePageSettingsSerialized.set -> void
Dynamo.Configuration.PreferenceSettings.IronPythonResolveTargetVersion.get -> string
Dynamo.Configuration.PreferenceSettings.IronPythonResolveTargetVersion.set -> void
Dynamo.Configuration.PreferenceSettings.IsADPAnalyticsReportingApproved.get -> bool
Expand Down Expand Up @@ -3141,4 +3139,4 @@ virtual Dynamo.Search.SearchElements.NodeSearchElement.FullName.get -> string
virtual Dynamo.Search.SearchElements.NodeSearchElement.GenerateInputParameters() -> System.Collections.Generic.IEnumerable<System.Tuple<string, string>>
virtual Dynamo.Search.SearchElements.NodeSearchElement.GenerateOutputParameters() -> System.Collections.Generic.IEnumerable<string>
virtual Dynamo.Search.SearchElements.NodeSearchElement.OnItemProduced(Dynamo.Graph.Nodes.NodeModel obj) -> void
virtual Dynamo.Search.SearchElements.SearchElementBase.CreationName.get -> string
virtual Dynamo.Search.SearchElements.SearchElementBase.CreationName.get -> string
3 changes: 1 addition & 2 deletions src/DynamoCoreWpf/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1576,8 +1576,7 @@ Dynamo.UI.Views.ScriptHomeObject.NewCustomNodeWorkspace() -> void
Dynamo.UI.Views.ScriptHomeObject.NewWorkspace() -> void
Dynamo.UI.Views.ScriptHomeObject.OpenFile(string path) -> void
Dynamo.UI.Views.ScriptHomeObject.OpenWorkspace() -> void
Dynamo.UI.Views.ScriptHomeObject.SaveSettings(string settings) -> void
Dynamo.UI.Views.ScriptHomeObject.ScriptHomeObject(System.Action<string> requestOpenFile, System.Action requestNewWorkspace, System.Action requestOpenWorkspace, System.Action requestNewCustomNodeWorkspace, System.Action requestApplicationLoaded, System.Action<string> requestShowGuidedTour, System.Action requestShowSampleFilesInFolder, System.Action requestShowBackupFilesInFolder, System.Action requestShowTemplate, System.Action<string> requestSaveSettings) -> void
Dynamo.UI.Views.ScriptHomeObject.ScriptHomeObject(System.Action<string> requestOpenFile, System.Action requestNewWorkspace, System.Action requestOpenWorkspace, System.Action requestNewCustomNodeWorkspace, System.Action requestApplicationLoaded, System.Action<string> requestShowGuidedTour, System.Action requestShowSampleFilesInFolder, System.Action requestShowBackupFilesInFolder, System.Action requestShowTemplate) -> void
Dynamo.UI.Views.ScriptHomeObject.ShowBackupFilesInFolder() -> void
Dynamo.UI.Views.ScriptHomeObject.ShowSampleFilesInFolder() -> void
Dynamo.UI.Views.ScriptHomeObject.ShowTempalte() -> void
Expand Down
95 changes: 19 additions & 76 deletions src/DynamoCoreWpf/Views/HomePage/HomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public partial class HomePage : UserControl, IDisposable
internal Action RequestShowSampleFilesInFolder;
internal Action RequestShowBackupFilesInFolder;
internal Action RequestShowTemplate;
internal Action<string> RequestSaveSettings;

internal List<GuidedTourItem> GuidedTourItems;

Expand Down Expand Up @@ -84,7 +83,6 @@ public HomePage()
RequestShowBackupFilesInFolder = ShowBackupFilesInFolder;
RequestShowTemplate = ShowTemplate;
RequestApplicationLoaded = ApplicationLoaded;
RequestSaveSettings = SaveSettings;

DataContextChanged += OnDataContextChanged;

Expand Down Expand Up @@ -198,8 +196,7 @@ private async void UserControl_Loaded(object sender, System.Windows.RoutedEventA
RequestShowGuidedTour,
RequestShowSampleFilesInFolder,
RequestShowBackupFilesInFolder,
RequestShowTemplate,
RequestSaveSettings));
RequestShowTemplate));
}
catch (ObjectDisposedException ex)
{
Expand Down Expand Up @@ -244,14 +241,25 @@ internal bool ProcessUri(string uri)
return false;
}

internal void LoadingDone()
internal async void LoadingDone()
{
SendGuidesData();

if (startPage == null) { return; }

SendGuidesData();
SendSamplesData();
SendRecentGraphsData();
SetLocale();

var recentFiles = startPage.RecentFiles;
if (recentFiles == null || !recentFiles.Any()) { return; }

LoadGraphs(recentFiles);

var userLocale = CultureInfo.CurrentCulture.Name;

if (dynWebView?.CoreWebView2 != null)
{
await dynWebView.CoreWebView2.ExecuteScriptAsync(@$"window.setLocale('{userLocale}');");
}
}

#region FrontEnd Initialization Calls
Expand Down Expand Up @@ -284,37 +292,6 @@ private async void SendSamplesData()
}
}

private async void SendRecentGraphsData()
{
// Send user preferences
if (dynWebView?.CoreWebView2 != null)
{
if (startPage.DynamoViewModel.PreferenceSettings.HomePageSettings != null)
{
var settingsJson = Newtonsoft.Json.JsonConvert.SerializeObject(startPage.DynamoViewModel.PreferenceSettings.HomePageSettings);
settingsJson = System.Web.HttpUtility.JavaScriptStringEncode(settingsJson);

await dynWebView.CoreWebView2.ExecuteScriptAsync(@$"window.setHomePageSettings('{settingsJson}');");
}
}

// Load recent files
var recentFiles = startPage.RecentFiles;
if (recentFiles != null && recentFiles.Any())
{
LoadGraphs(recentFiles);
}
}

private async void SetLocale()
{
var userLocale = CultureInfo.CurrentCulture.Name;

if (dynWebView?.CoreWebView2 != null)
{
await dynWebView.CoreWebView2.ExecuteScriptAsync(@$"window.setLocale('{userLocale}');");
}
}

/// <summary>
/// Sends guided tour data to react app
Expand Down Expand Up @@ -428,34 +405,6 @@ internal void StartGuidedTour(string path)
ShowGuidedTour(path);
}

internal void SaveSettings(string settingsJson)
{
if (!string.IsNullOrEmpty(settingsJson) && this.startPage != null)
{
var settingsDict = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>>(settingsJson);

// If the HomePageSettings have not been previously created, initialize it now
if (startPage.DynamoViewModel.PreferenceSettings.HomePageSettings == null)
{
startPage.DynamoViewModel.PreferenceSettings.HomePageSettings = new Dictionary<string, object>();
}

// Change existing values, or add new ones
foreach (var setting in settingsDict)
{
if (startPage.DynamoViewModel.PreferenceSettings.HomePageSettings.ContainsKey(setting.Key)
&& startPage.DynamoViewModel.PreferenceSettings.HomePageSettings[setting.Key] != setting.Value)
{
startPage.DynamoViewModel.PreferenceSettings.HomePageSettings[setting.Key] = setting.Value;
}
else
{
startPage.DynamoViewModel.PreferenceSettings.HomePageSettings.Add(setting.Key, setting.Value);
}
}
}
}

internal void NewWorkspace()
{
this.startPage?.DynamoViewModel?.NewHomeWorkspaceCommand.Execute(null);
Expand Down Expand Up @@ -566,7 +515,6 @@ public class ScriptHomeObject
readonly Action RequestShowSampleFilesInFolder;
readonly Action RequestShowBackupFilesInFolder;
readonly Action RequestShowTemplate;
readonly Action<string> RequestSaveSettings;

public ScriptHomeObject(Action<string> requestOpenFile,
Action requestNewWorkspace,
Expand All @@ -576,8 +524,7 @@ public ScriptHomeObject(Action<string> requestOpenFile,
Action<string> requestShowGuidedTour,
Action requestShowSampleFilesInFolder,
Action requestShowBackupFilesInFolder,
Action requestShowTemplate,
Action<string> requestSaveSettings)
Action requestShowTemplate)
{
RequestOpenFile = requestOpenFile;
RequestNewWorkspace = requestNewWorkspace;
Expand All @@ -588,7 +535,7 @@ public ScriptHomeObject(Action<string> requestOpenFile,
RequestShowSampleFilesInFolder = requestShowSampleFilesInFolder;
RequestShowBackupFilesInFolder = requestShowBackupFilesInFolder;
RequestShowTemplate = requestShowTemplate;
RequestSaveSettings = requestSaveSettings;

}
[DynamoJSInvokable]
public void OpenFile(string path)
Expand Down Expand Up @@ -636,11 +583,7 @@ public void ApplicationLoaded()
{
RequestApplicationLoaded();
}
[DynamoJSInvokable]
public void SaveSettings(string settings)
{
RequestSaveSettings(settings);
}

}

public enum GuidedTourType
Expand Down
22 changes: 0 additions & 22 deletions test/DynamoCoreTests/Configuration/PreferenceSettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -479,27 +479,5 @@ public void TestSanitizeValues()

Assert.IsTrue(allTheGroupStylesHaveAValidFontSize, $"All the GroupStyles have a valid Font size : {allTheGroupStylesHaveAValidFontSize}");
}

[Test]
[Category("UnitTests")]
public void TestSerializingHomePageSettings()
{
string tempPath = System.IO.Path.GetTempPath();
tempPath = Path.Combine(tempPath, "homePagePreference.xml");

PreferenceSettings settings = new PreferenceSettings();

// Assert defaults
Assert.AreEqual(settings.HomePageSettings, null);
Assert.AreEqual(settings.HomePageSettingsSerialized, "null");

settings.HomePageSettings = new Dictionary<string, object> { { "greeting", "Hello World" } };

// Save
settings.Save(tempPath);
settings = PreferenceSettings.Load(tempPath);

Assert.AreEqual(settings.HomePageSettings["greeting"], "Hello World");
}
}
}
30 changes: 0 additions & 30 deletions test/DynamoCoreWpfTests/HomePageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,36 +53,6 @@ public void ActionDelegates_ShouldBeProperlySetAfterConstruction()
Assert.IsNotNull(homePage.RequestShowBackupFilesInFolder);
Assert.IsNotNull(homePage.RequestShowTemplate);
}

[Test]
public void HomePage_NewSettingsAreAddedCorrectly()
{
// Arrange
var vm = View.DataContext as DynamoViewModel;
var startPage = new StartPageViewModel(vm, true);
var preferences = startPage.DynamoViewModel.PreferenceSettings;
var homePage = new HomePage();

homePage.DataContext = startPage;

Assert.IsNull(preferences.HomePageSettings);

// Act
var pair1 = @"{""Name"": ""Alice""}";
homePage.SaveSettings(pair1);

// Assert
Assert.IsNotNull(preferences.HomePageSettings);
Assert.AreEqual(preferences.HomePageSettings.Count, 1);

// Act
var pair2 = @"{""Number"": 12 }";
homePage.SaveSettings(pair2);

// Assert
Assert.AreEqual(preferences.HomePageSettings.Count, 2);
}

#endregion

#region integration tests
Expand Down

0 comments on commit b72cb2f

Please sign in to comment.