# HG changeset patch
# User StephaneLenclud
# Date 1469526710 -7200
# Node ID 99c407831232a510f2e4c063c7392e893bd5302f
# Parent c466f72a834febe12f27cbfd878cef22fbb94ff1
Basis for action property edition support.
diff -r c466f72a834f -r 99c407831232 Server/FormEditAction.Designer.cs
--- a/Server/FormEditAction.Designer.cs Mon Jul 25 17:48:12 2016 +0200
+++ b/Server/FormEditAction.Designer.cs Tue Jul 26 11:51:50 2016 +0200
@@ -28,10 +28,13 @@
///
private void InitializeComponent()
{
+ this.components = new System.ComponentModel.Container();
this.comboBoxActionType = new System.Windows.Forms.ComboBox();
this.labelActionType = new System.Windows.Forms.Label();
this.buttonOk = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
+ this.iTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
+ this.toolTip = new System.Windows.Forms.ToolTip(this.components);
this.SuspendLayout();
//
// comboBoxActionType
@@ -42,6 +45,7 @@
this.comboBoxActionType.Name = "comboBoxActionType";
this.comboBoxActionType.Size = new System.Drawing.Size(333, 21);
this.comboBoxActionType.TabIndex = 18;
+ this.comboBoxActionType.SelectedIndexChanged += new System.EventHandler(this.comboBoxActionType_SelectedIndexChanged);
//
// labelActionType
//
@@ -54,8 +58,9 @@
//
// buttonOk
//
+ this.buttonOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonOk.DialogResult = System.Windows.Forms.DialogResult.OK;
- this.buttonOk.Location = new System.Drawing.Point(12, 55);
+ this.buttonOk.Location = new System.Drawing.Point(12, 347);
this.buttonOk.Name = "buttonOk";
this.buttonOk.Size = new System.Drawing.Size(75, 23);
this.buttonOk.TabIndex = 21;
@@ -65,19 +70,36 @@
//
// 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, 55);
+ this.buttonCancel.Location = new System.Drawing.Point(93, 347);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 22;
this.buttonCancel.Text = "Cancel";
this.buttonCancel.UseVisualStyleBackColor = true;
//
+ // iTableLayoutPanel
+ //
+ this.iTableLayoutPanel.ColumnCount = 2;
+ this.iTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
+ this.iTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
+ this.iTableLayoutPanel.Location = new System.Drawing.Point(15, 50);
+ this.iTableLayoutPanel.Name = "iTableLayoutPanel";
+ this.iTableLayoutPanel.RowCount = 2;
+ this.iTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
+ this.iTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
+ this.iTableLayoutPanel.Size = new System.Drawing.Size(373, 114);
+ this.iTableLayoutPanel.TabIndex = 23;
+ //
// FormEditAction
//
+ this.AcceptButton = this.buttonOk;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(400, 86);
+ this.CancelButton = this.buttonCancel;
+ this.ClientSize = new System.Drawing.Size(400, 382);
+ this.Controls.Add(this.iTableLayoutPanel);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOk);
this.Controls.Add(this.labelActionType);
@@ -100,5 +122,7 @@
private System.Windows.Forms.Label labelActionType;
private System.Windows.Forms.Button buttonOk;
private System.Windows.Forms.Button buttonCancel;
+ private System.Windows.Forms.TableLayoutPanel iTableLayoutPanel;
+ private System.Windows.Forms.ToolTip toolTip;
}
}
\ No newline at end of file
diff -r c466f72a834f -r 99c407831232 Server/FormEditAction.cs
--- a/Server/FormEditAction.cs Mon Jul 25 17:48:12 2016 +0200
+++ b/Server/FormEditAction.cs Tue Jul 26 11:51:50 2016 +0200
@@ -2,38 +2,19 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
+using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
+using SharpLib.Display;
using SharpLib.Ear;
+using System.Reflection;
namespace SharpDisplayManager
{
///
- /// Used to populate our action type combobox with friendly names
- ///
- class ItemActionType
- {
- public Type Type;
-
- public ItemActionType(Type type)
- {
- this.Type = type;
- }
-
- public override string ToString()
- {
- //Get friendly action name from action attribute.
- //That we then show up in our combobox
- return SharpLib.Utils.Reflection.GetAttribute(Type).Name;
- }
- }
-
-
-
- ///
/// Action edit dialog form.
///
public partial class FormEditAction : Form
@@ -59,12 +40,136 @@
private void buttonOk_Click(object sender, EventArgs e)
{
- Action = (SharpLib.Ear.Action)Activator.CreateInstance(((ItemActionType)comboBoxActionType.SelectedItem).Type);
+
}
private void FormEditAction_Validating(object sender, CancelEventArgs e)
{
}
+
+ private void comboBoxActionType_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ //Instantiate an action corresponding to our type
+ Action = (SharpLib.Ear.Action)Activator.CreateInstance(((ItemActionType)comboBoxActionType.SelectedItem).Type);
+
+ //Create input fields
+ UpdateTableLayoutPanel(Action);
+ }
+
+ ///
+ /// Update our table layout.
+ /// Will instantiated every field control as defined by our action.
+ /// Fields must be specified by rows from the left.
+ ///
+ ///
+ private void UpdateTableLayoutPanel(SharpLib.Ear.Action aAction)
+ {
+ toolTip.RemoveAll();
+ //Debug.Print("UpdateTableLayoutPanel")
+ //First clean our current panel
+ iTableLayoutPanel.Controls.Clear();
+ iTableLayoutPanel.RowStyles.Clear();
+ iTableLayoutPanel.ColumnStyles.Clear();
+ iTableLayoutPanel.RowCount = 0;
+
+ //We always want two columns: one for label and one for the field
+ iTableLayoutPanel.ColumnCount = 2;
+ iTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
+ iTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
+
+
+ if (aAction == null)
+ {
+ //Just drop it
+ return;
+ }
+
+ //IEnumerable properties = aAction.GetType().GetProperties().Where(
+ // prop => Attribute.IsDefined(prop, typeof(AttributeActionProperty)));
+
+
+ foreach (PropertyInfo pi in aAction.GetType().GetProperties())
+ {
+ AttributeActionProperty[] attributes = ((AttributeActionProperty[])pi.GetCustomAttributes(typeof(AttributeActionProperty), true));
+ if (attributes.Length != 1)
+ {
+ continue;
+ }
+
+ AttributeActionProperty attribute = attributes[0];
+ //Add a new row
+ iTableLayoutPanel.RowCount++;
+ iTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
+ //Create the label
+ Label label = new Label();
+ label.Text = attribute.Name;
+ toolTip.SetToolTip(label, attribute.Description);
+ iTableLayoutPanel.Controls.Add(label, 0, iTableLayoutPanel.RowCount-1);
+
+
+ //Create the editor
+
+ }
+
+
+ /*
+ //Then recreate our rows...
+ while (iTableLayoutPanel.RowCount < layout.Rows.Count)
+ {
+ iTableLayoutPanel.RowCount++;
+ }
+
+ // ...and columns
+ while (iTableLayoutPanel.ColumnCount < layout.Columns.Count)
+ {
+ iTableLayoutPanel.ColumnCount++;
+ }
+
+ //For each column
+ for (int i = 0; i < iTableLayoutPanel.ColumnCount; i++)
+ {
+ //Create our column styles
+ this.iTableLayoutPanel.ColumnStyles.Add(layout.Columns[i]);
+
+ //For each rows
+ for (int j = 0; j < iTableLayoutPanel.RowCount; j++)
+ {
+ if (i == 0)
+ {
+ //Create our row styles
+ this.iTableLayoutPanel.RowStyles.Add(layout.Rows[j]);
+ }
+ else
+ {
+ continue;
+ }
+ }
+ }
+
+ //For each field
+ foreach (DataField field in aClient.Fields)
+ {
+ if (!field.IsTableField)
+ {
+ //That field is not taking part in our table layout skip it
+ continue;
+ }
+
+ TableField tableField = (TableField)field;
+
+ //Create a control corresponding to the field specified for that cell
+ Control control = CreateControlForDataField(tableField);
+
+ //Add newly created control to our table layout at the specified row and column
+ iTableLayoutPanel.Controls.Add(control, tableField.Column, tableField.Row);
+ //Make sure we specify column and row span for that new control
+ iTableLayoutPanel.SetColumnSpan(control, tableField.ColumnSpan);
+ iTableLayoutPanel.SetRowSpan(control, tableField.RowSpan);
+ }
+ */
+
+ }
+
}
}
diff -r c466f72a834f -r 99c407831232 Server/FormEditAction.resx
--- a/Server/FormEditAction.resx Mon Jul 25 17:48:12 2016 +0200
+++ b/Server/FormEditAction.resx Tue Jul 26 11:51:50 2016 +0200
@@ -117,4 +117,7 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ 17, 17
+
\ No newline at end of file
diff -r c466f72a834f -r 99c407831232 Server/ItemActionType.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Server/ItemActionType.cs Tue Jul 26 11:51:50 2016 +0200
@@ -0,0 +1,29 @@
+using SharpLib.Ear;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SharpDisplayManager
+{
+ ///
+ /// Used to populate our action type combobox with friendly names
+ ///
+ class ItemActionType
+ {
+ public Type Type;
+
+ public ItemActionType(Type type)
+ {
+ this.Type = type;
+ }
+
+ public override string ToString()
+ {
+ //Get friendly action name from action attribute.
+ //That we then show up in our combobox
+ return SharpLib.Utils.Reflection.GetAttribute(Type).Name;
+ }
+ }
+}
diff -r c466f72a834f -r 99c407831232 Server/MainForm.cs
--- a/Server/MainForm.cs Mon Jul 25 17:48:12 2016 +0200
+++ b/Server/MainForm.cs Tue Jul 26 11:51:50 2016 +0200
@@ -223,7 +223,7 @@
ResetCec();
//Setup Events
- SetupEvents();
+ PopulateEventsTreeView();
//Setup notification icon
SetupTrayIcon();
@@ -302,7 +302,7 @@
///
/// Populate tree view with events and actions
///
- private void SetupEvents()
+ private void PopulateEventsTreeView()
{
//Disable action buttons
buttonAddAction.Enabled = false;
@@ -331,6 +331,11 @@
iTreeViewEvents.ExpandAll();
SelectEvent(currentEvent);
+ //Select the last action if any
+ if (iTreeViewEvents.SelectedNode!= null && iTreeViewEvents.SelectedNode.Nodes[1].GetNodeCount(false) > 0)
+ {
+ iTreeViewEvents.SelectedNode = iTreeViewEvents.SelectedNode.Nodes[1].Nodes[iTreeViewEvents.SelectedNode.Nodes[1].GetNodeCount(false)-1];
+ }
}
@@ -2666,8 +2671,10 @@
}
}
+
+
///
- ///
+ /// Get the current event based on event tree view selection.
///
///
private Event CurrentEvent()
@@ -2689,7 +2696,7 @@
}
///
- ///
+ /// Get the current action based on event tree view selection
///
///
private SharpLib.Ear.Action CurrentAction()
@@ -2724,7 +2731,7 @@
selectedEvent.Actions.Add(ea.Action);
Properties.Settings.Default.Actions = ManagerEventAction.Current;
Properties.Settings.Default.Save();
- SetupEvents();
+ PopulateEventsTreeView();
}
}
@@ -2746,7 +2753,7 @@
ManagerEventAction.Current.RemoveAction(action);
Properties.Settings.Default.Actions = ManagerEventAction.Current;
Properties.Settings.Default.Save();
- SetupEvents();
+ PopulateEventsTreeView();
}
private void iTreeViewEvents_AfterSelect(object sender, TreeViewEventArgs e)
diff -r c466f72a834f -r 99c407831232 Server/SharpDisplayManager.csproj
--- a/Server/SharpDisplayManager.csproj Mon Jul 25 17:48:12 2016 +0200
+++ b/Server/SharpDisplayManager.csproj Tue Jul 26 11:51:50 2016 +0200
@@ -166,7 +166,9 @@
-
+
+ Form
+
FormEditAction.cs
@@ -176,6 +178,7 @@
FxControl.cs
+
MainForm.cs
diff -r c466f72a834f -r 99c407831232 SharpLibEar/ActionSleep.cs
--- a/SharpLibEar/ActionSleep.cs Mon Jul 25 17:48:12 2016 +0200
+++ b/SharpLibEar/ActionSleep.cs Tue Jul 26 11:51:50 2016 +0200
@@ -14,22 +14,24 @@
public class ActionSleep : Action
{
[DataMember]
- private readonly int iMillisecondsTimeout;
+ [AttributeActionProperty(Id = "Thread.Sleep.Timeout", Name = "Timeout",
+ Description = "Specifies the number of milliseconds this action will sleep for.")]
+ public int TimeoutInMilliseconds { get; set; }
public ActionSleep()
{
- iMillisecondsTimeout = 1000;
+ TimeoutInMilliseconds = 1000;
}
public ActionSleep(int aMillisecondsTimeout)
{
- iMillisecondsTimeout = aMillisecondsTimeout;
+ TimeoutInMilliseconds = aMillisecondsTimeout;
}
public override void Execute()
{
- Thread.Sleep(iMillisecondsTimeout);
+ Thread.Sleep(TimeoutInMilliseconds);
}
}
diff -r c466f72a834f -r 99c407831232 SharpLibEar/AttributeAction.cs
--- a/SharpLibEar/AttributeAction.cs Mon Jul 25 17:48:12 2016 +0200
+++ b/SharpLibEar/AttributeAction.cs Tue Jul 26 11:51:50 2016 +0200
@@ -7,7 +7,9 @@
namespace SharpLib.Ear
{
- // Multiuse attribute.
+ ///
+ /// For action class to define name and description.
+ ///
[System.AttributeUsage(System.AttributeTargets.Class)]
public class AttributeAction : System.Attribute
{
@@ -16,4 +18,5 @@
public string Description;
}
+
}
diff -r c466f72a834f -r 99c407831232 SharpLibEar/AttributeActionProperty.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SharpLibEar/AttributeActionProperty.cs Tue Jul 26 11:51:50 2016 +0200
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SharpLib.Ear
+{
+ ///
+ /// To expose an action property thus enabling user to edit it.
+ ///
+ [System.AttributeUsage(System.AttributeTargets.Property)]
+ public class AttributeActionProperty : System.Attribute
+ {
+ public string Id;
+ public string Name;
+ public string Description;
+ }
+}
diff -r c466f72a834f -r 99c407831232 SharpLibEar/SharpLibEar.csproj
--- a/SharpLibEar/SharpLibEar.csproj Mon Jul 25 17:48:12 2016 +0200
+++ b/SharpLibEar/SharpLibEar.csproj Tue Jul 26 11:51:50 2016 +0200
@@ -46,6 +46,7 @@
+