author | Stephane Lenclud |
Mon, 22 Aug 2016 13:20:54 +0200 | |
changeset 252 | 59ea5cb46258 |
child 253 | 2dae7a163fff |
permissions | -rw-r--r-- |
StephaneLenclud@250 | 1 |
using System; |
StephaneLenclud@250 | 2 |
using System.Collections.Generic; |
StephaneLenclud@250 | 3 |
using System.ComponentModel; |
StephaneLenclud@250 | 4 |
using System.Data; |
StephaneLenclud@250 | 5 |
using System.Drawing; |
StephaneLenclud@250 | 6 |
using System.Linq; |
StephaneLenclud@250 | 7 |
using System.Text; |
StephaneLenclud@250 | 8 |
using System.Threading.Tasks; |
StephaneLenclud@250 | 9 |
using System.Windows.Forms; |
StephaneLenclud@250 | 10 |
|
StephaneLenclud@250 | 11 |
namespace SharpDisplayManager |
StephaneLenclud@250 | 12 |
{ |
StephaneLenclud@250 | 13 |
public partial class FormSelectHarmonyCommand : Form |
StephaneLenclud@250 | 14 |
{ |
StephaneLenclud@250 | 15 |
public FormSelectHarmonyCommand() |
StephaneLenclud@250 | 16 |
{ |
StephaneLenclud@250 | 17 |
InitializeComponent(); |
StephaneLenclud@250 | 18 |
} |
StephaneLenclud@250 | 19 |
|
StephaneLenclud@250 | 20 |
public string DeviceId; |
StephaneLenclud@250 | 21 |
public string FunctionName; |
StephaneLenclud@250 | 22 |
|
StephaneLenclud@250 | 23 |
/// <summary> |
StephaneLenclud@250 | 24 |
/// |
StephaneLenclud@250 | 25 |
/// </summary> |
StephaneLenclud@250 | 26 |
/// <param name="sender"></param> |
StephaneLenclud@250 | 27 |
/// <param name="e"></param> |
StephaneLenclud@250 | 28 |
private void FormSelectHarmonyCommand_Load(object sender, EventArgs e) |
StephaneLenclud@250 | 29 |
{ |
StephaneLenclud@250 | 30 |
PopulateTreeViewHarmony(Program.HarmonyConfig); |
StephaneLenclud@250 | 31 |
} |
StephaneLenclud@250 | 32 |
|
StephaneLenclud@250 | 33 |
/// <summary> |
StephaneLenclud@250 | 34 |
/// |
StephaneLenclud@250 | 35 |
/// </summary> |
StephaneLenclud@250 | 36 |
/// <param name="aConfig"></param> |
StephaneLenclud@250 | 37 |
private void PopulateTreeViewHarmony(HarmonyHub.Config aConfig) |
StephaneLenclud@250 | 38 |
{ |
StephaneLenclud@250 | 39 |
iTreeViewHarmony.Nodes.Clear(); |
StephaneLenclud@250 | 40 |
//Add our devices |
StephaneLenclud@250 | 41 |
foreach (HarmonyHub.Device device in aConfig.Devices) |
StephaneLenclud@250 | 42 |
{ |
StephaneLenclud@250 | 43 |
TreeNode deviceNode = iTreeViewHarmony.Nodes.Add(device.Id, $"{device.Label} ({device.DeviceTypeDisplayName}/{device.Model})"); |
StephaneLenclud@250 | 44 |
deviceNode.Tag = device; |
StephaneLenclud@250 | 45 |
|
StephaneLenclud@250 | 46 |
foreach (HarmonyHub.ControlGroup cg in device.ControlGroups) |
StephaneLenclud@250 | 47 |
{ |
StephaneLenclud@250 | 48 |
TreeNode cgNode = deviceNode.Nodes.Add(cg.Name); |
StephaneLenclud@250 | 49 |
cgNode.Tag = cg; |
StephaneLenclud@250 | 50 |
|
StephaneLenclud@250 | 51 |
foreach (HarmonyHub.Function f in cg.Functions) |
StephaneLenclud@250 | 52 |
{ |
StephaneLenclud@250 | 53 |
TreeNode fNode = cgNode.Nodes.Add(f.Name); |
StephaneLenclud@250 | 54 |
fNode.Tag = f; |
StephaneLenclud@250 | 55 |
} |
StephaneLenclud@250 | 56 |
} |
StephaneLenclud@250 | 57 |
} |
StephaneLenclud@250 | 58 |
|
StephaneLenclud@250 | 59 |
//treeViewConfig.ExpandAll(); |
StephaneLenclud@250 | 60 |
} |
StephaneLenclud@250 | 61 |
|
StephaneLenclud@250 | 62 |
/// <summary> |
StephaneLenclud@250 | 63 |
/// |
StephaneLenclud@250 | 64 |
/// </summary> |
StephaneLenclud@250 | 65 |
/// <param name="sender"></param> |
StephaneLenclud@250 | 66 |
/// <param name="e"></param> |
StephaneLenclud@250 | 67 |
private async void iTreeViewHarmony_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) |
StephaneLenclud@250 | 68 |
{ |
StephaneLenclud@250 | 69 |
//Upon function node double click we execute it, so that user can test |
StephaneLenclud@250 | 70 |
var tag = e.Node.Tag as HarmonyHub.Function; |
StephaneLenclud@250 | 71 |
if (tag != null && e.Node.Parent.Parent.Tag is HarmonyHub.Device) |
StephaneLenclud@250 | 72 |
{ |
StephaneLenclud@250 | 73 |
HarmonyHub.Function f = tag; |
StephaneLenclud@250 | 74 |
HarmonyHub.Device d = (HarmonyHub.Device)e.Node.Parent.Parent.Tag; |
StephaneLenclud@250 | 75 |
|
StephaneLenclud@250 | 76 |
Console.WriteLine($"Harmony: Sending {f.Name} to {d.Label}..."); |
StephaneLenclud@250 | 77 |
|
StephaneLenclud@250 | 78 |
await Program.HarmonyClient.SendCommandAsync(d.Id, f.Name); |
StephaneLenclud@250 | 79 |
} |
StephaneLenclud@250 | 80 |
} |
StephaneLenclud@250 | 81 |
|
StephaneLenclud@250 | 82 |
/// <summary> |
StephaneLenclud@250 | 83 |
/// |
StephaneLenclud@250 | 84 |
/// </summary> |
StephaneLenclud@250 | 85 |
/// <param name="sender"></param> |
StephaneLenclud@250 | 86 |
/// <param name="e"></param> |
StephaneLenclud@250 | 87 |
private void iTreeViewHarmony_AfterSelect(object sender, TreeViewEventArgs e) |
StephaneLenclud@250 | 88 |
{ |
StephaneLenclud@250 | 89 |
//Enable ok button if a function is selected |
StephaneLenclud@250 | 90 |
iButtonOk.Enabled = e.Node.Tag is HarmonyHub.Function; |
StephaneLenclud@250 | 91 |
|
StephaneLenclud@250 | 92 |
// Get selected device ID and function name |
StephaneLenclud@250 | 93 |
HarmonyHub.Function f = e.Node.Tag as HarmonyHub.Function; |
StephaneLenclud@250 | 94 |
if (f != null && e.Node.Parent.Parent.Tag is HarmonyHub.Device) |
StephaneLenclud@250 | 95 |
{ |
StephaneLenclud@250 | 96 |
HarmonyHub.Device d = (HarmonyHub.Device)e.Node.Parent.Parent.Tag; |
StephaneLenclud@250 | 97 |
|
StephaneLenclud@250 | 98 |
DeviceId = d.Id; |
StephaneLenclud@250 | 99 |
FunctionName = f.Name; |
StephaneLenclud@250 | 100 |
} |
StephaneLenclud@250 | 101 |
else |
StephaneLenclud@250 | 102 |
{ |
StephaneLenclud@250 | 103 |
DeviceId = ""; |
StephaneLenclud@250 | 104 |
FunctionName = ""; |
StephaneLenclud@250 | 105 |
} |
StephaneLenclud@250 | 106 |
|
StephaneLenclud@250 | 107 |
} |
StephaneLenclud@250 | 108 |
} |
StephaneLenclud@250 | 109 |
} |