Ejemplo n.º 1
0
 public static void AppendTextToEditor(this TextEditor editor, string text, Color color)
 {
     editor.TextArea.ClearSelection();
     editor.TextArea.TextView.LineTransformers.Add(new LineColorizer(editor.LineCount, new SolidColorBrush(Color.FromArgb(color.A, color.R, color.G, color.B))));
     editor.AppendText(text);
     editor.AppendText(Environment.NewLine);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Appends text and scrolls down the log
        /// </summary>
        public void AppendOutput(string s, ErrorType errorType, ErrorOrigin origin)
        {
            if (errorType != ErrorType.Message)
            {
                s = "> (" + DateTime.Now.ToLongTimeString() + ") " + s;
            }
            TextEditor        editor = null;
            var               selTab = LogTab.System;
            TextMarkerService tms    = null;

            switch (origin)
            {
            default:
                editor = Text_Sys;
                selTab = LogTab.System;
                tms    = tms1;
                break;

            case ErrorOrigin.Build:
                editor = Text_Build;
                selTab = LogTab.Build;
                tms    = tms2;
                break;

            case ErrorOrigin.Debug:
            case ErrorOrigin.Program:
                selTab = LogTab.Output;
                editor = Text_Output;
                tms    = tms3;
                break;
            }

            if (editor == null)
            {
                return;
            }

            //TODO?: Find out why invoking the dispatcher thread blocks the entire application sometimes
            if (!Util.IsDispatcherThread)
            {
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    SelectedTab = selTab;
                    int off     = editor.Document.TextLength;
                    editor.AppendText(s + "\r\n");
                    editor.ScrollToEnd();

                    AddMarkerForOffsetUntilEnd(editor, tms, off, errorType);
                }), System.Windows.Threading.DispatcherPriority.Background);
            }
            else
            {
                int off = editor.Document.TextLength;
                SelectedTab = selTab;
                editor.AppendText(s + "\r\n");
                editor.ScrollToEnd();

                AddMarkerForOffsetUntilEnd(editor, tms, off, errorType);
            }
        }
Ejemplo n.º 3
0
        private void FormatCL()
        {
            if (this.ReadOnly)
            {
                return;
            }

            string[] Lines = textEditor.Text.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.None);
            textEditor.SelectAll();
            textEditor.SelectedText = "";
            int length = (RcdLen > 0 ? RcdLen : 80);

            textEditor.AppendText(String.Join(Environment.NewLine, CLFile.CorrectLines(Lines, length)));
        }
Ejemplo n.º 4
0
        public void FormatCL()
        {
            string[] Lines = textEditor.Text.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.None);
            textEditor.Clear();
            int length = (RcdLen > 0 ? RcdLen : 80);

            textEditor.AppendText(String.Join(Environment.NewLine, CLFile.CorrectLines(Lines, length)));
        }
Ejemplo n.º 5
0
        public TextInputView(string text, string info, string title)
        {
            InitializeComponent();

            InfoLabel.Content = info;
            TextEditor.AppendText(text);
            Title = title;
        }
Ejemplo n.º 6
0
        private void cmdProcess__Click(object sender, RoutedEventArgs e)
        {
            AlphabetPosition("The sunset sets at twelve o' clock.");

            TextEditor.Text += "\nsdgfsgdsfgsdfg";

            TextEditor.AppendText("\nzsdgasdfasdfasdf");

            ProcessFiles();
        }
Ejemplo n.º 7
0
 private void PerformTextInput(string text)
 {
     if (text == "\n" || text == "\r\n")
     {
         string newLine = TextUtilities.GetNewLineFromDocument(TextArea.Document, TextArea.Caret.Line);
         TextEditor.AppendText(newLine);
     }
     else
     {
         TextEditor.AppendText(text);
     }
     TextArea.Caret.BringCaretToView();
 }
Ejemplo n.º 8
0
 void FlushLog(object s = null, object e = null)
 {
     if (_writer.Buffer.Length > 0)
     {
         lock (_writer.Buffer)
         {
             var str = _writer.Buffer.ToString();
             TextEditor.AppendText(str);
             TextEditor.ScrollToEnd();
             _writer.Buffer.Clear();
             _output.Append(str);
         }
     }
 }
