Prechádzať zdrojové kódy

Save `Quality`, `Compression` and `Conversion` in the `Batch resize` window #204

Ruben 4 mesiacov pred
rodič
commit
359809e202

+ 13 - 0
src/PicView.Avalonia.MacOS/Views/BatchResizeWindow.axaml.cs

@@ -31,6 +31,19 @@ public partial class BatchResizeWindow : Window, IDisposable
                 .AddTo(_disposables);
             PositionChanged += (_, _) => UpdateWindowPosition();
         };
+        
+        Closing += async delegate
+        {
+            Hide();
+            if (VisualRoot is null)
+            {
+                return;
+            }
+
+            var hostWindow = (Window)VisualRoot;
+            hostWindow?.Focus();
+            await _config.SaveAsync();
+        };
     }
     
     private void UpdateWindowPosition()

+ 13 - 0
src/PicView.Avalonia.Win32/Views/BatchResizeResizeWindow.axaml.cs

@@ -78,6 +78,19 @@ public partial class BatchResizeWindow : Window, IDisposable
                 .AddTo(_disposables);
             PositionChanged += (_, _) => UpdateWindowPosition();
         };
+        
+        Closing += async delegate
+        {
+            Hide();
+            if (VisualRoot is null)
+            {
+                return;
+            }
+
+            var hostWindow = (Window)VisualRoot;
+            hostWindow?.BringIntoView();
+            await _config.SaveAsync();
+        };
     }
 
     private void MoveWindow(object? sender, PointerPressedEventArgs e)

+ 1 - 1
src/PicView.Avalonia.Win32/WindowImpl/WindowInitializer.cs

@@ -332,7 +332,7 @@ public class WindowInitializer : IPlatformSpecificUpdate
 
         void Show()
         {
-            WindowFunctions.InitializeWindowSizeAndPosition(_batchResizeWindow, vm.Window.BatchResizeWindowConfig.WindowProperties);
+            WindowFunctions.InitializeWindowPosition(_batchResizeWindow, vm.Window.BatchResizeWindowConfig.WindowProperties);
             _batchResizeWindow.Show(desktop.MainWindow);
         }
     }

+ 3 - 5
src/PicView.Avalonia/Views/Main/BatchResizeView.axaml

@@ -92,8 +92,7 @@
                         Height="30"
                         Margin="11,0,10,0"
                         Padding="5,7,0,7"
-                        SelectedIndex="0"
-                        SelectedItem="NoConversion"
+                        SelectedIndex="{CompiledBinding Window.BatchResizeWindowConfig.WindowProperties.ConvertToIndex}"
                         Width="195"
                         x:Name="ConversionComboBox">
                         <ComboBoxItem
@@ -146,8 +145,7 @@
                         Height="30"
                         Margin="11,0,10,0"
                         Padding="5,7,0,7"
-                        SelectedIndex="0"
-                        SelectedItem="Lossless"
+                        SelectedIndex="{CompiledBinding Window.BatchResizeWindowConfig.WindowProperties.CompressionIndex}"
                         Width="195"
                         x:Name="CompressionComboBox">
                         <ComboBoxItem
@@ -179,7 +177,7 @@
                         Width="130" />
 
                     <CheckBox
-                        IsChecked="False"
+                        IsChecked="{CompiledBinding Window.BatchResizeWindowConfig.WindowProperties.IsQualityEnabled}"
                         Margin="11,0,10,0"
                         x:Name="IsQualityEnabledBox" />
                     <customControls:CustomSlider

+ 1 - 3
src/PicView.Avalonia/Views/Main/BatchResizeView.axaml.cs

@@ -552,9 +552,7 @@ public partial class BatchResizeView : UserControl
         }
         catch (Exception e)
         {
-#if DEBUG
-            Console.WriteLine(e);
-#endif
+            DebugHelper.LogDebug(nameof(BatchResizeView), nameof(StartBatchResize), e);
         }
         finally
         {

+ 5 - 0
src/PicView.Avalonia/WindowBehavior/WindowFunctions.cs

@@ -81,6 +81,11 @@ public static class WindowFunctions
             await vm.Window.ImageInfoWindowConfig.SaveAsync();
         }
 
+        if (vm.Window.BatchResizeWindowConfig is not null)
+        {
+            await vm.Window.BatchResizeWindowConfig.SaveAsync();
+        }
+
         Environment.Exit(0);
     }
 

+ 2 - 2
src/PicView.Core/Config/BatchResizeWindowConfig.cs

@@ -20,7 +20,7 @@ public class BatchResizeWindowConfig() : ConfigFile("BatchResizeWindow.json")
             {
                 var jsonString = await File.ReadAllTextAsync(CorrectPath).ConfigureAwait(false);
                 if (JsonSerializer.Deserialize(
-                        jsonString, typeof(BatchResizeWindowProperties), SettingsWindowGenerationContext.Default) is BatchResizeWindowProperties settings)
+                        jsonString, typeof(BatchResizeWindowProperties), BatchResizeWindowGenerationContext.Default) is BatchResizeWindowProperties settings)
                 {
                     WindowProperties = settings;
                 }
@@ -43,7 +43,7 @@ public class BatchResizeWindowConfig() : ConfigFile("BatchResizeWindow.json")
     public async Task SaveAsync()
     {
         CorrectPath = await ConfigFileManager.SaveConfigFileAndReturnPathAsync(this,
-            CorrectPath, WindowProperties, typeof(BatchResizeWindowProperties), SettingsWindowGenerationContext.Default);
+            CorrectPath, WindowProperties, typeof(BatchResizeWindowProperties), BatchResizeWindowGenerationContext.Default);
     }
     
     public class BatchResizeWindowProperties : IWindowProperties