Exemple #1
0
        private void FastColoredTextBox_AutoIndentNeeded(object sender, FastColoredTextBoxNS.AutoIndentEventArgs e)
        {
            var l = e.LineText.Trim();

            if (l.EndsWith("(") || l.EndsWith("{"))
            {
                e.ShiftNextLines = e.TabLength;
            }
            if (l.StartsWith(")") || l.StartsWith("}"))
            {
                e.Shift          = -e.TabLength;
                e.ShiftNextLines = -e.TabLength;
            }
        }
Exemple #2
0
 private void CSharpAutoIndentNeeded(object sender, AutoIndentEventArgs args)
 {
     //block {}
     if (Regex.IsMatch(args.LineText, @"^[^""']*\{.*\}[^""']*$"))
     {
         return;
     }
     //start of block {}
     if (Regex.IsMatch(args.LineText, @"^[^""']*\{"))
     {
         args.ShiftNextLines = args.TabLength;
         return;
     }
     //end of block {}
     if (Regex.IsMatch(args.LineText, @"}[^""']*$"))
     {
         args.Shift          = -args.TabLength;
         args.ShiftNextLines = -args.TabLength;
         return;
     }
     //label
     if (Regex.IsMatch(args.LineText, @"^\s*\w+\s*:\s*($|//)") &&
         !Regex.IsMatch(args.LineText, @"^\s*default\s*:"))
     {
         args.Shift = -args.TabLength;
         return;
     }
     //some statements: case, default
     if (Regex.IsMatch(args.LineText, @"^\s*(case|default)\b.*:\s*($|//)"))
     {
         args.Shift = -args.TabLength / 2;
         return;
     }
     //is unclosed operator in previous line ?
     if (Regex.IsMatch(args.PrevLineText, @"^\s*(if|for|foreach|while|[\}\s]*else)\b[^{]*$"))
     {
         if (!Regex.IsMatch(args.PrevLineText, @"(;\s*$)|(;\s*//)"))//operator is unclosed
         {
             args.Shift = args.TabLength;
             return;
         }
     }
 }
        private void VBAutoIndentNeeded(object sender, AutoIndentEventArgs args)
        {
            //end of block
            if (Regex.IsMatch(args.LineText, @"^\s*(End|EndIf|Next|Loop)\b", RegexOptions.IgnoreCase))
            {
                args.Shift          = -args.TabLength;
                args.ShiftNextLines = -args.TabLength;
                return;
            }
            //start of declaration
            if (Regex.IsMatch(args.LineText,
                              @"\b(Class|Property|Enum|Structure|Sub|Function|Namespace|Interface|Get)\b|(Set\s*\()",
                              RegexOptions.IgnoreCase))
            {
                args.ShiftNextLines = args.TabLength;
                return;
            }
            // then ...
            if (Regex.IsMatch(args.LineText, @"\b(Then)\s*\S+", RegexOptions.IgnoreCase))
            {
                return;
            }
            //start of operator block
            if (Regex.IsMatch(args.LineText, @"^\s*(If|While|For|Do|Try|With|Using|Select)\b", RegexOptions.IgnoreCase))
            {
                args.ShiftNextLines = args.TabLength;
                return;
            }

            //Statements else, elseif, case etc
            if (Regex.IsMatch(args.LineText, @"^\s*(Else|ElseIf|Case|Catch|Finally)\b", RegexOptions.IgnoreCase))
            {
                args.Shift = -args.TabLength;
                return;
            }

            //Char _
            if (args.PrevLineText.TrimEnd().EndsWith("_"))
            {
                args.Shift = args.TabLength;
            }
        }
        public virtual void AutoIndentNeeded(object sender, AutoIndentEventArgs args)
        {
            FastColoredTextBox tb       = (sender as FastColoredTextBox);
            Language           language = tb.Language;

            switch (language)
            {
            case Language.CSharp: CSharpAutoIndentNeeded(sender, args); break;

            case Language.VB: VBAutoIndentNeeded(sender, args); break;

            case Language.HTML: HTMLAutoIndentNeeded(sender, args); break;

            case Language.SQL: SQLAutoIndentNeeded(sender, args); break;

            case Language.PHP: PHPAutoIndentNeeded(sender, args); break;

            default:
                break;
            }
        }
 private void RubyAutoIndentNeeded(object sender, AutoIndentEventArgs args)
 {
     if (Regex.IsMatch(args.LineText, @"^\s*(end)\b"))
     {
         args.Shift          = -args.TabLength;
         args.ShiftNextLines = -args.TabLength;
         return;
     }
     if (Regex.IsMatch(args.LineText, @"\b(then)\s*\S+"))
     {
         return;
     }
     if (Regex.IsMatch(args.LineText, @"^\s*(else|elsif)\b", RegexOptions.IgnoreCase))
     {
         args.Shift = -args.TabLength;
         return;
     }
     if (Regex.IsMatch(args.LineText, @"\b(def|if|for|class|case|when)\b"))
     {
         args.ShiftNextLines = args.TabLength;
     }
 }
