Commit 1ffe86d

mokhan <mokhan@ce5e1baf-6525-42e4-a1b2-857ea38da20a>
2009-03-28 20:19:03
putting menu item and toolbar item commands on to the command processor.
git-svn-id: https://svn.xp-dev.com/svn/mokhan-mo.money@122 ce5e1baf-6525-42e4-a1b2-857ea38da20a
1 parent b19f19d
Changed files (5)
trunk/product/MyMoney/boot/start_the_application.cs
@@ -15,21 +15,24 @@ namespace MoMoney.boot
     internal class start_the_application : ICommand
     {
         ILoadPresentationModulesCommand command;
+        ICommandProcessor processor;
 
-        public start_the_application() : this(Lazy.load<ILoadPresentationModulesCommand>())
+        public start_the_application()
+            : this(Lazy.load<ILoadPresentationModulesCommand>(), Lazy.load<ICommandProcessor>())
         {
         }
 
-        public start_the_application(ILoadPresentationModulesCommand command)
+        public start_the_application(ILoadPresentationModulesCommand command, ICommandProcessor processor)
         {
             this.command = command;
+            this.processor = processor;
         }
 
         public void run()
         {
             try
             {
-                resolve.dependency_for<ICommandProcessor>().run();
+                processor.run();
                 command.run();
                 Application.Run(resolve.dependency_for<ApplicationShell>());
             }
trunk/product/MyMoney/Presentation/Model/Menu/create.cs
@@ -1,5 +1,4 @@
 using MoMoney.Infrastructure.Container;
-using MoMoney.Infrastructure.eventing;
 
 namespace MoMoney.Presentation.Model.Menu
 {
@@ -7,7 +6,7 @@ namespace MoMoney.Presentation.Model.Menu
     {
         public static IMenuItemBuilder a_menu_item()
         {
-            return new MenuItemBuilder(resolve.dependency_for<IDependencyRegistry>(),resolve.dependency_for<IEventAggregator>());
+            return resolve.dependency_for<IMenuItemBuilder>();
         }
 
         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 ToolBarItemBuilder(resolve.dependency_for<IDependencyRegistry>(),resolve.dependency_for<IEventAggregator>());
+            return resolve.dependency_for<IToolbarItemBuilder>();
         }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Presentation/Model/Menu/MenuItemBuilder.cs
@@ -1,6 +1,7 @@
 using System;
 using MoMoney.Infrastructure.Container;
 using MoMoney.Infrastructure.eventing;
+using MoMoney.Infrastructure.Threading;
 using MoMoney.Presentation.Model.keyboard;
 using MoMoney.Presentation.Resources;
 using MoMoney.Utility.Core;
@@ -21,13 +22,15 @@ namespace MoMoney.Presentation.Model.Menu
     {
         readonly IDependencyRegistry registry;
         Func<bool> can_be_clicked = () => true;
-        IEventAggregator aggregator;
+        readonly IEventAggregator aggregator;
+        readonly ICommandProcessor processor;
 
-        public MenuItemBuilder(IDependencyRegistry registry, IEventAggregator aggregator)
+        public MenuItemBuilder(IDependencyRegistry registry, IEventAggregator aggregator, ICommandProcessor processor)
         {
             name_of_the_menu = "Unknown";
             command_to_execute = () => { };
             this.registry = registry;
+            this.processor = processor;
             this.aggregator = aggregator;
             icon = ApplicationIcons.Empty;
             key = ShortcutKeys.none;
@@ -46,7 +49,7 @@ namespace MoMoney.Presentation.Model.Menu
 
         public IMenuItemBuilder that_executes<TheCommand>() where TheCommand : ICommand
         {
-            command_to_execute = () => registry.get_a<TheCommand>().run();
+            command_to_execute = () => processor.add( registry.get_a<TheCommand>());
             return this;
         }
 
trunk/product/MyMoney/Presentation/Model/Menu/ToolBarItemBuilder.cs
@@ -2,6 +2,7 @@ using System;
 using System.Windows.Forms;
 using MoMoney.Infrastructure.Container;
 using MoMoney.Infrastructure.eventing;
+using MoMoney.Infrastructure.Threading;
 using MoMoney.Presentation.Resources;
 using MoMoney.Utility.Core;
 
@@ -10,12 +11,14 @@ namespace MoMoney.Presentation.Model.Menu
     public class ToolBarItemBuilder : IToolbarItemBuilder, IToolbarButton
     {
         readonly IDependencyRegistry registry;
-        Func<bool> the_condition;
         readonly ToolStripButton item;
+        readonly ICommandProcessor processor;
+        Func<bool> the_condition;
 
-        public ToolBarItemBuilder(IDependencyRegistry registry, IEventAggregator aggregator)
+        public ToolBarItemBuilder(IDependencyRegistry registry, IEventAggregator aggregator, ICommandProcessor processor)
         {
             this.registry = registry;
+            this.processor = processor;
             aggregator.subscribe(this);
             the_condition = () => true;
             item = new ToolStripButton {};
@@ -29,7 +32,7 @@ namespace MoMoney.Presentation.Model.Menu
 
         public IToolbarItemBuilder when_clicked_executes<Command>() where Command : ICommand
         {
-            item.Click += (sender, args) => registry.get_a<Command>();
+            item.Click += (sender, args) => processor.add(registry.get_a<Command>());
             return this;
         }
 
trunk/product/MyMoney/Presentation/Views/Shell/ApplicationShell.cs
@@ -32,8 +32,8 @@ namespace MoMoney.Presentation.Views.Shell
 
         protected override void OnLoad(EventArgs e)
         {
+            base.OnLoad(e);
             try_to_reduce_flickering();
-            //.top_most();
         }
 
         public void attach_to(IApplicationShellPresenter presenter)