diff --git a/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml.cs b/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml.cs index caa6b69ccf4..ae0a0bb4435 100644 --- a/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml.cs +++ b/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml.cs @@ -37,7 +37,7 @@ public partial class PreferencesView : Window private IDisposable managePackageCommandEvent; //This list will be passed everytime that we create a new GroupStyle so the custom colors can remain - private ObservableCollection stylesCustomColors; + internal ObservableCollection stylesCustomColors; /// /// Storing the original custom styles before the user could update them @@ -265,6 +265,17 @@ private void RemoveStyle_Click(object sender, RoutedEventArgs e) private void ButtonColorPicker_Click(object sender, RoutedEventArgs e) { var colorPicker = new CustomColorPicker(); + + //This section populate the CustomColorPicker custom colors with the colors defined in the custom GroupStyles + var customStylesColorsList = viewModel.StyleItemsList.Where(style => style.IsDefault == false); + foreach (var styleItem in customStylesColorsList) + { + Color color = (Color)ColorConverter.ConvertFromString("#"+styleItem.HexColorString); + var customColorItem = new CustomColorItem(color, string.Format("#{0},{1},{2}", color.R, color.G, color.B)); + if (!stylesCustomColors.Contains(customColorItem)) + stylesCustomColors.Add(customColorItem); + } + //This will set the custom colors list so the custom colors will remain the same for the Preferences panel (no matter if preferences is closed the list will remain). colorPicker.SetCustomColors(stylesCustomColors); if (colorPicker == null) return; diff --git a/src/Libraries/CoreNodeModelsWpf/Controls/ColorPalette.xaml.cs b/src/Libraries/CoreNodeModelsWpf/Controls/ColorPalette.xaml.cs index 662939405cb..aa4ea72abdb 100644 --- a/src/Libraries/CoreNodeModelsWpf/Controls/ColorPalette.xaml.cs +++ b/src/Libraries/CoreNodeModelsWpf/Controls/ColorPalette.xaml.cs @@ -1,4 +1,5 @@ using System.Collections.ObjectModel; +using System.Linq; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Media; @@ -33,8 +34,9 @@ public void OnColorPickerSelectedColor() } private ColorPaletteViewModel viewModel = null; + private DynamoViewModel dynViewModel = null; - public ColorPaletteUI() + public ColorPaletteUI(DynamoViewModel dynViewM) { InitializeComponent(); if(viewModel == null) @@ -42,6 +44,7 @@ public ColorPaletteUI() viewModel = new ColorPaletteViewModel(); } this.DataContext = viewModel; + dynViewModel = dynViewM; //By default the ToggleButton will contain the Black color viewModel.SelectedColor = new SolidColorBrush(Colors.Black); @@ -64,6 +67,20 @@ private void ColorPickerPopup_Closed(object sender, System.EventArgs e) private void ColorToggleButton_Click(object sender, System.Windows.RoutedEventArgs e) { var colorPickerPopup = new CustomColorPicker(); + + if (dynViewModel != null) + { + //This section populate the CustomColorPicker custom colors with the colors defined in the custom GroupStyles + var customStylesColorsList = dynViewModel.PreferencesViewModel.StyleItemsList.Where(style => style.IsDefault == false); + foreach (var styleItem in customStylesColorsList) + { + Color color = (Color)ColorConverter.ConvertFromString("#" + styleItem.HexColorString); + var customColorItem = new CustomColorItem(color, string.Format("#{0},{1},{2}", color.R, color.G, color.B)); + if (!nodeCustomColors.Contains(customColorItem)) + nodeCustomColors.Add(customColorItem); + } + } + //This will set the custom colors list so the custom colors will remain the same just for this node. colorPickerPopup.SetCustomColors(nodeCustomColors); colorPickerPopup.Placement = PlacementMode.Bottom; diff --git a/src/Libraries/CoreNodeModelsWpf/NodeViewCustomizations/ColorPalette.cs b/src/Libraries/CoreNodeModelsWpf/NodeViewCustomizations/ColorPalette.cs index b924fa0c387..633a7771853 100644 --- a/src/Libraries/CoreNodeModelsWpf/NodeViewCustomizations/ColorPalette.cs +++ b/src/Libraries/CoreNodeModelsWpf/NodeViewCustomizations/ColorPalette.cs @@ -31,7 +31,8 @@ public void CustomizeView(ColorPalette model, NodeView nodeView) viewNode = nodeView; colorPaletteNode = model; converter = new Converters.MediatoDSColorConverter(); - ColorPaletteUINode = new ColorPaletteUI(); + + ColorPaletteUINode = new ColorPaletteUI(viewNode.ViewModel.DynamoViewModel); colorPaletteViewModel = ColorPaletteUINode.DataContext as ColorPaletteViewModel; if(colorPaletteNode == null ) return; diff --git a/test/DynamoCoreWpfTests/GroupStylesTests.cs b/test/DynamoCoreWpfTests/GroupStylesTests.cs index f28b0d5e4db..069540bee01 100644 --- a/test/DynamoCoreWpfTests/GroupStylesTests.cs +++ b/test/DynamoCoreWpfTests/GroupStylesTests.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Controls; @@ -120,5 +120,60 @@ public void TestAddGroupStyle_ContextMenu() Assert.AreEqual(annotationViewModel.GroupStyleList.OfType().Count(), currentGroupStylesCounter); } + + [Test] + public void CustomColorPicker_PrePopulateDefaultColors() + { + Open(@"UI\GroupTest.dyn"); + var tabName = "Visual Settings"; + var expanderName = "Group Styles"; + + var preferencesSettings = (View.DataContext as DynamoViewModel).PreferenceSettings; + + //Creates the Preferences dialog + var preferencesWindow = new PreferencesView(View); + + //Validate the 4 default existing styles list + Assert.AreEqual(preferencesSettings.GroupStyleItemsList.Count, 4); + + //Adds two Custom Group Styles to the PreferencesView + preferencesSettings.GroupStyleItemsList.Add(new GroupStyleItem { Name = "Custom 1", HexColorString = "FFFF00", IsDefault = false }); + preferencesSettings.GroupStyleItemsList.Add(new GroupStyleItem { Name = "Custom 2", HexColorString = "FF00FF", IsDefault = false }); + + //Finds the Visual Settings tab and open it + var tabControl = preferencesWindow.preferencesTabControl; + if (tabControl == null) return; + var preferencesTab = (from TabItem tabItem in tabControl.Items + where tabItem.Header.ToString().Equals(tabName) + select tabItem).FirstOrDefault(); + if (preferencesTab == null) return; + tabControl.SelectedItem = preferencesTab; + + //Finds the Group Styles section and open it + var listExpanders = WpfUtilities.ChildrenOfType(preferencesTab.Content as Grid); + var tabExpander = (from expander in listExpanders + where expander.Header.ToString().Equals(expanderName) + select expander).FirstOrDefault(); + if (tabExpander == null) return; + tabExpander.IsExpanded = true; + + + preferencesWindow.Show(); + DispatcherUtil.DoEvents(); + + //Click the AddStyle button + preferencesWindow.AddStyleButton.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent)); + DispatcherUtil.DoEvents(); + + //The custom Colors list used by ColorPicker is empty + Assert.AreEqual(preferencesWindow.stylesCustomColors.Count, 0); + + //Clicks the color button, this will populate the custom Colors list with the style colors added in Group Styles + preferencesWindow.buttonColorPicker.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent)); + DispatcherUtil.DoEvents(); + + //Validates that the 3 added custom colors are present in the custom Colors list + Assert.AreEqual(preferencesWindow.stylesCustomColors.Count, 2); + } } }