> I want to add a new item to the Solution Explorer context menu
> immediately before the "Properties" item. I think I have most of the
[quoted text clipped - 3 lines]
> languages (can someone confirm this) but how do I locate "Properties"
> itself (presumably each item has a unique ID but where is this).
CommandBar.Name does not change in other languages but CommandBar.NameLocal
does. However, there's no guarantee that CommandBar.Name is unique between
other CommandBars. In fact, several CommandBars have the same name. Fortunately,
in this case ("Solution" & "Project"), you should be ok.
There really isn't a unique ID for CommandBarControls. CommandBarControl.Id
doesn't seem to be the same between VS 2003/2005 and I'm pretty certain that
CommandBarControl.InstanceId is just a pointer to some internal structure.
The trick to determining the differenece between built-in Visual Studio CommandBarControls
from within an add-in is to use the DTE.Commands.CommandInfo() method and
pass your CommandBarControl into it. This will return the guid:id pair for
the command that this CommandBarControl is linked (a full list of these can
be found in the header files that ship with the Visual Studio SDK).
Armed with this knowledge, you can find the Properties CommandBarControl
using code like this:
public void OnConnection(object application, ext_ConnectMode connectMode,
object addInInst, ref Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
CommandBars commandBars = (CommandBars)_applicationObject.CommandBars;
CommandBar solutionBar = commandBars["Solution"];
Commands commands = _applicationObject.Commands;
foreach (CommandBarControl control in solutionBar.Controls)
{
string guid;
int id;
commands.CommandInfo(control, out guid, out id);
if (id == 397 && String.Compare(guid, "{5EFC7975-14BC-11CF-9B2B-00AA00573819}",
true) == 0)
{
System.Diagnostics.Debug.WriteLine("Found it!");
break;
}
}
}
This works ok -- if a bit flimsy. The preferred way to add menu items is
with a via Visual Studio package where you have better control.
Best Regards,
Dustin Campbell
Developer Express Inc.
Michael Chambers - 22 Sep 2006 20:35 GMT
Thanks very much for the info (appreciated). I'll take some time to digest
it and post back if I have any further questions. Thanks again.