Reputation: 2555
I am building my first Visual Studio extension, and now that I am nearing the end I am just trying to make it look a little better. I have my own heading in the top menu with items in it. I would like to add a separator to the menu to make it neater, but can't figure out how to do so.
The separator I am talking about is the line that goes across menus/context menus to separate the items.
I am geussing it will have to be added to the xml in the vsct file but incase it's relevant the add-in is in C#.
I can't really find much on this at all, so I am hoping someone can help me out.
EDIT:I seemed to have figured out my issue. After looking around EVERYWHERE, I got the idea to try putting a couple of the menu items into a different group in the XML vsct file..and VOILA! I now have a cool separator. So the answer is that it is automatically added to separate groups, and it cannot be done by code(or so I think). Remember Extensions don't use C# or VB to add menu items, only add-ins do. Extensions use XML.
Upvotes: 4
Views: 3976
Reputation: 340
A separator is a visual separation of command groups defined in a .vsct file.
A command group is a logical container for commands belonging together. This kind of grouping also can be used for visual effects.
If you put more than one command group in a menu, a separator is created to visually emphasize the separation of command groups.
To learn more about .vsct files look at: http://dotneteers.net/blogs/divedeeper/archive/2008/03/02/LearnVSXNowPart14.aspx
Upvotes: 4
Reputation: 2817
In .vcts, Commands
section is responsible for that functionality. On order to do sthm with menus dynamically you may realise IVsShellPropertyEvents
interface and do your logic in OnShellPropertyChange
method
public int OnShellPropertyChange(int propid, object propValue)
{
// --- We handle the event if zombie state changesfrom true to false
if ((int)__VSSPROPID.VSSPROPID_Zombie == propid)
{
if ((bool)propValue == false)
{
// --- Show the commandbar
EnvDTE80.DTE2 dte = GetService(typeof(DTE)) as DTE2;
CommandBar cb = ((dte.CommandBars as CommandBars)["YourCommandBar"] as CommandBar);
foreach (CommandBarControl cbc in cb.Controls)
{
if (cbc.Caption == "YourCaption")
{
CommandBarButton btn = (CommandBarButton)cbc;
btn.BeginGroup = true; // HERE WE ADD NEW GROUP - means add separator
}
}
}
// --- Unsubscribe from events
var shellService = GetService(typeof(SVsShell)) as IVsShell;
if (shellService != null)
{
ErrorHandler.ThrowOnFailure(shellService.UnadviseShellPropertyChanges(_EventSinkCookie));
}
_EventSinkCookie = 0;
}
return VSConstants.S_OK;
}
Upvotes: 0
Reputation: 3081
Not sure how you're creating the menu, but if you're using the MenuItem
class, you can pass "-"
to its constructor to create a separator.
MenuItem separator = new MenuItem("-");
Upvotes: -3
Reputation: 1678
From here: http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/f26acf64-0ee6-4947-84e4-a7a0ded9d636
It looks like this is the code, but honestly I have no idea.
'Me.AddSeparatorLine(generateCodeCommandBarPopup, 3)
CType(cmnd_GenerateListDetailFormCode.AddControl(generateCodeCommandBarPopup.CommandBar, 3),CommandBarButton).BeginGroup = True
This also looks like it might be useful: http://www.mztools.com/articles/2005/MZ2005003.aspx
Upvotes: 0