2014-10-29 11:46:10 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
|
2014-10-29 09:40:50 -07:00
|
|
|
|
namespace MatterHackers.MatterControl
|
|
|
|
|
|
{
|
2015-04-08 15:20:10 -07:00
|
|
|
|
public class ConditionalClickWidget : ClickWidget
|
|
|
|
|
|
{
|
|
|
|
|
|
private Func<bool> enabledCallback;
|
2014-10-29 09:40:50 -07:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
public ConditionalClickWidget(Func<bool> enabledCallback)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.enabledCallback = enabledCallback;
|
|
|
|
|
|
}
|
2014-10-29 09:40:50 -07:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
// The ConditionalClickWidget provides a mechanism that allows the Enable property to be bound
|
|
|
|
|
|
// to a Delegate that resolves the value. This is a readonly value supplied via the constructor
|
|
|
|
|
|
// and should not be assigned after construction
|
|
|
|
|
|
public override bool Enabled
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return this.enabledCallback();
|
|
|
|
|
|
}
|
2014-10-29 09:40:50 -07:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine("Attempted to set readonly Enabled property on ConditionalClickWidget");
|
2014-10-29 12:31:37 -07:00
|
|
|
|
#if DEBUG
|
2015-04-08 15:20:10 -07:00
|
|
|
|
throw new InvalidOperationException("Cannot set Enabled on ConditionalClickWidget");
|
2014-10-29 12:31:37 -07:00
|
|
|
|
#endif
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|