using System;
using System.Collections;
using Ironring.MMC.Nodes;
namespace Ironring.MMC.Core{
/// <summary>
/// Delegate definition for all menu handlers
/// </summary>
public delegate void MenuCommandHandler(object item, BaseNode node);
/// <summary>
/// Handles menu item features
/// </summary>
public class MenuItem
{
/// <summary>
/// Command handler event for revicing notifications fo the menu command
/// </summary>
public event MenuCommandHandler Handler;
///////////////////////////////////////////////////////////////////////
//
// Private vars
//
#region
private CCM_SPECIAL _specialFlags = 0;
private MF _flags = 0;
private string _id;
private string _name;
private bool _visible = true;
private string _statusText;
private int _nCommandId = 0;
#endregion
///////////////////////////////////////////////////////////////////////
//
// Properties
//
#region
/// <summary>
/// Get or set the unique identifier of this menu item.
/// </summary>
public string ID
{
get{ return _id; }
set{ _id = value; }
}
/// <summary>
/// Get or set the menu display name
/// Name can support mnemonics like &File
/// </summary>
public string Name
{
get{ return _name; }
set{ _name = value; }
}
// added by Roman Kiss
/// <summary>
/// Get or set the flag to control visibility of the menu
/// </summary>
public bool Visible
{
get{ return _visible; }
set{ _visible = value; }
}
/// <summary>
/// Get or set the text to display in the MMC status bar when the user hovers over the menu item
/// </summary>
public string StatusText
{
get{ return _statusText; }
set{ _statusText = value; }
}
/// <summary>
/// Get or set the integer command that MMC uses when if fires the command
/// </summary>
public int CommandId
{
get{ return _nCommandId; }
set{ _nCommandId = value; }
}
/// <summary>
/// Get or set one or more of the flags (see CCM_SPECIAL enum in interfaces.cs)
/// </summary>
public CCM_SPECIAL SpecialFlags
{
get { return _specialFlags; }
set { _specialFlags = value; }
}
/// <summary>
/// Get or set one or more of the style flags (see MF enum in interfaces.cs)
/// </summary>
public MF Flags
{
get { return _flags; }
set { _flags = value; }
}
#endregion
///////////////////////////////////////////////////////////////////////
//
// Constructors
//
#region
/// <summary>
/// default ctor
/// </summary>
public MenuItem()
{
}
/// <summary>
/// Common usage ctor to provide the class flields at once
/// </summary>
/// <param name="Name"></param>
/// <param name="StatusText"></param>
/// <param name="handler"></param>
public MenuItem(string name, string statusText, MenuCommandHandler handler)
{
this.Name = name;
this.StatusText = statusText;
Handler += handler;
}
public MenuItem(string name, string statusText, MenuCommandHandler handler, MF flags)
: this(name, statusText, handler)
{
_flags = flags;
}
///Added by Greg Arnold
/// <summary>
/// Common usage ctor to provide the class flields at once
/// </summary>
/// <param name="id"></param>
/// <param name="Name"></param>
/// <param name="StatusText"></param>
/// <param name="handler"></param>
public MenuItem(string id, string name, string statusText, MenuCommandHandler handler) : this(name,statusText,handler)
{
this.ID = id;
}
/// <summary>
/// Common usage ctor to provide the class fields at once
/// </summary>
/// <param name="flags"></param>
public MenuItem(MF flags)
{
_flags = flags;
}
#endregion
/// <summary>
/// Called by the node when a command is fired by MMC
/// </summary>
/// <param name="node"></param>
public void Command(BaseNode node)
{
OnCommand(node);
}
/// <summary>
/// Called to handle the command. Consider inheriting from this
/// class and overriding this behavior if required.
/// </summary>
/// <param name="node"></param>
protected virtual void OnCommand(BaseNode node)
{
if (Handler != null)
Handler(this, node);
}
}
}
|