示例#1
0
        private void AddGetterSetterPreview(List <ReferenceInfo> refInfos, ASResult target, string prefix, string name, bool supportInsideComment, bool supportInsideString)
        {
            target = RenamingHelper.FindGetterSetter(target, prefix + name);
            if (target == null)
            {
                return;
            }

            var results = new FRRunner().SearchSync(GetConfig(prefix + name))[currentDoc.FileName];
            int offset  = prefix.Length;

            foreach (var match in results)
            {
                int    index         = match.Index + offset;
                int    length        = match.Length - offset;
                string value         = match.Value.Substring(offset);
                int    style         = sci.BaseStyleAt(index);
                bool   insideComment = supportInsideComment && RefactoringHelper.IsCommentStyle(style);
                bool   insideString  = supportInsideString && RefactoringHelper.IsStringStyle(style);

                if (RefactoringHelper.DoesMatchPointToTarget(sci, match, target, null) || insideComment || insideString)
                {
                    var @ref = new ReferenceInfo()
                    {
                        Index = index, Length = length, Value = value
                    };
                    refInfos.Add(@ref);

                    if (previewChanges && (!insideComment || includeComments) && (!insideString || includeStrings))
                    {
                        Highlight(index, value.Length);
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Set up required variables for live preview features.
        /// </summary>
        /// <param name="supportInsideComment">Whether searching inside comments are enabled.</param>
        /// <param name="supportInsideString">Whether searching inside strings are enabled.</param>
        /// <param name="supportPreviewChanges">Whether live preview is enabled.</param>
        /// <param name="target">Current target to rename.</param>
        private void SetupLivePreview(bool supportInsideComment, bool supportInsideString, bool supportPreviewChanges, ASResult target)
        {
            if (!supportPreviewChanges)
            {
                return;
            }

            var results  = new FRRunner().SearchSync(GetConfig(oldName))[currentDoc.FileName];
            var tempRefs = new List <ReferenceInfo>();

            foreach (var match in results)
            {
                int    index         = match.Index;
                int    length        = match.Length;
                string value         = match.Value;
                int    style         = sci.BaseStyleAt(index);
                bool   insideComment = supportInsideComment && RefactoringHelper.IsCommentStyle(style);
                bool   insideString  = supportInsideString && RefactoringHelper.IsStringStyle(style);

                if (RefactoringHelper.DoesMatchPointToTarget(sci, match, target, null) || insideComment || insideString)
                {
                    var @ref = new ReferenceInfo()
                    {
                        Index = index, Length = length, Value = value
                    };
                    tempRefs.Add(@ref);

                    if (currentRef == null && match.Index == start)
                    {
                        currentRef = @ref;
                    }
                    else if (previewChanges && (!insideComment || includeComments) && (!insideString || includeStrings))
                    {
                        Highlight(index, length);
                    }
                }
            }

            if (RenamingHelper.HasGetterSetter(target))
            {
                var list = target.Member.Parameters;
                if (list[0].Name == RenamingHelper.ParamGetter)
                {
                    AddGetterSetterPreview(tempRefs, target, RenamingHelper.PrefixGetter, oldName, supportInsideComment, supportInsideString);
                }
                if (list[1].Name == RenamingHelper.ParamSetter)
                {
                    AddGetterSetterPreview(tempRefs, target, RenamingHelper.PrefixSetter, oldName, supportInsideComment, supportInsideString);
                }
                tempRefs.Sort();
            }

            refs = tempRefs.ToArray();
        }
示例#3
0
        /// <summary>
        /// Update all references to the current target.
        /// </summary>
        /// <param name="replacement">Replacement string.</param>
        /// <param name="current">Whether the current reference is updated.</param>
        /// <param name="comments">Whether to update matches in comments.</param>
        /// <param name="strings">Whether to update matches in strings.</param>
        /// <param name="others">Whether to update other matches.</param>
        /// <param name="highlight">Whether to highlight the matches.</param>
        private void UpdateReferences(string replacement, bool current, bool comments, bool strings, bool others, bool highlight)
        {
            sci.DisableAllSciEvents = true;

            try
            {
                int pos       = sci.CurrentPos;
                int newLength = replacement.Length;
                int delta     = 0;

                pos -= start;

                for (int i = 0, l = refs.Length; i < l; i++)
                {
                    var @ref      = refs[i];
                    int oldLength = @ref.Length;

                    @ref.Index += delta;
                    int s = @ref.Index;
                    int e = s + oldLength;

                    if (@ref == currentRef)
                    {
                        if (!current)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        bool replace;
                        int  style = sci.BaseStyleAt(s);

                        if (RefactoringHelper.IsCommentStyle(style))
                        {
                            replace = comments;
                        }
                        else if (RefactoringHelper.IsStringStyle(style))
                        {
                            replace = strings;
                        }
                        else
                        {
                            replace = others;
                        }

                        if (!replace)
                        {
                            continue;
                        }

                        sci.SetSel(s, e);
                        sci.ReplaceSel(replacement);
                    }

                    @ref.Length = newLength;
                    @ref.Value  = replacement;
                    delta      += newLength - oldLength;

                    if (highlight)
                    {
                        Highlight(s, newLength);
                    }
                }

                start = currentRef.Index;
                end   = start + currentRef.Length;

                pos += start;
                sci.SetSel(pos, pos);
            }
            finally
            {
                sci.DisableAllSciEvents = false;
            }
        }