/// <summary> /// Adds Copy/Cut/Paste Context menu options /// </summary> public void AddCopyPaste() { var selText = Model.ActiveEditor?.AceEditor?.getselection(false); var model = Model; var miCut = new MenuItem { Header = "Cut", InputGestureText = "ctrl-x" }; miCut.Click += (o, args) => model.ActiveEditor.SetSelection(""); ContextMenu.Items.Add(miCut); var miCopy = new MenuItem() { Header = "Copy", InputGestureText = "ctrl-c" }; miCopy.Click += (o, args) => { ClipboardHelper.SetText(selText, true); }; ContextMenu.Items.Add(miCopy); var miCopyHtml = new MenuItem() { Header = "Copy As Html", InputGestureText = "ctrl-shift-c" }; miCopyHtml.Command = Model.Commands.CopyAsHtmlCommand; ContextMenu.Items.Add(miCopyHtml); bool hasClipboardData = false; var miPaste = new MenuItem() { Header = "Paste", InputGestureText = "ctrl-v" }; if (ClipboardHelper.ContainsImage()) { hasClipboardData = true; miPaste.Header = "Paste Image"; miPaste.Click += (o, args) => model.ActiveEditor?.PasteOperation(); } else { hasClipboardData = ClipboardHelper.ContainsText(); } miPaste.IsEnabled = hasClipboardData; ContextMenu.Items.Add(miPaste); if (string.IsNullOrEmpty(selText)) { miCopy.IsEnabled = false; miCopyHtml.IsEnabled = false; miCut.IsEnabled = false; } else { if (Model.ActiveEditor?.EditorSyntax != "markdown") { miCopyHtml.IsEnabled = false; } else { ContextMenu.Items.Add(new Separator()); var miRemoveFormatting = new MenuItem { Header = "Remove Markdown Formatting", InputGestureText = "ctrl-shift-z" }; miRemoveFormatting.Command = Model.Commands.RemoveMarkdownFormattingCommand; ContextMenu.Items.Add(miRemoveFormatting); } } }
public int ExecuteWkProcess(string parms, bool copyCommandLineToClipboard = false) { string exe = "wkhtmltopdf.exe"; if (!string.IsNullOrEmpty(ExecutionPath)) { exe = Path.Combine(ExecutionPath, exe); } StringBuilder output = new StringBuilder(); FullExecutionCommand = "\"" + exe + "\" " + parms; if (copyCommandLineToClipboard) { ClipboardHelper.SetText(FullExecutionCommand); } using (Process process = new Process()) { process.StartInfo.FileName = exe; process.StartInfo.Arguments = parms; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardInput = true; void OnProcessOnOutputDataReceived(object o, DataReceivedEventArgs e) => output.AppendLine(e.Data); process.OutputDataReceived += OnProcessOnOutputDataReceived; process.ErrorDataReceived += OnProcessOnOutputDataReceived; try { process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); bool result = process.WaitForExit(180000); if (!result) { return(1473); } } catch (Exception ex) { ErrorMessage = ex.Message; return(-1); } finally { process.OutputDataReceived -= OnProcessOnOutputDataReceived; process.ErrorDataReceived -= OnProcessOnOutputDataReceived; } ExecutionOutputText = output.ToString(); return(process.ExitCode); } }