I've got a control that I've added to the Commandbar for the code
window, and I'm trying to set the enabled state based on the selection
(or active point) for the current ActiveDocument. If the currently
selection is valid by some parameters, the control's enabled state will
be true, otherwise it will be false.
What I really want to do is have an event to fire before the commandbar
is shown, so that I can check where the selection is, see if it is
valid, and enable/disable the control before the commandbar is
presented to the user. I believe this same kind of functionality
occurs in addins like GhostDoc and Resharper - modifying enabled states
based on context.
Here is the code I'm working with now:
public void OnConnection(object application, ext_ConnectMode
connectMode, object addInInst, ref Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
// Get the CommandBar for the window in which you want to add the
menuitem. I am going to add it to the code window.
CommandBar commandBar = (_applicationObject.CommandBars as
CommandBars)["Code Window"];
// create a control
CommandBarControl gotoDeclarationControl = commandBar.Controls.Add(
MsoControlType.msoControlButton,
System.Reflection.Missing.Value, System.Reflection.Missing.Value, 1,
true);
gotoDeclarationControl.Caption = "Go to Declaration";
// add click handler for control
mGotoDeclarationItemHandler =
_applicationObject.Events.get_CommandBarEvents(gotoDeclarationControl)
as CommandBarEvents;
mGotoDeclarationItemHandler.Click += new
_dispCommandBarControlEvents_ClickEventHandler(mGotoDeclarationItemHandler_Click);
}
Anyone have any advice and/or a pointer to some relevant documentation?