0

我想向服務器資源管理器中列出的SQL Server數據庫中的每個表顯示的每個節點的上下文菜單中添加一個自定義命令。在服務器資源管理器中爲表節點創建Visual Studio擴展數據連接

Server Explorer

我已經通過一個基本的教程了,並添加到工具菜單欄命令,以及自定義頂級菜單。

我也看到了教程Extending the Server Explorer to Display Web Parts,它非常接近我想要做的事情,但它是特定於SharePoint連接節點,並使用特定於Sharepoint的IExplorerNodeTypeExtension接口。我無法找到任何有關數據連接節點的文檔。任何人都可以提供有關我應該利用哪些接口的相關文檔或信息的任何參考?

+0

就像卡洛斯·J的建議在這裏:https://social.msdn.microsoft.com/Forums/vstudio/en-US/6e43cd5a-f0b1-4e05- 8dc8-f5509590e28f/server-explorer-extension?forum = vsx,似乎您需要使用EnableVSIPLogging在上下文菜單中找到組的Guid:Id。 –

回答

1

隨着Jack Zhai和其他一些網絡資源的一些提示,我能夠追蹤到信息。

所以第一,我啓用VSIPLogging由計算機\ HKEY_CURRENT_USER \ SOFTWARE \微軟\ VisualStudio的### \一般

的EnableVSIPLogging設置爲1

Enable VSIPLogging registry key

然後,我可以通過按住CTRL + SHIFT並右鍵單擊它來確定Visual Studio中的任何菜單項或樹節點的GUID和ID。

enter image description here

從這個,我能夠確定與1283

命令ID,在服務器資源管理器中的頂級節點有{74D21310-2AEE-11D1-8BFB-00A0C90F26F7}的一個GUID在服務器瀏覽器

對象節點(如表,存儲過程,等等)有{d4f02a6a-c5ae-4bf2-938d-f1625bdca0e2}和33280(0x8200)一個指令id

對象節點父母在的一個GUID服務器資源管理器(例如靜態「表」,「存儲過程」,對對象節點進行分類的節點)具有{d4 f02a6a-c5ae-4bf2-938d-f1625bdca0e2}和命令ID 33024(0x8100)

因此,通過這些Guids,我現在可以將我的命令附加到我想要的位置。

我想要一個特定於單個表的命令,以及特定於數據庫中所有表的命令,因此我將使用d4f02a6a-c5ae-4bf2-938d-f1625bdca0e2,命令標識爲0x8200,Guid d4f02a6a-c5ae-4bf2-938d-f1625bdca0e2,命令ID爲0x8100。

接下來,我需要在我的VSIX項目我vsct文件來定義這些值,所以我把它們添加到符號部分:

VSCT symbols

我加2個命令項目,我的項目,然後我需要更改組的父,使他們在服務器資源管理器上正確的區域出現:

VSCT groups

現在,數據庫命令時出現的所有靜態對象的節點,即使我希望它只出現在「Tables」節點上,並且對於所有對象節點及其所有對象節點都會出現table命令,即使我希望它只出現在表節點本身中。我相信需要以某種方式在代碼中解決問題,動態確定命令菜單項的可見性,但是我必須單獨確定一個。

下面是整體的vsct:

