Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / Extensibility / September 2005

Tip: Looking for answers? Try searching our database.

Command routing question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Notre Poubelle - 28 Sep 2005 00:01 GMT
Hi,

I'm writing a package and I'd like to intercept some commands that are
executed from menus created by another package.  I understand from some VS
architecture discussion that commands are normally routed to the package that
defines the command and that not every command is routed to every package.  
It's stated that it is possible to override this behaviour with a priority
command target so that my package can override other packages.  I don't want
to change the behaviour of the other package; I just wanted to be notified
when a command is executed and add my own custom behaviour (along with do
what the owner package does).

Is a priority command target the way to go?  How would I go about doing this?

Thanks,
Notre
"Ed Dore [MSFT]" - 28 Sep 2005 00:17 GMT
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!

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.