コード例 #1
0
ファイル: PluginMain.cs プロジェクト: heon21st/flashdevelop
        public PositionInfos(ScintillaControl sci, Int32 position, String argString)
        {
            // Variables
            String[] vars = argString.Split('¤');
            this.ArgCurWord = vars[0];
            this.ArgPackageName = vars[1];
            this.ArgClassName = vars[2];
            this.ArgClassType = vars[3];
            this.ArgMemberName = vars[4];
            this.ArgMemberType = vars[5];

            // Selection
            Int32 ss = sci.SelectionStart;
            Int32 se = sci.SelectionEnd;
            if (se != ss)
            {
                this.SelectionStart = ss;
                this.SelectionEnd = se;
                this.HasSelection = true;
                if (sci.LineFromPosition(ss) != sci.LineFromPosition(se))
                    this.SelectionIsMultiline = true;
                else SelectedText = sci.SelText;
            }

            // Current
            this.CurrentPosition = position;
            this.CurrentCharCode = sci.CharAt(position);
            this.CurrentIsWhiteChar = (HelpTools.IsWhiteChar(this.CurrentCharCode));
            this.CurrentIsDotChar = (this.CurrentCharCode == 46);
            this.CurrentIsActionScriptChar = HelpTools.IsActionScriptChar(this.CurrentCharCode);
            this.CurrentIsWordChar = HelpTools.IsWordChar((byte)this.CurrentCharCode);
            Int32 s = sci.StyleAt(position);
            this.CurrentIsInsideComment = (s == 1 || s == 2 || s == 3 || s == 17);

            // Next
            Int32 np = sci.PositionAfter(position);
            if (np != position)
                this.NextPosition = np;
            else
                this.CaretIsAtEndOfDocument = true;

            // Word
            this.CodePage = sci.CodePage; // (UTF-8|Big Endian|Little Endian : 65001) (8 Bits|UTF-7 : 0)
            
            if (this.CurrentIsInsideComment == false && this.SelectionIsMultiline == false)
            {
                Int32 wsp = sci.WordStartPosition(position, true);
                // Attention (WordEndPosition n'est pas estimé comme par defaut)
                Int32 wep = sci.PositionBefore(sci.WordEndPosition(position, true));

                if (this.CodePage != 65001)
                {
                    wsp = HelpTools.GetWordStartPositionByWordChar(sci, position);
                    // Attention (WordEndPosition n'est pas estimé comme par defaut)
                    wep = sci.PositionBefore(HelpTools.GetWordEndPositionByWordChar(sci, position));
                }

                this.WordStartPosition = wsp;
                this.WordEndPosition = wep;

                if (this.CodePage == 65001)
                    this.WordFromPosition = this.ArgCurWord;
                else
                    this.WordFromPosition = HelpTools.GetText(sci, wsp, sci.PositionAfter(wep));

                if (position > wep)
                    this.CaretIsAfterLastLetter = true;
            }
            
            // Previous
            if (this.CurrentPosition > 0)
            {
                this.PreviousPosition = sci.PositionBefore(position);
                this.PreviousCharCode = sci.CharAt(this.PreviousPosition);
                this.PreviousIsWhiteChar = HelpTools.IsWhiteChar(this.PreviousCharCode);
                this.PreviousIsDotChar = (this.PreviousCharCode == 46);
                this.PreviousIsActionScriptChar = HelpTools.IsActionScriptChar(this.PreviousCharCode);
            }

            // Line
            this.CurrentLineIdx = sci.LineFromPosition(position);
            if (this.CurrentPosition > 0)
                this.PreviousLineIdx = sci.LineFromPosition(this.PreviousPosition);

            this.LineIdxMax = sci.LineCount - 1;
            this.LineStartPosition = HelpTools.LineStartPosition(sci, this.CurrentLineIdx);
            this.LineEndPosition = sci.LineEndPosition(this.CurrentLineIdx);
            this.NewLineMarker = LineEndDetector.GetNewLineMarker(sci.EOLMode);

            // Previous / Next
            if (this.WordStartPosition != -1)
            {
                this.PreviousNonWhiteCharPosition = HelpTools.PreviousNonWhiteCharPosition(sci, this.WordStartPosition);
                this.PreviousWordIsFunction = (sci.GetWordFromPosition(this.PreviousNonWhiteCharPosition) == "function");
                this.NextNonWhiteCharPosition = HelpTools.NextNonWhiteCharPosition(sci, this.WordEndPosition);
            }

            // Function
            if (this.PreviousWordIsFunction)
            {
                Int32 nobp = HelpTools.NextCharPosition(sci, position, "(");
                Int32 ncbp = HelpTools.NextCharPosition(sci, position, ")");
                Int32 nlbp = HelpTools.NextCharPosition(sci, position, "{");
                if ((nobp < ncbp) && (ncbp < nlbp))
                {
                    this.NextOpenBracketPosition = nobp;
                    this.NextCloseBracketPosition = ncbp;
                    this.NextLeftBracePosition = nlbp;
                }

                // Arguments
                String args = HelpTools.GetText(sci, sci.PositionAfter(this.NextOpenBracketPosition), this.NextCloseBracketPosition).Trim();
                if (args.Length > 0)
                {
                    this.HasArguments = true;
                    this.Arguments = HelpTools.ExtractArguments(sci, args);
                }
            }
        }
