locked
How to disable the menu items in the C++ Editor context menu? RRS feed

  • Question

  • We implememted a custom project and most files in teh project is C++ file. We want to disable some menu items in the C++ editor context menu since we do not support them in the custom project, but no lucky.

    We tried teh IVsTextView::AddCommandFilter way, but our fro teh specified command like cmdidFindReferences, our QueryStatus handle is never called. I think teh reason is that the C++ langauge servcie controls teh status fro these commands and do not give a chance to my filter.

    Is there any other way to do this? Thanks in advance.
    Sunday, December 21, 2008 3:07 PM

Answers

  • Hi Michael,

    I tried this myself quite some time ago, and found that it cannot be done. The problem here is that the code editor, directly invokes the IOleCommandTarget on the language service. The QS and Exec are immediately processed, and there are no hooks in between that'll allow you to change up the behavior.

    The other problem is that when you call IVsTextView::AddCommandFilter, you have no control over where in the filter chain it gets placed. So some other IOleCommandTarget may process the command, and you'll never see it.

    One suggestion that comes to mind is to see if you can hook the ECMD_SHOWCONTEXTMENU command from a priority command target . I haven't tried this, but if you could intercept that command, then you could display your own context menu instead of the stock IDM_VS_CTXT_CODEWIN context menu.

    Sincerely,
    Ed Dore
    Monday, December 22, 2008 10:50 PM

All replies

  • Hi Michael,

    I tried this myself quite some time ago, and found that it cannot be done. The problem here is that the code editor, directly invokes the IOleCommandTarget on the language service. The QS and Exec are immediately processed, and there are no hooks in between that'll allow you to change up the behavior.

    The other problem is that when you call IVsTextView::AddCommandFilter, you have no control over where in the filter chain it gets placed. So some other IOleCommandTarget may process the command, and you'll never see it.

    One suggestion that comes to mind is to see if you can hook the ECMD_SHOWCONTEXTMENU command from a priority command target . I haven't tried this, but if you could intercept that command, then you could display your own context menu instead of the stock IDM_VS_CTXT_CODEWIN context menu.

    Sincerely,
    Ed Dore
    Monday, December 22, 2008 10:50 PM
  • Thank you, Ed.
    Tuesday, December 23, 2008 3:30 AM