From 48fc52aab74250859d99181c0e56ff142eaf456c Mon Sep 17 00:00:00 2001 From: Robin Date: Sat, 24 Dec 2016 22:24:16 +0100 Subject: [PATCH] FEATURE-998: opening the explorer with the last file selected, this makes it jump to the correct file. [skip ci] --- Greenshot/Forms/MainForm.cs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Greenshot/Forms/MainForm.cs b/Greenshot/Forms/MainForm.cs index 9c957ef90..d5d275398 100644 --- a/Greenshot/Forms/MainForm.cs +++ b/Greenshot/Forms/MainForm.cs @@ -1304,8 +1304,8 @@ namespace Greenshot { private void NotifyIconClick(ClickActions clickAction) { switch (clickAction) { case ClickActions.OPEN_LAST_IN_EXPLORER: - string path = null; - if (!string.IsNullOrEmpty(_conf.OutputFileAsFullpath)) { + string path = _conf.OutputFileAsFullpath; + if (!File.Exists(path)) { string lastFilePath = Path.GetDirectoryName(_conf.OutputFileAsFullpath); if (!string.IsNullOrEmpty(lastFilePath) && Directory.Exists(lastFilePath)) { path = lastFilePath; @@ -1320,7 +1320,22 @@ namespace Greenshot { if (path != null) { try { - using (Process.Start(path)) {} + // Check if path is a directory + if (Directory.Exists(path)) + { + using (Process.Start(path)) + { + } + } + // Check if path is a file + else if (File.Exists(path)) + { + // Start the explorer process and select the file + using (var explorer = Process.Start("explorer.exe", $"/select,\"{path}\"")) + { + explorer?.WaitForInputIdle(500); + } + } } catch (Exception ex) { // Make sure we show what we tried to open in the exception ex.Data.Add("path", path);