예제 #1
0
        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);
        }
예제 #2
0
 private void OnUpdateCallTip(ScintillaControl sci, int position)
 {
     if (ASComplete.HasCalltip())
     {
         int pos = sci.CurrentPos - 1;
         char c = (char)sci.CharAt(pos);
         if ((c == ',' || c == '(') && sci.BaseStyleAt(pos) == 0)
             sci.Colourise(0, -1);
         ASComplete.HandleFunctionCompletion(sci, false, true);
     }
 }
예제 #3
0
 /// <summary>
 /// Updates editor Globals.Settings to the specified ScintillaControl
 /// </summary>
 public static void ApplySciSettings(ScintillaControl sci)
 {
     try
     {
         sci.CaretPeriod = Globals.Settings.CaretPeriod;
         sci.CaretWidth = Globals.Settings.CaretWidth;
         sci.EOLMode = LineEndDetector.DetectNewLineMarker(sci.Text, (Int32)Globals.Settings.EOLMode);
         sci.IsBraceMatching = Globals.Settings.BraceMatchingEnabled;
         sci.UseHighlightGuides = !Globals.Settings.HighlightGuide;
         sci.Indent = Globals.Settings.IndentSize;
         sci.SmartIndentType = Globals.Settings.SmartIndentType;
         sci.IsBackSpaceUnIndents = Globals.Settings.BackSpaceUnIndents;
         sci.IsCaretLineVisible = Globals.Settings.CaretLineVisible;
         sci.IsIndentationGuides = Globals.Settings.ViewIndentationGuides;
         sci.IsTabIndents = Globals.Settings.TabIndents;
         sci.IsUseTabs = Globals.Settings.UseTabs;
         sci.IsViewEOL = Globals.Settings.ViewEOL;
         sci.ScrollWidth = Globals.Settings.ScrollWidth;
         sci.TabWidth = Globals.Settings.TabWidth;
         sci.ViewWS = Convert.ToInt32(Globals.Settings.ViewWhitespace);
         sci.WrapMode = Convert.ToInt32(Globals.Settings.WrapText);
         sci.SetProperty("fold", Convert.ToInt32(Globals.Settings.UseFolding).ToString());
         sci.SetProperty("fold.comment", Convert.ToInt32(Globals.Settings.FoldComment).ToString());
         sci.SetProperty("fold.compact", Convert.ToInt32(Globals.Settings.FoldCompact).ToString());
         sci.SetProperty("fold.preprocessor", Convert.ToInt32(Globals.Settings.FoldPreprocessor).ToString());
         sci.SetProperty("fold.at.else", Convert.ToInt32(Globals.Settings.FoldAtElse).ToString());
         sci.SetProperty("fold.html", Convert.ToInt32(Globals.Settings.FoldHtml).ToString());
         sci.SetFoldFlags((Int32)Globals.Settings.FoldFlags);
         /** 
         * Set correct line number margin width
         */
         Boolean viewLineNumbers = Globals.Settings.ViewLineNumbers;
         if (viewLineNumbers) sci.SetMarginWidthN(1, 31);
         else sci.SetMarginWidthN(1, 0);
         /**
         * Set correct bookmark margin width
         */
         Boolean viewBookmarks = Globals.Settings.ViewBookmarks;
         if (viewBookmarks) sci.SetMarginWidthN(0, 14);
         else sci.SetMarginWidthN(0, 0);
         /**
         * Set correct folding margin width
         */
         Boolean useFolding = Globals.Settings.UseFolding;
         if (!useFolding && !viewBookmarks && !viewLineNumbers) sci.SetMarginWidthN(2, 0);
         else if (useFolding) sci.SetMarginWidthN(2, 15);
         else sci.SetMarginWidthN(2, 2);
         /**
         * Adjust the print margin
         */
         sci.EdgeColumn = Globals.Settings.PrintMarginColumn;
         if (sci.EdgeColumn > 0) sci.EdgeMode = 1;
         else sci.EdgeMode = 0;
         /**
         * Add missing ignored keys
         */
         Int32 count = Globals.MainForm.IgnoredKeys.Count;
         for (Int32 i = 0; i < count; i++)
         {
             Keys keys = (Keys)Globals.MainForm.IgnoredKeys[i];
             if (!sci.ContainsIgnoredKeys(keys))
             {
                 sci.AddIgnoredKeys(keys);
             }
         }
         String lang = sci.ConfigurationLanguage;
         sci.ConfigurationLanguage = lang;
         sci.Colourise(0, -1);
         sci.Refresh();
     }
     catch (Exception ex)
     {
         ErrorManager.ShowError(ex);
     }
 }
예제 #4
0
 /// <summary>
 /// Changes the current document's language
 /// </summary>
 public static void ChangeSyntax(String lang, ScintillaControl sci)
 {
     sci.StyleClearAll();
     sci.StyleResetDefault();
     sci.ClearDocumentStyle();
     sci.ConfigurationLanguage = lang;
     sci.Colourise(0, -1);
     sci.Refresh();
     ButtonManager.UpdateFlaggedButtons();
     Globals.MainForm.OnSyntaxChange(lang);
 }
