I am building my first VS extension, so my current skills in this area amount to following tutorials and asking questions. The extension is for encrypting/decryption a section of the web.config file of a web app project. I have 2 commands, and currently the buttons are set up in the .vsct file as follows:
<Buttons>
<Button guid="guidEncryptConfigCommandPackageCmdSet" id="EncryptConfigCommandId" priority="0x0100" type="Button">
<Parent guid="guidEncryptConfigCommandPackageCmdSet" id="MyMenuGroup" />
<Strings>
<ButtonText>Encrypt Mail Settings</ButtonText>
</Strings>
</Button>
<Button guid="guidEncryptConfigCommandPackageCmdSet" id="cmdidDecryptConfigCommand" priority="0x0100" type="Button">
<Parent guid="guidEncryptConfigCommandPackageCmdSet" id="MyMenuGroup" />
<Strings>
<ButtonText>Decrypt Mail Settings</ButtonText>
</Strings>
</Button>
</Buttons>
This gives me 2 buttons in the Tools menu, as follows:
Encrypt Mail Settings
Decrypt Mail Settings
I would like to have just one top level button in the Tools menu, with 2 nested buttons, one for each operation, e.g:
Config Encryptor
...Encrypt Mail Settings
...Decrypt Mail Settings
How do I achieve the outcome I am looking for?
Related documents about this issue:
Add submenu to menu, Add menu to menu bar, GUIDs and IDs for the VS Menus.
What we want:
Click the Tools menu in VS=>display Config Encryptor submenu, Click the Config Encryptor menu will display Encrypt Mail Settings and Decrypt Mail Settings commands.
The structure in my xx.vsct:
Tools menu in IDE
--SubMenuGroup
--SubMenu1
--ButtonsGroup
--EncryptConfigCommandId(Encrypt Mail Settings)
--DecryptConfigCommandId(Decrypt Mail Settings)
The real content in Commands section:
<Commands package="guidEncryptConfigCommandPackage">
<Menus>
<Menu guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenu1" priority="0x0100" type="Menu">
<Parent guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenuGroup"/>
<Strings>
<ButtonText>Config Encryptor</ButtonText>
<CommandName>Config Encryptor</CommandName>
</Strings>
</Menu>
</Menus>
<Groups>
<Group guid="guidEncryptConfigCommandPackageCmdSet" id="ButtonsGroup" priority="0x0600">
<Parent guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenu1"/>
</Group>
<Group guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenuGroup" priority="0x0600">
<Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS"/>
</Group>
</Groups>
<Buttons>
<Button guid="guidEncryptConfigCommandPackageCmdSet" id="EncryptConfigCommandId" priority="0x0100" type="Button">
<Parent guid="guidEncryptConfigCommandPackageCmdSet" id="ButtonsGroup" />
<Icon guid="guidImages" id="bmpPic1" />
<Strings>
<ButtonText>Encrypt Mail Settings</ButtonText>
</Strings>
</Button>
<Button guid="guidEncryptConfigCommandPackageCmdSet" id="DecryptConfigCommandId" priority="0x0110" type="Button">
<Parent guid="guidEncryptConfigCommandPackageCmdSet" id="ButtonsGroup" />
<Icon guid="guidImages" id="bmpPic1" />
<Strings>
<ButtonText>Decrypt Mail Settings</ButtonText>
</Strings>
</Button>
</Buttons>
<!--The bitmaps section is used to define the bitmaps that are used for the commands.-->
<Bitmaps>
<Bitmap guid="guidImages" href="Resources\EncryptConfigCommand.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough"/>
</Bitmaps>
</Commands>
And don't forget to define the IDSymbol in GuidSymbol:
<!-- This is the guid used to group the menu commands together -->
<GuidSymbol name="guidEncryptConfigCommandPackageCmdSet" value="{70c1a496-88b4-4c83-8539-39decdbdb8fb}">
<IDSymbol name="ButtonsGroup" value="0x1020" />
<IDSymbol name="EncryptConfigCommandId" value="0x0100" />
<IDSymbol name="DecryptConfigCommandId" value="0x0110" />
<IDSymbol name="SubMenu1" value="0x1100"/>
<IDSymbol name="SubMenuGroup" value="0x1150"/>
</GuidSymbol>
According to these three document above:
1.We can add submenu to an existing menu or custom menu according to the first document.Not clearly described in documents how to structure the button, menu, group and what's the relationship between them, but check the content in its code we can find 1. To add a submenu to Tools menu, we need to set a group as its parent, then sets the Tools menu as its parent.
2.And to group two buttons to a submenu, we need to set the two buttons's parent as GroupB, then set the SubMenu as GroupB's parent.
3.According to third document, the menus and groups on the Visual Studio menu bar use the GUID guidSHLMainMenu. And the ID of Tools menu is IDM_VS_MENU_TOOLS.
That's why I edit the content in this structure, luckily it works. And since I may misunderstand something in the documents, if there's something wrong or something can be better feel free to correct me:)
The appearance when debugging:
In addition:
1.About managing the handler of the commands see this.
2.See this document which indicates to add submenu to another VS menu, we need a a group in this process.
To add a group to an existing Visual Studio menu, set one of the following menus as its parent.
You need to create Menu for your buttons
<Menus>
<Menu guid="guidEncryptConfigCommandPackageCmdSet" id="ConfigEncryptorMenu" priority="0x0100" type="Menu">
<Parent guid="guidEncryptConfigCommandPackageCmdSet" id="ConfigEncryptorMenuGroup"/>
<Strings>
<MenuText>Config Encryptor</MenuText>
<ButtonText>Config Encryptor</ButtonText>
<CommandName>Config Encryptor</CommandName>
</Strings>
</Menu>
</Menus>
And set parents for Group
<Group guid="guidEncryptConfigCommandPackageCmdSet" id="ConfigEncryptorMenuGroup" priority="0x0100">
<Parent guid="guidEncryptConfigCommandPackageCmdSet" id="ConfigEncryptorMenu"/>
</Group>
<Group guid="guidEncryptConfigCommandPackageCmdSet" id="ConfigEncryptorMenu" priority="0x0200">
<Parent guid="guidEncryptConfigCommandPackageCmdSet" id="ToolsMenu"/>
</Group>
Also don't forget to add IDSymbol for Group and GroupMenu
and set correct name for Tools id="ToolsMenu"
Related
I'm creating an extension for Visual Studio 2010.
The extension is made available to the user via a button in the Debug-menu of VS.
The button is defined as follows in the VSCT file:
<Button guid="guidRTKDebuggerCmdSet" id="cmdidRtkDebug" priority="0x0300" type="Button">
<Parent guid="guidVSDebugGroup" id="IDG_EXECUTION" />
<Icon guid="guidImages" id="bmpPic1" />
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<CommandName>cmdidRtkDebug</CommandName>
<ButtonText>My Debug Extension</ButtonText>
</Strings>
</Button>
How would I make the button disappear when the debugger starts? All other debug buttons in Visual Studio show exactly this behavior, but my button remains visible all the time.
You need to use VisibilityConstraints (see http://msdn.microsoft.com/en-us/library/bb166229.aspx) and list all needed contexts except UICONTEXT_Debugging (see http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.vsconstants.aspx).
<VisibilityConstraints>
<VisibilityItem guid="guidRTKDebuggerCmdSet" id="cmdidRtkDebug"
context="UICONTEXT_SolutionHasSingleProject" />
<VisibilityItem guid="guidRTKDebuggerCmdSet" id="cmdidRtkDebug"
context="UICONTEXT_SolutionHasMultipleProjects" />
</VisibilityConstraints>
i'm developing a Visual Studio 2010 extension, i already have a toolbar inside my window. on that toolbar i have a button that i want to give an icon - my own icon!
I've read this article and it is great but... it explains how to replace the icons.
i want to add an additional icon.
how do i achieve that?
First, add the bitmap and set its build action to Resource
Remember, shocking pink = transparent (damn you, old school!)
Then, in your vsct file, add the image to the bitmaps section
<Bitmaps>
<Bitmap guid="AddSampleData.bmpGuid"
href="..\Button Bitmaps\AddSampleData.bmp"
usedList="AddSampleData.bmpId" />
<Bitmap guid="ApplySampleData.bmpGuid"
href="..\Button Bitmaps\ApplySampleData.bmp"
usedList="ApplySampleData.bmpId" />
</Bitmaps>
and assign it a guid in the symbols node
<Symbols>
<!-- snip -->
<GuidSymbol name="AddSampleData.bmpGuid"
value="{dcae7c84-8e91-4f8a-907b-95ccb0f52e6e}">
<IDSymbol name="AddSampleData.bmpId"
value="1" />
</GuidSymbol>
<GuidSymbol name="ApplySampleData.bmpGuid"
value="{9f555245-2430-4e6f-992b-b49ce87a31a2}">
<IDSymbol name="ApplySampleData.bmpId"
value="1" />
</GuidSymbol>
</Symbols>
and apply it to a button
<Buttons>
<!-- snip -->
<Button guid="guidEditorExtensionCommandSet"
id="setDesignTimeDataOnPage"
priority="0x0100">
<Icon guid="ApplySampleData.bmpGuid"
id="ApplySampleData.bmpId" />
<Strings>
<!-- snip -->
</Strings>
</Button>
</Buttons>
Of course, its always easier to use the available tools, including the excellent VSPackage Builder extension.
A workaround for this is to create a PNG and rename the extension as *.bmp. VS will accept it as an icon image and it will also have transparency (from Visual Studio Extensibility > Toolbox Icons -- Is transparency supported?)
I'm having a simple preference pane for Firefox Extension as follows:
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<prefwindow title="Preferences"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<preferences>
<preference id="extensions.autofc.signalSuccess" name="extensions.autofc.signalSuccess" type="bool"/>
<preference id="extensions.autofc.dpair" name="extensions.autofc.dpair" type="string"/>
</preferences>
<prefpane label="Preferences">
<checkbox preference="extensions.autofc.signalSuccess" label="Tell me if everything is okay"/>
<label value="NOTE: Errors are always alerted"/>
<html:hr />
<hbox align="center">
<label value="Pair Options" />
<groupbox>
<radiogroup preference="extensions.autofc.dpair">
<radio label="Pair 1" value="ee"/>
<radio label="Pair 2" value="ev"/>
</radiogroup>
</groupbox>
</hbox>
</prefpane>
</prefwindow>
This works perfectly on Linux, meaning users can tick or untick the checkbox or select radio buttons, click Okay and when the Preference is opened again, the latest selections are saved.
What amazed me was that when this was tested on Windows, the selections are not saved, i.e., when opening Preference Pane again, the selections return to the default values.
One thing I've supposed was that the selections in this preference Pane are handled by Firefox but I may be wrong.
Do you guys have any insights on why this doesn't work on Windows. In particular, it didn't work on FF 3.6.1, FF 8, FF 7.0.1 on Windows 7.
You should place <preferences> inside <prefpane>, not <prefwindow>.
We have an add in for VS that currently is launched from the tools menu, the add-in consists of a a UI offering the user a few option buttons, which I now want to convert to a top-level menu that would offer the same functionality.
I've read this tutorial, which helped me add a new top-level menu, but couldn't really understand the logic behind all the steps. The guide doesn't really clear what each of the steps create or how can your change the output.
What the steps create is a new top-level menu with a single item underneath it. I'm trying to create some hierarchy in my menu (i.e. Top Level -> Sub category -> Commands) but got abit lost with all the groups/menus/IDs structure.
Is there any clear explanation for the structure of these files? A documentation or a tutorial? If anyone had experience in the subject and could help clear things up I would much appreciate it...
I haven't tried doing hierarchical menu items, but I have had similar problems with the Visual SDK .vcst file. It is a pain. A couple of things you can do.
Install the VS Package Editor to Visual Studio Blog Entry for it: http://blogs.msdn.com/b/visualstudio/archive/2010/09/08/introducing-the-vspackage-builder.aspx
Download source code (open source so you can see how they do it) for an add-in that does similar things. Example is AnkhSVN which is a Subversion Repository Add-in to Visual Studio. Here is the source code: http://ankhsvn.open.collab.net/source/browse/ankhsvn/
I assume that nowadays by "add-in" you mean an extension that is a VS package (using the VS SDK) because an "add-in" was an older form of extension for VS 2013 and lower. (If you really mean an "add-in" then see my sample HOWTO: Adding buttons, commandbars and toolbars to Visual Studio .NET from an add-in)
Packages use .vsct files. To answer your question, see the .vsct files of my samples here:
CommandTopMenu
CommandSubMenu
(and to learn see also the other ones for context menus, toolbars, etc.). In the .vcst file they use "CommandPlacements" to separate the definition of an item from its "placement", and comments to explain the relationship between the 3 kinds of items:
Menus (Main-menu/Top-menus/Sub-menus/Context menus) and Toolbars.
Groups: a group is a container for other groups and also for commands and sub-menus.
Commands
Remember the rules:
The parent of a top-menu is always the Main menu of VS, never a group
The parent of a sub-menu is always a group, never directly a toolbar or any kind of menu.
The parent of a command is always a group, never directly a toolbar or any kind of menu (same rule that for sub-menus)
The parent of a group can be a menu, a toolbar, a context menu, etc. and it can be also another group.
A menu (any kind) or toolbar can be either created by your extension (except the main menu of VS) or an existing one of VS, identified by prefix "IDM_". See GUIDs and IDs of Visual Studio menus and GUIDs and IDs of Visual Studio toolbars.
A group can be either new (created by your extension) or an existing group of Visual Studio, identified by prefix "IDG_". You have some built-in Visual Studio groups in the links above, but for a more exhaustive list install the ExtensionTools extension (Mads Kristensen) that provides intellisense in the .vsct file or check the source code of its VsctBuiltInCache.cs file.
Code example
<?xml version="1.0" encoding="utf-8"?>
<CommandTable xmlns="...">
<!-- Extern section unchanged -->
<Commands package="guidHowToPackagePkg">
<Menus>
<!-- New menu added -->
<Menu guid="guidBasicVSCTSampleCmdSet" id="SubMenu" priority="0x200"
type="Menu">
<Parent guid="guidBasicVSCTSampleCmdSet" id="TopLevelMenuGroup" />
<Strings>
<ButtonText>Other Commands</ButtonText>
<CommandName>Other Commands</CommandName>
</Strings>
</Menu>
</Menus>
<Groups>
<!-- Group changed to SubMenuGroup and attached to SubMenu -->
<Group guid="guidBasicVSCTSampleCmdSet" id="SubMenuGroup"
priority="0x0600">
<Parent guid="guidBasicVSCTSampleCmdSet" id="SubMenu"/>
</Group>
</Groups>
<Buttons>
<!-- We attached these two buttons to SubMenuGroup -->
<Button guid="guidBasicVSCTSampleCmdSet" id="ThirdCommand" priority="0x0100"
type="Button">
<Parent guid="guidBasicVSCTSampleCmdSet" id="SubMenuGroup" />
<Icon guid="guidImages" id="bmpPicX" />
<Strings>
<CommandName>ThirdCommand</CommandName>
<ButtonText>Third Command</ButtonText>
</Strings>
</Button>
<Button guid="guidBasicVSCTSampleCmdSet" id="FourthCommand"
priority="0x0101" type="Button">
<Parent guid="guidBasicVSCTSampleCmdSet" id="SubMenuGroup" />
<Icon guid="guidImages" id="bmpPicArrows" />
<Strings>
<CommandName>FourthCommand</CommandName>
<ButtonText>Fourth Command</ButtonText>
</Strings>
</Button>
</Buttons>
</Commands>
<Symbols>
<!-- We add a SubMenu and changed SubMenuGroup -->
<GuidSymbol name="guidBasicVSCTSampleCmdSet" value="...">
<IDSymbol name="SubMenu" value="0x0101" />
<IDSymbol name="SubMenuGroup" value="0x0201" />
</GuidSymbol>
</Symbols>
</CommandTable>
This provides you with the following top-level menu:
Here's a full chapter on the topic. This pretty much explains everything there is to know on (hierarchical) menu's.
http://dotneteers.net/blogs/divedeeper/archive/2010/05/23/vs-2010-package-development-chapter-2-commands-menus-and-toolbars.aspx
I have a VS2010 VSIP package with several commands,Those commands are added to the javascript editor's context menu,and i am using
<Group guid="guidPrettyJsCmdSet" id="ContextMenuGroup" priority="0x0600">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_CODEWIN"/>
</Group>
but it work only C# file,how to make it work for .js file?
The HTML/CSS/JS code editors actually show different context menus than the main code editor. Unfortunately, the Guid/ID pairs for these context menus aren't published or defined in the Visual Studio SDK.
However, there is a debug hook (since VS 2005 SP1) that lets you identify the Guid/ID of almost any menu item you could be interested in. See this blog post for how to do that.
Using the technique described in that post, if I CTRL+SHIFT+RIGHTCLICK in the Javascript editor, I get the following dialog:
In the <Symbols> section of my VSCT file, I can put the following:
<GuidSymbol name="htmlEditorCommandSet" value="{D7E8C5E1-BDB8-11D0-9C88-0000F8040A53}">
<IDSymbol name="jsContextMenu" value="0x0034"/> <!-- 52 in hex is 0x0034 -->
</GuidSymbol>
Then, it's just a matter of parenting to that Guid/ID:
<Group guid="guidPrettyJsCmdSet" id="ContextMenuGroup" priority="0x0600">
<Parent guid="htmlEditorCommandSet" id="jsContextMenu"/>
</Group>