From 465b31844c71dcaa2afe9af59c61ea53ca5f68ce Mon Sep 17 00:00:00 2001 From: Jaex Date: Fri, 20 Sep 2019 13:58:47 +0300 Subject: [PATCH] fixed #2483: Added "Run actions" sub menu to task context menu --- ShareX.HelpersLib/ExternalProgram.cs | 6 ++++ ShareX/Forms/MainForm.Designer.cs | 44 +++++++++++++++---------- ShareX/Forms/MainForm.cs | 49 +++++++++++++++++++++++++--- ShareX/Forms/MainForm.resx | 42 +++++++++++++++++------- 4 files changed, 107 insertions(+), 34 deletions(-) diff --git a/ShareX.HelpersLib/ExternalProgram.cs b/ShareX.HelpersLib/ExternalProgram.cs index e6fea86ab..6ebaec523 100644 --- a/ShareX.HelpersLib/ExternalProgram.cs +++ b/ShareX.HelpersLib/ExternalProgram.cs @@ -26,6 +26,7 @@ You should have received a copy of the GNU General Public License using System; using System.Diagnostics; using System.IO; +using System.Threading.Tasks; namespace ShareX.HelpersLib { @@ -133,6 +134,11 @@ public string Run(string inputPath) return inputPath; } + public async Task RunAsync(string inputPath) + { + return await Task.Run(() => Run(inputPath)); + } + private bool CheckExtension(string path, string extensions) { if (!string.IsNullOrWhiteSpace(path)) diff --git a/ShareX/Forms/MainForm.Designer.cs b/ShareX/Forms/MainForm.Designer.cs index 6619d25aa..6e0196cc0 100644 --- a/ShareX/Forms/MainForm.Designer.cs +++ b/ShareX/Forms/MainForm.Designer.cs @@ -274,10 +274,8 @@ private void InitializeComponent() this.timerTraySingleClick = new System.Windows.Forms.Timer(this.components); this.pNews = new System.Windows.Forms.Panel(); this.btnCloseNews = new System.Windows.Forms.Button(); - this.ucNews = new ShareX.NewsListControl(); this.pThumbnailView = new System.Windows.Forms.Panel(); this.lblThumbnailViewTip = new System.Windows.Forms.Label(); - this.ucTaskThumbnailView = new ShareX.TaskThumbnailView(); this.flpSocialButtons = new System.Windows.Forms.FlowLayoutPanel(); this.pbPatreonButton = new System.Windows.Forms.PictureBox(); this.pbBitcoinButton = new System.Windows.Forms.PictureBox(); @@ -285,6 +283,9 @@ private void InitializeComponent() this.pbDiscordButton = new System.Windows.Forms.PictureBox(); this.pbSocialHideButton = new System.Windows.Forms.PictureBox(); this.ttMain = new System.Windows.Forms.ToolTip(this.components); + this.tsmiRunAction = new System.Windows.Forms.ToolStripMenuItem(); + this.ucNews = new ShareX.NewsListControl(); + this.ucTaskThumbnailView = new ShareX.TaskThumbnailView(); ((System.ComponentModel.ISupportInitialize)(this.scMain)).BeginInit(); this.scMain.Panel1.SuspendLayout(); this.scMain.Panel2.SuspendLayout(); @@ -1000,6 +1001,7 @@ private void InitializeComponent() this.tsmiUploadSelectedFile, this.tsmiDownloadSelectedURL, this.tsmiEditSelectedFile, + this.tsmiRunAction, this.tsmiDeleteSelectedItem, this.tsmiDeleteSelectedFile, this.tsmiShortenSelectedURL, @@ -2172,12 +2174,6 @@ private void InitializeComponent() this.btnCloseNews.UseVisualStyleBackColor = true; this.btnCloseNews.Click += new System.EventHandler(this.btnCloseNews_Click); // - // ucNews - // - this.ucNews.BackColor = System.Drawing.SystemColors.Window; - resources.ApplyResources(this.ucNews, "ucNews"); - this.ucNews.Name = "ucNews"; - // // pThumbnailView // this.pThumbnailView.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(42)))), ((int)(((byte)(47)))), ((int)(((byte)(56))))); @@ -2195,15 +2191,6 @@ private void InitializeComponent() this.lblThumbnailViewTip.UseMnemonic = false; this.lblThumbnailViewTip.MouseUp += new System.Windows.Forms.MouseEventHandler(this.LblThumbnailViewTip_MouseUp); // - // ucTaskThumbnailView - // - resources.ApplyResources(this.ucTaskThumbnailView, "ucTaskThumbnailView"); - this.ucTaskThumbnailView.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(42)))), ((int)(((byte)(47)))), ((int)(((byte)(56))))); - this.ucTaskThumbnailView.Name = "ucTaskThumbnailView"; - this.ucTaskThumbnailView.ThumbnailSize = new System.Drawing.Size(200, 150); - this.ucTaskThumbnailView.TitleVisible = true; - this.ucTaskThumbnailView.ContextMenuRequested += new ShareX.TaskThumbnailView.TaskViewMouseEventHandler(this.UcTaskView_ContextMenuRequested); - // // flpSocialButtons // resources.ApplyResources(this.flpSocialButtons, "flpSocialButtons"); @@ -2272,6 +2259,28 @@ private void InitializeComponent() this.ttMain.ReshowDelay = 100; this.ttMain.Draw += new System.Windows.Forms.DrawToolTipEventHandler(this.TtMain_Draw); // + // tsmiRunAction + // + this.tsmiRunAction.Image = global::ShareX.Properties.Resources.application_terminal; + this.tsmiRunAction.Name = "tsmiRunAction"; + resources.ApplyResources(this.tsmiRunAction, "tsmiRunAction"); + // + // ucNews + // + this.ucNews.BackColor = System.Drawing.SystemColors.Window; + resources.ApplyResources(this.ucNews, "ucNews"); + this.ucNews.Name = "ucNews"; + // + // ucTaskThumbnailView + // + resources.ApplyResources(this.ucTaskThumbnailView, "ucTaskThumbnailView"); + this.ucTaskThumbnailView.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(42)))), ((int)(((byte)(47)))), ((int)(((byte)(56))))); + this.ucTaskThumbnailView.Name = "ucTaskThumbnailView"; + this.ucTaskThumbnailView.ThumbnailSize = new System.Drawing.Size(200, 150); + this.ucTaskThumbnailView.TitleLocation = ShareX.ThumbnailTitleLocation.Top; + this.ucTaskThumbnailView.TitleVisible = true; + this.ucTaskThumbnailView.ContextMenuRequested += new ShareX.TaskThumbnailView.TaskViewMouseEventHandler(this.UcTaskView_ContextMenuRequested); + // // MainForm // this.AllowDrop = true; @@ -2573,5 +2582,6 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripSeparator tssThumbnailTitle; private System.Windows.Forms.ToolStripMenuItem tsmiThumbnailTitleTop; private System.Windows.Forms.ToolStripMenuItem tsmiThumbnailTitleBottom; + private System.Windows.Forms.ToolStripMenuItem tsmiRunAction; } } \ No newline at end of file diff --git a/ShareX/Forms/MainForm.cs b/ShareX/Forms/MainForm.cs index 85a173496..fcbb26b3b 100644 --- a/ShareX/Forms/MainForm.cs +++ b/ShareX/Forms/MainForm.cs @@ -616,7 +616,7 @@ private void UpdateContextMenu(WorkerTask task = null) tsmiStopUpload.Visible = tsmiOpen.Visible = tsmiCopy.Visible = tsmiShowErrors.Visible = tsmiShowResponse.Visible = tsmiSearchImage.Visible = tsmiShowQRCode.Visible = tsmiOCRImage.Visible = tsmiCombineImages.Visible = tsmiUploadSelectedFile.Visible = tsmiDownloadSelectedURL.Visible = - tsmiEditSelectedFile.Visible = tsmiDeleteSelectedItem.Visible = tsmiDeleteSelectedFile.Visible = tsmiShortenSelectedURL.Visible = + tsmiEditSelectedFile.Visible = tsmiRunAction.Visible = tsmiDeleteSelectedItem.Visible = tsmiDeleteSelectedFile.Visible = tsmiShortenSelectedURL.Visible = tsmiShareSelectedURL.Visible = false; if (Program.Settings.TaskViewMode == TaskViewMode.ListView) @@ -724,6 +724,8 @@ private void UpdateContextMenu(WorkerTask task = null) tsmiUploadSelectedFile.Visible = uim.SelectedItem.IsFileExist; tsmiDownloadSelectedURL.Visible = uim.SelectedItem.IsFileURL; tsmiEditSelectedFile.Visible = uim.SelectedItem.IsImageFile; + tsmiRunAction.Visible = uim.SelectedItem.IsFileExist && Program.DefaultTaskSettings.ExternalPrograms.Count > 0; + UpdateActionsMenu(uim.SelectedItem.Info.FilePath); tsmiDeleteSelectedItem.Visible = true; tsmiDeleteSelectedFile.Visible = uim.SelectedItem.IsFileExist; tsmiShortenSelectedURL.Visible = uim.SelectedItem.IsURLExist; @@ -862,6 +864,41 @@ private void CleanCustomClipboardFormats() } } + private void UpdateActionsMenu(string filePath) + { + tsmiRunAction.DropDownItems.Clear(); + + if (Program.DefaultTaskSettings.ExternalPrograms.Count > 0 && !string.IsNullOrEmpty(filePath) && File.Exists(filePath)) + { + foreach (ExternalProgram action in Program.DefaultTaskSettings.ExternalPrograms) + { + if (!string.IsNullOrEmpty(action.Name)) + { + string name = action.Name.Truncate(50, "..."); + ToolStripMenuItem tsmi = new ToolStripMenuItem(name); + + try + { + using (Icon icon = NativeMethods.GetFileIcon(action.Path, true)) + { + if (icon != null && icon.Width > 0 && icon.Height > 0) + { + tsmi.Image = icon.ToBitmap(); + } + } + } + catch (Exception e) + { + DebugHelper.WriteException(e); + } + + tsmi.Click += async (sender, e) => await action.RunAsync(filePath); + tsmiRunAction.DropDownItems.Add(tsmi); + } + } + } + } + private void AfterApplicationSettingsJobs() { if (Program.Settings.TrayTextMoreInfo) @@ -1231,17 +1268,19 @@ await Task.Run(() => try { string title = window.Text.Truncate(50, "..."); - ToolStripItem tsi = tsmiWindow.DropDownItems.Add(title); - tsi.Tag = window; - tsi.Click += handlerWindow; + ToolStripMenuItem tsmi = new ToolStripMenuItem(title); + tsmi.Tag = window; + tsmi.Click += handlerWindow; using (Icon icon = window.Icon) { if (icon != null && icon.Width > 0 && icon.Height > 0) { - tsi.Image = icon.ToBitmap(); + tsmi.Image = icon.ToBitmap(); } } + + tsmiWindow.DropDownItems.Add(tsmi); } catch (Exception e) { diff --git a/ShareX/Forms/MainForm.resx b/ShareX/Forms/MainForm.resx index ac77ddf9b..ce0245da5 100644 --- a/ShareX/Forms/MainForm.resx +++ b/ShareX/Forms/MainForm.resx @@ -1146,6 +1146,12 @@ Edit image... + + 228, 22 + + + Run action + Del @@ -1228,34 +1234,34 @@ Hide columns - 180, 22 + 130, 22 Show - 180, 22 + 130, 22 Hide - 180, 22 + 130, 22 Automatic - 177, 6 + 127, 6 - 180, 22 + 130, 22 Side - 180, 22 + 130, 22 Bottom @@ -1267,28 +1273,28 @@ Image preview - 180, 22 + 114, 22 Show - 180, 22 + 114, 22 Hide - 177, 6 + 111, 6 - 180, 22 + 114, 22 Top - 180, 22 + 114, 22 Bottom @@ -1306,7 +1312,7 @@ Switch to thumbnail view - 229, 494 + 229, 516 cmsTaskInfo @@ -1983,6 +1989,9 @@ GrowAndShrink + + NoControl + 0, 0 @@ -2181,6 +2190,9 @@ 834, 429 + + NoControl + 500, 250 @@ -3603,6 +3615,12 @@ System.Windows.Forms.ToolTip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + tsmiRunAction + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + MainForm