コード例 #2
0
ファイル: ASGenerator.cs プロジェクト: JoeRobich/flashdevelop
        public static void GenerateExtractVariable(ScintillaControl Sci, string NewName)
        {
            FileModel cFile;

            string expression = Sci.SelText.Trim(new char[] { '=', ' ', '\t', '\n', '\r', ';', '.' });
            expression = expression.TrimEnd(new char[] { '(', '[', '{', '<' });
            expression = expression.TrimStart(new char[] { ')', ']', '}', '>' });

            cFile = ASContext.Context.CurrentModel;
            ASFileParser parser = new ASFileParser();
            parser.ParseSrc(cFile, Sci.Text);

            MemberModel current = cFile.Context.CurrentMember;

            string characterClass = ScintillaControl.Configuration.GetLanguage(Sci.ConfigurationLanguage).characterclass.Characters;

            int funcBodyStart = GetBodyStart(current.LineFrom, current.LineTo, Sci);
            Sci.SetSel(funcBodyStart, Sci.LineEndPosition(current.LineTo));
            string currentMethodBody = Sci.SelText;

            bool isExprInSingleQuotes = (expression.StartsWith('\'') && expression.EndsWith('\''));
            bool isExprInDoubleQuotes = (expression.StartsWith('\"') && expression.EndsWith('\"'));
            int stylemask = (1 << Sci.StyleBits) - 1;
            int lastPos = -1;
            char prevOrNextChar;
            Sci.Colourise(0, -1);
            while (true)
            {
                lastPos = currentMethodBody.IndexOfOrdinal(expression, lastPos + 1);
                if (lastPos > -1)
                {
                    if (lastPos > 0)
                    {
                        prevOrNextChar = currentMethodBody[lastPos - 1];
                        if (characterClass.IndexOf(prevOrNextChar) > -1)
                        {
                            continue;
                        }
                    }
                    if (lastPos + expression.Length < currentMethodBody.Length)
                    {
                        prevOrNextChar = currentMethodBody[lastPos + expression.Length];
                        if (characterClass.IndexOf(prevOrNextChar) > -1)
                        {
                            continue;
                        }
                    }

                    int style = Sci.StyleAt(funcBodyStart + lastPos) & stylemask;
                    if (ASComplete.IsCommentStyle(style))
                    {
                        continue;
                    }
                    else if ((isExprInDoubleQuotes && currentMethodBody[lastPos] == '"' && currentMethodBody[lastPos + expression.Length - 1] == '"')
                        || (isExprInSingleQuotes && currentMethodBody[lastPos] == '\'' && currentMethodBody[lastPos + expression.Length - 1] == '\''))
                    {

                    }
                    else if (!ASComplete.IsTextStyle(style))
                    {
                        continue;
                    }

                    Sci.SetSel(funcBodyStart + lastPos, funcBodyStart + lastPos + expression.Length);
                    Sci.ReplaceSel(NewName);
                    currentMethodBody = currentMethodBody.Substring(0, lastPos) + NewName + currentMethodBody.Substring(lastPos + expression.Length);
                    lastPos += NewName.Length;
                }
                else
                {
                    break;
                }
            }

            Sci.CurrentPos = funcBodyStart;
            Sci.SetSel(Sci.CurrentPos, Sci.CurrentPos);

            MemberModel m = new MemberModel(NewName, "", FlagType.LocalVar, 0);
            m.Value = expression;

            string snippet = TemplateUtils.GetTemplate("Variable");
            snippet = TemplateUtils.ReplaceTemplateVariable(snippet, "Modifiers", null);
            snippet = TemplateUtils.ToDeclarationString(m, snippet);
            snippet += NewLine + "$(Boundary)";
            SnippetHelper.InsertSnippetText(Sci, Sci.CurrentPos, snippet);
        }
