示例#1
0
        void GenerateExtractVariable(List <SearchMatch> matches)
        {
            if (string.IsNullOrEmpty(newName))
            {
                newName = GetNewName();
            }
            if (string.IsNullOrEmpty(newName))
            {
                return;
            }
            var sci = PluginBase.MainForm.CurrentDocument.SciControl;

            sci.BeginUndoAction();
            try
            {
                var expression = sci.SelText.Trim(new char[] { '=', ' ', '\t', '\n', '\r', ';', '.' });
                expression = expression.TrimEnd(new char[] { '(', '[', '{', '<' });
                expression = expression.TrimStart(new char[] { ')', ']', '}', '>' });
                var insertPosition = sci.PositionFromLine(ASContext.Context.CurrentMember.LineTo);
                foreach (var match in matches)
                {
                    var position = sci.MBSafePosition(match.Index);
                    insertPosition = Math.Min(insertPosition, position);
                    match.LineText = sci.GetLine(match.Line - 1);
                }
                insertPosition = sci.LineFromPosition(insertPosition);
                insertPosition = sci.LineIndentPosition(insertPosition);
                RefactoringHelper.ReplaceMatches(matches, sci, newName);
                sci.SetSel(insertPosition, insertPosition);
                var member = new MemberModel(newName, string.Empty, FlagType.LocalVar, 0)
                {
                    Value = expression
                };
                var snippet = TemplateUtils.GetTemplate("Variable");
                snippet  = TemplateUtils.ReplaceTemplateVariable(snippet, "Modifiers", null);
                snippet  = TemplateUtils.ToDeclarationString(member, snippet);
                snippet += "$(Boundary)\n$(Boundary)";
                SnippetHelper.InsertSnippetText(sci, sci.CurrentPos, snippet);
                foreach (var match in matches)
                {
                    match.Line += 1;
                }
                Results = new Dictionary <string, List <SearchMatch> > {
                    { sci.FileName, matches }
                };
                if (outputResults)
                {
                    ReportResults();
                }
            }
            finally
            {
                sci.EndUndoAction();
            }
        }
示例#2
0
        protected override void ExecutionImplementation()
        {
            var sci           = PluginBase.MainForm.CurrentDocument.SciControl;
            var expr          = Complete.GetExpression(sci, sci.CurrentPos);
            var snippet       = GetSnippet(sci, expr);
            var startPosition = expr.StartPosition;

            sci.SetSel(startPosition, expr.EndPosition);
            sci.ReplaceSel(string.Empty);
            SnippetHelper.InsertSnippetText(sci, startPosition, snippet);
            sci.SetSel(startPosition, startPosition);
        }
示例#3
0
        static public bool HandleElementClose(object data)
        {
            if (!GetContext(data))
            {
                return(false);
            }

            if (tagContext.Closing)
            {
                return(false);
            }

            string type = ResolveType(mxmlContext, tagContext.Name);

            ScintillaNet.ScintillaControl sci = PluginBase.MainForm.CurrentDocument.SciControl;

            if (type.StartsWith("mx.builtin.") || type.StartsWith("fx.builtin.")) // special tags
            {
                if (type.EndsWith(".Script"))
                {
                    string snip = "$(Boundary)\n\t<![CDATA[\n\t$(EntryPoint)\n\t]]>\n</" + tagContext.Name + ">";
                    SnippetHelper.InsertSnippetText(sci, sci.CurrentPos, snip);
                    return(true);
                }
                if (type.EndsWith(".Style"))
                {
                    string snip = "$(Boundary)";
                    foreach (string ns in mxmlContext.namespaces.Keys)
                    {
                        string uri = mxmlContext.namespaces[ns];
                        if (ns != "fx")
                        {
                            snip += String.Format("\n\t@namespace {0} \"{1}\";", ns, uri);
                        }
                    }
                    snip += "\n\t$(EntryPoint)\n</" + tagContext.Name + ">";
                    SnippetHelper.InsertSnippetText(sci, sci.CurrentPos, snip);
                    return(true);
                }
            }
            return(false);
        }
示例#4
0
        /// <summary>
        /// 文字入力イベント
        /// </summary>
        /// <param name="sci"></param>
        /// <param name="value"></param>
        public void OnChar(ScintillaControl sci, Int32 value)
        {
            if (!m_showComplete)
            {
                return;
            }

            switch ((char)value)
            {
            case '[':
                showCompletion(m_compProvider.GenerateCompletionData(this.CurrentSci, (char)value));
                SnippetHelper.InsertSnippetText(sci, sci.CurrentPos, "]");
                break;

            case '@':
            case ' ':
            case '=':
                showCompletion(m_compProvider.GenerateCompletionData(this.CurrentSci, (char)value));
                break;
            }
        }
