Adding action edit button.
1.1 --- a/Server/FormEditAction.cs Fri Jul 29 10:40:15 2016 +0200
1.2 +++ b/Server/FormEditAction.cs Fri Jul 29 13:09:38 2016 +0200
1.3 @@ -26,16 +26,37 @@
1.4 InitializeComponent();
1.5 }
1.6
1.7 + /// <summary>
1.8 + ///
1.9 + /// </summary>
1.10 + /// <param name="sender"></param>
1.11 + /// <param name="e"></param>
1.12 private void FormEditAction_Load(object sender, EventArgs e)
1.13 {
1.14 - //Populate registered actions
1.15 + // Populate registered actions
1.16 foreach (string key in ManagerEventAction.Current.ActionTypes.Keys)
1.17 {
1.18 ItemActionType item = new ItemActionType(ManagerEventAction.Current.ActionTypes[key]);
1.19 comboBoxActionType.Items.Add(item);
1.20 }
1.21
1.22 - comboBoxActionType.SelectedIndex = 0;
1.23 + if (Action == null)
1.24 + {
1.25 + // Creating new issue, select our first item
1.26 + comboBoxActionType.SelectedIndex = 0;
1.27 + }
1.28 + else
1.29 + {
1.30 + // Editing existing issue
1.31 + // Look up our item in our combobox
1.32 + foreach (ItemActionType item in comboBoxActionType.Items)
1.33 + {
1.34 + if (item.Type == Action.GetType())
1.35 + {
1.36 + comboBoxActionType.SelectedItem = item;
1.37 + }
1.38 + }
1.39 + }
1.40 }
1.41
1.42 private void buttonOk_Click(object sender, EventArgs e)
1.43 @@ -51,8 +72,13 @@
1.44 private void comboBoxActionType_SelectedIndexChanged(object sender, EventArgs e)
1.45 {
1.46 //Instantiate an action corresponding to our type
1.47 - Action = (SharpLib.Ear.Action)Activator.CreateInstance(((ItemActionType)comboBoxActionType.SelectedItem).Type);
1.48 -
1.49 + Type actionType = ((ItemActionType) comboBoxActionType.SelectedItem).Type;
1.50 + //Create another type of action only if needed
1.51 + if (Action == null || Action.GetType() != actionType)
1.52 + {
1.53 + Action = (SharpLib.Ear.Action)Activator.CreateInstance(actionType);
1.54 + }
1.55 +
1.56 //Create input fields
1.57 UpdateTableLayoutPanel(Action);
1.58 }
2.1 --- a/Server/FormMain.Designer.cs Fri Jul 29 10:40:15 2016 +0200
2.2 +++ b/Server/FormMain.Designer.cs Fri Jul 29 13:09:38 2016 +0200
2.3 @@ -110,11 +110,12 @@
2.4 this.labelHdmiPort = new System.Windows.Forms.Label();
2.5 this.comboBoxHdmiPort = new System.Windows.Forms.ComboBox();
2.6 this.tabPageEvent = new System.Windows.Forms.TabPage();
2.7 + this.buttonActionEdit = new System.Windows.Forms.Button();
2.8 this.buttonActionMoveUp = new System.Windows.Forms.Button();
2.9 this.buttonActionMoveDown = new System.Windows.Forms.Button();
2.10 - this.buttonTestAction = new System.Windows.Forms.Button();
2.11 - this.buttonDeleteAction = new System.Windows.Forms.Button();
2.12 - this.buttonAddAction = new System.Windows.Forms.Button();
2.13 + this.buttonActionTest = new System.Windows.Forms.Button();
2.14 + this.buttonActionDelete = new System.Windows.Forms.Button();
2.15 + this.buttonActionAdd = new System.Windows.Forms.Button();
2.16 this.iTreeViewEvents = new System.Windows.Forms.TreeView();
2.17 this.tabPageApp = new System.Windows.Forms.TabPage();
2.18 this.checkBoxStartMinimized = new System.Windows.Forms.CheckBox();
2.19 @@ -972,11 +973,12 @@
2.20 //
2.21 // tabPageEvent
2.22 //
2.23 + this.tabPageEvent.Controls.Add(this.buttonActionEdit);
2.24 this.tabPageEvent.Controls.Add(this.buttonActionMoveUp);
2.25 this.tabPageEvent.Controls.Add(this.buttonActionMoveDown);
2.26 - this.tabPageEvent.Controls.Add(this.buttonTestAction);
2.27 - this.tabPageEvent.Controls.Add(this.buttonDeleteAction);
2.28 - this.tabPageEvent.Controls.Add(this.buttonAddAction);
2.29 + this.tabPageEvent.Controls.Add(this.buttonActionTest);
2.30 + this.tabPageEvent.Controls.Add(this.buttonActionDelete);
2.31 + this.tabPageEvent.Controls.Add(this.buttonActionAdd);
2.32 this.tabPageEvent.Controls.Add(this.iTreeViewEvents);
2.33 this.tabPageEvent.Location = new System.Drawing.Point(4, 22);
2.34 this.tabPageEvent.Name = "tabPageEvent";
2.35 @@ -986,6 +988,17 @@
2.36 this.tabPageEvent.Text = "Events";
2.37 this.tabPageEvent.UseVisualStyleBackColor = true;
2.38 //
2.39 + // buttonActionEdit
2.40 + //
2.41 + this.buttonActionEdit.Enabled = false;
2.42 + this.buttonActionEdit.Location = new System.Drawing.Point(6, 35);
2.43 + this.buttonActionEdit.Name = "buttonActionEdit";
2.44 + this.buttonActionEdit.Size = new System.Drawing.Size(96, 23);
2.45 + this.buttonActionEdit.TabIndex = 25;
2.46 + this.buttonActionEdit.Text = "Edit Action";
2.47 + this.buttonActionEdit.UseVisualStyleBackColor = true;
2.48 + this.buttonActionEdit.Click += new System.EventHandler(this.buttonActionEdit_Click);
2.49 + //
2.50 // buttonActionMoveUp
2.51 //
2.52 this.buttonActionMoveUp.Enabled = false;
2.53 @@ -1008,38 +1021,38 @@
2.54 this.buttonActionMoveDown.UseVisualStyleBackColor = true;
2.55 this.buttonActionMoveDown.Click += new System.EventHandler(this.buttonActionMoveDown_Click);
2.56 //
2.57 - // buttonTestAction
2.58 + // buttonActionTest
2.59 //
2.60 - this.buttonTestAction.Enabled = false;
2.61 - this.buttonTestAction.Location = new System.Drawing.Point(6, 64);
2.62 - this.buttonTestAction.Name = "buttonTestAction";
2.63 - this.buttonTestAction.Size = new System.Drawing.Size(96, 23);
2.64 - this.buttonTestAction.TabIndex = 22;
2.65 - this.buttonTestAction.Text = "Test Action";
2.66 - this.buttonTestAction.UseVisualStyleBackColor = true;
2.67 - this.buttonTestAction.Click += new System.EventHandler(this.buttonTestAction_Click);
2.68 + this.buttonActionTest.Enabled = false;
2.69 + this.buttonActionTest.Location = new System.Drawing.Point(6, 93);
2.70 + this.buttonActionTest.Name = "buttonActionTest";
2.71 + this.buttonActionTest.Size = new System.Drawing.Size(96, 23);
2.72 + this.buttonActionTest.TabIndex = 22;
2.73 + this.buttonActionTest.Text = "Test Action";
2.74 + this.buttonActionTest.UseVisualStyleBackColor = true;
2.75 + this.buttonActionTest.Click += new System.EventHandler(this.buttonActionTest_Click);
2.76 //
2.77 - // buttonDeleteAction
2.78 + // buttonActionDelete
2.79 //
2.80 - this.buttonDeleteAction.Enabled = false;
2.81 - this.buttonDeleteAction.Location = new System.Drawing.Point(6, 35);
2.82 - this.buttonDeleteAction.Name = "buttonDeleteAction";
2.83 - this.buttonDeleteAction.Size = new System.Drawing.Size(96, 23);
2.84 - this.buttonDeleteAction.TabIndex = 21;
2.85 - this.buttonDeleteAction.Text = "Delete Action";
2.86 - this.buttonDeleteAction.UseVisualStyleBackColor = true;
2.87 - this.buttonDeleteAction.Click += new System.EventHandler(this.buttonDeleteAction_Click);
2.88 + this.buttonActionDelete.Enabled = false;
2.89 + this.buttonActionDelete.Location = new System.Drawing.Point(6, 64);
2.90 + this.buttonActionDelete.Name = "buttonActionDelete";
2.91 + this.buttonActionDelete.Size = new System.Drawing.Size(96, 23);
2.92 + this.buttonActionDelete.TabIndex = 21;
2.93 + this.buttonActionDelete.Text = "Delete Action";
2.94 + this.buttonActionDelete.UseVisualStyleBackColor = true;
2.95 + this.buttonActionDelete.Click += new System.EventHandler(this.buttonActionDelete_Click);
2.96 //
2.97 - // buttonAddAction
2.98 + // buttonActionAdd
2.99 //
2.100 - this.buttonAddAction.Enabled = false;
2.101 - this.buttonAddAction.Location = new System.Drawing.Point(6, 6);
2.102 - this.buttonAddAction.Name = "buttonAddAction";
2.103 - this.buttonAddAction.Size = new System.Drawing.Size(96, 23);
2.104 - this.buttonAddAction.TabIndex = 20;
2.105 - this.buttonAddAction.Text = "Add Action";
2.106 - this.buttonAddAction.UseVisualStyleBackColor = true;
2.107 - this.buttonAddAction.Click += new System.EventHandler(this.buttonAddAction_Click);
2.108 + this.buttonActionAdd.Enabled = false;
2.109 + this.buttonActionAdd.Location = new System.Drawing.Point(6, 6);
2.110 + this.buttonActionAdd.Name = "buttonActionAdd";
2.111 + this.buttonActionAdd.Size = new System.Drawing.Size(96, 23);
2.112 + this.buttonActionAdd.TabIndex = 20;
2.113 + this.buttonActionAdd.Text = "Add Action";
2.114 + this.buttonActionAdd.UseVisualStyleBackColor = true;
2.115 + this.buttonActionAdd.Click += new System.EventHandler(this.buttonActionAdd_Click);
2.116 //
2.117 // iTreeViewEvents
2.118 //
2.119 @@ -1311,11 +1324,12 @@
2.120 private System.Windows.Forms.CheckBox checkBoxCecLogNoPoll;
2.121 private System.Windows.Forms.TabPage tabPageEvent;
2.122 private System.Windows.Forms.TreeView iTreeViewEvents;
2.123 - private System.Windows.Forms.Button buttonDeleteAction;
2.124 - private System.Windows.Forms.Button buttonAddAction;
2.125 + private System.Windows.Forms.Button buttonActionDelete;
2.126 + private System.Windows.Forms.Button buttonActionAdd;
2.127 private System.Windows.Forms.Button buttonActionMoveUp;
2.128 private System.Windows.Forms.Button buttonActionMoveDown;
2.129 - private System.Windows.Forms.Button buttonTestAction;
2.130 + private System.Windows.Forms.Button buttonActionTest;
2.131 + private System.Windows.Forms.Button buttonActionEdit;
2.132 }
2.133 }
2.134
3.1 --- a/Server/FormMain.cs Fri Jul 29 10:40:15 2016 +0200
3.2 +++ b/Server/FormMain.cs Fri Jul 29 13:09:38 2016 +0200
3.3 @@ -316,8 +316,8 @@
3.4 private void PopulateEventsTreeView()
3.5 {
3.6 //Disable action buttons
3.7 - buttonAddAction.Enabled = false;
3.8 - buttonDeleteAction.Enabled = false;
3.9 + buttonActionAdd.Enabled = false;
3.10 + buttonActionDelete.Enabled = false;
3.11
3.12 Event currentEvent = CurrentEvent();
3.13 SharpLib.Ear.Action currentAction = CurrentAction();
3.14 @@ -2780,7 +2780,7 @@
3.15 /// </summary>
3.16 /// <param name="sender"></param>
3.17 /// <param name="e"></param>
3.18 - private void buttonAddAction_Click(object sender, EventArgs e)
3.19 + private void buttonActionAdd_Click(object sender, EventArgs e)
3.20 {
3.21 Event selectedEvent = CurrentEvent();
3.22 if (selectedEvent == null)
3.23 @@ -2805,7 +2805,37 @@
3.24 /// </summary>
3.25 /// <param name="sender"></param>
3.26 /// <param name="e"></param>
3.27 - private void buttonDeleteAction_Click(object sender, EventArgs e)
3.28 + private void buttonActionEdit_Click(object sender, EventArgs e)
3.29 + {
3.30 + Event selectedEvent = CurrentEvent();
3.31 + SharpLib.Ear.Action selectedAction = CurrentAction();
3.32 + if (selectedEvent == null || selectedAction == null)
3.33 + {
3.34 + //We did not find a corresponding event
3.35 + return;
3.36 + }
3.37 +
3.38 + FormEditAction ea = new FormEditAction();
3.39 + ea.Action = selectedAction;
3.40 + int actionIndex = iTreeViewEvents.SelectedNode.Index;
3.41 + DialogResult res = CodeProject.Dialog.DlgBox.ShowDialog(ea);
3.42 + if (res == DialogResult.OK)
3.43 + {
3.44 + //Update our action
3.45 + selectedEvent.Actions[actionIndex]=ea.Action;
3.46 + //Save and rebuild our event tree view
3.47 + Properties.Settings.Default.Actions = ManagerEventAction.Current;
3.48 + Properties.Settings.Default.Save();
3.49 + PopulateEventsTreeView();
3.50 + }
3.51 + }
3.52 +
3.53 + /// <summary>
3.54 + ///
3.55 + /// </summary>
3.56 + /// <param name="sender"></param>
3.57 + /// <param name="e"></param>
3.58 + private void buttonActionDelete_Click(object sender, EventArgs e)
3.59 {
3.60
3.61 SharpLib.Ear.Action action = CurrentAction();
3.62 @@ -2821,35 +2851,12 @@
3.63 PopulateEventsTreeView();
3.64 }
3.65
3.66 - private void iTreeViewEvents_AfterSelect(object sender, TreeViewEventArgs e)
3.67 - {
3.68 - //Enable buttons according to selected item
3.69 - buttonAddAction.Enabled = CurrentEvent() != null;
3.70 -
3.71 - SharpLib.Ear.Action currentAction = CurrentAction();
3.72 - //If an action is selected enable the following buttons
3.73 - buttonTestAction.Enabled =
3.74 - buttonDeleteAction.Enabled =
3.75 - buttonActionMoveUp.Enabled =
3.76 - buttonActionMoveDown.Enabled =
3.77 - currentAction != null;
3.78 -
3.79 - if (currentAction != null)
3.80 - {
3.81 - //If an action is selected enable move buttons if needed
3.82 - buttonActionMoveUp.Enabled = iTreeViewEvents.SelectedNode.Index != 0;
3.83 - buttonActionMoveDown.Enabled = iTreeViewEvents.SelectedNode.Index <
3.84 - iTreeViewEvents.SelectedNode.Parent.Nodes.Count - 1;
3.85 - }
3.86 -
3.87 - }
3.88 -
3.89 /// <summary>
3.90 ///
3.91 /// </summary>
3.92 /// <param name="sender"></param>
3.93 /// <param name="e"></param>
3.94 - private void buttonTestAction_Click(object sender, EventArgs e)
3.95 + private void buttonActionTest_Click(object sender, EventArgs e)
3.96 {
3.97 SharpLib.Ear.Action a = CurrentAction();
3.98 if (a != null)
3.99 @@ -2918,5 +2925,36 @@
3.100 Properties.Settings.Default.Save();
3.101 PopulateEventsTreeView();
3.102 }
3.103 +
3.104 +
3.105 + /// <summary>
3.106 + /// Manages events and actions buttons according to selected item in event tree.
3.107 + /// </summary>
3.108 + /// <param name="sender"></param>
3.109 + /// <param name="e"></param>
3.110 + private void iTreeViewEvents_AfterSelect(object sender, TreeViewEventArgs e)
3.111 + {
3.112 + //Enable buttons according to selected item
3.113 + buttonActionAdd.Enabled = CurrentEvent() != null;
3.114 +
3.115 + SharpLib.Ear.Action currentAction = CurrentAction();
3.116 + //If an action is selected enable the following buttons
3.117 + buttonActionTest.Enabled =
3.118 + buttonActionDelete.Enabled =
3.119 + buttonActionMoveUp.Enabled =
3.120 + buttonActionMoveDown.Enabled =
3.121 + buttonActionEdit.Enabled =
3.122 + currentAction != null;
3.123 +
3.124 + if (currentAction != null)
3.125 + {
3.126 + //If an action is selected enable move buttons if needed
3.127 + buttonActionMoveUp.Enabled = iTreeViewEvents.SelectedNode.Index != 0;
3.128 + buttonActionMoveDown.Enabled = iTreeViewEvents.SelectedNode.Index <
3.129 + iTreeViewEvents.SelectedNode.Parent.Nodes.Count - 1;
3.130 + }
3.131 +
3.132 + }
3.133 +
3.134 }
3.135 }