Explorar o código

Attempt to fix code issues

Ruben %!s(int64=5) %!d(string=hai) anos
pai
achega
4ba0dee17a

+ 5 - 4
PicView/ChangeImage/Navigation.cs

@@ -115,11 +115,14 @@ namespace PicView.ChangeImage
             if (FreshStartup)
                 Trace.WriteLine("Pic(string path) entering Pic(int x)");
 #endif
+            if (ajaxLoading.Opacity != 0)
+            {
+                AjaxLoadingEnd();
+            }
 
             // Navigate to picture using obtained index
             await Pic(FolderIndex).ConfigureAwait(false);
-
-            AjaxLoadingEnd();
+            
 
             prevPicResource = null; // Make sure to not waste memory
         }
@@ -257,12 +260,10 @@ namespace PicView.ChangeImage
             }
 
             FreshStartup = false;
-
 #if DEBUG
             stopWatch.Stop();
             var s = $"Pic(); executed in {stopWatch.Elapsed.TotalMilliseconds} milliseconds";
             Trace.WriteLine(s);
-            //ToolTipStyle(s);
 #endif
         }
 

+ 36 - 37
PicView/FileHandling/FileLists.cs

@@ -141,7 +141,7 @@ namespace PicView.FileHandling
 
             switch (sortFilesBy)
             {
-                // Alphanumeric sort
+                default:  // Alphanumeric sort
                 case SortFilesBy.Name:
                     var list = items.ToList();
                     list.Sort((x, y) => { return SystemIntegration.NativeMethods.StrCmpLogicalW(x, y); });
@@ -181,48 +181,47 @@ namespace PicView.FileHandling
         /// <returns></returns>
         internal static async Task GetValues(string path)
         {
-            await Task.Run(() =>
+            var extension = Path.GetExtension(path);
+            extension = extension.ToLower(CultureInfo.CurrentCulture);
+            switch (extension)
             {
-                var extension = Path.GetExtension(path);
-                extension = extension.ToLower(CultureInfo.CurrentCulture);
-                switch (extension)
-                {
-                    // Archives
-                    case ".zip":
-                    case ".7zip":
-                    case ".7z":
-                    case ".rar":
-                    case ".cbr":
-                    case ".cb7":
-                    case ".cbt":
-                    case ".cbz":
-                    case ".xz":
-                    case ".bzip2":
-                    case ".gzip":
-                    case ".tar":
-                    case ".wim":
-                    case ".iso":
-                    case ".cab":
-                        if (!Extract(path))
-                        {
-                            Error_Handling.Reload(true);
-                        }
-                        return;
-                }
-
-                // Set files to Pics and get index
-                Pics = FileList(Path.GetDirectoryName(path));
-                if (Pics == null)
-                {
+                // Archives
+                case ".zip":
+                case ".7zip":
+                case ".7z":
+                case ".rar":
+                case ".cbr":
+                case ".cb7":
+                case ".cbt":
+                case ".cbz":
+                case ".xz":
+                case ".bzip2":
+                case ".gzip":
+                case ".tar":
+                case ".wim":
+                case ".iso":
+                case ".cab":
+                    if (!Extract(path))
+                    {
+                        await Error_Handling.Reload(true).ConfigureAwait(false);
+                    }
                     return;
-                }
+            }
+
+            // Set files to Pics and get index
+            Pics = FileList(Path.GetDirectoryName(path));
+            if (Pics == null)
+            {
+                return;
+            }
 
-                FolderIndex = Pics.IndexOf(path);
+            FolderIndex = Pics.IndexOf(path);
 
 #if DEBUG
-                Trace.WriteLine("Getvalues completed ");
+            Trace.WriteLine("Getvalues completed ");
 #endif
-            }).ConfigureAwait(false);
         }
+
+
     }
 }

+ 25 - 20
PicView/Shortcuts/MainShortcuts.cs

@@ -24,7 +24,7 @@ namespace PicView.Shortcuts
 {
     internal static class MainShortcuts
     {
-        internal static void MainWindow_KeysDown(object sender, KeyEventArgs e)
+        internal static async System.Threading.Tasks.Task MainWindow_KeysDownAsync(object sender, KeyEventArgs e)
         {
             // Don't allow keys when typing in text
             if (mainWindow.Bar.IsKeyboardFocusWithin) { return; }
@@ -94,11 +94,11 @@ namespace PicView.Shortcuts
                         // Go to first if Ctrl held down
                         if (ctrlDown)
                         {
-                            Pic(true, true);
+                            await Pic(true, true).ConfigureAwait(false);
                         }
                         else
                         {
-                            Pic();
+                            await Pic().ConfigureAwait(false);
                         }
                     }
                     else if (CanNavigate)
@@ -125,11 +125,11 @@ namespace PicView.Shortcuts
                         // Go to last if Ctrl held down
                         if (ctrlDown)
                         {
-                            Pic(false, true);
+                            await Pic(false, true).ConfigureAwait(false);
                         }
                         else
                         {
-                            Pic(false);
+                            await Pic(false).ConfigureAwait(false);
                         }
                     }
                     else if (CanNavigate)
@@ -198,7 +198,7 @@ namespace PicView.Shortcuts
                             }
                             else
                             {
-                                Pic(false);
+                                await Pic(false).ConfigureAwait(false);
                             }
                         }
                         else
