Browse Source

Update to ReactiveUI 20.2.45, move files to core, refactor & rename.

Ruben 7 months ago
parent
commit
b2e5b0d496

+ 1 - 1
src/PicView.Avalonia.MacOS/Views/MacMainWindow.axaml

@@ -8,7 +8,7 @@
     MinWidth="{CompiledBinding WindowMinSize}"
     SizeChanged="Control_OnSizeChanged"
     SizeToContent="{CompiledBinding SizeToContent}"
-    Title="{CompiledBinding WindowTitle}"
+    Title="{CompiledBinding PicViewer.WindowTitle}"
     x:Class="PicView.Avalonia.MacOS.Views.MacMainWindow"
     x:DataType="viewModels:MainViewModel"
     xmlns="https://github.com/avaloniaui"

+ 1 - 1
src/PicView.Avalonia.Win32/Views/WinMainWindow.axaml

@@ -5,7 +5,7 @@
     MinWidth="{CompiledBinding WindowMinSize}"
     SizeChanged="Control_OnSizeChanged"
     SizeToContent="{CompiledBinding SizeToContent}"
-    Title="{CompiledBinding WindowTitle,
+    Title="{CompiledBinding PicViewer.WindowTitle,
                             Mode=OneWay}"
     TransparencyLevelHint="AcrylicBlur"
     x:Class="PicView.Avalonia.Win32.Views.WinMainWindow"

+ 2 - 2
src/PicView.Avalonia/Crop/CropFunctions.cs

@@ -60,8 +60,8 @@ public static class CropFunctions
         vm.CurrentView = cropControl;
         
         IsCropping = true;
-        vm.Title = TranslationManager.Translation.CropMessage;
-        vm.TitleTooltip = TranslationManager.Translation.CropMessage;
+        vm.PicViewer.Title = TranslationManager.Translation.CropMessage;
+        vm.PicViewer.TitleTooltip = TranslationManager.Translation.CropMessage;
         
         FunctionsMapper.CloseMenus();
     }

+ 0 - 6
src/PicView.Avalonia/ImageHandling/GetImageModel.cs

@@ -41,12 +41,6 @@ public static class GetImageModel
             using var magickImage = new MagickImage();
             magickImage.Ping(fileInfo);
             
-            // If extension is missing, use format from MagickImage
-            if (string.IsNullOrEmpty(ext))
-            {
-                ext = $".{magickImage.Format.ToString().ToLower()}";
-            }
-            
             // Extract EXIF orientation early
             imageModel.EXIFOrientation = EXIFHelper.GetImageOrientation(magickImage);
 

+ 5 - 5
src/PicView.Avalonia/Navigation/NavigationManager.cs

