[recipes/inline-editing] Stop using selection mode



commit 553b4b317300850fab227d4093218a3dc23dedfe
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Apr 21 20:04:02 2017 -0400

    Stop using selection mode
    
    We can just start editing a row (ie showing the buttons)
    when it is activated.

 src/gr-ingredients-viewer-row.c  |    2 +-
 src/gr-ingredients-viewer-row.ui |    2 +-
 src/gr-ingredients-viewer.c      |   23 +++++++++++++++--------
 src/gr-ingredients-viewer.ui     |    3 ++-
 4 files changed, 19 insertions(+), 11 deletions(-)
---
diff --git a/src/gr-ingredients-viewer-row.c b/src/gr-ingredients-viewer-row.c
index e580fbc..c8dd6a2 100644
--- a/src/gr-ingredients-viewer-row.c
+++ b/src/gr-ingredients-viewer-row.c
@@ -272,7 +272,7 @@ gr_ingredients_viewer_row_class_init (GrIngredientsViewerRowClass *klass)
 
         pspec = g_param_spec_boolean ("editable", NULL, NULL,
                                       FALSE,
-                                      G_PARAM_READWRITE|G_PARAM_CONSTRUCT);
+                                      G_PARAM_READWRITE);
         g_object_class_install_property (object_class, PROP_EDITABLE, pspec);
 
         pspec = g_param_spec_boolean ("active", NULL, NULL,
diff --git a/src/gr-ingredients-viewer-row.ui b/src/gr-ingredients-viewer-row.ui
index 5bc3418..0608480 100644
--- a/src/gr-ingredients-viewer-row.ui
+++ b/src/gr-ingredients-viewer-row.ui
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface domain="gnome-recipes">
   <template class="GrIngredientsViewerRow" parent="GtkListBoxRow">
-    <property name="visible">True</property>
+    <property name="visible">1</property>
     <child>
       <object class="GtkBox" id="box">
         <property name="visible">1</property>
diff --git a/src/gr-ingredients-viewer.c b/src/gr-ingredients-viewer.c
index a90eeec..b305a67 100644
--- a/src/gr-ingredients-viewer.c
+++ b/src/gr-ingredients-viewer.c
@@ -102,12 +102,10 @@ set_active_row (GrIngredientsViewer *viewer,
 }
 
 static void
-selected_rows_changed (GtkListBox          *list,
-                       GrIngredientsViewer *viewer)
+row_activated (GtkListBox          *list,
+               GtkListBoxRow       *row,
+               GrIngredientsViewer *viewer)
 {
-        GtkListBoxRow *row;
-
-        row = gtk_list_box_get_selected_row (list);
         set_active_row (viewer, GTK_WIDGET (row));
 }
 
@@ -302,9 +300,18 @@ static void
 gr_ingredients_viewer_set_editable (GrIngredientsViewer *viewer,
                                     gboolean             editable)
 {
+        GList *children, *l;
+
         viewer->editable = editable;
         gtk_widget_set_visible (viewer->add_button, editable);
-        gtk_list_box_set_selection_mode (GTK_LIST_BOX (viewer->list), editable ? GTK_SELECTION_SINGLE : 
GTK_SELECTION_NONE);
+
+        children = gtk_container_get_children (GTK_CONTAINER (viewer->list));
+        for (l = children; l; l = l->next) {
+                GtkWidget *row = l->data;
+
+                g_object_set (row, "editable", viewer->editable, NULL);
+        }
+        g_list_free (children);
 }
 
 static void
@@ -312,7 +319,7 @@ gr_ingredients_viewer_set_active (GrIngredientsViewer *viewer,
                                   gboolean             active)
 {
         if (!active)
-                gtk_list_box_unselect_all (GTK_LIST_BOX (viewer->list));
+                set_active_row (viewer, NULL);
 }
 
 static void
@@ -427,7 +434,7 @@ gr_ingredients_viewer_class_init (GrIngredientsViewerClass *klass)
         gtk_widget_class_bind_template_child (widget_class, GrIngredientsViewer, add_button);
 
         gtk_widget_class_bind_template_callback (widget_class, title_changed);
-        gtk_widget_class_bind_template_callback (widget_class, selected_rows_changed);
+        gtk_widget_class_bind_template_callback (widget_class, row_activated);
         gtk_widget_class_bind_template_callback (widget_class, add_row);
         gtk_widget_class_bind_template_callback (widget_class, remove_list);
 }
diff --git a/src/gr-ingredients-viewer.ui b/src/gr-ingredients-viewer.ui
index 60cb69e..2c05655 100644
--- a/src/gr-ingredients-viewer.ui
+++ b/src/gr-ingredients-viewer.ui
@@ -55,7 +55,8 @@
       <object class="GtkListBox" id="list">
         <property name="visible">1</property>
         <property name="selection-mode">none</property>
-        <signal name="selected-rows-changed" handler="selected_rows_changed"/>
+        <property name="activate-on-single-click">1</property>
+        <signal name="row-activated" handler="row_activated"/>
         <style>
           <class name="frame"/>
         </style>


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