EditorButton.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. namespace InABox.Core
  2. {
  3. public delegate void EditorButtonClick(object editor, object? item);
  4. public delegate void EditorButtonClick<T>(object editor, T? item) where T : class;
  5. public delegate void EditorButtonEnabled(bool enabled);
  6. public class EditorButton
  7. {
  8. public EditorButton(object? item, string caption, int width, EditorButtonClick onclick, bool disableeditor)
  9. {
  10. Width = width;
  11. Caption = caption;
  12. OnClick = onclick;
  13. Item = item;
  14. DisableEditor = disableeditor;
  15. IsEnabled = true;
  16. }
  17. public int Width { get; }
  18. public string Caption { get; }
  19. public object? Item { get; }
  20. public bool DisableEditor { get; }
  21. public bool IsEnabled { get; private set; }
  22. public event EditorButtonClick OnClick;
  23. public event EditorButtonEnabled OnEnabled;
  24. public void Click(object editor)
  25. {
  26. if (IsEnabled)
  27. {
  28. OnClick?.Invoke(editor, Item);
  29. }
  30. }
  31. public void SetEnabled(bool enabled)
  32. {
  33. IsEnabled = enabled;
  34. OnEnabled?.Invoke(enabled);
  35. }
  36. }
  37. }