12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- using System;
- using System.ComponentModel;
- namespace InABox.Core
- {
- public class ButtonEditorCommandArgs : CancelEventArgs
- {
- public String Data { get; set; }
- }
- public delegate ButtonEditorCommand OnCommandCreated();
- public abstract class ButtonEditorCommand
- {
- public abstract void Execute(object sender, ButtonEditorCommandArgs args);
- }
- public class ButtonEditor : BaseEditor
- {
- private Type _commandtype;
- public event OnCommandCreated OnCommandCreate;
- public String Label { get; set; }
- public ButtonEditor(Type commandtype)
- {
- if (!typeof(ButtonEditorCommand).IsAssignableFrom(commandtype))
- throw new InvalidCastException("Command must be of type ButtonEditorCommand");
- _commandtype = commandtype;
- Label = "Edit";
- Alignment = Alignment.NotSet;
- }
- protected override BaseEditor DoClone()
- {
- return new ButtonEditor(_commandtype);
- }
- public ButtonEditorCommand? CreateCommand()
- {
- var delegatecommand = OnCommandCreate?.Invoke();
- if (delegatecommand != null)
- return delegatecommand;
- var command = Activator.CreateInstance(_commandtype) as ButtonEditorCommand;
- return command;
- }
- }
- }
|