From 973cf871c85f46314328a00ad4929572fae69317 Mon Sep 17 00:00:00 2001 From: Robin Krom Date: Sat, 29 May 2021 16:06:58 +0200 Subject: [PATCH] Additional improvements for the ClickActions, now possible to open a file directly in the editor. Inspired by FEATURE-1321 --- src/Greenshot.Base/Core/Enums/ClickActions.cs | 4 +++- src/Greenshot/Forms/MainForm.cs | 21 +++++++++++++----- src/Greenshot/Helpers/CaptureHelper.cs | 22 +++++++------------ 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/Greenshot.Base/Core/Enums/ClickActions.cs b/src/Greenshot.Base/Core/Enums/ClickActions.cs index ef836442f..a4e048a4b 100644 --- a/src/Greenshot.Base/Core/Enums/ClickActions.cs +++ b/src/Greenshot.Base/Core/Enums/ClickActions.cs @@ -35,6 +35,8 @@ namespace Greenshot.Base.Core.Enums CAPTURE_SCREEN, CAPTURE_CLIPBOARD, CAPTURE_WINDOW, - OPEN_EMPTY_EDITOR + OPEN_EMPTY_EDITOR, + OPEN_FILE_IN_EDITOR, + OPEN_CLIPBOARD_IN_EDITOR } } \ No newline at end of file diff --git a/src/Greenshot/Forms/MainForm.cs b/src/Greenshot/Forms/MainForm.cs index fa45cb04d..f00174843 100644 --- a/src/Greenshot/Forms/MainForm.cs +++ b/src/Greenshot/Forms/MainForm.cs @@ -518,7 +518,7 @@ namespace Greenshot.Forms new PickerDestination() }; - bool useEditor = true; + bool useEditor = false; if (WindowsVersion.IsWindows10OrLater) { int len = 250; @@ -527,8 +527,11 @@ namespace Greenshot.Forms var err = Kernel32.GetPackageFullName(proc.Handle, ref len, stringBuilder); if (err != 0) { - useEditor = false; + useEditor = true; } + } else + { + useEditor = true; } if (useEditor) @@ -931,7 +934,7 @@ namespace Greenshot.Forms CaptureHelper.CaptureRegion(true); } - private void CaptureFile() + private void CaptureFile(IDestination destination = null) { var openFileDialog = new OpenFileDialog { @@ -944,7 +947,7 @@ namespace Greenshot.Forms if (File.Exists(openFileDialog.FileName)) { - CaptureHelper.CaptureFile(openFileDialog.FileName); + CaptureHelper.CaptureFile(openFileDialog.FileName, destination); } } @@ -1255,12 +1258,12 @@ namespace Greenshot.Forms private void CaptureClipboardToolStripMenuItemClick(object sender, EventArgs e) { - BeginInvoke((MethodInvoker) CaptureHelper.CaptureClipboard); + BeginInvoke((MethodInvoker) delegate { CaptureHelper.CaptureClipboard(); }); } private void OpenFileToolStripMenuItemClick(object sender, EventArgs e) { - BeginInvoke((MethodInvoker) CaptureFile); + BeginInvoke((MethodInvoker) delegate { CaptureFile(); }); } private void CaptureFullScreenToolStripMenuItemClick(object sender, EventArgs e) @@ -1748,6 +1751,12 @@ namespace Greenshot.Forms case ClickActions.CAPTURE_CLIPBOARD: CaptureHelper.CaptureClipboard(); break; + case ClickActions.OPEN_CLIPBOARD_IN_EDITOR: + CaptureHelper.CaptureClipboard(DestinationHelper.GetDestination(EditorDestination.DESIGNATION)); + break; + case ClickActions.OPEN_FILE_IN_EDITOR: + CaptureFile(DestinationHelper.GetDestination(EditorDestination.DESIGNATION)); + break; case ClickActions.CAPTURE_REGION: CaptureHelper.CaptureRegion(false); break; diff --git a/src/Greenshot/Helpers/CaptureHelper.cs b/src/Greenshot/Helpers/CaptureHelper.cs index c55cc2946..662f3439a 100644 --- a/src/Greenshot/Helpers/CaptureHelper.cs +++ b/src/Greenshot/Helpers/CaptureHelper.cs @@ -93,13 +93,7 @@ namespace Greenshot.Helpers } } - public static void CaptureClipboard() - { - using CaptureHelper captureHelper = new CaptureHelper(CaptureMode.Clipboard); - captureHelper.MakeCapture(); - } - - public static void CaptureClipboard(IDestination destination) + public static void CaptureClipboard(IDestination destination = null) { using CaptureHelper captureHelper = new CaptureHelper(CaptureMode.Clipboard); if (destination != null) @@ -173,16 +167,16 @@ namespace Greenshot.Helpers captureHelper.MakeCapture(); } - public static void CaptureFile(string filename) + public static void CaptureFile(string filename, IDestination destination = null) { using CaptureHelper captureHelper = new CaptureHelper(CaptureMode.File); - captureHelper.MakeCapture(filename); - } - public static void CaptureFile(string filename, IDestination destination) - { - using CaptureHelper captureHelper = new CaptureHelper(CaptureMode.File); - captureHelper.AddDestination(destination).MakeCapture(filename); + if (destination != null) + { + captureHelper.AddDestination(destination); + } + + captureHelper.MakeCapture(filename); } public static void ImportCapture(ICapture captureToImport)