summaryrefslogtreecommitdiff
path: root/product/Presentation/Presenters/TitleBarPresenter.cs
blob: d4c98460afb31f239554a8f580a4f5b6ca4094f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using Gorilla.Commons.Infrastructure.Logging;
using MoMoney.Presentation.Model.messages;
using MoMoney.Presentation.Model.Projects;
using MoMoney.Presentation.Views;
using MoMoney.Service.Infrastructure.Eventing;

namespace MoMoney.Presentation.Presenters
{
    public interface ITitleBarPresenter : IModule,
                                          IEventSubscriber<UnsavedChangesEvent>,
                                          IEventSubscriber<SavedChangesEvent>,
                                          IEventSubscriber<NewProjectOpened>,
                                          IEventSubscriber<ClosingProjectEvent>
    {
    }

    public class TitleBarPresenter : ITitleBarPresenter
    {
        readonly ITitleBar view;
        readonly IProjectController project;
        readonly IEventAggregator broker;

        public TitleBarPresenter(ITitleBar view, IProjectController project, IEventAggregator broker)
        {
            this.view = view;
            this.project = project;
            this.broker = broker;
        }

        public void run()
        {
            view.display(project.name());
            broker.subscribe_to<UnsavedChangesEvent>(this);
            broker.subscribe_to<SavedChangesEvent>(this);
            broker.subscribe_to<NewProjectOpened>(this);
            broker.subscribe_to<ClosingProjectEvent>(this);
        }

        public void notify(UnsavedChangesEvent dto)
        {
            this.log().debug("adding asterik");
            view.append_asterik();
        }

        public void notify(SavedChangesEvent message)
        {
            view.display(project.name());
            view.remove_asterik();
        }

        public void notify(NewProjectOpened message)
        {
            view.display(project.name());
        }

        public void notify(ClosingProjectEvent message)
        {
            view.display(project.name());
        }
    }
}