コード例 #3
0
        private LocalContext GetContext(ScintillaControl sci, int position)
        {
            var ctx = new LocalContext(sci);
            int i = position - 1;
            int style = sci.StyleAt(i-1);

            if (style == (int)CSS.COMMENT) // inside comments
            {
                ctx.InComments = true;
                return ctx;
            }

            int inString = 0;
            if (style == 14) inString = 1;
            if (style == 13) inString = 2;

            bool inWord = true;
            bool inComment = false;
            bool inPar = false;
            string word = "";
            int lastCharPos = i;

            while (i > 1)
            {
                char c = (char)sci.CharAt(i--);

                if (wordChars.IndexOf(c) >= 0)
                {
                    lastCharPos = i + 1;
                    if (inWord) word = c + word;
                }
                else inWord = false;

                if (inString > 0)
                {
                    if (inString == 1 && c == '\'') inString = 0;
                    else if (inString == 2 && c == '"') inString = 0;
                    continue;
                }
                if (inComment)
                {
                    if (c == '*' && i > 0 && (char)sci.CharAt(i) == '/') inComment = false;
                    continue;
                }
                if (c == '/' && i > 0 && (char)sci.CharAt(i) == '*') // entering comment
                    inComment = true;
                if (c == '\'') inString = 1; // entering line
                else if (c == '"') inString = 2;

                else if (c == ')') inPar = true;
                else if (inPar)
                {
                    if (c == '(') inPar = false;
                    continue;
                }

                else if (c == ':')
                {
                    ctx.Separator = c;
                    ctx.Position = lastCharPos;
                    string attr = ReadAttribute(sci, i);
                    if (attr.Length > 1)
                    {
                        if (attr[0] == features.Trigger || IsVarDecl(sci, i))
                            ctx.IsVar = true;
                        else if (!IsTag(attr))
                        {
                            ctx.InValue = true;
                            ctx.Property = attr;
                        }
                    }
                    break;
                }
                else if (c == ';' || c == '{')
                {
                    ctx.Separator = c;
                    ctx.Position = lastCharPos;
                    ctx.InBlock = !IsVarDecl(sci, i);
                    break;
                }
                else if (c == '}' || c == ',' || c == '.' || c == '#')
                {
                    ctx.Separator = c;
                    ctx.Position = lastCharPos;
                    break;
                }
                else if (c == '(')
                {
                    string tok = ReadWordLeft(sci, i);
                    if (tok == "url")
                    {
                        ctx.Separator = '(';
                        ctx.InUrl = true;
                        ctx.Position = i + 1;
                        word = "";
                        for (int j = i + 2; j < position; j++)
                            word += (char)sci.CharAt(j);
                        break;
                    }
                }
            }
            if (word.Length > 0)
            {
                if (word[0] == '-')
                {
                    Match m = reNavPrefix.Match(word);
                    if (m.Success) word = m.Groups[1].Value;
                }
            }
            ctx.Word = word;
            return ctx;
        }
