[gnome-builder: 92/139] grep: port to libide-code and libide-editor



commit d6185b1335820a9e3fd717709ee728668f420820
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 9 17:26:40 2019 -0800

    grep: port to libide-code and libide-editor

 src/plugins/grep/gbp-grep-model.c                  |  88 ++++-----
 src/plugins/grep/gbp-grep-model.h                  |   2 +-
 src/plugins/grep/gbp-grep-panel.c                  |  33 ++--
 src/plugins/grep/gbp-grep-panel.h                  |   2 +-
 src/plugins/grep/gbp-grep-popover.c                |  24 +--
 src/plugins/grep/gbp-grep-project-tree-addin.c     | 203 ---------------------
 src/plugins/grep/gbp-grep-tree-addin.c             | 170 +++++++++++++++++
 ...-project-tree-addin.h => gbp-grep-tree-addin.h} |   8 +-
 .../grep/{gbp-grep-plugin.c => grep-plugin.c}      |  14 +-
 src/plugins/grep/grep.gresource.xml                |   4 +-
 src/plugins/grep/grep.plugin                       |  13 +-
 src/plugins/grep/gtk/menus.ui                      |   4 +-
 src/plugins/grep/meson.build                       |  23 ++-
 src/plugins/grep/themes/Adwaita-dark.css           |   2 +-
 src/plugins/grep/themes/Adwaita.css                |   2 +-
 15 files changed, 279 insertions(+), 313 deletions(-)
---
diff --git a/src/plugins/grep/gbp-grep-model.c b/src/plugins/grep/gbp-grep-model.c
index 4e9e32d60..3848801a5 100644
--- a/src/plugins/grep/gbp-grep-model.c
+++ b/src/plugins/grep/gbp-grep-model.c
@@ -22,6 +22,9 @@
 
 #include "config.h"
 
+#include <libide-code.h>
+#include <libide-vcs.h>
+
 #include "gbp-grep-model.h"
 
 typedef struct
