/// <summary> /// Executes the specified named command. /// </summary> /// <param name="CmdName">The name of the command to execute.</param> /// <param name="ExecuteOption">A <see cref="T:EnvDTE.vsCommandExecOption"></see> constant specifying the execution options.</param> /// <param name="VariantIn">A value passed to the command.</param> /// <param name="VariantOut">A value passed back to the invoker Exec method after the command executes.</param> /// <param name="Handled">true indicates that the command was implemented. false indicates that it was not.</param> void IDTCommandTarget.Exec(string cmdName, vsCommandExecOption ExecuteOption, ref object VariantIn, ref object VariantOut, ref bool Handled) { Handled = false; if (ExecuteOption == vsCommandExecOption.vsCommandExecOptionDoDefault) { if (this.vsCommands.ContainsKey(cmdName)) { VsCommand vsCommand = this.vsCommands[cmdName]; vsCommand.OnExecute(new VsCommandEventArgs(this.dte, this.addin)); Handled = true; } } }
/// <summary> /// Returns the current status (enabled, disabled, hidden, and so forth) of the specified named command. /// </summary> /// <param name="CmdName">The name of the command to check.</param> /// <param name="NeededText">A <see cref="T:EnvDTE.vsCommandStatusTextWanted"></see> constant specifying if information is returned from the check, and if so, what type of information is returned.</param> /// <param name="StatusOption">A <see cref="T:EnvDTE.vsCommandStatus"></see> specifying the current status of the command.</param> /// <param name="CommandText">The text to return if <see cref="F:EnvDTE.vsCommandStatusTextWanted.vsCommandStatusTextWantedStatus"></see> is specified.</param> void IDTCommandTarget.QueryStatus(string cmdName, vsCommandStatusTextWanted neededText, ref vsCommandStatus statusOption, ref object commandText) { if (neededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone) { if (this.vsCommands.ContainsKey(cmdName)) { VsCommand vsCommand = this.vsCommands[cmdName]; if (vsCommand.OnQueryStatus(new VsCommandEventArgs(this.dte, this.addin))) { statusOption = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled; } else { statusOption = (vsCommandStatus)vsCommandStatus.vsCommandStatusUnsupported; } } } }
protected void RegisterCommand(VsCommand command) { string fullCommandName = String.Format("{0}.{1}", this.GetType().FullName, command.CommandName); this.vsCommands.Add(fullCommandName, command); }