فهرست منبع

clean PictureMover

HOME 1 سال پیش
والد
کامیت
208929e171
3فایلهای تغییر یافته به همراه51 افزوده شده و 60 حذف شده
  1. 45 51
      PictureMover/CoverForm.cs
  2. 1 1
      PictureMover/MainForm.Designer.cs
  3. 5 8
      PictureMover/MainForm.cs

+ 45 - 51
PictureMover/CoverForm.cs

@@ -29,17 +29,7 @@ namespace PictureMover
         {
             Console.WriteLine("w " + e.Delta);
             if (_currentPath == null) return;
-
-            if (e.Delta < 0)
-            {
-                //next
-                await NextFile(true);
-            }
-            else if (_currentPath != null)
-            {
-                //prev
-                await NextFile(false);
-            }
+            await NavFile(e.Delta < 0);
         }
 
         private async void Form_PreviewKeyDown(object? sender, PreviewKeyDownEventArgs e)
@@ -49,47 +39,53 @@ namespace PictureMover
 
             if (_currentPath == null) return;
 
-            if (e.KeyCode == Keys.Home) await JumpToBoundFile(true);
-            if (e.KeyCode == Keys.End) await JumpToBoundFile(false);
-            if (e.KeyCode == Keys.Space || e.KeyCode == Keys.Enter || e.KeyCode == Keys.PageDown) await NextFile(true);
-            if (e.KeyCode == Keys.Back || e.KeyCode == Keys.PageUp) await NextFile(false);
-
-            if (e.KeyCode == Keys.B)
+            switch (e.KeyCode)
             {
-                var src = _currentPath;
-                await NextFile(true);
-                MoveToOuterDotSuffixDir(src, "b");
-            }
-
-            if (e.KeyCode == Keys.S)
-            {
-                var src = _currentPath;
-                await NextFile(true);
-                MoveToOuterDotSuffixDir(src, "s");
+                case Keys.Home:
+                    await JumpToFile(true);
+                    break;
+                case Keys.End:
+                    await JumpToFile(false);
+                    break;
+                case Keys.Space:
+                case Keys.Enter:
+                case Keys.PageDown:
+                    await NavFile(true);
+                    break;
+                case Keys.Back:
+                case Keys.PageUp:
+                    await NavFile(false);
+                    break;
+                case Keys.B:
+                {
+                    var src = _currentPath;
+                    await NavFile(true);
+                    MoveToOuterDotSuffixDir(src, "b");
+                    break;
+                }
+                case Keys.S:
+                {
+                    var src = _currentPath;
+                    await NavFile(true);
+                    MoveToOuterDotSuffixDir(src, "s");
+                    break;
+                }
             }
         }
 
         private void Form_DragEnter(object sender, DragEventArgs e)
         {
-            if (e.Data?.GetDataPresent(DataFormats.FileDrop) == true)
-            {
-                if (e.Data.GetData(DataFormats.FileDrop) is string[] arr)
-                {
-                    if (arr.Length == 1 && File.Exists(arr[0])) e.Effect = DragDropEffects.Link;
-                }
-            }
+            if (e.Data?.GetDataPresent(DataFormats.FileDrop) != true) return;
+            if (e.Data.GetData(DataFormats.FileDrop) is not string[] arr) return;
+            if (arr.Length == 1 && File.Exists(arr[0])) e.Effect = DragDropEffects.Link;
         }
 
         private async void Form_DragDrop(object sender, DragEventArgs e)
         {
-            if (e.Data.GetData(DataFormats.FileDrop) is string[] arr)
-            {
-                if (arr.Length == 1 && File.Exists(arr[0]))
-                {
-                    var path = arr[0];
-                    await ShowFileAsync(path);
-                }
-            }
+            if (e.Data?.GetData(DataFormats.FileDrop) is not string[] arr) return;
+            if (arr.Length != 1 || !File.Exists(arr[0])) return;
+            var path = arr[0];
+            await ShowFileAsync(path);
         }
 
         private void timer1_Tick(object sender, EventArgs e)
@@ -101,7 +97,7 @@ namespace PictureMover
             if (Size != size) Size = size;
         }
 
-        private async Task NextFile(bool isNext)
+        private async Task NavFile(bool isNext)
         {
             if (_currentPath == null) return;
             var nears = GetFilesAround(_currentPath);
@@ -132,7 +128,7 @@ namespace PictureMover
             }
         }
 
-        private async Task JumpToBoundFile(bool first)
+        private async Task JumpToFile(bool first)
         {
             if (_currentPath == null) return;
             var nears = GetFilesAround(_currentPath);
@@ -174,15 +170,13 @@ namespace PictureMover
                 File.Move(src, dst);
             }
 
-            if (_currentPath != null)
-            {
-                var nears = GetFilesAround(_currentPath);
-                var index = Array.IndexOf(nears, _currentPath);
-                _mainForm.Text = $"({nears.Length}/{index + 1}) {_currentPath}";
-            }
+            if (_currentPath == null) return;
+            var nears = GetFilesAround(_currentPath);
+            var index = Array.IndexOf(nears, _currentPath);
+            _mainForm.Text = $"({nears.Length}/{index + 1}) {_currentPath}";
         }
 
-        private string[] GetFilesAround(string filePath)
+        private static string[] GetFilesAround(string filePath)
         {
             var ext = Path.GetExtension(filePath);
             var dir = Path.GetDirectoryName(filePath);

+ 1 - 1
PictureMover/MainForm.Designer.cs

@@ -52,7 +52,7 @@
             Controls.Add(webView21);
             Name = "Form1";
             Text = "Form1";
-            Shown += Form1_Shown;
+            Shown += Form_Shown;
             ((System.ComponentModel.ISupportInitialize)webView21).EndInit();
             ResumeLayout(false);
         }

+ 5 - 8
PictureMover/MainForm.cs

@@ -2,7 +2,7 @@ namespace PictureMover
 {
     public partial class MainForm : Form
     {
-        private CoverForm _form2;
+        private readonly CoverForm _form2;
 
         public MainForm()
         {
@@ -10,15 +10,12 @@ namespace PictureMover
             _form2 = new CoverForm(this);
         }
 
-        private void Form1_Enter(object? sender, EventArgs e)
-        {
-            _form2.Focus();
-        }
-
-        private void Form1_Shown(object sender, EventArgs e)
+        private void Form_Shown(object sender, EventArgs e)
         {
             _form2.Show(this);
-            Enter += Form1_Enter;
+            Enter += Form_Enter;
         }
+
+        private void Form_Enter(object? sender, EventArgs e) => _form2.Focus();
     }
 }