@@ -321,7 +321,7 @@ public static class NavigationManager
         {
             vm.PlatformService.StopTaskbarProgress();
             await LoadWithoutImageIterator(new FileInfo(fileList[0]), vm, fileList);
-            if (vm.Title == TranslationManager.Translation.Loading)
+            if (vm.PicViewer.Title == TranslationManager.Translation.Loading)
             {
                 TitleManager.SetTitle(vm);
             }
@@ -545,9 +545,9 @@ public static class NavigationManager
 
                 var displayProgress = HttpManager.GetProgressDisplay(totalFileSize, totalBytesDownloaded,
                     progressPercentage);
-                vm.Title = displayProgress;
-                vm.TitleTooltip = displayProgress;
-                vm.WindowTitle = displayProgress;
+                vm.PicViewer.Title = displayProgress;
+                vm.PicViewer.TitleTooltip = displayProgress;
+                vm.PicViewer.WindowTitle = displayProgress;
                 if (Settings.UIProperties.IsTaskbarProgressEnabled)
                 {
                     vm.PlatformService.SetTaskbarProgress((ulong)totalBytesDownloaded, (ulong)totalFileSize);
@@ -817,7 +817,7 @@ public static class NavigationManager
         
         if (_imageIterator is null)
         {
-            var url = vm.Title.GetURL();
+            var url = vm.PicViewer.Title.GetURL();
             if (!string.IsNullOrEmpty(url))
             {
                 await LoadPicFromUrlAsync(url, vm).ConfigureAwait(false);

+ 3 - 3
src/PicView.Avalonia/Navigation/UpdateImage.cs

@@ -313,9 +313,9 @@ public static class UpdateImage
         await dispatchAction(() => { WindowResizing.SetSize(width, height, 0, 0, 0, vm); }, DispatcherPriority.Send);
 
         var singeImageWindowTitles = ImageTitleFormatter.GenerateTitleForSingleImage(width, height, name, 1);
-        vm.WindowTitle = singeImageWindowTitles.TitleWithAppName;
-        vm.Title = singeImageWindowTitles.BaseTitle;
-        vm.TitleTooltip = singeImageWindowTitles.BaseTitle;
+        vm.PicViewer.WindowTitle = singeImageWindowTitles.TitleWithAppName;
+        vm.PicViewer.Title = singeImageWindowTitles.BaseTitle;
+        vm.PicViewer.TitleTooltip = singeImageWindowTitles.BaseTitle;
 
         vm.PlatformService.StopTaskbarProgress();
 

+ 2 - 2
src/PicView.Avalonia/SettingsManagement/LanguageUpdater.cs

@@ -1,5 +1,5 @@
-using PicView.Avalonia.ViewModels;
-using PicView.Core.Localization;
+using PicView.Core.Localization;
+using PicView.Core.ViewModels;
 
 namespace PicView.Avalonia.SettingsManagement;
 

+ 26 - 26
src/PicView.Avalonia/UI/TitleManager.cs

@@ -22,10 +22,10 @@ public static class TitleManager
         if (!NavigationManager.CanNavigate(vm))
         {
             string title;
-            var s = vm.Title;
+            var s = vm.PicViewer.Title;
             if (!string.IsNullOrWhiteSpace(s.GetURL()))
             {
-                title = vm.Title.GetURL();
+                title = vm.PicViewer.Title.GetURL();
             }
             else if (s.Contains(TranslationManager.Translation.Base64Image))
             {
@@ -38,9 +38,9 @@ public static class TitleManager
 
             var singleImageWindowTitles =
                 ImageTitleFormatter.GenerateTitleForSingleImage(vm.PicViewer.PixelWidth, vm.PicViewer.PixelWidth, title, vm.ZoomValue);
-            vm.WindowTitle = singleImageWindowTitles.BaseTitle;
-            vm.Title = singleImageWindowTitles.TitleWithAppName;
-            vm.TitleTooltip = singleImageWindowTitles.TitleWithAppName;
+            vm.PicViewer.WindowTitle = singleImageWindowTitles.BaseTitle;
+            vm.PicViewer.Title = singleImageWindowTitles.TitleWithAppName;
+            vm.PicViewer.TitleTooltip = singleImageWindowTitles.TitleWithAppName;
             return;
         }
 
@@ -75,9 +75,9 @@ public static class TitleManager
         var windowTitles = ImageTitleFormatter.GenerateTitleStrings(vm.PicViewer.PixelWidth, vm.PicViewer.PixelHeight,
             NavigationManager.GetCurrentIndex,
             vm.PicViewer.FileInfo, vm.ZoomValue, NavigationManager.GetCollection);
-        vm.WindowTitle = windowTitles.TitleWithAppName;
-        vm.Title = windowTitles.BaseTitle;
-        vm.TitleTooltip = windowTitles.FilePathTitle;
+        vm.PicViewer.WindowTitle = windowTitles.TitleWithAppName;
+        vm.PicViewer.Title = windowTitles.BaseTitle;
+        vm.PicViewer.TitleTooltip = windowTitles.FilePathTitle;
     }
 
     /// <summary>
@@ -87,9 +87,9 @@ public static class TitleManager
     /// <param name="vm">The main view model instance.</param>
     public static void SetLoadingTitle(MainViewModel vm)
     {
-        vm.WindowTitle = $"{TranslationManager.Translation.Loading} - PicView";
-        vm.Title = TranslationManager.Translation.Loading;
-        vm.TitleTooltip = vm.Title;
+        vm.PicViewer.WindowTitle = $"{TranslationManager.Translation.Loading} - PicView";
+        vm.PicViewer.Title = TranslationManager.Translation.Loading;
+        vm.PicViewer.TitleTooltip = vm.PicViewer.Title;
     }
 
     /// <summary>
@@ -118,9 +118,9 @@ public static class TitleManager
         var windowTitles = ImageTitleFormatter.GenerateTitleStrings(imageModel.PixelWidth, imageModel.PixelHeight,
             NavigationManager.GetCurrentIndex,
             imageModel.FileInfo, vm.ZoomValue, NavigationManager.GetCollection);
-        vm.WindowTitle = windowTitles.TitleWithAppName;
-        vm.Title = windowTitles.BaseTitle;
-        vm.TitleTooltip = windowTitles.FilePathTitle;
+        vm.PicViewer.WindowTitle = windowTitles.TitleWithAppName;
+        vm.PicViewer.Title = windowTitles.BaseTitle;
+        vm.PicViewer.TitleTooltip = windowTitles.FilePathTitle;
     }
 
     /// <summary>
@@ -142,9 +142,9 @@ public static class TitleManager
     {
         var singeImageWindowTitles = ImageTitleFormatter.GenerateTiffTitleStrings(width, height, index, fileInfo,
             tiffNavigationInfo, 1, NavigationManager.GetCollection);
-        vm.WindowTitle = singeImageWindowTitles.TitleWithAppName;
-        vm.Title = singeImageWindowTitles.BaseTitle;
-        vm.TitleTooltip = singeImageWindowTitles.BaseTitle;
+        vm.PicViewer.WindowTitle = singeImageWindowTitles.TitleWithAppName;
+        vm.PicViewer.Title = singeImageWindowTitles.BaseTitle;
+        vm.PicViewer.TitleTooltip = singeImageWindowTitles.BaseTitle;
     }
 
     /// <summary>
@@ -241,9 +241,9 @@ public static class TitleManager
         var windowTitle = $"{firstWindowTitles.BaseTitle} \u21dc || \u21dd {secondWindowTitles.BaseTitle} - PicView";
         var title = $"{firstWindowTitles.BaseTitle} \u21dc || \u21dd  {secondWindowTitles.BaseTitle}";
         var titleTooltip = $"{firstWindowTitles.FilePathTitle} \u21dc || \u21dd  {secondWindowTitles.FilePathTitle}";
-        vm.WindowTitle = windowTitle;
-        vm.Title = title;
-        vm.TitleTooltip = titleTooltip;
+        vm.PicViewer.WindowTitle = windowTitle;
+        vm.PicViewer.Title = title;
+        vm.PicViewer.TitleTooltip = titleTooltip;
     }
 
     /// <summary>
@@ -256,16 +256,16 @@ public static class TitleManager
     /// </remarks>
     public static void SetNoImageTitle(MainViewModel vm)
     {
-        vm.Title = TranslationManager.Translation.NoImage;
-        vm.WindowTitle = TranslationManager.Translation.NoImage + " - PicView";
-        vm.TitleTooltip = TranslationManager.Translation.NoImage;
+        vm.PicViewer.Title = TranslationManager.Translation.NoImage;
+        vm.PicViewer.WindowTitle = TranslationManager.Translation.NoImage + " - PicView";
+        vm.PicViewer.TitleTooltip = TranslationManager.Translation.NoImage;
     }
 
     private static void ReturnError(MainViewModel vm)
     {
-        vm.WindowTitle =
-            vm.Title =
-                vm.TitleTooltip = TranslationManager.GetTranslation("UnableToRender");
+        vm.PicViewer.WindowTitle =
+            vm.PicViewer.Title =
+                vm.PicViewer.TitleTooltip = TranslationManager.GetTranslation("UnableToRender");
     }
 
     private static bool ValidateImageModel(ImageModel? imageModel, MainViewModel vm)

+ 1 - 19
src/PicView.Avalonia/ViewModels/MainViewModel.cs

@@ -16,10 +16,10 @@ using PicView.Avalonia.UI;
 using PicView.Avalonia.Wallpaper;
 using PicView.Avalonia.WindowBehavior;
 using PicView.Core.Calculations;
-using PicView.Core.Config;
 using PicView.Core.FileHandling;
 using PicView.Core.Gallery;
 using PicView.Core.ProcessHandling;
+using PicView.Core.ViewModels;
 using ReactiveUI;
 using ImageViewer = PicView.Avalonia.Views.ImageViewer;
 
@@ -970,24 +970,6 @@ public class MainViewModel : ReactiveObject
     
     #region Window Properties
 
-    public string? Title
-    {
-        get;
-        set => this.RaiseAndSetIfChanged(ref field, value);
-    } = "Loading...";
-
-    public string? TitleTooltip
-    {
-        get;
-        set => this.RaiseAndSetIfChanged(ref field, value);
-    } = "Loading...";
-
-    public string? WindowTitle
-    {
-        get;
-        set => this.RaiseAndSetIfChanged(ref field, value);
-    } = "PicView";
-
     public SizeToContent SizeToContent
     {
         get;

+ 16 - 2
src/PicView.Avalonia/Views/EffectsView.axaml.cs

@@ -6,9 +6,10 @@ using Avalonia.Input;
 using Avalonia.LogicalTree;
 using Avalonia.Threading;
 using ImageMagick;
-using PicView.Avalonia.ImageEffects;
+using PicView.Avalonia.ImageHandling;
 using PicView.Avalonia.Navigation;
 using PicView.Avalonia.ViewModels;
+using PicView.Core.ImageEffects;
 using ReactiveUI;
 using Timer = System.Timers.Timer;
 
@@ -156,7 +157,20 @@ public partial class EffectsView : UserControl
         MainViewModel? vm = null;
         await Dispatcher.UIThread.InvokeAsync(() => { vm = DataContext as MainViewModel; });
         
-        await ImageEffectsHelper.ApplyEffects(vm, vm.PicViewer.EffectConfig, _cancellationTokenSource.Token).ConfigureAwait(false);
+        vm.IsLoading = true;
+
+        try
+        {
+            var magick = await ImageEffectsHelper.ApplyEffects(vm.PicViewer.FileInfo, vm.PicViewer.EffectConfig, _cancellationTokenSource.Token).ConfigureAwait(false);
+            if (magick is not null)
+            {
+                vm.PicViewer.ImageSource = magick.ToWriteableBitmap();
+            }
+        }
+        finally
+        {
+            vm.IsLoading = false;
+        }
     }
 
     public async Task RemoveEffects(MainViewModel vm)

+ 2 - 2
src/PicView.Avalonia/Views/UC/EditableTitlebar.axaml

@@ -1,7 +1,7 @@
 <UserControl
     Height="{CompiledBinding TitlebarHeight,
                              Mode=OneWay}"
-    ToolTip.Tip="{Binding TitleTooltip, Mode=OneWay}"
+    ToolTip.Tip="{Binding PicViewer.TitleTooltip, Mode=OneWay}"
     Width="{CompiledBinding TitleMaxWidth,
                             Mode=OneWay}"
     d:DesignHeight="450"
@@ -25,7 +25,7 @@
             IsTabStop="False"
             IsVisible="{CompiledBinding !IsEditableTitlebarOpen}"
             Padding="0,7,0,5"
-            Text="{CompiledBinding Title,
+            Text="{CompiledBinding PicViewer.Title,
                                    Mode=OneWay}"
             TextAlignment="Center"
             TextTrimming="CharacterEllipsis"

+ 1 - 1
src/PicView.Avalonia/Views/UC/EditableTitlebar.axaml.cs

@@ -71,7 +71,7 @@ public partial class EditableTitlebar : UserControl
         vm.IsEditableTitlebarOpen = false;
         Cursor = new Cursor(StandardCursorType.Arrow);
         MainKeyboardShortcuts.IsKeysEnabled = true;
-        TextBlock.Text = vm.Title;
+        TextBlock.Text = vm.PicViewer.Title;
     }
     
     #region Rename

+ 2 - 2
src/PicView.Avalonia/Views/UC/TitleTextBox.axaml

@@ -25,11 +25,11 @@
                                      Mode=OneWay}"
             IsTabStop="False"
             Padding="0,7,0,5"
-            Text="{CompiledBinding Title,
+            Text="{CompiledBinding PicViewer.Title,
                                    Mode=OneWay}"
             TextAlignment="Center"
             TextTrimming="CharacterEllipsis"