Ejemplo n.º 9
0
        private void Execute()
        {
            Save();

            LogBox.Clear();
            LogBox.AppendText(DateTime.Now.ToString() + "\n");
            MemoryStream             ms       = new MemoryStream();
            EventRaisingStreamWriter outputWr = new EventRaisingStreamWriter(ms);

            outputWr.StringWritten += sWr_StringWritten;

            var o = MainForm.QHScriptEngine.Runtime.IO.OutputStream;

            MainForm.QHScriptEngine.Runtime.IO.SetOutput(ms, outputWr);
            var scope = HackContext.CreateScriptScope(MainForm.QHScriptEngine);

            MainForm.QHScriptEngine.Execute(CodeView.Text, scope);
            MainForm.QHScriptEngine.Runtime.IO.SetOutput(o, Encoding.UTF8);

            void sWr_StringWritten(object sd, OnWrittenEventArgs <string> ev)
            {
                LogBox.AppendText(ev.Value);
            }
        }
Ejemplo n.º 10
0
 public void OutputLog(string s)
 {
     LogBox.AppendText(s + "\n");
 }
Ejemplo n.º 11
0
        void ProcessAppendText()
        {
            List <AppendCall> appendCalls;

            lock (appendLock) {
                appendCalls      = this.appendCalls;
                this.appendCalls = new List <AppendCall>();
            }
            Debug.Assert(appendCalls.Count > 0);
            if (appendCalls.Count == 0)
            {
                return;
            }

            MessageViewCategory newCategory = appendCalls[appendCalls.Count - 1].Category;

            if (messageCategories[SelectedCategoryIndex] != newCategory)
            {
                SelectCategory(newCategory.Category);
                return;
            }

            bool   clear;
            string text;

            if (appendCalls.Count == 1)
            {
                //LoggingService.Debug("CompilerMessageView: Single append.");
                clear = appendCalls[0].ClearCategory;
                text  = appendCalls[0].Text;
            }
            else
            {
                if (LoggingService.IsDebugEnabled)
                {
                    LoggingService.Debug("CompilerMessageView: Combined " + appendCalls.Count + " appends.");
                }

                clear = false;
                StringBuilder b = new StringBuilder();
                foreach (AppendCall append in appendCalls)
                {
                    if (append.Category == newCategory)
                    {
                        if (append.ClearCategory)
                        {
                            b.Length = 0;
                            clear    = true;
                        }
                        b.Append(append.Text);
                    }
                }
                text = b.ToString();
            }

            if (clear)
            {
                textEditor.Text = text;
            }
            else
            {
                textEditor.AppendText(text);
            }

            textEditor.ScrollToEnd();
        }
