//-----------------------------------------------------------------------
//
// Copyright (c) 2009 Craig Sutherland. All rights reserved.
//
//-----------------------------------------------------------------------
/*
* Copyright (c) 2009 Craig Sutherland
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
namespace FastForward.WinCore
{
using System;
using System.ComponentModel;
using System.Drawing;
///
/// A command that has been added from a plug-in.
///
public class PluginCommand
: INotifyPropertyChanged
{
#region Private fields
///
/// The text of the command.
///
private string text;
///
/// The tooltip for the command.
///
private string tooltip;
///
/// The icon for the command.
///
private Image icon;
///
/// The type of the command.
///
private PluginCommandType type;
///
/// The command to run.
///
private EventHandler command;
#endregion
#region Constructors
///
/// Initializes a new instance of the class.
///
/// The text of the command.
/// The icon of the command.
/// The type of the command.
/// The command to run.
public PluginCommand(string text, Image icon, PluginCommandType type, EventHandler command)
{
this.text = text;
this.icon = icon;
this.type = type;
this.command = command;
}
#endregion
#region Public events
#region PropertyChanged()
///
/// A property has been changed.
///
public event PropertyChangedEventHandler PropertyChanged;
#endregion
#region Removed()
///
/// This command has been removed.
///
public event EventHandler Removed;
#endregion
#endregion
#region Public properties
#region Text
///
/// Gets or sets the text of the command.
///
public string Text
{
get
{
return this.text;
}
set
{
this.text = value;
this.FirePropertyChanged("Text");
}
}
#endregion
#region Tooltip
///
/// Gets or sets the tooltip for the command.
///
public string Tooltip
{
get
{
return this.tooltip;
}
set
{
this.tooltip = value;
this.FirePropertyChanged("Tooltip");
}
}
#endregion
#region Icon
///
/// Gets or sets the icon for the command.
///
public Image Icon
{
get
{
return this.icon;
}
set
{
this.icon = value;
this.FirePropertyChanged("Icon");
}
}
#endregion
#region Type
///
/// Gets the type of the command.
///
public PluginCommandType Type
{
get { return this.type; }
}
#endregion
#region Command
///
/// Gets or sets the command that will be run.
///
public EventHandler Command
{
get { return this.command; }
set { this.command = value; }
}
#endregion
#endregion
#region Public methods
#region Run()
///
/// Runs the command.
///
public void Run()
{
this.command(this, EventArgs.Empty);
}
#endregion
#region Remove()
///
/// Remove the command.
///
public void Remove()
{
if (this.Removed != null)
{
this.Removed(this, EventArgs.Empty);
}
}
#endregion
#endregion
#region Protected methods
#region FirePropertyChanged()
///
/// Firs the event.
///
/// The property that was changed.
protected void FirePropertyChanged(string property)
{
if (this.PropertyChanged != null)
{
var args = new PropertyChangedEventArgs(property);
this.PropertyChanged(this, args);
}
}
#endregion
#endregion
}
}