Exemplo n.º 1
0
 public void LockTextBox()
 {
     // Stop redrawing:
     TextBox.BeginUpdate();
     SendMessage(TextBox.Handle, WM_SETREDRAW, 0, IntPtr.Zero);
     // Stop sending of events:
     _savedEventMask = SendMessage(TextBox.Handle, EM_GETEVENTMASK, 0, IntPtr.Zero);
     SendMessage(TextBox.Handle, EM_SETEVENTMASK, 0, IntPtr.Zero);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Execute operation
        /// </summary>
        public override void Execute()
        {
            FastColoredTextBox tb = ts.CurrentTB;

            prevText.Clear();

            ts.OnTextChanging(ref insertedText);

            tb.Selection.BeginUpdate();
            tb.BeginUpdate();
            for (int i = ranges.Count - 1; i >= 0; i--)
            {
                tb.Selection.Start = ranges[i].Start;
                tb.Selection.End   = ranges[i].End;
                prevText.Add(tb.Selection.Text);
                ClearSelected(ts);
                if (insertedText != "")
                {
                    InsertTextCommand.InsertText(insertedText, ts);
                }
            }
            if (ranges.Count > 0)
            {
                ts.OnTextChanged(ranges[0].Start.iLine, ranges[ranges.Count - 1].End.iLine);
            }
            tb.EndUpdate();
            tb.Selection.EndUpdate();
            ts.NeedRecalc(new TextSource.TextChangedEventArgs(0, 1));

            lastSel = new RangeInfo(tb.Selection);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Undo operation
        /// </summary>
        public override void Undo()
        {
            FastColoredTextBox tb = ts.CurrentTB;

            ts.OnTextChanging();
            tb.BeginUpdate();

            tb.Selection.BeginUpdate();
            for (int i = 0; i < ranges.Count; i++)
            {
                tb.Selection.Start = ranges[i].Start;
                for (int j = 0; j < insertedText.Length; j++)
                {
                    tb.Selection.GoRight(true);
                }
                ClearSelected(ts);
                InsertTextCommand.InsertText(prevText[prevText.Count - i - 1], ts);
            }
            tb.Selection.EndUpdate();
            tb.EndUpdate();

            if (ranges.Count > 0)
            {
                ts.OnTextChanged(ranges[0].Start.iLine, ranges[ranges.Count - 1].End.iLine);
            }

            ts.NeedRecalc(new TextSource.TextChangedEventArgs(0, 1));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Colorizes the tokens.
        /// </summary>
        /// <param name="editor">The editor.</param>
        /// <param name="registry">The registry.</param>
        /// <param name="tokens">The tokens.</param>
        /// <param name="errorTokens">The error tokens.</param>
        public void ColorizeTokens(FastColoredTextBox editor, IStyleRegistry registry, IList <SyntaxToken> tokens, IList <IToken> errorTokens)
        {
            int coloring = Interlocked.Exchange(ref _TokenColoringInProgress, 1);

            if (coloring != 0)
            {
                return;
            }

            editor.BeginInvoke(
                new MethodInvoker(() =>
            {
                editor.BeginUpdate();

                try
                {
                    foreach (var token in tokens)
                    {
                        var startingPlace = new Place(token.ActualParserToken.Column, token.ActualParserToken.Line - 1);
                        var stoppingPlace = new Place(token.EndingColumnPosition, token.EndingLineNumber - 1);
                        var tokenRange    = editor.GetRange(startingPlace, stoppingPlace);
                        tokenRange.ClearStyle(StyleIndex.All);
                        var style = registry.GetTokenStyle(token);
                        tokenRange.SetStyle(style);
                    }
                    foreach (var token in errorTokens)
                    {
                        var startingPlace = new Place(token.Column, token.Line - 1);
                        var endPlace      = token.GetEndPlace();

                        // We shift the end position one forward so that the range colors correctly.
                        var stoppingPlace = new Place(endPlace.Position + 1, endPlace.Line - 1);

                        var tokenRange = editor.GetRange(startingPlace, stoppingPlace);
                        tokenRange.SetStyle(registry.GetParseErrorStyle());
                    }
                }
                // ReSharper disable once CatchAllClause
                catch (Exception ex)
                {
                    var errorDisplay = new ErrorDisplay
                    {
                        Text            = Resources.TokenColoringErrorTitle,
                        ErrorMessage    = ex.Message,
                        ErrorStackTrace = ex.StackTrace
                    };
                    errorDisplay.ShowDialog();
                }
                finally
                {
                    editor.EndUpdate();
                }

                _TokenColoringInProgress = 0;
            }));
        }
Exemplo n.º 5
0
 /// <summary>
 /// Executes recorded macro
 /// </summary>
 /// <returns></returns>
 public void ExecuteMacros()
 {
     IsRecording = false;
     UnderlayingControl.BeginUpdate();
     UnderlayingControl.Selection.BeginUpdate();
     UnderlayingControl.BeginAutoUndo();
     foreach (var item in macro)
     {
         if (item is Keys)
         {
             UnderlayingControl.ProcessKey((Keys)item);
         }
         if (item is KeyValuePair <char, Keys> )
         {
             var p = (KeyValuePair <char, Keys>)item;
             UnderlayingControl.ProcessKey(p.Key, p.Value);
         }
     }
     UnderlayingControl.EndAutoUndo();
     UnderlayingControl.Selection.EndUpdate();
     UnderlayingControl.EndUpdate();
 }
        public void SetState(CodeSnippet snippet)
        {
            _StateSnippet       = snippet;
            _supressTextChanged = true;
            _tb.BeginUpdate();

            _TextBoxHelper.SetEditorView(snippet);

            string _text = snippet.GetCode();

            _tb.Text = !string.IsNullOrEmpty(_text) ? _text : "";
            _tb.ClearUndo();
            _mainform.tbPath.Text = snippet.GetPath();// + $"    [C: {snippet.CreationDate},M:{snippet.CodeLastModificationDate:yyyy-MM-dd HH:mm:ss}]";
            _tb.WordWrap          = snippet.Wordwrap;
            _tb.SelectionStart    = 0;
            _tb.SelectionLength   = 0;
            _tb.ScrollControlIntoView(_tb);

            int _lines = _tb.LinesCount;

            try
            {
                if (_lines > snippet.CurrentLine)
                {
                    _tb.GotoLine(snippet.CurrentLine);
                }
            }
            catch { }

            _mainform.mnuWordwrap.Checked    = snippet.Wordwrap;
            _mainform.mnuHTMLPreview.Checked = snippet.HtmlPreview;

            _tb.EndUpdate();

            _supressTextChanged = false;
        }
Exemplo n.º 7
0
        protected override void Append(LoggingEvent loggingEvent)
        {
            if (_richTextBox == null)
            {
                if (string.IsNullOrEmpty(FormName) ||
                    string.IsNullOrEmpty(TextBoxName))
                {
                    return;
                }

                Form form = Application.OpenForms[FormName];
                if (form == null)
                {
                    return;
                }

                _richTextBox = FindControlRecursive(form, TextBoxName) as FastColoredTextBox;
                if (_richTextBox == null)
                {
                    return;
                }

                form.FormClosing += (s, e) => _richTextBox = null;
            }

            lock (_richTextBox)
            {
                // This check is required a second time because this class
                // is executing on multiple threads.
                if (_richTextBox == null)
                {
                    return;
                }

                // Because the logging is running on a different thread than
                // the GUI, the control's "BeginInvoke" method has to be
                // leveraged in order to append the message. Otherwise, a
                // threading exception will be thrown.
                Action <FastColoredTextBox, string> del = new Action <FastColoredTextBox, string>((_richTextBox, s) =>
                {
                    //some stuffs for best performance
                    _richTextBox.BeginUpdate();
                    _richTextBox.Selection.BeginUpdate();
                    //remember user selection
                    Range userSelection = _richTextBox.Selection.Clone();
                    //add text with predefined style
                    _richTextBox.TextSource.CurrentTB = _richTextBox;
                    _richTextBox.AppendText("=======================================================\n", styles[loggingEvent.Level.Name]);
                    _richTextBox.AppendText(s, styles[loggingEvent.Level.Name]);
                    _richTextBox.AppendText("=======================================================\n", styles[loggingEvent.Level.Name]);
                    //restore user selection
                    if (!userSelection.IsEmpty || userSelection.Start.iLine < _richTextBox.LinesCount - 2)
                    {
                        _richTextBox.Selection.Start = userSelection.Start;
                        _richTextBox.Selection.End   = userSelection.End;
                    }
                    else
                    {
                        _richTextBox.GoEnd();    //scroll to end of the text
                    }
                    //
                    _richTextBox.Selection.EndUpdate();
                    _richTextBox.EndUpdate();
                }
                                                                                                  );
                _richTextBox.BeginInvoke(del, _richTextBox, loggingEvent.RenderedMessage + Environment.NewLine);
            }
        }