Browse Source

Merge pull request #465 from PixiEditor/color-repalce-improvements

Color replacer replaces color in palette too
Krzysztof Krysiński 2 years ago
parent
commit
f079810147

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

@@ -235,7 +235,19 @@ internal class DocumentOperationsModule
     {
         if (Internals.ChangeController.IsChangeActive || oldColor == newColor)
             return;
+        
         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>

+ 1 - 6
src/PixiEditor/ViewModels/SubViewModels/Main/WindowViewModel.cs

@@ -18,10 +18,6 @@ internal class WindowViewModel : SubViewModel<ViewModelMain>
     private CommandController commandController;
     private ShortcutPopup? shortcutPopup;
     private ShortcutPopup ShortcutPopup => shortcutPopup ??= new(commandController);
-
-    private AboutPopup? _aboutPopup;
-    private AboutPopup AboutPopup => _aboutPopup ??= new();
-
     public RelayCommand<string> ShowAvalonDockWindowCommand { get; set; }
     public ObservableCollection<ViewportWindowViewModel> Viewports { get; } = new();
     public event EventHandler<ViewportWindowViewModel>? ActiveViewportChanged;
@@ -165,8 +161,7 @@ internal class WindowViewModel : SubViewModel<ViewModelMain>
     [Command.Basic("PixiEditor.Window.OpenAboutWindow", "Open About Window", "Open About Window")]
     public void OpenAboutWindow()
     {
-        AboutPopup.Show();
-        AboutPopup.Activate();
+        new AboutPopup().Show();
     }
 
     [Command.Basic("PixiEditor.Window.OpenNavigationWindow", "navigation", "Open Navigation Window", "Open Navigation Window")]

+ 0 - 2
src/PixiEditor/Views/Dialogs/AboutPopup.xaml.cs

@@ -12,8 +12,6 @@ public partial class AboutPopup : Window
         InitializeComponent();
     }
     
-    
-    
     private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
     {
         e.CanExecute = true;

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

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