[recipes/inline-editing-2] Fixes in allowing label editing of unit and ingredient



commit 4ff0d5228b2212f11e77ecb946c698c14b6e101e
Author: Ekta Nandwani <mailnandwaniekta gmail com>
Date:   Mon May 8 19:43:09 2017 +0530

    Fixes in allowing label editing of unit and ingredient
    
    Allow editing labels only on edit-page. Allow editing ingredient/unit one at a time. Remove unnecesary 
property 'name' from ingredient_label and unit_label

 src/gr-ingredients-viewer-row.c  |   45 ++++++++++++++++++++++++++++---------
 src/gr-ingredients-viewer-row.ui |    6 -----
 src/gr-ingredients-viewer.c      |    2 +-
 src/gr-ingredients-viewer.h      |    3 ++
 4 files changed, 38 insertions(+), 18 deletions(-)
---
diff --git a/src/gr-ingredients-viewer-row.c b/src/gr-ingredients-viewer-row.c
index 1efc1fa..0180996 100644
--- a/src/gr-ingredients-viewer-row.c
+++ b/src/gr-ingredients-viewer-row.c
@@ -194,6 +194,8 @@ gr_ingredients_viewer_row_set_editable (GrIngredientsViewerRow *row,
 }
 
 static void save_row (GrIngredientsViewerRow *row);
+static void save_unit (GrIngredientsViewerRow *row);
+static void save_ingredient (GrIngredientsViewerRow *row);
 
 static void
 gr_ingredients_viewer_row_set_active (GrIngredientsViewerRow *row,
@@ -259,10 +261,15 @@ drag_handle_clicked (GrIngredientsViewerRow *row)
 static void
 edit_ingredient (GrIngredientsViewerRow *row)
 {
-        gtk_entry_set_text (GTK_ENTRY (row->ingredient_entry), row->ingredient);
-        gtk_stack_set_visible_child_name (GTK_STACK (row->ingredient_stack), "ingredient_entry");
-        gtk_widget_grab_focus (row->ingredient_entry);
-        g_signal_emit (row, signals[EDIT], 0);
+        GrIngredientsViewer *viewer = gtk_widget_get_ancestor (row, GR_TYPE_INGREDIENTS_VIEWER);
+        save_unit (row);
+        if (row->editable) {
+                set_active_row (viewer, GTK_LIST_BOX_ROW (row));
+                gtk_entry_set_text (GTK_ENTRY (row->ingredient_entry), row->ingredient);
+                gtk_stack_set_visible_child_name (GTK_STACK (row->ingredient_stack), "ingredient_entry");
+                gtk_widget_grab_focus (row->ingredient_entry);
+                g_signal_emit (row, signals[EDIT], 0);
+        }
 }
 
 static void
@@ -272,16 +279,20 @@ edit_unit (GrIngredientsViewerRow *row)
         const char *amount;
         const char *space;
         const char *unit;
-
         amount = row->amount ? row->amount : "";
         space = amount[0] ? " " : "";
         unit = row->unit ? row->unit : "";
         tmp = g_strdup_printf ("%s%s%s", amount, space, unit);
-
-        gtk_entry_set_text (GTK_ENTRY (row->unit_entry), tmp);
-        gtk_stack_set_visible_child_name (GTK_STACK (row->unit_stack), "unit_entry");
-        gtk_widget_grab_focus (row->unit_entry);
-        g_signal_emit (row, signals[EDIT], 0);
+        GrIngredientsViewer *viewer = gtk_widget_get_ancestor (row, GR_TYPE_INGREDIENTS_VIEWER);
+        save_ingredient (row);
+
+        if (row->editable) {
+                set_active_row (viewer, GTK_LIST_BOX_ROW (row));
+                gtk_entry_set_text (GTK_ENTRY (row->unit_entry), tmp);
+                gtk_stack_set_visible_child_name (GTK_STACK (row->unit_stack), "unit_entry");
+                gtk_widget_grab_focus (row->unit_entry);
+                g_signal_emit (row, signals[EDIT], 0);
+        }
 }
 
 static void
@@ -304,7 +315,7 @@ parse_unit (const char  *text,
 }
 
 static void
-save_row (GrIngredientsViewerRow *row)
+save_unit (GrIngredientsViewerRow *row)
 {
         GtkWidget *visible;
 
@@ -314,7 +325,12 @@ save_row (GrIngredientsViewerRow *row)
                 update_unit (row);
                 gtk_stack_set_visible_child (GTK_STACK (row->unit_stack), row->unit_event_box);
         }
+}
 
+static void
+save_ingredient (GrIngredientsViewerRow *row)
+{
+        GtkWidget *visible;
         visible = gtk_stack_get_visible_child (GTK_STACK (row->ingredient_stack));
         if (visible == row->ingredient_entry) {
                 row->ingredient = g_strdup (gtk_entry_get_text (GTK_ENTRY (row->ingredient_entry)));
@@ -323,6 +339,13 @@ save_row (GrIngredientsViewerRow *row)
         }
 }
 
+static void
+save_row (GrIngredientsViewerRow *row)
+{
+        save_unit (row);
+        save_ingredient (row);
+}
+
 static gboolean
 entry_key_press (GrIngredientsViewerRow *row,
                  GdkEventKey            *event)
diff --git a/src/gr-ingredients-viewer-row.ui b/src/gr-ingredients-viewer-row.ui
index 839cc79..73f2ae1 100644
--- a/src/gr-ingredients-viewer-row.ui
+++ b/src/gr-ingredients-viewer-row.ui
@@ -26,9 +26,6 @@
                       <class name="dim-label"/>
                     </style>
                   </object>
-                  <packing>
-                    <property name="name">unit_label</property>
-                  </packing>
                 </child>
               </object>
             </child>
@@ -64,9 +61,6 @@
                     <property name="margin-start">9</property>
                     <property name="margin-end">9</property>
                   </object>
-                  <packing>
-                    <property name="name">ingredient_label</property>
-                  </packing>
                 </child>
               </object>
             </child>
diff --git a/src/gr-ingredients-viewer.c b/src/gr-ingredients-viewer.c
index 8ab74f2..986f6bf 100644
--- a/src/gr-ingredients-viewer.c
+++ b/src/gr-ingredients-viewer.c
@@ -82,7 +82,7 @@ gr_ingredients_viewer_finalize (GObject *object)
         G_OBJECT_CLASS (gr_ingredients_viewer_parent_class)->finalize (object);
 }
 
-static void
+void
 set_active_row (GrIngredientsViewer *viewer,
                 GtkWidget           *row)
 {
diff --git a/src/gr-ingredients-viewer.h b/src/gr-ingredients-viewer.h
index caef6a4..fa15edd 100644
--- a/src/gr-ingredients-viewer.h
+++ b/src/gr-ingredients-viewer.h
@@ -28,5 +28,8 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (GrIngredientsViewer, gr_ingredients_viewer, GR, INGREDIENTS_VIEWER, GtkBox)
 
+void set_active_row (GrIngredientsViewer *viewer,
+                     GtkWidget           *row);
+
 G_END_DECLS
 


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