Server/FormSelectHarmonyCommand.cs
author StephaneLenclud
Sun, 21 Aug 2016 19:31:08 +0200
changeset 251 f60cfcb98c9a
child 253 2dae7a163fff
permissions -rw-r--r--
Published v0.12.2.0
Adding setting for Logitech user name.
Improved event tree view update following Harmony connection.
Removed unneeded editable fields from Harmony command action.
     1 using System;
     2 using System.Collections.Generic;
     3 using System.ComponentModel;
     4 using System.Data;
     5 using System.Drawing;
     6 using System.Linq;
     7 using System.Text;
     8 using System.Threading.Tasks;
     9 using System.Windows.Forms;
    10 
    11 namespace SharpDisplayManager
    12 {
    13     public partial class FormSelectHarmonyCommand : Form
    14     {
    15         public FormSelectHarmonyCommand()
    16         {
    17             InitializeComponent();
    18         }
    19 
    20         public string DeviceId;
    21         public string FunctionName;
    22 
    23         /// <summary>
    24         /// 
    25         /// </summary>
    26         /// <param name="sender"></param>
    27         /// <param name="e"></param>
    28         private void FormSelectHarmonyCommand_Load(object sender, EventArgs e)
    29         {
    30             PopulateTreeViewHarmony(Program.HarmonyConfig);
    31         }
    32 
    33         /// <summary>
    34         /// 
    35         /// </summary>
    36         /// <param name="aConfig"></param>
    37         private void PopulateTreeViewHarmony(HarmonyHub.Config aConfig)
    38         {
    39             iTreeViewHarmony.Nodes.Clear();
    40             //Add our devices
    41             foreach (HarmonyHub.Device device in aConfig.Devices)
    42             {
    43                 TreeNode deviceNode = iTreeViewHarmony.Nodes.Add(device.Id, $"{device.Label} ({device.DeviceTypeDisplayName}/{device.Model})");
    44                 deviceNode.Tag = device;
    45 
    46                 foreach (HarmonyHub.ControlGroup cg in device.ControlGroups)
    47                 {
    48                     TreeNode cgNode = deviceNode.Nodes.Add(cg.Name);
    49                     cgNode.Tag = cg;
    50 
    51                     foreach (HarmonyHub.Function f in cg.Functions)
    52                     {
    53                         TreeNode fNode = cgNode.Nodes.Add(f.Name);
    54                         fNode.Tag = f;
    55                     }
    56                 }
    57             }
    58 
    59             //treeViewConfig.ExpandAll();
    60         }
    61 
    62         /// <summary>
    63         /// 
    64         /// </summary>
    65         /// <param name="sender"></param>
    66         /// <param name="e"></param>
    67         private async void iTreeViewHarmony_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
    68         {
    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)
    72             {
    73                 HarmonyHub.Function f = tag;
    74                 HarmonyHub.Device d = (HarmonyHub.Device)e.Node.Parent.Parent.Tag;
    75 
    76                 Console.WriteLine($"Harmony: Sending {f.Name} to {d.Label}...");
    77 
    78                 await Program.HarmonyClient.SendCommandAsync(d.Id, f.Name);
    79             }
    80         }
    81 
    82         /// <summary>
    83         /// 
    84         /// </summary>
    85         /// <param name="sender"></param>
    86         /// <param name="e"></param>
    87         private void iTreeViewHarmony_AfterSelect(object sender, TreeViewEventArgs e)
    88         {
    89             //Enable ok button if a function is selected
    90             iButtonOk.Enabled = e.Node.Tag is HarmonyHub.Function;
    91 
    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)
    95             {
    96                 HarmonyHub.Device d = (HarmonyHub.Device)e.Node.Parent.Parent.Tag;
    97 
    98                 DeviceId = d.Id;
    99                 FunctionName = f.Name;
   100             }
   101             else
   102             {
   103                 DeviceId = "";
   104                 FunctionName = "";
   105             }
   106 
   107         }
   108     }
   109 }