zoukankan      html  css  js  c++  java
  • Controlling IntelliSense Through Macros VS2005 sp1 vs2008

    http://blogs.msdn.com/b/vcblog/archive/2007/11/19/controlling-intellisense-through-macros.aspx

    First, bring up the Macro Explorer, which can be accessed through “Tools|Macros|Macro Explorer”.  In the Macro Explorer window, right click on the “Macros” node and select “New Macro Project”.  Select “Macro Project”, give it the name “Intellisense”, and specify a location to save it.  A macro project will be created along with a module called “Module1”.  Change the name of the module to “IntellisenseModule” by right clicking on the module and selecting “Rename”.  Next, right click on the module and select “Edit”.  This will bring up a new Visual Studio window with an empty module in it.  Paste the code from Figure 1 into this window and then select “File|Close and Return”.  You should see the five subroutines listed underneath the module now.

    OK, you now have the code in place and you just need to assign these macros to toolbar buttons.  Select the “Tools|Customize…” menu item and click the “New…” button on the toolbars tab of the dialog that came up. Give it the name “Intellisense” and click OK.  There should be an empty toolbar just to the right of the dialog box.  Select the “Commands” tab in the dialog, and scroll down the categories list box and select “Macros” from the list.  You should see the macros from the code you previously pasted.  The first one should be named “Intellisense.IntellisenseModule.DeleteNcbAndReload”.  Click and drag each of the five macros to the toolbar that you just created.  As you drop each one, a button will be created with just the name of the macro displayed on the button.  After dropping the button onto the toolbar, you can right click on each button and change the text and pick an icon for the button.

    To give you a preview, here is what it looks like when everything is done.  In your version, the text doesn’t need to be this long or you could create custom icons for it.  You could also add these commands to menus.

    Intellisense On

    This is the normal mode of operation and all aspects of Intellisense will be operating as normal.

    Intellisense Off

    In this mode, most of Intellisense is disabled, although if an NCB file exists, it will be opened, however no background parsing or updating or any queries will be directed to it.  This isn’t quite the same as deleting “feacp.dll”, which some customers have resorted to, although it is very close to the same.

    Intellisense NoUpdate

    This setting disables any reparsing of files when they become dirty and therefore no significant updates to the NCB are made.  This mode is useful when editing core header files that would trigger a reparse of significant portions of the solution.  When you turn Intellisense back on after being in this mode, the IDE will do a rescan of the solution and mark any changed files for reparsing.  This scan isn’t very expensive and is identical to what happens when you open a solution, but if a significant number of files need reparsing, that work will still happen in the background.

    Intellisense Status

    This macro queries for status and displays a message box showing what the current Intellisense settings are.

    DeleteNcbAndReload

    This macro doesn’t actually rely on any new functionality.  It simply closes the solution, deletes the corresponding NCB, and reloads the solution.  This is useful if Intellisense starts acting flaky such as not returning any correct information.  When the solution is reloaded, it will reparse the solution and regenerate the NCB file.

    Important notes:

    1)      These settings are persisted when the IDE is shutdown and are not tied to a solution or project, so don’t turn off Intellisense for one solution and then wonder why it isn’t working for another solution.  It is probably possible to create a macro that will remind you of this when loading a solution, but I haven’t looked into that.

    2)      Even though the settings are not per solution, changes to the settings may be ignored if there is no VC solution loaded, so make sure you have a VC solution open before changing the settings.
    (The actual issue is whether vcpkg.dll is loaded in the VS process.  If it isn’t these macros won’t change the real settings.)

    Figure 1

    Imports System

    Imports EnvDTE

    Imports EnvDTE80

    Imports System.Diagnostics

    Enum ISENSE_FLAGS

        ISENSE_NORMAL = 0       'normal (Intellisense On)

        ISENSE_NOBG = &H1       'no bg parsing (Intellisense Updating Off - although NCB file will be opened r/w and repersisted at shutdown)

        ISENSE_NOQUERY = &H2    'no queries (don't run any ISense queries)

        ISENSE_NCBRO = &H4      'no saving of NCB (must be set before opening NCB, doesn't affect updating or queries, just persisting of NCB)

        ISENSE_OFF = &H7        'no bg parsing, no queries, no saving of NCB, ncb will still be opened, however

    End Enum

    Public Module IntellisenseModule

        Sub Intellisense_NoUpdate()

            DTE.Properties("TextEditor", "C/C++ Specific").Item("IntellisenseOptions").Value = ISENSE_FLAGS.ISENSE_NOBG Or ISENSE_FLAGS.ISENSE_NCBRO

        End Sub

        Sub Intellisense_Off()

            DTE.Properties("TextEditor", "C/C++ Specific").Item("IntellisenseOptions").Value = ISENSE_FLAGS.ISENSE_OFF

        End Sub

        Sub Intellisense_On()

            DTE.Properties("TextEditor", "C/C++ Specific").Item("IntellisenseOptions").Value = ISENSE_FLAGS.ISENSE_NORMAL

        End Sub

        Sub Intellisense_Status()

            Dim x

            x = DTE.Properties("TextEditor", "C/C++ Specific").Item("IntellisenseOptions").Value

            Dim result

            If x = ISENSE_FLAGS.ISENSE_NORMAL Then

                result = "Intellisense On"

            ElseIf x = ISENSE_FLAGS.ISENSE_OFF Then

                result = "Intellisense Off"

            Else

                If x And ISENSE_FLAGS.ISENSE_NOBG Then

                    result = "No background parsing. "

                End If

                If x And ISENSE_FLAGS.ISENSE_NOQUERY Then

                    result = result + "No Intellisense queries in IDE. "

                End If

                If x And ISENSE_FLAGS.ISENSE_NCBRO Then

                    result = result + "No saving of NCB file. "

                End If

            End If

            MsgBox(result)

        End Sub

        Sub DeleteNcbAndReload()

            Dim name

            Dim namesln

            namesln = DTE.Solution.FullName()

            If Len(namesln) > 4 Then

                name = Left(namesln, Len(namesln) - 4) & ".ncb"

                If MsgBox("This may take a while.  Closing solution, deleting " & name & ", and reopening solution.", MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then

                    DTE.Solution.Close()

                    Kill(name)

                    MsgBox("NCB deleted", MsgBoxStyle.OkOnly)

                    DTE.Solution.Open(namesln)

                End If

            Else

                MsgBox("No solution is currently loaded.", MsgBoxStyle.OkOnly)

            End If

        End Sub

    End Module

    翻译:

    1.在“Tools|Macros|Macro Explorer”下打开Macro Explorer。

    2.点击Macros节点,选择 “New Macro Project”  ,取名为“Intellisense”,然后选一个位置保存(默认位置即可)。

    3.你可以看到一个宏工程,名字叫做Module1,通过右键的rename将其名字改为IntellisenseModule(程序员就是有拼写强迫症。。。其实随便取个名字也没什么问题)。

    4.  右键选择Edit,然后会打开一个新的窗口。将表1中的文字复制到窗口,然后选择“File|Close and Return” 

    5.现在宏代码已经都有了,只需要把宏代码添加按钮位置即可(可以看到这段宏代码一共定义了四个操作,分别是:不更新,关闭开启,当前状态,当然,这些跟设置没关系)。

     

  • 相关阅读:
    Pandas数据分析 (三)
    Pandas数据分析 (二)
    Pandas数据分析 (一)
    Django后台应用管理名称修改
    Jupyter Notebooks 配置
    Hadoop完全分布式搭建流程
    Java学习笔记(五)
    微信小程序学习笔记(一)
    redis windows版安装
    Linux计划任务
  • 原文地址:https://www.cnblogs.com/logitechlike/p/3037090.html
Copyright © 2011-2022 走看看