1.1 --- a/Server/Actions/ActionHarmonyCommand.cs Sun Aug 21 16:35:20 2016 +0200
1.2 +++ b/Server/Actions/ActionHarmonyCommand.cs Sun Aug 21 18:35:58 2016 +0200
1.3 @@ -6,6 +6,7 @@
1.4 using System.Text;
1.5 using System.Threading.Tasks;
1.6 using System.Runtime.Serialization;
1.7 +using System.Windows.Forms;
1.8
1.9 namespace SharpDisplayManager
1.10 {
1.11 @@ -30,6 +31,14 @@
1.12 )]
1.13 public string FunctionName { get; set; } = "";
1.14
1.15 + [DataMember]
1.16 + [AttributeObjectProperty(
1.17 + Id = "Harmony.Command.SelectCommand",
1.18 + Name = "Select command",
1.19 + Description = "Click to select a command."
1.20 + )]
1.21 + public PropertyButton SelectCommand { get; set; } = new PropertyButton { Text = "None" };
1.22 +
1.23 /// <summary>
1.24 ///
1.25 /// </summary>
1.26 @@ -54,6 +63,18 @@
1.27 return brief;
1.28 }
1.29
1.30 +
1.31 + protected override void DoConstruct()
1.32 + {
1.33 + base.DoConstruct();
1.34 +
1.35 + if (SelectCommand == null)
1.36 + {
1.37 + SelectCommand = new PropertyButton { Text = "None"};
1.38 + }
1.39 + SelectCommand.ClickEventHandler = ClickEventHandler;
1.40 + }
1.41 +
1.42 /// <summary>
1.43 ///
1.44 /// </summary>
1.45 @@ -72,5 +93,52 @@
1.46
1.47 }
1.48
1.49 +
1.50 + /// <summary>
1.51 + ///
1.52 + /// </summary>
1.53 + /// <returns></returns>
1.54 + public override bool IsValid()
1.55 + {
1.56 + if (Program.HarmonyConfig != null)
1.57 + {
1.58 + foreach (HarmonyHub.Device d in Program.HarmonyConfig.Devices)
1.59 + {
1.60 + if (d.Id.Equals(DeviceId))
1.61 + {
1.62 + foreach (HarmonyHub.ControlGroup cg in d.ControlGroups)
1.63 + {
1.64 + foreach (HarmonyHub.Function f in cg.Functions)
1.65 + {
1.66 + if (f.Name.Equals(FunctionName))
1.67 + {
1.68 + //We found our device and our function
1.69 + return true;
1.70 + }
1.71 + }
1.72 + }
1.73 + }
1.74 + }
1.75 + }
1.76 +
1.77 + return false;
1.78 + }
1.79 +
1.80 +
1.81 + void ClickEventHandler(object sender, EventArgs e)
1.82 + {
1.83 + FormSelectHarmonyCommand dlg = new FormSelectHarmonyCommand();
1.84 + DialogResult res = CodeProject.Dialog.DlgBox.ShowDialog(dlg);
1.85 + if (res == DialogResult.OK)
1.86 + {
1.87 + DeviceId = dlg.DeviceId;
1.88 + FunctionName = dlg.FunctionName;
1.89 + SelectCommand.Text = Brief();
1.90 + //Tell observer the object itself changed
1.91 + OnPropertyChanged("Brief");
1.92 + }
1.93 +
1.94 + }
1.95 +
1.96 }
1.97 }