示例#1
0
        public void UpdateListMargin(ScintillaNET.Scintilla sci, int?start, int?end)
        {
            int startLine = (start == null) ? 0                 : sci.LineFromPosition(start.Value);
            int endLine   = (end == null) ? sci.Lines.Count - 1 : sci.LineFromPosition(end.Value);

            startLine = Math.Max(0, startLine);
            endLine   = Math.Min(sci.Lines.Count - 1, endLine);

            for (int idxline = startLine; idxline <= endLine; idxline++)
            {
                var line = sci.Lines[idxline];

                line.MarkerDelete(STYLE_MARKER_LIST_ON);
                line.MarkerDelete(STYLE_MARKER_LIST_OFF);
                line.MarkerDelete(STYLE_MARKER_LIST_MIX);

                var hl = GetListHighlight(line.Text);

                if (hl == ListHighlightValue.TRUE)
                {
                    line.MarkerAdd(STYLE_MARKER_LIST_ON);
                }
                if (hl == ListHighlightValue.FALSE)
                {
                    line.MarkerAdd(STYLE_MARKER_LIST_OFF);
                }
                if (hl == ListHighlightValue.INTERMED)
                {
                    line.MarkerAdd(STYLE_MARKER_LIST_MIX);
                }
            }
        }
示例#2
0
            protected void Set(ScintillaNET.Scintilla ed, int position, int len)
            {
                int endPos  = position + len;
                int lnStart = ed.LineFromPosition(position);
                int lnEnd   = ed.LineFromPosition(endPos);

                line = ed.Lines.Count;

                count = lnEnd - lnStart;

                isEnable = false;

                if (count == 0)
                {
                    if (position == lnStart && endPos == lnEnd)
                    {
                        isEnable = true;
                        ++count;
                    }
                }
                else if (position == lnStart)
                {   // 行の開始位置か
                    if (endPos == lnEnd)
                    {
                        // 最終位置が終了行がスタート位置
                        --count;
                    }
                    else if (endPos == lnEnd)
                    {
                        // 最終位置が終了行が終了位置
                        //++count;
                    }
                }
                else
                {
                    if (endPos == lnEnd)
                    {
                        line++;
                        count--;
                    }
                    else if (endPos == lnEnd)
                    {
                        ;
                    }
                    else
                    {
                        Init();
                        return;
                    }
                }
            }
示例#3
0
 private void TextArea_MarginClick(object sender, MarginClickEventArgs e)
 {
     if (e.Margin == BOOKMARK_MARGIN)
     {
         // Do we have a marker for this line?
         const uint mask = (1 << BOOKMARK_MARKER);
         var        line = TextArea.Lines[TextArea.LineFromPosition(e.Position)];
         if ((line.MarkerGet() & mask) > 0)
         {
             // Remove existing bookmark
             line.MarkerDelete(BOOKMARK_MARKER);
         }
         else
         {
             // Add bookmark
             line.MarkerAdd(BOOKMARK_MARKER);
         }
     }
 }
