[recipes/inline-editing] Avoid accidentally wiping out row contents



commit ffa09357aabf49185506e2f973e0eeba82653a04
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Apr 26 22:43:26 2017 -0400

    Avoid accidentally wiping out row contents
    
    When saving a row, we must only write back the enty contents
    to the label if the entry has been set up with the current
    content.

 src/gr-ingredients-viewer-row.c |   23 +++++++++++++++--------
 1 files changed, 15 insertions(+), 8 deletions(-)
---
diff --git a/src/gr-ingredients-viewer-row.c b/src/gr-ingredients-viewer-row.c
index 0d97273..f0d6117 100644
--- a/src/gr-ingredients-viewer-row.c
+++ b/src/gr-ingredients-viewer-row.c
@@ -295,14 +295,21 @@ parse_unit (const char  *text,
 static void
 save_row (GrIngredientsViewerRow *row)
 {
-        parse_unit (gtk_entry_get_text (GTK_ENTRY (row->unit_entry)), &row->amount, &row->unit);
+        const char *visible;
 
-        row->ingredient = g_strdup (gtk_entry_get_text (GTK_ENTRY (row->ingredient_entry)));
-        update_unit (row);
-        gtk_label_set_label (GTK_LABEL (row->ingredient_label), row->ingredient);
+        visible = gtk_stack_get_visible_child_name (GTK_STACK (row->unit_stack));
+        if (strcmp (visible, "unit_entry") == 0) {
+                parse_unit (gtk_entry_get_text (GTK_ENTRY (row->unit_entry)), &row->amount, &row->unit);
+                update_unit (row);
+                gtk_stack_set_visible_child_name (GTK_STACK (row->unit_stack), "unit_label");
+        }
 
-        gtk_stack_set_visible_child_name (GTK_STACK (row->unit_stack), "unit_label");
-        gtk_stack_set_visible_child_name (GTK_STACK (row->ingredient_stack), "ingredient_label");
+        visible = gtk_stack_get_visible_child_name (GTK_STACK (row->ingredient_stack));
+        if (strcmp (visible, "ingredient_entry") == 0) {
+                row->ingredient = g_strdup (gtk_entry_get_text (GTK_ENTRY (row->ingredient_entry)));
+                gtk_label_set_label (GTK_LABEL (row->ingredient_label), row->ingredient);
+                gtk_stack_set_visible_child_name (GTK_STACK (row->ingredient_stack), "ingredient_label");
+        }
 }
 
 static void


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