lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [5245] Unify duplicates


From: Greg Chicares
Subject: [lmi-commits] [5245] Unify duplicates
Date: Sat, 13 Aug 2011 21:04:45 +0000

Revision: 5245
          http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=5245
Author:   chicares
Date:     2011-08-13 21:04:44 +0000 (Sat, 13 Aug 2011)
Log Message:
-----------
Unify duplicates

Modified Paths:
--------------
    lmi/trunk/Makefile.am
    lmi/trunk/census_view.cpp
    lmi/trunk/census_view.hpp
    lmi/trunk/illustration_view.cpp
    lmi/trunk/mec_view.cpp

Added Paths:
-----------
    lmi/trunk/edit_mvc_docview_parameters.hpp

Modified: lmi/trunk/Makefile.am
===================================================================
--- lmi/trunk/Makefile.am       2011-08-11 22:16:41 UTC (rev 5244)
+++ lmi/trunk/Makefile.am       2011-08-13 21:04:44 UTC (rev 5245)
@@ -965,6 +965,7 @@
     default_view.hpp \
     docmanager_ex.hpp \
     docmdichildframe_ex.hpp \
+    edit_mvc_docview_parameters.hpp \
     emit_ledger.hpp \
     exit_codes.hpp \
     expm1.h \

Modified: lmi/trunk/census_view.cpp
===================================================================
--- lmi/trunk/census_view.cpp   2011-08-11 22:16:41 UTC (rev 5244)
+++ lmi/trunk/census_view.cpp   2011-08-13 21:04:44 UTC (rev 5245)
@@ -34,13 +34,13 @@
 #include "configurable_settings.hpp"
 #include "contains.hpp"
 #include "default_view.hpp"
+#include "edit_mvc_docview_parameters.hpp"
 #include "illustration_view.hpp"
 #include "illustrator.hpp"
 #include "input.hpp"
 #include "ledger.hpp"
 #include "ledger_text_formats.hpp"
 #include "miscellany.hpp" // is_ok_for_cctype()
-#include "mvc_controller.hpp"
 #include "path_utility.hpp"
 #include "safely_dereference_as.hpp"
 #include "wx_new.hpp"
@@ -322,8 +322,8 @@
 }
 
 int CensusView::edit_parameters
-    (Input&             lmi_input
-    ,std::string const& name
+    (Input&             parameters
+    ,std::string const& title
     )
 {
     if(is_invalid())
@@ -331,23 +331,12 @@
         return false;
         }
 
-    bool dirty = document().IsModified();
-
-    Input edited_lmi_input = lmi_input;
-    DefaultView const default_view;
-    MvcController controller(GetFrame(), edited_lmi_input, default_view);
-    controller.SetTitle(name);
-    int rc = controller.ShowModal();
-    if(wxID_OK == rc)
-        {
-        if(lmi_input != edited_lmi_input)
-            {
-            lmi_input = edited_lmi_input;
-            dirty = true;
-            }
-        document().Modify(dirty);
-        }
-    return rc;
+    return edit_mvc_docview_parameters<DefaultView>
+        (parameters
+        ,document()
+        ,GetFrame()
+        ,title
+        );
 }
 
 bool CensusView::is_invalid()

Modified: lmi/trunk/census_view.hpp
===================================================================
--- lmi/trunk/census_view.hpp   2011-08-11 22:16:41 UTC (rev 5244)
+++ lmi/trunk/census_view.hpp   2011-08-13 21:04:44 UTC (rev 5245)
@@ -118,7 +118,7 @@
 
     int edit_parameters
         (Input&             parameters
-        ,std::string const& name
+        ,std::string const& title
         );
 
     bool is_invalid();