<?xml version="1.0" encoding="utf-8"?> 
<CommandTable xmlns="http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

    <!-- This is the file that defines the actual layout and type of the commands. 
     It is divided in different sections (e.g. command definition, command 
     placement, ...), with each defining a specific set of properties. 
     See the comment before each section for more details about how to 
     use it. --> 

    <!-- The VSCT compiler (the tool that translates this file into the binary 
     format that VisualStudio will consume) has the ability to run a preprocessor 
     on the vsct file; this preprocessor is (usually) the C++ preprocessor, so 
     it is possible to define includes and macros with the same syntax used 
     in C++ files. Using this ability of the compiler here, we include some files 
     defining some of the constants that we will use inside the file. --> 

    <!--This is the file that defines the IDs for all the commands exposed by VisualStudio. --> 
    <Extern href="stdidcmd.h" /> 

    <!--This header contains the command ids for the menus provided by the shell. --> 
    <Extern href="vsshlids.h" /> 

    <!--The Commands section is where commands, menus, and menu groups are defined. 
     This section uses a Guid to identify the package that provides the command defined inside it. --> 
    <Commands package="guidCRUDSPCommandsPackage"> 
    <!-- Inside this section we have different sub-sections: one for the menus, another 
    for the menu groups, one for the buttons (the actual commands), one for the combos 
    and the last one for the bitmaps used. Each element is identified by a command id that 
    is a unique pair of guid and numeric identifier; the guid part of the identifier is usually 
    called "command set" and is used to group different command inside a logically related 
    group; your package should define its own command set in order to avoid collisions 
    with command ids defined by other packages. --> 

    <!-- In this section you can define new menu groups. A menu group is a container for 
     other menus or buttons (commands); from a visual point of view you can see the 
     group as the part of a menu contained between two lines. The parent of a group 
     must be a menu. --> 
    <Groups> 

     <!-- Table scope --> 
     <Group guid="guidCRUDSPCommandsPackageCmdSet1" id="TableMenuGroup" priority="0x0600"> 
     <!--<Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS" />--> 
     <Parent guid="guidServerExplorerObjectNode" id="IDMX_DV_OBJECT_NODE" /> 
     </Group> 

     <!-- Database scope --> 
     <Group guid="guidCRUDSPCommandsPackageCmdSet1" id="DatabaseMenuGroup" priority="0x0600"> 
     <!--<Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS" />--> 
     <Parent guid="guidServerExplorerObjectNode" id="IDMX_DV_STATIC_NODE" /> 
     </Group> 

    </Groups> 

    <!--Buttons section. --> 
    <!--This section defines the elements the user can interact with, like a menu command or a button 
     or combo box in a toolbar. --> 
    <Buttons> 
     <!--To define a menu group you have to specify its ID, the parent menu and its display priority. 
      The command is visible and enabled by default. If you need to change the visibility, status, etc, you can use 
      the CommandFlag node. 
      You can add more than one CommandFlag node e.g.: 
       <CommandFlag>DefaultInvisible</CommandFlag> 
       <CommandFlag>DynamicVisibility</CommandFlag> 
      If you do not want an image next to your command, remove the Icon node /> --> 

     <Button guid="guidCRUDSPCommandsPackageCmdSet1" id="cmdidCmdTable" priority="0x0100" type="Button"> 
     <Parent guid="guidCRUDSPCommandsPackageCmdSet1" id="TableMenuGroup" /> 
     <Icon guid="guidImages" id="bmpPic1" /> 
     <Strings> 
      <ButtonText>Command for Table</ButtonText> 
     </Strings> 
     </Button> 

     <Button guid="guidCRUDSPCommandsPackageCmdSet1" id="cmdidCmdDatabase" priority="0x0100" type="Button"> 
     <Parent guid="guidCRUDSPCommandsPackageCmdSet1" id="DatabaseMenuGroup" /> 
     <Icon guid="guidImages1" id="bmpPic1" /> 
     <Strings> 
      <ButtonText>Command for Database</ButtonText> 
     </Strings> 
     </Button> 
    </Buttons> 

    <!--The bitmaps section is used to define the bitmaps that are used for the commands.--> 
    <Bitmaps> 
     <!-- The bitmap id is defined in a way that is a little bit different from the others: 
      the declaration starts with a guid for the bitmap strip, then there is the resource id of the 
      bitmap strip containing the bitmaps and then there are the numeric ids of the elements used 
      inside a button definition. An important aspect of this declaration is that the element id 
      must be the actual index (1-based) of the bitmap inside the bitmap strip. --> 


     <Bitmap guid="guidImages" href="Resources\CmdTable.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough" /> 
     <Bitmap guid="guidImages1" href="Resources\CmdDatabase.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough" /> 
    </Bitmaps> 
    </Commands> 

    <Symbols> 
    <!-- {d4f02a6a-c5ae-4bf2-938d-f1625bdca0e2} is the object node in the server explorer --> 
    <GuidSymbol name="guidServerExplorerObjectNode" value="{d4f02a6a-c5ae-4bf2-938d-f1625bdca0e2}"> 
     <!--server explorer - table--> 
     <IDSymbol name="IDMX_DV_OBJECT_NODE" value="0x8200" /> 
     <IDSymbol name="IDMX_DV_STATIC_NODE" value="0x8100" /> 
    </GuidSymbol> 

    <!-- {74D21310-2AEE-11D1-8BFB-00A0C90F26F7} is the server explorer --> 
    <GuidSymbol name="guidServerExplorer" value="{74D21310-2AEE-11D1-8BFB-00A0C90F26F7}"> 
     <!--server explorer - table--> 
     <IDSymbol name="IDMX_DV_SERVER_NODE" value="0x503" /> 
    </GuidSymbol> 

    <!-- This is the package guid. --> 
    <GuidSymbol name="guidCRUDSPCommandsPackage" value="{a71670bc-ef23-40a3-b8a0-ed872b79476c}" /> 

    <!-- Constants--> 
    <GuidSymbol value="{946311de-35f2-4379-84e2-91867976faf8}" name="guidCRUDSPCommandsPackageCmdSet1"> 
     <IDSymbol value="256" name="cmdidCmdTable" /> 
     <IDSymbol value="257" name="cmdidCmdDatabase" /> 
     <IDSymbol value="258" name="TableMenuGroup" /> 
     <IDSymbol value="259" name="DatabaseMenuGroup" /> 
    </GuidSymbol> 

    <GuidSymbol value="{679ecb35-41d9-4021-933b-ec6b25afc100}" name="guidImages"> 
     <IDSymbol name="bmpPic1" value="1" /> 
     <IDSymbol name="bmpPic2" value="2" /> 
     <IDSymbol name="bmpPicSearch" value="3" /> 
     <IDSymbol name="bmpPicX" value="4" /> 
     <IDSymbol name="bmpPicArrows" value="5" /> 
     <IDSymbol name="bmpPicStrikethrough" value="6" /> 
    </GuidSymbol> 

    <GuidSymbol value="{9392ca3d-3400-4b7a-a691-7108032249cd}" name="guidImages1"> 
     <IDSymbol name="bmpPic1" value="1" /> 
     <IDSymbol name="bmpPic2" value="2" /> 
     <IDSymbol name="bmpPicSearch" value="3" /> 
     <IDSymbol name="bmpPicX" value="4" /> 
     <IDSymbol name="bmpPicArrows" value="5" /> 
     <IDSymbol name="bmpPicStrikethrough" value="6" /> 
    </GuidSymbol> 
    </Symbols> 
</CommandTable> 
+0

感謝您的分享,如果已解決,您可以將其標記爲答案。祝你今天愉快。 –

+0

您如何能夠訪問MenuItemCallback函數中每個對象的數據? – user2531854

+0

我還沒有能夠,那就是我的項目所在,因爲我需要能夠訪問底層數據,或者以某種方式確定該節點代表什麼表。 – Jeremy

相關問題