Пример #1
0
        public bool QueryCommandStatus(Guid guidCmdGroup, uint commandId, IntPtr commandText, out OLECMDF commandStatus)
        {
            commandStatus = new OLECommandFlags();

            if (guidCmdGroup == VSConstants.VSStd2K)
            {
                switch ((VSConstants.VSStd2KCmdID)commandId)
                {
                case VSConstants.VSStd2KCmdID.FORMATDOCUMENT:
                    if (this.CanFormatDocument())
                    {
                        commandStatus = OLECommandFlags.OLECMDF_ENABLED | OLECommandFlags.OLECMDF_SUPPORTED;
                        return(true);
                    }

                    break;

                case VSConstants.VSStd2KCmdID.FORMATSELECTION:
                    if (this.CanFormatSelection())
                    {
                        commandStatus = OLECommandFlags.OLECMDF_SUPPORTED;
                        if (!this.textView.Selection.IsEmpty)
                        {
                            commandStatus |= OLECommandFlags.OLECMDF_ENABLED;
                        }

                        return(true);
                    }

                    break;
                }
            }

            return(false);
        }
Пример #2
0
        /// <summary>
        /// Provides a first chance to tell the shell that this window is capable of handling certain commands. Implements IOleCommandTarget.QueryStatus
        /// </summary>
        protected int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, MSOLE.OLECMD[] prgCmds, IntPtr pCmdText)
        {
            int  hr      = VSConstants.S_OK;
            bool handled = true;

            // Only handle commands from the Office 97 Command Set (aka VSStandardCommandSet97).
            if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97)
            {
                // There typically is only one command passed in to this array - in any case, we only care
                // about the first command.
                MSOLE.OLECMD       cmd   = prgCmds[0];
                MSOLE.OLECMDF      flags = 0;
                ReadingRichTextBox activeRichTextEditor = myActiveInlineEditor as ReadingRichTextBox;
                switch ((VSConstants.VSStd97CmdID)cmd.cmdID)
                {
                case VSConstants.VSStd97CmdID.Cut:
                    if (activeRichTextEditor != null)
                    {
                        flags = (myRichTextSelected && !myRichTextProtected) ? MSOLE.OLECMDF.OLECMDF_SUPPORTED | MSOLE.OLECMDF.OLECMDF_ENABLED : MSOLE.OLECMDF.OLECMDF_SUPPORTED;
                    }
                    break;

                case VSConstants.VSStd97CmdID.Copy:
                    if (activeRichTextEditor != null)
                    {
                        flags = myRichTextSelected ? MSOLE.OLECMDF.OLECMDF_SUPPORTED | MSOLE.OLECMDF.OLECMDF_ENABLED : MSOLE.OLECMDF.OLECMDF_SUPPORTED;
                    }
                    break;

                case VSConstants.VSStd97CmdID.Paste:
                    if (activeRichTextEditor != null)
                    {
                        flags = (!myRichTextProtected && (Clipboard.ContainsText(TextDataFormat.Text) || Clipboard.ContainsText(TextDataFormat.UnicodeText))) ? MSOLE.OLECMDF.OLECMDF_SUPPORTED | MSOLE.OLECMDF.OLECMDF_ENABLED : MSOLE.OLECMDF.OLECMDF_SUPPORTED;
                    }
                    break;

                case VSConstants.VSStd97CmdID.SelectAll:
                    if (activeRichTextEditor != null)
                    {
                        flags = MSOLE.OLECMDF.OLECMDF_SUPPORTED | MSOLE.OLECMDF.OLECMDF_ENABLED;
                    }
                    break;

                case VSConstants.VSStd97CmdID.Redo:
                case VSConstants.VSStd97CmdID.MultiLevelRedo:
                case VSConstants.VSStd97CmdID.MultiLevelUndo:
                    if (activeRichTextEditor != null)
                    {
                        flags = MSOLE.OLECMDF.OLECMDF_SUPPORTED;
                    }
                    break;

                case VSConstants.VSStd97CmdID.Undo:
                    if (activeRichTextEditor != null)
                    {
                        flags = activeRichTextEditor.CanUndo ? MSOLE.OLECMDF.OLECMDF_SUPPORTED | MSOLE.OLECMDF.OLECMDF_ENABLED : MSOLE.OLECMDF.OLECMDF_SUPPORTED;
                    }
                    break;

                case VSConstants.VSStd97CmdID.Delete:
                    // Inform the shell that we should have a chance to handle the delete command.
                    if (!this.myForm.ReadingEditor.EditingFactType.IsEmpty)
                    {
                        flags = MSOLE.OLECMDF.OLECMDF_SUPPORTED | MSOLE.OLECMDF.OLECMDF_ENABLED;
                    }
                    break;

                case VSConstants.VSStd97CmdID.EditLabel:
                    // Support this command regardless of the current state of the inline editor.
                    // If we do not do this, then an F2 keypress with an editor already open will
                    // report the command as disabled and we would need to use IVsUIShell.UpdateCommandUI
                    // whenever an editor closed to reenable the command.
                    flags = MSOLE.OLECMDF.OLECMDF_SUPPORTED | MSOLE.OLECMDF.OLECMDF_ENABLED;
                    break;
                }
                if (flags == 0)
                {
                    // Inform the shell that we don't support the command.
                    handled = false;
                    hr      = (int)MSOLE.Constants.OLECMDERR_E_NOTSUPPORTED;
                }
                else
                {
                    cmd.cmdf   = (uint)flags;
                    prgCmds[0] = cmd;
                }
            }
            else
            {
                // Inform the shell that we don't recognize this command group.
                handled = false;
                hr      = (int)MSOLE.Constants.OLECMDERR_E_UNKNOWNGROUP;
            }
            if (!handled)
            {
                Debug.Assert(ErrorHandler.Failed(hr));
                ModelingDocData docData = CurrentDocument;
                Microsoft.VisualStudio.Modeling.Shell.UndoManager undoManager;
                MSOLE.IOleCommandTarget forwardTo;
                if ((docData != null &&
                     null != (undoManager = docData.UndoManager) &&
                     null != (forwardTo = undoManager.VSUndoManager as MSOLE.IOleCommandTarget)) ||
                    null != (forwardTo = GetService(typeof(MSOLE.IOleCommandTarget)) as MSOLE.IOleCommandTarget))
                {
                    // If the command wasn't handled already, forward it to the undo manager.
                    hr = forwardTo.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText);
                }
            }
            return(hr);
        }
Пример #3
0
        public bool QueryCommandStatus(Guid guidCmdGroup, uint commandId, IntPtr commandText, out OLECMDF commandStatus)
        {
            commandStatus = new OLECommandFlags();

            if (guidCmdGroup == VSConstants.VSStd2K)
            {
                switch ((VSConstants.VSStd2KCmdID)commandId)
                {
                    case VSConstants.VSStd2KCmdID.FORMATDOCUMENT:
                    if (this.CanFormatDocument())
                    {
                        commandStatus = OLECommandFlags.OLECMDF_ENABLED | OLECommandFlags.OLECMDF_SUPPORTED;
                        return true;
                    }

                        break;

                    case VSConstants.VSStd2KCmdID.FORMATSELECTION:
                        if (this.CanFormatSelection())
                        {
                            commandStatus = OLECommandFlags.OLECMDF_SUPPORTED;
                            if (!this.textView.Selection.IsEmpty)
                            {
                                commandStatus |= OLECommandFlags.OLECMDF_ENABLED;
                }

                            return true;
            }

                        break;
                }
            }

            return false;
        }