summaryrefslogtreecommitdiff
path: root/product/Presentation/Presenters/ToolBarPresenter.cs
blob: 69d879823dc1c7a85bb3051f43e0955d474c6540 (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
using System.Collections.Generic;
using System.Windows.Forms;
using Gorilla.Commons.Utility.Extensions;
using MoMoney.Presentation.Core;
using MoMoney.Presentation.Model.Menu;
using MoMoney.Presentation.Model.Menu.File.Commands;
using MoMoney.Presentation.Model.Projects;
using MoMoney.Presentation.Views.Shell;
using MoMoney.Presentation.Winforms.Resources;

namespace MoMoney.Presentation.Presenters.Shell
{
    public interface IToolbarPresenter : IPresenter
    {
    }

    public class ToolBarPresenter : IToolbarPresenter
    {
        readonly IRegionManager shell;
        readonly IProjectController project;

        public ToolBarPresenter(IRegionManager shell, IProjectController project)
        {
            this.shell = shell;
            this.project = project;
        }

        public void run()
        {
            shell.region<ToolStrip>(x => buttons().each(y => y.add_to(x)));
        }

        IEnumerable<IToolbarButton> buttons()
        {
            yield return Create
                .a_tool_bar_item()
                .with_tool_tip_text_as("New")
                .when_clicked_executes<INewCommand>()
                .displays_icon(ApplicationIcons.NewProject)
                .button();
            yield return Create
                .a_tool_bar_item()
                .with_tool_tip_text_as("Open")
                .when_clicked_executes<IOpenCommand>()
                .displays_icon(ApplicationIcons.OpenProject)
                .button();
            yield return Create
                .a_tool_bar_item()
                .with_tool_tip_text_as("Save")
                .when_clicked_executes<ISaveCommand>()
                .can_be_clicked_when(() => project.has_unsaved_changes())
                .displays_icon(ApplicationIcons.SaveProject)
                .button();
        }
    }
}