コード例 #4
0
ファイル: AutoClose.cs プロジェクト: fordream/wanghe-project
        unsafe void SciControl_CharAdded(ScintillaControl sender, int ch)
        {
            if (ch == bracketOpen)
               {
               insert = arrBracketClose;

               }
               else if (ch == quote)
               {

               insert = arrQuote;
               }
               else if (ch == squareBracketOpen)
               {

               insert = arrSquareBracketClose;

               }
               else if (ch == bracketClose)
               {
               if (sender.CharAt(sender.CurrentPos) == bracketClose)
               {
                   // temporary disable
                   sender.ModEventMask ^= (Int32)ScintillaNet.Enums.ModificationFlags.BeforeDelete;
                   sender.CharRight();
                   sender.DeleteBack();
                   sender.ModEventMask ^= (Int32)ScintillaNet.Enums.ModificationFlags.BeforeDelete;
                   return;
               }
               return;
               }
               else if (ch == squareBracketClose)
               {
               if (sender.CharAt(sender.CurrentPos) == squareBracketClose)
               {
                   // temporary disable
                   sender.ModEventMask ^= (Int32)ScintillaNet.Enums.ModificationFlags.BeforeDelete;
                   sender.CharRight();
                   sender.DeleteBack();
                   sender.ModEventMask ^= (Int32)ScintillaNet.Enums.ModificationFlags.BeforeDelete;
                   return;
               }
               return;
               }
               else
               {
               return;
               }

               int pos = sender.CurrentPos;
               uint actPos = (uint)pos;

               char character;
               do
               {
               character =(char) sender.CharAt(pos);
               if (character == '\n') break;
               if (!Char.IsWhiteSpace(character)) break;
               pos++;

               } while (true);

             //  if (Char.IsLetterOrDigit(character) || character == ch || character == insert[0]) return;
               if (Char.IsLetterOrDigit(character) || character == ch ) return;

               int stylemask = (1 << sender.StyleBits) - 1;

               bool isTextStyle = ASComplete.IsTextStyle(sender.StyleAt(sender.CurrentPos) & stylemask);
               int style = sender.StyleAt(sender.CurrentPos - 1) & stylemask;

               if (ch == quote)
               {
               if (!isTextStyle)
               {

                   fixed (byte* b = System.Text.Encoding.GetEncoding(sender.CodePage).GetBytes(insert))
                   {
                       sender.SPerform(2003, actPos, (uint)b);
                   }

               }

               return;
               }

               if (!ASComplete.IsTextStyle(style) && !isTextStyle)
               {

               return;
               }

               fixed (byte* b = System.Text.Encoding.GetEncoding(sender.CodePage).GetBytes(insert))
               {
               sender.SPerform(2003, actPos, (uint)b);
               }
        }
コード例 #5
0
ファイル: AutoClose.cs プロジェクト: fordream/wanghe-project
        private static bool IsFunctionParameter(ScintillaControl sender, int position)
        {
            char c;
            int openBrace = 0;
            int commasCount = 0;

            ASResult result = null;
            do
            {
                c = (char)sender.CharAt(position);

                if (c == ';' || c == '{' || c == '}') break;
                if (c == '(')
                {
                    openBrace--;
                    if (openBrace == -1)
                    {
                        result = ASComplete.GetExpressionType(sender, position);
                        break;
                    }
                }
                else if (c == ')')
                {
                    openBrace++;
                }
                else if (c == ',')
                {

                    int stylemask = (1 << sender.StyleBits) - 1;

                    bool isTextStyle = ASComplete.IsTextStyle(sender.StyleAt(position) & stylemask);
                    //int style = sender.StyleAt(position - 1) & stylemask;
                    if (isTextStyle)
                        if (openBrace == 0) commasCount++;
                }

                position--;
            }
            while (true);
            //while (c != ';' && c != '{' && c != '}');

            if (result == null) return false;
            if (result.Member == null) return false;

            MemberModel md = result.Member;

            if (md.Parameters.Count <= commasCount) return false;
            if (md.Parameters==null || md.Parameters.Count == 0) return false;

            if (md.Parameters[commasCount].Type=="Function")
            {
                return true;
            }

            return false;
        }
