Figure 1 Partial List of IDE Extensibility Objects
Category | Object | Windows | Toolbars Task window Command window Output windows | Documents | Text selections Edit points | IDE Items | Status bar AddIns Source Control | Debugger | Breakpoints Processes Threads | Projects | Files Settings Configuration manager | Code Models | Types Namespaces Structs Interfaces Classes Enums Variables Functions Parameters | Figure 2 IDE Events
Event | Description | DTEEvents | IDE modes shift from designing to debugging | DocumentEvents | Documents opening, closing, beginning to be saved | WindowEvents | Windows opening, closing, activating, or moving | TaskListEvents | Tasks added, modified, and removed | FindEvents | Find in files finished | OutputWindowEvents | Output panes added, cleared, or updated | SelectionEvents | Selected text changes | BuildEvents | Builds and configuration started or finished | SolutionEvents | Solution opened or closed, or projects added, removed, or renamed | ProjectItemsEvents | Items added, removed, or renamed | DebuggerEvents | Exception thrown, exception not handled, context change, or break mode change | Figure 3 Properly Removing Commands Before Adding Them private void RemoveCommandsAndCommandBars ( )
{
// Get the commands collection.
Commands Cmds = m_ApplicationObject.Commands ;
// Look through each of the commands and delete the ones I
// add. Keep in mind this is only going to run just the
// first time you load this add-in. After that you have
// them.
foreach ( Command CmdDel in Cmds )
{
if ( ( CmdDel.Name == ResConstant.StripTWSSaveFullCommand )||
( CmdDel.Name == ResConstant.StripTWSSaveAllFullCommand)||
( CmdDel.Name == ResConstant.AutoSaveSetupFullCommand ) )
{
try
{
CmdDel.Delete ( ) ;
}
catch ( System.Exception )
{
}
}
}
}
private void DoInitialCommandSetup ( )
{
try
{
// Get the commands collection.
Commands Cmds = m_ApplicationObject.Commands ;
// Get the command bars collection.
_CommandBars CommandBars =
m_ApplicationObject.CommandBars ;
// To make my development life easier, I'm going to
// assume that the commands might already have been
// added to this instance of Visual Studio. Therefore, before I
// add them, I'll attempt to delete each one. This way,
// it will be much easier to continue to add commands
// from this add-in as I develop it.
RemoveCommandsAndCommandBars ( ) ;
// Allocate an empty context GUID array.
object []ContextGUIDS = new object[] { } ;
// Now I can add my commands. Safely. If anything
// throws here, it's something really serious!
int DisFlags = (int)vsCommandStatus.vsCommandStatusSupported +
(int)vsCommandStatus.vsCommandStatusEnabled ;
Command Cmd = null ;
// Add the StripTrailingWhiteSpaceSave command.
Cmd =
Cmds.AddNamedCommand ( m_AddInInstance ,
ResConstant.StripTWSSave ,
ResConstant.StripTWSSaveButtonText ,
ResConstant.StripTWSSaveToolTip ,
false ,
ResConstant.StripTWSBitmapID ,
ref ContextGUIDS ,
DisFlags ) ;
// Add the StripTrailingWhiteSpaceSaveAll command.
Cmd =
Cmds.AddNamedCommand ( m_AddInInstance ,
ResConstant.StripTWSSaveAll ,
ResConstant.StripTWSSaveAllButtonText,
ResConstant.StripTWSSaveAllToolTip ,
false ,
ResConstant.StripTWSAllBitmapID ,
ref ContextGUIDS ,
DisFlags ) ;
// Add the AutoSaveSetup command.
Cmd =
Cmds.AddNamedCommand ( m_AddInInstance ,
ResConstant.AutoSaveSetup ,
ResConstant.AutoSaveSetupButtonText,
ResConstant.AutoSaveSetupToolTip ,
false ,
ResConstant.AutoSaveSetupBitmapID,
ref ContextGUIDS ,
DisFlags ) ;
}
catch ( System.Exception eEx )
{
MessageBox.Show ( eEx.Message + "\r\n" +
eEx.StackTrace.ToString ( ) ,
"Exception in DoInitialCommandSetup" ) ;
}
}
|