#develop (short for SharpDevelop) is a free IDE for .NET programming languages.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

83 lines
2.3 KiB

// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Windows.Forms;
namespace ICSharpCode.Core.WinForms
{
public class ToolBarCommand : ToolStripButton, IStatusUpdate
{
object caller;
Codon codon;
ICommand menuCommand = null;
public ToolBarCommand(Codon codon, object caller, bool createCommand)
{
this.RightToLeft = RightToLeft.Inherit;
this.caller = caller;
this.codon = codon;
if (createCommand) {
menuCommand = (ICommand)codon.AddIn.CreateObject(codon.Properties["class"]);
}
if (codon.Properties.Contains("label")){
Text = StringParser.Parse(codon.Properties["label"]);
}
if (Image == null && codon.Properties.Contains("icon")) {
Image = WinFormsResourceService.GetBitmap(StringParser.Parse(codon.Properties["icon"]));
}
UpdateStatus();
UpdateText();
}
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
if (menuCommand == null) {
menuCommand = (ICommand)codon.AddIn.CreateObject(codon.Properties["class"]);
}
if (menuCommand != null) {
menuCommand.Owner = caller;
AnalyticsMonitorService.TrackFeature(menuCommand.GetType().FullName, "Toolbar");
menuCommand.Run();
}
}
public virtual void UpdateStatus()
{
if (codon != null) {
ConditionFailedAction failedAction = codon.GetFailedAction(caller);
this.Visible = failedAction != ConditionFailedAction.Exclude;
bool isEnabled = failedAction != ConditionFailedAction.Disable;
if (isEnabled && menuCommand != null && menuCommand is IMenuCommand) {
isEnabled = ((IMenuCommand)menuCommand).IsEnabled;
}
this.Enabled = isEnabled;
if (this.Visible && codon.Properties.Contains("icon")) {
Image = WinFormsResourceService.GetBitmap(StringParser.Parse(codon.Properties["icon"]));
}
}
}
public virtual void UpdateText()
{
if (codon != null) {
if (codon.Properties.Contains("tooltip")) {
ToolTipText = StringParser.Parse(codon.Properties["tooltip"]);
}
if (codon.Properties.Contains("label")){
Text = StringParser.Parse(codon.Properties["label"]);
}
}
}
}
}