[gnome-builder] wip



commit 1fa1e780730fd2be7ad3afedaee9e46eb1df169c
Author: Christian Hergert <christian hergert me>
Date:   Sun Feb 15 13:44:06 2015 -0800

    wip

 build/autotools/autoconf.d/50_dependencies.post-am |    5 +-
 configure.ac                                       |    2 +
 libide/Makefile.am                                 |    8 +
 libide/gjs/ide-gjs-script.cpp                      |  225 ++++++++++++++++++++
 libide/gjs/ide-gjs-script.h                        |   34 +++
 libide/ide-script.c                                |    2 +-
 6 files changed, 274 insertions(+), 2 deletions(-)
---
diff --git a/build/autotools/autoconf.d/50_dependencies.post-am 
b/build/autotools/autoconf.d/50_dependencies.post-am
index 7e8a729..ff6a092 100644
--- a/build/autotools/autoconf.d/50_dependencies.post-am
+++ b/build/autotools/autoconf.d/50_dependencies.post-am
@@ -2,6 +2,7 @@ m4_define([gtk_required_version], [3.15.6])
 m4_define([glib_required_version], [2.43.4])
 m4_define([gtksourceview_required_version], [3.15.4])
 m4_define([ggit_required_version], [0.0.24])
+m4_define([gjs_required_version], [1.42.0])
 
 PKG_CHECK_MODULES(BUILDER, [gtk+-3.0 >= gtk_required_version
                             gtksourceview-3.0 >= gtksourceview_required_version
@@ -11,7 +12,9 @@ PKG_CHECK_MODULES(BUILDER, [gtk+-3.0 >= gtk_required_version
 PKG_CHECK_MODULES(LIBIDE, [gio-2.0 >= glib_required_version
                            gio-unix-2.0 >= glib_required_version
                            gtksourceview-3.0 >= gtksourceview_required_version
-                           libgit2-glib-1.0 >= ggit_required_version])
+                           libgit2-glib-1.0 >= ggit_required_version
+                           gjs-1.0 >= gjs_required_version
+                           gjs-internals-1.0 >= gjs_required_version])
 
 
 AC_PATH_PROG([LLVM_CONFIG], [llvm-config])
diff --git a/configure.ac b/configure.ac
index bc00594..258f345 100644
--- a/configure.ac
+++ b/configure.ac
@@ -25,6 +25,8 @@ AC_DEFINE_UNQUOTED([GETTEXT_PACKAGE], ["$GETTEXT_PACKAGE"],
                    [GETTEXT package name])
 AM_GLIB_GNU_GETTEXT
 
+AC_PROG_CXX
+
 # Initlize libtool and things that go with it.
 m4_include([build/autotools/autoconf.d/pre-lt.m4])
 m4_include([build/autotools/autoconf.d/setup_libtool.m4])
diff --git a/libide/Makefile.am b/libide/Makefile.am
index 9a088ae..158c80d 100644
--- a/libide/Makefile.am
+++ b/libide/Makefile.am
@@ -32,6 +32,8 @@ libide_la_public_sources = \
        libide/editorconfig/ide-editorconfig-file-settings.h \
        libide/git/ide-git-vcs.c \
        libide/git/ide-git-vcs.h \
+       libide/gjs/ide-gjs-script.cpp \
+       libide/gjs/ide-gjs-script.h \
        libide/gsettings/ide-gsettings-file-settings.c \
        libide/gsettings/ide-gsettings-file-settings.h \
        libide/ide-back-forward-item.c \
@@ -167,16 +169,22 @@ libide_la_CFLAGS = \
        -I$(top_srcdir)/libide/editorconfig \
        -I$(top_srcdir)/libide/editorconfig/libeditorconfig \
        -I$(top_srcdir)/libide/git \
+       -I$(top_srcdir)/libide/gjs \
        -I$(top_srcdir)/libide/gsettings \
        -I$(top_srcdir)/libide/local \
        -I$(top_srcdir)/libide/tasks \
        $(LIBIDE_CFLAGS)
 
+libide_la_CXXFLAGS = \
+       $(libide_la_CFLAGS) \
+       $(NULL)
+
 libide_la_LIBADD = \
        $(CLANG_LDFLAGS) \
        $(LIBIDE_LIBS) \
        -lclang \
        libeditorconfig.la \
+       -lstdc++ \
        $(NULL)
 
 
diff --git a/libide/gjs/ide-gjs-script.cpp b/libide/gjs/ide-gjs-script.cpp
new file mode 100644
index 0000000..03848fc
--- /dev/null
+++ b/libide/gjs/ide-gjs-script.cpp
@@ -0,0 +1,225 @@
+/* ide-gjs-script.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 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/>.
+ */
+
+#define GLIB_DISABLE_DEPRECATION_WARNINGS
+#include <gjs/gjs.h>
+#include <gjs/gjs-module.h>
+#include <gi/object.h>
+#include <glib/gi18n.h>
+#undef GLIB_DISABLE_DEPRECATION_WARNINGS
+
+#include <jsapi.h>
+
+#include "ide-gjs-script.h"
+
+struct _IdeGjsScript
+{
+  IdeScript parent_instance;
+
+  GFile      *file;
+  GjsContext *gjs;
+};
+
+G_DEFINE_TYPE (IdeGjsScript, ide_gjs_script, IDE_TYPE_SCRIPT)
+
+enum {
+  PROP_0,
+  PROP_FILE,
+  LAST_PROP
+};
+
+static GParamSpec *gParamSpecs [LAST_PROP];
+
+/**
+ * ide_gjs_script_get_file:
+ *
+ * Retrieves the #GFile containing the script to be loaded in the context.
+ *
+ * Returns: (transfer none): A #GFile.
+ */
+GFile *
+ide_gjs_script_get_file (IdeGjsScript *self)
+{
+  g_return_val_if_fail (IDE_IS_GJS_SCRIPT (self), NULL);
+
+  return self->file;
+}
+
+static void
+ide_gjs_script_set_file (IdeGjsScript *self,
+                         GFile        *file)
+{
+  g_return_if_fail (IDE_IS_GJS_SCRIPT (self));
+  g_return_if_fail (G_IS_FILE (file));
+  g_return_if_fail (!self->file);
+
+  self->file = (GFile *)g_object_ref (file);
+}
+
+static void
+set_global (GjsContext  *context,
+            const gchar *name,
+            GObject     *value)
+{
+  JSContext *jscontext;
+  JSObject *jsglobal;
+  jsval jsvalue;
+
+  jscontext = (JSContext *)gjs_context_get_native_context (context);
+  jsglobal = (JSObject *)gjs_get_global_object (jscontext);
+  jsvalue.setObject (*gjs_object_from_g_object (jscontext, value));
+
+  if (!JS_SetProperty (jscontext, jsglobal, "Context", &jsvalue))
+    {
+      g_warning (_("Failed to set IdeContext in JavaScript runtime."));
+      return;
+    }
+}
+
+static void
+ide_gjs_script_load (IdeScript *script)
+{
+  IdeGjsScript *self = (IdeGjsScript *)script;
+  IdeContext *context;
+  g_autoptr(GError) error = NULL;
+  g_autoptr(gchar) contents = NULL;
+  g_autoptr(gchar) path;
+  gsize len;
+  int exit_status = 0;
+
+  g_return_if_fail (IDE_IS_GJS_SCRIPT (self));
+  g_return_if_fail (!self->gjs);
+  g_return_if_fail (G_IS_FILE (self->file));
+
+  if (!self->file)
+    {
+      g_warning (_("Attempt to load a GJS script with no filename."));
+      return;
+    }
+
+  path = g_file_get_basename (self->file);
+
+  if (!g_file_load_contents (self->file, NULL, &contents, &len, NULL, &error))
+    {
+      g_warning ("%s", error->message);
+      return;
+    }
+
+  self->gjs = gjs_context_new ();
+
+  if (!self->gjs)
+    {
+      g_warning (_("Failed to create JavaScript context."));
+      return;
+    }
+
+  context = ide_object_get_context (IDE_OBJECT (self));
+  set_global (self->gjs, "Context", G_OBJECT (context));
+
+  if (!gjs_context_eval (self->gjs, contents, len, path, &exit_status, &error))
+    {
+      g_warning ("%s", error->message);
+      return;
+    }
+
+  g_info ("GJS script \"%s\" loaded.", path);
+}
+
+static void
+ide_gjs_script_unload (IdeScript *self)
+{
+  g_return_if_fail (IDE_IS_GJS_SCRIPT (self));
+}
+
+static void
+ide_gjs_script_finalize (GObject *object)
+{
+  IdeGjsScript *self = (IdeGjsScript *)object;
+
+  g_clear_object (&self->file);
+
+  G_OBJECT_CLASS (ide_gjs_script_parent_class)->finalize (object);
+}
+
+static void
+ide_gjs_script_get_property (GObject    *object,
+                             guint       prop_id,
+                             GValue     *value,
+                             GParamSpec *pspec)
+{
+  IdeGjsScript *self = IDE_GJS_SCRIPT (object);
+
+  switch (prop_id)
+    {
+    case PROP_FILE:
+      g_value_set_object (value, ide_gjs_script_get_file (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_gjs_script_set_property (GObject      *object,
+                             guint         prop_id,
+                             const GValue *value,
+                             GParamSpec   *pspec)
+{
+  IdeGjsScript *self = IDE_GJS_SCRIPT (object);
+
+  switch (prop_id)
+    {
+    case PROP_FILE:
+      ide_gjs_script_set_file (self, (GFile *)g_value_get_object (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_gjs_script_class_init (IdeGjsScriptClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  IdeScriptClass *script_class = IDE_SCRIPT_CLASS (klass);
+
+  object_class->finalize = ide_gjs_script_finalize;
+  object_class->get_property = ide_gjs_script_get_property;
+  object_class->set_property = ide_gjs_script_set_property;
+
+  script_class->load = ide_gjs_script_load;
+  script_class->unload = ide_gjs_script_unload;
+
+  gParamSpecs [PROP_FILE] =
+    g_param_spec_object ("file",
+                         _("File"),
+                         _("The file containing the script contents."),
+                         G_TYPE_FILE,
+                         (GParamFlags)(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_gjs_script_init (IdeGjsScript *self)
+{
+}
diff --git a/libide/gjs/ide-gjs-script.h b/libide/gjs/ide-gjs-script.h
new file mode 100644
index 0000000..14b540d
--- /dev/null
+++ b/libide/gjs/ide-gjs-script.h
@@ -0,0 +1,34 @@
+/* ide-gjs-script.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_GJS_SCRIPT_H
+#define IDE_GJS_SCRIPT_H
+
+#include "ide-script.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_GJS_SCRIPT (ide_gjs_script_get_type())
+
+G_DECLARE_FINAL_TYPE (IdeGjsScript, ide_gjs_script, IDE, GJS_SCRIPT, IdeScript)
+
+GFile *ide_gjs_script_get_file (IdeGjsScript *self);
+
+G_END_DECLS
+
+#endif /* IDE_GJS_SCRIPT_H */
diff --git a/libide/ide-script.c b/libide/ide-script.c
index 0fb85bf..657ad31 100644
--- a/libide/ide-script.c
+++ b/libide/ide-script.c
@@ -20,7 +20,7 @@
 
 #include "ide-script.h"
 
-G_DEFINE_TYPE (IdeScript, ide_script, IDE_TYPE_OBJECT)
+G_DEFINE_ABSTRACT_TYPE (IdeScript, ide_script, IDE_TYPE_OBJECT)
 
 enum {
   LOAD,


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