コード例 #1
0
ファイル: LuaFileCodeMerger.cs プロジェクト: yishuihanly/NPL
        /// <summary>
        /// Replaces the selected text with the given text.
        /// </summary>
        /// <param name="startLine">The start line of the specified range of text.</param>
        /// <param name="startRow">The start row of the specified range of text.</param>
        /// <param name="endLine">The end line of the specified range of text.</param>
        /// <param name="endRow">The end row of the specified range of text.</param>
        /// <param name="newText">The replacement text for pattern.</param>
        public void SetText(int startLine, int startRow, int endLine, int endRow, string newText)
        {
            var       textPoint = new LuaTextPoint(Document, startRow, startLine);
            EditPoint ep        = Document.CreateEditPoint(textPoint);

            ep.ReplaceText(textPoint, newText, (int)vsEPReplaceTextOptions.vsEPReplaceTextAutoformat);
        }
コード例 #2
0
ファイル: LuaFileCodeMerger.cs プロジェクト: yishuihanly/NPL
        /// <summary>
        /// Finds a pattern in the specified range of text and replaces it with the specified text.
        /// </summary>
        /// <param name="startLine">The start line of the specified range of text.</param>
        /// <param name="startRow">The start row of the specified range of text.</param>
        /// <param name="endLine">The end line of the specified range of text.</param>
        /// <param name="endRow">The end row of the specified range of text.</param>
        /// <param name="oldText">The text to replace.</param>
        /// <param name="newText">The replacement text for pattern.</param>
        public bool Replace(int startLine, int startRow, int endLine, int endRow, string oldText, string newText)
        {
            EditPoint  ep           = Document.CreateEditPoint(new LuaTextPoint(Document, startRow, startLine));
            TextRanges tr           = null;
            TextPoint  endTextPoint = new LuaTextPoint(Document, endRow, endLine);

            //Trace.WriteLine(string.Format("Start: {0} - End: {1}", new LuaTextPoint(Document, startRow, startLine),endTextPoint));
            return(ep.ReplacePattern(endTextPoint, oldText, newText,
                                     (int)vsFindOptions.vsFindOptionsMatchWholeWord, ref tr));
        }
コード例 #3
0
        /// <summary>
        /// Gets CodeElement by actual EditPoint.
        /// </summary>
        /// <returns></returns>
        public CodeElement GetElementByEditPoint()
        {
            var textDocument = (TextDocument)ProjectItem.Document.Object("TextDocument");
            var point        = new LuaTextPoint(textDocument,
                                                textDocument.Selection.ActivePoint.LineCharOffset,
                                                textDocument.Selection.ActivePoint.Line);
            var element = GetElementByEditPoint(point);

            return(element);
        }
コード例 #4
0
        /// <summary>
        /// Returns function declaration line from source code.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="document">The document.</param>
        /// <param name="startPoint">The start point.</param>
        /// <returns></returns>
        public static TextPoint GetFunctionDeclarationFromSource(string name, TextDocument document, TextPoint startPoint)
        {
            TextPoint endPoint         = null;
            var       functionLineText = GetCodeLineText(document, startPoint.Line);

            if (!string.IsNullOrEmpty(functionLineText))
            {
                int startIndex = functionLineText.ToLower().IndexOf("function", StringComparison.CurrentCultureIgnoreCase);
                if (startIndex > -1)
                {
                    int nameIndex = functionLineText.IndexOf(name);
                    endPoint = new LuaTextPoint(document, nameIndex + name.Length + 2, startPoint.Line);
                }
            }
            return(endPoint);
        }
コード例 #5
0
ファイル: LuaFileCodeMerger.cs プロジェクト: yishuihanly/NPL
        /// <summary>
        /// Finds a function pattern in the specified range of text and replaces it with the specified text.
        /// </summary>
        /// <param name="startLine">The start line of the specified range of text.</param>
        /// <param name="startRow">The start row of the specified range of text.</param>
        /// <param name="endLine">The end line of the specified range of text.</param>
        /// <param name="endRow">The end row of the specified range of text.</param>
        /// <param name="oldName">The text to replace.</param>
        /// <param name="newName">The replacement text for pattern.</param>
        public bool RenameFunction(int startLine, int startRow, int endLine, int endRow, string oldName, string newName)
        {
            TextPoint textPoint        = new LuaTextPoint(Document, startRow, startLine);
            TextPoint endTextPoint     = new LuaTextPoint(Document, endRow, startLine);
            var       functionLineText = LuaCodeDomHelper.GetCodeLineText(Document, startLine);

            if (!string.IsNullOrEmpty(functionLineText))
            {
                int startIndex = functionLineText.ToLower().IndexOf("function", StringComparison.CurrentCultureIgnoreCase);
                if (startIndex > -1)
                {
                    int nameIndex = functionLineText.IndexOf(oldName);
                    textPoint    = new LuaTextPoint(Document, nameIndex, startLine);
                    endTextPoint = new LuaTextPoint(Document, nameIndex + oldName.Length + 2, startLine);
                }
            }
            return(Replace(textPoint, endTextPoint, oldName, newName));
            //ep.ReplaceText(textPoint, newName, (int)vsEPReplaceTextOptions.vsEPReplaceTextAutoformat);
        }
コード例 #6
0
        /// <summary>
        /// Converts a LexLocation type to TextPoint.
        /// </summary>
        /// <param name="location">LexLocation instance.</param>
        /// <param name="document">TextDocument</param>
        /// <returns>new LexLocation instance</returns>
        public static TextPoint LexLocationToTextPoint(TextDocument document, LexLocation location)
        {
            TextPoint point = new LuaTextPoint(document, location.sCol, location.sLin);

            return(point);
        }