[glom/cellrenderer_revert] Fix list-view editing retry. See bug #167818



commit f707ec6c4fbfb79d222e4202c85c3e4503d3db0e
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Nov 9 10:17:44 2010 +0100

    Fix list-view editing retry. See bug #167818

 glom/mode_data/db_adddel/db_adddel.cc |   45 +++++++++++++++++++++-----------
 glom/mode_data/db_adddel/db_adddel.h  |    5 +++
 2 files changed, 34 insertions(+), 16 deletions(-)
---
diff --git a/glom/mode_data/db_adddel/db_adddel.cc b/glom/mode_data/db_adddel/db_adddel.cc
index bfdd7b1..52bd4fd 100644
--- a/glom/mode_data/db_adddel/db_adddel.cc
+++ b/glom/mode_data/db_adddel/db_adddel.cc
@@ -57,6 +57,7 @@ DbAddDel::DbAddDel()
   m_allow_delete(true),
   m_find_mode(false),
   m_allow_only_one_related_record(false),
+  m_validation_retry(false),
   m_allow_view(true),
   m_allow_view_details(false),
 #ifndef GLOM_ENABLE_MAEMO
@@ -651,6 +652,8 @@ Gtk::CellRenderer* DbAddDel::construct_specified_columns_cellrenderer(const shar
     //Connect to edited signal:
     if(item_field) //Only fields can be edited:
     {
+      pCellRendererText->signal_editing_started().connect(sigc::mem_fun(*this, &DbAddDel::on_treeview_cell_editing_started));
+
       //Make it editable:
       pCellRendererText->set_property("editable", true);
 
@@ -1537,22 +1540,12 @@ void DbAddDel::on_treeview_cell_edited(const Glib::ustring& path_string, const G
                   Gtk::CellRendererText* pCell = dynamic_cast<Gtk::CellRendererText*>(pColumn->get_first_cell());
                   if(pCell)
                   {
-                    //TreeView::set_cursor(), or start_editing() would get the old value back from the model again
-                    //so we do something similar without getting the old value:
-                    m_TreeView.set_cursor(path, *pColumn, *pCell, true /* start_editing */); //This highlights the cell, and starts the editing.
-
-                    //This is based on gtk_tree_view_start_editing():
-                    //TODO: This does not actually work. I emailed gtk-list about how to do this.
-                    /*
-                    pCell->stop_editing();
-                    pCell->property_text() = "test"; //new_text; //Allow the user to start with the bad text that he entered so far.
-
-                    Gdk::Rectangle background_area;
-                    m_TreeView.get_background_area(path, *pColumn, background_area);
-
-                    Gdk::Rectangle cell_area;
-                    m_TreeView.get_cell_area(path, *pColumn, background_area);
-                    */
+                    //Set the text to be used in the start_editing signal handler:
+                    m_validation_invalid_text_for_retry = new_text;
+                    m_validation_retry = true;
+    
+                    //Highlights the cell, and start the editing:
+                    m_TreeView.set_cursor(path, *pColumn, *pCell, true /* start_editing */);
                   }
                 }
               }
@@ -2083,6 +2076,26 @@ Application* DbAddDel::get_application()
   return dynamic_cast<Application*>(pWindow);
 }
 
+void DbAddDel::on_treeview_cell_editing_started(Gtk::CellEditable* cell_editable, const Glib::ustring& /* path */)
+{
+  //Start editing with previously-entered (but invalid) text, 
+  //if we are allowing the user to correct some invalid data. 
+  if(m_validation_retry)
+  {
+    //This is the CellEditable inside the CellRenderer. 
+    Gtk::CellEditable* celleditable_validated = cell_editable;
+
+    //It's usually an Entry, at least for a CellRendererText:
+    Gtk::Entry* pEntry = dynamic_cast<Gtk::Entry*>(celleditable_validated);
+    if(pEntry)
+    {
+      pEntry->set_text(m_validation_invalid_text_for_retry);
+      m_validation_retry = false;
+      m_validation_invalid_text_for_retry.clear();
+    }
+  }
+}
+
 void DbAddDel::set_allow_view(bool val)
 {
   m_allow_view = val;
diff --git a/glom/mode_data/db_adddel/db_adddel.h b/glom/mode_data/db_adddel/db_adddel.h
index ad4f49f..7fbdecd 100644
--- a/glom/mode_data/db_adddel/db_adddel.h
+++ b/glom/mode_data/db_adddel/db_adddel.h
@@ -299,6 +299,7 @@ private:
   void on_maemo_touchselector_changed(int column);
   #else
   void treeviewcolumn_on_cell_data(Gtk::CellRenderer* renderer, const Gtk::TreeModel::iterator& iter, int model_column_index, int data_model_column_index);
+  void on_treeview_cell_editing_started(Gtk::CellEditable* cell_editable, const Glib::ustring& path);
   #endif //GLOM_ENABLE_MAEMO
 
 
@@ -431,6 +432,10 @@ private:
   bool m_find_mode;
   bool m_allow_only_one_related_record;
 
+  //Used to revert the currently-edited cell.
+  bool m_validation_retry;
+  Glib::ustring m_validation_invalid_text_for_retry;
+
   /// The primary key for the table:
   sharedptr<Field> m_key_field;
 



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