private IEnumerator <object> ManageTextViewTask() { var menu = new Menu() { new Command("View in External Editor", () => { if (textWriter.LogFilePath != null) { System.Diagnostics.Process.Start(textWriter.LogFilePath); } }), Command.MenuSeparator, new Command("Clear", () => { textView.Clear(); }), Command.Copy }; textView.Gestures.Add( new ClickGesture(0, () => { textView.SetFocus(); Window.Current.Activate(); }) ); textView.Gestures.Add( new ClickGesture(1, () => { textView.SetFocus(); Window.Current.Activate(); menu.Popup(); }) ); while (true) { if (textView.IsFocused()) { Command.Copy.Enabled = true; if (Command.Copy.WasIssued()) { Command.Copy.Consume(); Clipboard.Text = textView.DisplayText; } } if (textView.Content.Nodes.Count > TextViewWriter.MaxMessages) { textView.Content.Nodes.RemoveRange(0, textView.Content.Nodes.Count - TextViewWriter.MaxMessages / 2); } textWriter.ProcessPendingMessages(); yield return(null); } }
private Widget CreateTextView() { textView = new ThemedTextView { SquashDuplicateLines = true }; textWriter = new TextViewWriter(textView); System.Console.SetOut(textWriter); System.Console.SetError(textWriter); var menu = new Menu(); menu.Add(Command.Copy); textView.Updated += (dt) => { if (textView.Input.WasKeyPressed(Key.Mouse0)) { textView.SetFocus(); } if (textView.Input.WasKeyPressed(Key.Mouse1)) { menu.Popup(); } if (textView.IsFocused() && Command.Copy.WasIssued()) { Command.Copy.Consume(); Clipboard.Text = textView.Text; } var i = textView.Content.Nodes.Count; // numbers choosen by guess if (i >= 500) { textView.Content.Nodes.RemoveRange(0, 250); } }; return(textView); }