diff --git a/src/DynamoCore/Configuration/GroupStyleItem.cs b/src/DynamoCore/Configuration/GroupStyleItem.cs
index 3cd0098ceec..c179d8bfdb9 100644
--- a/src/DynamoCore/Configuration/GroupStyleItem.cs
+++ b/src/DynamoCore/Configuration/GroupStyleItem.cs
@@ -8,5 +8,19 @@ namespace Dynamo.Configuration
{
public class GroupStyleItem: StyleItem
{
+ private bool isChecked = false;
+
+ ///
+ /// This property will say it we should display the checkmark in the MenuItem (appearing in the GroupStyles context menu)
+ ///
+ public bool IsChecked
+ {
+ get { return isChecked; }
+ set
+ {
+ isChecked = value;
+ RaisePropertyChanged(nameof(IsChecked));
+ }
+ }
}
}
diff --git a/src/DynamoCore/Configuration/GroupStyleSeparator.cs b/src/DynamoCore/Configuration/GroupStyleSeparator.cs
new file mode 100644
index 00000000000..17dc2c0455b
--- /dev/null
+++ b/src/DynamoCore/Configuration/GroupStyleSeparator.cs
@@ -0,0 +1,11 @@
+using Dynamo.Configuration;
+
+namespace Dynamo.Graph.Annotations
+{
+ ///
+ /// This class will represent a separator item that once inserted in the list the Style selector will take the MenuItem separator style
+ ///
+ internal class GroupStyleSeparator : StyleItem
+ {
+ }
+}
diff --git a/src/DynamoCore/Configuration/PreferenceSettings.cs b/src/DynamoCore/Configuration/PreferenceSettings.cs
index b55507218d9..c7e30310f5b 100644
--- a/src/DynamoCore/Configuration/PreferenceSettings.cs
+++ b/src/DynamoCore/Configuration/PreferenceSettings.cs
@@ -7,6 +7,7 @@
using Dynamo.Graph.Connectors;
using Dynamo.Interfaces;
using Dynamo.Models;
+using Dynamo.Properties;
namespace Dynamo.Configuration
{
@@ -533,6 +534,9 @@ public PreferenceSettings()
DefaultPythonEngine = string.Empty;
ViewExtensionSettings = new List();
GroupStyleItemsList = new List();
+
+ //Add the default group styles
+ AddDefaultStyles();
}
///
@@ -606,11 +610,27 @@ public static PreferenceSettings Load(string filePath)
}
catch (Exception) { }
settings.CustomPackageFolders = settings.CustomPackageFolders.Distinct().ToList();
+ settings.GroupStyleItemsList = settings.GroupStyleItemsList.GroupBy(entry => entry.Name).Select(result => result.First()).ToList();
MigrateStdLibTokenToBuiltInToken(settings);
-
return settings;
}
+ ///
+ /// This method will add the Defaul GroupStyles that are shown in the Preferences panel
+ ///
+ public void AddDefaultStyles()
+ {
+ var defaultGroupStylesList = GroupStyleItemsList.Where(style => style.IsDefault == true);
+ //Just in case the Default profiles have not been added then are added.
+ if (defaultGroupStylesList != null && defaultGroupStylesList.Count() == 0)
+ {
+ GroupStyleItemsList.Add(new GroupStyleItem() { Name = Resources.GroupStyleDefaultActions, HexColorString = Resources.GroupStyleDefaultActionsColor, IsDefault = true });
+ GroupStyleItemsList.Add(new GroupStyleItem() { Name = Resources.GroupStyleDefaultInputs, HexColorString = Resources.GroupStyleDefaultInputsColor, IsDefault = true });
+ GroupStyleItemsList.Add(new GroupStyleItem() { Name = Resources.GroupStyleDefaultOutputs, HexColorString = Resources.GroupStyleDefaultOutputsColor, IsDefault = true });
+ GroupStyleItemsList.Add(new GroupStyleItem() { Name = Resources.GroupStyleDefaultReview, HexColorString = Resources.GroupStyleDefaultReviewColor, IsDefault = true });
+ }
+ }
+
///
/// Returns the static Python template file path.
/// When the file exists and is not empty, its contents are used to populate new Python Script nodes added to the Dynamo workspace.
diff --git a/src/DynamoCore/Configuration/StyleItem.cs b/src/DynamoCore/Configuration/StyleItem.cs
index 6ab78c3cd13..0dd681d03f1 100644
--- a/src/DynamoCore/Configuration/StyleItem.cs
+++ b/src/DynamoCore/Configuration/StyleItem.cs
@@ -1,19 +1,49 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using Dynamo.Core;
namespace Dynamo.Configuration
{
///
/// This class stores the group styles added by the user
///
- public class StyleItem
+ public class StyleItem : NotificationObject
{
+ private string hexColorString;
+ private string name;
+ private bool isDefault = false;
+
/// This property will contain the Group Name of the stored style
- public string Name { get; set; }
+ public string Name
+ {
+ get { return name; }
+ set
+ {
+ name = value;
+ RaisePropertyChanged(nameof(Name));
+ }
+ }
+
/// This property will contain the color in hexadecimal
- public string HexColorString { get; set; }
+ public string HexColorString
+ {
+ get { return hexColorString; }
+ set
+ {
+ hexColorString = value;
+ RaisePropertyChanged(nameof(HexColorString));
+ }
+ }
+
+ ///
+ /// This property will describe if the current GroupStyle added is a default one or a custom one.
+ ///
+ public bool IsDefault
+ {
+ get { return isDefault; }
+ set
+ {
+ isDefault = value;
+ RaisePropertyChanged(nameof(IsDefault));
+ }
+ }
}
}
diff --git a/src/DynamoCore/Models/DynamoModel.cs b/src/DynamoCore/Models/DynamoModel.cs
index 0d42a195ede..b3be53d1492 100644
--- a/src/DynamoCore/Models/DynamoModel.cs
+++ b/src/DynamoCore/Models/DynamoModel.cs
@@ -601,7 +601,7 @@ protected DynamoModel(IStartConfiguration config)
if (preferences is PreferenceSettings settings)
{
PreferenceSettings = settings;
- PreferenceSettings.PropertyChanged += PreferenceSettings_PropertyChanged;
+ PreferenceSettings.PropertyChanged += PreferenceSettings_PropertyChanged;
}
if (config is DefaultStartConfiguration defaultStartConfiguration)
diff --git a/src/DynamoCore/Properties/Resources.Designer.cs b/src/DynamoCore/Properties/Resources.Designer.cs
index 538c1afc52a..e84aca21d97 100644
--- a/src/DynamoCore/Properties/Resources.Designer.cs
+++ b/src/DynamoCore/Properties/Resources.Designer.cs
@@ -740,6 +740,78 @@ public static string GroupNameDefaultText {
}
}
+ ///
+ /// Looks up a localized string similar to Actions.
+ ///
+ public static string GroupStyleDefaultActions {
+ get {
+ return ResourceManager.GetString("GroupStyleDefaultActions", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to B9F9E1.
+ ///
+ public static string GroupStyleDefaultActionsColor {
+ get {
+ return ResourceManager.GetString("GroupStyleDefaultActionsColor", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Inputs.
+ ///
+ public static string GroupStyleDefaultInputs {
+ get {
+ return ResourceManager.GetString("GroupStyleDefaultInputs", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to FFB8D8.
+ ///
+ public static string GroupStyleDefaultInputsColor {
+ get {
+ return ResourceManager.GetString("GroupStyleDefaultInputsColor", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Outputs.
+ ///
+ public static string GroupStyleDefaultOutputs {
+ get {
+ return ResourceManager.GetString("GroupStyleDefaultOutputs", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to FFC999.
+ ///
+ public static string GroupStyleDefaultOutputsColor {
+ get {
+ return ResourceManager.GetString("GroupStyleDefaultOutputsColor", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Review.
+ ///
+ public static string GroupStyleDefaultReview {
+ get {
+ return ResourceManager.GetString("GroupStyleDefaultReview", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to A4E1FF.
+ ///
+ public static string GroupStyleDefaultReviewColor {
+ get {
+ return ResourceManager.GetString("GroupStyleDefaultReviewColor", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to ACTIONS.
///
diff --git a/src/DynamoCore/Properties/Resources.en-US.resx b/src/DynamoCore/Properties/Resources.en-US.resx
index d6762630d52..5722ef291ae 100644
--- a/src/DynamoCore/Properties/Resources.en-US.resx
+++ b/src/DynamoCore/Properties/Resources.en-US.resx
@@ -831,4 +831,28 @@ This package likely contains an assembly that is blocked. You will need to load
Library load failure
+
+ Actions
+
+
+ B9F9E1
+
+
+ Inputs
+
+
+ FFB8D8
+
+
+ Outputs
+
+
+ FFC999
+
+
+ Review
+
+
+ A4E1FF
+
\ No newline at end of file
diff --git a/src/DynamoCore/Properties/Resources.resx b/src/DynamoCore/Properties/Resources.resx
index 267464080a2..2635648b02d 100644
--- a/src/DynamoCore/Properties/Resources.resx
+++ b/src/DynamoCore/Properties/Resources.resx
@@ -834,4 +834,28 @@ This package likely contains an assembly that is blocked. You will need to load
Library load failure
+
+ Actions
+
+
+ B9F9E1
+
+
+ Inputs
+
+
+ FFB8D8
+
+
+ Outputs
+
+
+ FFC999
+
+
+ Review
+
+
+ A4E1FF
+
\ No newline at end of file
diff --git a/src/DynamoCoreWpf/DynamoCoreWpf.csproj b/src/DynamoCoreWpf/DynamoCoreWpf.csproj
index d6737b10043..95e1266815d 100644
--- a/src/DynamoCoreWpf/DynamoCoreWpf.csproj
+++ b/src/DynamoCoreWpf/DynamoCoreWpf.csproj
@@ -165,6 +165,7 @@
+
diff --git a/src/DynamoCoreWpf/Properties/Resources.Designer.cs b/src/DynamoCoreWpf/Properties/Resources.Designer.cs
index f751b755346..5d28b140d34 100644
--- a/src/DynamoCoreWpf/Properties/Resources.Designer.cs
+++ b/src/DynamoCoreWpf/Properties/Resources.Designer.cs
@@ -2992,6 +2992,15 @@ public static string GroupNameDefaultText {
}
}
+ ///
+ /// Looks up a localized string similar to Group Style.
+ ///
+ public static string GroupStyleContextAnnotation {
+ get {
+ return ResourceManager.GetString("GroupStyleContextAnnotation", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Hide Classic Node Library.
///
diff --git a/src/DynamoCoreWpf/Properties/Resources.en-US.resx b/src/DynamoCoreWpf/Properties/Resources.en-US.resx
index bf326f0d68a..4c371d0d28c 100644
--- a/src/DynamoCoreWpf/Properties/Resources.en-US.resx
+++ b/src/DynamoCoreWpf/Properties/Resources.en-US.resx
@@ -3040,4 +3040,7 @@ To install the latest version of a package, click Install. \n
Group Name
+
+ Group Style
+
\ No newline at end of file
diff --git a/src/DynamoCoreWpf/Properties/Resources.resx b/src/DynamoCoreWpf/Properties/Resources.resx
index d21e2a6942d..da4b8fe7338 100644
--- a/src/DynamoCoreWpf/Properties/Resources.resx
+++ b/src/DynamoCoreWpf/Properties/Resources.resx
@@ -3027,4 +3027,7 @@ To install the latest version of a package, click Install. \n
Group Name
+
+ Group Style
+
\ No newline at end of file
diff --git a/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml b/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml
index e9d732c9eb0..8b44842179f 100644
--- a/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml
+++ b/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml
@@ -4219,4 +4219,101 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/DynamoCoreWpf/Utilities/GroupStyleItemSelector.cs b/src/DynamoCoreWpf/Utilities/GroupStyleItemSelector.cs
new file mode 100644
index 00000000000..584df0c0505
--- /dev/null
+++ b/src/DynamoCoreWpf/Utilities/GroupStyleItemSelector.cs
@@ -0,0 +1,26 @@
+using System.Windows;
+using System.Windows.Controls;
+using Dynamo.Configuration;
+using Dynamo.Graph.Annotations;
+
+namespace Dynamo.Wpf.Utilities
+{
+ ///
+ /// This class will be used for select a specific Style depending if the list item is a Separator or MenuItem
+ ///
+ public class GroupStyleItemSelector : StyleSelector
+ {
+ public override Style SelectStyle(object item, DependencyObject container)
+ {
+ if (item is GroupStyleSeparator)
+ {
+ return (Style)((FrameworkElement)container).FindResource("GroupStyleSeparatorStyle");
+ }
+ if (item is GroupStyleItem)
+ {
+ return (Style)((FrameworkElement)container).FindResource("GroupStyleItemStyle");
+ }
+ return null;
+ }
+ }
+}
diff --git a/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs
index 7acaca67486..702c04866ec 100644
--- a/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs
+++ b/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs
@@ -5,6 +5,7 @@
using System.Linq;
using System.Windows.Input;
using System.Windows.Media;
+using Dynamo.Configuration;
using Dynamo.Graph;
using Dynamo.Graph.Annotations;
using Dynamo.Graph.Nodes;
@@ -27,7 +28,10 @@ public class AnnotationViewModel : ViewModelBase
// vertical offset accounts for the port margins
private const int verticalOffset = 20;
private const int portVerticalMidPoint = 17;
-
+ private ObservableCollection groupStyleList;
+ private IEnumerable preferencesStyleItemsList;
+ private PreferenceSettings preferenceSettings;
+
public readonly WorkspaceViewModel WorkspaceViewModel;
#region Properties
@@ -170,6 +174,9 @@ public Double FontSize
}
}
+ [JsonIgnore]
+ internal GroupStyleItem CurrentGroupStyleSelected { get; set; }
+
[JsonIgnore]
public IEnumerable Nodes
{
@@ -330,6 +337,22 @@ public GeometryCollection NestedGroupsGeometryCollection
get => new GeometryCollection(GroupIdToCutGeometry.Values.Select(x => x));
}
+ ///
+ /// This property will be used to populate the GroupStyle context menu (the one shown when clicking right over a Group)
+ ///
+ [JsonIgnore]
+ public ObservableCollection GroupStyleList
+ {
+ get
+ {
+ return groupStyleList;
+ }
+ set
+ {
+ groupStyleList = value;
+ RaisePropertyChanged(nameof(GroupStyleList));
+ }
+ }
#endregion
#region Commands
@@ -507,6 +530,7 @@ public AnnotationViewModel(WorkspaceViewModel workspaceViewModel, AnnotationMode
{
annotationModel = model;
this.WorkspaceViewModel = workspaceViewModel;
+ this.preferenceSettings = WorkspaceViewModel.DynamoViewModel.PreferenceSettings;
model.PropertyChanged += model_PropertyChanged;
model.RemovedFromGroup += OnModelRemovedFromGroup;
model.AddedToGroup += OnModelAddedToGroup;
@@ -542,6 +566,9 @@ public AnnotationViewModel(WorkspaceViewModel workspaceViewModel, AnnotationMode
SetGroupOutPorts();
CollapseGroupContents(true);
}
+ groupStyleList = new ObservableCollection();
+ //This will add the GroupStyles created in Preferences panel to the Group Style Context menu.
+ LoadGroupStylesFromPreferences(preferenceSettings.GroupStyleItemsList);
}
///
@@ -943,6 +970,69 @@ private void UpdateFontSize(object parameter)
WorkspaceViewModel.DynamoViewModel.RaiseCanExecuteUndoRedo();
}
+ ///
+ /// This method will be called by the ChangeGroupStyleCommand when a GroupStyle is selected from the ContextMenu
+ ///
+ /// GroupStyle item selected
+ internal void UpdateGroupStyle(GroupStyleItem itemEntryParameter)
+ {
+ if (itemEntryParameter == null) return;
+
+ var groupStyleItems = GroupStyleList.OfType();
+ groupStyleItems.Where(c => !c.Name.Equals(itemEntryParameter.Name)).ToList().ForEach(cc =>
+ {
+ cc.IsChecked = false;
+ });
+
+ itemEntryParameter.IsChecked = true;
+ CurrentGroupStyleSelected = itemEntryParameter;
+ Background = (Color)ColorConverter.ConvertFromString("#"+itemEntryParameter.HexColorString);
+
+ WorkspaceViewModel.HasUnsavedChanges = true;
+ }
+
+ ///
+ /// This method loads the group styles defined by the user and stored in the xml file
+ ///
+ ///
+ ///
+ private void LoadGroupStylesFromPreferences(IEnumerable styleItemsList)
+ {
+ preferencesStyleItemsList = styleItemsList;
+
+ var defaultGroupStylesList = styleItemsList.Where(style => style.IsDefault == true);
+ var customGroupStylesList = styleItemsList.Where(style => style.IsDefault == false);
+
+ //Adds to the list the Default Group Styles created by Dynamo
+ groupStyleList.AddRange(defaultGroupStylesList);
+
+ //Adds the separator between the Default Group Styles and the Custom Group Styles
+ groupStyleList.Add(new GroupStyleSeparator());
+
+ //Adds to the list the Custom Group Styles created by the user
+ groupStyleList.AddRange(customGroupStylesList);
+ }
+
+ ///
+ /// This method will be executed when the MenuIte.SubmenuOpened event is executed
+ /// The purpose is adding to the GroupStyles ContextMenu the Styles added in the Preferences panel.
+ ///
+ internal void ReloadGroupStyles()
+ {
+ if (preferencesStyleItemsList == null) return;
+ var currentSelectedGroupStyle = groupStyleList.OfType().Where(style => style.IsChecked == true).FirstOrDefault();
+ groupStyleList.Clear();
+
+ LoadGroupStylesFromPreferences(preferencesStyleItemsList);
+ if (currentSelectedGroupStyle == null) return;
+
+ var currentCustomGroupStyles = groupStyleList.OfType();
+ var selectedGroupStyle = currentCustomGroupStyles.Where(style => style.Name.Equals(currentSelectedGroupStyle.Name)).FirstOrDefault();
+
+ if (selectedGroupStyle == null) return;
+ selectedGroupStyle.IsChecked = true;
+ }
+
///
/// Selects this group and models within it.
///
diff --git a/src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs b/src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs
index 13094fce7cb..089e00f8f10 100644
--- a/src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs
+++ b/src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs
@@ -424,10 +424,12 @@ public ObservableCollection StyleItemsList
public void AddStyle(StyleItem style)
{
StyleItemsList.Add(style);
- preferenceSettings.GroupStyleItemsList.Add(new GroupStyleItem { HexColorString = style.HexColorString, Name = style.GroupName });
+ preferenceSettings.GroupStyleItemsList.Add(new GroupStyleItem { HexColorString = style.HexColorString, Name = style.Name, IsDefault = style.IsDefault });
RaisePropertyChanged(nameof(StyleItemsList));
}
+
+
///
/// This flag will be in true when the Style that user is trying to add already exists (otherwise will be false - Default)
///
@@ -769,7 +771,7 @@ public PreferencesViewModel(DynamoViewModel dynamoViewModel)
StyleItemsList = LoadStyles(preferenceSettings.GroupStyleItemsList);
//When pressing the "Add Style" button some controls will be shown with some values by default so later they can be populated by the user
- AddStyleControl = new StyleItem() { GroupName = "", HexColorString = "#" + GetRandomHexStringColor() };
+ AddStyleControl = new StyleItem() { Name = string.Empty, HexColorString = GetRandomHexStringColor() };
//This piece of code will populate all the description text for the RadioButtons in the Geometry Scaling section.
optionsGeometryScale = new GeometryScalingOptions();
@@ -807,6 +809,7 @@ public PreferencesViewModel(DynamoViewModel dynamoViewModel)
WorkspaceEvents.WorkspaceSettingsChanged += PreferencesViewModel_WorkspaceSettingsChanged;
PropertyChanged += Model_PropertyChanged;
+
}
///
@@ -819,7 +822,7 @@ private ObservableCollection LoadStyles(IEnumerable styles = new ObservableCollection();
foreach (var style in styleItemsList)
{
- styles.Add(new StyleItem { GroupName = style.Name, HexColorString = style.HexColorString });
+ styles.Add(new StyleItem { Name = style.Name, HexColorString = style.HexColorString, IsDefault = style.IsDefault });
}
return styles;
}
@@ -1024,7 +1027,7 @@ internal void UpdateSavedChangesLabel()
///
internal void RemoveStyleEntry(string groupName)
{
- StyleItem itemToRemove = (from item in StyleItemsList where item.GroupName.Equals(groupName) select item).FirstOrDefault();
+ StyleItem itemToRemove = (from item in StyleItemsList where item.Name.Equals(groupName) select item).FirstOrDefault();
StyleItemsList.Remove(itemToRemove);
GroupStyleItem itemToRemovePreferences = preferenceSettings.GroupStyleItemsList.FirstOrDefault(x => x.Name.Equals(groupName));
@@ -1040,7 +1043,7 @@ internal void RemoveStyleEntry(string groupName)
///
internal bool ValidateExistingStyle(StyleItem item1)
{
- return StyleItemsList.Where(x => x.GroupName.Equals(item1.GroupName)).Any();
+ return StyleItemsList.Where(x => x.Name.Equals(item1.Name)).Any();
}
///
@@ -1048,8 +1051,8 @@ internal bool ValidateExistingStyle(StyleItem item1)
///
internal void ResetAddStyleControl()
{
- AddStyleControl.GroupName = String.Empty;
- AddStyleControl.HexColorString = "#" + GetRandomHexStringColor();
+ AddStyleControl.Name = String.Empty;
+ AddStyleControl.HexColorString = GetRandomHexStringColor();
IsWarningEnabled = false;
}
@@ -1073,41 +1076,6 @@ private void PythonEnginesChanged(object sender, NotifyCollectionChangedEventArg
}
}
- ///
- /// This Class will act as a container for each of the StyleItems in the Styles list located in in the Visual Settings -> Group Styles section
- ///
- public class StyleItem : ViewModelBase
- {
- private string groupName;
- private string hexColorString;
-
- ///
- /// This property will containt the Group Name thas was added by the user when creating a new Style
- ///
- public string GroupName
- {
- get { return groupName; }
- set
- {
- groupName = value;
- RaisePropertyChanged(nameof(GroupName));
- }
- }
-
- ///
- /// This property represents a color in a hexadecimal representation (with the # character at the beginning of the string)
- ///
- public string HexColorString
- {
- get { return hexColorString; }
- set
- {
- hexColorString = value;
- RaisePropertyChanged(nameof(HexColorString));
- }
- }
- }
-
///
/// This class will contain the Enum value and the corresponding description for each radio button in the Visual Settings -> Geometry Scaling section
///
diff --git a/src/DynamoCoreWpf/Views/Core/AnnotationView.xaml b/src/DynamoCoreWpf/Views/Core/AnnotationView.xaml
index ddf19368081..7f9794753b7 100644
--- a/src/DynamoCoreWpf/Views/Core/AnnotationView.xaml
+++ b/src/DynamoCoreWpf/Views/Core/AnnotationView.xaml
@@ -12,6 +12,7 @@
xmlns:dynui="clr-namespace:Dynamo.UI.Controls"
xmlns:fa="http://schemas.fontawesome.io/icons/"
xmlns:nodes="clr-namespace:Dynamo.Graph.Nodes;assembly=DynamoCore"
+ xmlns:utilities="clr-namespace:Dynamo.Wpf.Utilities"
mc:Ignorable="d"
Height="Auto"
Width="Auto"
@@ -25,6 +26,8 @@
d:DataContext="{d:DesignInstance Type=viewModels:AnnotationViewModel}">
+
+
@@ -262,6 +265,66 @@
+
+
+
+
+
+
-
+
@@ -288,6 +353,13 @@
+
+ ///
+ ///
+ private void GroupStyleCheckmark_Click(object sender, RoutedEventArgs e)
+ {
+ var menuItemSelected = sender as MenuItem;
+ if (menuItemSelected == null) return;
+
+ var groupStyleItemSelected = menuItemSelected.DataContext as GroupStyleItem;
+ if (groupStyleItemSelected == null) return;
+
+ //Means that no GroupStyle (Default, Custom) has been selected then the clicked one will be selected
+ if (ViewModel.CurrentGroupStyleSelected == null)
+ {
+ ViewModel.UpdateGroupStyle(groupStyleItemSelected);
+ return;
+ }
+
+ //Means that the user clicked over a MenuItem that is already selected, when we need uncheck it if is not a Default Style
+ if (groupStyleItemSelected != ViewModel.CurrentGroupStyleSelected && groupStyleItemSelected.IsChecked == false)
+ {
+ ViewModel.UpdateGroupStyle(groupStyleItemSelected);
+ return;
+ }
+
+ //Means that the GroupStyle selected is not a Default Style and is already checked
+ if (ViewModel.CurrentGroupStyleSelected.IsChecked == true && !groupStyleItemSelected.IsDefault)
+ {
+ var groupStyleItems = ViewModel.GroupStyleList.OfType();
+ var firstDefaultGroupStyle = groupStyleItems.Where(item => item.IsDefault == true).FirstOrDefault();
+ ViewModel.UpdateGroupStyle(firstDefaultGroupStyle);
+ return;
+ }
+ }
+
+ private void GroupStyleCheckmark_Checked(object sender, RoutedEventArgs e)
+ {
+ var menuItemSelected = sender as MenuItem;
+ if (menuItemSelected == null) return;
+
+ var groupStyleItemSelected = menuItemSelected.DataContext as GroupStyleItem;
+ if (groupStyleItemSelected == null) return;
+
+ ViewModel.CurrentGroupStyleSelected = groupStyleItemSelected;
+ }
+
+ ///
+ /// When the GroupStyle Submenu is opened then we need to re-load the GroupStyles in the ContextMenu (in case more Styles were added in Preferences panel).
+ ///
+ ///
+ ///
+ private void GroupStyleAnnotation_SubmenuOpened(object sender, RoutedEventArgs e)
+ {
+ ViewModel.ReloadGroupStyles();
+ }
}
}
diff --git a/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml b/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml
index fc31c0c5581..0b96fe7e9f1 100644
--- a/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml
+++ b/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml
@@ -55,7 +55,7 @@
diff --git a/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml.cs b/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml.cs
index 213e6a7d448..94bb1410f0c 100644
--- a/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml.cs
+++ b/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml.cs
@@ -1,15 +1,13 @@
using System;
-using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
-using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
+using Dynamo.Configuration;
using Dynamo.Controls;
using Dynamo.Logging;
-using Dynamo.Models;
using Dynamo.ViewModels;
using Res = Dynamo.Wpf.Properties.Resources;
@@ -173,10 +171,10 @@ private void AddStyle_SaveButton_Click(object sender, RoutedEventArgs e)
var colorHexString = grid.FindName("colorHexVal") as Label;
- var newItem = new StyleItem() { GroupName = groupNameLabel.Text, HexColorString = colorHexString.Content.ToString() };
+ var newItem = new StyleItem() { Name = groupNameLabel.Text, HexColorString = colorHexString.Content.ToString() };
- if (string.IsNullOrEmpty(newItem.GroupName))
- newItem.GroupName = "Input";
+ if (string.IsNullOrEmpty(newItem.Name))
+ newItem.Name = "Input";
//if the validation returns false it means that the new style that will be added doesn't exists
if (viewModel.ValidateExistingStyle(newItem) == false)
diff --git a/test/DynamoCoreTests/Configuration/PreferenceSettingsTests.cs b/test/DynamoCoreTests/Configuration/PreferenceSettingsTests.cs
index 64b2d02be8e..45d4165359a 100644
--- a/test/DynamoCoreTests/Configuration/PreferenceSettingsTests.cs
+++ b/test/DynamoCoreTests/Configuration/PreferenceSettingsTests.cs
@@ -132,8 +132,9 @@ public void TestSettingsSerialization()
Assert.AreEqual(windowSettings.Height, 321);
Assert.AreEqual(windowSettings.Width, 654);
Assert.AreEqual(windowSettings.Status, WindowStatus.Maximized);
- Assert.AreEqual(settings.GroupStyleItemsList.Count, 1);
- var styleItemsList = settings.GroupStyleItemsList[0];
+ // 5 styles in total, 4 default ones plus the one added in test
+ Assert.AreEqual(settings.GroupStyleItemsList.Count, 5);
+ var styleItemsList = settings.GroupStyleItemsList[4];
Assert.AreEqual(styleItemsList.Name, "TestGroup");
Assert.AreEqual(styleItemsList.HexColorString, "000000");
}
diff --git a/test/DynamoCoreWpfTests/CoreUITests.cs b/test/DynamoCoreWpfTests/CoreUITests.cs
index 3c5942df2aa..2f5f88c8118 100644
--- a/test/DynamoCoreWpfTests/CoreUITests.cs
+++ b/test/DynamoCoreWpfTests/CoreUITests.cs
@@ -515,7 +515,9 @@ public void PreferenceSetting_GroupStyles()
{
// Test that thte group style list is being initialized with an empty list
Assert.NotNull(ViewModel.PreferenceSettings.GroupStyleItemsList);
- Assert.AreEqual(0, ViewModel.PreferenceSettings.GroupStyleItemsList.Count);
+
+ //Now by default we will have always 4 GroupStyles added by Dynamo
+ Assert.AreEqual(4, ViewModel.PreferenceSettings.GroupStyleItemsList.Count);
// Test serialization of GroupStyles
string tempPath = System.IO.Path.GetTempPath();
@@ -533,16 +535,16 @@ public void PreferenceSetting_GroupStyles()
resultSetting = PreferenceSettings.Load(tempPath);
// Test if the fields are being saved
- Assert.AreEqual(1, initalSetting.GroupStyleItemsList.Count);
- Assert.AreEqual(resultSetting.GroupStyleItemsList[0].Name, initalSetting.GroupStyleItemsList[0].Name);
- Assert.AreEqual(resultSetting.GroupStyleItemsList[0].HexColorString, initalSetting.GroupStyleItemsList[0].HexColorString);
+ Assert.AreEqual(5, initalSetting.GroupStyleItemsList.Count);
+ Assert.AreEqual(resultSetting.GroupStyleItemsList[4].Name, initalSetting.GroupStyleItemsList[4].Name);
+ Assert.AreEqual(resultSetting.GroupStyleItemsList[4].HexColorString, initalSetting.GroupStyleItemsList[4].HexColorString);
// Test loading the settings defined in the xml configuration file
var filePath = Path.Combine(GetTestDirectory(ExecutingDirectory), @"settings\DynamoSettings-OneGroupStyle.xml");
PreferenceSettings OneGroupStyle = PreferenceSettings.Load(filePath);
- Assert.AreEqual(1, OneGroupStyle.GroupStyleItemsList.Count);
- Assert.AreEqual(OneGroupStyle.GroupStyleItemsList[0].Name, initalSetting.GroupStyleItemsList[0].Name);
- Assert.AreEqual(OneGroupStyle.GroupStyleItemsList[0].HexColorString, initalSetting.GroupStyleItemsList[0].HexColorString);
+ Assert.AreEqual(5, OneGroupStyle.GroupStyleItemsList.Count);
+ Assert.AreEqual(OneGroupStyle.GroupStyleItemsList[4].Name, initalSetting.GroupStyleItemsList[4].Name);
+ Assert.AreEqual(OneGroupStyle.GroupStyleItemsList[4].HexColorString, initalSetting.GroupStyleItemsList[4].HexColorString);
}
[Test]
diff --git a/test/DynamoCoreWpfTests/GroupStylesTests.cs b/test/DynamoCoreWpfTests/GroupStylesTests.cs
new file mode 100644
index 00000000000..f28b0d5e4db
--- /dev/null
+++ b/test/DynamoCoreWpfTests/GroupStylesTests.cs
@@ -0,0 +1,124 @@
+using System.Collections.Generic;
+using System.Linq;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Controls.Primitives;
+using Dynamo.Configuration;
+using Dynamo.Nodes;
+using Dynamo.Utilities;
+using Dynamo.ViewModels;
+using Dynamo.Views;
+using Dynamo.Wpf.Views;
+using DynamoCoreWpfTests.Utility;
+using NUnit.Framework;
+
+namespace DynamoCoreWpfTests
+{
+ [TestFixture]
+ public class GroupStylesTests : DynamoTestUIBase
+ {
+ public AnnotationView NodeViewWithGuid(string guid)
+ {
+ var annotationView =
+ View.WorkspaceTabs.ChildrenOfType().First().ChildrenOfType();
+ var annotationViewOfType = annotationView.Where(x => x.ViewModel.AnnotationModel.GUID.ToString() == guid);
+ Assert.AreEqual(1, annotationViewOfType.Count(), "Expected a single Annotation View with guid: " + guid);
+
+ return annotationViewOfType.First();
+ }
+
+ public override void Open(string path)
+ {
+ base.Open(path);
+ DispatcherUtil.DoEvents();
+ }
+
+ public override void Run()
+ {
+ base.Run();
+
+ DispatcherUtil.DoEvents();
+ }
+
+ protected override void GetLibrariesToPreload(List libraries)
+ {
+ libraries.Add("VMDataBridge.dll");
+ libraries.Add("ProtoGeometry.dll");
+ base.GetLibrariesToPreload(libraries);
+ }
+
+ ///
+ /// Validates that the GroupStyles in the PreferencesView match the ones in the AnnotationView
+ ///
+ [Test]
+ public void TestDefaultGroupStyles_PreferencesView()
+ {
+ int defaultGroupStylesCounter = 4;
+ Open(@"UI\GroupTest.dyn");
+
+ //Creates the Preferences dialog and the ScaleFactor = 2 ( Medium)
+ var preferencesWindow = new PreferencesView(View);
+ preferencesWindow.Show();
+ DispatcherUtil.DoEvents();
+
+ var prefViewModel = preferencesWindow.DataContext as PreferencesViewModel;
+
+ var annotationView = NodeViewWithGuid("a432d63f-7a36-45ad-b30a-7924beb20e90");
+
+ var annotationViewModel = annotationView.DataContext as AnnotationViewModel;
+
+ //Close the Preferences Dialog
+ preferencesWindow.CloseButton.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
+ DispatcherUtil.DoEvents();
+
+ //Check that the GroupStyles in the AnnotationView match the ones in the PreferencesView (default ones)
+ Assert.AreEqual(annotationViewModel.GroupStyleList.OfType().Count(), prefViewModel.StyleItemsList.Count);
+
+ }
+
+ ///
+ /// Add a new GroupStyle and validates that the GroupStyles in the PreferencesView match the ones in the AnnotationView
+ ///
+ [Test]
+ public void TestAddGroupStyle_ContextMenu()
+ {
+ int currentGroupStylesCounter = 5;
+ Open(@"UI\GroupTest.dyn");
+
+ var preferencesSettings = (View.DataContext as DynamoViewModel).PreferenceSettings;
+
+ //Creates the Preferences dialog and the ScaleFactor = 2 ( Medium)
+ var preferencesWindow = new PreferencesView(View);
+ preferencesWindow.Show();
+ DispatcherUtil.DoEvents();
+
+ var prefViewModel = preferencesWindow.DataContext as PreferencesViewModel;
+
+ var annotationView = NodeViewWithGuid("a432d63f-7a36-45ad-b30a-7924beb20e90");
+
+ var annotationViewModel = annotationView.DataContext as AnnotationViewModel;
+
+ //Check that the GroupStyles in the AnnotationView match the ones in the PreferencesView
+ Assert.AreEqual(annotationViewModel.GroupStyleList.OfType().Count(), prefViewModel.StyleItemsList.Count);
+
+ //Add one Custom Group Style to the PreferencesView
+ preferencesSettings.GroupStyleItemsList.Add(new Dynamo.Configuration.GroupStyleItem { Name = "Custom 1", HexColorString = "FFFF00", IsDefault = false });
+
+ //Close the Preferences Dialog
+ preferencesWindow.CloseButton.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
+ DispatcherUtil.DoEvents();
+
+ var groupStylesMenuItem = annotationView.AnnotationContextMenu
+ .Items
+ .OfType()
+ .First(x => x.Header.ToString() == "Group Style");
+
+ groupStylesMenuItem.RaiseEvent(new RoutedEventArgs(MenuItem.SubmenuOpenedEvent));
+ DispatcherUtil.DoEvents();
+
+ //Check that the GroupStyles in the AnnotationView match the ones in the PreferencesView
+ Assert.AreEqual(annotationViewModel.GroupStyleList.OfType().Count(), currentGroupStylesCounter);
+
+ }
+ }
+}