Skip to content

Commit

Permalink
Dyn 5396 group style bidirectional change (#13518)
Browse files Browse the repository at this point in the history
* Update Styling from preferences

* Naming Refactoring

* Rename Refactoring 2
  • Loading branch information
jesusalvino authored Nov 15, 2022
1 parent 124feaa commit bee67f2
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 19 deletions.
9 changes: 5 additions & 4 deletions src/DynamoCore/Configuration/GroupStyleItem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.ObjectModel;
using Dynamo.Properties;

Expand All @@ -14,10 +15,10 @@ public class GroupStyleItem: StyleItem
/// </summary>
public static ObservableCollection<GroupStyleItem> DefaultGroupStyleItems =
new ObservableCollection<GroupStyleItem>() {
new GroupStyleItem() { Name = Resources.GroupStyleDefaultActions, HexColorString = Resources.GroupStyleDefaultActionsColor, FontSize = 36, IsDefault = true },
new GroupStyleItem() { Name = Resources.GroupStyleDefaultInputs, HexColorString = Resources.GroupStyleDefaultInputsColor, FontSize = 36, IsDefault = true },
new GroupStyleItem() { Name = Resources.GroupStyleDefaultOutputs, HexColorString = Resources.GroupStyleDefaultOutputsColor, FontSize = 36, IsDefault = true },
new GroupStyleItem() { Name = Resources.GroupStyleDefaultReview, HexColorString = Resources.GroupStyleDefaultReviewColor, FontSize = 36 ,IsDefault = true }
new GroupStyleItem() { Name = Resources.GroupStyleDefaultActions, HexColorString = Resources.GroupStyleDefaultActionsColor, FontSize = 36, IsDefault = true, GroupStyleId = new Guid("4d68be4a-a04d-4945-9dd5-cdf61079d790") },
new GroupStyleItem() { Name = Resources.GroupStyleDefaultInputs, HexColorString = Resources.GroupStyleDefaultInputsColor, FontSize = 36, IsDefault = true, GroupStyleId = new Guid("883066aa-1fe2-44a4-9bd1-c3df86bfe9f6") },
new GroupStyleItem() { Name = Resources.GroupStyleDefaultOutputs, HexColorString = Resources.GroupStyleDefaultOutputsColor, FontSize = 36, IsDefault = true, GroupStyleId = new Guid("07655dc1-2d65-4fed-8d6a-37235d3e3a8d") },
new GroupStyleItem() { Name = Resources.GroupStyleDefaultReview, HexColorString = Resources.GroupStyleDefaultReviewColor, FontSize = 36 ,IsDefault = true, GroupStyleId = new Guid("bc688959-ce34-4bf5-90f8-6ddd23f80989") }
};
}
}
15 changes: 15 additions & 0 deletions src/DynamoCore/Configuration/StyleItem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dynamo.Core;
using System;

namespace Dynamo.Configuration
{
Expand All @@ -11,6 +12,7 @@ public class StyleItem : NotificationObject
private string name;
private bool isDefault = false;
private int fontSize = 36;
private Guid groupStyleId;

/// This property will contain the Group Name of the stored style
public string Name
Expand Down Expand Up @@ -59,5 +61,18 @@ public int FontSize
RaisePropertyChanged(nameof(FontSize));
}
}

/// <summary>
/// This property will support the id of the Groupstyle
/// </summary>
public Guid GroupStyleId
{
get { return groupStyleId; }
set
{
groupStyleId = value;
RaisePropertyChanged(nameof(GroupStyleId));
}
}
}
}
39 changes: 31 additions & 8 deletions src/DynamoCore/Graph/Annotations/AnnotationModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
Expand Down Expand Up @@ -286,7 +286,24 @@ public double FontSize
set
{
fontSize = value;
RaisePropertyChanged("FontSize");
RaisePropertyChanged(nameof(FontSize));
}
}

private Guid groupStyleId;
/// <summary>
/// Returns the Groupstyle applied
/// </summary>
public Guid GroupStyleId
{
get
{
return groupStyleId;
}
set
{
groupStyleId = value;
RaisePropertyChanged(nameof(GroupStyleId));
}
}

Expand Down Expand Up @@ -605,10 +622,13 @@ protected override bool UpdateValueCore(UpdateValueParams updateValueParams)