コード例 #6
0
ファイル: RTF.cs プロジェクト: nagyist/flashdevelop
 /// <summary>
 /// Converts a string to RTF based on scintilla configuration
 /// </summary>
 public static String GetConversion(Language lang, ScintillaControl sci, int start, int end) 
 {
     UseStyle[] useStyles = lang.usestyles;
     Dictionary<uint, ColorData> StyleColors = new Dictionary<uint, ColorData>(MAX_COLORDEF);
     Dictionary<string, FontData> StyleFonts = new Dictionary<string, FontData>(MAX_FONTDEF);
     String text = sci.Text.Clone().ToString();
     StringBuilder rtfHeader = new StringBuilder(RTF_HEADEROPEN);
     StringBuilder rtfFont = new StringBuilder(RTF_FONTDEFOPEN);
     StringBuilder rtfColor = new StringBuilder(RTF_COLORDEFOPEN);
     StringBuilder rtf = new StringBuilder();
     char[] chars = text.ToCharArray();
     int lengthDoc = text.Length;
     int lastStyleByte = -1;
     string lastFontName = "";
     int lastFontSize = -1;
     bool lastBold = false;
     bool lastItalic = false;
     uint lastBack = 0;
     uint lastFore = 0;
     if (end < 0 || end > lengthDoc) 
     {
         end = lengthDoc;
     }
     int totalColors = 1;
     int totalFonts = 0;
     //----------------------------------------------------
     //  Grab all styles used based on the Style Byte. 
     //  Then store the basic properties in a Dictionary.
     //----------------------------------------------------
     for (int istyle = start; istyle < end; istyle++) 
     {
         // Store Byte
         int styleByte = sci.StyleAt(istyle);
         // Check Difference
         if (styleByte != lastStyleByte) 
         {
             // Store Style
             UseStyle sty = useStyles[styleByte];
             // Grab Properties
             string fontName = sty.FontName;
             int fontSize = sty.FontSize * 2;
             bool bold = sty.IsBold;
             bool italic = sty.IsItalics;
             uint back = (uint)sty.BackgroundColor;
             uint fore = (uint)(sty.fore != null && sty.fore.Length > 0 ? int.Parse(sty.fore.Substring(2, sty.fore.Length - 2), System.Globalization.NumberStyles.HexNumber) : 0);
             if (lastFontName != fontName || lastFontSize != fontSize || lastBold != bold || lastItalic != italic || lastBack != back || lastFore != fore) 
             {
                 // Check Colors
                 ColorData backColorTest;
                 ColorData foreColorTest;
                 if (!StyleColors.TryGetValue(back, out backColorTest)) 
                 {
                     Color newColor = Color.FromArgb((int)back);
                     backColorTest = new ColorData(totalColors++, newColor);
                     StyleColors.Add(back, backColorTest);
                     rtfColor.AppendFormat(RTF_SET_COLOR, newColor.R, newColor.G, newColor.B);
                     Console.WriteLine(Color.FromArgb((int)back));
                 }
                 if (!StyleColors.TryGetValue(fore, out foreColorTest)) 
                 {
                     Color newColor = Color.FromArgb((int)fore);
                     foreColorTest = new ColorData(totalColors++, newColor);
                     StyleColors.Add(fore, foreColorTest);
                     rtfColor.AppendFormat(RTF_SET_COLOR, newColor.R, newColor.G, newColor.B);
                     Console.WriteLine(Color.FromArgb((int)fore));
                 }
                 // Check Fonts
                 FontData fontTest;
                 if (!StyleFonts.TryGetValue(fontName, out fontTest)) 
                 {
                     fontTest = new FontData(totalFonts, fontName);
                     StyleFonts.Add(fontName, fontTest);
                     rtfFont.Append(@"{" + RTF_SETFONTFACE + totalFonts + " " + fontName + ";}");
                     totalFonts++;
                     Console.WriteLine(fontName);
                 }
                 rtf.Append((lastStyleByte == -1 ? "{\\pard\\plain" : "}{\\pard\\plain"));
                 // Write out RTF
                 rtf.AppendFormat(RTF_SET_FORMAT, fontTest.FontIndex, fontSize, backColorTest.ColorIndex, foreColorTest.ColorIndex, (bold ? "" : "0"), (italic ? "" : "0"));
             }
             lastFontName = fontName;
             lastFontSize = fontSize;
             lastBold = bold;
             lastItalic = italic;
             lastBack = back;
             lastFore = fore;
         }
         lastStyleByte = styleByte;
         char ch = chars[istyle];
         String curr = "";
         if (ch == '{') curr = "\\{";
         else if (ch == '}') curr = "\\}";
         else if (ch == '\\') curr = "\\\\";
         else if (ch == '\t') 
         {
             if (sci.IsUseTabs) curr = RTF_TAB;
             else curr = "".PadRight(sci.Indent, ' ');
         } 
         else if (ch == '\n') 
         {
             if (istyle == 0 || chars[istyle - 1] != '\r') curr = "\\line\n";
         } 
         else if (ch == '\r') curr = "\\line\n";
         else if (!(Char.IsLetterOrDigit(ch) || Char.IsWhiteSpace(ch))) curr = "\\'" + ((int)ch).ToString("x2");
         else curr = ch.ToString();
         rtf.Append(@curr);
     }
     // Close Headers
     rtfColor.Append('}');
     rtfFont.Append('}');
     rtf.Append('}');
     rtfHeader.AppendFormat("\n{0}\n{1}\n{2}\n{3}", rtfFont.ToString(), rtfColor.ToString(), rtf.ToString(), "}");
     return rtfHeader.ToString();
 }
