Index: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/ExpressionSelectionView.cs
===================================================================
--- branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/ExpressionSelectionView.cs	(revision 14777)
+++ branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/ExpressionSelectionView.cs	(revision 14834)
@@ -19,4 +19,5 @@
     public ExpressionSelectionView() {
       InitializeComponent();
+
       InitEvents();
       Name = "Push Expression Selection Editor";
@@ -28,4 +29,5 @@
       set
       {
+        if (Content != null) Content.EnabledExpressionsChanged -= EnabledExpressionsChanged;
         base.Content = value;
       }
@@ -35,35 +37,38 @@
       base.OnReadOnlyChanged();
 
-      this.expressionsTreeView.Enabled = !ReadOnly;
+      expressionsTreeView.Enabled = !ReadOnly;
     }
 
     private void InitEvents() {
-      this.expressionsTreeView.AfterCheck += ExpressionsTreeViewAfterCheck;
+      expressionsTreeView.AfterCheck += ExpressionsTreeViewAfterCheck;
     }
 
     private void ExpressionsTreeViewAfterCheck(object sender, TreeViewEventArgs e) {
-      var isStackNode = e.Node.Tag is StackTypes;
+      if (e.Action == TreeViewAction.Unknown)
+        return;
 
-      if (isStackNode) {
-        if (e.Node.Checked) {
-          Content.EnableStack((StackTypes)e.Node.Tag);
-          foreach (var subNode in e.Node.Nodes.Cast<TreeNode>())
-            subNode.Checked = true;
-        } else {
-          Content.DisableStack((StackTypes)e.Node.Tag);
-          foreach (var subNode in e.Node.Nodes.Cast<TreeNode>())
-            subNode.Checked = false;
-        }
+      Content.EnabledExpressionsChanged -= EnabledExpressionsChanged;
+      var stackType = (StackTypes)e.Node.Tag;
+
+      if (e.Node.Parent == null) {
+        Content.SetStack(stackType, e.Node.Checked, true);
+        SetStackNodeText(e.Node);
+        foreach (var subNode in e.Node.Nodes.OfType<TreeNode>().Where(n => n.Checked != e.Node.Checked))
+          subNode.Checked = e.Node.Checked;
       } else {
-        if (e.Node.Checked) {
-          Content.EnableExpression(e.Node.Text);
-        } else {
-          Content.DisableExpression(e.Node.Text);
-        }
+        Content.SetExpression(e.Node.Text, e.Node.Checked, true);
+        SetStackNodeText(e.Node.Parent);
+
+        if ((e.Node.Checked && !e.Node.Parent.Checked) ||
+            (!e.Node.Checked && !e.Node.Parent.Nodes.OfType<TreeNode>().Any(n => n.Checked)))
+          e.Node.Parent.Checked = e.Node.Checked;
       }
+
+      Content.EnabledExpressionsChanged += EnabledExpressionsChanged;
     }
 
     protected override void OnContentChanged() {
       expressionsTreeView.Nodes.Clear();
+      nameTextBox.Text = "Push Expression Selection";
 
       if (Content == null) {
@@ -71,5 +76,16 @@
       }
 
-      this.nameTextBox.Text = "Push Expression Selection";
+      Content.EnabledExpressionsChanged += EnabledExpressionsChanged;
+      var treeNodes = GetTreeNodes(Content.EnabledExpressions).ToArray();
+      expressionsTreeView.Nodes.AddRange(treeNodes);
+    }
+
+    private void EnabledExpressionsChanged(object sender, EnabledExpressionsChangedEventArgs e) {
+      if (InvokeRequired) Invoke(new MethodInvoker(UpdateNodes));
+      else UpdateNodes();
+    }
+
+    private void UpdateNodes() {
+      expressionsTreeView.Nodes.Clear();
 
       var treeNodes = GetTreeNodes(Content.EnabledExpressions).ToArray();
@@ -80,11 +96,11 @@
       foreach (var stackType in ExpressionTable.StackTypeToNamesTable.Keys) {
         var stackTreeNode = new TreeNode {
-          Tag = stackType,
-          Text = Enum.GetName(typeof(StackTypes), stackType),
+          Tag = stackType
         };
 
         var stackExpressions = ExpressionTable.StackTypeToNamesTable[stackType];
-        var enabledStackExpressions = enabledExpressions.Intersect(ExpressionTable.StackTypeToNamesTable[stackType]);
+        var enabledStackExpressions = enabledExpressions.Intersect(stackExpressions).ToList();
 
+        SetStackNodeText(stackTreeNode);
         stackTreeNode.Checked = enabledStackExpressions.Any();
 
@@ -93,4 +109,5 @@
           .Select(name => new TreeNode {
             Text = name,
+            Tag = stackType,
             Checked = enabledStackExpressions.Contains(name),
           }).ToArray();
@@ -101,4 +118,16 @@
       }
     }
+
+    private void SetStackNodeText(TreeNode node) {
+      var stackType = (StackTypes)node.Tag;
+      var stackExpressions = ExpressionTable.StackTypeToNamesTable[stackType];
+      var enabledStackExpressions = Content.EnabledExpressions.Intersect(stackExpressions).ToList();
+
+      node.Text = string.Format(
+                "{0} ({1}/{2})",
+                Enum.GetName(typeof(StackTypes), stackType),
+                enabledStackExpressions.Count,
+                ExpressionTable.StackTypeToNamesTable[stackType].Count);
+    }
   }
 }
