Adding user given name to EAR events and enabling User Events.
2 using System.Collections.Generic;
3 using System.Diagnostics;
4 using System.ComponentModel;
9 using System.Threading.Tasks;
10 using System.Windows.Forms;
12 namespace SharpDisplayManager
14 public partial class FormSelectHarmonyCommand : Form
16 public FormSelectHarmonyCommand()
18 InitializeComponent();
21 public string DeviceId;
22 public string Command;
27 /// <param name="sender"></param>
28 /// <param name="e"></param>
29 private void FormSelectHarmonyCommand_Load(object sender, EventArgs e)
31 PopulateTreeViewHarmony(Program.HarmonyConfig);
37 /// <param name="aConfig"></param>
38 private void PopulateTreeViewHarmony(HarmonyHub.Config aConfig)
40 iTreeViewHarmony.Nodes.Clear();
42 foreach (HarmonyHub.Device device in aConfig.Devices)
44 TreeNode deviceNode = iTreeViewHarmony.Nodes.Add(device.Id, $"{device.Label} ({device.DeviceTypeDisplayName}/{device.Model})");
45 deviceNode.Tag = device;
47 foreach (HarmonyHub.ControlGroup cg in device.ControlGroups)
49 TreeNode cgNode = deviceNode.Nodes.Add(cg.Name);
52 foreach (HarmonyHub.Function f in cg.Functions)
54 TreeNode fNode = cgNode.Nodes.Add(f.Label);
60 //treeViewConfig.ExpandAll();
66 /// <param name="sender"></param>
67 /// <param name="e"></param>
68 private async void iTreeViewHarmony_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
70 //Upon function node double click we execute it, so that user can test
71 var tag = e.Node.Tag as HarmonyHub.Function;
72 if (tag != null && e.Node.Parent.Parent.Tag is HarmonyHub.Device)
74 HarmonyHub.Function f = tag;
75 HarmonyHub.Device d = (HarmonyHub.Device)e.Node.Parent.Parent.Tag;
77 Trace.WriteLine($"Harmony: Sending {f.Label} to {d.Label}...");
79 await Program.HarmonyClient.TrySendKeyPressAsync(d.Id, f.Action.Command);
86 /// <param name="sender"></param>
87 /// <param name="e"></param>
88 private void iTreeViewHarmony_AfterSelect(object sender, TreeViewEventArgs e)
90 //Enable ok button if a function is selected
91 iButtonOk.Enabled = e.Node.Tag is HarmonyHub.Function;
93 // Get selected device ID and function name
94 HarmonyHub.Function f = e.Node.Tag as HarmonyHub.Function;
95 if (f != null && e.Node.Parent.Parent.Tag is HarmonyHub.Device)
97 HarmonyHub.Device d = (HarmonyHub.Device)e.Node.Parent.Parent.Tag;
100 Command = f.Action.Command;