main
1using System.Windows.Forms;
2using gorilla.commons.utility;
3using MoMoney.Presentation.Model.Menu;
4using MoMoney.Presentation.Model.Menu.File;
5using MoMoney.Presentation.Model.Menu.Help;
6using MoMoney.Presentation.Model.Menu.window;
7using momoney.presentation.views;
8using MoMoney.Presentation.Winforms.Resources;
9using MenuItem=System.Windows.Forms.MenuItem;
10
11namespace MoMoney.Presentation.Winforms.Views
12{
13 public class NotificationIconView : INotificationIconView
14 {
15 readonly IFileMenu file_menu;
16 readonly IWindowMenu window_menu;
17 readonly IHelpMenu help_menu;
18 readonly IRegionManager shell;
19
20 public NotificationIconView(IFileMenu file_menu, IWindowMenu window_menu, IHelpMenu help_menu, IRegionManager shell)
21 {
22 this.file_menu = file_menu;
23 this.shell = shell;
24 this.window_menu = window_menu;
25 this.help_menu = help_menu;
26 Application.ApplicationExit += (sender, e) => Dispose();
27 }
28
29 public void display(ApplicationIcon icon_to_display, string text_to_display)
30 {
31 shell.region<NotifyIcon>(x =>
32 {
33 x.Icon = icon_to_display;
34 x.Text = text_to_display;
35 x.ContextMenu = new ContextMenu
36 {
37 MenuItems =
38 {
39 map_from(file_menu),
40 map_from(window_menu),
41 map_from(help_menu)
42 }
43 };
44 });
45 }
46
47 public void opened_new_project()
48 {
49 show_popup_message("If you need any help check out mokhan.ca");
50 }
51
52 public void show_popup_message(string message)
53 {
54 shell.region<NotifyIcon>(x => x.ShowBalloonTip(100, message, message, ToolTipIcon.Info));
55 }
56
57 MenuItem map_from(ISubMenu item)
58 {
59 var menu_item = new MenuItem(item.name);
60 item.all_menu_items().each(x => menu_item.MenuItems.Add(x.build_menu_item()));
61 return menu_item;
62 }
63
64 public void Dispose()
65 {
66 shell.region<NotifyIcon>(x =>
67 {
68 if (x != null)
69 {
70 x.Visible = false;
71 x.Dispose();
72 }
73 });
74 }
75 }
76}