# HG changeset patch
# User StephaneLenclud
# Date 1471797358 -7200
# Node ID b2121d03f6f03907dcf9546b0c48a4dfc13dddee
# Parent cadc4e4302c6ab2d29c1abfecec561d0a57eebca
Adding Harmony command selection dialog.
diff -r cadc4e4302c6 -r b2121d03f6f0 Server/Actions/ActionHarmonyCommand.cs
--- a/Server/Actions/ActionHarmonyCommand.cs Sun Aug 21 16:35:20 2016 +0200
+++ b/Server/Actions/ActionHarmonyCommand.cs Sun Aug 21 18:35:58 2016 +0200
@@ -6,6 +6,7 @@
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
+using System.Windows.Forms;
namespace SharpDisplayManager
{
@@ -30,6 +31,14 @@
)]
public string FunctionName { get; set; } = "";
+ [DataMember]
+ [AttributeObjectProperty(
+ Id = "Harmony.Command.SelectCommand",
+ Name = "Select command",
+ Description = "Click to select a command."
+ )]
+ public PropertyButton SelectCommand { get; set; } = new PropertyButton { Text = "None" };
+
///
///
///
@@ -54,6 +63,18 @@
return brief;
}
+
+ protected override void DoConstruct()
+ {
+ base.DoConstruct();
+
+ if (SelectCommand == null)
+ {
+ SelectCommand = new PropertyButton { Text = "None"};
+ }
+ SelectCommand.ClickEventHandler = ClickEventHandler;
+ }
+
///
///
///
@@ -72,5 +93,52 @@
}
+
+ ///
+ ///
+ ///
+ ///
+ public override bool IsValid()
+ {
+ if (Program.HarmonyConfig != null)
+ {
+ foreach (HarmonyHub.Device d in Program.HarmonyConfig.Devices)
+ {
+ if (d.Id.Equals(DeviceId))
+ {
+ foreach (HarmonyHub.ControlGroup cg in d.ControlGroups)
+ {
+ foreach (HarmonyHub.Function f in cg.Functions)
+ {
+ if (f.Name.Equals(FunctionName))
+ {
+ //We found our device and our function
+ return true;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return false;
+ }
+
+
+ void ClickEventHandler(object sender, EventArgs e)
+ {
+ FormSelectHarmonyCommand dlg = new FormSelectHarmonyCommand();
+ DialogResult res = CodeProject.Dialog.DlgBox.ShowDialog(dlg);
+ if (res == DialogResult.OK)
+ {
+ DeviceId = dlg.DeviceId;
+ FunctionName = dlg.FunctionName;
+ SelectCommand.Text = Brief();
+ //Tell observer the object itself changed
+ OnPropertyChanged("Brief");
+ }
+
+ }
+
}
}
diff -r cadc4e4302c6 -r b2121d03f6f0 Server/FormEditObject.cs
--- a/Server/FormEditObject.cs Sun Aug 21 16:35:20 2016 +0200
+++ b/Server/FormEditObject.cs Sun Aug 21 18:35:58 2016 +0200
@@ -196,6 +196,12 @@
//Not strictly needed but makes sure the set method is called
aInfo.SetValue(aObject, value);
}
+ else if (aInfo.PropertyType == typeof(PropertyButton))
+ {
+ Button ctrl = (Button)aControl;
+ PropertyButton value = new PropertyButton { Text = ctrl.Text };
+ aInfo.SetValue(aObject, value);
+ }
//TODO: add support for other types here
}
@@ -324,6 +330,20 @@
//
return ctrl;
}
+ else if (aInfo.PropertyType == typeof(PropertyButton))
+ {
+ // We have a button property
+ // Create a button that will trigger the custom action.
+ Button ctrl = new Button();
+ ctrl.AutoSize = true;
+ ctrl.Text = ((PropertyButton)aInfo.GetValue(aObject)).Text;
+ // Hook in click event
+ ctrl.Click += ((PropertyButton)aInfo.GetValue(aObject)).ClickEventHandler;
+ // Hook-in change notification after setting the value
+ ctrl.TextChanged += ControlValueChanged;
+ return ctrl;
+ }
+
//TODO: add support for other control type here
return null;
}
@@ -358,6 +378,10 @@
{
return true;
}
+ else if (aInfo.PropertyType == typeof(PropertyButton))
+ {
+ return true;
+ }
//TODO: add support for other type here
@@ -465,7 +489,17 @@
// Our object has changed behind our back.
// That's currently only the case for HID events that are listening for inputs.
- UpdateStaticControls();
+ if (Object is EventHid)
+ {
+ //HID can't do full control updates for some reason
+ //We are getting spammed with HID events after a few clicks
+ //We need to investigate, HID bug?
+ UpdateStaticControls();
+ }
+ else
+ {
+ UpdateControls();
+ }
}
}
diff -r cadc4e4302c6 -r b2121d03f6f0 Server/FormMain.cs
--- a/Server/FormMain.cs Sun Aug 21 16:35:20 2016 +0200
+++ b/Server/FormMain.cs Sun Aug 21 18:35:58 2016 +0200
@@ -2576,6 +2576,8 @@
try
{
await ConnectHarmonyAsync();
+ //To make sure harmony commands are showing device name instead of device id
+ PopulateEventsTreeView();
}
finally
{
@@ -2892,6 +2894,11 @@
}
}
+ ///
+ ///
+ ///
+ ///
+ ///
private void buttonEventAdd_Click(object sender, EventArgs e)
{
FormEditObject ea = new FormEditObject();
@@ -2906,6 +2913,11 @@
}
}
+ ///
+ ///
+ ///
+ ///
+ ///
private void buttonEventDelete_Click(object sender, EventArgs e)
{
Ear.Event currentEvent = CurrentEvent();
@@ -2920,6 +2932,11 @@
PopulateEventsTreeView();
}
+ ///
+ ///
+ ///
+ ///
+ ///
private void buttonEventEdit_Click(object sender, EventArgs e)
{
Ear.Event selectedEvent = CurrentEvent();
@@ -2946,12 +2963,22 @@
}
}
+ ///
+ ///
+ ///
+ ///
+ ///
private void iTreeViewEvents_Leave(object sender, EventArgs e)
{
//Make sure our event tree never looses focus
((TreeView) sender).Focus();
}
+ ///
+ ///
+ ///
+ ///
+ ///
private async void iButtonHarmonyConnect_Click(object sender, EventArgs e)
{
//Save hub address
@@ -2970,7 +2997,10 @@
}
-
+ ///
+ ///
+ ///
+ ///
private async Task ConnectHarmonyAsync()
{
if (Program.HarmonyClient != null)
diff -r cadc4e4302c6 -r b2121d03f6f0 Server/FormSelectHarmonyCommand.Designer.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Server/FormSelectHarmonyCommand.Designer.cs Sun Aug 21 18:35:58 2016 +0200
@@ -0,0 +1,94 @@
+namespace SharpDisplayManager
+{
+ partial class FormSelectHarmonyCommand
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.iTreeViewHarmony = new System.Windows.Forms.TreeView();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.iButtonOk = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // iTreeViewHarmony
+ //
+ this.iTreeViewHarmony.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.iTreeViewHarmony.Location = new System.Drawing.Point(12, 12);
+ this.iTreeViewHarmony.Name = "iTreeViewHarmony";
+ this.iTreeViewHarmony.Size = new System.Drawing.Size(302, 317);
+ this.iTreeViewHarmony.TabIndex = 0;
+ this.iTreeViewHarmony.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.iTreeViewHarmony_AfterSelect);
+ this.iTreeViewHarmony.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.iTreeViewHarmony_NodeMouseDoubleClick);
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
+ this.buttonCancel.Location = new System.Drawing.Point(93, 335);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(75, 23);
+ this.buttonCancel.TabIndex = 24;
+ this.buttonCancel.Text = "Cancel";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ //
+ // iButtonOk
+ //
+ this.iButtonOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.iButtonOk.DialogResult = System.Windows.Forms.DialogResult.OK;
+ this.iButtonOk.Enabled = false;
+ this.iButtonOk.Location = new System.Drawing.Point(12, 335);
+ this.iButtonOk.Name = "iButtonOk";
+ this.iButtonOk.Size = new System.Drawing.Size(75, 23);
+ this.iButtonOk.TabIndex = 23;
+ this.iButtonOk.Text = "Ok";
+ this.iButtonOk.UseVisualStyleBackColor = true;
+ //
+ // FormSelectHarmonyCommand
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(326, 370);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.iButtonOk);
+ this.Controls.Add(this.iTreeViewHarmony);
+ this.MaximizeBox = false;
+ this.MinimizeBox = false;
+ this.Name = "FormSelectHarmonyCommand";
+ this.Text = "Select command";
+ this.Load += new System.EventHandler(this.FormSelectHarmonyCommand_Load);
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.TreeView iTreeViewHarmony;
+ private System.Windows.Forms.Button buttonCancel;
+ private System.Windows.Forms.Button iButtonOk;
+ }
+}
\ No newline at end of file
diff -r cadc4e4302c6 -r b2121d03f6f0 Server/FormSelectHarmonyCommand.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Server/FormSelectHarmonyCommand.cs Sun Aug 21 18:35:58 2016 +0200
@@ -0,0 +1,109 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace SharpDisplayManager
+{
+ public partial class FormSelectHarmonyCommand : Form
+ {
+ public FormSelectHarmonyCommand()
+ {
+ InitializeComponent();
+ }
+
+ public string DeviceId;
+ public string FunctionName;
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ private void FormSelectHarmonyCommand_Load(object sender, EventArgs e)
+ {
+ PopulateTreeViewHarmony(Program.HarmonyConfig);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ private void PopulateTreeViewHarmony(HarmonyHub.Config aConfig)
+ {
+ iTreeViewHarmony.Nodes.Clear();
+ //Add our devices
+ foreach (HarmonyHub.Device device in aConfig.Devices)
+ {
+ TreeNode deviceNode = iTreeViewHarmony.Nodes.Add(device.Id, $"{device.Label} ({device.DeviceTypeDisplayName}/{device.Model})");
+ deviceNode.Tag = device;
+
+ foreach (HarmonyHub.ControlGroup cg in device.ControlGroups)
+ {
+ TreeNode cgNode = deviceNode.Nodes.Add(cg.Name);
+ cgNode.Tag = cg;
+
+ foreach (HarmonyHub.Function f in cg.Functions)
+ {
+ TreeNode fNode = cgNode.Nodes.Add(f.Name);
+ fNode.Tag = f;
+ }
+ }
+ }
+
+ //treeViewConfig.ExpandAll();
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ private async void iTreeViewHarmony_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
+ {
+ //Upon function node double click we execute it, so that user can test
+ var tag = e.Node.Tag as HarmonyHub.Function;
+ if (tag != null && e.Node.Parent.Parent.Tag is HarmonyHub.Device)
+ {
+ HarmonyHub.Function f = tag;
+ HarmonyHub.Device d = (HarmonyHub.Device)e.Node.Parent.Parent.Tag;
+
+ Console.WriteLine($"Harmony: Sending {f.Name} to {d.Label}...");
+
+ await Program.HarmonyClient.SendCommandAsync(d.Id, f.Name);
+ }
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ private void iTreeViewHarmony_AfterSelect(object sender, TreeViewEventArgs e)
+ {
+ //Enable ok button if a function is selected
+ iButtonOk.Enabled = e.Node.Tag is HarmonyHub.Function;
+
+ // Get selected device ID and function name
+ HarmonyHub.Function f = e.Node.Tag as HarmonyHub.Function;
+ if (f != null && e.Node.Parent.Parent.Tag is HarmonyHub.Device)
+ {
+ HarmonyHub.Device d = (HarmonyHub.Device)e.Node.Parent.Parent.Tag;
+
+ DeviceId = d.Id;
+ FunctionName = f.Name;
+ }
+ else
+ {
+ DeviceId = "";
+ FunctionName = "";
+ }
+
+ }
+ }
+}
diff -r cadc4e4302c6 -r b2121d03f6f0 Server/FormSelectHarmonyCommand.resx
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Server/FormSelectHarmonyCommand.resx Sun Aug 21 18:35:58 2016 +0200
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff -r cadc4e4302c6 -r b2121d03f6f0 Server/SharpDisplayManager.csproj
--- a/Server/SharpDisplayManager.csproj Sun Aug 21 16:35:20 2016 +0200
+++ b/Server/SharpDisplayManager.csproj Sun Aug 21 18:35:58 2016 +0200
@@ -34,7 +34,7 @@
index.htm
false
0
- 0.11.0.0
+ 0.12.0.0
false
true
true
@@ -193,6 +193,12 @@
FormMain.cs
+
+ Form
+
+
+ FormSelectHarmonyCommand.cs
+
UserControl
@@ -227,6 +233,9 @@
FormMain.cs
+
+ FormSelectHarmonyCommand.cs
+
FxControl.cs
@@ -288,9 +297,9 @@
-
+
False
- Microsoft .NET Framework 4 %28x86 and x64%29
+ Microsoft .NET Framework 4.6 %28x86 and x64%29
true
diff -r cadc4e4302c6 -r b2121d03f6f0 SharpDisplayManager.sln
--- a/SharpDisplayManager.sln Sun Aug 21 16:35:20 2016 +0200
+++ b/SharpDisplayManager.sln Sun Aug 21 18:35:58 2016 +0200
@@ -61,8 +61,8 @@
{A76579E5-AA8D-45A3-99E1-239A5C030A78}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A76579E5-AA8D-45A3-99E1-239A5C030A78}.Debug|x64.ActiveCfg = Debug|Any CPU
{A76579E5-AA8D-45A3-99E1-239A5C030A78}.Debug|x64.Build.0 = Debug|Any CPU
- {A76579E5-AA8D-45A3-99E1-239A5C030A78}.Debug|x86.ActiveCfg = Debug|Any CPU
- {A76579E5-AA8D-45A3-99E1-239A5C030A78}.Debug|x86.Build.0 = Debug|Any CPU
+ {A76579E5-AA8D-45A3-99E1-239A5C030A78}.Debug|x86.ActiveCfg = Debug|x86
+ {A76579E5-AA8D-45A3-99E1-239A5C030A78}.Debug|x86.Build.0 = Debug|x86
{A76579E5-AA8D-45A3-99E1-239A5C030A78}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A76579E5-AA8D-45A3-99E1-239A5C030A78}.Release|Any CPU.Build.0 = Release|Any CPU
{A76579E5-AA8D-45A3-99E1-239A5C030A78}.Release|x64.ActiveCfg = Release|Any CPU
@@ -85,8 +85,8 @@
{AE897704-461D-4018-8336-2517988BF7AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE897704-461D-4018-8336-2517988BF7AD}.Debug|x64.ActiveCfg = Debug|Any CPU
{AE897704-461D-4018-8336-2517988BF7AD}.Debug|x64.Build.0 = Debug|Any CPU
- {AE897704-461D-4018-8336-2517988BF7AD}.Debug|x86.ActiveCfg = Debug|Any CPU
- {AE897704-461D-4018-8336-2517988BF7AD}.Debug|x86.Build.0 = Debug|Any CPU
+ {AE897704-461D-4018-8336-2517988BF7AD}.Debug|x86.ActiveCfg = Debug|x86
+ {AE897704-461D-4018-8336-2517988BF7AD}.Debug|x86.Build.0 = Debug|x86
{AE897704-461D-4018-8336-2517988BF7AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE897704-461D-4018-8336-2517988BF7AD}.Release|Any CPU.Build.0 = Release|Any CPU
{AE897704-461D-4018-8336-2517988BF7AD}.Release|x64.ActiveCfg = Release|Any CPU
@@ -97,8 +97,8 @@
{84A9ED37-E6EA-4CBD-B995-B713F46EAAB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84A9ED37-E6EA-4CBD-B995-B713F46EAAB0}.Debug|x64.ActiveCfg = Debug|Any CPU
{84A9ED37-E6EA-4CBD-B995-B713F46EAAB0}.Debug|x64.Build.0 = Debug|Any CPU
- {84A9ED37-E6EA-4CBD-B995-B713F46EAAB0}.Debug|x86.ActiveCfg = Debug|Any CPU
- {84A9ED37-E6EA-4CBD-B995-B713F46EAAB0}.Debug|x86.Build.0 = Debug|Any CPU
+ {84A9ED37-E6EA-4CBD-B995-B713F46EAAB0}.Debug|x86.ActiveCfg = Debug|x86
+ {84A9ED37-E6EA-4CBD-B995-B713F46EAAB0}.Debug|x86.Build.0 = Debug|x86
{84A9ED37-E6EA-4CBD-B995-B713F46EAAB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{84A9ED37-E6EA-4CBD-B995-B713F46EAAB0}.Release|Any CPU.Build.0 = Release|Any CPU
{84A9ED37-E6EA-4CBD-B995-B713F46EAAB0}.Release|x64.ActiveCfg = Release|Any CPU
@@ -109,8 +109,8 @@
{D9AAD299-E97F-47E0-8E92-110F49F2B89C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D9AAD299-E97F-47E0-8E92-110F49F2B89C}.Debug|x64.ActiveCfg = Debug|Any CPU
{D9AAD299-E97F-47E0-8E92-110F49F2B89C}.Debug|x64.Build.0 = Debug|Any CPU
- {D9AAD299-E97F-47E0-8E92-110F49F2B89C}.Debug|x86.ActiveCfg = Debug|Any CPU
- {D9AAD299-E97F-47E0-8E92-110F49F2B89C}.Debug|x86.Build.0 = Debug|Any CPU
+ {D9AAD299-E97F-47E0-8E92-110F49F2B89C}.Debug|x86.ActiveCfg = Debug|x86
+ {D9AAD299-E97F-47E0-8E92-110F49F2B89C}.Debug|x86.Build.0 = Debug|x86
{D9AAD299-E97F-47E0-8E92-110F49F2B89C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D9AAD299-E97F-47E0-8E92-110F49F2B89C}.Release|Any CPU.Build.0 = Release|Any CPU
{D9AAD299-E97F-47E0-8E92-110F49F2B89C}.Release|x64.ActiveCfg = Release|Any CPU
diff -r cadc4e4302c6 -r b2121d03f6f0 SharpLibEar/Object.cs
--- a/SharpLibEar/Object.cs Sun Aug 21 16:35:20 2016 +0200
+++ b/SharpLibEar/Object.cs Sun Aug 21 18:35:58 2016 +0200
@@ -3,10 +3,6 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
-
-
-using System;
-using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ComponentModel;
diff -r cadc4e4302c6 -r b2121d03f6f0 SharpLibEar/PropertyButton.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SharpLibEar/PropertyButton.cs Sun Aug 21 18:35:58 2016 +0200
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SharpLib.Ear
+{
+ ///
+ /// Generic button property
+ ///
+ [DataContract]
+ [AttributeObject(Id = "Property.Button", Name = "Button", Description = "Button property.")]
+ public class PropertyButton : Object
+ {
+ public EventHandler ClickEventHandler;
+
+ [DataMember]
+ public string Text { get; set; }
+ }
+}
diff -r cadc4e4302c6 -r b2121d03f6f0 SharpLibEar/SharpLibEar.csproj
--- a/SharpLibEar/SharpLibEar.csproj Sun Aug 21 16:35:20 2016 +0200
+++ b/SharpLibEar/SharpLibEar.csproj Sun Aug 21 18:35:58 2016 +0200
@@ -77,6 +77,7 @@
+