Added: lmi/trunk/edit_mvc_docview_parameters.hpp
===================================================================
--- lmi/trunk/edit_mvc_docview_parameters.hpp                           (rev 0)
+++ lmi/trunk/edit_mvc_docview_parameters.hpp   2011-08-13 21:04:44 UTC (rev 
5245)
@@ -0,0 +1,65 @@
+// Edit parameters of a wx docview class using lmi's MVC framework.
+//
+// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 
2010, 2011 Gregory W. Chicares.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software Foundation,
+// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+//
+// http://savannah.nongnu.org/projects/lmi
+// email: <address@hidden>
+// snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
+
+// $Id$
+
+#ifndef edit_mvc_docview_parameters_hpp
+#define edit_mvc_docview_parameters_hpp
+
+#include "config.hpp"
+
+#include "mvc_controller.hpp"
+
+#include <wx/docview.h>
+#include <wx/window.h>
+
+#include <string>
+
+/// Edit parameters of a wx docview class using lmi's MVC framework.
+
+template<typename ViewT, typename ModelT>
+int edit_mvc_docview_parameters
+    (ModelT&            parameters
+    ,wxDocument&        document
+    ,wxWindow*          frame
+    ,std::string const& title = "Edit parameters"
+    )
+{
+    bool dirty = document.IsModified();
+    ModelT edited_parameters = parameters;
+    ViewT const view;
+    MvcController controller(frame, edited_parameters, view);
+    controller.SetTitle(title);
+    int rc = controller.ShowModal();
+    if(wxID_OK == rc)
+        {
+        if(parameters != edited_parameters)
+            {
+            parameters = edited_parameters;
+            dirty = true;
+            }
+        document.Modify(dirty);
+        }
+    return rc;
+}
+
+#endif // edit_mvc_docview_parameters_hpp
+


Property changes on: lmi/trunk/edit_mvc_docview_parameters.hpp
___________________________________________________________________
Added: svn:keywords
   + Id

Modified: lmi/trunk/illustration_view.cpp
===================================================================
--- lmi/trunk/illustration_view.cpp     2011-08-11 22:16:41 UTC (rev 5244)
+++ lmi/trunk/illustration_view.cpp     2011-08-13 21:04:44 UTC (rev 5245)
@@ -43,6 +43,7 @@
 #include "configurable_settings.hpp"
 #include "custom_io_0.hpp"
 #include "default_view.hpp"
+#include "edit_mvc_docview_parameters.hpp"
 #include "emit_ledger.hpp"
 #include "handle_exceptions.hpp"
 #include "illustration_document.hpp"
@@ -51,7 +52,6 @@
 #include "istream_to_string.hpp"
 #include "ledger.hpp"
 #include "ledger_text_formats.hpp"
-#include "mvc_controller.hpp"
 #include "safely_dereference_as.hpp"
 #include "timer.hpp"
 #include "wx_new.hpp"
@@ -131,22 +131,11 @@
         return wxID_CANCEL;
         }
 
-    bool dirty = document().IsModified();
-
-    Input edited_lmi_input = input_data();
-    DefaultView const default_view;
-    MvcController controller(GetFrame(), edited_lmi_input, default_view);
-    int rc = controller.ShowModal();
-    if(wxID_OK == rc)
-        {
-        if(edited_lmi_input != input_data())
-            {
-            input_data() = edited_lmi_input;
-            dirty = true;
-            }
-        document().Modify(dirty);
-        }
-    return rc;
+    return edit_mvc_docview_parameters<DefaultView>
+        (input_data()
+        ,document()
+        ,GetFrame()
+        );
 }
 
 void IllustrationView::DisplaySelectedValuesAsHtml()

Modified: lmi/trunk/mec_view.cpp
===================================================================
--- lmi/trunk/mec_view.cpp      2011-08-11 22:16:41 UTC (rev 5244)
+++ lmi/trunk/mec_view.cpp      2011-08-13 21:04:44 UTC (rev 5245)
@@ -28,11 +28,11 @@
 
 #include "mec_view.hpp"
 
+#include "edit_mvc_docview_parameters.hpp"
 #include "handle_exceptions.hpp"
 #include "mec_document.hpp"
 #include "mec_input.hpp"
 #include "mec_server.hpp"
-#include "mvc_controller.hpp"
 #include "safely_dereference_as.hpp"
 #include "wx_new.hpp"
 
@@ -118,21 +118,11 @@
 
 int mec_view::EditProperties()
 {
-    bool dirty = document().IsModified();
-    mec_input edited_input = input_data();
-    mec_mvc_view const v;
-    MvcController controller(GetFrame(), edited_input, v);
-    int rc = controller.ShowModal();
-    if(wxID_OK == rc)
-        {
-        if(edited_input != input_data())
-            {
-            input_data() = edited_input;
-            dirty = true;
-            }
-        document().Modify(dirty);
-        }
-    return rc;
+    return edit_mvc_docview_parameters<mec_mvc_view>
+        (input_data()
+        ,document()
+        ,GetFrame()
+        );
 }
 
 wxIcon mec_view::Icon() const




reply via email to

[Prev in Thread] Current Thread [Next in Thread]