ButtonEditor.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 abstract class ButtonEditorCommand
  10. {
  11. public abstract void Execute(object sender, ButtonEditorCommandArgs args);
  12. }
  13. public class ButtonEditor : BaseEditor
  14. {
  15. private Type _commandtype;
  16. public String Label { get; set; }
  17. public ButtonEditor(Type commandtype)
  18. {
  19. if (!typeof(ButtonEditorCommand).IsAssignableFrom(commandtype))
  20. throw new InvalidCastException("Command must be of type ButtonEditorCommand");
  21. _commandtype = commandtype;
  22. Label = "Edit";
  23. Alignment = Alignment.NotSet;
  24. }
  25. protected override BaseEditor DoClone()
  26. {
  27. return new ButtonEditor(_commandtype);
  28. }
  29. public ButtonEditorCommand? CreateCommand() => Activator.CreateInstance(_commandtype) as ButtonEditorCommand;
  30. }
  31. }