Browse Source

Color replacer replaces color in palette too

Krzysztof Krysiński 2 years ago
parent
commit
c90cb24ccf

+ 12 - 0
src/PixiEditor/Models/DocumentModels/Public/DocumentOperationsModule.cs

@@ -234,7 +234,19 @@ internal class DocumentOperationsModule
     {
     {
         if (Internals.ChangeController.IsChangeActive || oldColor == newColor)
         if (Internals.ChangeController.IsChangeActive || oldColor == newColor)
             return;
             return;
+        
         Internals.ActionAccumulator.AddFinishedActions(new ReplaceColor_Action(oldColor, newColor));
         Internals.ActionAccumulator.AddFinishedActions(new ReplaceColor_Action(oldColor, newColor));
+        ReplaceInPalette(oldColor, newColor);
+    }
+
+    private void ReplaceInPalette(Color oldColor, Color newColor)
+    {
+        int indexOfOldColor = Document.Palette.IndexOf(oldColor);
+        if(indexOfOldColor == -1)
+            return;
+        
+        Document.Palette.RemoveAt(indexOfOldColor);
+        Document.Palette.Insert(indexOfOldColor, newColor);
     }
     }
 
 
     /// <summary>
     /// <summary>

+ 3 - 11
src/PixiEditor/Views/UserControls/Palettes/ColorReplacer.xaml.cs

@@ -40,30 +40,21 @@ internal partial class ColorReplacer : UserControl
         set { SetValue(ReplaceColorsCommandProperty, value); }
         set { SetValue(ReplaceColorsCommandProperty, value); }
     }
     }
 
 
-
-
     public static readonly DependencyProperty NewColorProperty =
     public static readonly DependencyProperty NewColorProperty =
         DependencyProperty.Register(nameof(NewColor), typeof(Color), typeof(ColorReplacer), new PropertyMetadata(Colors.Black));
         DependencyProperty.Register(nameof(NewColor), typeof(Color), typeof(ColorReplacer), new PropertyMetadata(Colors.Black));
-
-
-
+    
     public static readonly DependencyProperty HintColorProperty =
     public static readonly DependencyProperty HintColorProperty =
         DependencyProperty.Register(nameof(HintColor), typeof(Color), typeof(ColorReplacer), new PropertyMetadata(Colors.Black));
         DependencyProperty.Register(nameof(HintColor), typeof(Color), typeof(ColorReplacer), new PropertyMetadata(Colors.Black));
 
 
-
-
     public bool IsCollapsed
     public bool IsCollapsed
     {
     {
         get { return (bool)GetValue(IsCollapsedProperty); }
         get { return (bool)GetValue(IsCollapsedProperty); }
         set { SetValue(IsCollapsedProperty, value); }
         set { SetValue(IsCollapsedProperty, value); }
     }
     }
 
 
-
     public static readonly DependencyProperty IsCollapsedProperty =
     public static readonly DependencyProperty IsCollapsedProperty =
         DependencyProperty.Register(nameof(IsCollapsed), typeof(bool), typeof(ColorReplacer), new PropertyMetadata(false));
         DependencyProperty.Register(nameof(IsCollapsed), typeof(bool), typeof(ColorReplacer), new PropertyMetadata(false));
 
 
-
-
     private void UIElement_OnDrop(object sender, DragEventArgs e)
     private void UIElement_OnDrop(object sender, DragEventArgs e)
     {
     {
         if (e.Data.GetDataPresent(PaletteColor.PaletteColorDaoFormat))
         if (e.Data.GetDataPresent(PaletteColor.PaletteColorDaoFormat))
@@ -91,6 +82,7 @@ internal partial class ColorReplacer : UserControl
             ReplaceColorsCommand.Execute(pack);
             ReplaceColorsCommand.Execute(pack);
         }
         }
 
 
-        ColorToReplace = BackendColors.White;
+        ColorToReplace = second;
+        NewColor = first.ToOpaqueMediaColor();
     }
     }
 }
 }