Hello,
I have a ToolWindowPane with a toolbar and an embedded Editor (IWpfTextViewHost).
The keyboard shortcuts for insert/delete etc work fine but the VS MainMenu and Toolbar items do not work
I found that I can intercept the VSConstants.GUID_VSStandardCommandSet97
My first problem is how can I query the IWpfTextViewHost
- if text is selected (for cut / copy)
- if I can paste Clipboard contents
If I enable them always (dispite quering their real state) the items work
The second problem is Undo / Redo works with VS Toolbar but not with keyboard or VS Menu
A related question: Do I have to tell the IWpfTextViewHost to execute actions as cut/copy/paste/undo/redo and how do I do this, if necessary ?
here my current code for QueryStatus
int IOleCommandTarget.QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { if (pguidCmdGroup == GuidList.guidiNEXTCmdSet) return VSConstants.S_OK; // own comands if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97) { OLECMDF cmdf = OLECMDF.OLECMDF_SUPPORTED; // validate parameters if (prgCmds == null || cCmds != 1) return VSConstants.E_INVALIDARG; // Process standard Commands switch (prgCmds[0].cmdID) { case (uint)VSConstants.VSStd97CmdID.SelectAll: { // Always enabled cmdf = OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED; break; } case (uint)VSConstants.VSStd97CmdID.Copy: case (uint)VSConstants.VSStd97CmdID.Cut: { // Enable if something is selected if (viewModel.TextSelected) cmdf |= OLECMDF.OLECMDF_ENABLED; break; } case (uint)VSConstants.VSStd97CmdID.Paste: { // Enable if clipboard has content we can paste // if (SQLEdit.SQLEdit.CanPaste(DataFormats.GetFormat(DataFormats.Text))) { cmdf |= OLECMDF.OLECMDF_ENABLED; } break; } case (uint)VSConstants.VSStd97CmdID.Redo: { // Enable if actions that have occurred within the RichTextBox // can be reapplied if (viewModel.EditorIsRedoEnabled) cmdf |= OLECMDF.OLECMDF_ENABLED; break; } case (uint)VSConstants.VSStd97CmdID.Undo: { if (viewModel.EditorIsUndoEnabled) cmdf |= OLECMDF.OLECMDF_ENABLED; break; } default: { return (int)(Constants.OLECMDERR_E_NOTSUPPORTED); } } prgCmds[0].cmdf = (uint)cmdf; return VSConstants.S_OK; }
in routines like viewModel.TextSelected I want to query the IWpfTextViewHost
best regards Stephan Hartmann ML-Software GmbH