Beispiel #1
0
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (GuidRefIsNull(ref pguidCmdGroup))
            {
                return(VSErr.OLECMDERR_E_NOTSUPPORTED);
            }

            if (Zombied || pguidCmdGroup != AnkhId.CommandSetGuid)
            {
                return(VSErr.OLECMDERR_E_UNKNOWNGROUP);
            }

            switch ((OLECMDEXECOPT)nCmdexecopt)
            {
            case OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT:
            case OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER:
            case OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER:
                break;

            case OLECMDEXECOPT.OLECMDEXECOPT_SHOWHELP:
            default:
                // VS Doesn't use OLECMDEXECOPT.OLECMDEXECOPT_SHOWHELP
                return(VSErr.E_NOTIMPL);

            case (OLECMDEXECOPT)0x00010000 | OLECMDEXECOPT.OLECMDEXECOPT_SHOWHELP:
                // Retrieve parameter information of command for immediate window
                // See http://blogs.msdn.com/dr._ex/archive/2005/03/16/396877.aspx for more info

                if (pvaOut == IntPtr.Zero)
                {
                    return(VSErr.E_POINTER);
                }

                string definition;
                if (pvaOut != IntPtr.Zero && CommandMapper.TryGetParameterList((AnkhCommand)nCmdID, out definition))
                {
                    Marshal.GetNativeVariantForObject(definition, pvaOut);

                    return(VSErr.S_OK);
                }

                return(VSErr.E_NOTIMPL);
            }

            object argIn = null;

            if (pvaIn != IntPtr.Zero)
            {
                argIn = Marshal.GetObjectForNativeVariant(pvaIn);
            }

            CommandEventArgs args = new CommandEventArgs(
                (AnkhCommand)nCmdID,
                Context,
                argIn,
                (OLECMDEXECOPT)nCmdexecopt == OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER,
                (OLECMDEXECOPT)nCmdexecopt == OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER);

            if (!CommandMapper.Execute(args.Command, args))
            {
                return(VSErr.OLECMDERR_E_DISABLED);
            }

            if (pvaOut != IntPtr.Zero)
            {
                Marshal.GetNativeVariantForObject(args.Result, pvaOut);
            }

            return(VSErr.S_OK);
        }