/// <summary> /// Assumes the bytes are UTF8 and writes them to the text editor. /// </summary> public override void Write(byte[] buffer, int offset, int count) { string text = UTF8Encoding.UTF8.GetString(buffer, offset, count); textEditor.Write(text); if (!string.IsNullOrEmpty(text)) { OnTextWritten(); } }
protected void OnPaste(object target, ExecutedRoutedEventArgs args) { if (target != textEditor.textArea) { return; } TextArea textArea = textEditor.textArea; if (textArea != null && textArea.Document != null) { Debug.WriteLine(Clipboard.GetText(TextDataFormat.Html)); // convert text back to correct newlines for this document string newLine = TextUtilities.GetNewLineFromDocument(textArea.Document, textArea.Caret.Line); string text = TextUtilities.NormalizeNewLines(Clipboard.GetText(), newLine); string[] commands = text.Split(new String[] { newLine }, StringSplitOptions.None); string scriptText = ""; if (commands.Length > 1) { text = newLine; foreach (string command in commands) { text += "... " + command + newLine; scriptText += command.Replace("\t", " ") + newLine; } } if (!string.IsNullOrEmpty(text)) { bool fullLine = textArea.Options.CutCopyWholeLine && Clipboard.ContainsData(LineSelectedType); bool rectangular = Clipboard.ContainsData(RectangleSelection.RectangularSelectionDataType); if (fullLine) { DocumentLine currentLine = textArea.Document.GetLineByNumber(textArea.Caret.Line); if (textArea.ReadOnlySectionProvider.CanInsert(currentLine.Offset)) { textArea.Document.Insert(currentLine.Offset, text); } } else if (rectangular && textArea.Selection.IsEmpty) { if (!RectangleSelection.PerformRectangularPaste(textArea, textArea.Caret.Position, text, false)) { textEditor.Write(text, false); } } else { textEditor.Write(text, false); } } textArea.Caret.BringCaretToView(); args.Handled = true; if (commands.Length > 1) { dispatcherWindow.Dispatcher.BeginInvoke(new Action(delegate() { ExecuteStatements(scriptText); })); } } }
/// <summary> /// Run on the statement execution thread. /// </summary> private void ExecuteStatements(string scriptText) { lock (scriptText) { _textEditor.Write("\r\n"); ScriptSource scriptSource = _commandLine.ScriptScope.Engine.CreateScriptSourceFromString(scriptText, SourceCodeKind.Statements); string error = ""; try { Executing = true; scriptSource.Execute(_commandLine.ScriptScope); } catch (ThreadAbortException tae) { if (tae.ExceptionState is KeyboardInterruptException) { Thread.ResetAbort(); } error = "KeyboardInterrupt" + System.Environment.NewLine; } catch (SyntaxErrorException exception) { ExceptionOperations eo; eo = _commandLine.ScriptScope.Engine.GetService <ExceptionOperations>(); error = eo.FormatException(exception); } catch (Exception exception) { ExceptionOperations eo; eo = _commandLine.ScriptScope.Engine.GetService <ExceptionOperations>(); error = eo.FormatException(exception) + Environment.NewLine; } Executing = false; if (error != "") { _textEditor.Write(error); } _textEditor.Write(_prompt); } }
/// <summary> /// Assumes the bytes are UTF8 and writes them to the text editor. /// </summary> public override void Write(byte[] buffer, int offset, int count) { string text = UTF8Encoding.UTF8.GetString(buffer, offset, count); textEditor.Write(text); }