Przeglądaj źródła

Fixed replace palette confirmation being shown when there's no palette or the palette is the same as the current one #554

CPKreuz 2 lat temu
rodzic
commit
0f597787dd

+ 2 - 2
src/PixiEditor/ViewModels/SubViewModels/Document/DocumentViewModel.cs

@@ -144,8 +144,8 @@ internal partial class DocumentViewModel : NotifyableObject
     private VectorPath selectionPath = new VectorPath();
     public VectorPath SelectionPathBindable => selectionPath;
 
-    public WpfObservableRangeCollection<PaletteColor> Swatches { get; set; } = new WpfObservableRangeCollection<PaletteColor>();
-    public WpfObservableRangeCollection<PaletteColor> Palette { get; set; } = new WpfObservableRangeCollection<PaletteColor>();
+    public WpfObservableRangeCollection<PaletteColor> Swatches { get; set; } = new();
+    public WpfObservableRangeCollection<PaletteColor> Palette { get; set; } = new();
 
     public DocumentTransformViewModel TransformViewModel { get; }
     public ReferenceLayerViewModel ReferenceLayerViewModel { get; }

+ 2 - 7
src/PixiEditor/ViewModels/SubViewModels/Main/ColorsViewModel.cs

@@ -218,16 +218,11 @@ internal class ColorsViewModel : SubViewModel<ViewModelMain>
     public void ImportPalette(List<PaletteColor> palette)
     {
         var doc = Owner.DocumentManagerSubViewModel.ActiveDocument;
-        if (doc is null)
+        if (doc is null || doc.Palette.SequenceEqual(palette))
             return;
 
-        if (ConfirmationDialog.Show(new LocalizedString("REPLACE_PALETTE_CONSENT"), new LocalizedString("REPLACE_PALETTE")) == ConfirmationType.Yes)
+        if (doc.Palette.Count == 0 || ConfirmationDialog.Show(new LocalizedString("REPLACE_PALETTE_CONSENT"), new LocalizedString("REPLACE_PALETTE")) == ConfirmationType.Yes)
         {
-            if (doc.Palette is null)
-            {
-                doc.Palette = new WpfObservableRangeCollection<PaletteColor>();
-            }
-
             doc.Palette.ReplaceRange(palette.Select(x => new PaletteColor(x.R, x.G, x.B)));
         }
     }