main
 1using System;
 2using System.Drawing;
 3using System.Windows.Forms;
 4using gorilla.commons.utility;
 5using MoMoney.Presentation.Winforms.Resources;
 6
 7namespace MoMoney.Presentation.Model.Navigation
 8{
 9    public class TreeBranch : ITreeBranch
10    {
11        readonly TreeNode node;
12        readonly Command the_command;
13
14        public TreeBranch(TreeNode node, Command the_command)
15        {
16            this.node = node;
17            this.the_command = the_command;
18            this.node.TreeView.DoubleClick += (sender, e) => Click();
19        }
20
21        public void accept(Visitor<ITreeBranch> visitor)
22        {
23            visitor.visit(this);
24        }
25
26        public ITreeBranch add_child(string name, ApplicationIcon icon, Command command)
27        {
28            var new_node = new TreeNode(name)
29                               {
30                                   ImageKey = icon.name_of_the_icon,
31                                   SelectedImageKey = icon.name_of_the_icon
32                               };
33            node.Nodes.Add(new_node);
34            return new TreeBranch(new_node, command);
35        }
36
37        public ITreeBranch add_child(string name, ApplicationIcon icon, Action command)
38        {
39            return add_child(name, icon, new AnonymousCommand(command));
40        }
41
42        void Click()
43        {
44            if (node.Equals(node.TreeView.SelectedNode))
45            {
46                node.Expand();
47                the_command.run();
48                node.BackColor = Color.HotPink;
49            }
50            else
51            {
52                node.BackColor = Color.Empty;
53            }
54        }
55    }
56}