Commit 5deb1be
Changed files (22)
trunk
product
MyMoney
Infrastructure
eventing
Presentation
Model
Menu
Navigation
Projects
Presenters
Utility
trunk/product/MyMoney/Infrastructure/eventing/EventAggregator.cs
@@ -14,11 +14,11 @@ namespace MoMoney.Infrastructure.eventing
public class EventAggregator : IEventAggregator
{
- readonly IDictionary<string, HashSet<object>> subscribers;
+ readonly IDictionary<string, List<object>> subscribers;
public EventAggregator()
{
- subscribers = new Dictionary<string, HashSet<object>>();
+ subscribers = new Dictionary<string, List<object>>();
}
public void subscribe_to<Event>(IEventSubscriber<Event> subscriber) where Event : IEvent
@@ -46,11 +46,11 @@ namespace MoMoney.Infrastructure.eventing
publish(new Event());
}
- HashSet<object> get_list_for<Event>()
+ List<object> get_list_for<Event>()
{
if (!subscribers.ContainsKey(typeof (Event).FullName))
{
- subscribers.Add(typeof (Event).FullName, new HashSet<object>());
+ subscribers.Add(typeof (Event).FullName, new List<object>());
}
return subscribers[typeof (Event).FullName];
}
trunk/product/MyMoney/Presentation/Model/Menu/File/FileMenu.cs
@@ -21,7 +21,7 @@ namespace MoMoney.Presentation.Model.Menu.File
public IEnumerable<IMenuItem> all_menu_items()
{
- yield return create
+ yield return Create
.a_menu_item()
.named("&New")
.that_executes<INewCommand>()
@@ -29,7 +29,7 @@ namespace MoMoney.Presentation.Model.Menu.File
.can_be_accessed_with(shortcut_keys.control.and(shortcut_keys.N))
.build();
- yield return create
+ yield return Create
.a_menu_item()
.named("&Open")
.that_executes<IOpenCommand>()
@@ -37,7 +37,7 @@ namespace MoMoney.Presentation.Model.Menu.File
.can_be_accessed_with(shortcut_keys.control.and(shortcut_keys.O))
.build();
- yield return create
+ yield return Create
.a_menu_item()
.named("&Save")
.that_executes<ISaveCommand>()
@@ -46,7 +46,7 @@ namespace MoMoney.Presentation.Model.Menu.File
.can_be_accessed_with(shortcut_keys.control.and(shortcut_keys.S))
.build();
- yield return create
+ yield return Create
.a_menu_item()
.named("Save &As...")
.that_executes<ISaveAsCommand>()
@@ -54,16 +54,16 @@ namespace MoMoney.Presentation.Model.Menu.File
.represented_by(ApplicationIcons.SaveProjectAs)
.build();
- yield return create
+ yield return Create
.a_menu_item()
.named("&Close")
//.can_be_clicked_when(() => project.is_open())
.that_executes<ICloseCommand>()
.build();
- yield return create.a_menu_item_separator();
+ yield return Create.a_menu_item_separator();
- yield return create
+ yield return Create
.a_menu_item()
.named("E&xit")
.that_executes<IExitCommand>()
trunk/product/MyMoney/Presentation/Model/Menu/Help/HelpMenu.cs
@@ -22,22 +22,22 @@ namespace MoMoney.Presentation.Model.Menu.Help
public IEnumerable<IMenuItem> all_menu_items()
{
- yield return create
+ yield return Create
.a_menu_item()
.named("&About")
.that_executes<IDisplayInformationAboutTheApplication>()
.represented_by(ApplicationIcons.About)
.build();
- yield return create
+ yield return Create
.a_menu_item()
.named("Check For Updates...")
.that_executes(() => command.run<ICheckForUpdatesPresenter>())
.build();
- yield return create.a_menu_item_separator();
+ yield return Create.a_menu_item_separator();
- yield return create
+ yield return Create
.a_menu_item()
.named("View Log File")
.that_executes(() => command.run<ILogFilePresenter>())
trunk/product/MyMoney/Presentation/Model/Menu/window/window_menu.cs → trunk/product/MyMoney/Presentation/Model/Menu/window/WindowMenu.cs
@@ -7,7 +7,7 @@ namespace MoMoney.Presentation.Model.Menu.window
{
}
- public class window_menu : IWindowMenu
+ public class WindowMenu : IWindowMenu
{
public string name
{
@@ -16,7 +16,7 @@ namespace MoMoney.Presentation.Model.Menu.window
public IEnumerable<IMenuItem> all_menu_items()
{
- yield return create
+ yield return Create
.a_menu_item()
.named("&Close Window")
.that_executes<ICloseWindowCommand>()
trunk/product/MyMoney/Presentation/Model/Menu/create.cs
@@ -1,13 +1,12 @@
using MoMoney.Infrastructure.Container;
-using MoMoney.Infrastructure.eventing;
namespace MoMoney.Presentation.Model.Menu
{
- public static class create
+ public static class Create
{
public static IMenuItemBuilder a_menu_item()
{
- return new MenuItemBuilder(resolve.dependency_for<IDependencyRegistry>(),resolve.dependency_for<IEventAggregator>());
+ return new MenuItemBuilder(resolve.dependency_for<IDependencyRegistry>());
}
public static IMenuItem a_menu_item_separator()
@@ -17,7 +16,7 @@ namespace MoMoney.Presentation.Model.Menu
public static IToolbarItemBuilder a_tool_bar_item()
{
- return new tool_bar_item_builder(resolve.dependency_for<IDependencyRegistry>());
+ return new ToolBarItemBuilder(resolve.dependency_for<IDependencyRegistry>());
}
}
}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Model/Menu/IToolbarButton.cs
@@ -0,0 +1,9 @@
+using System.Windows.Forms;
+
+namespace MoMoney.Presentation.Model.Menu
+{
+ public interface IToolbarButton
+ {
+ void add_to(ToolStrip collection);
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Model/Menu/IToolbarItemBuilder.cs
@@ -0,0 +1,15 @@
+using System;
+using MoMoney.Presentation.Resources;
+using MoMoney.Utility.Core;
+
+namespace MoMoney.Presentation.Model.Menu
+{
+ public interface IToolbarItemBuilder
+ {
+ IToolbarItemBuilder with_tool_tip_text_as(string text);
+ IToolbarItemBuilder when_clicked_executes<T>() where T : ICommand;
+ IToolbarItemBuilder displays_icon(HybridIcon project);
+ IToolbarItemBuilder can_be_clicked_when(Func<bool> condition);
+ IToolbarButton button();
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Model/Menu/MenuItem.cs
@@ -1,5 +1,6 @@
using System;
using System.Windows.Forms;
+using MoMoney.Infrastructure.eventing;
using MoMoney.Presentation.Model.keyboard;
using MoMoney.Presentation.Resources;
@@ -7,16 +8,13 @@ namespace MoMoney.Presentation.Model.Menu
{
public interface IMenuItem
{
- string name { get; }
- void click();
ToolStripItem build();
System.Windows.Forms.MenuItem build_menu_item();
}
public class MenuItem : IMenuItem
{
- public MenuItem(string name, Action command, HybridIcon underlying_icon, ShortcutKey key,
- Func<bool> can_be_clicked)
+ public MenuItem(string name, Action command, HybridIcon underlying_icon, ShortcutKey key, Func<bool> can_be_clicked)
{
this.name = name;
this.command = command;
@@ -33,15 +31,10 @@ namespace MoMoney.Presentation.Model.Menu
ToolStripMenuItem tool_strip_menu_item;
System.Windows.Forms.MenuItem menu_item;
- public void click()
- {
- command();
- }
-
public ToolStripItem build()
{
tool_strip_menu_item = new ToolStripMenuItem(name);
- tool_strip_menu_item.Click += ((o, e) => click());
+ tool_strip_menu_item.Click += ((o, e) => command());
tool_strip_menu_item.Image = underlying_icon;
tool_strip_menu_item.ShortcutKeys = key;
tool_strip_menu_item.Enabled = can_be_clicked();
@@ -51,7 +44,7 @@ namespace MoMoney.Presentation.Model.Menu
public System.Windows.Forms.MenuItem build_menu_item()
{
menu_item = new System.Windows.Forms.MenuItem(name);
- menu_item.Click += ((sender, e) => click());
+ menu_item.Click += ((sender, e) => command());
menu_item.ShowShortcut = true;
menu_item.Enabled = can_be_clicked();
return menu_item;
trunk/product/MyMoney/Presentation/Model/Menu/MenuItemBuilder.cs
@@ -1,13 +1,12 @@
using System;
using MoMoney.Infrastructure.Container;
-using MoMoney.Infrastructure.eventing;
using MoMoney.Presentation.Model.keyboard;
using MoMoney.Presentation.Resources;
using MoMoney.Utility.Core;
namespace MoMoney.Presentation.Model.Menu
{
- public interface IMenuItemBuilder
+ public interface IMenuItemBuilder : IBuilder<IMenuItem>
{
IMenuItemBuilder named(string name);
IMenuItemBuilder that_executes<TheCommand>() where TheCommand : ICommand;
@@ -15,21 +14,18 @@ namespace MoMoney.Presentation.Model.Menu
IMenuItemBuilder represented_by(HybridIcon project);
IMenuItemBuilder can_be_accessed_with(ShortcutKey hot_key);
IMenuItemBuilder can_be_clicked_when(Func<bool> predicate);
- IMenuItem build();
}
public class MenuItemBuilder : IMenuItemBuilder
{
readonly IDependencyRegistry registry;
Func<bool> can_be_clicked = () => true;
- readonly IEventAggregator broker;
- public MenuItemBuilder(IDependencyRegistry registry, IEventAggregator broker)
+ public MenuItemBuilder(IDependencyRegistry registry)
{
name_of_the_menu = "Unknown";
command_to_execute = () => { };
this.registry = registry;
- this.broker = broker;
icon = ApplicationIcons.Empty;
key = shortcut_keys.none;
}
trunk/product/MyMoney/Presentation/Model/Menu/MenuItemSeparator.cs
@@ -4,12 +4,6 @@ namespace MoMoney.Presentation.Model.Menu
{
internal class MenuItemSeparator : IMenuItem
{
- public string name { get; private set; }
-
- public void click()
- {
- }
-
public ToolStripItem build()
{
return new ToolStripSeparator();
trunk/product/MyMoney/Presentation/Model/Menu/tool_bar_item_builder.cs
@@ -1,57 +0,0 @@
-using System.Windows.Forms;
-using MoMoney.Infrastructure.Container;
-using MoMoney.Presentation.Resources;
-using MoMoney.Utility.Core;
-
-namespace MoMoney.Presentation.Model.Menu
-{
- public interface IToolbarItemBuilder
- {
- IToolbarItemBuilder with_tool_tip_text_as(string text);
- IToolbarItemBuilder when_clicked_executes<T>() where T : ICommand;
- IToolbarItemBuilder displays_icon(HybridIcon project);
- ToolStripItem build();
- }
-
- public class tool_bar_item_builder : IToolbarItemBuilder
- {
- private readonly IDependencyRegistry registry;
- private string tooltip_text;
- private ICommand the_command;
- private HybridIcon icon_to_display;
-
- public tool_bar_item_builder(IDependencyRegistry registry)
- {
- this.registry = registry;
- tooltip_text = "";
- the_command = new empty_command();
- icon_to_display = ApplicationIcons.Empty;
- }
-
- public IToolbarItemBuilder with_tool_tip_text_as(string text)
- {
- tooltip_text = text;
- return this;
- }
-
- public IToolbarItemBuilder when_clicked_executes<Command>() where Command : ICommand
- {
- the_command = registry.get_a<Command>();
- return this;
- }
-
- public IToolbarItemBuilder displays_icon(HybridIcon icon)
- {
- icon_to_display = icon;
- return this;
- }
-
- public ToolStripItem build()
- {
- var tool_strip_menu_item = new ToolStripButton {ToolTipText = tooltip_text};
- tool_strip_menu_item.Click += delegate { the_command.run(); };
- tool_strip_menu_item.Image = icon_to_display;
- return tool_strip_menu_item;
- }
- }
-}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Model/Menu/ToolBarItemBuilder.cs
@@ -0,0 +1,67 @@
+using System;
+using System.Windows.Forms;
+using MoMoney.Infrastructure.Container;
+using MoMoney.Presentation.Resources;
+using MoMoney.Utility.Core;
+
+namespace MoMoney.Presentation.Model.Menu
+{
+ public class ToolBarItemBuilder : IToolbarItemBuilder, IToolbarButton
+ {
+ readonly IDependencyRegistry registry;
+ string tooltip_text;
+ ICommand the_command;
+ HybridIcon icon_to_display;
+ Func<bool> the_condition;
+
+ public ToolBarItemBuilder(IDependencyRegistry registry)
+ {
+ this.registry = registry;
+ tooltip_text = "";
+ the_command = new EmptyCommand();
+ icon_to_display = ApplicationIcons.Empty;
+ the_condition = () => true;
+ }
+
+ public IToolbarItemBuilder with_tool_tip_text_as(string text)
+ {
+ tooltip_text = text;
+ return this;
+ }
+
+ public IToolbarItemBuilder when_clicked_executes<Command>() where Command : ICommand
+ {
+ the_command = registry.get_a<Command>();
+ return this;
+ }
+
+ public IToolbarItemBuilder displays_icon(HybridIcon icon)
+ {
+ icon_to_display = icon;
+ return this;
+ }
+
+ public IToolbarItemBuilder can_be_clicked_when(Func<bool> condition)
+ {
+ the_condition = condition;
+ return this;
+ }
+
+ public IToolbarButton button()
+ {
+ return this;
+ }
+
+ public void add_to(ToolStrip tool_strip)
+ {
+ var item = new ToolStripButton
+ {
+ ToolTipText = tooltip_text,
+ Image = icon_to_display,
+ Enabled = the_condition()
+ };
+ item.Click += (sender, args) => the_command.run();
+ tool_strip.Items.Add(item);
+ }
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Model/Projects/file_not_specified_exception.cs
@@ -2,6 +2,7 @@ using System;
namespace MoMoney.Presentation.Model.Projects
{
- public class file_not_specified_exception : Exception
- {}
+ public class FileNotSpecifiedException : Exception
+ {
+ }
}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Presenters/Shell/ToolbarModule.cs
@@ -0,0 +1,56 @@
+using MoMoney.Infrastructure.eventing;
+using MoMoney.Presentation.Core;
+using MoMoney.Presentation.Model.messages;
+using MoMoney.Presentation.Presenters.Commands;
+
+namespace MoMoney.Presentation.Presenters.Shell
+{
+ public interface IToolbarModule : IPresentationModule,
+ IEventSubscriber<NewProjectOpened>,
+ IEventSubscriber<ClosingProjectEvent>,
+ IEventSubscriber<SavedChangesEvent>,
+ IEventSubscriber<UnsavedChangesEvent>
+
+ {
+ }
+
+ public class ToolbarModule : IToolbarModule
+ {
+ readonly IEventAggregator broker;
+ readonly IRunPresenterCommand command;
+
+ public ToolbarModule(IEventAggregator broker, IRunPresenterCommand command)
+ {
+ this.broker = broker;
+ this.command = command;
+ }
+
+ public void run()
+ {
+ broker.subscribe_to<NewProjectOpened>(this);
+ broker.subscribe_to<ClosingProjectEvent>(this);
+ broker.subscribe_to<SavedChangesEvent>(this);
+ broker.subscribe_to<UnsavedChangesEvent>(this);
+ }
+
+ public void notify(NewProjectOpened message)
+ {
+ command.run<IToolbarPresenter>();
+ }
+
+ public void notify(ClosingProjectEvent message)
+ {
+ command.run<IToolbarPresenter>();
+ }
+
+ public void notify(SavedChangesEvent message)
+ {
+ command.run<IToolbarPresenter>();
+ }
+
+ public void notify(UnsavedChangesEvent message)
+ {
+ command.run<IToolbarPresenter>();
+ }
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Presenters/Shell/ToolBarPresenter.cs
@@ -3,51 +3,58 @@ using System.Windows.Forms;
using MoMoney.Presentation.Core;
using MoMoney.Presentation.Model.Menu;
using MoMoney.Presentation.Model.Menu.File.Commands;
+using MoMoney.Presentation.Model.Projects;
using MoMoney.Presentation.Resources;
using MoMoney.Presentation.Views.Shell;
using MoMoney.Utility.Extensions;
namespace MoMoney.Presentation.Presenters.Shell
{
- public interface IToolbarPresenter : IPresentationModule
+ public interface IToolbarPresenter : IPresenter
{
}
public class ToolBarPresenter : IToolbarPresenter
{
readonly IShell shell;
+ readonly IProject project;
- public ToolBarPresenter(IShell shell)
+ public ToolBarPresenter(IShell shell, IProject project)
{
this.shell = shell;
+ this.project = project;
}
public void run()
{
- shell.region<ToolStrip>(x => all_tool_bar_buttons().each(y => x.Items.Add(y)));
- //all_tool_bar_buttons().each(x => shell.add_to_tool_bar(x));
+ shell.region<ToolStrip>(x =>
+ {
+ x.Items.Clear();
+ buttons().each(y => y.add_to(x));
+ });
}
- static IEnumerable<ToolStripItem> all_tool_bar_buttons()
+ IEnumerable<IToolbarButton> buttons()
{
- yield return create
+ yield return Create
.a_tool_bar_item()
.with_tool_tip_text_as("New")
.when_clicked_executes<INewCommand>()
.displays_icon(ApplicationIcons.NewProject)
- .build();
- yield return create
+ .button();
+ yield return Create
.a_tool_bar_item()
.with_tool_tip_text_as("Open")
.when_clicked_executes<IOpenCommand>()
.displays_icon(ApplicationIcons.OpenProject)
- .build();
- yield return create
+ .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)
- .build();
+ .button();
}
}
}
\ No newline at end of file
trunk/product/MyMoney/Utility/Core/empty_command.cs
@@ -1,8 +0,0 @@
-namespace MoMoney.Utility.Core
-{
- internal class empty_command : ICommand
- {
- public void run()
- {}
- }
-}
\ No newline at end of file
trunk/product/MyMoney/Utility/Core/EmptyCommand.cs
@@ -0,0 +1,9 @@
+namespace MoMoney.Utility.Core
+{
+ internal class EmptyCommand : ICommand
+ {
+ public void run()
+ {
+ }
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/MyMoney.csproj
@@ -311,14 +311,16 @@
<Compile Include="Presentation\Model\Menu\File\Commands\SaveChangesCommand.cs" />
<Compile Include="Presentation\Model\Menu\File\Commands\save_as_command_specs.cs" />
<Compile Include="Presentation\Model\Menu\File\Commands\save_command_specs.cs" />
+ <Compile Include="Presentation\Model\Menu\IToolbarButton.cs" />
+ <Compile Include="Presentation\Model\Menu\IToolbarItemBuilder.cs" />
<Compile Include="Presentation\Model\Menu\MenuItemSeparator.cs" />
- <Compile Include="Presentation\Model\Menu\tool_bar_item_builder.cs" />
- <Compile Include="Presentation\Model\Menu\window\window_menu.cs" />
+ <Compile Include="Presentation\Model\Menu\ToolBarItemBuilder.cs" />
+ <Compile Include="Presentation\Model\Menu\window\WindowMenu.cs" />
<Compile Include="Presentation\Model\messages\closing_project_event.cs" />
<Compile Include="Presentation\Model\messages\closing_the_application.cs" />
<Compile Include="Presentation\Model\messages\unhandled_error_occurred.cs" />
<Compile Include="Presentation\Model\Navigation\branches\add_bill_payment_branch.cs" />
- <Compile Include="Presentation\Model\Navigation\branches\add_new_income_branch.cs" />
+ <Compile Include="Presentation\Model\Navigation\branches\AddNewIncomeBranch.cs" />
<Compile Include="Presentation\Model\Navigation\branches\view_all_bills_branch.cs" />
<Compile Include="Presentation\Model\Navigation\branches\view_all_bills_report_branch.cs" />
<Compile Include="Presentation\Model\Projects\CurrentProject.cs" />
@@ -338,9 +340,9 @@
<Compile Include="Presentation\Model\Navigation\IBranchVisitor.cs" />
<Compile Include="Presentation\Model\Navigation\NavigationTreeVisitor.cs" />
<Compile Include="Presentation\Model\Navigation\navigation_tree_visitor_specs.cs" />
- <Compile Include="Presentation\Model\Navigation\tree_branch.cs" />
+ <Compile Include="Presentation\Model\Navigation\TreeBranch.cs" />
<Compile Include="Presentation\Model\Navigation\tree_branch_specs.cs" />
- <Compile Include="Presentation\Model\Navigation\tree_view_to_root_node_mapper.cs" />
+ <Compile Include="Presentation\Model\Navigation\TreeViewToRootNodeMapper.cs" />
<Compile Include="Presentation\Model\Projects\CurrentProjectSpecs.cs" />
<Compile Include="Presentation\Model\Projects\file.cs" />
<Compile Include="Presentation\Model\Projects\file_not_specified_exception.cs" />
@@ -396,6 +398,7 @@
<Compile Include="Presentation\Presenters\Shell\GettingStartedPresenterSpecs.cs" />
<Compile Include="Presentation\Presenters\Shell\LogFilePresenter.cs" />
<Compile Include="Presentation\Presenters\Shell\LogFileViewPresenterSpecs.cs" />
+ <Compile Include="Presentation\Presenters\Shell\ToolbarModule.cs" />
<Compile Include="Presentation\Presenters\Shell\ToolBarPresenter.cs" />
<Compile Include="Presentation\Presenters\Navigation\MainMenuPresenter.cs" />
<Compile Include="Presentation\Presenters\Navigation\NavigationPresenter.cs" />
@@ -564,7 +567,7 @@
<Compile Include="Utility\Core\AndSpecification.cs" />
<Compile Include="Utility\Core\DisposableCommand.cs" />
<Compile Include="Utility\Core\EmptyCallback.cs" />
- <Compile Include="Utility\Core\empty_command.cs" />
+ <Compile Include="Utility\Core\EmptyCommand.cs" />
<Compile Include="Utility\Core\IBuilder.cs" />
<Compile Include="Utility\Core\ICallback.cs" />
<Compile Include="Utility\Core\IConfiguration.cs" />