Ejemplo n.º 1
0
        private Widget CreateTextView()
        {
            textView = new ThemedTextView {
                SquashDuplicateLines = true
            };
            textWriter = new TextViewWriter(textView)
            {
                SystemOut = System.Console.Out,
            };
            System.Console.SetOut(textWriter);
            System.Console.SetError(textWriter);
            var menu = new Menu();

            menu.Add(Command.Copy);

            menu.Add(commandClear);
            textView.Updated += (dt) => {
                if (
                    textView.Input.WasKeyPressed(Key.Mouse0) ||
                    textView.Input.WasKeyPressed(Key.Mouse1)
                    )
                {
                    textView.SetFocus();
                    Window.Current.Activate();
                }
                if (textView.IsFocused())
                {
                    Command.Copy.Enabled = true;
                    if (Command.Copy.WasIssued())
                    {
                        Command.Copy.Consume();
                        Clipboard.Text = textView.DisplayText;
                    }
                }
                if (textView.Input.WasKeyPressed(Key.Mouse1))
                {
                    menu.Popup();
                }
                if (textView.IsFocused() && Command.Copy.WasIssued())
                {
                    Command.Copy.Consume();
                    Clipboard.Text = textView.Text;
                }
                if (commandClear.WasIssued())
                {
                    commandClear.Consume();
                    textView.Clear();
                }
                var i = textView.Content.Nodes.Count;
                // numbers choosen by guess
                if (i >= 500)
                {
                    textView.Content.Nodes.RemoveRange(0, 250);
                }
            };

            return(textView);
        }
Ejemplo n.º 2
0
        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);
            }
        }