• 强大的宏删除所匹配字符串的行


          开发过程中经常碰到一种情况,要去除基类的一个属性,而基类去掉后,所有子类的这个属性必须手动删除,多的时候相当郁闷,而下面这个宏可解决。具体使用方面如下:

    1 在VS IDE 中按ALT+F8打开宏资源管理器,右键MyMacros项目建立一个模块DeleteLine 。

    2 右键这个模块--》编辑会打开宏项目,把下面的代码粘贴上去就建立了这个宏命令。

    3 回到项目中,在宏资源管理器中双击DeleteLine -->DeleteAll或右键--》运行会弹出对话框让你输入要查找的字符串,如.Text = "我是中国人",则命令会自动查找当前项目,把含有这串字符的行删除;同时在“输出窗口”把删除的行显示出来以便核对。

    4 注意:此命令是针对当前项目,同时要删除时打开项目中一个当前文件,否则可能出现未能查找到的情况。,ENJOY


    Imports EnvDTE
    Imports EnvDTE80
    Imports System.Diagnostics
    Imports Microsoft.VisualBasic
    Imports Microsoft.VisualBasic.ControlChars

    Public Module DeleteLine '删除匹配的字符串行

        Dim findWhat = ""
        Dim textDocument As EnvDTE.TextDocument
        Dim outputWindowPane As OutputWindowPane

        Sub DeleteAll()
            Dim lastDocument As Integer = 1

            findWhat = InputBox("请输入要删除行查找字符串!")
            outputWindowPane = GetOutputWindowPane("删除的行")
            OpenFindDocument() '打开含有所要查找字串的窗口

            While (DTE.Documents.Count >= lastDocument)
                textDocument = DTE.Documents.Item(lastDocument).Object("textDocument")
                lastDocument = lastDocument + 1

                textDocument.Parent.Activate() '激活页面作为当前操作界面
                textDocument.StartPoint.CreateEditPoint().StartOfDocument()
                textDocument.Selection.SelectAll()

                Delete() '删除找到的行
            End While
        End Sub

        Sub OpenFindDocument()
            DTE.Find.Action = vsFindAction.vsFindActionReplaceAll
            DTE.Find.Backwards = False
            DTE.Find.MatchWholeWord = False
            DTE.Find.MatchCase = True
            DTE.Find.MatchInHiddenText = True
            DTE.Find.KeepModifiedDocumentsOpen = True
            DTE.Find.Target = vsFindTarget.vsFindTargetCurrentProject
            DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxLiteral
            DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone
            DTE.Find.FindWhat = findWhat
            DTE.Find.ReplaceWith = findWhat
            DTE.Find.Execute()
        End Sub

        Sub Delete()
            Dim textSelection As TextSelection
            Dim textSelectionPointSaved As TextPoint
            Dim findResult As EnvDTE.vsFindResult
            Dim lastFoundAt As Integer = 0

            textSelection = textDocument.Selection

            DTE.Find.MatchWholeWord = False
            DTE.Find.Action = vsFindAction.vsFindActionFind
            DTE.Find.Target = vsFindTarget.vsFindTargetOpenDocuments
            DTE.Find.MatchCase = False
            DTE.Find.Backwards = False
            DTE.Find.MatchInHiddenText = True
            DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxLiteral
            DTE.Find.FindWhat = findWhat

            textSelection.StartOfDocument()
            textSelectionPointSaved = textSelection.ActivePoint.CreateEditPoint()

            ''清空“输出窗口”
            outputWindowPane.Clear()

            CType(DTE.Find, EnvDTE80.Find2).WaitForFindToComplete = True
            findResult = DTE.Find.Execute()
            While (findResult = vsFindResult.vsFindResultFound)
                If textSelection.AnchorPoint.Line <= lastFoundAt Then
                    Exit While
                End If

                textSelection.SelectLine()

                If textSelection.Text.IndexOf(findWhat) >= 0 Then
                    outputWindowPane.OutputString(textDocument.Parent.FullName + "(" + textSelection.AnchorPoint.Line.ToString() + "):" + textSelection.Text)
                    textSelection.Delete() '删除行
                End If

                lastFoundAt = textSelection.AnchorPoint.Line
                textSelection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn)
                findResult = DTE.Find.Execute()
            End While

            '' 将插入符号还原到调用此命令之前的位置。
            textSelection.MoveToPoint(textSelectionPointSaved)
        End Sub

        '输出信息到  输出窗口
        Function GetOutputWindowPane(ByVal Name As String, Optional ByVal show As Boolean = True) As OutputWindowPane
            Dim window As Window
            Dim outputWindow As OutputWindow
            Dim outputWindowPane As OutputWindowPane

            window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
            If show Then window.Visible = True
            outputWindow = window.Object
            Try
                outputWindowPane = outputWindow.OutputWindowPanes.Item(Name)
            Catch e As System.Exception
                outputWindowPane = outputWindow.OutputWindowPanes.Add(Name)
            End Try
            outputWindowPane.Activate()
            Return outputWindowPane
        End Function
    End Module

    [注:有点BUG, 修改了一下]

  • 相关阅读:
    2、netlink简介
    1、netlink 连接器 通信机制
    第一章 02 谈谈static关键词
    第一章 01 namespace 命名空间
    第一章 00 StringUtil.cpp和StringUtil.hh分析
    说说log4cplus
    Jq 操作json
    怪怪的bug,提示值不能为空,连action都不进
    浏览器兼容性部分---FF&IE678
    Jquery 随笔
  • 原文地址:https://www.cnblogs.com/eugenewu0808/p/1326929.html
Copyright © 2020-2023  润新知