Browse Source

fix file dialog filter nullable annotation, and osx platform.

Dan Walmsley 3 năm trước cách đây
mục cha
commit
af237c6dd7

+ 2 - 1
samples/ControlCatalog/ControlCatalog.csproj

@@ -1,7 +1,8 @@
 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
     <TargetFramework>netstandard2.0</TargetFramework>
-    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>    
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+    <Nullable>enable</Nullable>    
   </PropertyGroup>
   <ItemGroup>
     <Compile Update="**\*.xaml.cs">

+ 1 - 2
samples/ControlCatalog/Pages/DialogsPage.xaml.cs

@@ -8,7 +8,6 @@ using Avalonia.Dialogs;
 using Avalonia.Layout;
 using Avalonia.Markup.Xaml;
 #pragma warning disable 4014
-
 namespace ControlCatalog.Pages
 {
     public class DialogsPage : UserControl
@@ -22,7 +21,7 @@ namespace ControlCatalog.Pages
 
             string lastSelectedDirectory = null;
 
-            List<FileDialogFilter> GetFilters()
+            List<FileDialogFilter>? GetFilters()
             {
                 if (this.FindControl<CheckBox>("UseFilters").IsChecked != true)
                     return null;

+ 1 - 1
src/Avalonia.Controls/SystemDialog.cs

@@ -15,7 +15,7 @@ namespace Avalonia.Controls
         /// Gets or sets a collection of filters which determine the types of files displayed in an
         /// <see cref="OpenFileDialog"/> or an <see cref="SaveFileDialog"/>.
         /// </summary>
-        public List<FileDialogFilter> Filters { get; set; } = new List<FileDialogFilter>();
+        public List<FileDialogFilter>? Filters { get; set; } = new List<FileDialogFilter>();
 
         /// <summary>
         /// Gets or sets initial file name that is displayed when the dialog is opened.

+ 2 - 2
src/Avalonia.Native/SystemDialogs.cs

@@ -30,7 +30,7 @@ namespace Avalonia.Native
                                         ofd.Title ?? "",
                                         ofd.Directory ?? "",
                                         ofd.InitialFileName ?? "",
-                                        string.Join(";", dialog.Filters.SelectMany(f => f.Extensions)));
+                                        string.Join(";", dialog.Filters?.SelectMany(f => f.Extensions) ?? Array.Empty<string>()));
             }
             else
             {
@@ -39,7 +39,7 @@ namespace Avalonia.Native
                                         dialog.Title ?? "",
                                         dialog.Directory ?? "",
                                         dialog.InitialFileName ?? "",
-                                        string.Join(";", dialog.Filters.SelectMany(f => f.Extensions)));
+                                        string.Join(";", dialog.Filters?.SelectMany(f => f.Extensions) ?? Array.Empty<string>()));
             }
 
             return events.Task.ContinueWith(t => { events.Dispose(); return t.Result; });