Exemple #6
0
        private void HTMLAutoIndentNeeded(object sender, AutoIndentEventArgs args)
        {
            FastColoredTextBox tb = sender as FastColoredTextBox;

            tb.CalcAutoIndentShiftByCodeFolding(sender, args);
        }
Exemple #7
0
 public virtual void AutoIndentNeeded(object sender, AutoIndentEventArgs args)
 {
     RazorAutoIndentNeeded(sender, args);
 }
        // ReSharper disable once UnusedParameter.Local
        private void CobolAutoIndentNeeded(object sender, AutoIndentEventArgs args)
        {
            // input: args.LineText;
            // output: args.Shift; (current line), args.ShiftNextLines; (next line)

            const int basicIndent = 4;
            const int ifIndent    = 8;

            var currentLine = args.LineText;

            // endings
            if (args.PrevLineText.IndexOf('.') > 0)
            {
                _inLastElseBlock = false;
                // rulerForWrappedLines = 0;
                args.AbsoluteIndentation = basicIndent;
            }

            // validate text
            if (currentLine.Length < 8)
            {
                return;
            }

            // ignore comments
            if (currentLine[6] == '*')
            {
                return;
            }

            // trim line numbers and author comments
            currentLine = ExtractCode(currentLine);
            var previousLine = ExtractCode(args.PrevLineText);

            // VARIABLE DEFINITIONS
            if (currentLine.Length > 2 && char.IsDigit(currentLine[0]) && char.IsDigit(currentLine[1]))
            {
                var number = int.Parse(currentLine.Substring(0, 2));

                if (number == 1 || number == 77)
                {
                    args.AbsoluteIndentation = 0;
                }
                else if (number == 88)
                {
                    args.AbsoluteIndentation = CalculateSpaces(args.PrevLineText, 7) + (previousLine.StartsWith("88") ? 0 : 4);
                }
                else
                {
                    args.AbsoluteIndentation = number * 2 - 2;
                }

                return;
            }

            // LABELS
            if (_cobolProceduresRegex.IsMatch(args.LineText))
            {
                args.AbsoluteIndentation = 0;
                return;
            }

            // IF / ELSE IF / ELSE
            if (currentLine.StartsWith("IF"))
            {
                _inLastElseBlock = false;

                // ELSE \n IF
                if (previousLine.StartsWith("ELSE"))
                {
                    args.AbsoluteIndentation = args.PrevLineText.IndexOf('E') - 7;
                }

                args.ShiftNextLines = ifIndent;
                return;
            }

            if (currentLine.StartsWith("ELSE"))
            {
                args.Shift          = args.AbsoluteIndentation <= 12 ? -ifIndent : _inLastElseBlock ? -2 * ifIndent : -ifIndent;
                args.ShiftNextLines = ifIndent;
                _inLastElseBlock    = true;
                return;
            }

            // NON-KEYWORDS / WRAPPED LINES
            var keyword = (currentLine + " ").Substring(0, (currentLine + " ").IndexOf(' ')).Trim(new char['.']);

            if (!CobolKeywords.Keywords.Contains(keyword))
            {
                args.WrappedLine = true;

                // try to set new ruler
                if (TryFindRuler(args, "= "))
                {
                    return;
                }
                if (TryFindRuler(args, "USING "))
                {
                    return;
                }
                if (TryFindRuler(args, "TO "))
                {
                    return;
                }
                if (TryFindRuler(args, "VALUE "))
                {
                    return;
                }
                if (TryFindRuler(args, "\""))
                {
                    return;
                }

                // otherwise use last ruler, IF it was less then 5 lines ago. Also update that.
                if (_rulerForWrappedLines > 0 && Math.Abs(_rulerForWrappedLinesLine - args.iLine) < 5)
                {
                    _rulerForWrappedLinesLine = args.iLine;
                    args.Shift = _rulerForWrappedLines;
                    return;
                }

                // otherwise shift by four
                args.Shift = 4;
            }
        }
        public virtual void AutoIndentNeeded(object sender, AutoIndentEventArgs args)
        {
            var tb = (sender as FastColoredTextBox);

            tb.Language.AutoIndentNeeded(args);
        }
        protected void SQLAutoIndentNeeded(object sender, AutoIndentEventArgs args)
        {
            var tb = sender as FastColoredTextBox;

            tb.CalcAutoIndentShiftByCodeFolding(sender, args);
        }
        public virtual void AutoIndentNeeded(object sender, AutoIndentEventArgs args)
        {
            var tb = (sender as FastColoredTextBox);

            SQLAutoIndentNeeded(sender, args);
        }