void RemoveScriptCommands() { var dte = _applicationObject; if (null == dte) { return; } var keepers = new[] { StudioShellExecuteCommandName, StudioShellRestartCommandName, StudioShellCommandName, StudioShellCancelCommandName }; List <Command> losers = new List <Command>(); foreach (Command cmd in dte.Commands) { if (keepers.Contains(cmd.Name, StringComparer.InvariantCultureIgnoreCase)) { continue; } if (FunctionUtilities.IsPowerShellCommandName(cmd.Name)) { losers.Add(cmd); } } losers.ForEach(cmd => cmd.Delete()); }
/// <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, vsCommandStatusTextWanted neededText, ref vsCommandStatus status, ref object commandText) { if (neededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone) { if (commandName == StudioShellCommandName) { status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled; return; } if (commandName == StudioShellRestartCommandName) { if (null != Shell) { status = (vsCommandStatus)(vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled); } else { status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported; } return; } if (commandName == StudioShellCancelCommandName) { if (null != Shell && Shell.CurrentState == CommandExecutorState.Unavailable) { status = (vsCommandStatus)(vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled); } else { status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported; } return; } if (commandName == StudioShellExecuteCommandName || FunctionUtilities.IsPowerShellCommandName(commandName)) { if (null != Shell && Shell.CurrentState == CommandExecutorState.Unavailable) { status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported; } else { status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled; } return; } if (commandName == StudioShellDoNothingCommandName) { status = vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled; } } }
/// <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, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled) { handled = false; if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault) { if (commandName == StudioShellCommandName) { ExecuteStudioShellCommand(); handled = true; return; } if (commandName == StudioShellRestartCommandName) { RestartShell(); handled = true; return; } if (commandName == StudioShellExecuteCommandName) { varOut = ExecuteStudioShellExecuteCommand(varIn); handled = true; return; } if (commandName == StudioShellCancelCommandName) { ExecuteStudioShellCancelCommand(); handled = true; return; } if (commandName.EndsWith("_1")) { handled = true; return; } if (FunctionUtilities.IsPowerShellCommandName(commandName)) { varOut = null; handled = true; object input = varIn; ThreadPool.QueueUserWorkItem(ctx => ExecuteStudioShellPowerShellCommand(commandName, input)); return; } } }