Skip to content

Commit

Permalink
Fixed palette browser duplication bug
Browse files Browse the repository at this point in the history
  • Loading branch information
flabbet committed Apr 19, 2024
1 parent 554a36d commit 5ad10a4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public async Task RefreshCacheAll()
{
string[] files = DirectoryExtensions.GetFiles(
Paths.PathToPalettesFolder,
string.Join("|", AvailableParsers.SelectMany(x => x.SupportedFileExtensions)),
string.Join("|", AvailableParsers.SelectMany(x => x.SupportedFileExtensions).Distinct()),
SearchOption.TopDirectoryOnly);
cachedPalettes = await ParseAll(files);
CacheUpdated?.Invoke(RefreshType.All, null, null);
Expand Down
10 changes: 5 additions & 5 deletions src/PixiEditor.AvaloniaUI/Views/Windows/PalettesBrowser.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
<DockPanel Background="{DynamicResource ThemeBackgroundBrush}" Grid.Row="0">
<StackPanel HorizontalAlignment="Left" Margin="10" Orientation="Horizontal" 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="COLOR_COUNT"/>
</ComboBox>
Expand Down Expand Up @@ -62,8 +62,8 @@
</input:InputBox>

<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="MIN"/>
<ComboBoxItem ui:Translator.Key="EXACT"/>
Expand Down Expand Up @@ -98,7 +98,7 @@
</DockPanel>
<Grid Grid.Row="1" Margin="10">
<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"
IsVisible="{Binding ElementName=palettesBrowser, Path=SortedResults.Count, Converter={converters:CountToVisibilityConverter}}">
<TextBlock ui:Translator.Key="NO_PALETTES_FOUND" Foreground="White" FontSize="20" TextAlignment="Center"/>
Expand Down
14 changes: 11 additions & 3 deletions src/PixiEditor.AvaloniaUI/Views/Windows/PalettesBrowser.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public bool SortAscending


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
{
Expand Down Expand Up @@ -339,8 +339,16 @@ private void HandleCacheItemUpdated(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();
}

Expand Down

0 comments on commit 5ad10a4

Please sign in to comment.