[gnome-builder] bring back opening files from git index



commit a1272170879bb3c0b3b66eac897d19b4a5fb312b
Author: Christian Hergert <christian hergert me>
Date:   Sat Mar 21 18:23:57 2015 -0700

    bring back opening files from git index

 libide/Makefile.am                 |    2 +
 libide/git/ide-git-search-index.c  |   23 +++++---
 libide/git/ide-git-search-result.c |  110 ++++++++++++++++++++++++++++++++++++
 libide/git/ide-git-search-result.h |   32 ++++++++++
 libide/ide.h                       |    1 +
 src/search/gb-search-box.c         |   28 +++++++++
 6 files changed, 187 insertions(+), 9 deletions(-)
---
diff --git a/libide/Makefile.am b/libide/Makefile.am
index 52f0191..772e139 100644
--- a/libide/Makefile.am
+++ b/libide/Makefile.am
@@ -34,6 +34,8 @@ libide_1_0_la_public_sources = \
        libide/editorconfig/ide-editorconfig-file-settings.h \
        libide/git/ide-git-search-provider.c \
        libide/git/ide-git-search-provider.h \
+       libide/git/ide-git-search-result.c \
+       libide/git/ide-git-search-result.h \
        libide/git/ide-git-vcs.c \
        libide/git/ide-git-vcs.h \
        libide/gjs/ide-gjs-script.cpp \
diff --git a/libide/git/ide-git-search-index.c b/libide/git/ide-git-search-index.c
index 76a50c5..7f3b9e2 100644
--- a/libide/git/ide-git-search-index.c
+++ b/libide/git/ide-git-search-index.c
@@ -23,6 +23,7 @@
 
 #include "ide-context.h"
 #include "ide-git-search-index.h"
+#include "ide-git-search-result.h"
 #include "ide-project.h"
 #include "ide-search-context.h"
 #include "ide-search-provider.h"
@@ -34,6 +35,7 @@ struct _IdeGitSearchIndex
   IdeObject parent_instance;
 
   GFile *location;
+  GFile *workdir;
   gchar *shorthand;
   Fuzzy *fuzzy;
 };
@@ -211,6 +213,7 @@ ide_git_search_index_populate (IdeGitSearchIndex *self,
           g_autofree gchar *shortname = NULL;
           g_autofree gchar *markup = NULL;
           g_autoptr(IdeSearchResult) result = NULL;
+          GFile *file;
           gchar **parts;
           gsize j;
 
@@ -223,18 +226,17 @@ ide_git_search_index_populate (IdeGitSearchIndex *self,
             g_string_append_printf (str, " / %s", parts [j]);
           g_strfreev (parts);
 
-          /* highlight the title string with underlines */
           markup = str_highlight (shortname, search_terms);
+          file = g_file_get_child (self->workdir, match->value);
 
-          /* create our search result and connect to signals */
-          result = ide_search_result_new (context, markup, str->str, match->score);
-          g_object_set_qdata_full (G_OBJECT (result), gPathQuark, g_strdup (match->value), g_free);
-#if 0
-          /* I think we might want to leave this signal on the provider */
-          g_signal_connect (result, "activate", G_CALLBACK (activate_cb), NULL);
-#endif
+          result = g_object_new (IDE_TYPE_GIT_SEARCH_RESULT,
+                                 "context", context,
+                                 "title", markup,
+                                 "subtitle", str->str,
+                                 "score", match->score,
+                                 "file", file,
+                                 NULL);
 
-          /* push the result through the search reducer */
           ide_search_reducer_push (&reducer, result);
         }
     }
@@ -249,6 +251,7 @@ ide_git_search_index_finalize (GObject *object)
   IdeGitSearchIndex *self = (IdeGitSearchIndex *)object;
 
   g_clear_object (&self->location);
+  g_clear_object (&self->workdir);
   g_clear_pointer (&self->shorthand, g_free);
   g_clear_pointer (&self->fuzzy, fuzzy_unref);
 
@@ -356,6 +359,8 @@ ide_git_search_index_init_worker (GTask        *task,
       goto cleanup;
     }
 
+  self->workdir = ggit_repository_get_workdir (repository);
+
   ref = ggit_repository_get_head (repository, NULL);
 
   if (ref)