示例#5
0
        /// <summary>
        /// Inserts text from the snippets class
        /// </summary>
        public static Boolean InsertTextByWord(String word, Boolean emptyUndoBuffer)
        {
            ScintillaControl sci = Globals.SciControl;

            if (sci == null)
            {
                return(false);
            }
            Boolean canShowList = false;
            String  snippet     = null;

            if (word == null)
            {
                canShowList = true;
                word        = sci.GetWordFromPosition(sci.CurrentPos);
            }
            if (word != null && word.Length > 0)
            {
                snippet = GetSnippet(word, sci.ConfigurationLanguage, sci.Encoding);
            }
            // let plugins handle the snippet
            Hashtable data = new Hashtable();

            data["word"]    = word;
            data["snippet"] = snippet;
            DataEvent de = new DataEvent(EventType.Command, "SnippetManager.Expand", data);

            EventManager.DispatchEvent(Globals.MainForm, de);
            if (de.Handled)
            {
                return(true);
            }
            snippet = (string)data["snippet"];
            if (!String.IsNullOrEmpty(sci.SelText))
            {
                // Remember the previous selection
                ArgsProcessor.PrevSelText = sci.SelText;
            }
            if (snippet != null)
            {
                Int32  endPos   = sci.SelectionEnd;
                Int32  startPos = sci.SelectionStart;
                String curWord  = sci.GetWordFromPosition(endPos);
                if (startPos == endPos)
                {
                    endPos   = sci.WordEndPosition(sci.CurrentPos, true);
                    startPos = sci.WordStartPosition(sci.CurrentPos, true);
                    sci.SetSel(startPos, endPos);
                }
                if (!String.IsNullOrEmpty(curWord))
                {
                    // Remember the current word
                    ArgsProcessor.PrevSelWord = curWord;
                }
                SnippetHelper.InsertSnippetText(sci, endPos, snippet);
                return(true);
            }
            else if (canShowList)
            {
                ICompletionListItem        item;
                List <ICompletionListItem> items = new List <ICompletionListItem>();
                PathWalker    walker             = new PathWalker(PathHelper.SnippetDir, "*.fds", false);
                List <String> files = walker.GetFiles();
                foreach (String file in files)
                {
                    item = new SnippetItem(Path.GetFileNameWithoutExtension(file), file);
                    items.Add(item);
                }
                String path = Path.Combine(PathHelper.SnippetDir, sci.ConfigurationLanguage);
                if (Directory.Exists(path))
                {
                    walker = new PathWalker(path, "*.fds", false);
                    files  = walker.GetFiles();
                    foreach (String file in files)
                    {
                        item = new SnippetItem(Path.GetFileNameWithoutExtension(file), file);
                        items.Add(item);
                    }
                }
                if (items.Count > 0)
                {
                    items.Sort();
                    if (!String.IsNullOrEmpty(sci.SelText))
                    {
                        word = sci.SelText;
                    }
                    else
                    {
                        word = sci.GetWordFromPosition(sci.CurrentPos);
                        if (word == null)
                        {
                            word = String.Empty;
                        }
                    }
                    CompletionList.OnInsert += new InsertedTextHandler(HandleListInsert);
                    CompletionList.OnCancel += new InsertedTextHandler(HandleListInsert);
                    CompletionList.Show(items, false, word);
                    return(true);
                }
            }
            return(false);
        }
示例#6
0
        /// <summary>
        /// The actual process implementation
        /// </summary>
        protected void ExecutionImplementation()
        {
            ScintillaControl sci = PluginBase.MainForm.CurrentDocument.SciControl;

            sci.BeginUndoAction();
            try
            {
                string selection = sci.SelText;
                if (string.IsNullOrEmpty(selection))
                {
                    return;
                }

                if (selection.TrimStart().Length == 0)
                {
                    return;
                }

                sci.SetSel(sci.SelectionStart + selection.Length - selection.TrimStart().Length,
                           sci.SelectionEnd);
                sci.CurrentPos = sci.SelectionEnd;
                selection      = sci.SelText;

                int lineStart        = sci.LineFromPosition(sci.SelectionStart);
                int lineEnd          = sci.LineFromPosition(sci.SelectionEnd);
                int firstLineIndent  = sci.GetLineIndentation(lineStart);
                int entryPointIndent = 0;

                string snippet = GetSnippet(SnippetCode, sci.ConfigurationLanguage, sci.Encoding);
                int    pos     = snippet.IndexOfOrdinal("{0}");
                if (pos > -1)
                {
                    while (pos >= 0)
                    {
                        string c = snippet.Substring(--pos, 1);
                        if (c.Equals("\t"))
                        {
                            entryPointIndent += sci.Indent;
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                for (int i = lineStart; i <= lineEnd; i++)
                {
                    int indent = sci.GetLineIndentation(i);
                    if (i > lineStart)
                    {
                        sci.SetLineIndentation(i, indent - firstLineIndent + entryPointIndent);
                    }
                }

                snippet = snippet.Replace("{0}", sci.SelText);

                int insertPos = sci.SelectionStart;
                int selEnd    = sci.SelectionEnd;

                sci.SetSel(insertPos, selEnd);
                SnippetHelper.InsertSnippetText(sci, insertPos, snippet);
            }
            finally
            {
                sci.EndUndoAction();
            }
        }
        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();
            }
        }