OldMenuCommand.BeforeQueryStatus doesn't always get called.

Answered OldMenuCommand.BeforeQueryStatus doesn't always get called.

  • Friday, January 27, 2012 10:27 PM
     
     

    I have a custom menu command that I've added as follows:

                    CommandID openClassCommandID = new CommandID(GuidList.guidVisualUCCmdSet, (int)PkgCmdIDList.cmdidVUCOpenClass);
                    OleMenuCommand menuOpenClass = new OleMenuCommand(OpenByClass, openClassCommandID);
                    menuOpenClass.BeforeQueryStatus += new EventHandler(OpenByClassQueryStatus);
                    mcs.AddCommand(menuOpenClass);

    The command displays and works fine, however, OpenByClassQueryStatus doesn't always get called.  It seems like it won't get called until some visual portion of the extension is activated.  Once I activate the toolwindow of the package, the menu command will then work for there on.  I'm new to VSPackages so I'm sure I'm missing a flag somewhere.  Anyone had an idea?

All Replies

  • Friday, January 27, 2012 10:51 PM
    Moderator
     
     

    Where is the MenuCommandService coming from (your package or toolwindow)?  At what point are you registering the handler?  In general command routing in VS is contextually based and we don't load packages in order to execute a QueryStatus callback.  I suspect your package isn't loaded at all.

    Ryan

  • Friday, January 27, 2012 11:45 PM
     
     
    I'm creating the command in the Initialized() of my Package.  I suspected that the package isn't getting loaded.  How would I go about making sure it's always loaded and active?
  • Saturday, January 28, 2012 12:23 AM
     
     Answered
    I got it.  I forced my package to autoload and it's now working.  Thanks for the push in the right direction.
    • Marked As Answer by Joe NC Monday, January 30, 2012 3:15 AM
    •  
  • Saturday, January 28, 2012 1:03 AM
    Moderator
     
     

    Forced auto load is rarely the "right" direction. What kind of things are you checking in QueryStatus?

    Ryan

  • Saturday, January 28, 2012 5:01 AM
     
     
    It has a feature that is similar to VA's OpenFileInSolution but uses a subset of the Solution.  In the case no solution is loaded (ie start up), I want to disable the menu command.  But since I don't generate my internal structures until the package init's I can't set the state of the command.
  • Saturday, January 28, 2012 4:55 PM
    Moderator
     
     

    If hiding it is acceptable (as opposed to disabling it) you can look at VisibilityItem, specifically the UI Context SolutionExists. The problem with force loading is it means disk I/O, on startup disk I/O is the enemy of performance as disks are relatively slow, if possible one should always strive to avoid making VS slower by installing their extension. 

    Ryan

  • Thursday, March 22, 2012 4:26 PM
     
     
    i agree with Ryan, it is a performance issue i want to avoid.

    BUT...

    I've got an "open with..." button added to the solution explorer context menu, and it should be visible only on certain types of files  i am doing this by using BeforeQueryStatus.

    how can i make my button visibility true/false BEFORE the extension is loaded?