Events tab button state management.
authorStephaneLenclud
Mon, 25 Jul 2016 17:14:45 +0200
changeset 21794f91d446339
parent 216 24d131a00f1c
child 218 c466f72a834f
Events tab button state management.
Server/MainForm.Designer.cs
Server/MainForm.cs
     1.1 --- a/Server/MainForm.Designer.cs	Sun Jul 24 23:34:29 2016 +0200
     1.2 +++ b/Server/MainForm.Designer.cs	Mon Jul 25 17:14:45 2016 +0200
     1.3 @@ -982,6 +982,7 @@
     1.4              // 
     1.5              // buttonDeleteAction
     1.6              // 
     1.7 +            this.buttonDeleteAction.Enabled = false;
     1.8              this.buttonDeleteAction.Location = new System.Drawing.Point(6, 35);
     1.9              this.buttonDeleteAction.Name = "buttonDeleteAction";
    1.10              this.buttonDeleteAction.Size = new System.Drawing.Size(96, 23);
    1.11 @@ -992,6 +993,7 @@
    1.12              // 
    1.13              // buttonAddAction
    1.14              // 
    1.15 +            this.buttonAddAction.Enabled = false;
    1.16              this.buttonAddAction.Location = new System.Drawing.Point(6, 6);
    1.17              this.buttonAddAction.Name = "buttonAddAction";
    1.18              this.buttonAddAction.Size = new System.Drawing.Size(96, 23);
    1.19 @@ -1009,6 +1011,7 @@
    1.20              this.iTreeViewEvents.Name = "iTreeViewEvents";
    1.21              this.iTreeViewEvents.Size = new System.Drawing.Size(638, 376);
    1.22              this.iTreeViewEvents.TabIndex = 1;
    1.23 +            this.iTreeViewEvents.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.iTreeViewEvents_AfterSelect);
    1.24              // 
    1.25              // tabPageApp
    1.26              // 
     2.1 --- a/Server/MainForm.cs	Sun Jul 24 23:34:29 2016 +0200
     2.2 +++ b/Server/MainForm.cs	Mon Jul 25 17:14:45 2016 +0200
     2.3 @@ -304,6 +304,10 @@
     2.4          /// </summary>
     2.5          private void SetupEvents()
     2.6          {
     2.7 +            //Disable action buttons
     2.8 +            buttonAddAction.Enabled = false;
     2.9 +            buttonDeleteAction.Enabled = false;
    2.10 +
    2.11              //Reset our tree
    2.12              iTreeViewEvents.Nodes.Clear();
    2.13              //Populate registered events
    2.14 @@ -2638,18 +2642,54 @@
    2.15              SetupCecLogLevel();
    2.16          }
    2.17  
    2.18 +        /// <summary>
    2.19 +        /// 
    2.20 +        /// </summary>
    2.21 +        /// <returns></returns>
    2.22 +        private Event CurrentEvent()
    2.23 +        {
    2.24 +            //Walk up the tree from the selected node to find our event
    2.25 +            TreeNode node = iTreeViewEvents.SelectedNode;
    2.26 +            Event selectedEvent = null;
    2.27 +            while (node != null)
    2.28 +            {
    2.29 +                if (node.Tag is Event)
    2.30 +                {
    2.31 +                    selectedEvent = (Event)node.Tag;
    2.32 +                    break;
    2.33 +                }
    2.34 +                node = node.Parent;
    2.35 +            }
    2.36 +
    2.37 +            return selectedEvent;
    2.38 +        }
    2.39 +
    2.40 +        /// <summary>
    2.41 +        /// 
    2.42 +        /// </summary>
    2.43 +        /// <returns></returns>
    2.44 +        private SharpLib.Ear.Action CurrentAction()
    2.45 +        {
    2.46 +            TreeNode node = iTreeViewEvents.SelectedNode;
    2.47 +            if (node != null && node.Tag is SharpLib.Ear.Action)
    2.48 +            {
    2.49 +                return (SharpLib.Ear.Action) node.Tag;
    2.50 +            }
    2.51 +
    2.52 +            return null;
    2.53 +        }
    2.54 +
    2.55 +        /// <summary>
    2.56 +        /// 
    2.57 +        /// </summary>
    2.58 +        /// <param name="sender"></param>
    2.59 +        /// <param name="e"></param>
    2.60          private void buttonAddAction_Click(object sender, EventArgs e)
    2.61          {
    2.62 -            if (iTreeViewEvents.SelectedNode==null
    2.63 -                || !(iTreeViewEvents.SelectedNode.Tag is Event))
    2.64 +            Event selectedEvent = CurrentEvent();
    2.65 +            if (selectedEvent == null)
    2.66              {
    2.67 -                return;
    2.68 -            }
    2.69 -
    2.70 -            Event earEvent = (Event)iTreeViewEvents.SelectedNode.Tag;
    2.71 -            if (earEvent == null)
    2.72 -            {
    2.73 -                //Must select event node
    2.74 +                //We did not find a corresponding event
    2.75                  return;
    2.76              }
    2.77  
    2.78 @@ -2657,22 +2697,22 @@
    2.79              DialogResult res = CodeProject.Dialog.DlgBox.ShowDialog(ea);
    2.80              if (res == DialogResult.OK)
    2.81              {
    2.82 -                earEvent.Actions.Add(ea.Action);                
    2.83 +                selectedEvent.Actions.Add(ea.Action);                
    2.84                  Properties.Settings.Default.Actions = ManagerEventAction.Current;
    2.85                  Properties.Settings.Default.Save();
    2.86                  SetupEvents();
    2.87              }
    2.88          }
    2.89  
    2.90 +        /// <summary>
    2.91 +        /// 
    2.92 +        /// </summary>
    2.93 +        /// <param name="sender"></param>
    2.94 +        /// <param name="e"></param>
    2.95          private void buttonDeleteAction_Click(object sender, EventArgs e)
    2.96          {
    2.97 -            if (iTreeViewEvents.SelectedNode == null
    2.98 -                || !(iTreeViewEvents.SelectedNode.Tag is SharpLib.Ear.Action))
    2.99 -            {
   2.100 -                return;
   2.101 -            }
   2.102  
   2.103 -            SharpLib.Ear.Action action = (SharpLib.Ear.Action)iTreeViewEvents.SelectedNode.Tag;
   2.104 +            SharpLib.Ear.Action action = CurrentAction();
   2.105              if (action == null)
   2.106              {
   2.107                  //Must select action node
   2.108 @@ -2684,5 +2724,12 @@
   2.109              Properties.Settings.Default.Save();
   2.110              SetupEvents();
   2.111          }
   2.112 +
   2.113 +        private void iTreeViewEvents_AfterSelect(object sender, TreeViewEventArgs e)
   2.114 +        {
   2.115 +            //Enable buttons according to selected item
   2.116 +            buttonAddAction.Enabled = CurrentEvent() != null;
   2.117 +            buttonDeleteAction.Enabled = CurrentAction() != null;
   2.118 +        }
   2.119      }
   2.120  }