[epiphany/wip/bookmarks: 17/76] bookmarks: Use GActions instead of connecting callbacks to signals



commit 586e4e34b01dcd37f1b5fd06893dd20ceba10b90
Author: Iulian Radu <iulian radu67 gmail com>
Date:   Sat Jul 30 15:40:38 2016 +0300

    bookmarks: Use GActions instead of connecting callbacks to signals

 src/ephy-bookmark-properties-grid.c           |   41 ++++++++++++++----------
 src/ephy-bookmarks-popover.c                  |   24 +++++++++++----
 src/resources/gtk/bookmark-properties-grid.ui |    2 +
 src/resources/gtk/bookmarks-popover.ui        |    1 +
 4 files changed, 45 insertions(+), 23 deletions(-)
---
diff --git a/src/ephy-bookmark-properties-grid.c b/src/ephy-bookmark-properties-grid.c
index a7c2ca7..62c5ee3 100644
--- a/src/ephy-bookmark-properties-grid.c
+++ b/src/ephy-bookmark-properties-grid.c
@@ -180,16 +180,17 @@ ephy_bookmark_properties_grid_create_tag_widget (EphyBookmarkPropertiesGrid *sel
 }
 
 static void
-ephy_bookmark_properties_grid_add_tag_button_clicked_cb (EphyBookmarkPropertiesGrid *self,
-                                                         GtkButton                  *button)
+ephy_bookmarks_properties_grid_actions_add_tag (GSimpleAction *action,
+                                                GVariant      *value,
+                                                gpointer       user_data)
 {
+  EphyBookmarkPropertiesGrid *self = user_data;
   EphyBookmarksManager *manager = ephy_shell_get_bookmarks_manager (ephy_shell_get_default ());
   GtkEntryBuffer *buffer;
   GtkWidget *widget;
   const char *text;
 
   g_assert (EPHY_IS_BOOKMARK_PROPERTIES_GRID (self));
-  g_assert (GTK_IS_BUTTON (button));
 
   buffer = gtk_entry_get_buffer (GTK_ENTRY (self->add_tag_entry));
   text = gtk_entry_buffer_get_text (buffer);
@@ -205,15 +206,17 @@ ephy_bookmark_properties_grid_add_tag_button_clicked_cb (EphyBookmarkPropertiesG
   gtk_flow_box_insert (GTK_FLOW_BOX (self->tags_box), widget, -1);
 
   gtk_entry_set_text (GTK_ENTRY (self->add_tag_entry), "");
-  gtk_widget_set_sensitive (GTK_WIDGET (button), FALSE);
+  gtk_widget_set_sensitive (GTK_WIDGET (self->add_tag_button), FALSE);
 }
 
 static void
-ephy_bookmark_properties_grid_remove_bookmark_button_clicked_cb (EphyBookmarkPropertiesGrid *self,
-                                                                 GtkButton *button)
+ephy_bookmarks_properties_grid_actions_remove_bookmark (GSimpleAction *action,
+                                                        GVariant      *value,
+                                                        gpointer       user_data)
 {
+  EphyBookmarkPropertiesGrid *self = user_data;
+
   g_assert (EPHY_IS_BOOKMARK_PROPERTIES_GRID (self));
-  g_assert (GTK_IS_BUTTON (button));
 
   g_signal_emit_by_name (self->bookmark, "removed");
 
@@ -363,9 +366,16 @@ ephy_bookmark_properties_grid_class_init (EphyBookmarkPropertiesGridClass *klass
   gtk_widget_class_bind_template_child (widget_class, EphyBookmarkPropertiesGrid, remove_bookmark_button);
 }
 
+static const GActionEntry entries[] = {
+  { "add-tag", ephy_bookmarks_properties_grid_actions_add_tag },
+  { "remove-bookmark", ephy_bookmarks_properties_grid_actions_remove_bookmark }
+};
+
 static void
 ephy_bookmark_properties_grid_init (EphyBookmarkPropertiesGrid *self)
 {
+  GSimpleActionGroup *group;
+
   gtk_widget_init_template (GTK_WIDGET (self));
 
   if (self->type == EPHY_BOOKMARK_PROPERTIES_GRID_TYPE_DIALOG) {
@@ -379,21 +389,18 @@ ephy_bookmark_properties_grid_init (EphyBookmarkPropertiesGrid *self)
                               (GtkFlowBoxSortFunc)flow_box_sort_func,
                               NULL, NULL);
 
+  group = g_simple_action_group_new ();
+  g_action_map_add_action_entries (G_ACTION_MAP (group), entries,
+                                   G_N_ELEMENTS (entries), self);
+  gtk_widget_insert_action_group (GTK_WIDGET (self), "grid",
+                                  G_ACTION_GROUP (group));
+  g_object_unref (group);
+
   g_signal_connect_object (gtk_entry_get_buffer (GTK_ENTRY (self->add_tag_entry)),
                            "notify::text",
                            G_CALLBACK (ephy_bookmark_properties_grid_buffer_text_changed_cb),
                            self,
                            G_CONNECT_SWAPPED);
-  g_signal_connect_object (self->add_tag_button,
-                           "clicked",
-                           G_CALLBACK (ephy_bookmark_properties_grid_add_tag_button_clicked_cb),
-                           self,
-                           G_CONNECT_SWAPPED);
-  g_signal_connect_object (self->remove_bookmark_button,
-                           "clicked",
-                           G_CALLBACK (ephy_bookmark_properties_grid_remove_bookmark_button_clicked_cb),
-                           self,
-                           G_CONNECT_SWAPPED);
 }
 
 GtkWidget *
diff --git a/src/ephy-bookmarks-popover.c b/src/ephy-bookmarks-popover.c
index c44b38d..03124ef 100644
--- a/src/ephy-bookmarks-popover.c
+++ b/src/ephy-bookmarks-popover.c
@@ -96,11 +96,15 @@ create_bookmark_row (gpointer item,
 }
 
 static void
-ephy_bookmarks_popover_show_tags (EphyBookmarksPopover *self,
-                                  GtkButton            *button)
+ephy_bookmarks_popover_actions_tag_detail_back (GSimpleAction *action,
+                                                GVariant      *value,
+                                                gpointer       user_data)
 {
+  EphyBookmarksPopover *self = user_data;
   GList *l;
 
+  g_assert (EPHY_IS_BOOKMARKS_POPOVER (self));
+
   gtk_stack_set_visible_child_name (GTK_STACK (self->toplevel_stack),
                                     "default");
 
@@ -129,10 +133,6 @@ ephy_bookmarks_popover_show_tag_detail (EphyBookmarksPopover *self,
   }
 
   gtk_label_set_label (GTK_LABEL (self->tag_detail_label), tag);
-  g_signal_connect_object (GTK_BUTTON (self->tag_detail_back_button),
-                           "clicked",
-                           G_CALLBACK (ephy_bookmarks_popover_show_tags),
-                           self, G_CONNECT_SWAPPED);
 
   gtk_stack_set_visible_child_name (GTK_STACK (self->toplevel_stack),
                                     "tag_detail");
@@ -254,6 +254,10 @@ ephy_bookmarks_popover_class_init (EphyBookmarksPopoverClass *klass)
   gtk_widget_class_bind_template_child (widget_class, EphyBookmarksPopover, tag_detail_label);
 }
 
+static const GActionEntry entries[] = {
+  { "tag-detail-back", ephy_bookmarks_popover_actions_tag_detail_back }
+};
+
 static void
 ephy_bookmarks_popover_init (EphyBookmarksPopover *self)
 {
@@ -264,9 +268,17 @@ ephy_bookmarks_popover_init (EphyBookmarksPopover *self)
   GList *l;
   EphyBookmark *dummy_bookmark;
   GSequence *dummy_tags;
+  GSimpleActionGroup *group;
 
   gtk_widget_init_template (GTK_WIDGET (self));
 
+  group = g_simple_action_group_new ();
+  g_action_map_add_action_entries (G_ACTION_MAP (group), entries,
+                                   G_N_ELEMENTS (entries), self);
+  gtk_widget_insert_action_group (GTK_WIDGET (self), "popover",
+                                  G_ACTION_GROUP (group));
+  g_object_unref (group);
+
   dummy_bookmark = ephy_bookmark_new (g_strdup ("https://facebook.com";),
                                       g_strdup ("Facebook"),
                                       g_sequence_new (g_free));
diff --git a/src/resources/gtk/bookmark-properties-grid.ui b/src/resources/gtk/bookmark-properties-grid.ui
index 5ec3e98..45a3e83 100644
--- a/src/resources/gtk/bookmark-properties-grid.ui
+++ b/src/resources/gtk/bookmark-properties-grid.ui
@@ -140,6 +140,7 @@
         <child>
           <object class="GtkButton" id="add_tag_button">
             <property name="label" translatable="yes">_Add</property>
+            <property name="action-name">grid.add-tag</property>
             <property name="can-default">true</property>
             <property name="sensitive">false</property>
             <property name="use-underline">true</property>
@@ -155,6 +156,7 @@
     <child>
       <object class="GtkButton" id="remove_bookmark_button">
         <property name="label" translatable="yes">_Remove Bookmark</property>
+        <property name="action-name">grid.remove-bookmark</property>
         <property name="use-underline">true</property>
         <property name="halign">end</property>
         <property name="visible">true</property>
diff --git a/src/resources/gtk/bookmarks-popover.ui b/src/resources/gtk/bookmarks-popover.ui
index 5bce5ef..26a2594 100644
--- a/src/resources/gtk/bookmarks-popover.ui
+++ b/src/resources/gtk/bookmarks-popover.ui
@@ -75,6 +75,7 @@
                     <property name="visible">true</property>
                     <child>
                       <object class="GtkButton" id="tag_detail_back_button">
+                        <property name="action-name">popover.tag-detail-back</property>
                         <property name="visible">true</property>
                         <style>
                           <class name="image-button"/>


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