|
|
|
@ -12,39 +12,6 @@ namespace Perspex |
|
|
|
using System.Reactive.Disposables; |
|
|
|
using Perspex.Controls; |
|
|
|
|
|
|
|
internal class SetterSubject : IObservable<object> |
|
|
|
{ |
|
|
|
private Control control; |
|
|
|
|
|
|
|
private object onValue; |
|
|
|
|
|
|
|
private object offValue; |
|
|
|
|
|
|
|
private List<IObserver<object>> observers; |
|
|
|
|
|
|
|
public SetterSubject(Control control, object onValue, object offValue) |
|
|
|
{ |
|
|
|
this.control = control; |
|
|
|
this.onValue = onValue; |
|
|
|
this.offValue = offValue; |
|
|
|
this.observers = new List<IObserver<object>>(); |
|
|
|
} |
|
|
|
|
|
|
|
public IDisposable Subscribe(IObserver<object> observer) |
|
|
|
{ |
|
|
|
observers.Add(observer); |
|
|
|
return Disposable.Create(() => this.observers.Remove(observer)); |
|
|
|
} |
|
|
|
|
|
|
|
public void Push(bool on) |
|
|
|
{ |
|
|
|
foreach (IObserver<object> o in this.observers) |
|
|
|
{ |
|
|
|
o.OnNext(on ? this.onValue : this.offValue); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public class Setter |
|
|
|
{ |
|
|
|
private object oldValue; |
|
|
|
@ -61,10 +28,43 @@ namespace Perspex |
|
|
|
set; |
|
|
|
} |
|
|
|
|
|
|
|
internal SetterSubject CreateSubject(Control control) |
|
|
|
internal Subject CreateSubject(Control control) |
|
|
|
{ |
|
|
|
object oldValue = control.GetValue(this.Property); |
|
|
|
return new SetterSubject(control, this.Value, oldValue); |
|
|
|
return new Subject(control, this.Value, oldValue); |
|
|
|
} |
|
|
|
|
|
|
|
internal class Subject : IObservable<object> |
|
|
|
{ |
|
|
|
private Control control; |
|
|
|
|
|
|
|
private object onValue; |
|
|
|
|
|
|
|
private object offValue; |
|
|
|
|
|
|
|
private List<IObserver<object>> observers; |
|
|
|
|
|
|
|
public Subject(Control control, object onValue, object offValue) |
|
|
|
{ |
|
|
|
this.control = control; |
|
|
|
this.onValue = onValue; |
|
|
|
this.offValue = offValue; |
|
|
|
this.observers = new List<IObserver<object>>(); |
|
|
|
} |
|
|
|
|
|
|
|
public IDisposable Subscribe(IObserver<object> observer) |
|
|
|
{ |
|
|
|
observers.Add(observer); |
|
|
|
return Disposable.Create(() => this.observers.Remove(observer)); |
|
|
|
} |
|
|
|
|
|
|
|
public void Push(bool on) |
|
|
|
{ |
|
|
|
foreach (IObserver<object> o in this.observers) |
|
|
|
{ |
|
|
|
o.OnNext(on ? this.onValue : this.offValue); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|