/// /// Copyright © 2003-2008 JetBrains s.r.o. /// You may distribute under the terms of the GNU General Public License, as published by the Free Software Foundation, version 2 (see License.txt in the repository root folder). /// using System; using JetBrains.Omea.OpenAPI; namespace JetBrains.Omea.GUIControls { /// /// An action that executes a specific command on the command processor. /// /// ///

This action is populated upon creation with a string that represents a command name.

///

Upon execution, the command is applied to a command processor of the action context provided along with the execution request.

///

The same command is used to retrieve the visual state and style information for the action.

///
public class CommandProcessorAction : IAction, IComparable { /// /// Initializes the instance by populating it with a particular command. /// /// Name of the command to execute and query for visual state. /// ///

This action is populated upon creation with a string that represents a command name.

///

Upon execution, the command is applied to a command processor of the action context provided along with the execution request.

///

The same command is used to retrieve the visual state and style information for the action.

///
public CommandProcessorAction( string command ) { _command = command; } /// /// Name of a command that this action executes or queries for the state on an active command processor. /// protected string _command; /// /// Name of a command that this action executes or queries for the state on an active command processor. /// public string Command { get { return _command; } } #region IAction Members /// /// Executes an action by applying the command specified on creation to the command processor supplied to this method thru the parameter. /// /// Context for this action. public void Execute( IActionContext context ) { context.CommandProcessor.ExecuteCommand( _command ); } /// /// Updates the action's state based on the command processor's (supplied to this method thru the parameter) ability to execute this command, as specified in the constructor. /// /// Context for this action. /// An object that allows to control the state and style of a visual representation of this action. public void Update( IActionContext context, ref ActionPresentation presentation ) { bool avail = context.CommandProcessor.CanExecuteCommand( Command ); if( context.Kind == ActionContextKind.ContextMenu ) presentation.Visible = avail; // Hide disabled items from the context menu else presentation.Enabled = avail; // Let disabled items at other places } #endregion #region Object Overrides public override string ToString() { return "CommandProcessorAction/" + _command; } public override bool Equals( object obj ) { return _command.Equals( ((CommandProcessorAction)obj)._command ); } public override int GetHashCode() { return ToString().GetHashCode(); } #endregion #region IComparable Members public int CompareTo( object obj ) { return _command.CompareTo( ((CommandProcessorAction)obj)._command ); } #endregion } }