BoolParam.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace RecipeEditorLib.RecipeModel.Params
  8. {
  9. public class BoolParam : Param
  10. {
  11. public delegate void ValueChangedEventHandler(object sender, SetValueEventArgs e);
  12. public event ValueChangedEventHandler ValueChangedEvent;
  13. public BoolParam() : base()
  14. {
  15. e.Sender = this;
  16. e.PropertyName = Name;
  17. }
  18. private SetValueEventArgs e = new SetValueEventArgs();
  19. public void OnValueChanged(SetValueEventArgs e)
  20. {
  21. if (ValueChangedEvent != null)
  22. {
  23. ValueChangedEvent(this, e);
  24. }
  25. }
  26. private bool _oldValue;
  27. public bool OldValue
  28. {
  29. get => _oldValue;
  30. set
  31. {
  32. _oldValue = value;
  33. NotifyOfPropertyChange("OldValue");
  34. }
  35. }
  36. private bool _value;
  37. public bool Value
  38. {
  39. get { return this._value; }
  40. set
  41. {
  42. this._value = value;
  43. if (IsSaved)
  44. {
  45. OldValue = value;
  46. }
  47. e.PropertyValue = value.ToString();
  48. if (!IsSaved)
  49. OnValueChanged(e);
  50. if (this.Feedback != null)
  51. this.Feedback(this);
  52. this.NotifyOfPropertyChange("Value");
  53. }
  54. }
  55. public void SetValue(bool value)
  56. {
  57. OldValue= Value;
  58. IsSaved = false;
  59. Value = value;
  60. }
  61. public override bool UndoChanges()
  62. {
  63. Value = OldValue;
  64. IsSaved = true;
  65. return true;
  66. }
  67. }
  68. }