@@ -217,7 +217,7 @@ namespace PicView.Shortcuts
                 case Key.S:
                     if (ctrlDown && picGallery != null && !GalleryFunctions.IsOpen)
                     {
-                        SaveFiles();
+                        await SaveFiles().ConfigureAwait(false);
                     }
                     else if (Properties.Settings.Default.ScrollEnabled)
                     {
@@ -238,7 +238,7 @@ namespace PicView.Shortcuts
                             }
                             else
                             {
-                                Pic();
+                                await Pic().ConfigureAwait(false);
                             }
                         }
                         else
@@ -263,6 +263,7 @@ namespace PicView.Shortcuts
                 case Key.OemMinus:
                     Zoom(-1, ctrlDown);
                     return;
+                default: break; // Please automatic code analyzers...
             }
 
             #endregion Keys where it can be held down
@@ -297,7 +298,7 @@ namespace PicView.Shortcuts
                         }
                         if (GalleryFunctions.IsOpen)
                         {
-                            Toggle();
+                            await ToggleAsync().ConfigureAwait(false);
                             return;
                         }
                         if (IsDialogOpen)
@@ -338,7 +339,7 @@ namespace PicView.Shortcuts
 
                     // O, Ctrl + O
                     case Key.O:
-                        Open();
+                        await Open().ConfigureAwait(false);
                         break;
 
                     // X, Ctrl + X
@@ -397,7 +398,7 @@ namespace PicView.Shortcuts
                     case Key.V:
                         if (ctrlDown)
                         {
-                            Paste();
+                            await Paste().ConfigureAwait(false);
                         }
 
                         break;
@@ -424,7 +425,7 @@ namespace PicView.Shortcuts
                     case Key.R:
                         if (ctrlDown)
                         {
-                            Reload();
+                            await Reload().ConfigureAwait(false);
                         }
                         break;
 
@@ -538,6 +539,8 @@ namespace PicView.Shortcuts
                     case Key.End:
                         mainWindow.Scroller.ScrollToEnd();
                         break;
+
+                    default: break;
                 }
             }
 
@@ -553,7 +556,6 @@ namespace PicView.Shortcuts
                 {
                     HideInterfaceLogic.ToggleInterface();
                 }
-                //e.Handled = true;
             }
 
             // Alt + Enter
@@ -563,13 +565,12 @@ namespace PicView.Shortcuts
                 {
                     Fullscreen_Restore();
                 }
-                //e.Handled = true;
             }
 
             #endregion Alt + keys
         }
 
-        internal static void MainWindow_KeysUp(object sender, KeyEventArgs e)
+        internal static async System.Threading.Tasks.Task MainWindow_KeysUpAsync(object sender, KeyEventArgs e)
         {
             // Don't allow keys when typing in text
             if (mainWindow.Bar.IsKeyboardFocusWithin) { return; }
@@ -581,14 +582,16 @@ namespace PicView.Shortcuts
                 case Key.A:
                 case Key.Right:
                 case Key.D:
-                    FastPicUpdate();
+                    await FastPicUpdate().ConfigureAwait(false);
                     break;
 
-                    #endregion FastPicUpdate()
+                #endregion FastPicUpdate()
+
+                default: break;
             }
         }
 
-        internal static void MainWindow_MouseDown(object sender, MouseButtonEventArgs e)
+        internal static async System.Threading.Tasks.Task MainWindow_MouseDownAsync(object sender, MouseButtonEventArgs e)
         {
             switch (e.ChangedButton)
             {
@@ -613,12 +616,14 @@ namespace PicView.Shortcuts
                     break;
 
                 case MouseButton.XButton1:
-                    Pic(false);
+                    await Pic(false).ConfigureAwait(false);
                     break;
 
                 case MouseButton.XButton2:
-                    Pic();
+                    await Pic().ConfigureAwait(false);
                     break;
+
+                default: break;
             }
         }
     }

+ 29 - 2
PicView/SystemIntegration/MonitorSize.cs