예제 #5
0
 public static void ApplySciSettings(ScintillaControl sci, Boolean hardUpdate)
 {
     try
     {
         sci.CaretPeriod = Globals.Settings.CaretPeriod;
         sci.CaretWidth = Globals.Settings.CaretWidth;
         sci.EOLMode = LineEndDetector.DetectNewLineMarker(sci.Text, (Int32)Globals.Settings.EOLMode);
         sci.IsBraceMatching = Globals.Settings.BraceMatchingEnabled;
         sci.UseHighlightGuides = !Globals.Settings.HighlightGuide;
         sci.Indent = Globals.Settings.IndentSize;
         sci.SmartIndentType = Globals.Settings.SmartIndentType;
         sci.IsBackSpaceUnIndents = Globals.Settings.BackSpaceUnIndents;
         sci.IsCaretLineVisible = Globals.Settings.CaretLineVisible;
         sci.IsIndentationGuides = Globals.Settings.ViewIndentationGuides;
         sci.IndentView = Globals.Settings.IndentView;
         sci.IsTabIndents = Globals.Settings.TabIndents;
         sci.IsUseTabs = Globals.Settings.UseTabs;
         sci.IsViewEOL = Globals.Settings.ViewEOL;
         sci.ScrollWidth = Globals.Settings.ScrollWidth;
         sci.TabWidth = Globals.Settings.TabWidth;
         sci.ViewWS = Convert.ToInt32(Globals.Settings.ViewWhitespace);
         sci.WrapMode = Convert.ToInt32(Globals.Settings.WrapText);
         sci.SetProperty("fold", Convert.ToInt32(Globals.Settings.UseFolding).ToString());
         sci.SetProperty("fold.comment", Convert.ToInt32(Globals.Settings.FoldComment).ToString());
         sci.SetProperty("fold.compact", Convert.ToInt32(Globals.Settings.FoldCompact).ToString());
         sci.SetProperty("fold.preprocessor", Convert.ToInt32(Globals.Settings.FoldPreprocessor).ToString());
         sci.SetProperty("fold.at.else", Convert.ToInt32(Globals.Settings.FoldAtElse).ToString());
         sci.SetProperty("fold.html", Convert.ToInt32(Globals.Settings.FoldHtml).ToString());
         sci.SetProperty("lexer.cpp.track.preprocessor", "0");
         sci.SetVirtualSpaceOptions((Int32)Globals.Settings.VirtualSpaceMode);
         sci.SetFoldFlags((Int32)Globals.Settings.FoldFlags);
         /**
         * Set if themes should colorize the first margin
         */
         Language language = SciConfig.GetLanguage(sci.ConfigurationLanguage);
         if (language != null && language.editorstyle != null)
         {
             Boolean colorizeMarkerBack = language.editorstyle.ColorizeMarkerBack;
             if (colorizeMarkerBack) sci.SetMarginTypeN(0, (Int32)MarginType.Fore);
             else sci.SetMarginTypeN(0, (Int32)MarginType.Symbol);
         }
         /**
         * Set correct line number margin width
         */
         Boolean viewLineNumbers = Globals.Settings.ViewLineNumbers;
         if (viewLineNumbers) sci.SetMarginWidthN(1, ScaleArea(sci, 36));
         else sci.SetMarginWidthN(1, 0);
         /**
         * Set correct bookmark margin width
         */
         Boolean viewBookmarks = Globals.Settings.ViewBookmarks;
         if (viewBookmarks) sci.SetMarginWidthN(0, ScaleArea(sci, 14));
         else sci.SetMarginWidthN(0, 0);
         /**
         * Set correct folding margin width
         */
         Boolean useFolding = Globals.Settings.UseFolding;
         if (!useFolding && !viewBookmarks && !viewLineNumbers) sci.SetMarginWidthN(2, 0);
         else if (useFolding) sci.SetMarginWidthN(2, ScaleArea(sci, 15));
         else sci.SetMarginWidthN(2, ScaleArea(sci, 2));
         /**
         * Adjust the print margin
         */
         sci.EdgeColumn = Globals.Settings.PrintMarginColumn;
         if (sci.EdgeColumn > 0) sci.EdgeMode = 1;
         else sci.EdgeMode = 0;
         /**
         * Add missing ignored keys
         */
         foreach (Keys keys in ShortcutManager.AllShortcuts)
         {
             if (keys != Keys.None && !sci.ContainsIgnoredKeys(keys))
             {
                 sci.AddIgnoredKeys(keys);
             }
         }
         if (hardUpdate)
         {
             String lang = sci.ConfigurationLanguage;
             sci.ConfigurationLanguage = lang;
         }
         sci.Colourise(0, -1);
         sci.Refresh();
     }
     catch (Exception ex)
     {
         ErrorManager.ShowError(ex);
     }
 }
        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();
            }
        }
예제 #7
0
        public static void GenerateExtractVariable(ScintillaControl sci, string newName)
        {
            string expression = sci.SelText.Trim(new char[] { '=', ' ', '\t', '\n', '\r', ';', '.' });
            expression = expression.TrimEnd(new char[] { '(', '[', '{', '<' });
            expression = expression.TrimStart(new char[] { ')', ']', '}', '>' });

            var 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;
            var insertPosition = funcBodyStart + currentMethodBody.IndexOfOrdinal(expression);
            var line = sci.LineFromPosition(insertPosition);
            insertPosition = sci.LineIndentPosition(line);

            int lastPos = -1;
            sci.Colourise(0, -1);
            while (true)
            {
                lastPos = currentMethodBody.IndexOfOrdinal(expression, lastPos + 1);
                if (lastPos > -1)
                {
                    char prevOrNextChar;
                    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;
                        }
                    }

                    var pos = funcBodyStart + lastPos;
                    int style = sci.BaseStyleAt(pos);
                    if (ASComplete.IsCommentStyle(style)) continue;
                    sci.SetSel(pos, pos + expression.Length);
                    sci.ReplaceSel(newName);
                    currentMethodBody = currentMethodBody.Substring(0, lastPos) + newName + currentMethodBody.Substring(lastPos + expression.Length);
                    lastPos += newName.Length;
                }
                else
                {
                    break;
                }
            }

            sci.CurrentPos = insertPosition;
            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);
        }