Kaynağa Gözat

More null and exception checks

Krzysztof Krysiński 3 hafta önce
ebeveyn
işleme
dd4b58e81c

+ 14 - 2
src/PixiEditor/ViewModels/SettingsWindowViewModel.cs

@@ -170,11 +170,23 @@ internal partial class SettingsWindowViewModel : ViewModelBase
         {
             Patterns = fileTypes.SelectMany(a => a.Patterns).ToList(),
         });
-        
+
+        IStorageFolder? suggestedLocation = null;
+        try
+        {
+            suggestedLocation =
+                await MainWindow.Current!.StorageProvider.TryGetWellKnownFolderAsync(WellKnownFolder.Documents);
+        }
+        catch (Exception)
+        {
+            // If we can't get the documents folder, we will just use the default location
+            // This is not a critical error, so we can ignore it
+        }
+
         IReadOnlyList<IStorageFile> files = await MainWindow.Current!.StorageProvider.OpenFilePickerAsync(new()
         {
             AllowMultiple = false,
-            SuggestedStartLocation = await MainWindow.Current!.StorageProvider.TryGetWellKnownFolderAsync(WellKnownFolder.Documents),
+            SuggestedStartLocation = suggestedLocation,
             FileTypeFilter = fileTypes,
         });
         

+ 15 - 2
src/PixiEditor/Views/Nodes/Properties/StringPropertyView.axaml.cs

@@ -17,14 +17,16 @@ namespace PixiEditor.Views.Nodes.Properties;
 
 public partial class StringPropertyView : NodePropertyView
 {
-    public static readonly StyledProperty<ICommand> OpenInDefaultAppCommandProperty = AvaloniaProperty.Register<StringPropertyView, ICommand>(
-        nameof(OpenInDefaultAppCommand));
+    public static readonly StyledProperty<ICommand> OpenInDefaultAppCommandProperty =
+        AvaloniaProperty.Register<StringPropertyView, ICommand>(
+            nameof(OpenInDefaultAppCommand));
 
     public ICommand OpenInDefaultAppCommand
     {
         get => GetValue(OpenInDefaultAppCommandProperty);
         set => SetValue(OpenInDefaultAppCommandProperty, value);
     }
+
     public StringPropertyView()
     {
         InitializeComponent();
@@ -33,7 +35,18 @@ public partial class StringPropertyView : NodePropertyView
     protected override void OnLoaded(RoutedEventArgs e)
     {
         base.OnLoaded(e);
+        if (smallTextBox is null)
+        {
+            return;
+        }
+
         ScrollViewer scroll = smallTextBox.FindDescendantOfType<ScrollViewer>();
+
+        if (scroll is null)
+        {
+            return;
+        }
+
         scroll.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
         scroll.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled;
     }