main
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.ComponentModel.Composition;
5using System.Windows.Forms;
6using gorilla.commons.utility;
7using momoney.presentation.presenters;
8using momoney.presentation.views;
9using MoMoney.Presentation.Views;
10using MoMoney.Presentation.Winforms.Helpers;
11
12namespace MoMoney.Presentation.Winforms.Views
13{
14 [Export(typeof (IShell))]
15 public partial class ApplicationShell : ApplicationWindow, IShell
16 {
17 readonly IDictionary<string, IComponent> regions;
18 ControlAction<EventArgs> closed_action;
19
20 public ApplicationShell()
21 {
22 InitializeComponent();
23 regions = new Dictionary<string, IComponent>
24 {
25 {GetType().FullName, this},
26 {typeof (Form).FullName, this},
27 {ux_main_menu_strip.GetType().FullName, ux_main_menu_strip},
28 {ux_dock_panel.GetType().FullName, ux_dock_panel},
29 {ux_tool_bar_strip.GetType().FullName, ux_tool_bar_strip},
30 {ux_status_bar.GetType().FullName, ux_status_bar},
31 {notification_icon.GetType().FullName, notification_icon},
32 {status_bar_label.GetType().FullName, status_bar_label},
33 {status_bar_progress_bar.GetType().FullName, status_bar_progress_bar}
34 };
35 Closed += (o, e) => closed_action(e);
36 }
37
38 protected override void OnLoad(EventArgs e)
39 {
40 base.OnLoad(e);
41 try_to_reduce_flickering();
42 }
43
44 public void attach_to(IApplicationShellPresenter presenter)
45 {
46 closed_action = x => presenter.shut_down();
47 }
48
49 public void add(IDockedContentView view)
50 {
51 view.add_to(ux_dock_panel);
52 }
53
54 public void region<Region>(Action<Region> action) where Region : IComponent
55 {
56 ensure_that_the_region_exists<Region>();
57 action(regions[typeof (Region).FullName].downcast_to<Region>());
58 }
59
60 public void close_the_active_window()
61 {
62 ux_dock_panel.ActiveDocument.DockHandler.Close();
63 }
64
65 public void close_all_windows()
66 {
67 using (new SuspendLayout(ux_dock_panel))
68 while (ux_dock_panel.Contents.Count > 0)
69 {
70 ux_dock_panel.Contents[0].DockHandler.Close();
71 }
72 }
73
74 void ensure_that_the_region_exists<T>()
75 {
76 if (!regions.ContainsKey(typeof (T).FullName))
77 throw new Exception("Could not find region: {0}".formatted_using(typeof (T)));
78 }
79 }
80}