From 112427071b50828c011b01195b7c015cac104363 Mon Sep 17 00:00:00 2001 From: Jaex Date: Thu, 31 Mar 2022 15:49:21 +0300 Subject: [PATCH] Support image preview navigation in main window list view too --- ShareX.HelpersLib/Forms/ImageViewer.cs | 18 +- ShareX/Forms/MainForm.Designer.cs | 18 +- ShareX/Forms/MainForm.cs | 10 + ShareX/Forms/MainForm.resx | 814 ++++++++++++------------- ShareX/TaskHelpers.cs | 2 +- 5 files changed, 426 insertions(+), 436 deletions(-) diff --git a/ShareX.HelpersLib/Forms/ImageViewer.cs b/ShareX.HelpersLib/Forms/ImageViewer.cs index 7b4ee4802..202244641 100644 --- a/ShareX.HelpersLib/Forms/ImageViewer.cs +++ b/ShareX.HelpersLib/Forms/ImageViewer.cs @@ -77,8 +77,9 @@ private void LoadCurrentImage() CurrentImageFilePath = Images[CurrentImageIndex]; Image img = ImageHelpers.LoadImage(CurrentImageFilePath); LoadImage(img); - UpdateStatusLabel(); } + + UpdateStatusLabel(); } private void NavigateImage(int position) @@ -127,7 +128,7 @@ private void FilterImageFiles() } else { - CurrentImageIndex = 0; + CurrentImageIndex = Math.Max(filteredImages.Count - 1, 0); } } @@ -162,7 +163,10 @@ private void UpdateStatusLabel() sbStatus.Append($" ({CurrentImage.Width} x {CurrentImage.Height})"); } - lblStatus.Text = sbStatus.ToString().Trim(); + string status = sbStatus.ToString().Trim(); + + lblStatus.Visible = !string.IsNullOrEmpty(status); + lblStatus.Text = status; lblStatus.Location = new Point((ClientSize.Width - lblStatus.Width) / 2, 0); } @@ -197,11 +201,11 @@ public static void ShowImage(string filePath) } } - public static void ShowImage(string[] images, int currentImageIndex = 0) + public static void ShowImage(string[] files, int imageIndex = 0) { - if (images != null && images.Length > 0) + if (files != null && files.Length > 0) { - using (ImageViewer viewer = new ImageViewer(images, currentImageIndex)) + using (ImageViewer viewer = new ImageViewer(files, imageIndex)) { viewer.ShowDialog(); } @@ -245,7 +249,7 @@ private void pbPreview_MouseClick(object sender, MouseEventArgs e) private void pbPreview_MouseMove(object sender, MouseEventArgs e) { - lblStatus.Visible = !new Rectangle(lblStatus.Location, lblStatus.Size).Contains(e.Location); + lblStatus.Visible = !string.IsNullOrEmpty(lblStatus.Text) && !new Rectangle(lblStatus.Location, lblStatus.Size).Contains(e.Location); lblLeft.Visible = CanNavigateLeft && new Rectangle(lblLeft.Location, lblLeft.Size).Contains(e.Location); lblRight.Visible = CanNavigateRight && new Rectangle(lblRight.Location, lblRight.Size).Contains(e.Location); } diff --git a/ShareX/Forms/MainForm.Designer.cs b/ShareX/Forms/MainForm.Designer.cs index 645e277c8..dcf68c82c 100644 --- a/ShareX/Forms/MainForm.Designer.cs +++ b/ShareX/Forms/MainForm.Designer.cs @@ -232,6 +232,7 @@ private void InitializeComponent() this.tssTrayTools1 = new System.Windows.Forms.ToolStripSeparator(); this.tsmiTrayImageEditor = new System.Windows.Forms.ToolStripMenuItem(); this.tsmiTrayImageEffects = new System.Windows.Forms.ToolStripMenuItem(); + this.tsmiTrayImageViewer = new System.Windows.Forms.ToolStripMenuItem(); this.tsmiTrayImageCombiner = new System.Windows.Forms.ToolStripMenuItem(); this.tsmiTrayImageSplitter = new System.Windows.Forms.ToolStripMenuItem(); this.tsmiTrayImageThumbnailer = new System.Windows.Forms.ToolStripMenuItem(); @@ -280,7 +281,6 @@ private void InitializeComponent() this.ucTaskThumbnailView = new ShareX.TaskThumbnailView(); this.ttMain = new System.Windows.Forms.ToolTip(this.components); this.pToolbars = new System.Windows.Forms.Panel(); - this.tsmiTrayImageViewer = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.scMain)).BeginInit(); this.scMain.Panel1.SuspendLayout(); this.scMain.Panel2.SuspendLayout(); @@ -380,10 +380,10 @@ private void InitializeComponent() resources.ApplyResources(this.pbPreview, "pbPreview"); this.pbPreview.DrawCheckeredBackground = true; this.pbPreview.EnableRightClickMenu = true; - this.pbPreview.FullscreenOnClick = true; this.pbPreview.Name = "pbPreview"; this.pbPreview.PictureBoxBackColor = System.Drawing.SystemColors.Control; this.pbPreview.ShowImageSizeLabel = true; + this.pbPreview.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pbPreview_MouseDown); // // tsMain // @@ -1863,6 +1863,13 @@ private void InitializeComponent() resources.ApplyResources(this.tsmiTrayImageEffects, "tsmiTrayImageEffects"); this.tsmiTrayImageEffects.Click += new System.EventHandler(this.tsmiImageEffects_Click); // + // tsmiTrayImageViewer + // + this.tsmiTrayImageViewer.Image = global::ShareX.Properties.Resources.images_flickr; + this.tsmiTrayImageViewer.Name = "tsmiTrayImageViewer"; + resources.ApplyResources(this.tsmiTrayImageViewer, "tsmiTrayImageViewer"); + this.tsmiTrayImageViewer.Click += new System.EventHandler(this.tsmiImageViewer_Click); + // // tsmiTrayImageCombiner // this.tsmiTrayImageCombiner.Image = global::ShareX.Properties.Resources.document_break; @@ -2193,13 +2200,6 @@ private void InitializeComponent() this.pToolbars.Controls.Add(this.tsMain); this.pToolbars.Name = "pToolbars"; // - // tsmiTrayImageViewer - // - this.tsmiTrayImageViewer.Image = global::ShareX.Properties.Resources.images_flickr; - this.tsmiTrayImageViewer.Name = "tsmiTrayImageViewer"; - resources.ApplyResources(this.tsmiTrayImageViewer, "tsmiTrayImageViewer"); - this.tsmiTrayImageViewer.Click += new System.EventHandler(this.tsmiImageViewer_Click); - // // MainForm // this.AllowDrop = true; diff --git a/ShareX/Forms/MainForm.cs b/ShareX/Forms/MainForm.cs index ed8cb90d9..4e9a332aa 100644 --- a/ShareX/Forms/MainForm.cs +++ b/ShareX/Forms/MainForm.cs @@ -1452,6 +1452,16 @@ private void lvUploads_KeyDown(object sender, KeyEventArgs e) e.Handled = e.SuppressKeyPress = true; } + private void pbPreview_MouseDown(object sender, MouseEventArgs e) + { + if (lvUploads.SelectedIndices.Count > 0) + { + string[] files = lvUploads.Items.Cast().Select(x => ((WorkerTask)x.Tag).Info?.FilePath).ToArray(); + int index = lvUploads.SelectedIndices[0]; + ImageViewer.ShowImage(files, index); + } + } + private void ucTaskThumbnailView_SelectedPanelChanged(object sender, EventArgs e) { UpdateInfoManager(); diff --git a/ShareX/Forms/MainForm.resx b/ShareX/Forms/MainForm.resx index c6b8d18b1..31b28cb85 100644 --- a/ShareX/Forms/MainForm.resx +++ b/ShareX/Forms/MainForm.resx @@ -159,6 +159,45 @@ 0 + + Filename + + + 150 + + + Status + + + Progress + + + 125 + + + Speed + + + 75 + + + Elapsed + + + 45 + + + Remaining + + + 45 + + + URL + + + 145 + Fill @@ -255,90 +294,12 @@ 3 - - Filename - - - 150 - - - Status - - - Progress - - - 125 - - - Speed - - - 75 - - - Elapsed - - - 45 - - - Remaining - - - 45 - - - URL - - - 145 - 17, 17 Fill - - 0, 0 - - - 165, 0 - - - 6, 5, 6, 2 - - - 165, 471 - - - 1 - - - tsMain - - - ShareX.HelpersLib.ToolStripBorderRight, ShareX.HelpersLib, Version=13.7.2.0, Culture=neutral, PublicKeyToken=null - - - pToolbars - - - 0 - - - MiddleLeft - - - Magenta - - - 152, 20 - - - Capture - 191, 22 @@ -420,12 +381,6 @@ Show cursor - - 191, 22 - - - Screenshot delay - 126, 22 @@ -462,17 +417,23 @@ 5 seconds - + + 191, 22 + + + Screenshot delay + + MiddleLeft - + Magenta - + 152, 20 - - Upload + + Capture 203, 22 @@ -522,6 +483,18 @@ Tweet message... + + MiddleLeft + + + Magenta + + + 152, 20 + + + Upload + BottomLeft @@ -534,18 +507,6 @@ Workflows - - MiddleLeft - - - Magenta - - - 152, 20 - - - Tools - 184, 22 @@ -672,6 +633,18 @@ DNS changer... + + MiddleLeft + + + Magenta + + + 152, 20 + + + Tools + 152, 6 @@ -699,18 +672,6 @@ After upload tasks - - MiddleLeft - - - Magenta - - - 152, 20 - - - Destinations - 219, 22 @@ -756,6 +717,18 @@ Custom uploader settings... + + MiddleLeft + + + Magenta + + + 152, 20 + + + Destinations + MiddleLeft @@ -834,18 +807,6 @@ 152, 6 - - MiddleLeft - - - Magenta - - - 152, 20 - - - Debug - 171, 22 @@ -882,6 +843,18 @@ Test URL sharing + + MiddleLeft + + + Magenta + + + 152, 20 + + + Debug + MiddleLeft @@ -930,18 +903,36 @@ About... + + 0, 0 + + + 165, 0 + + + 6, 5, 6, 2 + + + 165, 471 + + + 1 + + + tsMain + + + ShareX.HelpersLib.ToolStripBorderRight, ShareX.HelpersLib, Version=13.7.2.0, Culture=neutral, PublicKeyToken=null + + + pToolbars + + + 0 + 286, 17 - - 229, 472 - - - cmsTaskInfo - - - System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - 228, 22 @@ -954,12 +945,6 @@ Stop upload - - 228, 22 - - - Open - Enter @@ -1014,11 +999,11 @@ Thumbnail file - + 228, 22 - - Copy + + Open Ctrl+C @@ -1191,6 +1176,12 @@ False + + 228, 22 + + + Copy + Ctrl+U @@ -1284,12 +1275,6 @@ OCR image... - - 228, 22 - - - Combine images... - 188, 22 @@ -1302,6 +1287,12 @@ Combine vertically + + 228, 22 + + + Combine images... + 228, 22 @@ -1323,18 +1314,198 @@ Switch to thumbnail view + + 229, 472 + + + cmsTaskInfo + + + System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + 105, 17 190, 17 + + 191, 22 + + + Fullscreen + + + 191, 22 + + + Window + + + 191, 22 + + + Monitor + + + 191, 22 + + + Region + + + 191, 22 + + + Region (Light) + + + 191, 22 + + + Region (Transparent) + + + 191, 22 + + + Last region + + + 191, 22 + + + Screen recording + + + 191, 22 + + + Screen recording (GIF) + + + 191, 22 + + + Scrolling capture... + + + 191, 22 + + + Text capture (OCR)... + + + 191, 22 + + + Auto capture... + + + 188, 6 + + + 191, 22 + + + Show cursor + + + 126, 22 + + + No delay + + + 126, 22 + + + 1 second + + + 126, 22 + + + 2 seconds + + + 126, 22 + + + 3 seconds + + + 126, 22 + + + 4 seconds + + + 126, 22 + + + 5 seconds + + + 191, 22 + + + Screenshot delay + 200, 22 Capture + + 203, 22 + + + Upload file... + + + 203, 22 + + + Upload folder... + + + 203, 22 + + + Upload from clipboard... + + + 203, 22 + + + Upload text... + + + 203, 22 + + + Upload from URL... + + + 203, 22 + + + Drag and drop upload... + + + 203, 22 + + + Shorten URL... + + + 203, 22 + + + Tweet message... + 200, 22 @@ -1494,6 +1665,51 @@ After upload tasks + + 219, 22 + + + Image uploaders + + + 219, 22 + + + Text uploaders + + + 219, 22 + + + File uploaders + + + 219, 22 + + + URL shorteners + + + 219, 22 + + + URL sharing services + + + 216, 6 + + + 219, 22 + + + Destination settings... + + + 219, 22 + + + Custom uploader settings... + 200, 22 @@ -1596,273 +1812,9 @@ ShareX - - 191, 22 - - - Fullscreen - - - 191, 22 - - - Window - - - 191, 22 - - - Monitor - - - 191, 22 - - - Region - - - 191, 22 - - - Region (Light) - - - 191, 22 - - - Region (Transparent) - - - 191, 22 - - - Last region - - - 191, 22 - - - Screen recording - - - 191, 22 - - - Screen recording (GIF) - - - 191, 22 - - - Scrolling capture... - - - 191, 22 - - - Text capture (OCR)... - - - 191, 22 - - - Auto capture... - - - 188, 6 - - - 191, 22 - - - Show cursor - - - 191, 22 - - - Screenshot delay - - - 126, 22 - - - No delay - - - 126, 22 - - - 1 second - - - 126, 22 - - - 2 seconds - - - 126, 22 - - - 3 seconds - - - 126, 22 - - - 4 seconds - - - 126, 22 - - - 5 seconds - - - 203, 22 - - - Upload file... - - - 203, 22 - - - Upload folder... - - - 203, 22 - - - Upload from clipboard... - - - 203, 22 - - - Upload text... - - - 203, 22 - - - Upload from URL... - - - 203, 22 - - - Drag and drop upload... - - - 203, 22 - - - Shorten URL... - - - 203, 22 - - - Tweet message... - - - 219, 22 - - - Image uploaders - - - 219, 22 - - - Text uploaders - - - 219, 22 - - - File uploaders - - - 219, 22 - - - URL shorteners - - - 219, 22 - - - URL sharing services - - - 216, 6 - - - 219, 22 - - - Destination settings... - - - 219, 22 - - - Custom uploader settings... - 405, 17 - - lblThumbnailViewTip - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - pThumbnailView - - - 0 - - - ucTaskThumbnailView - - - ShareX.TaskThumbnailView, ShareX, Version=13.7.2.0, Culture=neutral, PublicKeyToken=null - - - pThumbnailView - - - 1 - - - Fill - - - 165, 0 - - - 679, 471 - - - 7 - - - pThumbnailView - - - System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 2 - True @@ -1926,6 +1878,30 @@ 1 + + Fill + + + 165, 0 + + + 679, 471 + + + 7 + + + pThumbnailView + + + System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 2 + 567, 17 @@ -3144,6 +3120,12 @@ System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + tsmiTrayImageViewer + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + tsmiTrayImageCombiner @@ -3408,12 +3390,6 @@ System.Windows.Forms.ToolTip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - tsmiTrayImageViewer - - - System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - MainForm diff --git a/ShareX/TaskHelpers.cs b/ShareX/TaskHelpers.cs index 7f8b5687b..e1baa3856 100644 --- a/ShareX/TaskHelpers.cs +++ b/ShareX/TaskHelpers.cs @@ -1090,7 +1090,7 @@ public static void OpenImageViewer() public static void OpenImageViewer(string filePath) { - if (!string.IsNullOrEmpty(filePath)) + if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath)) { string folderPath = Path.GetDirectoryName(filePath); string[] files = Directory.GetFiles(folderPath);