Hi Notre,
The Priority Command Target is probably your best bet. Though there are
some instances, like when you pass a specific IOleCommandTarget to
IVsUIShell.ShowContext menu for example, where even a priority command
target wouldn't get said command.
Setting up a priority command target isn't something that we want to see a
lot of people using though, as it can lead to performance and behavioral
issues if abused. Use the SVsRegisterPriorityCommandTarget service. It's
undocumented, but there are some good comments in the vsshell.idl that
detail this service.
Personally, you might want to consider using the DTE automation model to
hook the CommandEvents.OnBeforeExecute event. This should allow you to
intercept even those pesky context menu commands.
Sincerely,
Ed Dore [MSFT]
This post is 'AS IS' with no warranties, and confers no rights.
Notre Poubelle - 28 Sep 2005 00:32 GMT
Okay, I wondered about using the DTE automation model from my package. The
way I read the documentation was that Addins get first crack at command
routing, but it sounds like any automation client, such as my package could
subscribe with the same priority as the addin..?
"Ed Dore [MSFT]" - 28 Sep 2005 18:09 GMT
Hi Notre,
That's correct. You can leverage the DTE automation model by calling
QueryService on the IOleServiceProvider initially passed to your package's
SetSite implementation. For managed packages, this just means calling the
package's GetService method with typeof(_DTE) to retieve the _DTE interface.
http://blogs.msdn.com/dr._ex/archive/2004/03/09/86972.aspx
http://www.codecomments.com/archive358-2005-9-596368.html
Sincerely,
Ed Dore [MSFT]
This post is 'AS IS' with no warranties, and confers no rights.
Notre Poubelle - 29 Sep 2005 20:52 GMT
Hooking into the CommandEvents worked great. I had some trouble at first as
my event handlers were not firing, but I noticed some other posts where
others had trouble and it turned out that my event handlers were being
garbage collected.
I will use this approach, rather than the priority command target. Thanks!