Explorar o código

Clean up and improve

Ruben hai 8 meses
pai
achega
c5e6c426f5

+ 12 - 6
src/PicView.Avalonia/CustomControls/PicBox.cs

@@ -200,17 +200,19 @@ public class PicBox : Control
 
     private void RenderBasedOnSettings(DrawingContext context, IImage source)
     {
-        var is1To1 = false; // TODO: replace with settings value
-        var isSideBySide = Settings.ImageScaling.ShowImageSideBySide;
-        var secondarySource = SecondarySource as IImage;
-        
-        var viewPort = DetermineViewPort();
-        Size sourceSize;
         if (source is null)
         {
             return;
         }
+        
+        const bool is1To1 = false; // TODO: replace with settings value
+        var isSideBySide = Settings.ImageScaling.ShowImageSideBySide;
+        var secondarySource = SecondarySource as IImage;
+        var viewPort = DetermineViewPort();
+        
+        Size sourceSize;
         Size? secondarySourceSize = null;
+        
         try
         {
             sourceSize = source.Size;
@@ -382,6 +384,10 @@ public class PicBox : Control
     /// <returns>The desired size of the control.</returns>
     protected override Size MeasureOverride(Size availableSize)
     {
+        if (Source is null)
+        {
+            return new Size();
+        }
         try
         {
             return Source is not IImage source ? new Size() : CalculateSize(availableSize, source.Size);

+ 1 - 1
src/PicView.Avalonia/Navigation/ImageIterator.cs

@@ -499,7 +499,7 @@ public class ImageIterator : IAsyncDisposable
             if (preloadValue is not null)
             {
                 // Wait for image to load
-                if (preloadValue is { IsLoading: true, ImageModel.Image: not null })
+                if (preloadValue is { IsLoading: true, ImageModel.Image: null })
                 {
                     UpdateImage.LoadingPreview(_vm, CurrentIndex);
 

+ 0 - 3
src/PicView.Avalonia/Navigation/NavigationManager.cs

@@ -775,9 +775,6 @@ public static class NavigationManager
     
     public static void AddToPreloader(int index, ImageModel imageModel) => _imageIterator?.Add(index, imageModel);
     public static async Task PreloadAsync() => await _imageIterator?.PreloadAsync();
-    
-    public static void RemoveCurrentItemFromPreLoader() => _imageIterator?.RemoveItemFromPreLoader(_imageIterator.CurrentIndex);
-    public static void RemoveItemFromPreLoader(string fileName) => _imageIterator?.RemoveItemFromPreLoader(fileName);
 
     #endregion
 

+ 2 - 3
src/PicView.Avalonia/Preloading/Preloader.cs

@@ -479,7 +479,6 @@ public class PreLoader : IAsyncDisposable
 
         try
         {
-            _cancellationTokenSource.CancelAfter(TimeSpan.FromMinutes(5));
             await PreLoadInternalAsync(currentIndex, reverse, list, _cancellationTokenSource.Token)
                 .ConfigureAwait(false);
         }
@@ -560,10 +559,10 @@ public class PreLoader : IAsyncDisposable
                 return;
             }
 
-            do
+            while (_preLoadList.Count > PreLoaderConfig.MaxCount)
             {
                 Remove(reverse ? _preLoadList.Keys.Max() : _preLoadList.Keys.Min(), list);
-            } while (_preLoadList.Count > PreLoaderConfig.MaxCount);
+            }
         }
     }
 

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

@@ -68,7 +68,6 @@ public partial class EditableTitlebar : UserControl
         {
             return;
         }
-        SetTitleHelper.RefreshTitle(vm);
         vm.IsEditableTitlebarOpen = false;
         Cursor = new Cursor(StandardCursorType.Arrow);
         MainKeyboardShortcuts.IsKeysEnabled = true;
@@ -140,22 +139,6 @@ public partial class EditableTitlebar : UserControl
             return;
         }
         
-        // Check if the file is being moved to a different directory
-        if (Path.GetDirectoryName(oldPath) != Path.GetDirectoryName(newPath))
-        {
-            await Dispatcher.UIThread.InvokeAsync(() =>
-            {
-                TextBox.ClearSelection();
-                Cursor = new Cursor(StandardCursorType.Arrow);
-                MainKeyboardShortcuts.IsKeysEnabled = true;
-                UIHelper.GetMainView.Focus();
-            });
-            NavigationManager.RemoveCurrentItemFromPreLoader();
-            await NavigationManager.Navigate(true, vm);
-            FileHelper.RenameFile(oldPath, newPath);
-            return;
-        }
-        
         // Handle renaming with different extensions
         if (Path.GetExtension(newPath) != Path.GetExtension(oldPath))
         {
@@ -167,9 +150,6 @@ public partial class EditableTitlebar : UserControl
 
             if (saved)
             {
-                // Delete old file
-                NavigationManager.RemoveItemFromPreLoader(oldPath);
-                
                 var deleteMsg = FileDeletionHelper.DeleteFileWithErrorMsg(oldPath, false);
                 if (!string.IsNullOrWhiteSpace(deleteMsg))
                 {