[gnome-builder] buildui: add editor-page-addin to set project version



commit c1aa77ac84951194df4284364c59da66c3392d76
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jan 11 12:37:52 2019 -0800

    buildui: add editor-page-addin to set project version
    
    This adds a project version variable to snippets so that it may be added
    to gtk-doc documentation upon expansion.

 src/plugins/buildui/buildui-plugin.c               |   5 +
 .../buildui/gbp-buildui-editor-page-addin.c        | 135 +++++++++++++++++++++
 .../buildui/gbp-buildui-editor-page-addin.h        |  31 +++++
 src/plugins/buildui/meson.build                    |   1 +
 src/plugins/snippets/snippets/gobject.snippets     |   2 +
 5 files changed, 174 insertions(+)
---
diff --git a/src/plugins/buildui/buildui-plugin.c b/src/plugins/buildui/buildui-plugin.c
index cf395308f..ed8059117 100644
--- a/src/plugins/buildui/buildui-plugin.c
+++ b/src/plugins/buildui/buildui-plugin.c
@@ -23,10 +23,12 @@
 #include "config.h"
 
 #include <libpeas/peas.h>
+#include <libide-editor.h>
 #include <libide-gui.h>
 #include <libide-tree.h>
 
 #include "gbp-buildui-config-view-addin.h"
+#include "gbp-buildui-editor-page-addin.h"
 #include "gbp-buildui-workspace-addin.h"
 #include "gbp-buildui-tree-addin.h"
 
@@ -36,6 +38,9 @@ _gbp_buildui_register_types (PeasObjectModule *module)
   peas_object_module_register_extension_type (module,
                                               IDE_TYPE_CONFIG_VIEW_ADDIN,
                                               GBP_TYPE_BUILDUI_CONFIG_VIEW_ADDIN);
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_EDITOR_PAGE_ADDIN,
+                                              GBP_TYPE_BUILDUI_EDITOR_PAGE_ADDIN);
   peas_object_module_register_extension_type (module,
                                               IDE_TYPE_WORKSPACE_ADDIN,
                                               GBP_TYPE_BUILDUI_WORKSPACE_ADDIN);