示例#4
0
        public void Style(Scintilla scintilla, int startPos, int endPos)
        {
            // 改行コードをWindowsフォーマット(CR+LF)またはUnixフォーマット(LF)から
            // Macフォーマット(CR)にしたときに発生する例外(IndexOutOfRangeException)を回避
            startPos = startPos < 0 ? 0 : startPos;
            endPos = endPos > scintilla.TextLength ? scintilla.TextLength : endPos;

            int lineNumber = scintilla.LineFromPosition(startPos);
            startPos = scintilla.Lines[lineNumber].Position;

            char chBeforePrev = '\0';
            char chPrev = '\0';
            char ch = '\0';
            char chNext = '\0';
            char chAfterNext = '\0';
            int length = 0;
            ParseState state = ParseState.None;

            switch (scintilla.GetStyleAt(startPos - 1)) {
                case HspLexer.StylePreprocessor:
                    state = ParseState.AfterPreprocessor;
                    break;
                case HspLexer.StyleString:
                    state = ParseState.String;
                    break;
                case HspLexer.StyleComment:
                    state = ParseState.Comment;
                    break;
            }

            scintilla.StartStyling(startPos);

            int currentPos = startPos;
            int currentLine = lineNumber;
            int currentLineStartPos = startPos;
            int currentLineEndPos = scintilla.Lines[lineNumber].EndPosition;

            while (currentPos < endPos) {
                chBeforePrev = (char)scintilla.GetCharAt(currentPos - 2);
                chPrev = (char)scintilla.GetCharAt(currentPos - 1);
                ch = (char)scintilla.GetCharAt(currentPos);
                chNext = (char)scintilla.GetCharAt(currentPos + 1);
                chAfterNext = (char)scintilla.GetCharAt(currentPos + 2);

            Process:
                switch (state) {
                    case ParseState.None:
                        if (ch == '\"') {
                            // 文字列
                            scintilla.SetStyling(1, HspLexer.StyleStringLine);
                            state = ParseState.StringLine;
                        } else if (ch == '{' && chNext == '\"') {
                            // 複数行文字列
                            scintilla.SetStyling(2, HspLexer.StyleString);
                            state = ParseState.String;
                            ++currentPos;
                        } else if (ch == '\'') {
                            // 文字
                            scintilla.SetStyling(1, HspLexer.StyleCharacter);
                            state = ParseState.Character;
                        } else if (ch == ';') {
                            // 単一行コメント
                            scintilla.SetStyling(1, HspLexer.StyleCommentLine);
                            state = ParseState.CommentLine;
                        } else if (ch == '/' && chNext == '/') {
                            // 単一行コメント
                            scintilla.SetStyling(2, HspLexer.StyleCommentLine);
                            state = ParseState.CommentLine;
                            ++currentPos;
                        } else if (ch == '/' && chNext == '*') {
                            // 複数行コメント
                            scintilla.SetStyling(2, HspLexer.StyleComment);
                            state = ParseState.Comment;
                            ++currentPos;
                        } else if (ch == '*' && (Char.IsLetter(chNext) || chNext == '_') &&
                            String.IsNullOrWhiteSpace(scintilla.GetTextRange(
                                currentLineStartPos, currentPos - currentLineStartPos))) {
                            // ラベル
                            scintilla.SetStyling(2, HspLexer.StyleLabel);
                            state = ParseState.Label;
                            ++currentPos;
                        } else if (ch == '#' && length == 0 &&
                            String.IsNullOrWhiteSpace(scintilla.GetTextRange(
                                currentLineStartPos, currentPos - currentLineStartPos))) {
                            // プリプロセッサ
                            state = ParseState.Preprocessor;
                            goto Process;
                        } else if ((Char.IsLetter(ch) || ch == '_') && length == 0) {
                            // 識別子
                            state = ParseState.Identifier;
                            goto Process;
                        } else if (ch == ':') {
                            // 行区切り
                            currentLineStartPos = currentPos + 1;
                            scintilla.SetStyling(1, HspLexer.StyleDefault);
                        } else if (ch == '\0') {
                            // NULL文字の場合はすぐreturn
                            return;
                        } else {
                            scintilla.SetStyling(1, HspLexer.StyleDefault);
                        }
                        break;

                    case ParseState.StringLine:
                        if (ch == '\\' && chNext == '\\') {
                            // エスケープシーケンス '\\'
                            scintilla.SetStyling(2, HspLexer.StyleStringLine);
                            ++currentPos;
                        } else if (ch == '\\' && chNext == '\"') {
                            // エスケープシーケンス '\"'
                            scintilla.SetStyling(2, HspLexer.StyleStringLine);
                            ++currentPos;
                        } else if (ch == '\"') {
                            scintilla.SetStyling(1, HspLexer.StyleStringLine);
                            state = ParseState.None;
                        } else {
                            scintilla.SetStyling(1, HspLexer.StyleStringLine);
                        }
                        break;

                    case ParseState.String:
                        if (ch == '\\' && chNext == '\\') {
                            // エスケープシーケンス '\\'
                            scintilla.SetStyling(2, HspLexer.StyleString);
                            ++currentPos;
                        } else if (ch == '\\' && chNext == '\"') {
                            // エスケープシーケンス '\"'
                            scintilla.SetStyling(2, HspLexer.StyleString);
                            ++currentPos;
                        } else if (ch == '\"' && chNext == '}') {
                            scintilla.SetStyling(2, HspLexer.StyleString);
                            state = ParseState.None;
                            ++currentPos;
                        } else {
                            scintilla.SetStyling(1, HspLexer.StyleString);
                        }
                        break;

                    case ParseState.Character:
                        if (ch == '\'') {
                            scintilla.SetStyling(1, HspLexer.StyleCharacter);
                            state = ParseState.None;
                        } else {
                            scintilla.SetStyling(1, HspLexer.StyleCharacter);
                        }
                        break;

                    case ParseState.CommentLine:
                        if (ch == '\n') {
                            scintilla.SetStyling(1, HspLexer.StyleCommentLine);
                            state = ParseState.None;
                        } else {
                            scintilla.SetStyling(1, HspLexer.StyleCommentLine);
                        }
                        break;

                    case ParseState.Comment:
                        if (ch == '*' && chNext == '/') {
                            scintilla.SetStyling(2, HspLexer.StyleComment);
                            state = ParseState.None;
                            ++currentPos;
                        } else {
                            scintilla.SetStyling(1, HspLexer.StyleComment);
                        }
                        break;

                    case ParseState.Label:
                        if (Char.IsLetterOrDigit(ch) || ch == '_') {
                            scintilla.SetStyling(1, HspLexer.StyleLabel);
                        } else {
                            state = ParseState.None;
                            goto Process;
                        }
                        break;

                    case ParseState.Preprocessor:
                        if (ch == '#' && length == 0 &&
                            String.IsNullOrWhiteSpace(scintilla.GetTextRange(
                                currentLineStartPos, currentPos - currentLineStartPos))) {
                            ++length;
                        } else if ((ch == '\t' || ch == '\u0020' || ch == '\u3000') && length == 1) {
                            // '#' の後のタブ文字, 半角スペース, 全角スペースの場合
                            state = ParseState.SpaceInPreprocessor;
                            goto Process;
                        } else if ((Char.IsLetter(ch) || ch == '_') && length == 1) {
                            ++length;
                        } else if ((Char.IsLetterOrDigit(ch) || ch == '_') && length > 1) {
                            ++length;
                        } else {
                            int style = HspLexer.StyleDefault;
                            string identifier = scintilla.GetTextRange(currentPos - length, length);

                            char[] removeChars = { '\t', '\u0020', '\u3000' };
                            identifier = removeChars.Aggregate(identifier, (s, c) => s.Replace(c.ToString(), String.Empty));
                            identifier = identifier.ToLower();

                            if (this.mKeywords.ContainsKey(identifier)) {
                                switch (this.mKeywords[identifier].mType) {
                                    case KeywordType.Preprocessor:
                                        style = HspLexer.StylePreprocessor;
                                        break;
                                }
                            }

                            scintilla.SetStyling(length, style);
                            length = 0;

                            switch (style) {
                                case HspLexer.StyleDefault:
                                    state = ParseState.None;
                                    break;
                                case HspLexer.StylePreprocessor:
                                    state = ParseState.AfterPreprocessor;
                                    break;
                            }
                            goto Process;
                        }
                        break;

                    case ParseState.SpaceInPreprocessor:
                        if ((ch == '\t' || ch == '\u0020' || ch == '\u3000')) {
                            ++length;
                        } else if ((Char.IsLetter(ch) || ch == '_')) {
                            state = ParseState.Preprocessor;
                            goto Process;
                        } else {
                            scintilla.SetStyling(length, HspLexer.StyleDefault);
                            length = 0;
                            state = ParseState.None;
                            goto Process;
                        }
                        break;

                    case ParseState.AfterPreprocessor:
                        if (ch == '\\' && chNext == '\r' && chAfterNext == '\n') {
                            scintilla.SetStyling(3, HspLexer.StylePreprocessor);
                            currentPos += 2;
                        } else if (ch == '\\' && chNext == '\n') {
                            scintilla.SetStyling(2, HspLexer.StylePreprocessor);
                            ++currentPos;
                        } else if (ch == '\r' && chNext == '\n') {
                            scintilla.SetStyling(2, HspLexer.StyleDefault);
                            state = ParseState.None;
                            ++currentPos;
                        } else if (ch == '\n') {
                            scintilla.SetStyling(1, HspLexer.StyleDefault);
                            state = ParseState.None;
                        } else {
                            scintilla.SetStyling(1, HspLexer.StylePreprocessor);
                        }
                        break;

                    case ParseState.Identifier:
                        if (Char.IsLetterOrDigit(ch) || ch == '_') {
                            ++length;
                        } else {
                            int style = HspLexer.StyleDefault;
                            string identifier = scintilla.GetTextRange(currentPos - length, length);
                            identifier = identifier.ToLower();

                            if (this.mKeywords.ContainsKey(identifier)) {
                                switch (this.mKeywords[identifier].mType) {
                                    case KeywordType.Macro:
                                        style = HspLexer.StyleMacro;
                                        break;
                                    case KeywordType.Function:
                                        style = HspLexer.StyleFunction;
                                        break;
                                    case KeywordType.Type:
                                        style = HspLexer.StyleType;
                                        break;
                                }
                            }

                            scintilla.SetStyling(length, style);
                            length = 0;
                            state = ParseState.None;
                            goto Process;
                        }
                        break;
                }

                ++currentPos;
                currentLine = scintilla.LineFromPosition(currentPos);

                if (currentLineStartPos < scintilla.Lines[currentLine].Position) {
                    currentLineStartPos = scintilla.Lines[currentLine].Position;
                }

                currentLineEndPos = scintilla.Lines[currentLine].EndPosition;
            }
        }
