From 596510f2e562f85b340b44b0550c0faefd76ab91 Mon Sep 17 00:00:00 2001 From: Jaex Date: Wed, 18 Nov 2020 21:39:45 +0300 Subject: [PATCH] Support drag n drop .sxie files to image effects window --- .../Forms/ImageEffectsForm.Designer.cs | 3 + .../Forms/ImageEffectsForm.cs | 55 +++++++++++++++++++ .../Forms/ImageEffectsForm.resx | 47 ++++++++-------- 3 files changed, 83 insertions(+), 22 deletions(-) diff --git a/ShareX.ImageEffectsLib/Forms/ImageEffectsForm.Designer.cs b/ShareX.ImageEffectsLib/Forms/ImageEffectsForm.Designer.cs index 93eb97716..9a10a8737 100644 --- a/ShareX.ImageEffectsLib/Forms/ImageEffectsForm.Designer.cs +++ b/ShareX.ImageEffectsLib/Forms/ImageEffectsForm.Designer.cs @@ -318,6 +318,7 @@ private void InitializeComponent() // // ImageEffectsForm // + this.AllowDrop = true; resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.BackColor = System.Drawing.SystemColors.Window; @@ -349,6 +350,8 @@ private void InitializeComponent() this.Name = "ImageEffectsForm"; this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; this.Shown += new System.EventHandler(this.ImageEffectsForm_Shown); + this.DragDrop += new System.Windows.Forms.DragEventHandler(this.ImageEffectsForm_DragDrop); + this.DragEnter += new System.Windows.Forms.DragEventHandler(this.ImageEffectsForm_DragEnter); this.cmsLoadImage.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); diff --git a/ShareX.ImageEffectsLib/Forms/ImageEffectsForm.cs b/ShareX.ImageEffectsLib/Forms/ImageEffectsForm.cs index 75c40cccb..dc9f2084a 100644 --- a/ShareX.ImageEffectsLib/Forms/ImageEffectsForm.cs +++ b/ShareX.ImageEffectsLib/Forms/ImageEffectsForm.cs @@ -30,6 +30,7 @@ You should have received a copy of the GNU General Public License using System.Collections.Generic; using System.Diagnostics; using System.Drawing; +using System.Linq; using System.Windows.Forms; namespace ShareX.ImageEffectsLib @@ -122,6 +123,23 @@ public void ImportImageEffect(string json) } } + public void ImportImageEffectFile(string filePath) + { + try + { + string configJson = ImageEffectPackager.ExtractPackage(filePath, HelpersOptions.ShareXSpecialFolders["ShareXImageEffects"]); + + if (!string.IsNullOrEmpty(configJson)) + { + ImportImageEffect(configJson); + } + } + catch (Exception ex) + { + ex.ShowError(false); + } + } + protected void OnImageProcessRequested(Bitmap bmp) { ImageProcessRequested?.Invoke(bmp); @@ -478,6 +496,43 @@ private void ImageEffectsForm_Shown(object sender, EventArgs e) UpdatePreview(); } + private void ImageEffectsForm_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(DataFormats.FileDrop, false)) + { + string[] files = e.Data.GetData(DataFormats.FileDrop, false) as string[]; + + if (files != null && files.Any(x => !string.IsNullOrEmpty(x) && x.EndsWith(".sxie"))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + else + { + e.Effect = DragDropEffects.None; + } + } + + private void ImageEffectsForm_DragDrop(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(DataFormats.FileDrop, false)) + { + string[] files = e.Data.GetData(DataFormats.FileDrop, false) as string[]; + + if (files != null) + { + foreach (string filePath in files.Where(x => !string.IsNullOrEmpty(x) && x.EndsWith(".sxie"))) + { + ImportImageEffectFile(filePath); + } + } + } + } + private void btnPresetNew_Click(object sender, EventArgs e) { AddPreset(); diff --git a/ShareX.ImageEffectsLib/Forms/ImageEffectsForm.resx b/ShareX.ImageEffectsLib/Forms/ImageEffectsForm.resx index 8adfdf0bd..0b7b466e8 100644 --- a/ShareX.ImageEffectsLib/Forms/ImageEffectsForm.resx +++ b/ShareX.ImageEffectsLib/Forms/ImageEffectsForm.resx @@ -171,6 +171,15 @@ 126, 17 + + 131, 48 + + + cmsLoadImage + + + System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + 130, 22 @@ -183,15 +192,6 @@ From clipboard - - 131, 48 - - - cmsLoadImage - - - System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - True @@ -399,6 +399,9 @@ 16 + + 260, 17 + NoControl @@ -411,9 +414,6 @@ 3 - - 260, 17 - New @@ -648,12 +648,12 @@ 6 + + 260, 17 + Top, Bottom, Left - - 164 - 8, 53 @@ -667,7 +667,7 @@ lvPresets - ShareX.HelpersLib.MyListView, ShareX.HelpersLib, Version=13.2.2.0, Culture=neutral, PublicKeyToken=null + ShareX.HelpersLib.MyListView, ShareX.HelpersLib, Version=13.3.1.0, Culture=neutral, PublicKeyToken=null $this @@ -675,6 +675,9 @@ 12 + + 164 + Top, Bottom, Left @@ -718,7 +721,7 @@ pbResult - ShareX.HelpersLib.MyPictureBox, ShareX.HelpersLib, Version=13.2.2.0, Culture=neutral, PublicKeyToken=null + ShareX.HelpersLib.MyPictureBox, ShareX.HelpersLib, Version=13.3.1.0, Culture=neutral, PublicKeyToken=null $this @@ -751,7 +754,7 @@ mbLoadImage - ShareX.HelpersLib.MenuButton, ShareX.HelpersLib, Version=13.2.2.0, Culture=neutral, PublicKeyToken=null + ShareX.HelpersLib.MenuButton, ShareX.HelpersLib, Version=13.3.1.0, Culture=neutral, PublicKeyToken=null $this @@ -762,9 +765,6 @@ Top, Bottom, Left - - 50 - 184, 101 @@ -778,7 +778,7 @@ lvEffects - ShareX.HelpersLib.MyListView, ShareX.HelpersLib, Version=13.2.2.0, Culture=neutral, PublicKeyToken=null + ShareX.HelpersLib.MyListView, ShareX.HelpersLib, Version=13.3.1.0, Culture=neutral, PublicKeyToken=null $this @@ -786,6 +786,9 @@ 25 + + 50 + True