Here's some sample C# code showing how to intercept DTE commands. _dispCommandEvents_BeforeExecuteEventHandler has a parameter that allows you to cancel execution of the command if that is what you want to do.
private EnvDTE.CommandEvents mCommandNewProject;
// set up events for IDE commands
cmd = DTE.Commands.Item("File.NewProject", -1);
mCommandNewProject = mDTE.Events.get_CommandEvents(cmd.Guid, cmd.ID);
mCommandNewProject.AfterExecute += new EnvDTE._dispCommandEvents_AfterExecuteEventHandler(CommandNewProject_AfterExecute);
...
Here's the related event handler
// handler for after a new project is opened in the IDE
void CommandNewProject_AfterExecute(string Guid, int ID, object CustomIn, object CustomOut)
{
//…
}
There is no way to suppress the DTE message box which says that the user is attempting to edit a read-only file.
For more information, see this post in Melody's blog.
Posted
May 28 2009, 01:32 PM
by
BillL