locked
What is the best way to detect Copy (Ctrl+C) event in an IWpfTextView? RRS feed

  • Question

  • I am trying to detect a copy event in the text view and I have been researching the best way to do this. Is it to possibly hook into the StandardCommand Copy event somehow and detect it that way? Or is it possible to use the KeyProcessor(and simply detect Ctrl+C keypresses)?

    My extension is currently implementing the IWpfTextViewCreationListener; is there a way to somehow get access to the KeyProcessor or StandardCommand from the IWpfTextView that the listener is passing to me? If so, can you post a code sample that demonstrates this?

    Wednesday, June 2, 2010 7:55 PM

Answers

  • You can implement an IOleCommandTarget (hooked up by an IVsTextViewCreationListener)*. In the Exec method, check that the pguidCmdGroup is equal to VSConstants.GUID_VSStandardCommandSet97 and that the nCmdID is equal to (uint)VSConstants.VSStd97CmdID.Copy.

    *NOTE: See "Walkthrough: Displaying Statement Completion" for an example of using an IVsTextViewCreationListener to hook up and IOleCommandTarget.

    Wednesday, June 2, 2010 11:52 PM

All replies

  • You can implement an IOleCommandTarget (hooked up by an IVsTextViewCreationListener)*. In the Exec method, check that the pguidCmdGroup is equal to VSConstants.GUID_VSStandardCommandSet97 and that the nCmdID is equal to (uint)VSConstants.VSStd97CmdID.Copy.

    *NOTE: See "Walkthrough: Displaying Statement Completion" for an example of using an IVsTextViewCreationListener to hook up and IOleCommandTarget.

    Wednesday, June 2, 2010 11:52 PM
  • Thanks for the answer and the helpful link!!!
    Friday, June 4, 2010 12:25 AM