Adding a delimiter to a Visual Studio extension menu

I'm building my first Visual Studio extension, and now that I'm nearing the end, I'm just trying to make it a little better. I have my own header in the top menu with items in it. I would like to add a separator to the menu to make it tidier, but I can't figure out how.

The delimiter I'm talking about is a line that crosses menus / context menus to separate items.

I want it to be added to the xml in the vsct file, but if appropriate the add-in is in C #.

I can't really find much, so I hope someone can help me.

EDIT: I seemed to figure out my problem. After looking around EVERYONE I got the idea to try putting a couple of menu items in a different group in the vsct XML file .. and VOILA! Now I have a cool separator. So the answer is that it is automatically added to the individual groups and it cannot be done with code (or I think it is). Remember, extensions don't use C # or VB to add menu items, only add-ins. The extensions use XML.

+3


source to share


4 answers


A delimiter is a visual separation of command groups defined in the .vsct file.

A group of commands is a logical container for commands that belong to each other. This grouping can also be used for visual effects.



If you place multiple commands on a menu, a separator is created to visually emphasize the separation of command groups.

To learn more about .vsct files see: http://dotneteers.net/blogs/divedeeper/archive/2008/03/02/LearnVSXNowPart14.aspx

+1


source


From here: http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/f26acf64-0ee6-4947-84e4-a7a0ded9d636

It looks like this is code, but honestly I have no idea.



'Me.AddSeparatorLine(generateCodeCommandBarPopup, 3)   
CType(cmnd_GenerateListDetailFormCode.AddControl(generateCodeCommandBarPopup.CommandBar, 3),CommandBarButton).BeginGroup = True 

      

It also looks like it might be useful: http://www.mztools.com/articles/2005/MZ2005003.aspx

0


source


The .vcts is Commands

responsible for this functionality. In order to dynamically work with files using the menu, you can implement the interface IVsShellPropertyEvents

and execute your logic in the methodOnShellPropertyChange

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;
    }

      

0


source


Not sure how you create the menu, but if you are using a class MenuItem

you can pass "-"

it to the constructor to create the separator.

MenuItem separator = new MenuItem("-");

      

-2


source







All Articles