[gnome-builder: 78/139] file-search: port to libide-search



commit dd1b34376451cbc88b638136d45b8556a939d66c
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 9 17:17:35 2019 -0800

    file-search: port to libide-search
    
    This also renames the gb- prefix to gbp-.

 src/plugins/file-search/file-search-plugin.c       |  36 ++++
 src/plugins/file-search/file-search.gresource.xml  |   2 +-
 src/plugins/file-search/file-search.plugin         |  10 +-
 ...file-search-index.c => gbp-file-search-index.c} |  98 ++++++-----
 ...file-search-index.h => gbp-file-search-index.h} |  20 +--
 ...earch-provider.c => gbp-file-search-provider.c} | 194 +++++++++++----------
 ...earch-provider.h => gbp-file-search-provider.h} |   9 +-
 ...le-search-result.c => gbp-file-search-result.c} |  70 ++++----
 ...le-search-result.h => gbp-file-search-result.h} |   8 +-
 src/plugins/file-search/meson.build                |  25 ++-
 10 files changed, 261 insertions(+), 211 deletions(-)
---
diff --git a/src/plugins/file-search/file-search-plugin.c b/src/plugins/file-search/file-search-plugin.c
new file mode 100644
index 000000000..52d25f9b8
--- /dev/null
+++ b/src/plugins/file-search/file-search-plugin.c
@@ -0,0 +1,36 @@
+/* file-search-plugin.c
+ *
+ * Copyright 2015-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 "file-search-plugin"
+
+#include "config.h"
+
+#include <libide-search.h>
+#include <libpeas/peas.h>
+
+#include "gbp-file-search-provider.h"
+
+void
+_gbp_file_search_register_types (PeasObjectModule *module)
+{
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_SEARCH_PROVIDER,
+                                              GBP_TYPE_FILE_SEARCH_PROVIDER);
+}
diff --git a/src/plugins/file-search/file-search.gresource.xml 
b/src/plugins/file-search/file-search.gresource.xml
index 344062a83..a00b8c87c 100644
--- a/src/plugins/file-search/file-search.gresource.xml
+++ b/src/plugins/file-search/file-search.gresource.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
-  <gresource prefix="/org/gnome/builder/plugins">
+  <gresource prefix="/plugins/file-search">
     <file>file-search.plugin</file>
   </gresource>
 </gresources>
diff --git a/src/plugins/file-search/file-search.plugin b/src/plugins/file-search/file-search.plugin
index b356c4313..b4721368e 100644
--- a/src/plugins/file-search/file-search.plugin
+++ b/src/plugins/file-search/file-search.plugin
@@ -1,8 +1,8 @@
 [Plugin]
-Module=file-search
-Name=File Search
-Description=Search for files in the global search bar
 Authors=Christian Hergert <christian hergert me>
-Copyright=Copyright © 2015-2017 Christian Hergert
 Builtin=true
-Embedded=gb_file_search_register_types
+Copyright=Copyright © 2015-2018 Christian Hergert
+Description=Search for files in the global search bar
+Embedded=_gbp_file_search_register_types
+Module=file-search
+Name=File Search
diff --git a/src/plugins/file-search/gb-file-search-index.c b/src/plugins/file-search/gbp-file-search-index.c
similarity index 79%
rename from src/plugins/file-search/gb-file-search-index.c
rename to src/plugins/file-search/gbp-file-search-index.c
index 8e6baf31b..b2059bdb2 100644
--- a/src/plugins/file-search/gb-file-search-index.c
+++ b/src/plugins/file-search/gbp-file-search-index.c
@@ -1,4 +1,4 @@
-/* gb-file-search-index.c
+/* gbp-file-search-index.c
  *
  * Copyright 2015-2019 Christian Hergert <christian hergert me>
  *
@@ -18,16 +18,18 @@
  * SPDX-License-Identifier: GPL-3.0-or-later
  */
 
-#define G_LOG_DOMAIN "gb-file-search-index"
+#define G_LOG_DOMAIN "gbp-file-search-index"
 
 #include <glib/gi18n.h>
-#include <ide.h>
+#include <libide-search.h>
+#include <libide-code.h>
+#include <libide-vcs.h>
 #include <string.h>
 
-#include "gb-file-search-index.h"
-#include "gb-file-search-result.h"
+#include "gbp-file-search-index.h"
+#include "gbp-file-search-result.h"
 
-struct _GbFileSearchIndex
+struct _GbpFileSearchIndex
 {
   IdeObject             parent_instance;
 
@@ -35,7 +37,7 @@ struct _GbFileSearchIndex
   DzlFuzzyMutableIndex *fuzzy;
 };
 
