locked
Changing commands vsCommandStatus RRS feed

  • Question

  • Hi there,

    I have a trivial case. I have a command which is created disabled (using AddNamedCommand2, without vsCommandStatus.vsCommandStatusEnabled flag set) and when the solution is loaded I would like to enable it. I found that this can be done in “QueryStatus” method, but I don’t know how to invoke it from my Addin. So my question is – is there any way to change commands status outside from QueryStatus method?

    Regards

    Saturday, April 17, 2010 11:09 AM

Answers

All replies

  • see:

    HOWTO: Controlling the state of command in a Visual Studio add-in

    http://www.mztools.com/resources_vsnet_addins.aspx


    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/
    Saturday, April 17, 2010 11:57 PM
  • Hi Carlos,

    Thanks for your replay, but is there any way to control the state of command without QueryStatus method?

    Monday, April 19, 2010 6:20 PM
  • based on my understanding... NO

    QueryStaus is the typical way you control your command status. . and I don't think there is any other way we can do it..

    As to your another question "I found that this can be done in “QueryStatus” method, but I don’t know how to invoke it from my Addin ". Well, we don't call this method by ourself, visual studio will do it.. What we need to do is to implement this method in our package/add-in.

    I'm not familiar with add-in, so will take package as example (i think add-in should be similiar to package).

    The first thing you need to do is to create a commandTarget class that implements Iolecommandtarget, then in your package file, within Ivspackage::setsite() method, query the service for SID_SVsRegisterPriorityCommandTarget, after you have got the handle of this service, use its RegisterPriorityCommandTarget method to register your own commandTarget class as the command handler..

    After this, visual studio UI will keep invoking the querystatus method,, and there you can control the command status..

    I believe there must be some easier way,,i'm not sure, but this is how i do it..

     


    Thanks, B.C.
    Tuesday, April 20, 2010 3:15 AM
  •  By the way,If you have implemented any widnowPane, e.g. a tool window, then you have already got an IoleCommandTarget,

    You can control the command status within that window.

    [ComVisibleAttribute(

    true)]

    public

     

    abstract class WindowPane : IVsWindowPane,

    IOleCommandTarget, IVsBroadcastMessageEvents,

    IServiceProvider, IDisposable


    Thanks, B.C.
    Tuesday, April 20, 2010 6:16 AM
  • No, the state of the command of a loaded add-in is controlled through QueryStatus which is called by VS when something changes in the environment that VS thinks that can change the state of commands.

    The sample that I provided explained your scenario of command enabled/disabled with solution loaded/not loaded.

    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/
    Thursday, April 22, 2010 11:18 PM