# HG changeset patch # User StephaneLenclud # Date 1469459685 -7200 # Node ID 94f91d446339e83cedad3ded7fb126b3801167d0 # Parent 24d131a00f1c0158bcb65c38d5cbaf26b0c392bf Events tab button state management. diff -r 24d131a00f1c -r 94f91d446339 Server/MainForm.Designer.cs --- a/Server/MainForm.Designer.cs Sun Jul 24 23:34:29 2016 +0200 +++ b/Server/MainForm.Designer.cs Mon Jul 25 17:14:45 2016 +0200 @@ -982,6 +982,7 @@ // // buttonDeleteAction // + this.buttonDeleteAction.Enabled = false; this.buttonDeleteAction.Location = new System.Drawing.Point(6, 35); this.buttonDeleteAction.Name = "buttonDeleteAction"; this.buttonDeleteAction.Size = new System.Drawing.Size(96, 23); @@ -992,6 +993,7 @@ // // buttonAddAction // + this.buttonAddAction.Enabled = false; this.buttonAddAction.Location = new System.Drawing.Point(6, 6); this.buttonAddAction.Name = "buttonAddAction"; this.buttonAddAction.Size = new System.Drawing.Size(96, 23); @@ -1009,6 +1011,7 @@ this.iTreeViewEvents.Name = "iTreeViewEvents"; this.iTreeViewEvents.Size = new System.Drawing.Size(638, 376); this.iTreeViewEvents.TabIndex = 1; + this.iTreeViewEvents.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.iTreeViewEvents_AfterSelect); // // tabPageApp // diff -r 24d131a00f1c -r 94f91d446339 Server/MainForm.cs --- a/Server/MainForm.cs Sun Jul 24 23:34:29 2016 +0200 +++ b/Server/MainForm.cs Mon Jul 25 17:14:45 2016 +0200 @@ -304,6 +304,10 @@ /// private void SetupEvents() { + //Disable action buttons + buttonAddAction.Enabled = false; + buttonDeleteAction.Enabled = false; + //Reset our tree iTreeViewEvents.Nodes.Clear(); //Populate registered events @@ -2638,18 +2642,54 @@ SetupCecLogLevel(); } + /// + /// + /// + /// + private Event CurrentEvent() + { + //Walk up the tree from the selected node to find our event + TreeNode node = iTreeViewEvents.SelectedNode; + Event selectedEvent = null; + while (node != null) + { + if (node.Tag is Event) + { + selectedEvent = (Event)node.Tag; + break; + } + node = node.Parent; + } + + return selectedEvent; + } + + /// + /// + /// + /// + private SharpLib.Ear.Action CurrentAction() + { + TreeNode node = iTreeViewEvents.SelectedNode; + if (node != null && node.Tag is SharpLib.Ear.Action) + { + return (SharpLib.Ear.Action) node.Tag; + } + + return null; + } + + /// + /// + /// + /// + /// private void buttonAddAction_Click(object sender, EventArgs e) { - if (iTreeViewEvents.SelectedNode==null - || !(iTreeViewEvents.SelectedNode.Tag is Event)) + Event selectedEvent = CurrentEvent(); + if (selectedEvent == null) { - return; - } - - Event earEvent = (Event)iTreeViewEvents.SelectedNode.Tag; - if (earEvent == null) - { - //Must select event node + //We did not find a corresponding event return; } @@ -2657,22 +2697,22 @@ DialogResult res = CodeProject.Dialog.DlgBox.ShowDialog(ea); if (res == DialogResult.OK) { - earEvent.Actions.Add(ea.Action); + selectedEvent.Actions.Add(ea.Action); Properties.Settings.Default.Actions = ManagerEventAction.Current; Properties.Settings.Default.Save(); SetupEvents(); } } + /// + /// + /// + /// + /// private void buttonDeleteAction_Click(object sender, EventArgs e) { - if (iTreeViewEvents.SelectedNode == null - || !(iTreeViewEvents.SelectedNode.Tag is SharpLib.Ear.Action)) - { - return; - } - SharpLib.Ear.Action action = (SharpLib.Ear.Action)iTreeViewEvents.SelectedNode.Tag; + SharpLib.Ear.Action action = CurrentAction(); if (action == null) { //Must select action node @@ -2684,5 +2724,12 @@ Properties.Settings.Default.Save(); SetupEvents(); } + + private void iTreeViewEvents_AfterSelect(object sender, TreeViewEventArgs e) + { + //Enable buttons according to selected item + buttonAddAction.Enabled = CurrentEvent() != null; + buttonDeleteAction.Enabled = CurrentAction() != null; + } } }