switch (name)
{
case "FontSize":
case nameof(FontSize):
FontSize = Convert.ToDouble(value);
break;
case "Background":
case nameof(GroupStyleId):
GroupStyleId = new Guid(value);
break;
case nameof(Background):
Background = value;
break;
case "TextBlockText":
Expand All @@ -634,6 +654,7 @@ void SerializeCore(XmlElement element, SaveContext context)
helper.SetAttribute("width", this.Width);
helper.SetAttribute("height", this.Height);
helper.SetAttribute("fontSize", this.FontSize);
helper.SetAttribute("groupStyleId", this.GroupStyleId);
helper.SetAttribute("InitialTop", this.InitialTop);
helper.SetAttribute("InitialHeight", this.InitialHeight);
helper.SetAttribute("TextblockHeight", this.TextBlockHeight);
Expand Down Expand Up @@ -666,6 +687,7 @@ protected override void DeserializeCore(XmlElement element, SaveContext context)
this.height = helper.ReadDouble("height", DoubleValue);
this.background = helper.ReadString("backgrouund", "");
this.fontSize = helper.ReadDouble("fontSize", fontSize);
this.groupStyleId = helper.ReadGuid("groupStyleId", GroupStyleId);
this.textBlockHeight = helper.ReadDouble("TextblockHeight", DoubleValue);
this.InitialTop = helper.ReadDouble("InitialTop", DoubleValue);
this.InitialHeight = helper.ReadDouble("InitialHeight", DoubleValue);
Expand Down Expand Up @@ -709,10 +731,11 @@ protected override void DeserializeCore(XmlElement element, SaveContext context)

//On any Undo Operation, current values are restored to previous values.
//These properties should be Raised, so that they get the correct value on Undo.
RaisePropertyChanged("Background");
RaisePropertyChanged("FontSize");
RaisePropertyChanged("AnnotationText");
RaisePropertyChanged("Nodes");
RaisePropertyChanged(nameof(Background));
RaisePropertyChanged(nameof(FontSize));
RaisePropertyChanged(nameof(GroupStyleId));
RaisePropertyChanged(nameof(AnnotationText));
RaisePropertyChanged(nameof(Nodes));
this.ReportPosition();
}

Expand Down
3 changes: 3 additions & 0 deletions src/DynamoCore/Graph/Workspaces/WorkspaceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public class ExtraAnnotationViewInfo
public IEnumerable<string> Nodes;
public bool HasNestedGroups;
public double FontSize;
public Guid GroupStyleId;
public string Background;
public string Id;
public string PinnedNode;
Expand Down Expand Up @@ -139,6 +140,7 @@ public override bool Equals(object obj)
this.Nodes.SequenceEqual(other.Nodes) &&
this.HasNestedGroups == other.HasNestedGroups &&
this.FontSize == other.FontSize &&
this.GroupStyleId == other.GroupStyleId &&
this.Background == other.Background &&
this.WidthAdjustment == other.WidthAdjustment &&
this.HeightAdjustment == other.HeightAdjustment;
Expand Down Expand Up @@ -2667,6 +2669,7 @@ private void LoadAnnotation(ExtraAnnotationViewInfo annotationViewInfo)
annotationModel.AnnotationDescriptionText = annotationViewInfo.DescriptionText;
annotationModel.IsExpanded = annotationViewInfo.IsExpanded;
annotationModel.FontSize = annotationViewInfo.FontSize;
annotationModel.GroupStyleId = annotationViewInfo.GroupStyleId;
annotationModel.Background = annotationViewInfo.Background;
annotationModel.GUID = annotationGuidValue;
annotationModel.HeightAdjustment = annotationViewInfo.HeightAdjustment;
Expand Down
1 change: 1 addition & 0 deletions src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3005,6 +3005,7 @@ private AnnotationModel CreateAnnotationModel(
WidthAdjustment = model.WidthAdjustment,
Background = model.Background,
FontSize = model.FontSize,
GroupStyleId = model.GroupStyleId,
};

modelLookup.Add(model.GUID, annotationModel);
Expand Down
17 changes: 17 additions & 0 deletions src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,22 @@ public Double FontSize
}
}

/// <summary>
/// Id of the applied GroupStyle
/// </summary>
[JsonIgnore]
public Guid GroupStyleId
{
get
{
return annotationModel.GroupStyleId;
}
set
{
annotationModel.GroupStyleId = value;
}
}

[JsonIgnore]
public IEnumerable<ModelBase> Nodes
{
Expand Down Expand Up @@ -1064,6 +1080,7 @@ internal void UpdateGroupStyle(GroupStyleItem itemEntryParameter)

Background = (Color)ColorConverter.ConvertFromString("#" + itemEntryParameter.HexColorString);
FontSize = (double)itemEntryParameter.FontSize;
GroupStyleId = itemEntryParameter.GroupStyleId;

WorkspaceViewModel.HasUnsavedChanges = true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using Dynamo.Graph;
using Dynamo.Graph.Annotations;
Expand Down Expand Up @@ -146,6 +146,8 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
writer.WriteValue(anno.Height);
writer.WritePropertyName("FontSize");
writer.WriteValue(anno.FontSize);
writer.WritePropertyName("GroupStyleId");
writer.WriteValue(anno.GroupStyleId);
writer.WritePropertyName("InitialTop");
writer.WriteValue(anno.InitialTop);
writer.WritePropertyName("InitialHeight");
Expand Down
30 changes: 30 additions & 0 deletions src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Reflection;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Media;
using System.Windows.Threading;
using Dynamo.Configuration;
using Dynamo.Engine;
Expand Down Expand Up @@ -3050,6 +3051,35 @@ public void Escape(object parameter)
BackgroundPreviewViewModel.RefreshState();
}

