Browse Source

Fixed AlwaysEnabled decorator

Krzysztof Krysiński 1 year ago
parent
commit
968e9c3898

+ 1 - 1
src/PixiEditor.AvaloniaUI/Helpers/PaletteHelpers.cs

@@ -29,7 +29,7 @@ internal static class PaletteHelpers
 
         foreach (var parser in parsers)
         {
-            string supportedFormats = string.Join(';', parser.SupportedFileExtensions).Replace(".", "*.");
+            string supportedFormats = string.Join(';', parser.SupportedFileExtensions);
             filePickerFileTypes.Add(new FilePickerFileType($"{parser.FileName} ({supportedFormats})")
             {
                 Patterns = parser.SupportedFileExtensions

+ 4 - 18
src/PixiEditor.AvaloniaUI/Models/Structures/ObservableRangeCollection.cs

@@ -2,10 +2,11 @@
 using System.Collections.ObjectModel;
 using System.Collections.Specialized;
 using System.Linq;
+using Avalonia.Collections;
 
 namespace PixiEditor.AvaloniaUI.Models.Structures;
 
-public class ObservableRangeCollection<T> : ObservableCollection<T>
+public class ObservableRangeCollection<T> : AvaloniaList<T>
 {
     public ObservableRangeCollection()
     {
@@ -15,24 +16,9 @@ public class ObservableRangeCollection<T> : ObservableCollection<T>
     {
     }
 
-    public void AddRange(IEnumerable<T> collection)
-    {
-        foreach (var i in collection)
-        {
-            Items.Add(i);
-        }
-
-        OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, collection.ToList()));
-    }
-
     public void ReplaceRange(IEnumerable<T> collection)
     {
-        Items.Clear();
-        foreach (var i in collection)
-        {
-            Items.Add(i);
-        }
-
-        OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
+        Clear();
+        AddRange(collection);
     }
 }

+ 1 - 1
src/PixiEditor.AvaloniaUI/ViewModels/Document/DocumentViewModel.Serialization.cs

@@ -158,6 +158,6 @@ internal partial class DocumentViewModel
         };
     }
 
-    private ColorCollection ToCollection(ObservableCollection<PaletteColor> collection) =>
+    private ColorCollection ToCollection(IList<PaletteColor> collection) =>
         new(collection.Select(x => Color.FromArgb(255, x.R, x.G, x.B)));
 }

+ 1 - 1
src/PixiEditor.AvaloniaUI/Views/Decorators/AlwaysEnabled.cs

@@ -3,7 +3,7 @@ using Avalonia.Controls;
 
 namespace PixiEditor.AvaloniaUI.Views.Decorators;
 
-public class AlwaysEnabled : ContentControl
+public class AlwaysEnabled : Decorator
 {
     static AlwaysEnabled()
     {

+ 1 - 0
src/PixiEditor.AvaloniaUI/Views/Dialogs/ConfirmationPopup.axaml

@@ -35,6 +35,7 @@
         <StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Center"
                     Margin="0,0,10,15">
             <Button Margin="10,0,10,0" IsDefault="True" Padding="5 0"
+                    ui:Translator.LocalizedString="{Binding FirstOptionText}"
                     Command="{Binding Path=DataContext.SetResultAndCloseCommand, ElementName=popup}">
                 <Button.CommandParameter>
                     <system:Boolean>True</system:Boolean>

+ 0 - 1
src/PixiEditor.AvaloniaUI/Views/Palettes/PaletteViewer.axaml

@@ -66,7 +66,6 @@
                 <TextBlock TextWrapping="Wrap" ui:Translator.Key="DROP_PALETTE" Foreground="White" FontSize="32" HorizontalAlignment="Center" VerticalAlignment="Center"/>
             </Grid>
             <ScrollViewer Grid.Row="2" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
-                <!--TODO: Alternation count was here-->
                 <ItemsControl ItemsSource="{Binding Colors, ElementName=paletteControl}">
                     <ItemsControl.ItemsPanel>
                         <ItemsPanelTemplate>

+ 3 - 3
src/PixiEditor.AvaloniaUI/Views/Palettes/PaletteViewer.axaml.cs

@@ -155,17 +155,17 @@ internal partial class PaletteViewer : UserControl
 
             if (file is null) return;
 
-            string fileName = file.Name;
+            string path = file.Path.AbsolutePath;
             var foundParser =
                 PaletteProvider.AvailableParsers.First(x =>
-                    x.SupportedFileExtensions.Contains(Path.GetExtension(fileName)));
+                    x.SupportedFileExtensions.Contains(Path.GetExtension(path)));
             if (Colors == null || Colors.Count == 0)
             {
                 NoticeDialog.Show("NO_COLORS_TO_SAVE", "ERROR");
                 return;
             }
 
-            bool saved = await foundParser.Save(fileName, new PaletteFileData(Colors.ToArray()));
+            bool saved = await foundParser.Save(path, new PaletteFileData(Colors.ToArray()));
             if (!saved)
             {
                 NoticeDialog.Show("COULD_NOT_SAVE_PALETTE", "ERROR");