Ejemplo n.º 1
0
 void fctb_AutoIndentNeeded(object sender, AutoIndentEventArgs e)
 {
     // if current line is "begin" then next
     // line shift to right
     if (e.LineText.Trim() == "begin")
     {
         e.ShiftNextLines = e.TabLength;
         return;
     }
     // if current line is "end" then current
     // and next line shift to left
     if (e.LineText.Trim() == "end")
     {
         e.Shift = -e.TabLength;
         e.ShiftNextLines = -e.TabLength;
         return;
     }
     // if previous line contains "then" or "else",
     // and current line do not contain "begin"
     // then shift current line to right
     if (Regex.IsMatch(e.PrevLineText, @"\b(then|else)\b") &&
         !Regex.IsMatch(e.LineText, @"\bbegin\b"))
     {
         e.Shift = e.TabLength;
         return;
     }
 }
Ejemplo n.º 2
0
        private void FastColoredTextBox1OnAutoIndentNeeded(object sender, AutoIndentEventArgs args)
        {
            // start of a tag
            // the tag start line look as follows:
            // TAGNAME VALUES* (ATTR-NAME=ATTR-VALUE)* {
            // We want to shift the next line when the current line (afte trimming) ends with a { and doesn't start with a comment
            // TODO: a line within a multi line comment will be a false positive, so be it...
            string trimmedLine = args.LineText.Trim();
            if (!(trimmedLine.StartsWith("//") || trimmedLine.StartsWith("#") || trimmedLine.StartsWith("--"))
                && trimmedLine.EndsWith("{"))
            {
                // increase indent
                args.ShiftNextLines = args.TabLength;
                return;
            }

            if (!(trimmedLine.StartsWith("//") || trimmedLine.StartsWith("#") || trimmedLine.StartsWith("--"))
                && trimmedLine.EndsWith("}"))
            {
                // decrease indent
                args.Shift = -args.TabLength;
                args.ShiftNextLines = -args.TabLength;
                return;
            }
        }
Ejemplo n.º 3
0
 private void fctb_AutoIndentNeeded(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;
         }
 }
 protected void HTMLAutoIndentNeeded(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);
     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;
         case Language.JS:
             CSharpAutoIndentNeeded(sender, args);
             break; //JS like C#
         case Language.Lua:
             LuaAutoIndentNeeded(sender, args);
             break;
         default:
             break;
     }
 }
        protected 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;
                return;
            }
        }
 protected void PHPAutoIndentNeeded(object sender, AutoIndentEventArgs args)
 {
     /*
     FastColoredTextBox tb = sender as FastColoredTextBox;
     tb.CalcAutoIndentShiftByCodeFolding(sender, 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;
     }
     //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;
         }
 }
        protected void LuaAutoIndentNeeded(object sender, AutoIndentEventArgs args)
        {
            //end of block
            if (Regex.IsMatch(args.LineText, @"^\s*(end|until)\b"))
            {
                args.Shift = -args.TabLength;
                args.ShiftNextLines = -args.TabLength;
                return;
            }
            // then ...
            if (Regex.IsMatch(args.LineText, @"\b(then)\s*\S+"))
                return;
            //start of operator block
            if (Regex.IsMatch(args.LineText, @"^\s*(function|do|for|while|repeat|if)\b"))
            {
                args.ShiftNextLines = args.TabLength;
                return;
            }

            //Statements else, elseif, case etc
            if (Regex.IsMatch(args.LineText, @"^\s*(else|elseif)\b", RegexOptions.IgnoreCase))
            {
                args.Shift = -args.TabLength;
                return;
            }
        }
 private void fctb_AutoIndentNeeded(object sender, AutoIndentEventArgs e)
 {
     //we assign this handler for disable AutoIndent by folding
 }