-            ToolTip.Tip="{CompiledBinding TitleTooltip,
+            ToolTip.Tip="{CompiledBinding PicViewer.TitleTooltip,
                                           Mode=OneWay}"
             VerticalAlignment="Center" />
         <TextBox

+ 1 - 1
src/PicView.Avalonia/WindowBehavior/WindowFunctions.cs

@@ -56,7 +56,7 @@ public static class WindowFunctions
         }
         else
         {
-            var url = vm?.Title.GetURL();
+            var url = vm?.PicViewer.Title.GetURL();
             lastFile = !string.IsNullOrWhiteSpace(url) ? url : FileHistory.GetLastEntry();
         }
 

+ 0 - 0
src/PicView.Avalonia/ImageHandling/ImageType.cs → src/PicView.Core/ImageDecoding/ImageType.cs


+ 1 - 1
src/PicView.Avalonia/ImageEffects/ImageEffectConfig.cs → src/PicView.Core/ImageEffects/ImageEffectConfig.cs

@@ -1,6 +1,6 @@
 using ImageMagick;
 
-namespace PicView.Avalonia.ImageEffects;
+namespace PicView.Core.ImageEffects;
 
 public class ImageEffectConfig
 {

+ 10 - 18
src/PicView.Avalonia/ImageEffects/ImageEffectsHelper.cs → src/PicView.Core/ImageEffects/ImageEffectsHelper.cs

@@ -1,19 +1,16 @@
-using Avalonia.Media.Imaging;
-using ImageMagick;
-using PicView.Avalonia.ImageHandling;
-using PicView.Avalonia.ViewModels;
+using ImageMagick;
 using PicView.Core.FileHandling;
 
-namespace PicView.Avalonia.ImageEffects;
+namespace PicView.Core.ImageEffects;
 
 public static class ImageEffectsHelper
 {
-    public static async Task<WriteableBitmap> GetRadialBlur(string file)
+    public static async Task<MagickImage?> GetRadialBlur(string file)
     {
-        using var magick = new MagickImage();
+        var magick = new MagickImage();
         await magick.ReadAsync(file).ConfigureAwait(false);
         ApplyRadialBlur(magick);
-        return magick.ToWriteableBitmap();
+        return magick;
     }
 
     private static void ApplyRadialBlur(MagickImage magick)
@@ -27,17 +24,15 @@ public static class ImageEffectsHelper
         magick.Morphology(morphology);
     }
     
-    public static async Task ApplyEffects(MainViewModel vm, ImageEffectConfig config, CancellationToken cancellationToken)
+    public static async Task<MagickImage?> ApplyEffects(FileInfo fileInfo, ImageEffectConfig config, CancellationToken cancellationToken)
     {
-        vm.IsLoading = true;
         try
         {
-            await Task.Run(async () =>
+            return await Task.Run(async () =>
             {
-                using var magick = await LoadImage(vm.PicViewer.FileInfo, cancellationToken);
+                var magick = await LoadImage(fileInfo, cancellationToken);
                 ApplyImageEffects(magick, config, cancellationToken);
-                var bitmap = magick.ToWriteableBitmap();
-                vm.PicViewer.ImageSource = bitmap;
+                return magick;
             }, cancellationToken).ConfigureAwait(false);
         }
         catch (OperationCanceledException)
@@ -50,10 +45,7 @@ public static class ImageEffectsHelper
             Console.WriteLine(e);
 #endif
         }
-        finally
-        {
-            vm.IsLoading = false;
-        }
+        return null;
     }
 
     private static async Task<MagickImage> LoadImage(FileInfo fileInfo, CancellationToken cancellationToken)

+ 1 - 0
src/PicView.Core/PicView.Core.csproj

@@ -25,6 +25,7 @@
   </PropertyGroup>
   <ItemGroup>
     <PackageReference Include="Magick.NET-Q8-OpenMP-x64" Version="14.3.0" />
+    <PackageReference Include="ReactiveUI" Version="20.2.45" />
     <PackageReference Include="SharpCompress" Version="0.39.0" />
     <PackageReference Include="ZString" Version="2.6.0" />
   </ItemGroup>

+ 1 - 1
src/PicView.Avalonia/ViewModels/ExifViewModel.cs → src/PicView.Core/ViewModels/ExifViewModel.cs

@@ -1,6 +1,6 @@
 using ReactiveUI;
 
-namespace PicView.Avalonia.ViewModels;
+namespace PicView.Core.ViewModels;
 
 public class ExifViewModel : ReactiveObject
 {

+ 21 - 3
src/PicView.Avalonia/ViewModels/PicViewerModel.cs → src/PicView.Core/ViewModels/PicViewerModel.cs

@@ -1,9 +1,9 @@
-using PicView.Avalonia.ImageEffects;
-using PicView.Avalonia.ImageHandling;
+using PicView.Avalonia.ImageHandling;
 using PicView.Core.ImageDecoding;
+using PicView.Core.ImageEffects;
 using ReactiveUI;
 
-namespace PicView.Avalonia.ViewModels;
+namespace PicView.Core.ViewModels;
 
 public class PicViewerModel : ReactiveObject
 {
@@ -116,4 +116,22 @@ public class PicViewerModel : ReactiveObject
         get;
         set => this.RaiseAndSetIfChanged(ref field, value);
     } = 1;
+    
+    public string? Title
+    {
+        get;
+        set => this.RaiseAndSetIfChanged(ref field, value);
+    } = "Loading...";
+
+    public string? TitleTooltip
+    {
+        get;
+        set => this.RaiseAndSetIfChanged(ref field, value);
+    } = "Loading...";
+
+    public string? WindowTitle
+    {
+        get;
+        set => this.RaiseAndSetIfChanged(ref field, value);
+    } = "PicView";
 }

+ 1 - 1
src/PicView.Avalonia/ViewModels/PupUpViewModel.cs → src/PicView.Core/ViewModels/PupUpViewModel.cs

@@ -1,7 +1,7 @@
 using System.Reactive;
 using ReactiveUI;
 
-namespace PicView.Avalonia.ViewModels;
+namespace PicView.Core.ViewModels;
 
 public class PopUpViewModel : ReactiveObject
 {

+ 1 - 1
src/PicView.Avalonia/ViewModels/TranslationViewModel.cs → src/PicView.Core/ViewModels/TranslationViewModel.cs

@@ -2,7 +2,7 @@
 using PicView.Core.Localization;
 using ReactiveUI;
 
-namespace PicView.Avalonia.ViewModels;
+namespace PicView.Core.ViewModels;
 
 public class TranslationViewModel : ReactiveObject
 {