Browse Source

Fixed filters and drop palette

Krzysztof Krysiński 1 year ago
parent
commit
b54236f824

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

@@ -23,7 +23,7 @@ internal static class PaletteHelpers
                     .Select(x => x.Replace(".", "*.")));
             }
 
-            string allSupportedFormatsString = string.Join(';', allSupportedFormats).Replace(".", "*.");
+            string allSupportedFormatsString = string.Join(';', allSupportedFormats);
             filePickerFileTypes.Add(new FilePickerFileType($"Palette Files ({allSupportedFormatsString}")
             {
                 Patterns = allSupportedFormats
@@ -32,8 +32,8 @@ internal static class PaletteHelpers
 
         foreach (var parser in parsers)
         {
-            string supportedFormats = string.Join(';', parser.SupportedFileExtensions);
-            filePickerFileTypes.Add(new FilePickerFileType($"{parser.FileName} ({supportedFormats})")
+            string supportedFormats = string.Join(';', parser.SupportedFileExtensions).Replace(".", "*.");
+            filePickerFileTypes.Add(new FilePickerFileType($"{parser.FileName}")
             {
                 Patterns = parser.SupportedFileExtensions
             });

+ 2 - 2
src/PixiEditor.AvaloniaUI/Views/Palettes/PaletteViewer.axaml

@@ -56,8 +56,8 @@
                     </StackPanel>
                 </DockPanel>
             </StackPanel>
-            <Separator Grid.Row="1" Margin="0, 0, 0, 0" BorderBrush="{StaticResource DarkerAccentColor}" BorderThickness="2" />
-            <Grid IsVisible="False" Background="{StaticResource AccentColor}" Opacity="0.7" Grid.Row="2" Name="dragDropGrid">
+            <Separator Grid.Row="1" Margin="0, 0, 0, 0" BorderBrush="{DynamicResource ThemeControlLowBrush}" BorderThickness="2" />
+            <Grid IsVisible="False" Background="{DynamicResource ThemeControlHighlightBrush}" Opacity="0.7" Grid.Row="2" Name="dragDropGrid">
                 <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">

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

@@ -226,19 +226,25 @@ internal partial class PaletteViewer : UserControl
         dragDropGrid.IsVisible = false;
     }
 
-    private bool IsSupportedFilePresent(DragEventArgs e, out string filePath)
+    private bool IsSupportedFilePresent(DragEventArgs e, out string? filePath)
     {
         if (e.Data.Contains(DataFormats.Files))
         {
-            string[] files = (string[])e.Data.Get(DataFormats.Files);
+            IStorageItem[]? files = e.Data.GetFiles()?.ToArray();
+            if (files is null)
+            {
+                filePath = null;
+                return false;
+            }
+
             if (files is { Length: > 0 })
             {
-                var fileName = files[0];
+                IStorageItem file = files[0];
                 var foundParser = PaletteProvider.AvailableParsers.FirstOrDefault(x =>
-                    x.SupportedFileExtensions.Contains(Path.GetExtension(fileName)));
+                    x.SupportedFileExtensions.Contains(Path.GetExtension(file.Path.AbsolutePath)));
                 if (foundParser != null)
                 {
-                    filePath = fileName;
+                    filePath = file.Path.AbsolutePath;
                     return true;
                 }
             }