I'm trying to make a plugin that captures the edit.copy
command of visual studio, and skips it if nothing is selected.
I have installed the Visual Studio SDK and created a VSPackage project. My initialize method curently looks like the following:
private EnvDTE.DTE m_objDTE = null;
protected override void Initialize()
{
Debug.WriteLine (string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
base.Initialize();
m_objDTE = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));
m_objDTE.Events.CommandEvents.BeforeExecute += (
string Guid,
int ID,
Object CustomIn,
Object CustomOut,
ref bool CancelDefault
) =>
{
EnvDTE.Command objCommand;
string commandName = "";
objCommand = m_objDTE.Commands.Item(Guid, ID);
if (objCommand != null)
{
commandName = objCommand.Name;
if (string.IsNullOrEmpty(commandName))
{
commandName = "<unnamed>";
}
}
Debug.WriteLine("Before executing command with Guid=" + Guid + " and ID=" + ID + " named " + commandName);
};
}
The Initialize()
method is called when a solution is opened, I have the [ProvideAutoLoad(UIContextGuids80.SolutionExists)]
tag added to my package. But the BeforeExecute is not called when I do things, like pressing ctrl + c
which is a command, With this code I expect all commands to be printed in the debug console, why isn't this happening?
Here is the code I used that works: