Beispiel #1
0
        private void mSLSyntaxHighlight(FastColoredTextBox sender, Range range, DocumentType syntaxType)
        {
            range.ClearStyle(MslSyntaxHighlighter.CommandStyle,
                             MslSyntaxHighlighter.CommentStyle,
                             MslSyntaxHighlighter.CustomCommandStyle,
                             MslSyntaxHighlighter.ErrorStyle,
                             MslSyntaxHighlighter.FunctionStyle,
                             MslSyntaxHighlighter.FunctionPropertyStyle,
                             MslSyntaxHighlighter.KeywordStyle,
                             MslSyntaxHighlighter.AliasStyle,
                             MslSyntaxHighlighter.VariableStyle);

            // Highlight the text.
            bool bookmarksChanged = false; bool errorsChanged = false;
            // If the changed line was a continuation, find the start.
            int      i = range.FromLine;
            LineInfo lineInfo;

            while (i != 0 && this.lineInfoTable.TryGetValue(this.TextBox[i - 1].UniqueId, out lineInfo) && lineInfo.State == (byte)MslSyntaxHighlighter.ParseStateIndex.Continuation)
            {
                --i;
            }

            for (; i < range.tb.LinesCount; ++i)
            {
                LineInfo oldLineInfo; MslBookmark oldBookmark = null; string oldTitle = null;
                if (this.lineInfoTable.TryGetValue(range.tb[i].UniqueId, out oldLineInfo))
                {
                    oldBookmark = oldLineInfo.bookmark;
                    oldTitle    = oldBookmark?.title;
                }

                var newLineInfo = MslSyntaxHighlighter.Highlight(range.tb, i, syntaxType);

                if (this.Type != DocumentType.Text)
                {
                    // Deal with bookmarks.
                    if (oldBookmark != null)
                    {
                        if (newLineInfo.bookmark != null)
                        {
                            if (oldBookmark != newLineInfo.bookmark)
                            {
                                // A bookmark was replaced.
                                this.bookmarks[this.bookmarks.IndexOf(oldBookmark)] = newLineInfo.bookmark;
                                bookmarksChanged = true;
                            }
                            else if (oldTitle != newLineInfo.bookmark.title)
                            {
                                // A bookmark was renamed.
                                this.BookmarkChanged?.Invoke(this, new BookmarkEventArgs(newLineInfo.bookmark));
                            }
                        }
                        else
                        {
                            // A bookmark was removed.
                            this.bookmarks.Remove(oldLineInfo.bookmark);
                            bookmarksChanged = true;
                        }
                    }
                    else
                    {
                        if (newLineInfo?.bookmark != null)
                        {
                            // A bookmark was added.
                            this.bookmarks.Add(newLineInfo.bookmark);
                            bookmarksChanged = true;
                        }
                    }
                }

                if (this.Type != DocumentType.Text && this.Type != DocumentType.INI)
                {
                    if (oldLineInfo != null && oldLineInfo.errors.Length != 0)
                    {
                        errorsChanged = true;
                        foreach (var error in oldLineInfo.errors)
                        {
                            this.errors.Remove(error);
                        }
                    }

                    // Skip past continued lines.
                    while (i < range.tb.LinesCount && this.lineInfoTable.TryGetValue(this.TextBox[i].UniqueId, out lineInfo) && lineInfo.State == (byte)MslSyntaxHighlighter.ParseStateIndex.Continuation)
                    {
                        // Always reparse the next line if there is a continuation.
                        // This avoids glitches when continuations are added or removed.
                        oldLineInfo = null;
                        ++i;

                        if (lineInfo.errors.Length != 0)
                        {
                            errorsChanged = true;
                        }
                        foreach (Error error in lineInfo.errors)
                        {
                            this.errors.Remove(error);
                        }
                    }

                    // Deal with errors.
                    if (newLineInfo != null && newLineInfo.errors.Length != 0)
                    {
                        errorsChanged = true;
                        foreach (var error in newLineInfo.errors)
                        {
                            this.errors.Add(error);
                        }
                    }

                    // (Normally we only reparse the next line if it was changed, or the current line was changed in such
                    //  a way as to affect its meaning, such as adding braces.)
                    if (i >= range.ToLine && oldLineInfo != null &&
                        newLineInfo.BraceLevel == oldLineInfo.BraceLevel && newLineInfo.State == oldLineInfo.State)
                    {
                        break;
                    }
                }
                else
                {
                    // Such cascading isn't an issue for INI files.
                    if (i >= range.ToLine)
                    {
                        break;
                    }
                }
            }

            if (bookmarksChanged)
            {
                //functionList.Items.Clear();
                //if (currentItem == document) RebuildFunctionList();
            }

            if (errorsChanged)
            {
                //errorList.Items.Clear();
                //RebuildErrorList();
            }

            range.SetStyle(ControlCharStyle.Instance, @"[\x01-\x03\x0F\x13\x16\x1C\x1F]");

            range.ClearFoldingMarkers();
            range.SetFoldingMarkers("(?<![^ :\r\n]){(?![^ \r\n])", "(?<![^ \r\n])}(?![^ \r\n])");

            this.TextChanged?.Invoke(this, new TextChangedEventArgs(range));
        }
Beispiel #2
0
 public BookmarkEventArgs(MslBookmark bookmark)
 {
     this.Bookmark = bookmark;
 }
Beispiel #3
0
 public MslDialog(string name, MslDocument document, MslBookmark bookmark) : base("pixels")
 {
     this.Name     = name;
     this.Document = document;
     this.Bookmark = bookmark;
 }