@@ -32,7 +35,9 @@ typedef struct
 
 struct _GbpGrepModel
 {
-  IdeObject parent_instance;
+  GObject parent_instance;
+
+  IdeContext *context;
 
   /* The root directory to start searching from. */
   GFile *directory;
@@ -44,7 +49,7 @@ struct _GbpGrepModel
 
   /* We need to do client-side processing to extract the exact message
    * locations after grep gives us the matching lines. This allows us to
-   * create IdeProjectEdit source ranges later as well as creating the
+   * create IdeTextEdit source ranges later as well as creating the
    * match positions for highlighting in the treeview cell renderers.
    */
   GRegex *message_regex;
@@ -77,7 +82,7 @@ struct _GbpGrepModel
 
 static void tree_model_iface_init (GtkTreeModelIface *iface);
 
-G_DEFINE_TYPE_WITH_CODE (GbpGrepModel, gbp_grep_model, IDE_TYPE_OBJECT,
+G_DEFINE_TYPE_WITH_CODE (GbpGrepModel, gbp_grep_model, G_TYPE_OBJECT,
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL, tree_model_iface_init))
 
 enum {
@@ -159,7 +164,7 @@ gbp_grep_model_line_parse (GbpGrepModelLine *cl,
           cl->line = g_ascii_strtoll (linestr, NULL, 10);
 
           /* Now parse the matches for the line so that we can highlight
-           * them in the treeview and also determine the IdeProjectEdit
+           * them in the treeview and also determine the IdeTextEdit
            * source range when editing files.
            */
 
@@ -205,11 +210,24 @@ gbp_grep_model_line_parse (GbpGrepModelLine *cl,
 GbpGrepModel *
 gbp_grep_model_new (IdeContext *context)
 {
+  GbpGrepModel *self;
+
   g_return_val_if_fail (IDE_IS_CONTEXT (context), NULL);
 
-  return g_object_new (GBP_TYPE_GREP_MODEL,
-                       "context", context,
-                       NULL);
+  self = g_object_new (GBP_TYPE_GREP_MODEL, NULL);
+  self->context = g_object_ref (context);
+
+  return g_steal_pointer (&self);
+}
+
+static void
+gbp_grep_model_dispose (GObject *object)
+{
+  GbpGrepModel *self = (GbpGrepModel *)object;
+
+  g_clear_object (&self->context);
+
+  G_OBJECT_CLASS (gbp_grep_model_parent_class)->dispose (object);
 }
 
 static void
@@ -219,6 +237,7 @@ gbp_grep_model_finalize (GObject *object)
 
   clear_line (&self->prev_line);
 
+  g_clear_object (&self->context);
   g_clear_object (&self->directory);
   g_clear_pointer (&self->index, index_free);
   g_clear_pointer (&self->query, g_free);
@@ -311,6 +330,7 @@ gbp_grep_model_class_init (GbpGrepModelClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
+  object_class->dispose = gbp_grep_model_dispose;
   object_class->finalize = gbp_grep_model_finalize;
   object_class->get_property = gbp_grep_model_get_property;
   object_class->set_property = gbp_grep_model_set_property;
@@ -424,8 +444,6 @@ gbp_grep_model_set_query (GbpGrepModel *self,
  * @self: a #GbpGrepModel
  *
  * Returns: (transfer none) (nullable): A #GFile or %NULL
- *
- * Since: 3.32
  */
 GFile *
 gbp_grep_model_get_directory (GbpGrepModel *self)
@@ -551,7 +569,6 @@ gbp_grep_model_create_launcher (GbpGrepModel *self)
 {
   g_autoptr(IdeSubprocessLauncher) launcher = NULL;
   const gchar *path;
-  IdeContext *context;
   IdeVcs *vcs;
   GFile *workdir;
   GType git_vcs;
@@ -561,10 +578,9 @@ gbp_grep_model_create_launcher (GbpGrepModel *self)
   g_assert (self->query != NULL);
   g_assert (self->query[0] != '\0');
 
-  context = ide_object_get_context (IDE_OBJECT (self));
-  vcs = ide_context_get_vcs (context);
-  workdir = ide_vcs_get_working_directory (vcs);
-  git_vcs = g_type_from_name ("IdeGitVcs");
+  vcs = ide_vcs_from_context (self->context);
+  workdir = ide_vcs_get_workdir (vcs);
+  git_vcs = g_type_from_name ("GbpGitVcs");
 
   if (self->directory != NULL)
     path = g_file_peek_path (self->directory);
@@ -577,7 +593,7 @@ gbp_grep_model_create_launcher (GbpGrepModel *self)
    * Soft runtime check for Git support, so that we can use "git grep"
    * instead of the system "grep".
    */
-  if (git_vcs != G_TYPE_INVALID && g_type_is_a (G_OBJECT_TYPE (vcs), git_vcs))
+  if (git_vcs != G_TYPE_INVALID && G_TYPE_CHECK_INSTANCE_TYPE (vcs, git_vcs))
     use_git_grep = TRUE;
 
   if (use_git_grep)
@@ -768,7 +784,7 @@ gbp_grep_model_scan_async (GbpGrepModel        *self,
       IDE_EXIT;
     }
 
-  if (dzl_str_empty0 (self->query))
+  if (ide_str_empty0 (self->query))
     {
       ide_task_return_new_error (task,
                                  G_IO_ERROR,
@@ -1122,37 +1138,27 @@ create_edits_cb (GbpGrepModel *self,
 
   if (gbp_grep_model_line_parse (&line, row, self->message_regex))
     {
-      g_autoptr(IdeFile) file = NULL;
-      g_autoptr(GFile) gfile = NULL;
-      IdeContext *context;
+      g_autoptr(GFile) file = NULL;
       guint lineno;
 
-      context = ide_object_get_context (IDE_OBJECT (self));
-      g_assert (IDE_IS_CONTEXT (context));
-
-      gfile = gbp_grep_model_get_file (self, line.path);
-      g_assert (G_IS_FILE (gfile));
-
-      file = ide_file_new (context, gfile);
-      g_assert (IDE_IS_FILE (file));
+      file = gbp_grep_model_get_file (self, line.path);
+      g_assert (G_IS_FILE (file));
 
       lineno = line.line ? line.line - 1 : 0;
 
       for (guint i = 0; i < line.matches->len; i++)
         {
           const GbpGrepModelMatch *match = &g_array_index (line.matches, GbpGrepModelMatch, i);
-          g_autoptr(IdeProjectEdit) edit = NULL;
-          g_autoptr(IdeSourceRange) range = NULL;
-          g_autoptr(IdeSourceLocation) begin = NULL;
-          g_autoptr(IdeSourceLocation) end = NULL;
+          g_autoptr(IdeTextEdit) edit = NULL;
+          g_autoptr(IdeRange) range = NULL;
+          g_autoptr(IdeLocation) begin = NULL;
+          g_autoptr(IdeLocation) end = NULL;
 
-          begin = ide_source_location_new (file, lineno, match->match_begin, 0);
-          end = ide_source_location_new (file, lineno, match->match_end, 0);
-          range = ide_source_range_new (begin, end);
+          begin = ide_location_new (file, lineno, match->match_begin);
+          end = ide_location_new (file, lineno, match->match_end);
+          range = ide_range_new (begin, end);
 
-          edit = g_object_new (IDE_TYPE_PROJECT_EDIT,
-                               "range", range,
-                               NULL);
+          edit = ide_text_edit_new (range, NULL);
 
           g_ptr_array_add (edits, g_steal_pointer (&edit));
         }
@@ -1165,9 +1171,7 @@ create_edits_cb (GbpGrepModel *self,
  * gbp_grep_model_create_edits:
  * @self: a #GbpGrepModel
  *
- * Returns: (transfer container): a #GPtrArray of IdeProjectEdit
- *
- * Since: 3.32
+ * Returns: (transfer container): a #GPtrArray of IdeTextEdit
  */
 GPtrArray *
 gbp_grep_model_create_edits (GbpGrepModel *self)
@@ -1195,8 +1199,6 @@ gbp_grep_model_create_edits (GbpGrepModel *self)
  * @line: (out): a location for the line info
  *
  * Gets information about the line that @iter points at.
- *
- * Since: 3.32
  */
 void
 gbp_grep_model_get_line (GbpGrepModel            *self,
@@ -1239,8 +1241,6 @@ gbp_grep_model_get_line (GbpGrepModel            *self,
  * gbp_grep_model_get_file:
  *
  * Returns: (transfer full): a #GFile
- *
- * Since: 3.32
  */
 GFile *
 gbp_grep_model_get_file (GbpGrepModel *self,
diff --git a/src/plugins/grep/gbp-grep-model.h b/src/plugins/grep/gbp-grep-model.h
index b2b4b5555..863934bf6 100644
--- a/src/plugins/grep/gbp-grep-model.h
+++ b/src/plugins/grep/gbp-grep-model.h
@@ -20,7 +20,7 @@
 
 #pragma once
 
-#include <ide.h>
+#include <libide-core.h>
 
 G_BEGIN_DECLS
 
diff --git a/src/plugins/grep/gbp-grep-panel.c b/src/plugins/grep/gbp-grep-panel.c
index a06799f6a..82f6ca243 100644
--- a/src/plugins/grep/gbp-grep-panel.c
+++ b/src/plugins/grep/gbp-grep-panel.c
@@ -23,6 +23,9 @@
 #include "config.h"
 
 #include <glib/gi18n.h>
+#include <libide-code.h>
+#include <libide-editor.h>
+#include <libide-gui.h>
 
 #include "gbp-grep-panel.h"
 
@@ -220,26 +223,22 @@ gbp_grep_panel_row_activated_cb (GbpGrepPanel      *self,
 
       if G_LIKELY (line != NULL)
         {
-          g_autoptr(IdeSourceLocation) location = NULL;
+          g_autoptr(IdeLocation) location = NULL;
           g_autoptr(GFile) child = NULL;
-          g_autoptr(IdeFile) ichild = NULL;
-          IdePerspective *editor;
-          IdeWorkbench *workbench;
-          IdeContext *context;
+          IdeWorkspace *workspace;
+          IdeSurface *editor;
           guint lineno = line->line;
 
-          workbench = ide_widget_get_workbench (GTK_WIDGET (self));
-          context = ide_workbench_get_context (workbench);
-          editor = ide_workbench_get_perspective_by_name (workbench, "editor");
+          workspace = ide_widget_get_workspace (GTK_WIDGET (self));
+          editor = ide_workspace_get_surface_by_name (workspace, "editor");
 
           if (lineno > 0)
             lineno--;
 
           child = gbp_grep_model_get_file (GBP_GREP_MODEL (model), line->path);
-          ichild = ide_file_new (context, child);
-          location = ide_source_location_new (ichild, lineno, 0, 0);
+          location = ide_location_new (child, lineno, -1);
 
-          ide_editor_perspective_focus_location (IDE_EDITOR_PERSPECTIVE (editor), location);
+          ide_editor_surface_focus_location (IDE_EDITOR_SURFACE (editor), location);
         }
     }
 }
@@ -334,8 +333,8 @@ gbp_grep_panel_replace_clicked_cb (GbpGrepPanel *self,
 
   for (guint i = 0; i < edits->len; i++)
     {
-      IdeProjectEdit *edit = g_ptr_array_index (edits, i);
-      ide_project_edit_set_replacement (edit, text);
+      IdeTextEdit *edit = g_ptr_array_index (edits, i);
+      ide_text_edit_set_text (edit, text);
     }
 
   g_debug ("Replacing %u edit points with %s", edits->len, text);
@@ -347,7 +346,7 @@ gbp_grep_panel_replace_clicked_cb (GbpGrepPanel *self,
   gtk_spinner_start (self->spinner);
 
   context = ide_widget_get_context (GTK_WIDGET (self));
-  bufmgr = ide_context_get_buffer_manager (context);
+  bufmgr = ide_buffer_manager_from_context (context);
 
   ide_buffer_manager_apply_edits_async (bufmgr,
                                         IDE_PTR_ARRAY_STEAL_FULL (&edits),
@@ -411,7 +410,7 @@ gbp_grep_panel_class_init (GbpGrepPanelClass *klass)
   g_object_class_install_properties (object_class, N_PROPS, properties);
 
   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_set_template_from_resource (widget_class, "/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, replace_entry);
@@ -490,8 +489,8 @@ gbp_grep_panel_init (GbpGrepPanel *self)
                        "ellipsize", PANGO_ELLIPSIZE_END,
                        NULL);
   gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), cell, TRUE);
-  gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (column), cell, match_data_func, NULL, NULL);
   /* translators: the column header for the matches in the 'find in files' results */
+  gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (column), cell, match_data_func, NULL, NULL);
   gtk_tree_view_column_set_title (column, _("Match"));
   gtk_tree_view_column_set_expand (column, TRUE);
   gtk_tree_view_column_set_resizable (column, TRUE);
@@ -536,8 +535,6 @@ gbp_grep_panel_set_model (GbpGrepPanel *self,
  * @self: a #GbpGrepPanel
  *
  * Returns: (transfer none) (nullable): a #GbpGrepModel
- *
- * Since: 3.32
  */
 GbpGrepModel *
 gbp_grep_panel_get_model (GbpGrepPanel *self)
diff --git a/src/plugins/grep/gbp-grep-panel.h b/src/plugins/grep/gbp-grep-panel.h
index e10dc095f..8a8cd3521 100644
--- a/src/plugins/grep/gbp-grep-panel.h
+++ b/src/plugins/grep/gbp-grep-panel.h
@@ -20,7 +20,7 @@
 
 #pragma once
 
-#include <ide.h>
+#include <dazzle.h>
 
 #include "gbp-grep-model.h"
 
diff --git a/src/plugins/grep/gbp-grep-popover.c b/src/plugins/grep/gbp-grep-popover.c
index 22ab65430..af2df8e2a 100644
--- a/src/plugins/grep/gbp-grep-popover.c
+++ b/src/plugins/grep/gbp-grep-popover.c
@@ -22,7 +22,9 @@
 
 #include "config.h"
 
-#include <ide.h>
+#include <libide-code.h>
+#include <libide-gui.h>
+#include <libide-editor.h>
 
 #include "gbp-grep-model.h"
 #include "gbp-grep-panel.h"
@@ -30,9 +32,9 @@
 
 struct _GbpGrepPopover
 {
-  GtkPopover parent_instance;
+  GtkPopover      parent_instance;
 
-  GFile *file;
+  GFile          *file;
 
   GtkEntry       *entry;
   GtkButton      *button;
@@ -67,7 +69,7 @@ gbp_grep_popover_scan_cb (GObject      *object,
   g_assert (GBP_IS_GREP_PANEL (panel));
 
   if (!gbp_grep_model_scan_finish (model, result, &error))
-    ide_widget_warning (GTK_WIDGET (panel), "Failed to find files: %s", error->message);
+    g_warning ("Failed to find files: %s", error->message);
   else
     gbp_grep_panel_set_model (panel, model);
 
@@ -79,8 +81,8 @@ gbp_grep_popover_button_clicked_cb (GbpGrepPopover *self,
                                     GtkButton      *button)
 {
   g_autoptr(GbpGrepModel) model = NULL;
-  IdePerspective *editor;
-  IdeWorkbench *workbench;
+  IdeSurface *editor;
+  IdeWorkspace *workspace;
   IdeContext *context;
   GtkWidget *panel;
   GtkWidget *utils;
@@ -92,10 +94,10 @@ gbp_grep_popover_button_clicked_cb (GbpGrepPopover *self,
   g_assert (GBP_IS_GREP_POPOVER (self));
   g_assert (GTK_IS_BUTTON (button));
 
-  workbench = ide_widget_get_workbench (GTK_WIDGET (self));
-  editor = ide_workbench_get_perspective_by_name (workbench, "editor");
-  utils = ide_editor_perspective_get_utilities (IDE_EDITOR_PERSPECTIVE (editor));
-  context = ide_workbench_get_context (workbench);
+  workspace = ide_widget_get_workspace (GTK_WIDGET (self));
+  editor = ide_workspace_get_surface_by_name (workspace, "editor");
+  utils = ide_editor_surface_get_utilities (IDE_EDITOR_SURFACE (editor));
+  context = ide_widget_get_context (GTK_WIDGET (workspace));
 
   use_regex = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->regex_button));
   at_word_boundaries = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->whole_button));
@@ -213,7 +215,7 @@ gbp_grep_popover_class_init (GbpGrepPopoverClass *klass)
 
   g_object_class_install_properties (object_class, N_PROPS, properties);
 
-  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/builder/plugins/grep/gbp-grep-popover.ui");
+  gtk_widget_class_set_template_from_resource (widget_class, "/plugins/grep/gbp-grep-popover.ui");
   gtk_widget_class_bind_template_child (widget_class, GbpGrepPopover, button);
   gtk_widget_class_bind_template_child (widget_class, GbpGrepPopover, entry);
   gtk_widget_class_bind_template_child (widget_class, GbpGrepPopover, regex_button);
diff --git a/src/plugins/grep/gbp-grep-tree-addin.c b/src/plugins/grep/gbp-grep-tree-addin.c
new file mode 100644
index 000000000..45038c52c
--- /dev/null
+++ b/src/plugins/grep/gbp-grep-tree-addin.c
@@ -0,0 +1,170 @@
+/* gbp-grep-tree-addin.c
+ *
+ * Copyright 2018-2019 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-grep-tree-addin"
+
+#include "config.h"
+
+#include <libide-projects.h>
+#include <libide-tree.h>
+
+#include "gbp-grep-tree-addin.h"
+#include "gbp-grep-popover.h"
+
+struct _GbpGrepTreeAddin
+{
+  GObject  parent_instance;
+
+  IdeTree *tree;
+};
+
+static void
+popover_closed_cb (GtkPopover *popover)
+{
+  GtkWidget *toplevel;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GTK_IS_POPOVER (popover));
+
+  /*
+   * Clear focus before destroying popover, or we risk some
+   * re-entrancy issues in libdazzle. Needs safer tracking of
+   * focus widgets as gtk is not clearing pointers in destroy.
+   */
+
+  toplevel = gtk_widget_get_toplevel (GTK_WIDGET (popover));
+  gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
+  gtk_widget_destroy (GTK_WIDGET (popover));
+}
+
+static void
+find_in_files_action (GSimpleAction *action,
+                      GVariant      *param,
+                      gpointer       user_data)
+{
+  GbpGrepTreeAddin *self = user_data;
+  g_autoptr(GFile) file = NULL;
+  IdeProjectFile *project_file;
+  IdeTreeNode *node;
+
+  g_assert (G_IS_SIMPLE_ACTION (action));
+  g_assert (GBP_IS_GREP_TREE_ADDIN (self));
+  g_assert (self->tree != NULL);
+  g_assert (IDE_IS_TREE (self->tree));
+
+  if ((node = ide_tree_get_selected_node (self->tree)) &&
+      ide_tree_node_holds (node, IDE_TYPE_PROJECT_FILE) &&
+      (project_file = ide_tree_node_get_item (node)) &&
+      (file = ide_project_file_ref_file (project_file)))
+    {
+      gboolean is_dir = ide_project_file_is_directory (project_file);
+      GtkPopover *popover;
+
+      popover = g_object_new (GBP_TYPE_GREP_POPOVER,
+                              "file", file,
+                              "is-directory", is_dir,
+                              "position", GTK_POS_RIGHT,
+                              NULL);
+      g_signal_connect_after (popover,
+                              "closed",
+                              G_CALLBACK (popover_closed_cb),
+                              NULL);
+      ide_tree_show_popover_at_node (self->tree, node, popover);
+    }
+}
+
+static void
+gbp_grep_tree_addin_load (IdeTreeAddin *addin,
+                          IdeTree      *tree,
+                          IdeTreeModel *model)
+{
+  GbpGrepTreeAddin *self = (GbpGrepTreeAddin *)addin;
+  g_autoptr(GActionMap) group = NULL;
+  static const GActionEntry actions[] = {
+    { "find-in-files", find_in_files_action },
+  };
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_GREP_TREE_ADDIN (self));
+  g_assert (IDE_IS_TREE (tree));
+  g_assert (IDE_IS_TREE_MODEL (model));
+
+  self->tree = tree;
+
+  group = G_ACTION_MAP (g_simple_action_group_new ());
+  g_action_map_add_action_entries (group, actions, G_N_ELEMENTS (actions), self);
+  gtk_widget_insert_action_group (GTK_WIDGET (tree), "grep", G_ACTION_GROUP (group));
+}
+
+static void
+gbp_grep_tree_addin_unload (IdeTreeAddin *addin,
+                            IdeTree      *tree,
+                            IdeTreeModel *model)
+{
+  GbpGrepTreeAddin *self = (GbpGrepTreeAddin *)addin;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_GREP_TREE_ADDIN (self));
+  g_assert (IDE_IS_TREE (tree));
+  g_assert (IDE_IS_TREE_MODEL (model));
+
+  gtk_widget_insert_action_group (GTK_WIDGET (tree), "grep", NULL);
+
+  self->tree = NULL;
+}
+
+static void
+gbp_grep_tree_addin_selection_changed (IdeTreeAddin *addin,
+                                       IdeTreeNode  *node)
+{
+  GbpGrepTreeAddin *self = (GbpGrepTreeAddin *)addin;
+  gboolean enabled;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_GREP_TREE_ADDIN (self));
+  g_assert (!node || IDE_IS_TREE_NODE (node));
+
+  enabled = node && ide_tree_node_holds (node, IDE_TYPE_PROJECT_FILE);
+
+  dzl_gtk_widget_action_set (GTK_WIDGET (self->tree), "grep", "find-in-files",
+                             "enabled", enabled,
+                             NULL);
+}
+
+static void
+tree_addin_iface_init (IdeTreeAddinInterface *iface)
+{
+  iface->load = gbp_grep_tree_addin_load;
+  iface->unload = gbp_grep_tree_addin_unload;
+  iface->selection_changed = gbp_grep_tree_addin_selection_changed;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpGrepTreeAddin, gbp_grep_tree_addin, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (IDE_TYPE_TREE_ADDIN, tree_addin_iface_init))
+
+static void
+gbp_grep_tree_addin_class_init (GbpGrepTreeAddinClass *klass)
+{
+}
+
+static void
+gbp_grep_tree_addin_init (GbpGrepTreeAddin *self)
+{
+}
diff --git a/src/plugins/grep/gbp-grep-project-tree-addin.h b/src/plugins/grep/gbp-grep-tree-addin.h
similarity index 76%
rename from src/plugins/grep/gbp-grep-project-tree-addin.h
rename to src/plugins/grep/gbp-grep-tree-addin.h
index b67d71a56..7e90aa768 100644
--- a/src/plugins/grep/gbp-grep-project-tree-addin.h
+++ b/src/plugins/grep/gbp-grep-tree-addin.h
@@ -1,4 +1,4 @@
-/* gbp-grep-project-tree-addin.h
+/* gbp-grep-tree-addin.h
  *
  * Copyright 2018-2019 Christian Hergert <chergert redhat com>
  *
@@ -20,12 +20,12 @@
 
 #pragma once
 
-#include <ide.h>
+#include <glib-object.h>
 
 G_BEGIN_DECLS
 
-#define GBP_TYPE_GREP_PROJECT_TREE_ADDIN (gbp_grep_project_tree_addin_get_type())
+#define GBP_TYPE_GREP_TREE_ADDIN (gbp_grep_tree_addin_get_type())
 
-G_DECLARE_FINAL_TYPE (GbpGrepProjectTreeAddin, gbp_grep_project_tree_addin, GBP, GREP_PROJECT_TREE_ADDIN, 
GObject)
+G_DECLARE_FINAL_TYPE (GbpGrepTreeAddin, gbp_grep_tree_addin, GBP, GREP_TREE_ADDIN, GObject)
 
 G_END_DECLS
diff --git a/src/plugins/grep/gbp-grep-plugin.c b/src/plugins/grep/grep-plugin.c
similarity index 75%
rename from src/plugins/grep/gbp-grep-plugin.c
rename to src/plugins/grep/grep-plugin.c
index bcae06e9d..561dc0b1f 100644
--- a/src/plugins/grep/gbp-grep-plugin.c
+++ b/src/plugins/grep/grep-plugin.c
@@ -18,15 +18,17 @@
  * SPDX-License-Identifier: GPL-3.0-or-later
  */
 
-#include <ide.h>
+#include "config.h"
+
+#include <libide-tree.h>
 #include <libpeas/peas.h>
 
-#include "gbp-grep-project-tree-addin.h"
+#include "gbp-grep-tree-addin.h"
 
-void
-gbp_grep_register_types (PeasObjectModule *module)
+_IDE_EXTERN void
+_gbp_grep_register_types (PeasObjectModule *module)
 {
   peas_object_module_register_extension_type (module,
-                                              IDE_TYPE_PROJECT_TREE_ADDIN,
-                                              GBP_TYPE_GREP_PROJECT_TREE_ADDIN);
+                                              IDE_TYPE_TREE_ADDIN,
+                                              GBP_TYPE_GREP_TREE_ADDIN);
 }
diff --git a/src/plugins/grep/grep.gresource.xml b/src/plugins/grep/grep.gresource.xml
index ead09764c..3b3e67fff 100644
--- a/src/plugins/grep/grep.gresource.xml
+++ b/src/plugins/grep/grep.gresource.xml
@@ -1,9 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
-  <gresource prefix="/org/gnome/builder/plugins">
+  <gresource prefix="/plugins/grep">
     <file>grep.plugin</file>
-  </gresource>
-  <gresource prefix="/org/gnome/builder/plugins/grep">
     <file preprocess="xml-stripblanks">gbp-grep-panel.ui</file>
     <file preprocess="xml-stripblanks">gbp-grep-popover.ui</file>
     <file preprocess="xml-stripblanks">gtk/menus.ui</file>
diff --git a/src/plugins/grep/grep.plugin b/src/plugins/grep/grep.plugin
index 8812d8ab0..d3c3e63c4 100644
--- a/src/plugins/grep/grep.plugin
+++ b/src/plugins/grep/grep.plugin
@@ -1,9 +1,10 @@
 [Plugin]
-Module=grep
-Name=Find in Files
-Description=Search across project files
 Authors=Christian Hergert <christian hergert me>
-Copyright=Copyright © 2018 Christian Hergert
 Builtin=true
-Depends=editor;project-tree-plugin
-Embedded=gbp_grep_register_types
+Copyright=Copyright © 2018 Christian Hergert
+Depends=editor;project-tree;
+Description=Search across project files
+Embedded=_gbp_grep_register_types
+Module=grep
+Name=Find in Files
+X-Tree-Kind=project-tree;
diff --git a/src/plugins/grep/gtk/menus.ui b/src/plugins/grep/gtk/menus.ui
index aef127545..b088282ec 100644
--- a/src/plugins/grep/gtk/menus.ui
+++ b/src/plugins/grep/gtk/menus.ui
@@ -1,7 +1,7 @@
 <?xml version="1.0"?>
 <interface>
-  <menu id="gb-project-tree-popup-menu">
-    <section id="gb-project-tree-find-section">
+  <menu id="project-tree-menu">
+    <section id="project-tree-menu-placeholder2">
       <item>
         <attribute name="label" translatable="yes">Find in Files</attribute>
         <attribute name="action">grep.find-in-files</attribute>
diff --git a/src/plugins/grep/meson.build b/src/plugins/grep/meson.build
index 8a921fe25..d6e586c7b 100644
--- a/src/plugins/grep/meson.build
+++ b/src/plugins/grep/meson.build
@@ -1,20 +1,19 @@
-if get_option('with_grep')
+if get_option('plugin_grep')
 
-grep_resources = gnome.compile_resources(
+plugins_sources += files([
+  'gbp-grep-model.c',
+  'gbp-grep-panel.c',
+  'gbp-grep-popover.c',
+  'gbp-grep-tree-addin.c',
+  'grep-plugin.c',
+])
+
+plugin_grep_resources = gnome.compile_resources(
   'grep-resources',
   'grep.gresource.xml',
   c_name: 'gbp_grep',
 )
 
-grep_sources = [
-  'gbp-grep-model.c',
-  'gbp-grep-panel.c',
-  'gbp-grep-plugin.c',
-  'gbp-grep-popover.c',
-  'gbp-grep-project-tree-addin.c',
-]
-
-gnome_builder_plugins_sources += files(grep_sources)
-gnome_builder_plugins_sources += grep_resources[0]
+plugins_sources += plugin_grep_resources[0]
 
 endif
diff --git a/src/plugins/grep/themes/Adwaita-dark.css b/src/plugins/grep/themes/Adwaita-dark.css
index 0413f3e93..7341ec7c4 100644
--- a/src/plugins/grep/themes/Adwaita-dark.css
+++ b/src/plugins/grep/themes/Adwaita-dark.css
@@ -1,2 +1,2 @@
-@import url("resource:///org/gnome/builder/plugins/grep/themes/Adwaita-shared.css");
+@import url("resource:///plugins/grep/themes/Adwaita-shared.css");
 
diff --git a/src/plugins/grep/themes/Adwaita.css b/src/plugins/grep/themes/Adwaita.css
index 0413f3e93..7341ec7c4 100644
--- a/src/plugins/grep/themes/Adwaita.css
+++ b/src/plugins/grep/themes/Adwaita.css
@@ -1,2 +1,2 @@
-@import url("resource:///org/gnome/builder/plugins/grep/themes/Adwaita-shared.css");
+@import url("resource:///plugins/grep/themes/Adwaita-shared.css");
 


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