示例#5
0
        public void Find(bool next, bool incremental)
        {
            bool first = LastSearch != SearchBox.Text;


            if (SearchBox.Text.Length > 0)
            {
                if (next)
                {
                    if (incremental && first)
                    {
                        TextArea.TargetStart = 0;
                    }
                    else
                    {
                        TextArea.TargetStart = TextArea.CurrentPosition;
                    }
                    LastSearch         = SearchBox.Text;
                    TextArea.TargetEnd = TextArea.TextLength;

                    // Search, and if not found..
                    if (TextArea.SearchInTarget(LastSearch) == -1)
                    {
                        PopUp.Information("Search finished!");
                        LastSearch = "";
                        return;
                    }
                }
                else
                {
                    if (LastSearchIndex != 0 && TextArea.SelectedText.Length > 0)
                    {
                        TextArea.TargetStart = LastSearchIndex;
                    }
                    else if (LastSearchIndex == 0 && TextArea.SelectedText == LastSearch && TextArea.SelectedText.Length > 0)
                    {
                        TextArea.TargetStart = 0;
                    }
                    else
                    {
                        TextArea.TargetStart = TextArea.CurrentPosition;
                    }
                    TextArea.TargetEnd = 0;
                    LastSearch         = SearchBox.Text;

                    // Search, and if not found..
                    if (TextArea.SearchInTarget(LastSearch) == -1)
                    {
                        PopUp.Information("Search finished!");
                        LastSearch = "";
                        return;
                    }
                }

                // Select the occurance
                LastSearchIndex = TextArea.TargetStart;
                TextArea.SetSelection(TextArea.TargetEnd, TextArea.TargetStart);
                int  currentLineIndex = TextArea.LineFromPosition(TextArea.CurrentPosition);
                Line currentLine      = TextArea.Lines[currentLineIndex];
                int  linesInView      = TextArea.LinesOnScreen;
                int  halfLines        = linesInView / 2;
                int  lowerLine        = currentLineIndex + halfLines > TextArea.Lines.Count ? TextArea.Lines.Count : currentLineIndex + halfLines;
                int  upperLine        = currentLineIndex - halfLines > 0 ? currentLineIndex - halfLines : 0;
                if (next)
                {
                    TextArea.ScrollRange(TextArea.Lines[lowerLine].Position, 0);
                }
                else
                {
                    TextArea.ScrollRange(TextArea.Lines[upperLine].Position, 0);
                    TextArea.ScrollRange(TextArea.Lines[lowerLine].Position, 0);
                }

                TextArea.ScrollCaret();
            }

            SearchBox.Focus();
        }
        public void StyleText(Scintilla scintilla, int startPos, int endPos)
        {
            if(scintilla.GetCharAt(0) != '=') //Not Expression
                return;

            // Back up to the line start
            var line = scintilla.LineFromPosition(startPos);
            startPos = scintilla.Lines[line].Position;

            var length = 0;
            char stringStartChar = '"';
            var state = LexerState.Unknown;
            var EOF = false;

            // Start styling
            scintilla.StartStyling(startPos);
            while (startPos < endPos)
            {
                var c = (char)scintilla.GetCharAt(startPos);
                //lastSymbol = startPos == endPos - 1;

            REPROCESS:
                switch (state)
                {
                    case LexerState.Unknown:
                        if (c == '"' || c == '\'')
                        {
                            // Start of "string"
                            stringStartChar = c;
                            scintilla.SetStyling(1, (int)Style.String);
                            state = LexerState.String;
                        }
                        else if (c == '{')
                        {
                            state = LexerState.Braces;
                            goto REPROCESS;
                        }
                        else if (Char.IsDigit(c))
                        {
                            state = LexerState.Number;
                            goto REPROCESS;
                        }
                        else if (Char.IsLetter(c))
                        {
                            state = LexerState.Identifier;
                            goto REPROCESS;
                        }
                        else if (operators.Any(x => x[0] == c))
                        {
                            state = LexerState.Operator;
                            goto REPROCESS;
                        }
                        else
                        {
                            // Everything else
                            scintilla.SetStyling(1, (int)Style.Default);
                        }
                        break;

                    case LexerState.String:
                        if (c == stringStartChar)
                        {
                            length++;
                            scintilla.SetStyling(length, (int)Style.String);
                            length = 0;
                            state = LexerState.Unknown;
                        }
                        else
                        {
                            length++;
                        }
                        break;

                    case LexerState.Braces:
                        if (c == '}')
                        {
                            length++;
                            var style = Style.Identifier;
                            var identifier = scintilla.GetTextRange(startPos - length + 2, length - 2);
                            if (identifier.Length == 0)
                            {
                                style = Style.Error;
                            }
                            else if (identifier[0] == '!')
                            {
                                if (userInfo.Contains(identifier.Substring(1)))
                                    style = Style.UserInfo;
                                else
                                    style = Style.Error;
                            }
                            else if (identifier[0] == '@')
                            {
                                if (globals.Contains(identifier.Substring(1)))
                                    style = Style.Globals;
                                else
                                    style = Style.Error;
                            }
                            else if (identifier[0] == '?' && parameters != null)
                            {
                                if (parameters.Contains(identifier.Substring(1)))
                                    style = Style.Parameter;
                                else
                                    style = Style.Error;
                            }
                            else
                            {
                                if (fields.Contains(identifier))
                                    style = Style.Field;
                                else
                                    style = Style.Error;
                            }

                            scintilla.SetStyling(length, (int)style);
                            length = 0;
                            state = LexerState.Unknown;
                        }
                        else
                            length++;
                        break;

                    case LexerState.Number:
                        if (Char.IsDigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') || c == 'x')
                        {
                            length++;
                        }
                        else
                        {
                            scintilla.SetStyling(length, (int)Style.Number);
                            length = 0;
                            state = LexerState.Unknown;
                            goto REPROCESS;
                        }
                        break;

                    case LexerState.Identifier:
                        if (!EOF && (Char.IsLetterOrDigit(c) || c == '.' || c == '!' || c == '_'))
                        {
                            length++;
                        }
                        else
                        {
                            var style = Style.Identifier;
                            var identifier = scintilla.GetTextRange(startPos - length, length);

                            var endFirstWord = identifier.IndexOf('.');
                            if (endFirstWord != -1)
                            {
                                var firstWord = identifier.Substring(0, endFirstWord);
                                var secondWord = identifier.Substring(endFirstWord + 1);
                                if (calssMethods.ContainsKey(firstWord) && calssMethods[firstWord].Contains(secondWord))
                                {
                                    style = Style.Method;
                                }
                                else
                                    style = Style.Error;
                            }

                            endFirstWord = identifier.IndexOf('!');
                            if (endFirstWord != -1)
                            {
                                var firstWord = identifier.Substring(0, endFirstWord);
                                var secondWord = identifier.Substring(endFirstWord +1);
                                if (firstWord == "User")
                                {
                                    if (userInfo.Contains(secondWord))
                                        style = Style.UserInfo;
                                    else
                                        style = Style.Error;
                                }
                                if (firstWord == "Globals")
                                {
                                    if (globals.Contains(secondWord))
                                        style = Style.Globals;
                                    else
                                        style = Style.Error;
                                }
                                if (firstWord == "Parameters")
                                {
                                    if (globals.Contains(secondWord))
                                        style = Style.Parameter;
                                    else
                                        style = Style.Error;
                                }
                                if (firstWord == "Fields")
                                {
                                    var field = secondWord.Split('.');
                                    if (field.Length == 2 && fields.Contains(field[0])
                                        && (field[1] == "Value" || field[1] == "IsMissing"))
                                        style = Style.Field;
                                    else
                                        style = Style.Error;
                                }

                            }

                            if (simpleMethods.Contains(identifier))
                                style = Style.Method;

                            if (aggrMethods.Contains(identifier))
                                style = Style.AggrMethod;

                            scintilla.SetStyling(length, (int)style);
                            length = 0;
                            state = LexerState.Unknown;
                            if(!EOF)
                                goto REPROCESS;
                        }
                        break;
                    case LexerState.Operator:
                        var cur = scintilla.GetTextRange(startPos - length, length +1);
                        if (operators.Any(x => x.StartsWith(cur)))
                        {
                            length++;
                        }
                        else
                        {
                            cur = scintilla.GetTextRange(startPos - length, length);
                            Style style;
                            if (operators.Contains(cur))
                            {
                                //length++;
                                style = Style.Operator;
                            }
                            else
                            {
                                style = Style.Error;
                            }
                            scintilla.SetStyling(length, (int)style);
                            length = 0;
                            state = LexerState.Unknown;
                            goto REPROCESS;
                        }
                        break;
                }

                startPos++;
                if (!EOF && startPos == endPos && state == LexerState.Identifier)
                {
                    EOF = true;
                    goto REPROCESS;
                }

            }
        }