/// <summary> /// Implements the QueryStatus method of the IDTCommandTarget interface. /// This is called when the command's availability is updated /// </summary> /// <param term='commandName'> /// The name of the command to determine state for. /// </param> /// <param term='neededText'> /// Text that is needed for the command. /// </param> /// <param term='status'> /// The state of the command in the user interface. /// </param> /// <param term='commandText'> /// Text requested by the neededText parameter. /// </param> /// <seealso class='Exec' /> public void QueryStatus(string commandName, EnvDTE.vsCommandStatusTextWanted neededText, ref EnvDTE.vsCommandStatus status, ref object commandText) { IAddInCommand currentCommand = GetAddIn(commandName); if (currentCommand == null) { return; } currentCommand.QueryStatus(ref status); switch (neededText) { case EnvDTE.vsCommandStatusTextWanted.vsCommandStatusTextWantedName: commandText = currentCommand.commandName; break; case EnvDTE.vsCommandStatusTextWanted.vsCommandStatusTextWantedStatus: // CONSIDER: what does this do? break; default: break; } }
/// <summary> /// If available, this command takes a fully-qualified AddIn command name and returns /// its implementation object. /// </summary> /// <param name="commandName"> A full ProgID.CommandName string, as passed by the Shell to QueryStatus & Exec </param> private IAddInCommand GetAddIn(string commandName) { string strPrefix = m_strProgID + "."; string strCurrent = null; IAddInCommand command = null; foreach (IAddInCommand currCommand in m_Commands) { strCurrent = strPrefix + currCommand.commandName; if (System.String.Compare(strCurrent, commandName, true) == 0) { command = currCommand; break; } } return(command); }
/// <summary> /// Implements the Exec method of the IDTCommandTarget interface. /// This is called when the command is invoked. /// </summary> /// <param term='commandName'> /// The name of the command to execute. /// </param> /// <param term='executeOption'> /// Describes how the command should be run. /// </param> /// <param term='varIn'> /// Parameters passed from the caller to the command handler. /// </param> /// <param term='varOut'> /// Parameters passed from the command handler to the caller. /// </param> /// <param term='handled'> /// Informs the caller if the command was handled or not. /// </param> /// <seealso class='Exec' /> public void Exec(string commandName, EnvDTE.vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled) { handled = false; IAddInCommand currentCommand = GetAddIn(commandName); if (currentCommand == null) { return; } try { currentCommand.Exec(executeOption, ref varIn, ref varOut); handled = true; } catch (System.Exception /*e*/) { } }