diff --git a/src/DynamoCore/Configuration/GroupStyleItem.cs b/src/DynamoCore/Configuration/GroupStyleItem.cs index 6acdc3a0ae1..7c3cf91b6d9 100644 --- a/src/DynamoCore/Configuration/GroupStyleItem.cs +++ b/src/DynamoCore/Configuration/GroupStyleItem.cs @@ -1,6 +1,23 @@ -namespace Dynamo.Configuration +using System.Collections.ObjectModel; +using Dynamo.Properties; + +namespace Dynamo.Configuration { + /// + /// Group specific style item + /// Note: This class does not contain special property yet comparing to base class + /// public class GroupStyleItem: StyleItem { + /// + /// Static set of default group styles defined by Dynamo Team + /// + public static ObservableCollection DefaultGroupStyleItems = + new ObservableCollection() { + new GroupStyleItem() { Name = Resources.GroupStyleDefaultActions, HexColorString = Resources.GroupStyleDefaultActionsColor, IsDefault = true }, + new GroupStyleItem() { Name = Resources.GroupStyleDefaultInputs, HexColorString = Resources.GroupStyleDefaultInputsColor, IsDefault = true }, + new GroupStyleItem() { Name = Resources.GroupStyleDefaultOutputs, HexColorString = Resources.GroupStyleDefaultOutputsColor, IsDefault = true }, + new GroupStyleItem() { Name = Resources.GroupStyleDefaultReview, HexColorString = Resources.GroupStyleDefaultReviewColor, IsDefault = true } + }; } } diff --git a/src/DynamoCore/Configuration/PreferenceSettings.cs b/src/DynamoCore/Configuration/PreferenceSettings.cs index c7e30310f5b..82a1f7bd3ba 100644 --- a/src/DynamoCore/Configuration/PreferenceSettings.cs +++ b/src/DynamoCore/Configuration/PreferenceSettings.cs @@ -7,7 +7,6 @@ using Dynamo.Graph.Connectors; using Dynamo.Interfaces; using Dynamo.Models; -using Dynamo.Properties; namespace Dynamo.Configuration { @@ -534,9 +533,6 @@ public PreferenceSettings() DefaultPythonEngine = string.Empty; ViewExtensionSettings = new List(); GroupStyleItemsList = new List(); - - //Add the default group styles - AddDefaultStyles(); } /// @@ -585,7 +581,7 @@ public bool SaveInternal(string preferenceFilePath) /// /// Loads PreferenceSettings from specified XML file if possible, - /// else initialises PreferenceSettings with default values. + /// else initializes PreferenceSettings with default values. /// /// Path of the XML File /// @@ -594,10 +590,11 @@ public bool SaveInternal(string preferenceFilePath) /// public static PreferenceSettings Load(string filePath) { - var settings = new PreferenceSettings(); + // Constructor will be called anyway in either condition below so no need to initialize now. + PreferenceSettings settings = null; if (String.IsNullOrEmpty(filePath) || (!File.Exists(filePath))) - return settings; + return new PreferenceSettings(); try { @@ -615,22 +612,6 @@ public static PreferenceSettings Load(string filePath) 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/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs b/src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs index 6f9a257120d..20b27ee9c1d 100644 --- a/src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs @@ -1,4 +1,12 @@ -using Dynamo.Configuration; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Collections.Specialized; +using System.ComponentModel; +using System.Drawing; +using System.IO; +using System.Linq; +using Dynamo.Configuration; using Dynamo.Core; using Dynamo.Events; using Dynamo.Graph.Workspaces; @@ -8,14 +16,6 @@ using Dynamo.PythonServices; using Dynamo.Utilities; using Dynamo.Wpf.ViewModels.Core.Converters; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Collections.Specialized; -using System.ComponentModel; -using System.Drawing; -using System.IO; -using System.Linq; using Res = Dynamo.Wpf.Properties.Resources; namespace Dynamo.ViewModels @@ -39,7 +39,6 @@ public class PreferencesViewModel : ViewModelBase, INotifyPropertyChanged private ObservableCollection packagePathsForInstall; private ObservableCollection fontSizeList; private ObservableCollection numberFormatList; - private ObservableCollection styleItemsList; private StyleItem addStyleControl; private ObservableCollection pythonEngineList; @@ -411,12 +410,12 @@ public ObservableCollection NumberFormatList /// /// This will contain a list of all the Styles created by the user in the Styles list ( Visual Settings -> Group Styles section) /// - public ObservableCollection StyleItemsList + public ObservableCollection StyleItemsList { - get { return styleItemsList; } + get { return preferenceSettings.GroupStyleItemsList.ToObservableCollection(); } set { - styleItemsList = value; + preferenceSettings.GroupStyleItemsList = value.ToList(); RaisePropertyChanged(nameof(StyleItemsList)); } } @@ -424,11 +423,14 @@ public ObservableCollection StyleItemsList /// /// Used to add styles to the StyleItemsListe while also update the saved changes label /// - /// + /// style to be added public void AddStyle(StyleItem style) { - StyleItemsList.Add(style); - preferenceSettings.GroupStyleItemsList.Add(new GroupStyleItem { HexColorString = style.HexColorString, Name = style.Name, IsDefault = style.IsDefault }); + preferenceSettings.GroupStyleItemsList.Add(new GroupStyleItem { + HexColorString = style.HexColorString, + Name = style.Name, + IsDefault = style.IsDefault + }); RaisePropertyChanged(nameof(StyleItemsList)); } @@ -815,19 +817,24 @@ public PreferencesViewModel(DynamoViewModel dynamoViewModel) LanguagesList = new ObservableCollection(languages.Split(',')); SelectedLanguage = languages.Split(',').First(); - FontSizeList = new ObservableCollection(); - FontSizeList.Add(Wpf.Properties.Resources.ScalingSmallButton); - FontSizeList.Add(Wpf.Properties.Resources.ScalingMediumButton); - FontSizeList.Add(Wpf.Properties.Resources.ScalingLargeButton); - FontSizeList.Add(Wpf.Properties.Resources.ScalingExtraLargeButton); + FontSizeList = new ObservableCollection + { + Wpf.Properties.Resources.ScalingSmallButton, + Wpf.Properties.Resources.ScalingMediumButton, + Wpf.Properties.Resources.ScalingLargeButton, + Wpf.Properties.Resources.ScalingExtraLargeButton + }; SelectedFontSize = Wpf.Properties.Resources.ScalingMediumButton; - NumberFormatList = new ObservableCollection(); - NumberFormatList.Add(Wpf.Properties.Resources.DynamoViewSettingMenuNumber0); - NumberFormatList.Add(Wpf.Properties.Resources.DynamoViewSettingMenuNumber00); - NumberFormatList.Add(Wpf.Properties.Resources.DynamoViewSettingMenuNumber000); - NumberFormatList.Add(Wpf.Properties.Resources.DynamoViewSettingMenuNumber0000); - NumberFormatList.Add(Wpf.Properties.Resources.DynamoViewSettingMenuNumber00000); + // Number format settings + NumberFormatList = new ObservableCollection + { + Wpf.Properties.Resources.DynamoViewSettingMenuNumber0, + Wpf.Properties.Resources.DynamoViewSettingMenuNumber00, + Wpf.Properties.Resources.DynamoViewSettingMenuNumber000, + Wpf.Properties.Resources.DynamoViewSettingMenuNumber0000, + Wpf.Properties.Resources.DynamoViewSettingMenuNumber00000 + }; SelectedNumberFormat = preferenceSettings.NumberFormat; runSettingsIsChecked = preferenceSettings.DefaultRunType; @@ -836,8 +843,9 @@ public PreferencesViewModel(DynamoViewModel dynamoViewModel) //By Default the warning state of the Visual Settings tab (Group Styles section) will be disabled isWarningEnabled = false; - StyleItemsList = LoadStyles(preferenceSettings.GroupStyleItemsList); - + // Initialize group styles with default and non-default GroupStyleItems + StyleItemsList = GroupStyleItem.DefaultGroupStyleItems.AddRange(preferenceSettings.GroupStyleItemsList.Where(style => style.IsDefault != true)).ToObservableCollection(); + //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() { Name = string.Empty, HexColorString = GetRandomHexStringColor() }; @@ -859,6 +867,7 @@ public PreferencesViewModel(DynamoViewModel dynamoViewModel) SavedChangesLabel = string.Empty; SavedChangesTooltip = string.Empty; + // Add tabs preferencesTabs = new Dictionary(); preferencesTabs.Add("General", new TabSettings() { Name = "General", ExpanderActive = string.Empty }); preferencesTabs.Add("Features",new TabSettings() { Name = "Features", ExpanderActive = string.Empty }); @@ -881,22 +890,7 @@ public PreferencesViewModel(DynamoViewModel dynamoViewModel) } /// - /// This method loads the group styles defined by the user and stored in the xml file - /// - /// - /// - private ObservableCollection LoadStyles(IEnumerable styleItemsList) - { - ObservableCollection styles = new ObservableCollection(); - foreach (var style in styleItemsList) - { - styles.Add(new StyleItem { Name = style.Name, HexColorString = style.HexColorString, IsDefault = style.IsDefault }); - } - return styles; - } - - /// - /// This method will be executed everytime the WorkspaceModel.ScaleFactor value is updated. + /// This method will be executed every time the WorkspaceModel.ScaleFactor value is updated. /// /// private void PreferencesViewModel_WorkspaceSettingsChanged(WorkspacesSettingsChangedEventArgs args) @@ -1090,28 +1084,35 @@ internal void UpdateSavedChangesLabel() } /// - /// This method will remove the current Style selected from the Styles list + /// This method will remove the current Style selected from the Styles list by name /// - /// - internal void RemoveStyleEntry(string groupName) + /// + internal void RemoveStyleEntry(string styleName) { - 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)); + GroupStyleItem itemToRemovePreferences = preferenceSettings.GroupStyleItemsList.FirstOrDefault(x => x.Name.Equals(styleName)); preferenceSettings.GroupStyleItemsList.Remove(itemToRemovePreferences); - + RaisePropertyChanged(nameof(StyleItemsList)); UpdateSavedChangesLabel(); } /// - /// This method will check if the Style that is being created already exists in the Styles list + /// This method will check if the name of Style that is being created already exists in the Styles list + /// + /// target style item to check + /// + internal bool IsStyleNameValid(StyleItem item) + { + return StyleItemsList.Where(x => x.Name.Equals(item.Name)).Any(); + } + + /// + /// This method will check if the name of Style that is being created already exists in the Styles list /// - /// + /// target style to be checked /// - internal bool ValidateExistingStyle(StyleItem item1) + internal bool ValidateStyleGuid(StyleItem item) { - return StyleItemsList.Where(x => x.Name.Equals(item1.Name)).Any(); + return StyleItemsList.Where(x => x.Name.Equals(item.Name)).Any(); } /// diff --git a/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml.cs b/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml.cs index 6203661dc83..b806b73a798 100644 --- a/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml.cs +++ b/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml.cs @@ -192,7 +192,7 @@ private void AddStyle_SaveButton_Click(object sender, RoutedEventArgs e) viewModel.EnableGroupStyleWarningState(Res.PreferencesViewEmptyStyleWarning); } //Means that the Style name to be created already exists - else if (viewModel.ValidateExistingStyle(newItem)) + else if (viewModel.IsStyleNameValid(newItem)) { viewModel.EnableGroupStyleWarningState(Res.PreferencesViewAlreadyExistingStyleWarning); } diff --git a/test/DynamoCoreTests/Configuration/PreferenceSettingsTests.cs b/test/DynamoCoreTests/Configuration/PreferenceSettingsTests.cs index 45d4165359a..86b241cfb66 100644 --- a/test/DynamoCoreTests/Configuration/PreferenceSettingsTests.cs +++ b/test/DynamoCoreTests/Configuration/PreferenceSettingsTests.cs @@ -1,7 +1,7 @@ -using Dynamo.Configuration; +using System.IO; +using Dynamo.Configuration; using Dynamo.Models; using NUnit.Framework; -using System.IO; namespace Dynamo.Tests.Configuration { @@ -132,9 +132,9 @@ public void TestSettingsSerialization() Assert.AreEqual(windowSettings.Height, 321); Assert.AreEqual(windowSettings.Width, 654); Assert.AreEqual(windowSettings.Status, WindowStatus.Maximized); - // 5 styles in total, 4 default ones plus the one added in test - Assert.AreEqual(settings.GroupStyleItemsList.Count, 5); - var styleItemsList = settings.GroupStyleItemsList[4]; + // Load function will only deserialize the customized style + Assert.AreEqual(settings.GroupStyleItemsList.Count, 1); + var styleItemsList = settings.GroupStyleItemsList[0]; Assert.AreEqual(styleItemsList.Name, "TestGroup"); Assert.AreEqual(styleItemsList.HexColorString, "000000"); } diff --git a/test/DynamoCoreWpfTests/CoreUITests.cs b/test/DynamoCoreWpfTests/CoreUITests.cs index 2f5f88c8118..39bfbf9837b 100644 --- a/test/DynamoCoreWpfTests/CoreUITests.cs +++ b/test/DynamoCoreWpfTests/CoreUITests.cs @@ -513,7 +513,7 @@ public void PreferenceSetting_RenderPrecision() [Category("DynamoUI")] public void PreferenceSetting_GroupStyles() { - // Test that thte group style list is being initialized with an empty list + // Test that the group style list is being initialized with a non-empty list Assert.NotNull(ViewModel.PreferenceSettings.GroupStyleItemsList); //Now by default we will have always 4 GroupStyles added by Dynamo @@ -534,17 +534,17 @@ public void PreferenceSetting_GroupStyles() initalSetting.Save(tempPath); resultSetting = PreferenceSettings.Load(tempPath); - // Test if the fields are being saved - 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 if the customized group styles can be loaded + 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); // 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(5, OneGroupStyle.GroupStyleItemsList.Count); - Assert.AreEqual(OneGroupStyle.GroupStyleItemsList[4].Name, initalSetting.GroupStyleItemsList[4].Name); - Assert.AreEqual(OneGroupStyle.GroupStyleItemsList[4].HexColorString, initalSetting.GroupStyleItemsList[4].HexColorString); + 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); } [Test] diff --git a/test/settings/DynamoSettings-WithoutRenderPrecision.xml b/test/settings/DynamoSettings-WithoutRenderPrecision.xml index 28b9fe7d6d0..283222de7c8 100644 --- a/test/settings/DynamoSettings-WithoutRenderPrecision.xml +++ b/test/settings/DynamoSettings-WithoutRenderPrecision.xml @@ -1,76 +1,167 @@ -- - - - true - - - false - - - false - - - 304 - - - 0 - - - true - - - true - - - BEZIER - - - - true - - - false - - - true - - - 0 - - - 0 - - - 1024 - - - 768 - - - true - - - f3 - - - 10 - - - - - - - - 60000 - - - 1 - - - false - - - false - - + + false + false + 1 + 0 + true + true + false + true + BEZIER + + + IsBackgroundPreviewActive + false + + + false + false + true + 345 + 76 + 1024 + 768 + true + f3 + 10 + + C:\Users\tanga\Desktop\Home.dyn + C:\Users\tanga\Downloads\20220217 Dynamo group bugs.dyn + C:\ProgramData\Dynamo\Dynamo Core\samples\en-US\Revit\Revit_Color.dyn + C:\Users\tanga\Downloads\error_warning_bubble.dyn + C:\Users\tanga\Downloads\Workspace Layout\Workspace Layout.dyn + C:\Users\tanga\Downloads\Three Box Massing.dyn + C:\Users\tanga\Documents\GitHub\Dynamo\test\core\annotationViewModelTests\groupsTestFile.dyn + C:\ProgramData\Dynamo\Dynamo Core\samples\en-US\Geometry\Geometry_Solids.dyn + C:\ProgramData\Dynamo\Dynamo Core\samples\en-US\Geometry\Geometry_Surfaces.dyn + C:\ProgramData\Dynamo\Dynamo Core\samples\en-US\Basics\Basics_Basic01.dyn + + + C:\Users\tanga\AppData\Roaming\Dynamo\Dynamo Core\backup\backup.DYN + + + C:\Users\tanga\AppData\Roaming\Dynamo\Dynamo Core\2.14 + %BuiltInPackages% + C:\ProgramData\Dynamo\Dynamo Core\2.14\packages + + + C:\Users\tanga\AppData\Roaming\Dynamo\Dynamo Core\2.11\packages\TuneUp + + + 60000 + 1 + true + false + true + false + true + + C:\Users\tanga\AppData\Roaming\Dynamo\Dynamo Core\2.14 + + ProtoGeometry.dll:Autodesk.DesignScript.Geometry.TSpline + + + + Documentation Browser + 68B45FC0-0BD1-435C-BF28-B97CB03C71C8 + DockRight + + Normal + 1060 + 416 + 160 + 32 + + + + TuneUp + b318f80b-b1d0-4935-b80e-7ab1be7742b4 + FloatingWindow + + Normal + 94 + 193 + 347 + 727 + + + + Workspace References + A6706BF5-11C2-458F-B7C8-B745A77EF7FD + DockRight + + Normal + 234 + 194 + 1440 + 759 + + + + Workspace References + 85c3fb83-a886-482f-9ed6-6eb9994e20d3 + DockRight + + + Properties + 28992e1d-abb9-417f-8b1b-05e053bee670 + DockRight + + + Package Details + C71CA1B9-BF9F-425A-A12C-53DF56770406 + DockRight + + Normal + 240 + 141 + 1440 + 759 + + + + Voice Control + F884D20E-3B9A-4DCD-890C-D786B4A5DB9D + DockRight + + + false + false + Automatic + false + + + Actions + B9F9E1 + true + + + Inputs + FFB8D8 + true + + + Outputs + FFC999 + true + + + Review + A4E1FF + true + + + My way too long style + 0E7033 + false + + + Sample Style 01 + 6C9C9B + false + + + 300 + 2.1.0 + \ No newline at end of file