Visual Studio Extention - Context Menu for 'Server Explorer'

穿精又带淫゛_ 提交于 2019-12-11 05:46:52

问题


In a VSIX project, in the .vsct file I can see how to target different objects and provide a custom context menu:

For instance, the following will target an item node in the solution explorer:

    <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_ITEMNODE"/>
    <!--<Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS"/>-->
  </Group>

Changing the id property from IDM_VS_CTXT_ITEMNODE to IDM_VS_CTXT_CODEWIN will result in the context menu appearing in the code window instead.

This is documented here: Microsoft Documentation

However, I would like my context menu to appear in the 'Server Explorer' instead. An example and a link to the documentation would be very helpful.


回答1:


To find Visual Studio menu guids, this usually works. In your registry set EnableVSIPLogging DWORD to 1, under HKEY_CURRENT_USER\SOFTWARE\Microsoft\VisualStudio\14.0\General.

Restart Visual Studio (and computer?) and hold Ctrl+Shift and right click an item in the server explorer, it will open a dialog window with something like this:

You can go from there.




回答2:


All of VS 2015's commands, menus, toolbars etc are detailed in a couple of c++ header files (stdidcmd.h and vsshlids.h).

On my install they are in 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VSSDK\VisualStudioIntegration\Common\Inc'.

Had a very brief look in the files and i think you'll need something starting

  • IDG_SE_CONTEXT_ to target groups within the server explorer context menu
  • IDG_SE_TOOLBAR_ to get into the toolbar
  • IDM_SE_CONTEXT_ to get to the context menu
  • IDM_SE_TOOLBAR_ to get to the toolbar menu



回答3:


Thanks to Paul Swetz and James Sinclair I was able to get this working.

Using the method described by Paul Swetz I could identify the guid required for the Server Window object I was clicking, in this case the table node.

Having got that I added that id to the Symbols in the .vsct file, with a name of my choice:

<GuidSymbol name="guidWhatever" value="{d4f02a6a-c5ae-4bf2-938d-f1625bdca0e2}"> <!--//server explorer - table-->
  <IDSymbol name="IDMX_DV_OBJECT_NODE" value="0x8200"/>
</GuidSymbol>

Now I can use that in Groups and the custom command appears in the dropdown.

<Groups> 
  <Group guid="guidFirstCommandPackageCmdSet" id="MyMenuGroup" priority="0x0600">
    <!--<Parent guid="{D309F791-903F-11D0-9EFC-00A0C911004F}" id="IDM_VS_CTXT_ITEMNODE"/>-->
    <Parent guid="guidWhatever" id="IDMX_DV_OBJECT_NODE"/>
  </Group>
</Groups>

The only problem now is identifying and accessing the selected table and database but that's another matter.



来源:https://stackoverflow.com/questions/39508063/visual-studio-extention-context-menu-for-server-explorer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!