locked
VS Commands in Dialog Windows RRS feed

  • Question

  • Hello,

    I'm writing a Visual Studio package that has a custom editor, which provided data grid (or table) based editing. Adding and removing lines is done by executing corresponding custom Visual Studio commands. These commands are bound to keyboard gestures and may be remapped by the user (from the Keyboard options dialog).

    Now I would like to do something that is a bit unorthodox in Visual Studio: I want to use the same commands within a Modal Dialog Window, so that if the user remaps the command to other key stroke combinations, it will reflect in the dialog window.

    I used the technique described here to accomplish this. The following describes how it works in my code:

    Initialization stage:

    1. I instantiate an IOleCommandTarget implementation. I'll name it here "MyCommandTarget".
    2. Register "MyCommandTarget" as priority command target  (RegisterPriorityCommandTarget(0, MyCommandTarget, out cookie))
    3. Register an event handler on ComponentDispatcher.ThreadFilterMessage to override WPF message processing.

    When pressing an accelerator key:

    1. The message is first captured by the ThreadFilterMessage handler.
    2. -- The handler uses IvsFilterKeys2.TranslateAcceleratorEx(...) to translate and execute the command like so:
    int res = filterKeys.TranslateAcceleratorEx(
       new Microsoft.VisualStudio.OLE.Interop.MSG[] {oleMSG},
       (uint)(__VSTRANSACCELEXFLAGS.VSTAEXF_AllowModalState),
       1 /*scope count*/,
       new Guid[1] { typeof(RepositoryEditorFactory).GUID },
       out cmdGuid,
       out cmdId,
       out fTranslated,
       out fStartsMultiKeyChord);
    1. -- The 'QueryStatus' method of MyCommandTarget is executed, sets the command to enabled and returns VSConstants.S_OK.
    2. -- The QueryStatus method of the editor pane is executed and it changes the status of the command to 'Disabled' (because indeed, on the editor pane it should be disabled...).

    The last step breaks the operation. I can't make the command run in the dialog window, unless I enable it on the editor pane.

    Is there an inherent way to prevent the system from querying the command status on the editor pane by stopping the command propagation somehow, or by turning a flag on?

    Sunday, April 27, 2014 1:41 PM

Answers

  • I found the problem. It turns out I did not properly set the values for each command in the prgCmds[] array in the IOleCommandTarget implementation.

    When I fixed it, the commands would not propagate and would correctly act according to state on the Dialog Window.


    • Marked as answer by rmashal Monday, April 28, 2014 12:16 PM
    Monday, April 28, 2014 12:16 PM

All replies

  • I found the problem. It turns out I did not properly set the values for each command in the prgCmds[] array in the IOleCommandTarget implementation.

    When I fixed it, the commands would not propagate and would correctly act according to state on the Dialog Window.


    • Marked as answer by rmashal Monday, April 28, 2014 12:16 PM
    Monday, April 28, 2014 12:16 PM
  • Hi,

    Glad to hear that you got it working!

    Thank you for sharing the solution here, it will beneficial for other community members who have similar questions. 

    Best regards,

    Sunny

    Tuesday, April 29, 2014 1:37 AM