locked
KeyBinding and BeforeQueryStatus function RRS feed

  • Question

  • Hi All,

    I have developed  a small Add-in which got a tree view , this tree view contains nodes which can be of two different types:

    Folder
    Files

    I have linked a contextual menu on this Add-in with sereval entries, one dedicated to COPY treeview node, to do so i have add the necessary entry

    in the VSCT and add a menu hanlder in source code.

    I Have also add a handler BeforeQueryStatus for the COPY function, this function shared the visibility of the contextual menu COPY( visible if the selected node is a file)

    At this step everything works fine.

    Now i add a Key binding in the VSCT (CTRL+C) file link to the COPY command previously defined, and it seems that the COPY function is not always called even if the selected node inside the tree view is a file node.

    This Problem seems to appear because BeforeQueryStatus in never call when i used the accelerator key in my case CTRL+C (to perform the COPY)

    Does my diagnostic is correct ?

    Is there any workarround when we use Key binding on contextual menu which got a BeforeQueryStatus function which handle the menu visibility?

    Thanks,

     

     

     


     

     


    Richard
    Tuesday, September 13, 2011 1:44 PM

Answers

  • If something happens within your window that changes command state you need to let the shell know about it vis IVsUIShell::UpdateCommandUI (pass 0 not 1 as the param).  Otherwise we think the most recent information we have pulled (i.e. the last time we did a QueryStatus) is still applicable so we don't do another one.

    Just to be sure, you said you have used a CommandPlacement, you mean to place the existing copy command into your menu right?  You didn't create a new command in your VSCT file that you are calling 'Copy' did you?

    Ryan

    • Marked as answer by Poline Tuesday, September 13, 2011 3:51 PM
    Tuesday, September 13, 2011 3:23 PM

All replies

  • It sounds like your diagnosis is accurate, though you shouldn't need to define your own copy command, the copy command already exists.  You can add a CommandPlacement to place the normal copy command ({guidVsStd97, cmdidCopy} I believe) on your context menu.  I imagine what is happening in your case is that you haven't defined a keybinding scope for your toolwindow and thus you are trying to bind your command to Ctrl+C globally, but that is already bound to the standard copy command thus your binding is ignored.

    Ryan

    Tuesday, September 13, 2011 2:31 PM
  • Hi Ryan,

    I don't have any problem regarding Key Binding in my project, the key binding works fine. I'm able to intercept the CTRL+C command in my source code (i have already used command placement).

    The only problem i have is when i right click with the mouse to display the contextual menu the function BeforeQueryStatus function is called and if for some reason BeforeQueryStatus disable the COPY entry in the contextual menu

    Then i mouve the mouse to select a an entry which valid the COPY function (CTRL+C). 

    Perform the CTRL+C nothing happen because the BeforeQueryStatus function has not been called.

    Right click with the mouse on the previous selection(just to display the Contextual menu),

     the BeforeQueryStatus is called and the COPY function is now enable.

    Perform the CTRL+C the COPY function is called.

    My question is how to deal with Key binding link to  command which has BeforeQueryStatus function?

     


    Richard
    Tuesday, September 13, 2011 3:00 PM
  • If something happens within your window that changes command state you need to let the shell know about it vis IVsUIShell::UpdateCommandUI (pass 0 not 1 as the param).  Otherwise we think the most recent information we have pulled (i.e. the last time we did a QueryStatus) is still applicable so we don't do another one.

    Just to be sure, you said you have used a CommandPlacement, you mean to place the existing copy command into your menu right?  You didn't create a new command in your VSCT file that you are calling 'Copy' did you?

    Ryan

    • Marked as answer by Poline Tuesday, September 13, 2011 3:51 PM
    Tuesday, September 13, 2011 3:23 PM
  • Absolutely, I just put the existing order 'copy' in my own men,

    Calling IVsUIShell::UpdateCommandUI seems to fix my problem ( the command look like the one used with MFC :-)  )


    Richard
    Tuesday, September 13, 2011 3:51 PM