private void ExecuteSnagitCapture() { var config = ScreenCaptureConfiguration.Current; if (config.AlwaysShowCaptureOptions) { var form = new ScreenCaptureConfigurationForm() { Owner = Model.Window, IsPreCaptureMode = true }; var result = form.ShowDialog(); if (result == null || !result.Value) { return; } } SnagItAutomation SnagIt = SnagItAutomation.Create(); SnagIt.ActiveForm = Model.Window; var editor = Model.Window.GetActiveMarkdownEditor(); if (editor == null) { return; } SnagIt.CapturePath = editor?.MarkdownDocument.Filename; SnagIt.CapturePath = !string.IsNullOrEmpty(SnagIt.CapturePath) && SnagIt.CapturePath != "untitled" ? Path.GetDirectoryName(SnagIt.CapturePath) : editor.MarkdownDocument.LastImageFolder; string capturedFile = SnagIt.CaptureImageToFile(); if (string.IsNullOrEmpty(capturedFile) || !File.Exists(capturedFile)) { return; } string relPath = FileUtils.GetRelativePath(capturedFile, SnagIt.CapturePath); relPath = relPath.Replace("\\", "/"); if (relPath.StartsWith("..")) { relPath = capturedFile; } if (relPath.Contains(":\\")) { relPath = "file:///" + relPath.Replace("\\", "/"); } string replaceText = "![](" + relPath.Replace(" ", "%20") + ")"; editor.MarkdownDocument.LastImageFolder = SnagIt.CapturePath; // Push the new text into the Editor's Selection editor.SetSelectionAndFocus(replaceText); }