2 using System.Collections.Generic;
3 using System.ComponentModel;
8 using System.Threading.Tasks;
9 using System.Windows.Forms;
11 namespace SharpDisplayManager
13 public partial class FormSelectHarmonyCommand : Form
15 public FormSelectHarmonyCommand()
17 InitializeComponent();
20 public string DeviceId;
21 public string FunctionName;
26 /// <param name="sender"></param>
27 /// <param name="e"></param>
28 private void FormSelectHarmonyCommand_Load(object sender, EventArgs e)
30 PopulateTreeViewHarmony(Program.HarmonyConfig);
36 /// <param name="aConfig"></param>
37 private void PopulateTreeViewHarmony(HarmonyHub.Config aConfig)
39 iTreeViewHarmony.Nodes.Clear();
41 foreach (HarmonyHub.Device device in aConfig.Devices)
43 TreeNode deviceNode = iTreeViewHarmony.Nodes.Add(device.Id, $"{device.Label} ({device.DeviceTypeDisplayName}/{device.Model})");
44 deviceNode.Tag = device;
46 foreach (HarmonyHub.ControlGroup cg in device.ControlGroups)
48 TreeNode cgNode = deviceNode.Nodes.Add(cg.Name);
51 foreach (HarmonyHub.Function f in cg.Functions)
53 TreeNode fNode = cgNode.Nodes.Add(f.Name);
59 //treeViewConfig.ExpandAll();
65 /// <param name="sender"></param>
66 /// <param name="e"></param>
67 private async void iTreeViewHarmony_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
69 //Upon function node double click we execute it, so that user can test
70 var tag = e.Node.Tag as HarmonyHub.Function;
71 if (tag != null && e.Node.Parent.Parent.Tag is HarmonyHub.Device)
73 HarmonyHub.Function f = tag;
74 HarmonyHub.Device d = (HarmonyHub.Device)e.Node.Parent.Parent.Tag;
76 Console.WriteLine($"Harmony: Sending {f.Name} to {d.Label}...");
78 await Program.HarmonyClient.SendCommandAsync(d.Id, f.Name);
85 /// <param name="sender"></param>
86 /// <param name="e"></param>
87 private void iTreeViewHarmony_AfterSelect(object sender, TreeViewEventArgs e)
89 //Enable ok button if a function is selected
90 iButtonOk.Enabled = e.Node.Tag is HarmonyHub.Function;
92 // Get selected device ID and function name
93 HarmonyHub.Function f = e.Node.Tag as HarmonyHub.Function;
94 if (f != null && e.Node.Parent.Parent.Tag is HarmonyHub.Device)
96 HarmonyHub.Device d = (HarmonyHub.Device)e.Node.Parent.Parent.Tag;
99 FunctionName = f.Name;