コード例 #7
0
        public void Execute()
        {
            Sci = PluginBase.MainForm.CurrentDocument.SciControl;
            Sci.BeginUndoAction();
            try
            {
                IASContext context = ASContext.Context;
                Int32 pos = Sci.CurrentPos;

                string expression = Sci.SelText.Trim(new char[] { '=', ' ', '\t', '\n', '\r', ';', '.' });
                expression = expression.TrimEnd(new char[] { '(', '[', '{', '<' });
                expression = expression.TrimStart(new char[] { ')', ']', '}', '>' });

                cFile = ASContext.Context.CurrentModel;
                ASFileParser parser = new ASFileParser();
                parser.ParseSrc(cFile, Sci.Text);

                MemberModel current = cFile.Context.CurrentMember;
               
                string characterClass = ScintillaControl.Configuration.GetLanguage(Sci.ConfigurationLanguage).characterclass.Characters;

                int funcBodyStart = ASGenerator.GetBodyStart(current.LineFrom, current.LineTo, Sci);
                Sci.SetSel(funcBodyStart, Sci.LineEndPosition(current.LineTo));
                string currentMethodBody = Sci.SelText;

                bool isExprInSingleQuotes = (expression.StartsWith("'") && expression.EndsWith("'"));
                bool isExprInDoubleQuotes = (expression.StartsWith("\"") && expression.EndsWith("\""));
                int stylemask = (1 << Sci.StyleBits) - 1;
                int lastPos = -1;
                char prevOrNextChar;
                Sci.Colourise(0, -1);
                while (true)
                {
                    lastPos = currentMethodBody.IndexOf(expression, lastPos + 1);
                    if (lastPos > -1)
                    {
                        if (lastPos > 0)
                        {
                            prevOrNextChar = currentMethodBody[lastPos - 1];
                            if (characterClass.IndexOf(prevOrNextChar) > -1)
                            {
                                continue;
                            }
                        }
                        if (lastPos + expression.Length < currentMethodBody.Length)
                        {
                            prevOrNextChar = currentMethodBody[lastPos + expression.Length];
                            if (characterClass.IndexOf(prevOrNextChar) > -1)
                            {
                                continue;
                            }
                        }

                        int style = Sci.StyleAt(funcBodyStart + lastPos) & stylemask;
                        if (ASComplete.IsCommentStyle(style))
                        {
                            continue;
                        }
                        else if ((isExprInDoubleQuotes && currentMethodBody[lastPos] == '"' && currentMethodBody[lastPos + expression.Length - 1] == '"')
                            || (isExprInSingleQuotes && currentMethodBody[lastPos] == '\'' && currentMethodBody[lastPos + expression.Length - 1] == '\''))
                        {
                            
                        }
                        else if (!ASComplete.IsTextStyle(style))
                        {
                            continue;
                        }

                        Sci.SetSel(funcBodyStart + lastPos, funcBodyStart + lastPos + expression.Length);
                        Sci.ReplaceSel(NewName);
                        currentMethodBody = currentMethodBody.Substring(0, lastPos) + NewName + currentMethodBody.Substring(lastPos + expression.Length);
                        lastPos += NewName.Length;
                    }
                    else
                    {
                        break;
                    }
                }

                Sci.CurrentPos = funcBodyStart;
                Sci.SetSel(Sci.CurrentPos, Sci.CurrentPos);

                string snippet = "var " + NewName + ":$(EntryPoint) = " + expression + ";\n$(Boundary)";
                SnippetHelper.InsertSnippetText(Sci, Sci.CurrentPos, snippet);
            }
            finally
            {
                Sci.EndUndoAction();
            }
        }