Browse Source

Fixed palette browser duplication bug

Krzysztof Krysiński 1 year ago
parent
commit
5ad10a4ec0

+ 1 - 1
src/PixiEditor.AvaloniaUI/Models/Palettes/LocalPalettesFetcher.cs

@@ -150,7 +150,7 @@ internal class LocalPalettesFetcher : PaletteListDataSource
     {
     {
         string[] files = DirectoryExtensions.GetFiles(
         string[] files = DirectoryExtensions.GetFiles(
             Paths.PathToPalettesFolder,
             Paths.PathToPalettesFolder,
-            string.Join("|", AvailableParsers.SelectMany(x => x.SupportedFileExtensions)),
+            string.Join("|", AvailableParsers.SelectMany(x => x.SupportedFileExtensions).Distinct()),
             SearchOption.TopDirectoryOnly);
             SearchOption.TopDirectoryOnly);
         cachedPalettes = await ParseAll(files);
         cachedPalettes = await ParseAll(files);
         CacheUpdated?.Invoke(RefreshType.All, null, null);
         CacheUpdated?.Invoke(RefreshType.All, null, null);

+ 5 - 5
src/PixiEditor.AvaloniaUI/Views/Windows/PalettesBrowser.axaml

@@ -26,8 +26,8 @@
         <DockPanel Background="{DynamicResource ThemeBackgroundBrush}" Grid.Row="0">
         <DockPanel Background="{DynamicResource ThemeBackgroundBrush}" Grid.Row="0">
             <StackPanel HorizontalAlignment="Left" Margin="10" Orientation="Horizontal" VerticalAlignment="Center">
             <StackPanel HorizontalAlignment="Left" Margin="10" Orientation="Horizontal" VerticalAlignment="Center">
                 <Label ui:Translator.Key="SORT_BY" VerticalAlignment="Center"/>
                 <Label ui:Translator.Key="SORT_BY" VerticalAlignment="Center"/>
-                <ComboBox x:Name="sortingComboBox" VerticalAlignment="Center" SelectionChanged="SortingComboBox_SelectionChanged">
-                    <ComboBoxItem IsSelected="True" ui:Translator.Key="DEFAULT"/>
+                <ComboBox x:Name="sortingComboBox" VerticalAlignment="Center" SelectedIndex="0" SelectionChanged="SortingComboBox_SelectionChanged">
+                    <ComboBoxItem ui:Translator.Key="DEFAULT"/>
                     <ComboBoxItem ui:Translator.Key="ALPHABETICAL"/>
                     <ComboBoxItem ui:Translator.Key="ALPHABETICAL"/>
                     <ComboBoxItem ui:Translator.Key="COLOR_COUNT"/>
                     <ComboBoxItem ui:Translator.Key="COLOR_COUNT"/>
                 </ComboBox>
                 </ComboBox>
@@ -62,8 +62,8 @@
                 </input:InputBox>
                 </input:InputBox>
 
 
                 <Label Margin="10 0 0 0" ui:Translator.Key="COLORS" VerticalAlignment="Center"/>
                 <Label Margin="10 0 0 0" ui:Translator.Key="COLORS" VerticalAlignment="Center"/>
-                <ComboBox x:Name="colorsComboBox" VerticalAlignment="Center" SelectionChanged="ColorsComboBox_SelectionChanged">
-                    <ComboBoxItem IsSelected="True" ui:Translator.Key="ANY"/>
+                <ComboBox x:Name="colorsComboBox" VerticalAlignment="Center" SelectedIndex="0" SelectionChanged="ColorsComboBox_SelectionChanged">
+                    <ComboBoxItem ui:Translator.Key="ANY"/>
                     <ComboBoxItem ui:Translator.Key="MAX"/>
                     <ComboBoxItem ui:Translator.Key="MAX"/>
                     <ComboBoxItem ui:Translator.Key="MIN"/>
                     <ComboBoxItem ui:Translator.Key="MIN"/>
                     <ComboBoxItem ui:Translator.Key="EXACT"/>
                     <ComboBoxItem ui:Translator.Key="EXACT"/>
@@ -98,7 +98,7 @@
         </DockPanel>
         </DockPanel>
         <Grid Grid.Row="1" Margin="10">
         <Grid Grid.Row="1" Margin="10">
             <TextBlock ui:Translator.Key="COULD_NOT_LOAD_PALETTE" Foreground="White" FontSize="20" HorizontalAlignment="Center"
             <TextBlock ui:Translator.Key="COULD_NOT_LOAD_PALETTE" Foreground="White" FontSize="20" HorizontalAlignment="Center"
-                       VerticalAlignment="Center" IsVisible="{Binding !Visibility, ElementName=itemsControl}"/>
+                       VerticalAlignment="Center" IsVisible="{Binding !IsVisible, ElementName=itemsControl}"/>
             <StackPanel Panel.ZIndex="10" Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center"
             <StackPanel Panel.ZIndex="10" Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center"
                         IsVisible="{Binding ElementName=palettesBrowser, Path=SortedResults.Count, Converter={converters:CountToVisibilityConverter}}">
                         IsVisible="{Binding ElementName=palettesBrowser, Path=SortedResults.Count, Converter={converters:CountToVisibilityConverter}}">
                 <TextBlock ui:Translator.Key="NO_PALETTES_FOUND" Foreground="White" FontSize="20" TextAlignment="Center"/>
                 <TextBlock ui:Translator.Key="NO_PALETTES_FOUND" Foreground="White" FontSize="20" TextAlignment="Center"/>

+ 11 - 3
src/PixiEditor.AvaloniaUI/Views/Windows/PalettesBrowser.axaml.cs

@@ -110,7 +110,7 @@ internal partial class PalettesBrowser : PixiEditorPopup, IPopupWindow
 
 
 
 
     public static readonly StyledProperty<ObservableRangeCollection<Palette>> SortedResultsProperty =
     public static readonly StyledProperty<ObservableRangeCollection<Palette>> SortedResultsProperty =
-        AvaloniaProperty.Register<PalettesBrowser, ObservableRangeCollection<Palette>>(nameof(SortedResults), new ObservableRangeCollection<Palette>());
+        AvaloniaProperty.Register<PalettesBrowser, ObservableRangeCollection<Palette>>(nameof(SortedResults));
 
 
     public ObservableRangeCollection<Palette> SortedResults
     public ObservableRangeCollection<Palette> SortedResults
     {
     {
@@ -339,8 +339,16 @@ internal partial class PalettesBrowser : PixiEditorPopup, IPopupWindow
 
 
     private void HandleCachePaletteCreated(Palette updatedItem)
     private void HandleCachePaletteCreated(Palette updatedItem)
     {
     {
-        SortedResults.Add(updatedItem);
-        PaletteList.Palettes.Add(updatedItem);
+        if (!SortedResults.Contains(updatedItem))
+        {
+            SortedResults.Add(updatedItem);
+        }
+
+        if(!PaletteList.Palettes.Contains(updatedItem))
+        {
+            PaletteList.Palettes.Add(updatedItem);
+        }
+
         Sort();
         Sort();
     }
     }