[gnome-builder] file-search: update index when new file is created by buffer-manager
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] file-search: update index when new file is created by buffer-manager
- Date: Sat, 12 Mar 2016 23:10:36 +0000 (UTC)
commit 1a3795bd92a6fd4d927ef53104d476b0fb0e5f6a
Author: Christian Hergert <christian hergert me>
Date: Sat Mar 12 15:09:05 2016 -0800
file-search: update index when new file is created by buffer-manager
Long term, I think we want a better way to update the index when a file
is added to the project. But to do that, we need to introduce some signals
to IdeProject or similar structure (perhaps IdeContext).
The easiest way to fix this bug for 3.20 is to watch for the new file
being created by the buffer manager, since new files in the project tree
get immediately opened.
https://bugzilla.gnome.org/show_bug.cgi?id=760586
plugins/file-search/gb-file-search-index.c | 22 +++++++++++++
plugins/file-search/gb-file-search-index.h | 4 ++
plugins/file-search/gb-file-search-provider.c | 42 +++++++++++++++++++++++++
3 files changed, 68 insertions(+), 0 deletions(-)
---
diff --git a/plugins/file-search/gb-file-search-index.c b/plugins/file-search/gb-file-search-index.c
index 9748b35..a835d08 100644
--- a/plugins/file-search/gb-file-search-index.c
+++ b/plugins/file-search/gb-file-search-index.c
@@ -339,3 +339,25 @@ gb_file_search_index_populate (GbFileSearchIndex *self,
}
}
}
+
+gboolean
+gb_file_search_index_contains (GbFileSearchIndex *self,
+ const gchar *relative_path)
+{
+ g_return_val_if_fail (GB_IS_FILE_SEARCH_INDEX (self), FALSE);
+ g_return_val_if_fail (relative_path != NULL, FALSE);
+ g_return_val_if_fail (self->fuzzy != NULL, FALSE);
+
+ return fuzzy_contains (self->fuzzy, relative_path);
+}
+
+void
+gb_file_search_index_insert (GbFileSearchIndex *self,
+ const gchar *relative_path)
+{
+ g_return_if_fail (GB_IS_FILE_SEARCH_INDEX (self));
+ g_return_if_fail (relative_path != NULL);
+ g_return_if_fail (self->fuzzy != NULL);
+
+ fuzzy_insert (self->fuzzy, g_strdup (relative_path), NULL);
+}
diff --git a/plugins/file-search/gb-file-search-index.h b/plugins/file-search/gb-file-search-index.h
index 51339de..fee9240 100644
--- a/plugins/file-search/gb-file-search-index.h
+++ b/plugins/file-search/gb-file-search-index.h
@@ -38,6 +38,10 @@ void gb_file_search_index_build_async (GbFileSearchIndex *self,
gboolean gb_file_search_index_build_finish (GbFileSearchIndex *self,
GAsyncResult *result,
GError **error);
+gboolean gb_file_search_index_contains (GbFileSearchIndex *self,
+ const gchar *relative_path);
+void gb_file_search_index_insert (GbFileSearchIndex *self,
+ const gchar *relative_path);
G_END_DECLS
diff --git a/plugins/file-search/gb-file-search-provider.c b/plugins/file-search/gb-file-search-provider.c
index e25280e..a61ec64 100644
--- a/plugins/file-search/gb-file-search-provider.c
+++ b/plugins/file-search/gb-file-search-provider.c
@@ -65,12 +65,44 @@ gb_file_search_provider_populate (IdeSearchProvider *provider,
}
static void
+on_buffer_loaded (GbFileSearchProvider *self,
+ IdeBuffer *buffer,
+ IdeBufferManager *bufmgr)
+{
+ g_autofree gchar *relative_path = NULL;
+ IdeContext *context;
+ IdeVcs *vcs;
+ GFile *file;
+ GFile *workdir;
+
+ g_assert (GB_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);
+ 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);
+}
+
+static void
gb_file_search_provider_build_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
GbFileSearchIndex *index = (GbFileSearchIndex *)object;
g_autoptr(GbFileSearchProvider) self = user_data;
+ IdeContext *context;
+ IdeBufferManager *bufmgr;
GError *error = NULL;
g_assert (GB_IS_FILE_SEARCH_INDEX (index));
@@ -80,7 +112,17 @@ gb_file_search_provider_build_cb (GObject *object,
{
g_warning ("%s", error->message);
g_clear_error (&error);
+ return;
}
+
+ context = ide_object_get_context (IDE_OBJECT (self));
+ bufmgr = ide_context_get_buffer_manager (context);
+
+ g_signal_connect_object (bufmgr,
+ "buffer-loaded",
+ G_CALLBACK (on_buffer_loaded),
+ self,
+ G_CONNECT_SWAPPED);
}
static GtkWidget *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]