StephaneLenclud@250: using System;
StephaneLenclud@250: using System.Collections.Generic;
StephaneLenclud@253: using System.Diagnostics;
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@262: using CodeProject.Dialog;
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@257: public string Command;
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@262: if (Program.HarmonyConfig != null)
StephaneLenclud@262: {
StephaneLenclud@262: PopulateTreeViewHarmony(Program.HarmonyConfig);
StephaneLenclud@262: }
StephaneLenclud@262: else
StephaneLenclud@262: {
StephaneLenclud@262: ErrBox.Show("No Harmony Hub configuration!");
StephaneLenclud@262: Close();
StephaneLenclud@262: }
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@257: TreeNode fNode = cgNode.Nodes.Add(f.Label);
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@257: Trace.WriteLine($"Harmony: Sending {f.Label} to {d.Label}...");
StephaneLenclud@250:
StephaneLenclud@257: await Program.HarmonyClient.TrySendKeyPressAsync(d.Id, f.Action.Command);
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@257: Command = f.Action.Command;
StephaneLenclud@250: }
StephaneLenclud@250: else
StephaneLenclud@250: {
StephaneLenclud@250: DeviceId = "";
StephaneLenclud@257: Command = "";
StephaneLenclud@250: }
StephaneLenclud@250:
StephaneLenclud@250: }
StephaneLenclud@250: }
StephaneLenclud@250: }