Skip to content

Commit

Permalink
DYN-4964-WorkingRange-Popup CodeReview 2
Browse files Browse the repository at this point in the history
Add functionality for when a custom node is created the Workspace Scale Factor is set.
Updating and removing some comments and also I started to add the unit test.
  • Loading branch information
RobertGlobant20 committed Jan 23, 2023
1 parent 8f5ba85 commit c209794
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
23 changes: 15 additions & 8 deletions src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2211,6 +2211,8 @@ private void ShowNewFunctionDialogAndMakeFunction(object parameter)
this.ExecuteCommand(new DynamoModel.CreateCustomNodeCommand(Guid.NewGuid(),
args.Name, args.Category, args.Description, true));
this.ShowStartPage = false;

SetDefaultScaleFactor();
}
}

Expand Down Expand Up @@ -2524,13 +2526,7 @@ public void MakeNewHomeWorkspace(object parameter)

ShowStartPage = false; // Hide start page if there's one.

var defaultWorkspace = Workspaces.FirstOrDefault();

if (defaultWorkspace != null)
{
defaultWorkspace.GeoScalingViewModel.ScaleValue = PreferenceSettings.DefaultScaleFactor;
defaultWorkspace.GeoScalingViewModel.UpdateGeometryScale(PreferenceSettings.DefaultScaleFactor);
}
SetDefaultScaleFactor();
}
}

Expand Down Expand Up @@ -2576,7 +2572,7 @@ internal bool ClearHomeWorkspaceInternal()
model.ClearCurrentWorkspace();

var defaultWorkspace = Workspaces.FirstOrDefault();
//Every time that a new workspace is created we have to assign the Defautl Geometry Scaling value defined in Preferences (comming from DynamoSettings.xml)
//Every time that a new workspace is created we have to assign the Default Geometry Scaling value defined in Preferences
if (defaultWorkspace !=null && defaultWorkspace.GeoScalingViewModel != null && preferencesViewModel != null)
defaultWorkspace.GeoScalingViewModel.ScaleSize = preferencesViewModel.DefaultGeometryScaling;

Expand Down Expand Up @@ -3180,6 +3176,17 @@ private bool CanSetNumberFormat(object parameter)
return true;
}

private void SetDefaultScaleFactor()
{
var defaultWorkspace = Workspaces.FirstOrDefault();

if (defaultWorkspace != null)
{
defaultWorkspace.GeoScalingViewModel.ScaleValue = PreferenceSettings.DefaultScaleFactor;
defaultWorkspace.GeoScalingViewModel.UpdateGeometryScale(PreferenceSettings.DefaultScaleFactor);
}
}

#region Shutdown related methods

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion src/DynamoCoreWpf/Views/Core/GeometryScalingPopup.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ private void Geometry_Scaling_Checked(object sender, System.Windows.RoutedEventA
{
var selectedButton = sender as Button;
if (selectedButton == null) return;
//var buttons = BaseGrid.Children.OfType<Button>();
var buttons = GeometryScalingRadiosPanel.Children.OfType<Button>();

int index = 0;
Expand Down
7 changes: 4 additions & 3 deletions src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,10 +1054,11 @@ private void OnContextMenuOpened(object sender, EventArgs e)
private void OnGeometryScaling_Click(object sender, RoutedEventArgs e)
{
if (GeoScalingPopup == null)
{
GeoScalingPopup = new GeometryScalingPopup(ViewModel.DynamoViewModel);

GeoScalingPopup.Placement = PlacementMode.Bottom;
GeoScalingPopup.PlacementTarget = geometryScalingButton;
GeoScalingPopup.Placement = PlacementMode.Bottom;
GeoScalingPopup.PlacementTarget = geometryScalingButton;
}
GeoScalingPopup.IsOpen = true;
}
}
Expand Down
27 changes: 26 additions & 1 deletion test/DynamoCoreWpfTests/PreferencesGeometryScalingTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Collections.Generic;
using System.Windows;
Expand All @@ -7,6 +7,8 @@
using Dynamo.Wpf.Views;
using DynamoCoreWpfTests.Utility;
using NUnit.Framework;
using Dynamo.Configuration;
using Dynamo.ViewModels;

namespace DynamoCoreWpfTests
{
Expand Down Expand Up @@ -90,5 +92,28 @@ public void PreferencesGeoScaling_RunGraph_Manual_Mode()
//When RunType = Manual and the MarkNodesAsModifiedAndRequestRun() method is called, the graph won't be executed and the node state will remain in Active
Assert.AreEqual(nodeView.ViewModel.State, ElementState.Active);
}

[Test]
public void PreferencesGeoScaling_Serializing()
{
int scaleFactor;
double defaultScaleFactor;

var settings = new PreferenceSettings();

var settingFilePath = Path.Combine(TempFolder, "DynamoSettings.xml");

var settingsLoadedFromFile = PreferenceSettings.Load(settingFilePath);

//The GeometryScalingCodeBlock.dyn contains a CodeBlock with a large number that needs ScaleFactor > Medium
Open(@"core\GeometryScalingCodeBlock.dyn");

var dynViewModel = View.DataContext as DynamoViewModel;
scaleFactor = dynViewModel.ScaleFactorLog;
defaultScaleFactor = dynViewModel.PreferenceSettings.DefaultScaleFactor;

}


}
}

0 comments on commit c209794

Please sign in to comment.