-G_DEFINE_TYPE (GbFileSearchIndex, gb_file_search_index, IDE_TYPE_OBJECT)
+G_DEFINE_TYPE (GbpFileSearchIndex, gbp_file_search_index, IDE_TYPE_OBJECT)
 
 enum {
   PROP_0,
@@ -46,10 +48,10 @@ enum {
 static GParamSpec *properties [LAST_PROP];
 
 static void
-gb_file_search_index_set_root_directory (GbFileSearchIndex *self,
+gbp_file_search_index_set_root_directory (GbpFileSearchIndex *self,
                                          GFile             *root_directory)
 {
-  g_return_if_fail (GB_IS_FILE_SEARCH_INDEX (self));
+  g_return_if_fail (GBP_IS_FILE_SEARCH_INDEX (self));
   g_return_if_fail (!root_directory || G_IS_FILE (root_directory));
 
   if (g_set_object (&self->root_directory, root_directory))
@@ -61,23 +63,23 @@ gb_file_search_index_set_root_directory (GbFileSearchIndex *self,
 }
 
 static void
-gb_file_search_index_finalize (GObject *object)
+gbp_file_search_index_finalize (GObject *object)
 {
-  GbFileSearchIndex *self = (GbFileSearchIndex *)object;
+  GbpFileSearchIndex *self = (GbpFileSearchIndex *)object;
 
   g_clear_object (&self->root_directory);
   g_clear_pointer (&self->fuzzy, dzl_fuzzy_mutable_index_unref);
 
-  G_OBJECT_CLASS (gb_file_search_index_parent_class)->finalize (object);
+  G_OBJECT_CLASS (gbp_file_search_index_parent_class)->finalize (object);
 }
 
 static void
-gb_file_search_index_get_property (GObject    *object,
+gbp_file_search_index_get_property (GObject    *object,
                                    guint       prop_id,
                                    GValue     *value,
                                    GParamSpec *pspec)
 {
-  GbFileSearchIndex *self = GB_FILE_SEARCH_INDEX (object);
+  GbpFileSearchIndex *self = GBP_FILE_SEARCH_INDEX (object);
 
   switch (prop_id)
     {
@@ -91,17 +93,17 @@ gb_file_search_index_get_property (GObject    *object,
 }
 
 static void
-gb_file_search_index_set_property (GObject      *object,
+gbp_file_search_index_set_property (GObject      *object,
                                    guint         prop_id,
                                    const GValue *value,
                                    GParamSpec   *pspec)
 {
-  GbFileSearchIndex *self = GB_FILE_SEARCH_INDEX (object);
+  GbpFileSearchIndex *self = GBP_FILE_SEARCH_INDEX (object);
 
   switch (prop_id)
     {
     case PROP_ROOT_DIRECTORY:
-      gb_file_search_index_set_root_directory (self, g_value_get_object (value));
+      gbp_file_search_index_set_root_directory (self, g_value_get_object (value));
       break;
 
     default:
@@ -110,13 +112,13 @@ gb_file_search_index_set_property (GObject      *object,
 }
 
 static void
-gb_file_search_index_class_init (GbFileSearchIndexClass *klass)
+gbp_file_search_index_class_init (GbpFileSearchIndexClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-  object_class->finalize = gb_file_search_index_finalize;
-  object_class->get_property = gb_file_search_index_get_property;
-  object_class->set_property = gb_file_search_index_set_property;
+  object_class->finalize = gbp_file_search_index_finalize;
+  object_class->get_property = gbp_file_search_index_get_property;
+  object_class->set_property = gbp_file_search_index_set_property;
 
   properties [PROP_ROOT_DIRECTORY] =
     g_param_spec_object ("root-directory",
@@ -129,7 +131,7 @@ gb_file_search_index_class_init (GbFileSearchIndexClass *klass)
 }
 
 static void
-gb_file_search_index_init (GbFileSearchIndex *self)
+gbp_file_search_index_init (GbpFileSearchIndex *self)
 {
 }
 
@@ -228,26 +230,26 @@ populate_from_dir (DzlFuzzyMutableIndex *fuzzy,
 }
 
 static void
-gb_file_search_index_builder (IdeTask      *task,
+gbp_file_search_index_builder (IdeTask      *task,
                               gpointer      source_object,
                               gpointer      task_data,
                               GCancellable *cancellable)
 {
-  GbFileSearchIndex *self = source_object;
+  GbpFileSearchIndex *self = source_object;
   g_autoptr(GTimer) timer = NULL;
+  g_autoptr(IdeVcs) vcs = NULL;
+  g_autoptr(IdeContext) context = NULL;
   GFile *directory = task_data;
-  IdeContext *context;
-  IdeVcs *vcs;
   DzlFuzzyMutableIndex *fuzzy;
   gdouble elapsed;
 
   g_assert (IDE_IS_TASK (task));
-  g_assert (GB_IS_FILE_SEARCH_INDEX (self));
+  g_assert (GBP_IS_FILE_SEARCH_INDEX (self));
   g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
   g_assert (G_IS_FILE (directory));
 
-  context = ide_object_get_context (IDE_OBJECT (self));
-  vcs = ide_context_get_vcs (context);
+  context = ide_object_ref_context (IDE_OBJECT (self));
+  vcs = ide_vcs_ref_from_context (context);
 
   timer = g_timer_new ();
 
@@ -267,18 +269,18 @@ gb_file_search_index_builder (IdeTask      *task,
 }
 
 void
-gb_file_search_index_build_async (GbFileSearchIndex   *self,
-                                  GCancellable        *cancellable,
-                                  GAsyncReadyCallback  callback,
-                                  gpointer             user_data)
+gbp_file_search_index_build_async (GbpFileSearchIndex  *self,
+                                   GCancellable        *cancellable,
+                                   GAsyncReadyCallback  callback,
+                                   gpointer             user_data)
 {
   g_autoptr(IdeTask) task = NULL;
 
-  g_return_if_fail (GB_IS_FILE_SEARCH_INDEX (self));
+  g_return_if_fail (GBP_IS_FILE_SEARCH_INDEX (self));
   g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
 
   task = ide_task_new (self, cancellable, callback, user_data);
-  ide_task_set_source_tag (task, gb_file_search_index_build_async);
+  ide_task_set_source_tag (task, gbp_file_search_index_build_async);
   ide_task_set_priority (task, G_PRIORITY_LOW);
 
   if (self->root_directory == NULL)
@@ -291,17 +293,17 @@ gb_file_search_index_build_async (GbFileSearchIndex   *self,
     }
 
   ide_task_set_task_data (task, g_object_ref (self->root_directory), g_object_unref);
-  ide_task_run_in_thread (task, gb_file_search_index_builder);
+  ide_task_run_in_thread (task, gbp_file_search_index_builder);
 }
 
 gboolean
-gb_file_search_index_build_finish (GbFileSearchIndex  *self,
+gbp_file_search_index_build_finish (GbpFileSearchIndex  *self,
                                    GAsyncResult       *result,
                                    GError            **error)
 {
   IdeTask *task = (IdeTask *)result;
 
-  g_return_val_if_fail (GB_IS_FILE_SEARCH_INDEX (self), FALSE);
+  g_return_val_if_fail (GBP_IS_FILE_SEARCH_INDEX (self), FALSE);
   g_return_val_if_fail (IDE_IS_TASK (result), FALSE);
   g_return_val_if_fail (IDE_IS_TASK (task), FALSE);
 
@@ -309,7 +311,7 @@ gb_file_search_index_build_finish (GbFileSearchIndex  *self,
 }
 
 GPtrArray *
-gb_file_search_index_populate (GbFileSearchIndex *self,
+gbp_file_search_index_populate (GbpFileSearchIndex *self,
                                const gchar       *query,
                                gsize              max_results)
 {
@@ -320,7 +322,7 @@ gb_file_search_index_populate (GbFileSearchIndex *self,
   IdeContext *context;
   gsize i;
 
-  g_return_val_if_fail (GB_IS_FILE_SEARCH_INDEX (self), NULL);
+  g_return_val_if_fail (GBP_IS_FILE_SEARCH_INDEX (self), NULL);
   g_return_val_if_fail (query != NULL, NULL);
 
   if (self->fuzzy == NULL)
@@ -348,7 +350,7 @@ gb_file_search_index_populate (GbFileSearchIndex *self,
 
       if (ide_search_reducer_accepts (&reducer, match->score))
         {
-          g_autoptr(GbFileSearchResult) result = NULL;
+          g_autoptr(GbpFileSearchResult) result = NULL;
           g_autofree gchar *escaped = NULL;
           g_autofree gchar *markup = NULL;
           g_autofree gchar *free_me = NULL;
@@ -367,7 +369,7 @@ gb_file_search_index_populate (GbFileSearchIndex *self,
           if ((content_type = g_content_type_guess (filename, NULL, 0, NULL)))
             themed_icon = ide_g_content_type_get_symbolic_icon (content_type);
 
-          result = g_object_new (GB_TYPE_FILE_SEARCH_RESULT,
+          result = g_object_new (GBP_TYPE_FILE_SEARCH_RESULT,
                                  "context", context,
                                  "score", match->score,
                                  "title", markup,
@@ -385,10 +387,10 @@ gb_file_search_index_populate (GbFileSearchIndex *self,
 }
 
 gboolean
-gb_file_search_index_contains (GbFileSearchIndex *self,
+gbp_file_search_index_contains (GbpFileSearchIndex *self,
                                const gchar       *relative_path)
 {
-  g_return_val_if_fail (GB_IS_FILE_SEARCH_INDEX (self), FALSE);
+  g_return_val_if_fail (GBP_IS_FILE_SEARCH_INDEX (self), FALSE);
   g_return_val_if_fail (relative_path != NULL, FALSE);
   g_return_val_if_fail (self->fuzzy != NULL, FALSE);
 
@@ -396,10 +398,10 @@ gb_file_search_index_contains (GbFileSearchIndex *self,
 }
 
 void
-gb_file_search_index_insert (GbFileSearchIndex *self,
+gbp_file_search_index_insert (GbpFileSearchIndex *self,
                              const gchar       *relative_path)
 {
-  g_return_if_fail (GB_IS_FILE_SEARCH_INDEX (self));
+  g_return_if_fail (GBP_IS_FILE_SEARCH_INDEX (self));
   g_return_if_fail (relative_path != NULL);
   g_return_if_fail (self->fuzzy != NULL);
 
@@ -407,10 +409,10 @@ gb_file_search_index_insert (GbFileSearchIndex *self,
 }
 
 void
-gb_file_search_index_remove (GbFileSearchIndex *self,
+gbp_file_search_index_remove (GbpFileSearchIndex *self,
                              const gchar       *relative_path)
 {
-  g_return_if_fail (GB_IS_FILE_SEARCH_INDEX (self));
+  g_return_if_fail (GBP_IS_FILE_SEARCH_INDEX (self));
   g_return_if_fail (relative_path != NULL);
   g_return_if_fail (self->fuzzy != NULL);
 
diff --git a/src/plugins/file-search/gb-file-search-index.h b/src/plugins/file-search/gbp-file-search-index.h
similarity index 70%
rename from src/plugins/file-search/gb-file-search-index.h
rename to src/plugins/file-search/gbp-file-search-index.h
index 66dae8a21..feb45ca58 100644
--- a/src/plugins/file-search/gb-file-search-index.h
+++ b/src/plugins/file-search/gbp-file-search-index.h
@@ -1,4 +1,4 @@
-/* gb-file-search-index.h
+/* gbp-file-search-index.h
  *
  * Copyright 2015-2019 Christian Hergert <christian hergert me>
  *
@@ -20,29 +20,29 @@
 
 #pragma once
 
-#include <ide.h>
+#include <libide-search.h>
 
 G_BEGIN_DECLS
 
-#define GB_TYPE_FILE_SEARCH_INDEX (gb_file_search_index_get_type())
+#define GBP_TYPE_FILE_SEARCH_INDEX (gbp_file_search_index_get_type())
 
-G_DECLARE_FINAL_TYPE (GbFileSearchIndex, gb_file_search_index, GB, FILE_SEARCH_INDEX, IdeObject)
+G_DECLARE_FINAL_TYPE (GbpFileSearchIndex, gbp_file_search_index, GBP, FILE_SEARCH_INDEX, IdeObject)
 
-GPtrArray *gb_file_search_index_populate     (GbFileSearchIndex    *self,
+GPtrArray *gbp_file_search_index_populate     (GbpFileSearchIndex    *self,
                                               const gchar          *query,
                                               gsize                 max_results);
-void       gb_file_search_index_build_async  (GbFileSearchIndex    *self,
+void       gbp_file_search_index_build_async  (GbpFileSearchIndex    *self,
                                               GCancellable         *cancellable,
                                               GAsyncReadyCallback   callback,
                                               gpointer              user_data);
-gboolean   gb_file_search_index_build_finish (GbFileSearchIndex    *self,
+gboolean   gbp_file_search_index_build_finish (GbpFileSearchIndex    *self,
                                               GAsyncResult         *result,
                                               GError              **error);
-gboolean   gb_file_search_index_contains     (GbFileSearchIndex    *self,
+gboolean   gbp_file_search_index_contains     (GbpFileSearchIndex    *self,
                                               const gchar          *relative_path);
-void       gb_file_search_index_insert       (GbFileSearchIndex    *self,
+void       gbp_file_search_index_insert       (GbpFileSearchIndex    *self,
                                               const gchar          *relative_path);
-void       gb_file_search_index_remove       (GbFileSearchIndex    *self,
+void       gbp_file_search_index_remove       (GbpFileSearchIndex    *self,
                                               const gchar          *relative_path);
 
 G_END_DECLS
diff --git a/src/plugins/file-search/gb-file-search-provider.c 
b/src/plugins/file-search/gbp-file-search-provider.c
similarity index 57%
rename from src/plugins/file-search/gb-file-search-provider.c
rename to src/plugins/file-search/gbp-file-search-provider.c
index 76a2c0ac8..ad9b3b13a 100644
--- a/src/plugins/file-search/gb-file-search-provider.c
+++ b/src/plugins/file-search/gbp-file-search-provider.c
@@ -1,4 +1,4 @@
-/* gb-file-search-provider.c
+/* gbp-file-search-provider.c
  *
  * Copyright 2015-2019 Christian Hergert <christian hergert me>
  *
@@ -18,52 +18,55 @@
  * SPDX-License-Identifier: GPL-3.0-or-later
  */
 
-#define G_LOG_DOMAIN "gb-file-search-provider"
+#define G_LOG_DOMAIN "gbp-file-search-provider"
 
 #include "config.h"
 
 #include <glib/gi18n.h>
-#include <ide.h>
+#include <libide-code.h>
+#include <libide-projects.h>
+#include <libide-search.h>
+#include <libide-vcs.h>
 #include <libpeas/peas.h>
 
-#include "gb-file-search-provider.h"
-#include "gb-file-search-index.h"
+#include "gbp-file-search-provider.h"
+#include "gbp-file-search-index.h"
 
-struct _GbFileSearchProvider
+struct _GbpFileSearchProvider
 {
-  IdeObject          parent_instance;
-  GbFileSearchIndex *index;
+  IdeObject           parent_instance;
+  GbpFileSearchIndex *index;
 };
 
 static void search_provider_iface_init (IdeSearchProviderInterface *iface);
 
-G_DEFINE_TYPE_WITH_CODE (GbFileSearchProvider,
-                         gb_file_search_provider,
+G_DEFINE_TYPE_WITH_CODE (GbpFileSearchProvider,
+                         gbp_file_search_provider,
                          IDE_TYPE_OBJECT,
                          G_IMPLEMENT_INTERFACE (IDE_TYPE_SEARCH_PROVIDER, search_provider_iface_init))
 
 static void
-gb_file_search_provider_search_async (IdeSearchProvider   *provider,
+gbp_file_search_provider_search_async (IdeSearchProvider   *provider,
                                       const gchar         *search_terms,
                                       guint                max_results,
                                       GCancellable        *cancellable,
                                       GAsyncReadyCallback  callback,
                                       gpointer             user_data)
 {
-  GbFileSearchProvider *self = (GbFileSearchProvider *)provider;
+  GbpFileSearchProvider *self = (GbpFileSearchProvider *)provider;
   g_autoptr(IdeTask) task = NULL;
   g_autoptr(GPtrArray) results = NULL;
 
-  g_assert (GB_IS_FILE_SEARCH_PROVIDER (self));
+  g_assert (GBP_IS_FILE_SEARCH_PROVIDER (self));
   g_assert (search_terms != NULL);
   g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
 
   task = ide_task_new (self, cancellable, callback, user_data);
-  ide_task_set_source_tag (task, gb_file_search_provider_search_async);
+  ide_task_set_source_tag (task, gbp_file_search_provider_search_async);
   ide_task_set_priority (task, G_PRIORITY_LOW);
 
   if (self->index != NULL)
-    results = gb_file_search_index_populate (self->index, search_terms, max_results);
+    results = gbp_file_search_index_populate (self->index, search_terms, max_results);
   else
     results = g_ptr_array_new_with_free_func (g_object_unref);
 
@@ -71,13 +74,13 @@ gb_file_search_provider_search_async (IdeSearchProvider   *provider,
 }
 
 static GPtrArray *
-gb_file_search_provider_search_finish (IdeSearchProvider  *provider,
+gbp_file_search_provider_search_finish (IdeSearchProvider  *provider,
                                        GAsyncResult       *result,
                                        GError            **error)
 {
   GPtrArray *ret;
 
-  g_assert (GB_IS_FILE_SEARCH_PROVIDER (provider));
+  g_assert (GBP_IS_FILE_SEARCH_PROVIDER (provider));
   g_assert (IDE_IS_TASK (result));
 
   ret = ide_task_propagate_pointer (IDE_TASK (result), error);
@@ -86,100 +89,96 @@ gb_file_search_provider_search_finish (IdeSearchProvider  *provider,
 }
 
 static void
-on_buffer_loaded (GbFileSearchProvider *self,
+on_buffer_loaded (GbpFileSearchProvider *self,
                   IdeBuffer            *buffer,
                   IdeBufferManager     *bufmgr)
 {
   g_autofree gchar *relative_path = NULL;
-  IdeContext *context;
+  g_autoptr(IdeContext) context = NULL;
+  g_autoptr(GFile) workdir = NULL;
   IdeVcs *vcs;
   GFile *file;
-  GFile *workdir;
 
-  g_assert (GB_IS_FILE_SEARCH_PROVIDER (self));
+  g_assert (GBP_IS_FILE_SEARCH_PROVIDER (self));
   g_assert (IDE_IS_BUFFER (buffer));
   g_assert (IDE_IS_BUFFER_MANAGER (bufmgr));
 
   if (self->index == NULL)
     return;
 
-  file = ide_file_get_file (ide_buffer_get_file (buffer));
-  context = ide_buffer_get_context (buffer);
-  vcs = ide_context_get_vcs (context);
-  workdir = ide_vcs_get_working_directory (vcs);
+  file = ide_buffer_get_file (buffer);
+  context = ide_buffer_ref_context (buffer);
+  vcs = ide_vcs_from_context (context);
+  workdir = ide_context_ref_workdir (context);
   relative_path = g_file_get_relative_path (workdir, file);
 
   if ((relative_path != NULL) &&
       !ide_vcs_is_ignored (vcs, file, NULL) &&
-      !gb_file_search_index_contains (self->index, relative_path))
-    gb_file_search_index_insert (self->index, relative_path);
+      !gbp_file_search_index_contains (self->index, relative_path))
+    gbp_file_search_index_insert (self->index, relative_path);
 }
 
 static void
-on_file_renamed (GbFileSearchProvider *self,
+on_file_renamed (GbpFileSearchProvider *self,
                  GFile                *src_file,
                  GFile                *dst_file,
                  IdeProject           *project)
 {
   g_autofree gchar *old_path = NULL;
   g_autofree gchar *new_path = NULL;
+  g_autoptr(GFile) workdir = NULL;
   IdeContext *context;
-  IdeVcs *vcs;
-  GFile *workdir;
 
-  g_assert (GB_IS_FILE_SEARCH_PROVIDER (self));
+  g_assert (GBP_IS_FILE_SEARCH_PROVIDER (self));
   g_assert (G_IS_FILE (src_file));
   g_assert (G_IS_FILE (dst_file));
   g_assert (IDE_IS_PROJECT (project));
-  g_assert (GB_IS_FILE_SEARCH_INDEX (self->index));
+  g_assert (GBP_IS_FILE_SEARCH_INDEX (self->index));
 
   context = ide_object_get_context (IDE_OBJECT (project));
-  vcs = ide_context_get_vcs (context);
-  workdir = ide_vcs_get_working_directory (vcs);
+  workdir = ide_context_ref_workdir (context);
 
   if (NULL != (old_path = g_file_get_relative_path (workdir, src_file)))
-    gb_file_search_index_remove (self->index, old_path);
+    gbp_file_search_index_remove (self->index, old_path);
 
   if (NULL != (new_path = g_file_get_relative_path (workdir, dst_file)))
-    gb_file_search_index_insert (self->index, new_path);
+    gbp_file_search_index_insert (self->index, new_path);
 }
 
 static void
-on_file_trashed (GbFileSearchProvider *self,
+on_file_trashed (GbpFileSearchProvider *self,
                  GFile                *file,
                  IdeProject           *project)
 {
   g_autofree gchar *path = NULL;
+  g_autoptr(GFile) workdir = NULL;
   IdeContext *context;
-  IdeVcs *vcs;
-  GFile *workdir;
 
-  g_assert (GB_IS_FILE_SEARCH_PROVIDER (self));
+  g_assert (GBP_IS_FILE_SEARCH_PROVIDER (self));
   g_assert (G_IS_FILE (file));
   g_assert (IDE_IS_PROJECT (project));
-  g_assert (GB_IS_FILE_SEARCH_INDEX (self->index));
+  g_assert (GBP_IS_FILE_SEARCH_INDEX (self->index));
 
   context = ide_object_get_context (IDE_OBJECT (project));
-  vcs = ide_context_get_vcs (context);
-  workdir = ide_vcs_get_working_directory (vcs);
+  workdir = ide_context_ref_workdir (context);
 
   if (NULL != (path = g_file_get_relative_path (workdir, file)))
-    gb_file_search_index_remove (self->index, path);
+    gbp_file_search_index_remove (self->index, path);
 }
 
 static void
-gb_file_search_provider_build_cb (GObject      *object,
+gbp_file_search_provider_build_cb (GObject      *object,
                                   GAsyncResult *result,
                                   gpointer      user_data)
 {
-  GbFileSearchIndex *index = (GbFileSearchIndex *)object;
-  g_autoptr(GbFileSearchProvider) self = user_data;
+  GbpFileSearchIndex *index = (GbpFileSearchIndex *)object;
+  g_autoptr(GbpFileSearchProvider) self = user_data;
   g_autoptr(GError) error = NULL;
 
-  g_assert (GB_IS_FILE_SEARCH_INDEX (index));
-  g_assert (GB_IS_FILE_SEARCH_PROVIDER (self));
+  g_assert (GBP_IS_FILE_SEARCH_INDEX (index));
+  g_assert (GBP_IS_FILE_SEARCH_PROVIDER (self));
 
-  if (!gb_file_search_index_build_finish (index, result, &error))
+  if (!gbp_file_search_index_build_finish (index, result, &error))
     {
       g_warning ("%s", error->message);
       return;
@@ -190,7 +189,7 @@ gb_file_search_provider_build_cb (GObject      *object,
 
 #if 0
 static void
-gb_file_search_provider_activate (IdeSearchProvider *provider,
+gbp_file_search_provider_activate (IdeSearchProvider *provider,
                                   GtkWidget         *row,
                                   IdeSearchResult   *result)
 {
@@ -206,13 +205,13 @@ gb_file_search_provider_activate (IdeSearchProvider *provider,
     {
       g_autofree gchar *path = NULL;
       g_autoptr(GFile) file = NULL;
+      g_autoptr(GFile) workdir = NULL;
       IdeContext *context;
       IdeVcs *vcs;
-      GFile *workdir;
 
       context = ide_workbench_get_context (IDE_WORKBENCH (toplevel));
-      vcs = ide_context_get_vcs (context);
-      workdir = ide_vcs_get_working_directory (vcs);
+      vcs = ide_vcs_from_context (context);
+      workdir = ide_context_ref_workdir (context);
       g_object_get (result, "path", &path, NULL);
       file = g_file_get_child (workdir, path);
 
@@ -229,56 +228,64 @@ gb_file_search_provider_activate (IdeSearchProvider *provider,
 #endif
 
 static void
-gb_file_search_provider_vcs_changed_cb (GbFileSearchProvider *self,
-                                        IdeVcs               *vcs)
+gbp_file_search_provider_vcs_changed_cb (GbpFileSearchProvider *self,
+                                         IdeVcs                *vcs)
 {
-  g_autoptr(GbFileSearchIndex) index = NULL;
+  g_autoptr(GbpFileSearchIndex) index = NULL;
+  g_autoptr(GFile) workdir = NULL;
   IdeContext *context;
-  GFile *workdir;
 
   IDE_ENTRY;
 
-  g_return_if_fail (GB_IS_FILE_SEARCH_PROVIDER (self));
+  g_return_if_fail (GBP_IS_FILE_SEARCH_PROVIDER (self));
   g_return_if_fail (IDE_IS_VCS (vcs));
 
   context = ide_object_get_context (IDE_OBJECT (self));
-  workdir = ide_vcs_get_working_directory (vcs);
+  workdir = ide_context_ref_workdir (context);
 
-  index = g_object_new (GB_TYPE_FILE_SEARCH_INDEX,
-                        "context", context,
+  index = g_object_new (GBP_TYPE_FILE_SEARCH_INDEX,
                         "root-directory", workdir,
                         NULL);
 
-  gb_file_search_index_build_async (index,
-                                    NULL,
-                                    gb_file_search_provider_build_cb,
-                                    g_object_ref (self));
+  ide_object_append (IDE_OBJECT (self), IDE_OBJECT (index));
+
+  gbp_file_search_index_build_async (index,
+                                     NULL,
+                                     gbp_file_search_provider_build_cb,
+                                     g_object_ref (self));
 
   IDE_EXIT;
 }
 
 static void
-gb_file_search_provider_constructed (GObject *object)
+gbp_file_search_provider_parent_set (IdeObject *object,
+                                     IdeObject *parent)
 {
-  GbFileSearchProvider *self = (GbFileSearchProvider *)object;
-  g_autoptr(GbFileSearchIndex) index = NULL;
+  GbpFileSearchProvider *self = (GbpFileSearchProvider *)object;
+  g_autoptr(GbpFileSearchIndex) index = NULL;
+  g_autoptr(GFile) workdir = NULL;
   IdeBufferManager *bufmgr;
   IdeContext *context;
   IdeProject *project;
   IdeVcs *vcs;
-  GFile *workdir;
+
+  g_assert (GBP_IS_FILE_SEARCH_PROVIDER (self));
+  g_assert (!parent || IDE_IS_OBJECT (parent));
+
+  if (parent == NULL)
+    return;
 
   context = ide_object_get_context (IDE_OBJECT (self));
 
-  bufmgr = ide_context_get_buffer_manager (context);
-  project = ide_context_get_project (context);
-  vcs = ide_context_get_vcs (context);
+  bufmgr = ide_buffer_manager_from_context (context);
+  project = ide_project_from_context (context);
+  vcs = ide_vcs_from_context (context);
 
-  workdir = ide_vcs_get_working_directory (vcs);
+  workdir = ide_context_ref_workdir (context);
 
   g_signal_connect_object (vcs,
                            "changed",
-                           G_CALLBACK (gb_file_search_provider_vcs_changed_cb),
+                           G_CALLBACK (gbp_file_search_provider_vcs_changed_cb),
                            self,
                            G_CONNECT_SWAPPED);
 
@@ -300,54 +307,55 @@ gb_file_search_provider_constructed (GObject *object)
                            self,
                            G_CONNECT_SWAPPED);
 
-  index = g_object_new (GB_TYPE_FILE_SEARCH_INDEX,
-                        "context", context,
+  index = g_object_new (GBP_TYPE_FILE_SEARCH_INDEX,
                         "root-directory", workdir,
                         NULL);
 
-  gb_file_search_index_build_async (index,
-                                    NULL,
-                                    gb_file_search_provider_build_cb,
-                                    g_object_ref (self));
+  ide_object_append (IDE_OBJECT (self), IDE_OBJECT (index));
 
-  G_OBJECT_CLASS (gb_file_search_provider_parent_class)->constructed (object);
+  gbp_file_search_index_build_async (index,
+                                     NULL,
+                                     gbp_file_search_provider_build_cb,
+                                     g_object_ref (self));
 }
 
 static void
-gb_file_search_provider_finalize (GObject *object)
+gbp_file_search_provider_finalize (GObject *object)
 {
-  GbFileSearchProvider *self = (GbFileSearchProvider *)object;
+  GbpFileSearchProvider *self = (GbpFileSearchProvider *)object;
 
   g_clear_object (&self->index);
 
-  G_OBJECT_CLASS (gb_file_search_provider_parent_class)->finalize (object);
+  G_OBJECT_CLASS (gbp_file_search_provider_parent_class)->finalize (object);
 }
 
 static void
-gb_file_search_provider_class_init (GbFileSearchProviderClass *klass)
+gbp_file_search_provider_class_init (GbpFileSearchProviderClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  IdeObjectClass *i_object_class = IDE_OBJECT_CLASS (klass);
+
+  object_class->finalize = gbp_file_search_provider_finalize;
 
-  object_class->constructed = gb_file_search_provider_constructed;
-  object_class->finalize = gb_file_search_provider_finalize;
+  i_object_class->parent_set = gbp_file_search_provider_parent_set;
 }
 
 static void
-gb_file_search_provider_init (GbFileSearchProvider *self)
+gbp_file_search_provider_init (GbpFileSearchProvider *self)
 {
 }
 
 static void
 search_provider_iface_init (IdeSearchProviderInterface *iface)
 {
-  iface->search_async = gb_file_search_provider_search_async;
-  iface->search_finish = gb_file_search_provider_search_finish;
+  iface->search_async = gbp_file_search_provider_search_async;
+  iface->search_finish = gbp_file_search_provider_search_finish;
 }
 
 void
-gb_file_search_register_types (PeasObjectModule *module)
+gbp_file_search_register_types (PeasObjectModule *module)
 {
   peas_object_module_register_extension_type (module,
                                               IDE_TYPE_SEARCH_PROVIDER,
-                                              GB_TYPE_FILE_SEARCH_PROVIDER);
+                                              GBP_TYPE_FILE_SEARCH_PROVIDER);
 }
diff --git a/src/plugins/file-search/gb-file-search-provider.h 
b/src/plugins/file-search/gbp-file-search-provider.h
similarity index 76%
rename from src/plugins/file-search/gb-file-search-provider.h
rename to src/plugins/file-search/gbp-file-search-provider.h
index 16fb0fdaa..95844c3d3 100644
--- a/src/plugins/file-search/gb-file-search-provider.h
+++ b/src/plugins/file-search/gbp-file-search-provider.h
@@ -1,4 +1,4 @@
-/* gb-file-search-provider.h
+/* gbp-file-search-provider.h
  *
  * Copyright 2015-2019 Christian Hergert <christian hergert me>
  *
@@ -20,13 +20,12 @@
 
 #pragma once
 
-#include <ide.h>
+#include <libide-search.h>
 
 G_BEGIN_DECLS
 
-#define GB_TYPE_FILE_SEARCH_PROVIDER (gb_file_search_provider_get_type())
+#define GBP_TYPE_FILE_SEARCH_PROVIDER (gbp_file_search_provider_get_type())
 
-G_DECLARE_FINAL_TYPE (GbFileSearchProvider, gb_file_search_provider,
-                      GB, FILE_SEARCH_PROVIDER, IdeObject)
+G_DECLARE_FINAL_TYPE (GbpFileSearchProvider, gbp_file_search_provider, GBP, FILE_SEARCH_PROVIDER, IdeObject)
 
 G_END_DECLS
diff --git a/src/plugins/file-search/gb-file-search-result.c 
b/src/plugins/file-search/gbp-file-search-result.c
similarity index 61%
rename from src/plugins/file-search/gb-file-search-result.c
rename to src/plugins/file-search/gbp-file-search-result.c
index 6e617621b..e57eba9f7 100644
--- a/src/plugins/file-search/gb-file-search-result.c
+++ b/src/plugins/file-search/gbp-file-search-result.c
@@ -1,4 +1,4 @@
-/* gb-file-search-result.c
+/* gbp-file-search-result.c
  *
  * Copyright 2015-2019 Christian Hergert <christian hergert me>
  *
@@ -18,11 +18,13 @@
  * SPDX-License-Identifier: GPL-3.0-or-later
  */
 
-#define G_LOG_DOMAIN "gb-file-search-result"
+#define G_LOG_DOMAIN "gbp-file-search-result"
 
-#include "gb-file-search-result.h"
+#include <libide-gui.h>
 
-struct _GbFileSearchResult
+#include "gbp-file-search-result.h"
+
+struct _GbpFileSearchResult
 {
   IdeSearchResult  parent_instance;
 
@@ -30,7 +32,7 @@ struct _GbFileSearchResult
   gchar           *path;
 };
 
-G_DEFINE_TYPE (GbFileSearchResult, gb_file_search_result, IDE_TYPE_SEARCH_RESULT)
+G_DEFINE_TYPE (GbpFileSearchResult, gbp_file_search_result, IDE_TYPE_SEARCH_RESULT)
 
 enum {
   PROP_0,
@@ -41,43 +43,49 @@ enum {
 
 static GParamSpec *properties [LAST_PROP];
 
-static IdeSourceLocation *
-gb_file_search_result_get_source_location (IdeSearchResult *result)
+static void
+gbp_file_search_result_activate (IdeSearchResult *result,
+                                 GtkWidget       *last_focus)
 {
-  GbFileSearchResult *self = (GbFileSearchResult *)result;
-  g_autoptr(GFile) file = NULL;
-  g_autoptr(IdeFile) ifile = NULL;
-  IdeVcs *vcs;
-  GFile *workdir;
+  g_autoptr(GFile) workdir = NULL;
+  IdeWorkbench *workbench;
+  IdeContext *context;
+  GFile *file;
+
+  g_assert (GBP_IS_FILE_SEARCH_RESULT (result));
+  g_assert (!last_focus || GTK_IS_WIDGET (last_focus));
+
+  if (!last_focus)
+    return;
 
-  g_return_val_if_fail (GB_IS_FILE_SEARCH_RESULT (self), NULL);
+  if (!(workbench = ide_widget_get_workbench (last_focus)) ||
+      !(context = ide_workbench_get_context (workbench)) ||
+      !(workdir = ide_context_ref_workdir (context)))
+    return;
 
-  vcs = ide_context_get_vcs (self->context);
-  workdir = ide_vcs_get_working_directory (vcs);
-  file = g_file_get_child (workdir, self->path);
-  ifile = ide_file_new (self->context, file);
+  file = g_file_get_child (workdir, GBP_FILE_SEARCH_RESULT (result)->path);
 
-  return ide_source_location_new (ifile, 0, 0, 0);
+  ide_workbench_open_async (workbench, file, NULL, 0,NULL, NULL, NULL);
 }
 
 static void
-gb_file_search_result_finalize (GObject *object)
+gbp_file_search_result_finalize (GObject *object)
 {
-  GbFileSearchResult *self = (GbFileSearchResult *)object;
+  GbpFileSearchResult *self = (GbpFileSearchResult *)object;
 
   g_clear_weak_pointer (&self->context);
   g_clear_pointer (&self->path, g_free);
 
-  G_OBJECT_CLASS (gb_file_search_result_parent_class)->finalize (object);
+  G_OBJECT_CLASS (gbp_file_search_result_parent_class)->finalize (object);
 }
 
 static void
-gb_file_search_result_get_property (GObject    *object,
+gbp_file_search_result_get_property (GObject    *object,
                                     guint       prop_id,
                                     GValue     *value,
                                     GParamSpec *pspec)
 {
-  GbFileSearchResult *self = (GbFileSearchResult *)object;
+  GbpFileSearchResult *self = (GbpFileSearchResult *)object;
 
   switch (prop_id)
     {
@@ -91,12 +99,12 @@ gb_file_search_result_get_property (GObject    *object,
 }
 
 static void
-gb_file_search_result_set_property (GObject      *object,
+gbp_file_search_result_set_property (GObject      *object,
                                     guint         prop_id,
                                     const GValue *value,
                                     GParamSpec   *pspec)
 {
-  GbFileSearchResult *self = (GbFileSearchResult *)object;
+  GbpFileSearchResult *self = (GbpFileSearchResult *)object;
 
   switch (prop_id)
     {
@@ -114,16 +122,16 @@ gb_file_search_result_set_property (GObject      *object,
 }
 
 static void
-gb_file_search_result_class_init (GbFileSearchResultClass *klass)
+gbp_file_search_result_class_init (GbpFileSearchResultClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   IdeSearchResultClass *result_class = IDE_SEARCH_RESULT_CLASS (klass);
 
-  object_class->finalize = gb_file_search_result_finalize;
-  object_class->get_property = gb_file_search_result_get_property;
-  object_class->set_property = gb_file_search_result_set_property;
+  object_class->finalize = gbp_file_search_result_finalize;
+  object_class->get_property = gbp_file_search_result_get_property;
+  object_class->set_property = gbp_file_search_result_set_property;
 
-  result_class->get_source_location = gb_file_search_result_get_source_location;
+  result_class->activate = gbp_file_search_result_activate;
 
   properties [PROP_CONTEXT] =
     g_param_spec_object ("context",
@@ -143,6 +151,6 @@ gb_file_search_result_class_init (GbFileSearchResultClass *klass)
 }
 
 static void
-gb_file_search_result_init (GbFileSearchResult *self)
+gbp_file_search_result_init (GbpFileSearchResult *self)
 {
 }
diff --git a/src/plugins/file-search/gb-file-search-result.h 
b/src/plugins/file-search/gbp-file-search-result.h
similarity index 77%
rename from src/plugins/file-search/gb-file-search-result.h
rename to src/plugins/file-search/gbp-file-search-result.h
index 47ebf8d00..b1ed2152a 100644
--- a/src/plugins/file-search/gb-file-search-result.h
+++ b/src/plugins/file-search/gbp-file-search-result.h
@@ -1,4 +1,4 @@
-/* gb-file-search-result.h
+/* gbp-file-search-result.h
  *
  * Copyright 2015-2019 Christian Hergert <christian hergert me>
  *
@@ -20,12 +20,12 @@
 
 #pragma once
 
-#include <ide.h>
+#include <libide-search.h>
 
 G_BEGIN_DECLS
 
-#define GB_TYPE_FILE_SEARCH_RESULT (gb_file_search_result_get_type())
+#define GBP_TYPE_FILE_SEARCH_RESULT (gbp_file_search_result_get_type())
 
-G_DECLARE_FINAL_TYPE (GbFileSearchResult, gb_file_search_result, GB, FILE_SEARCH_RESULT, IdeSearchResult)
+G_DECLARE_FINAL_TYPE (GbpFileSearchResult, gbp_file_search_result, GBP, FILE_SEARCH_RESULT, IdeSearchResult)
 
 G_END_DECLS
diff --git a/src/plugins/file-search/meson.build b/src/plugins/file-search/meson.build
index aa3260400..8ae908f90 100644
--- a/src/plugins/file-search/meson.build
+++ b/src/plugins/file-search/meson.build
@@ -1,21 +1,18 @@
-if get_option('with_file_search')
+if get_option('plugin_file_search')
 
-file_search_resources = gnome.compile_resources(
+plugins_sources += files([
+  'gbp-file-search-provider.c',
+  'gbp-file-search-result.c',
+  'gbp-file-search-index.c',
+  'file-search-plugin.c',
+])
+
+plugin_file_search_resources = gnome.compile_resources(
   'file-search-resources',
   'file-search.gresource.xml',
-  c_name: 'gb_file_search',
+  c_name: 'gbp_file_search',
 )
 
-file_search_sources = [
-  'gb-file-search-provider.c',
-  'gb-file-search-provider.h',
-  'gb-file-search-result.c',
-  'gb-file-search-result.h',
-  'gb-file-search-index.c',
-  'gb-file-search-index.h',
-]
-
-gnome_builder_plugins_sources += files(file_search_sources)
-gnome_builder_plugins_sources += file_search_resources[0]
+plugins_sources += plugin_file_search_resources[0]
 
 endif



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