private static int RouteQueryStatus(Func <CommandTargetParameters, RoutedCommand, bool> canExecuteFunc, ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { RoutedCommand command = InheritanceMarginPackage.Instance.FindCommand(pguidCmdGroup, prgCmds[0].cmdID); if (command == null) { return((int)OleConstants.MSOCMDERR_E_UNKNOWNGROUP); } string commandText = GetCommandText(pCmdText); CommandTargetParameters @params = CommandTargetParameters.CreateInstance(prgCmds[0].cmdID, commandText); if (!canExecuteFunc(@params, command)) { return((int)OleConstants.MSOCMDERR_E_NOTSUPPORTED); } prgCmds[0].cmdf = (uint)OLECMDF.OLECMDF_SUPPORTED; prgCmds[0].cmdf |= @params.Enabled ? (uint)OLECMDF.OLECMDF_ENABLED : 0; prgCmds[0].cmdf |= [email protected] ? (uint)OLECMDF.OLECMDF_INVISIBLE : 0; prgCmds[0].cmdf |= @params.Pressed ? (uint)OLECMDF.OLECMDF_LATCHED : 0; if (@params.Text == null) { @params.Text = string.Empty; } if (commandText != @params.Text) { SetCommandText(pCmdText, @params.Text); } return(VSConstants.S_OK); }
private static int RouteExec(Func <CommandTargetParameters, RoutedCommand, bool> canExecuteFunc, Action <CommandTargetParameters, RoutedCommand> executeFunc, ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) { RoutedCommand command = InheritanceMarginPackage.Instance.FindCommand(pguidCmdGroup, nCmdID); if (command == null) { return((int)OleConstants.MSOCMDERR_E_UNKNOWNGROUP); } CommandTargetParameters @params = CommandTargetParameters.CreateInstance(nCmdID); @params.InArgs = (pvaIn == IntPtr.Zero) ? null : Marshal.GetObjectForNativeVariant(pvaIn); if (canExecuteFunc(@params, command)) { try { executeFunc(@params, command); return(VSConstants.S_OK); } catch (COMException exception) { return(exception.ErrorCode); } } return((int)OleConstants.MSOCMDERR_E_NOTSUPPORTED); }