/// <summary>
/// Checking if a custom Group style has been updated, if so it will update the styling of the existing groups
/// </summary>
/// <param name="originalCustomGroupStyles"></param>
public void CheckCustomGroupStylesChanges(List<GroupStyleItem> originalCustomGroupStyles)
{
foreach (var originalCustomGroupStyle in originalCustomGroupStyles)
{
var currentCustomGroupStyle = PreferenceSettings.GroupStyleItemsList.Where(
groupStyle => !groupStyle.GroupStyleId.Equals(Guid.Empty) && groupStyle.GroupStyleId.Equals(originalCustomGroupStyle.GroupStyleId)).FirstOrDefault();

if (currentCustomGroupStyle != null)
{
if (!originalCustomGroupStyle.HexColorString.Equals(currentCustomGroupStyle.HexColorString)
|| !originalCustomGroupStyle.FontSize.Equals(currentCustomGroupStyle.FontSize))
{
foreach (var annotation in CurrentSpaceViewModel.Annotations)
{
if (annotation.GroupStyleId.Equals(currentCustomGroupStyle.GroupStyleId))
{
annotation.FontSize = currentCustomGroupStyle.FontSize;
annotation.Background = (Color)ColorConverter.ConvertFromString("#" + currentCustomGroupStyle.HexColorString);
}
}
}
}
}
}

internal bool CanEscape(object parameter)
{
return true;
Expand Down
1 change: 1 addition & 0 deletions src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ public void AddStyle(StyleItem style)
HexColorString = style.HexColorString,
Name = style.Name,
FontSize = style.FontSize,
GroupStyleId = style.GroupStyleId,
IsDefault = style.IsDefault
});
RaisePropertyChanged(nameof(StyleItemsList));
Expand Down
28 changes: 22 additions & 6 deletions src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,35 @@ public partial class PreferencesView : Window
private readonly PreferencesViewModel viewModel;
private readonly DynamoViewModel dynViewModel;
private int scaleValue = 0;
private List<GroupStyleItem> originalCustomGroupStyles { get; set; }

// Used for tracking the manage package command event
// This is not a command any more but we keep it
// around in a compatible way for now
private IDisposable managePackageCommandEvent;

/// <summary>
/// Storing the original custom styles before the user could update them
/// </summary>
private void StoreOriginalCustomGroupStyles()
{
originalCustomGroupStyles = new List<GroupStyleItem>();
foreach (var groupStyle in dynViewModel.PreferenceSettings.GroupStyleItemsList)
{
if (!groupStyle.IsDefault)
{
originalCustomGroupStyles.Add(new GroupStyleItem() { GroupStyleId = groupStyle.GroupStyleId, HexColorString = groupStyle.HexColorString, FontSize = groupStyle.FontSize });
}
}
}

/// <summary>
/// Constructor of Preferences View
/// </summary>
/// <param name="dynamoViewModel"> Dynamo ViewModel</param>
public PreferencesView(DynamoView dynamoView)
{
dynViewModel = dynamoView.DataContext as DynamoViewModel;

{
dynViewModel = dynamoView.DataContext as DynamoViewModel;
SetupPreferencesViewModel(dynViewModel);

DataContext = dynViewModel.PreferencesViewModel;
Expand All @@ -63,6 +78,7 @@ public PreferencesView(DynamoView dynamoView)
//We need to store the ScaleFactor value in a temporary variable always when the Preferences dialog is created.
scaleValue = dynViewModel.ScaleFactorLog;
ResetGroupStyleForm();
StoreOriginalCustomGroupStyles();

viewModel.RequestShowFileDialog += OnRequestShowFileDialog;
}
Expand Down Expand Up @@ -139,6 +155,7 @@ private void CloseButton_Click(object sender, RoutedEventArgs e)
RunGraphWhenScaleFactorUpdated();

dynViewModel.PreferencesViewModel.TrustedPathsViewModel.PropertyChanged -= TrustedPathsViewModel_PropertyChanged;
dynViewModel.CheckCustomGroupStylesChanges(originalCustomGroupStyles);

Close();
}
Expand Down Expand Up @@ -213,12 +230,11 @@ private void AddStyle_SaveButton_Click(object sender, RoutedEventArgs e)
var grid = (saveChangesButton.Parent as Grid).Parent as Grid;

var groupNameLabel = grid.FindName("groupNameBox") as TextBox;

var colorHexString = grid.FindName("colorHexVal") as Label;

var groupStyleFontSize = grid.FindName("groupStyleFontSize") as ComboBox;
var groupStyleId = Guid.NewGuid();

var newItem = new StyleItem() { Name = groupNameLabel.Text, HexColorString = colorHexString.Content.ToString(), FontSize = Convert.ToInt32(groupStyleFontSize.SelectedValue) };
var newItem = new StyleItem() { Name = groupNameLabel.Text, HexColorString = colorHexString.Content.ToString(), FontSize = Convert.ToInt32(groupStyleFontSize.SelectedValue), GroupStyleId = groupStyleId };

if (string.IsNullOrEmpty(newItem.Name))
newItem.Name = "Input";
Expand Down

0 comments on commit bee67f2

Please sign in to comment.