main
 1using System;
 2using System.Windows.Forms;
 3using MoMoney.Presentation.Winforms.Keyboard;
 4using MoMoney.Presentation.Winforms.Resources;
 5
 6namespace MoMoney.Presentation.Model.Menu
 7{
 8    public interface IMenuItem
 9    {
10        ToolStripItem build();
11        System.Windows.Forms.MenuItem build_menu_item();
12        void refresh();
13    }
14
15    public class MenuItem : IMenuItem
16    {
17        readonly Func<bool> can_be_clicked;
18        readonly ToolStripMenuItem item;
19        readonly System.Windows.Forms.MenuItem task_tray_item;
20
21        public MenuItem(string name, Action command, HybridIcon icon, ShortcutKey key, Func<bool> can_be_clicked)
22        {
23            this.can_be_clicked = can_be_clicked;
24
25            item = new ToolStripMenuItem(name)
26                       {
27                           Image = icon,
28                           ShortcutKeys = key,
29                           Enabled = can_be_clicked()
30                       };
31            item.Click += (o, e) => command();
32
33            task_tray_item = new System.Windows.Forms.MenuItem(name) {ShowShortcut = true, Enabled = can_be_clicked()};
34            task_tray_item.Click += (o, e) => command();
35        }
36
37        public ToolStripItem build()
38        {
39            return item;
40        }
41
42        public System.Windows.Forms.MenuItem build_menu_item()
43        {
44            return task_tray_item;
45        }
46
47        public void refresh()
48        {
49            item.Enabled = can_be_clicked();
50            task_tray_item.Enabled = can_be_clicked();
51            //this.log().debug("item: {0}, is enabled: {1}", item.Text, item.Enabled);
52        }
53    }
54}