Ejemplo n.º 12
0
 public void AppendText(string text)
 {
     TextEditor.AppendText(text);
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Sets the editor options.
        /// </summary>
        /// <param name="editor">The editor.</param>
        /// <param name="leftSide">if set to <c>true</c> [left side].</param>
        protected virtual void SetEditorOptions(TextEditor editor, bool leftSide)
        {
            var ctx = new ContextMenu
            {
                Items = new List <MenuItem>()
                {
                    new MenuItem()
                    {
                        Header  = ViewModel.EditorCopy,
                        Command = ReactiveCommand.Create(() => editor.Copy()).DisposeWith(Disposables)
                    },
                    new MenuItem()
                    {
                        Header  = ViewModel.EditorCut,
                        Command = ReactiveCommand.Create(() => editor.Cut()).DisposeWith(Disposables)
                    },
                    new MenuItem()
                    {
                        Header  = ViewModel.EditorPaste,
                        Command = ReactiveCommand.Create(() => editor.Paste()).DisposeWith(Disposables)
                    },
                    new MenuItem()
                    {
                        Header  = ViewModel.EditorDelete,
                        Command = ReactiveCommand.Create(() => editor.Delete()).DisposeWith(Disposables)
                    },
                    new MenuItem()
                    {
                        Header  = ViewModel.EditorSelectAll,
                        Command = ReactiveCommand.Create(() => editor.SelectAll()).DisposeWith(Disposables)
                    },
                    new MenuItem()
                    {
                        Header = "-"
                    },
                    new MenuItem()
                    {
                        Header  = ViewModel.EditorUndo,
                        Command = ReactiveCommand.Create(() => editor.Undo()).DisposeWith(Disposables)
                    },
                    new MenuItem()
                    {
                        Header  = ViewModel.EditorRedo,
                        Command = ReactiveCommand.Create(() => editor.Redo()).DisposeWith(Disposables)
                    }
                }
            };

            editor.ContextMenu = ctx;

            editor.Options = new TextEditorOptions()
            {
                ConvertTabsToSpaces = true,
                IndentationSize     = 4
            };
            editor.TextArea.ActiveInputHandler = new Implementation.AvaloniaEdit.TextAreaInputHandler(editor);

            ViewModel.WhenAnyValue(p => p.EditingYaml).Subscribe(s =>
            {
                setEditMode();
            }).DisposeWith(Disposables);
            setEditMode();

            void setEditMode()
            {
                if (ViewModel.EditingYaml)
                {
                    if (yamlHighlightingDefinition == null)
                    {
                        yamlHighlightingDefinition = GetHighlightingDefinition(Constants.Resources.YAML);
                    }
                    editor.SyntaxHighlighting = yamlHighlightingDefinition;
                }
                else
                {
                    if (pdxScriptHighlightingDefinition == null)
                    {
                        pdxScriptHighlightingDefinition = GetHighlightingDefinition(Constants.Resources.PDXScript);
                    }
                    editor.SyntaxHighlighting = pdxScriptHighlightingDefinition;
                }
            }

            bool manualAppend = false;

            editor.TextChanged += (sender, args) =>
            {
                // It's a hack I know see: https://github.com/AvaloniaUI/AvaloniaEdit/issues/99.
                // I'd need to go into the code to fix it and it ain't worth it. There doesn't seem to be any feedback on this issue as well.
                var lines = editor.Text.SplitOnNewLine(false).ToList();
                if (lines.Count() > 3)
                {
                    if (manualAppend)
                    {
                        manualAppend = false;
                        return;
                    }
                    var carretOffset = editor.CaretOffset;
                    for (int i = 1; i <= 3; i++)
                    {
                        var last = lines[lines.Count() - i];
                        if (!string.IsNullOrWhiteSpace(last))
                        {
                            manualAppend = true;
                            editor.AppendText("\r\n");
                        }
                    }
                    if (manualAppend)
                    {
                        editor.CaretOffset = carretOffset;
                    }
                }
                lines = editor.Text.SplitOnNewLine().ToList();
                string text = string.Join(Environment.NewLine, lines);
                ViewModel.CurrentEditText = text;
            };
        }
Ejemplo n.º 14
0
 public override void Write(string v)
 {
     tb.AppendText(v);
 }
Ejemplo n.º 15
0
        public static void Initialize(Dispatcher dispatcher)
        {
            LogView.Implementation.Factory = (stream, color, clear, dark) =>
            {
                TextEditor textBox = null;

                return(Control.Create(self =>
                {
                    textBox = new TextEditor()
                    {
                        IsReadOnly = true,
                        Background = Brushes.Transparent,
                        VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
                        HorizontalScrollBarVisibility = ScrollBarVisibility.Auto
                    };

                    textBox.SizeChanged += (sender, args) =>
                    {
                        var scrollToEnd = args.PreviousSize.Height + textBox.VerticalOffset + 20 >= textBox.ExtentHeight;
                        if (scrollToEnd)
                        {
                            textBox.ScrollToEnd();
                        }
                    };

                    stream.Buffer(TimeSpan.FromSeconds(1.0 / 30.0))
                    .Where(c => c.Count > 0)
                    .ObserveOn(Fusion.Application.MainThread)
                    .Subscribe(msgsToAdd =>
                    {
                        var shouldScrollToEnd = textBox.ViewportHeight + textBox.VerticalOffset + 20 >= textBox.ExtentHeight;

                        textBox.BeginChange();
                        foreach (var msg in msgsToAdd)
                        {
                            textBox.AppendText(msg);
                        }
                        textBox.EndChange();

                        if (shouldScrollToEnd)
                        {
                            textBox.ScrollToVerticalOffset(double.MaxValue);
                        }
                    });

                    clear.ObserveOn(Fusion.Application.MainThread)
                    .Subscribe(_ => textBox.Clear());

                    self.BindNativeDefaults(textBox, dispatcher);

                    self.BindNativeProperty(dispatcher, "color", color,
                                            value =>
                    {
                        textBox.Foreground = new SolidColorBrush(value.ToColor());
                    });

                    return textBox;
                }).SetContextMenu(
                           Menu.Item(name: "Copy", command: Command.Enabled(() => textBox.Copy()))
                           + Menu.Item(name: "Select All", command: Command.Enabled(() => textBox.SelectAll()))
                           ));
            };
        }
Ejemplo n.º 16
0
 private void AppendToEditor(TextEditor editor, string text)
 {
     Dispatcher.Invoke(() => { editor.AppendText(text); });
 }