@@ -6,7 +6,7 @@ namespace PicView.SystemIntegration
     /// <summary>
     /// Logic for the current monitor's screen resolution
     /// </summary>
-    internal readonly struct MonitorSize
+    internal readonly struct MonitorSize : IEquatable<MonitorSize>
     {
         internal readonly int Width { get; }
         internal readonly int Height { get; }
@@ -15,6 +15,34 @@ namespace PicView.SystemIntegration
 
         internal readonly Rect WorkArea { get; }
 
+        public bool Equals(MonitorSize other)
+        {
+            throw new NotImplementedException();
+        }
+
+        public override bool Equals(object obj)
+        {
+            if (obj == null || !(obj is MonitorSize))
+                return false;
+
+            return Equals((MonitorSize)obj);
+        }
+
+        public static bool operator ==(MonitorSize e1, MonitorSize e2)
+        {
+            return e1.Equals(e2);
+        }
+
+        public static bool operator !=(MonitorSize e1, MonitorSize e2)
+        {
+            return !(e1 == e2);
+        }
+
+        public override int GetHashCode()
+        {
+            throw new NotImplementedException();
+        }
+
         /// <summary>
         /// Store current monitor info
         /// </summary>
@@ -54,7 +82,6 @@ namespace PicView.SystemIntegration
             var workAreaWidth = (int)Math.Floor(workArea.Width * dpiScaling);
             var workAreaHeight = (int)Math.Floor(workArea.Height * dpiScaling);
 
-            //return new MonitorSize(workAreaWidth, workAreaHeight, dpiScaling, workArea);
             return new MonitorSize(workAreaWidth, workAreaHeight, dpiScaling, workArea);
         }
     }

+ 1 - 1
PicView/SystemIntegration/Taskbar.cs

