StephaneLenclud@250: using System;
StephaneLenclud@250: using System.Collections.Generic;
StephaneLenclud@250: using System.ComponentModel;
StephaneLenclud@250: using System.Data;
StephaneLenclud@250: using System.Drawing;
StephaneLenclud@250: using System.Linq;
StephaneLenclud@250: using System.Text;
StephaneLenclud@250: using System.Threading.Tasks;
StephaneLenclud@250: using System.Windows.Forms;
StephaneLenclud@250:
StephaneLenclud@250: namespace SharpDisplayManager
StephaneLenclud@250: {
StephaneLenclud@250: public partial class FormSelectHarmonyCommand : Form
StephaneLenclud@250: {
StephaneLenclud@250: public FormSelectHarmonyCommand()
StephaneLenclud@250: {
StephaneLenclud@250: InitializeComponent();
StephaneLenclud@250: }
StephaneLenclud@250:
StephaneLenclud@250: public string DeviceId;
StephaneLenclud@250: public string FunctionName;
StephaneLenclud@250:
StephaneLenclud@250: ///
StephaneLenclud@250: ///
StephaneLenclud@250: ///
StephaneLenclud@250: ///
StephaneLenclud@250: ///
StephaneLenclud@250: private void FormSelectHarmonyCommand_Load(object sender, EventArgs e)
StephaneLenclud@250: {
StephaneLenclud@250: PopulateTreeViewHarmony(Program.HarmonyConfig);
StephaneLenclud@250: }
StephaneLenclud@250:
StephaneLenclud@250: ///
StephaneLenclud@250: ///
StephaneLenclud@250: ///
StephaneLenclud@250: ///
StephaneLenclud@250: private void PopulateTreeViewHarmony(HarmonyHub.Config aConfig)
StephaneLenclud@250: {
StephaneLenclud@250: iTreeViewHarmony.Nodes.Clear();
StephaneLenclud@250: //Add our devices
StephaneLenclud@250: foreach (HarmonyHub.Device device in aConfig.Devices)
StephaneLenclud@250: {
StephaneLenclud@250: TreeNode deviceNode = iTreeViewHarmony.Nodes.Add(device.Id, $"{device.Label} ({device.DeviceTypeDisplayName}/{device.Model})");
StephaneLenclud@250: deviceNode.Tag = device;
StephaneLenclud@250:
StephaneLenclud@250: foreach (HarmonyHub.ControlGroup cg in device.ControlGroups)
StephaneLenclud@250: {
StephaneLenclud@250: TreeNode cgNode = deviceNode.Nodes.Add(cg.Name);
StephaneLenclud@250: cgNode.Tag = cg;
StephaneLenclud@250:
StephaneLenclud@250: foreach (HarmonyHub.Function f in cg.Functions)
StephaneLenclud@250: {
StephaneLenclud@250: TreeNode fNode = cgNode.Nodes.Add(f.Name);
StephaneLenclud@250: fNode.Tag = f;
StephaneLenclud@250: }
StephaneLenclud@250: }
StephaneLenclud@250: }
StephaneLenclud@250:
StephaneLenclud@250: //treeViewConfig.ExpandAll();
StephaneLenclud@250: }
StephaneLenclud@250:
StephaneLenclud@250: ///
StephaneLenclud@250: ///
StephaneLenclud@250: ///
StephaneLenclud@250: ///
StephaneLenclud@250: ///
StephaneLenclud@250: private async void iTreeViewHarmony_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
StephaneLenclud@250: {
StephaneLenclud@250: //Upon function node double click we execute it, so that user can test
StephaneLenclud@250: var tag = e.Node.Tag as HarmonyHub.Function;
StephaneLenclud@250: if (tag != null && e.Node.Parent.Parent.Tag is HarmonyHub.Device)
StephaneLenclud@250: {
StephaneLenclud@250: HarmonyHub.Function f = tag;
StephaneLenclud@250: HarmonyHub.Device d = (HarmonyHub.Device)e.Node.Parent.Parent.Tag;
StephaneLenclud@250:
StephaneLenclud@250: Console.WriteLine($"Harmony: Sending {f.Name} to {d.Label}...");
StephaneLenclud@250:
StephaneLenclud@250: await Program.HarmonyClient.SendCommandAsync(d.Id, f.Name);
StephaneLenclud@250: }
StephaneLenclud@250: }
StephaneLenclud@250:
StephaneLenclud@250: ///
StephaneLenclud@250: ///
StephaneLenclud@250: ///
StephaneLenclud@250: ///
StephaneLenclud@250: ///
StephaneLenclud@250: private void iTreeViewHarmony_AfterSelect(object sender, TreeViewEventArgs e)
StephaneLenclud@250: {
StephaneLenclud@250: //Enable ok button if a function is selected
StephaneLenclud@250: iButtonOk.Enabled = e.Node.Tag is HarmonyHub.Function;
StephaneLenclud@250:
StephaneLenclud@250: // Get selected device ID and function name
StephaneLenclud@250: HarmonyHub.Function f = e.Node.Tag as HarmonyHub.Function;
StephaneLenclud@250: if (f != null && e.Node.Parent.Parent.Tag is HarmonyHub.Device)
StephaneLenclud@250: {
StephaneLenclud@250: HarmonyHub.Device d = (HarmonyHub.Device)e.Node.Parent.Parent.Tag;
StephaneLenclud@250:
StephaneLenclud@250: DeviceId = d.Id;
StephaneLenclud@250: FunctionName = f.Name;
StephaneLenclud@250: }
StephaneLenclud@250: else
StephaneLenclud@250: {
StephaneLenclud@250: DeviceId = "";
StephaneLenclud@250: FunctionName = "";
StephaneLenclud@250: }
StephaneLenclud@250:
StephaneLenclud@250: }
StephaneLenclud@250: }
StephaneLenclud@250: }