main
1using System;
2using gorilla.commons.utility;
3using Gorilla.Commons.Utility;
4using momoney.presentation.model.eventing;
5using MoMoney.Presentation.Views;
6using MoMoney.Presentation.Winforms.Resources;
7using MoMoney.Service.Infrastructure.Eventing;
8using MoMoney.Service.Infrastructure.Threading;
9
10namespace MoMoney.Presentation.Presenters
11{
12 public interface IStatusBarPresenter : IModule,
13 IEventSubscriber<SavedChangesEvent>,
14 IEventSubscriber<NewProjectOpened>,
15 IEventSubscriber<ClosingTheApplication>,
16 IEventSubscriber<UnsavedChangesEvent>,
17 IEventSubscriber<StartedRunningCommand>,
18 IEventSubscriber<FinishedRunningCommand>,
19 IEventSubscriber<ClosingProjectEvent>
20 {
21 }
22
23 public class StatusBarPresenter : IStatusBarPresenter
24 {
25 readonly IStatusBarView view;
26 readonly IEventAggregator broker;
27 readonly ITimer timer;
28
29 public StatusBarPresenter(IStatusBarView view, IEventAggregator broker, ITimer timer)
30 {
31 this.view = view;
32 this.broker = broker;
33 this.timer = timer;
34 }
35
36 public void run()
37 {
38 broker.subscribe(this);
39 view.display(ApplicationIcons.blue_circle, "...");
40 }
41
42 public void notify(SavedChangesEvent message)
43 {
44 view.display(ApplicationIcons.floppy_disk, "Last Saved: {0}".formatted_using(Clock.now()));
45 }
46
47 public void notify(NewProjectOpened message)
48 {
49 view.display(ApplicationIcons.green_circle, "Ready");
50 }
51
52 public void notify(ClosingTheApplication message)
53 {
54 view.display(ApplicationIcons.hour_glass, "Good Bye!");
55 }
56
57 public void notify(ClosingProjectEvent message)
58 {
59 view.display(ApplicationIcons.grey_circle, "Closed");
60 }
61
62 public void notify(UnsavedChangesEvent message)
63 {
64 view.display(ApplicationIcons.red_circle, "Don't forget to save your work...");
65 }
66
67 public void notify(StartedRunningCommand message)
68 {
69 timer.start_notifying(view, new TimeSpan(1));
70 }
71
72 public void notify(FinishedRunningCommand message)
73 {
74 timer.stop_notifying(view);
75 view.reset_progress_bar();
76 }
77 }
78}