Beispiel #1
0
        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();

            SnagIt.CapturePath = editor?.MarkdownDocument.Filename;
            SnagIt.CapturePath = !string.IsNullOrEmpty(SnagIt.CapturePath) && SnagIt.CapturePath != "untitled" ?
                                 Path.GetDirectoryName(SnagIt.CapturePath) :
                                 mmApp.Configuration.LastImageFolder;


            string capturedFile = SnagIt.CaptureImageToFile();

            if (string.IsNullOrEmpty(capturedFile) || !File.Exists(capturedFile))
            {
                return;
            }

            capturedFile = FileUtils.GetRelativePath(capturedFile, SnagIt.CapturePath);
            string relPath = capturedFile.Replace("\\", "/");

            if (relPath.StartsWith(".."))
            {
                relPath = capturedFile;
            }

            if (relPath.Contains(":\\"))
            {
                relPath = "file:///" + relPath.Replace("\\", "/");
            }

            string replaceText = "![](" + relPath.Replace(" ", "%20") + ")";

            mmApp.Configuration.LastImageFolder = SnagIt.CapturePath;

            // Push the new text into the Editor's Selection
            SetSelection(replaceText);
        }
Beispiel #2
0
        public override void OnExecute(object sender)
        {
            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();

            SnagIt.CapturePath = editor?.MarkdownDocument.Filename;
            if (!string.IsNullOrEmpty(SnagIt.CapturePath))
            {
                SnagIt.CapturePath = Path.GetDirectoryName(SnagIt.CapturePath);
            }


            string capturedFile = SnagIt.CaptureImageToFile();

            if (string.IsNullOrEmpty(capturedFile) || !File.Exists(capturedFile))
            {
                return;
            }

            capturedFile = FileUtils.GetRelativePath(capturedFile, SnagIt.CapturePath);
            string relPath = capturedFile.Replace("\\", "/");

            if (relPath.StartsWith(".."))
            {
                relPath = capturedFile;
            }

            string replaceText = "![](" + relPath + ")";

            // Push the new text into the Editor's Selection
            SetSelection(replaceText);
        }
        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;


            if (!SnagIt.CaptureImageToClipboard())
            {
                return;
            }

            using (var bitmap = ClipboardHelper.GetImage())
            {
                if (bitmap == null ||
                    FileSaver.SaveBitmapAndLinkInEditor(bitmap) == null)
                {
                    ShowStatusError("Image capture failed.");
                    return;
                }
            }
        }