[niepce] * Edited labels only update when closing the dialog.



commit f5c07dfad3c819c39635744d7185d49bf250446a
Author: Hubert Figuiere <hub figuiere net>
Date:   Tue Apr 14 03:16:04 2009 -0400

    	* Edited labels only update when closing the dialog.
---
 ChangeLog                            |    4 +++
 src/niepce/ui/dialogs/editlabels.cpp |   44 ++++++++++++++++++++++++---------
 src/niepce/ui/dialogs/editlabels.hpp |   10 ++++++-
 3 files changed, 44 insertions(+), 14 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 78907af..a7f7859 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-04-14  Hubert Figuiere  <hub figuiere net>
+
+	* Edited labels only update when closing the dialog.
+
 2009-04-13  Hubert Figuiere  <hub figuiere net>
 
 	* Make undo easier to use.
diff --git a/src/niepce/ui/dialogs/editlabels.cpp b/src/niepce/ui/dialogs/editlabels.cpp
index 50a5552..eeda5fe 100644
--- a/src/niepce/ui/dialogs/editlabels.cpp
+++ b/src/niepce/ui/dialogs/editlabels.cpp
@@ -18,6 +18,8 @@
  */
 
 
+#include <algorithm>
+
 #include <boost/bind.hpp>
 #include <boost/format.hpp>
 
@@ -41,6 +43,7 @@ EditLabels::EditLabels(const eng::Label::List & labels, const LibraryClient::Ptr
     , m_labels(labels)
     , m_lib_client(libclient)
 {
+    std::fill(m_status.begin(), m_status.end(), false);
 }
 
 
@@ -62,23 +65,40 @@ void EditLabels::setup_widget()
         _builder->get_widget(str(boost::format(value_fmt) % (i+1)), labelentry);
         DBG_ASSERT(labelentry, "couldn't find label");
         labelentry->set_text(m_labels[i]->label());
-        labelentry->signal_changed().connect(
-            sigc::bind(sigc::mem_fun(*this, &EditLabels::label_name_changed), labelentry, i));
+        labelentry->property_text().signal_changed().connect(
+            sigc::bind(sigc::mem_fun(*this, &EditLabels::label_name_changed), i));
+        m_entries[i] = labelentry;
     }
+    gtkDialog().signal_response().connect(sigc::mem_fun(*this, &EditLabels::update_labels));
+}
+
+
+void EditLabels::label_name_changed(size_t idx)
+{
+    m_status[idx] = true;
 }
 
 
-void EditLabels::label_name_changed(Gtk::Entry *w, size_t idx)
+void EditLabels::update_labels(int /*response*/)
 {
-    std::string current_name = m_labels[idx]->label();
-    std::string new_name = w->get_text();
-    DBG_OUT("setting to %s", new_name.c_str());
-    fwk::UndoTransaction *undo = fwk::Application::app()->begin_undo(_("Change Label name"));
-    undo->new_command(boost::bind(&libraryclient::LibraryClient::renameLabel, 
-                                  m_lib_client, m_labels[idx]->id(), new_name),
-                      boost::bind(&libraryclient::LibraryClient::renameLabel, 
-                                  m_lib_client, m_labels[idx]->id(), current_name));
-    undo->execute();
+    fwk::UndoTransaction *undo = NULL;
+    for(int i = 0; i < 5; i++) {
+        if(m_status[i]) {
+            DBG_OUT("updating label %d", i);
+            std::string current_name = m_labels[i]->label();
+            std::string new_name = m_entries[i]->get_text();
+            if(!undo) {
+                undo = fwk::Application::app()->begin_undo(_("Change Label name"));
+            }
+            undo->new_command(boost::bind(&libraryclient::LibraryClient::renameLabel, 
+                                          m_lib_client, m_labels[i]->id(), new_name),
+                              boost::bind(&libraryclient::LibraryClient::renameLabel, 
+                                          m_lib_client, m_labels[i]->id(), current_name));
+        }
+    }
+    if(undo) {
+        undo->execute();
+    }
 }
 
 /*
diff --git a/src/niepce/ui/dialogs/editlabels.hpp b/src/niepce/ui/dialogs/editlabels.hpp
index acdfe13..14eb856 100644
--- a/src/niepce/ui/dialogs/editlabels.hpp
+++ b/src/niepce/ui/dialogs/editlabels.hpp
@@ -21,6 +21,9 @@
 #ifndef __UI_EDITLABELS_HPP__
 #define __UI_EDITLABELS_HPP__
 
+#include <tr1/array>
+
+#include <gtkmm/entry.h>
 #include <gtkmm/label.h>
 
 #include "engine/db/label.hpp"
@@ -39,8 +42,11 @@ public:
 
     virtual void setup_widget();
 private:
-    void label_name_changed(Gtk::Entry *, size_t idx);
-    eng::Label::List m_labels;
+    void label_name_changed(size_t idx);
+    void update_labels(int /*response*/);
+    eng::Label::List                  m_labels;
+    std::tr1::array<Gtk::Entry*, 5>   m_entries;
+    std::tr1::array<bool, 5>          m_status;
     libraryclient::LibraryClient::Ptr m_lib_client;
 };
 



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