diff --git a/src/plugins/buildui/gbp-buildui-editor-page-addin.c 
b/src/plugins/buildui/gbp-buildui-editor-page-addin.c
new file mode 100644
index 000000000..fd1cef41b
--- /dev/null
+++ b/src/plugins/buildui/gbp-buildui-editor-page-addin.c
@@ -0,0 +1,135 @@
+/* gbp-buildui-editor-page-addin.c
+ *
+ * Copyright 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-buildui-editor-page-addin"
+
+#include <libide-editor.h>
+#include <libide-foundry.h>
+
+#include "gbp-buildui-editor-page-addin.h"
+
+struct _GbpBuilduiEditorPageAddin
+{
+  GObject parent_instance;
+};
+
+static void
+transpose_version (gchar *str)
+{
+  gchar *dot;
+
+  g_assert (str);
+
+  if ((dot = strchr (str, '.')))
+    {
+      dot++;
+      if ((dot = strchr (str, '.')))
+        *dot = 0;
+    }
+}
+
+static void
+on_push_snippet_cb (GbpBuilduiEditorPageAddin *self,
+                    IdeSnippet                *snippet,
+                    const GtkTextIter         *iter,
+                    IdeSourceView             *view)
+{
+  g_autoptr(IdeContext) context = NULL;
+  g_autofree gchar *project_version = NULL;
+  GtkTextBuffer *buffer;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (IDE_IS_SNIPPET (snippet));
+  g_assert (IDE_IS_SOURCE_VIEW (view));
+
+  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+  context = ide_buffer_ref_context (IDE_BUFFER (buffer));
+
+  if (ide_context_has_project (context))
+    {
+      IdeBuildSystem *build_system = ide_build_system_from_context (context);
+
+      if (build_system != NULL)
+        {
+          if ((project_version = ide_build_system_get_project_version (build_system)))
+            transpose_version (project_version);
+        }
+    }
+
+  ide_snippet_context_add_variable (ide_snippet_get_context (snippet),
+                                    "project_version",
+                                    project_version ?: "");
+}
+
+static void
+gbp_buildui_editor_page_addin_load (IdeEditorPageAddin *addin,
+                                    IdeEditorPage      *page)
+{
+  IdeSourceView *view;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (IDE_IS_EDITOR_PAGE_ADDIN (addin));
+  g_assert (IDE_IS_EDITOR_PAGE (page));
+
+  view = ide_editor_page_get_view (page);
+
+  g_signal_connect_object (view,
+                           "push-snippet",
+                           G_CALLBACK (on_push_snippet_cb),
+                           addin,
+                           G_CONNECT_SWAPPED);
+}
+
+static void
+gbp_buildui_editor_page_addin_unload (IdeEditorPageAddin *addin,
+                                      IdeEditorPage      *page)
+{
+  IdeSourceView *view;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (IDE_IS_EDITOR_PAGE_ADDIN (addin));
+  g_assert (IDE_IS_EDITOR_PAGE (page));
+
+  view = ide_editor_page_get_view (page);
+
+  g_signal_handlers_disconnect_by_func (view,
+                                        G_CALLBACK (on_push_snippet_cb),
+                                        addin);
+}
+
+static void
+editor_page_addin_iface_init (IdeEditorPageAddinInterface *iface)
+{
+  iface->load = gbp_buildui_editor_page_addin_load;
+  iface->unload = gbp_buildui_editor_page_addin_unload;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpBuilduiEditorPageAddin, gbp_buildui_editor_page_addin, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (IDE_TYPE_EDITOR_PAGE_ADDIN, editor_page_addin_iface_init))
+
+static void
+gbp_buildui_editor_page_addin_class_init (GbpBuilduiEditorPageAddinClass *klass)
+{
+}
+
+static void
+gbp_buildui_editor_page_addin_init (GbpBuilduiEditorPageAddin *self)
+{
+}
diff --git a/src/plugins/buildui/gbp-buildui-editor-page-addin.h 
b/src/plugins/buildui/gbp-buildui-editor-page-addin.h
new file mode 100644
index 000000000..cb06b3e9b
--- /dev/null
+++ b/src/plugins/buildui/gbp-buildui-editor-page-addin.h
@@ -0,0 +1,31 @@
+/* gbp-buildui-editor-page-addin.h
+ *
+ * Copyright 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
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_BUILDUI_EDITOR_PAGE_ADDIN (gbp_buildui_editor_page_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpBuilduiEditorPageAddin, gbp_buildui_editor_page_addin, GBP, 
BUILDUI_EDITOR_PAGE_ADDIN, GObject)
+
+G_END_DECLS
diff --git a/src/plugins/buildui/meson.build b/src/plugins/buildui/meson.build
index fe69f85e4..eb2e71947 100644
--- a/src/plugins/buildui/meson.build
+++ b/src/plugins/buildui/meson.build
@@ -2,6 +2,7 @@ plugins_sources += files([
   'buildui-plugin.c',
   'gbp-buildui-config-surface.c',
   'gbp-buildui-config-view-addin.c',
+  'gbp-buildui-editor-page-addin.c',
   'gbp-buildui-log-pane.c',
   'gbp-buildui-omni-bar-section.c',
   'gbp-buildui-pane.c',
diff --git a/src/plugins/snippets/snippets/gobject.snippets b/src/plugins/snippets/snippets/gobject.snippets
index a6785ed60..dd20246d3 100644
--- a/src/plugins/snippets/snippets/gobject.snippets
+++ b/src/plugins/snippets/snippets/gobject.snippets
@@ -599,6 +599,8 @@ snippet doc
         * ${3}
         *
         * Returns: ${2}
+        *
+        * Since: ${4:$project_version}
         */$0
 snippet fail
 - desc Snippet for g_return_if_fail()


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