diff --git a/libide/git/ide-git-search-result.c b/libide/git/ide-git-search-result.c
new file mode 100644
index 0000000..aec8d27
--- /dev/null
+++ b/libide/git/ide-git-search-result.c
@@ -0,0 +1,110 @@
+/* ide-git-search-result.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This file is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This file 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
+ * Lesser 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/>.
+ */
+
+#include <glib/gi18n.h>
+
+#include "ide-git-search-result.h"
+
+struct _IdeGitSearchResult
+{
+  IdeSearchResult  parent_instance;
+  GFile           *file;
+};
+
+enum
+{
+  PROP_0,
+  PROP_FILE,
+  LAST_PROP
+};
+
+G_DEFINE_TYPE (IdeGitSearchResult, ide_git_search_result, IDE_TYPE_SEARCH_RESULT)
+
+static GParamSpec *gParamSpecs [LAST_PROP];
+
+static void
+ide_git_search_result_finalize (GObject *object)
+{
+  IdeGitSearchResult *self = (IdeGitSearchResult *)object;
+
+  g_clear_object (&self->file);
+
+  G_OBJECT_CLASS (ide_git_search_result_parent_class)->finalize (object);
+}
+
+static void
+ide_git_search_result_get_property (GObject    *object,
+                                    guint       prop_id,
+                                    GValue     *value,
+                                    GParamSpec *pspec)
+{
+  IdeGitSearchResult *self = IDE_GIT_SEARCH_RESULT (object);
+
+  switch (prop_id)
+    {
+    case PROP_FILE:
+      g_value_set_object (value, self->file);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_git_search_result_set_property (GObject      *object,
+                                    guint         prop_id,
+                                    const GValue *value,
+                                    GParamSpec   *pspec)
+{
+  IdeGitSearchResult *self = IDE_GIT_SEARCH_RESULT (object);
+
+  switch (prop_id)
+    {
+    case PROP_FILE:
+      g_set_object (&self->file, g_value_get_object (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_git_search_result_class_init (IdeGitSearchResultClass *klass)
+{
+  GObjectClass *object_class;
+
+  object_class = G_OBJECT_CLASS (klass);
+  object_class->finalize = ide_git_search_result_finalize;
+  object_class->get_property = ide_git_search_result_get_property;
+  object_class->set_property = ide_git_search_result_set_property;
+
+  gParamSpecs [PROP_FILE] =
+    g_param_spec_object ("file",
+                         _("File"),
+                         _("The file to be opened."),
+                         G_TYPE_FILE,
+                         (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+  g_object_class_install_property (object_class, PROP_FILE, gParamSpecs [PROP_FILE]);
+}
+
+static void
+ide_git_search_result_init (IdeGitSearchResult *result)
+{
+}
diff --git a/libide/git/ide-git-search-result.h b/libide/git/ide-git-search-result.h
new file mode 100644
index 0000000..0be0221
--- /dev/null
+++ b/libide/git/ide-git-search-result.h
@@ -0,0 +1,32 @@
+/* ide-git-search-result.h
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This file is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This file 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
+ * Lesser 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/>.
+ */
+
+#ifndef IDE_GIT_SEARCH_RESULT_H
+#define IDE_GIT_SEARCH_RESULT_H
+
+#include "ide-search-result.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_GIT_SEARCH_RESULT (ide_git_search_result_get_type())
+
+G_DECLARE_FINAL_TYPE (IdeGitSearchResult, ide_git_search_result, IDE, GIT_SEARCH_RESULT, IdeSearchResult)
+
+G_END_DECLS
+
+#endif /* IDE_GIT_SEARCH_RESULT_H */
diff --git a/libide/ide.h b/libide/ide.h
index c5080a9..cbaafff 100644
--- a/libide/ide.h
+++ b/libide/ide.h
@@ -89,6 +89,7 @@ G_BEGIN_DECLS
 #include "autotools/ide-autotools-build-system.h"
 #include "directory/ide-directory-build-system.h"
 #include "directory/ide-directory-vcs.h"
+#include "git/ide-git-search-result.h"
 #include "git/ide-git-vcs.h"
 #include "local/ide-local-device.h"
 #include "theatrics/ide-animation.h"
diff --git a/src/search/gb-search-box.c b/src/search/gb-search-box.c
index af2ab33..3b551cd 100644
--- a/src/search/gb-search-box.c
+++ b/src/search/gb-search-box.c
@@ -226,10 +226,38 @@ gb_search_box_display_result_activated (GbSearchBox     *self,
                                         IdeSearchResult *result,
                                         GbSearchDisplay *display)
 {
+  GbWorkbench *workbench;
+
   g_return_if_fail (GB_IS_SEARCH_BOX (self));
   g_return_if_fail (IDE_IS_SEARCH_RESULT (result));
   g_return_if_fail (GB_IS_SEARCH_DISPLAY (display));
 
+  workbench = gb_widget_get_workbench (GTK_WIDGET (self));
+
+  /*
+   * FIXME:
+   *
+   * This is not ideal, but we don't have time before the 3.16 release to build
+   * the proper abstraction for us to keep the load hooks inside of the Builder
+   * code and out of the libide code.
+   *
+   * After release, we should revisit this, and probably add an extension
+   * point to register the handler for a given result type.
+   */
+  if (IDE_IS_GIT_SEARCH_RESULT (result))
+    {
+      g_autoptr(GFile) file = NULL;
+
+      g_object_get (result, "file", &file, NULL);
+      if (file)
+        gb_workbench_open (workbench, file);
+    }
+  else
+    {
+      g_warning (_("Builder does not know how to load %s"),
+                 g_type_name (G_TYPE_FROM_INSTANCE (result)));
+    }
+
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->button), FALSE);
   gtk_entry_set_text (GTK_ENTRY (self->entry), "");
 }


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