1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/Server/FormSelectHarmonyCommand.cs Sun Aug 21 18:35:58 2016 +0200
1.3 @@ -0,0 +1,109 @@
1.4 +using System;
1.5 +using System.Collections.Generic;
1.6 +using System.ComponentModel;
1.7 +using System.Data;
1.8 +using System.Drawing;
1.9 +using System.Linq;
1.10 +using System.Text;
1.11 +using System.Threading.Tasks;
1.12 +using System.Windows.Forms;
1.13 +
1.14 +namespace SharpDisplayManager
1.15 +{
1.16 + public partial class FormSelectHarmonyCommand : Form
1.17 + {
1.18 + public FormSelectHarmonyCommand()
1.19 + {
1.20 + InitializeComponent();
1.21 + }
1.22 +
1.23 + public string DeviceId;
1.24 + public string FunctionName;
1.25 +
1.26 + /// <summary>
1.27 + ///
1.28 + /// </summary>
1.29 + /// <param name="sender"></param>
1.30 + /// <param name="e"></param>
1.31 + private void FormSelectHarmonyCommand_Load(object sender, EventArgs e)
1.32 + {
1.33 + PopulateTreeViewHarmony(Program.HarmonyConfig);
1.34 + }
1.35 +
1.36 + /// <summary>
1.37 + ///
1.38 + /// </summary>
1.39 + /// <param name="aConfig"></param>
1.40 + private void PopulateTreeViewHarmony(HarmonyHub.Config aConfig)
1.41 + {
1.42 + iTreeViewHarmony.Nodes.Clear();
1.43 + //Add our devices
1.44 + foreach (HarmonyHub.Device device in aConfig.Devices)
1.45 + {
1.46 + TreeNode deviceNode = iTreeViewHarmony.Nodes.Add(device.Id, $"{device.Label} ({device.DeviceTypeDisplayName}/{device.Model})");
1.47 + deviceNode.Tag = device;
1.48 +
1.49 + foreach (HarmonyHub.ControlGroup cg in device.ControlGroups)
1.50 + {
1.51 + TreeNode cgNode = deviceNode.Nodes.Add(cg.Name);
1.52 + cgNode.Tag = cg;
1.53 +
1.54 + foreach (HarmonyHub.Function f in cg.Functions)
1.55 + {
1.56 + TreeNode fNode = cgNode.Nodes.Add(f.Name);
1.57 + fNode.Tag = f;
1.58 + }
1.59 + }
1.60 + }
1.61 +
1.62 + //treeViewConfig.ExpandAll();
1.63 + }
1.64 +
1.65 + /// <summary>
1.66 + ///
1.67 + /// </summary>
1.68 + /// <param name="sender"></param>
1.69 + /// <param name="e"></param>
1.70 + private async void iTreeViewHarmony_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
1.71 + {
1.72 + //Upon function node double click we execute it, so that user can test
1.73 + var tag = e.Node.Tag as HarmonyHub.Function;
1.74 + if (tag != null && e.Node.Parent.Parent.Tag is HarmonyHub.Device)
1.75 + {
1.76 + HarmonyHub.Function f = tag;
1.77 + HarmonyHub.Device d = (HarmonyHub.Device)e.Node.Parent.Parent.Tag;
1.78 +
1.79 + Console.WriteLine($"Harmony: Sending {f.Name} to {d.Label}...");
1.80 +
1.81 + await Program.HarmonyClient.SendCommandAsync(d.Id, f.Name);
1.82 + }
1.83 + }
1.84 +
1.85 + /// <summary>
1.86 + ///
1.87 + /// </summary>
1.88 + /// <param name="sender"></param>
1.89 + /// <param name="e"></param>
1.90 + private void iTreeViewHarmony_AfterSelect(object sender, TreeViewEventArgs e)
1.91 + {
1.92 + //Enable ok button if a function is selected
1.93 + iButtonOk.Enabled = e.Node.Tag is HarmonyHub.Function;
1.94 +
1.95 + // Get selected device ID and function name
1.96 + HarmonyHub.Function f = e.Node.Tag as HarmonyHub.Function;
1.97 + if (f != null && e.Node.Parent.Parent.Tag is HarmonyHub.Device)
1.98 + {
1.99 + HarmonyHub.Device d = (HarmonyHub.Device)e.Node.Parent.Parent.Tag;
1.100 +
1.101 + DeviceId = d.Id;
1.102 + FunctionName = f.Name;
1.103 + }
1.104 + else
1.105 + {
1.106 + DeviceId = "";
1.107 + FunctionName = "";
1.108 + }
1.109 +
1.110 + }
1.111 + }
1.112 +}