Commit f79c668

mokhan <mokhan@ce5e1baf-6525-42e4-a1b2-857ea38da20a>
2009-02-26 17:36:38
implementing the save changes command.
git-svn-id: https://svn.xp-dev.com/svn/mokhan-mo.money@15 ce5e1baf-6525-42e4-a1b2-857ea38da20a
1 parent 10388f4
trunk/src/MyMoney/Presentation/Core/IPresenter.cs
@@ -3,5 +3,6 @@ using MyMoney.Utility.Core;
 namespace MyMoney.Presentation.Core
 {
     public interface IPresenter : ICommand
-    {}
+    {
+    }
 }
\ No newline at end of file
trunk/src/MyMoney/Presentation/Model/Menu/File/Commands/close_project_command.cs
@@ -5,12 +5,14 @@ using MyMoney.Utility.Core;
 namespace MyMoney.Presentation.Model.Menu.File.Commands
 {
     public interface ICloseCommand : ICommand
-    {}
+    {
+    }
 
     public class close_project_command : ICloseCommand
     {
-        private readonly IShell shell;
-        private IProject project;
+        readonly IShell shell;
+        readonly IProject project;
+
         public close_project_command(IShell shell, IProject project)
         {
             this.shell = shell;
trunk/src/MyMoney/Presentation/Model/Menu/File/Commands/SaveChangesCommand.cs
@@ -0,0 +1,79 @@
+using System;
+using MyMoney.Presentation.Core;
+using MyMoney.Presentation.Model.Projects;
+using MyMoney.Presentation.Views.dialogs;
+using MyMoney.Utility.Core;
+
+namespace MyMoney.Presentation.Model.Menu.File.Commands
+{
+    public interface ISaveChangesCommand : IParameterizedCommand<ISaveChangesCallback>
+    {
+    }
+
+    public interface ISaveChangesPresenter : IPresenter
+    {
+        void save();
+        void dont_save();
+        void cancel();
+    }
+
+    public interface ISaveChangesCallback
+    {
+        void saved();
+        void not_saved();
+        void cancelled();
+    }
+
+    public class SaveChangesCommand : ISaveChangesCommand, ISaveChangesPresenter
+    {
+        readonly IProject current_project;
+        readonly ISaveChangesView view;
+        readonly ISaveAsCommand save_as_command;
+        ISaveChangesCallback callback;
+
+        public SaveChangesCommand(IProject current_project, ISaveChangesView view, ISaveAsCommand save_as_command)
+        {
+            this.current_project = current_project;
+            this.save_as_command = save_as_command;
+            this.view = view;
+        }
+
+        public void run()
+        {
+            throw new NotImplementedException();
+        }
+
+        public void run(ISaveChangesCallback item)
+        {
+            callback = item;
+            if (current_project.has_unsaved_changes())
+            {
+                view.attach_to(this);
+                view.prompt_user_to_save();
+            }
+        }
+
+        public void save()
+        {
+            if (current_project.has_been_saved_at_least_once())
+            {
+                current_project.save_changes();
+            }
+            else
+            {
+                save_as_command.run();
+            }
+            callback.saved();
+        }
+
+        public void dont_save()
+        {
+            callback.not_saved();
+        }
+
+        public void cancel()
+        {
+            callback.cancelled();
+        }
+    }
+}
\ No newline at end of file
trunk/src/MyMoney/Presentation/Model/Projects/current_project.cs
@@ -1,3 +1,4 @@
+using System;
 using System.IO;
 using Castle.Core;
 using MyMoney.DataAccess.db40;
@@ -14,6 +15,7 @@ namespace MyMoney.Presentation.Model.Projects
         void save_to(IFile new_file);
         bool has_been_saved_at_least_once();
         void save_changes();
+        bool has_unsaved_changes();
     }
 
     [Singleton]
@@ -70,6 +72,11 @@ namespace MyMoney.Presentation.Model.Projects
             broker.publish<saved_changes_event>();
         }
 
+        public bool has_unsaved_changes()
+        {
+            throw new NotImplementedException();
+        }
+
         private void ensure_that_a_path_to_save_to_has_been_specified()
         {
             if (!has_been_saved_at_least_once()) {
trunk/src/MyMoney/Presentation/Presenters/Commands/display_the_splash_screen.cs
@@ -7,11 +7,12 @@ namespace MyMoney.Presentation.Presenters.Commands
 {
     public class display_the_splash_screen : IDisposableCommand
     {
-        private readonly ISplashScreenPresenter presenter;
+        readonly ISplashScreenPresenter presenter;
 
         public display_the_splash_screen()
             : this(new splash_screen_presenter(new interval_timer(new timer_factory()), new splash_screen_view()))
-        {}
+        {
+        }
 
         public display_the_splash_screen(ISplashScreenPresenter presenter)
         {
trunk/src/MyMoney/Presentation/Presenters/Commands/load_application_shell.cs
@@ -27,9 +27,7 @@ namespace MyMoney.Presentation.Presenters.Commands
         {
             shell.clear_menu_items();
             shell.close_all_windows();
-            registry
-                .all_implementations_of<IPresentationModule>()
-                .each(x => controller.run(x));
+            registry.all_implementations_of<IPresentationModule>().each(x => controller.run(x));
         }
     }
 }
\ No newline at end of file
trunk/src/MyMoney/Presentation/Views/dialogs/ISaveChangesView.cs
@@ -0,0 +1,10 @@
+using MyMoney.Presentation.Model.Menu.File.Commands;
+using MyMoney.Presentation.Views.core;
+
+namespace MyMoney.Presentation.Views.dialogs
+{
+    public interface ISaveChangesView : IView<ISaveChangesPresenter>
+    {
+        void prompt_user_to_save();
+    }
+}
\ No newline at end of file
trunk/src/MyMoney/windows.ui/bootstrap.cs
@@ -10,7 +10,7 @@ namespace MyMoney.windows.ui
         {
             hookup.the<global_error_handling>()
                 .then<wire_up_the_container>()
-                .then<check_for_updates>()
+                //.then<check_for_updates>()
                 .then<start_the_application>()
                 .run();
         }
trunk/src/MyMoney/windows.ui/start_the_application.cs
@@ -11,10 +11,12 @@ namespace MyMoney.windows.ui
     {
         public void run()
         {
-            try {
+            try
+            {
                 Application.Run(resolve.dependency_for<the_application_context>());
             }
-            catch (Exception e) {
+            catch (Exception e)
+            {
                 this.log().error(e);
                 MessageBox.Show(e.ToString(), e.Message);
             }
trunk/src/MyMoney/MyMoney.csproj
@@ -243,6 +243,7 @@
     <Compile Include="Presentation\Model\Menu\File\Commands\close_project_command.cs" />
     <Compile Include="Presentation\Model\Menu\File\Commands\close_window_command.cs" />
     <Compile Include="Presentation\Model\Menu\File\Commands\new_command_specs.cs" />
+    <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\menu_item_separator.cs" />
@@ -349,6 +350,7 @@
       <DependentUpon>add_bill_payment.cs</DependentUpon>
     </Compile>
     <Compile Include="Presentation\Views\billing\IAddBillPaymentView.cs" />
+    <Compile Include="Presentation\Views\dialogs\ISaveChangesView.cs" />
     <Compile Include="Presentation\Views\IAddCompanyView.cs" />
     <Compile Include="Presentation\Views\billing\IViewAllBills.cs" />
     <Compile Include="Presentation\Views\billing\view_all_bills.cs">