main
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Windows;
5using gorilla.utility;
6using solidware.financials.windows.ui.views.icons;
7
8namespace solidware.financials.windows.ui.views
9{
10 public partial class Shell : RegionManager
11 {
12 public Shell()
13 {
14 InitializeComponent();
15 regions = new Dictionary<Type, UIElement>
16 {
17 {GetType(), this},
18 {typeof (Window), this},
19 {StatusBar.GetType(), StatusBar},
20 {Menu.GetType(), Menu},
21 {DockManager.GetType(), DockManager},
22 {Tabs.GetType(), Tabs},
23 {ResizingPanel.GetType(), ResizingPanel},
24 {ButtonBar.GetType(), ButtonBar},
25 {TaskBarIcon.GetType(), TaskBarIcon},
26 {StockWatch.GetType(), StockWatch},
27 };
28 DockManager.Loaded += (o, e) =>
29 {
30 if (File.Exists(settings_file)) DockManager.RestoreLayout(settings_file);
31 };
32 Closing += (o, e) => DockManager.SaveLayout(settings_file);
33 Closing += (o, e) => TaskBarIcon.Dispose();
34 Loaded += (o, e) =>
35 {
36 TaskBarIcon.Icon = UIIcon.Application.AsIcon();
37 };
38 }
39
40 public void region<Region>(Action<Region> configure) where Region : UIElement
41 {
42 ensure_that_the_region_exists<Region>();
43 Action action = () =>
44 {
45 configure(regions[typeof (Region)].downcast_to<Region>());
46 };
47 Dispatcher.BeginInvoke(action);
48 }
49
50 public void region<Region>(Configuration<Region> configuration) where Region : UIElement
51 {
52 region<Region>(x => configuration.configure(x));
53 }
54
55 void ensure_that_the_region_exists<Region>()
56 {
57 if (!regions.ContainsKey(typeof (Region)))
58 throw new Exception("Could not find region: {0}".format(typeof (Region)));
59 }
60
61 readonly IDictionary<Type, UIElement> regions;
62 string settings_file = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"mokhan.ca\momoney\default.ui.settings");
63 }
64}