ButtonEditor.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.ComponentModel;
  3. namespace InABox.Core
  4. {
  5. public class ButtonEditorCommandArgs : CancelEventArgs
  6. {
  7. public String Data { get; set; }
  8. }
  9. public delegate ButtonEditorCommand OnCommandCreated();
  10. public abstract class ButtonEditorCommand
  11. {
  12. public abstract void Execute(object sender, ButtonEditorCommandArgs args);
  13. }
  14. public class ButtonEditor : BaseEditor
  15. {
  16. private Type _commandtype;
  17. public event OnCommandCreated OnCommandCreate;
  18. public String Label { get; set; }
  19. public ButtonEditor(Type commandtype)
  20. {
  21. if (!typeof(ButtonEditorCommand).IsAssignableFrom(commandtype))
  22. throw new InvalidCastException("Command must be of type ButtonEditorCommand");
  23. _commandtype = commandtype;
  24. Label = "Edit";
  25. Alignment = Alignment.NotSet;
  26. }
  27. protected override BaseEditor DoClone()
  28. {
  29. return new ButtonEditor(_commandtype);
  30. }
  31. public ButtonEditorCommand? CreateCommand()
  32. {
  33. var delegatecommand = OnCommandCreate?.Invoke();
  34. if (delegatecommand != null)
  35. return delegatecommand;
  36. var command = Activator.CreateInstance(_commandtype) as ButtonEditorCommand;
  37. return command;
  38. }
  39. }
  40. }