[gnome-builder/wip/chergert/grep: 6/11] grep: wire up hooks to create edit points



commit 6abcffca189341e43ac7721fb33e29fd1610f5c8
Author: Christian Hergert <chergert redhat com>
Date:   Fri Oct 26 19:57:02 2018 -0700

    grep: wire up hooks to create edit points

 src/plugins/grep/gbp-grep-model.c | 67 +++++++++++++++++++++++++++++++++++++++
 src/plugins/grep/gbp-grep-model.h |  1 +
 src/plugins/grep/gbp-grep-panel.c | 18 +++++++++++
 3 files changed, 86 insertions(+)
---
diff --git a/src/plugins/grep/gbp-grep-model.c b/src/plugins/grep/gbp-grep-model.c
index 5bc14ef72..4f2ae2c27 100644
--- a/src/plugins/grep/gbp-grep-model.c
+++ b/src/plugins/grep/gbp-grep-model.c
@@ -882,3 +882,70 @@ tree_model_iface_init (GtkTreeModelIface *iface)
   iface->iter_nth_child = gbp_grep_model_iter_nth_child;
   iface->iter_parent = gbp_grep_model_iter_parent;
 }
+
+static void
+gbp_grep_model_foreach_selected (GbpGrepModel *self,
+                                 void        (*callback) (GbpGrepModel *self, guint index_, gpointer 
user_data),
+                                 gpointer      user_data)
+{
+  g_assert (GBP_IS_GREP_MODEL (self));
+  g_assert (callback != NULL);
+
+  if (self->index == NULL)
+    return;
+
+  if (self->mode == MODE_NONE)
+    {
+      GHashTableIter iter;
+      gpointer key;
+
+      g_hash_table_iter_init (&iter, self->toggled);
+      while (g_hash_table_iter_next (&iter, &key, NULL))
+        callback (self, GPOINTER_TO_UINT (key), user_data);
+    }
+  else if (self->mode == MODE_ALL)
+    {
+      for (guint i = 0; i < self->index->rows->len; i++)
+        {
+          if (!g_hash_table_contains (self->toggled, GINT_TO_POINTER (i)))
+            callback (self, i, user_data);
+        }
+    }
+  else
+    g_assert_not_reached ();
+}
+
+static void
+create_edits_cb (GbpGrepModel *self,
+                 guint         index_,
+                 gpointer      user_data)
+{
+  GPtrArray *edits = user_data;
+  const gchar *row;
+
+  g_assert (GBP_IS_GREP_MODEL (self));
+  g_assert (edits != NULL);
+
+  row = g_ptr_array_index (self->index->rows, index_);
+
+  //g_print ("ROW: %s\n", row);
+}
+
+/**
+ * gbp_grep_model_create_edits:
+ * @self: a #GbpGrepModel
+ *
+ * Returns: (transfer container): a #GPtrArray of IdeProjectEdit
+ */
+GPtrArray *
+gbp_grep_model_create_edits (GbpGrepModel *self)
+{
+  g_autoptr(GPtrArray) edits = NULL;
+
+  g_return_val_if_fail (GBP_IS_GREP_MODEL (self), NULL);
+
+  edits = g_ptr_array_new_with_free_func (g_object_unref);
+  gbp_grep_model_foreach_selected (self, create_edits_cb, edits);
+
+  return g_steal_pointer (&edits);
+}
diff --git a/src/plugins/grep/gbp-grep-model.h b/src/plugins/grep/gbp-grep-model.h
index f992b5adc..8b20d7390 100644
--- a/src/plugins/grep/gbp-grep-model.h
+++ b/src/plugins/grep/gbp-grep-model.h
@@ -47,6 +47,7 @@ void          gbp_grep_model_set_at_word_boundaries (GbpGrepModel         *self,
 const gchar  *gbp_grep_model_get_query              (GbpGrepModel         *self);
 void          gbp_grep_model_set_query              (GbpGrepModel         *self,
                                                      const gchar          *query);
+GPtrArray    *gbp_grep_model_create_edits           (GbpGrepModel         *self);
 void          gbp_grep_model_select_all             (GbpGrepModel         *self);
 void          gbp_grep_model_select_none            (GbpGrepModel         *self);
 void          gbp_grep_model_toggle_mode            (GbpGrepModel         *self);
diff --git a/src/plugins/grep/gbp-grep-panel.c b/src/plugins/grep/gbp-grep-panel.c
index 6e171f73e..14b136dc4 100644
--- a/src/plugins/grep/gbp-grep-panel.c
+++ b/src/plugins/grep/gbp-grep-panel.c
@@ -35,6 +35,7 @@ struct _GbpGrepPanel
   GtkTreeViewColumn *toggle_column;
   GtkCheckButton    *check;
   GtkButton         *close_button;
+  GtkButton         *replace_button;
 };
 
 enum {
@@ -293,6 +294,16 @@ gbp_grep_panel_toggle_all_cb (GbpGrepPanel      *self,
   gtk_widget_queue_resize (GTK_WIDGET (self->tree_view));
 }
 
+static void
+gbp_grep_panel_replace_cb (GbpGrepPanel *self,
+                           GtkButton    *button)
+{
+  g_assert (GBP_IS_GREP_PANEL (self));
+  g_assert (GTK_IS_BUTTON (button));
+
+  gbp_grep_model_create_edits (GBP_GREP_MODEL (gtk_tree_view_get_model (self->tree_view)));
+}
+
 static void
 gbp_grep_panel_get_property (GObject    *object,
                              guint       prop_id,
@@ -350,6 +361,7 @@ gbp_grep_panel_class_init (GbpGrepPanelClass *klass)
   gtk_widget_class_set_css_name (widget_class, "gbpgreppanel");
   gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/builder/plugins/grep/gbp-grep-panel.ui");
   gtk_widget_class_bind_template_child (widget_class, GbpGrepPanel, close_button);
+  gtk_widget_class_bind_template_child (widget_class, GbpGrepPanel, replace_button);
   gtk_widget_class_bind_template_child (widget_class, GbpGrepPanel, tree_view);
 }
 
@@ -367,6 +379,12 @@ gbp_grep_panel_init (GbpGrepPanel *self)
                            self,
                            G_CONNECT_SWAPPED);
 
+  g_signal_connect_object (self->replace_button,
+                           "clicked",
+                           G_CALLBACK (gbp_grep_panel_replace_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
+
   g_signal_connect_object (self->tree_view,
                            "row-activated",
                            G_CALLBACK (gbp_grep_panel_row_activated_cb),


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