@@ -2,7 +2,7 @@
 
 namespace PicView.SystemIntegration
 {
-    internal class Taskbar
+    internal static class Taskbar
     {
         #region Progress
 

+ 4 - 15
PicView/UI/Loading/AjaxLoader.cs

@@ -6,20 +6,6 @@ namespace PicView.UI.Loading
 {
     internal static class AjaxLoader
     {
-        //// AjaxLoading
-        ///// <summary>
-        ///// Loads AjaxLoading and adds it to the window
-        ///// </summary>
-        //internal static void LoadAjaxLoading()
-        //{
-        //    ajaxLoading = new AjaxLoading
-        //    {
-        //        Focusable = false,
-        //        Opacity = 0
-        //    };
-
-        //    mainWindow.bg.Children.Add(ajaxLoading);
-        //}
 
         /// <summary>
         /// Start loading animation
@@ -37,7 +23,10 @@ namespace PicView.UI.Loading
         /// </summary>
         internal static void AjaxLoadingEnd()
         {
-            AnimationHelper.Fade(ajaxLoading, 0, TimeSpan.FromSeconds(.2));
+            if (ajaxLoading.Opacity != 0)
+            {
+                AnimationHelper.Fade(ajaxLoading, 0, TimeSpan.FromSeconds(.2));
+            }
         }
     }
 }

+ 12 - 7
PicView/UI/Loading/EventsHandling.cs

@@ -32,9 +32,9 @@ namespace PicView.UI.Loading
         internal static void Go()
         {
             // keyboard and Mouse_Keys Keys
-            mainWindow.KeyDown += MainWindow_KeysDown;
-            mainWindow.KeyUp += MainWindow_KeysUp;
-            mainWindow.MouseDown += MainWindow_MouseDown;
+            mainWindow.KeyDown += async (s,x) => await MainWindow_KeysDownAsync(s, x).ConfigureAwait(false);
+            mainWindow.KeyUp += async (s, x) => await MainWindow_KeysUpAsync(s, x).ConfigureAwait(false);
+            mainWindow.MouseDown += async (s, x) => await MainWindow_MouseDownAsync(s, x).ConfigureAwait(false);
 
             // MinButton
             mainWindow.MinButton.TheButton.Click += (s, x) => SystemCommands.MinimizeWindow(mainWindow);
@@ -61,9 +61,14 @@ namespace PicView.UI.Loading
             fileMenu.OpenBorder.MouseLeftButtonUp += async (s, x) => await Open().ConfigureAwait(false); ;
             fileMenu.FileLocationBorder.MouseLeftButtonUp += (s, x) => Open_In_Explorer();
             fileMenu.PrintBorder.MouseLeftButtonUp += (s, x) => Print(Pics[FolderIndex]);
-            fileMenu.Save_File_Location_Border.MouseLeftButtonUp += async (s, x) => await SaveFiles().ConfigureAwait(false); ;
-
-            fileMenu.PasteButton.Click += async (s, x) => await Paste();
+            fileMenu.Save_File_Location_Border.MouseLeftButtonUp += async delegate
+            {
+                await SaveFiles().ConfigureAwait(false);
+            };
+            fileMenu.PasteButton.Click += async delegate
+            {
+                await Paste().ConfigureAwait(false);
+            };
             fileMenu.CopyButton.Click += (s, x) => Copyfile();
 
             // image_button
@@ -142,7 +147,7 @@ namespace PicView.UI.Loading
             minus.MouseEnter += Interface_MouseEnter_Negative;
 
             // GalleryShortcut
-            galleryShortcut.MouseLeftButtonDown += (s, x) => GalleryToggle.Toggle();
+            galleryShortcut.MouseLeftButtonDown += (s, x) => GalleryToggle.ToggleAsync();
             galleryShortcut.MouseEnter += Interface_MouseEnter_Negative;
 
             // Bar

+ 2 - 2
PicView/UI/Loading/StartLoading.cs

@@ -5,7 +5,7 @@ using PicView.UI.UserControls;
 using System;
 using System.Collections.Generic;
 using System.Diagnostics;
-using System.Globalization;
+using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Interop;
@@ -55,7 +55,7 @@ namespace PicView.UI.Loading
             AjaxLoadingStart();
         }
 
-        internal static async void Start()
+        internal static async Task Start()
         {
 #if DEBUG
             Trace.WriteLine("ContentRendered started");

+ 6 - 5
PicView/UI/PicGallery/GalleryToggle.cs

@@ -1,6 +1,7 @@
 using PicView.UI.Sizing;
 using PicView.UI.Windows;
 using System;
+using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Media.Animation;
 using static PicView.Library.Fields;
@@ -16,7 +17,7 @@ namespace PicView.UI.PicGallery
     {
         #region Toggle
 
-        internal static void Toggle(bool change = false)
+        internal static async Task ToggleAsync(bool change = false)
         {
             if (Pics.Count < 1)
             {
@@ -32,7 +33,7 @@ namespace PicView.UI.PicGallery
                 {
                     if (!IsOpen)
                     {
-                        OpenContainedGallery();
+                        await OpenContainedGallery().ConfigureAwait(false);
                     }
                     else
                     {
@@ -43,7 +44,7 @@ namespace PicView.UI.PicGallery
                 {
                     if (!IsOpen)
                     {
-                        OpenFullscreenGallery();
+                        await OpenFullscreenGallery().ConfigureAwait(false);
                     }
                     else
                     {
@@ -69,7 +70,7 @@ namespace PicView.UI.PicGallery
 
         #region Open
 
-        internal static async void OpenContainedGallery()
+        internal static async Task OpenContainedGallery()
         {
             if (Pics.Count < 1)
             {
@@ -111,7 +112,7 @@ namespace PicView.UI.PicGallery
             }
         }
 
-        internal static async void OpenFullscreenGallery()
+        internal static async Task OpenFullscreenGallery()
         {
             if (Pics.Count < 1)
             {

+ 4 - 4
PicView/UI/UserControls/Buttons/ClickArrow.xaml.cs

@@ -11,10 +11,10 @@ namespace PicView.UI.UserControls
     {
         private ColorAnimation ccAnim;
         private ColorAnimation ccAnim2;
-        private Color bb;
-        private Color bg;
-        private Color bg2;
-        private Color fg;
+        private readonly Color bb;
+        private readonly Color bg;
+        private readonly Color bg2;
+        private readonly Color fg;
 
         public ClickArrow(bool right)
         {

+ 4 - 4
PicView/UI/UserControls/Buttons/Minus.xaml.cs

@@ -14,10 +14,10 @@ namespace PicView.UI.UserControls
     {
         private ColorAnimation ccAnim;
         private ColorAnimation ccAnim2;
-        private Color bb;
-        private Color bg;
-        private Color bg2;
-        private Color fg;
+        private readonly Color bb;
+        private readonly Color bg;
+        private readonly Color bg2;
+        private readonly Color fg;
 
         public Minus()
         {

+ 9 - 2
PicView/UI/UserControls/Misc/CustomTextBox.xaml.cs

@@ -12,8 +12,15 @@ namespace PicView.UI.UserControls
             InitializeComponent();
         }
 
-        public string Text { get { return Bar.Text; } set { Bar.Text = value; } }
+        public string Text {
+            get => Bar.Text;
+            set => Bar.Text = value;
+        }
 
-        public new bool IsFocused { get { return Bar.IsFocused; } }
+        public new bool IsFocused {
+            get {
+                return Bar.IsFocused; 
+            }
+        }
     }
 }