[gnome-builder/wip/gtk4-port: 395/736] libide/editor: add IdeEditorPageAddin
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 395/736] libide/editor: add IdeEditorPageAddin
- Date: Tue, 26 Apr 2022 01:46:25 +0000 (UTC)
commit 29725ddac129177acd27527408b54edba684658c
Author: Christian Hergert <chergert redhat com>
Date: Mon Apr 4 17:16:53 2022 -0700
libide/editor: add IdeEditorPageAddin
This brings back the editor page addin in the new libde-editor.
src/libide/editor/ide-editor-page-addin.c | 115 ++++++++++++++++++++++++++++
src/libide/editor/ide-editor-page-addin.h | 69 +++++++++++++++++
src/libide/editor/ide-editor-page-private.h | 19 +++--
src/libide/editor/ide-editor-page.c | 100 ++++++++++++++++++++++++
src/libide/editor/libide-editor.h | 1 +
src/libide/editor/meson.build | 3 +
6 files changed, 299 insertions(+), 8 deletions(-)
---
diff --git a/src/libide/editor/ide-editor-page-addin.c b/src/libide/editor/ide-editor-page-addin.c
new file mode 100644
index 000000000..86ff6d776
--- /dev/null
+++ b/src/libide/editor/ide-editor-page-addin.c
@@ -0,0 +1,115 @@
+/* ide-editor-page-addin.c
+ *
+ * Copyright 2015-2022 Christian Hergert <christian hergert me>
+ *
+ * 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 "ide-editor-page-addin"
+
+#include "config.h"
+
+#include <libide-plugins.h>
+
+#include "ide-editor-page-addin.h"
+#include "ide-editor-page-private.h"
+
+G_DEFINE_INTERFACE (IdeEditorPageAddin, ide_editor_page_addin, G_TYPE_OBJECT)
+
+static void
+ide_editor_page_addin_default_init (IdeEditorPageAddinInterface *iface)
+{
+}
+
+void
+ide_editor_page_addin_load (IdeEditorPageAddin *self,
+ IdeEditorPage *page)
+{
+ g_return_if_fail (IDE_IS_EDITOR_PAGE_ADDIN (self));
+ g_return_if_fail (IDE_IS_EDITOR_PAGE (page));
+
+ if (IDE_EDITOR_PAGE_ADDIN_GET_IFACE (self)->load)
+ IDE_EDITOR_PAGE_ADDIN_GET_IFACE (self)->load (self, page);
+}
+
+void
+ide_editor_page_addin_unload (IdeEditorPageAddin *self,
+ IdeEditorPage *page)
+{
+ g_return_if_fail (IDE_IS_EDITOR_PAGE_ADDIN (self));
+ g_return_if_fail (IDE_IS_EDITOR_PAGE (page));
+
+ if (IDE_EDITOR_PAGE_ADDIN_GET_IFACE (self)->unload)
+ IDE_EDITOR_PAGE_ADDIN_GET_IFACE (self)->unload (self, page);
+}
+
+void
+ide_editor_page_addin_language_changed (IdeEditorPageAddin *self,
+ const gchar *language_id)
+{
+ g_return_if_fail (IDE_IS_EDITOR_PAGE_ADDIN (self));
+
+ if (IDE_EDITOR_PAGE_ADDIN_GET_IFACE (self)->language_changed)
+ IDE_EDITOR_PAGE_ADDIN_GET_IFACE (self)->language_changed (self, language_id);
+}
+
+void
+ide_editor_page_addin_frame_set (IdeEditorPageAddin *self,
+ IdeFrame *frame)
+{
+ g_return_if_fail (IDE_IS_EDITOR_PAGE_ADDIN (self));
+ g_return_if_fail (IDE_IS_FRAME (frame));
+
+ if (IDE_EDITOR_PAGE_ADDIN_GET_IFACE (self)->frame_set)
+ IDE_EDITOR_PAGE_ADDIN_GET_IFACE (self)->frame_set (self, frame);
+}
+
+/**
+ * ide_editor_page_addin_find_by_module_name:
+ * @page: an #IdeEditorPage
+ * @module_name: the module name which provides the addin
+ *
+ * This function will locate the #IdeEditorPageAddin that was registered
+ * by the addin named @module_name (which should match the module_name
+ * provided in the .plugin file).
+ *
+ * If no module was found or that module does not implement the
+ * #IdeEditorPageAddinInterface, then %NULL is returned.
+ *
+ * Returns: (transfer none) (nullable): An #IdeEditorPageAddin or %NULL
+ *
+ * Since: 3.32
+ */
+IdeEditorPageAddin *
+ide_editor_page_addin_find_by_module_name (IdeEditorPage *page,
+ const gchar *module_name)
+{
+ PeasExtension *ret = NULL;
+ PeasPluginInfo *plugin_info;
+
+ g_return_val_if_fail (IDE_IS_EDITOR_PAGE (page), NULL);
+ g_return_val_if_fail (page->addins != NULL, NULL);
+ g_return_val_if_fail (module_name != NULL, NULL);
+
+ plugin_info = peas_engine_get_plugin_info (peas_engine_get_default (), module_name);
+
+ if (plugin_info != NULL)
+ ret = ide_extension_set_adapter_get_extension (page->addins, plugin_info);
+ else
+ g_warning ("No addin could be found matching module \"%s\"", module_name);
+
+ return ret ? IDE_EDITOR_PAGE_ADDIN (ret) : NULL;
+}
diff --git a/src/libide/editor/ide-editor-page-addin.h b/src/libide/editor/ide-editor-page-addin.h
new file mode 100644
index 000000000..e0fd9ebfe
--- /dev/null
+++ b/src/libide/editor/ide-editor-page-addin.h
@@ -0,0 +1,69 @@
+/* ide-editor-page-addin.h
+ *
+ * Copyright 2015-2022 Christian Hergert <christian hergert me>
+ *
+ * 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
+
+#if !defined (IDE_EDITOR_INSIDE) && !defined (IDE_EDITOR_COMPILATION)
+# error "Only <libide-editor.h> can be included directly."
+#endif
+
+#include <libide-core.h>
+#include <libide-gui.h>
+
+#include "ide-editor-page.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_EDITOR_PAGE_ADDIN (ide_editor_page_addin_get_type ())
+
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_INTERFACE (IdeEditorPageAddin, ide_editor_page_addin, IDE, EDITOR_PAGE_ADDIN, GObject)
+
+struct _IdeEditorPageAddinInterface
+{
+ GTypeInterface parent;
+
+ void (*load) (IdeEditorPageAddin *self,
+ IdeEditorPage *page);
+ void (*unload) (IdeEditorPageAddin *self,
+ IdeEditorPage *page);
+ void (*language_changed) (IdeEditorPageAddin *self,
+ const gchar *language_id);
+ void (*frame_set) (IdeEditorPageAddin *self,
+ IdeFrame *frame);
+};
+
+IDE_AVAILABLE_IN_ALL
+void ide_editor_page_addin_load (IdeEditorPageAddin *self,
+ IdeEditorPage *page);
+IDE_AVAILABLE_IN_ALL
+void ide_editor_page_addin_unload (IdeEditorPageAddin *self,
+ IdeEditorPage *page);
+IDE_AVAILABLE_IN_ALL
+void ide_editor_page_addin_frame_set (IdeEditorPageAddin *self,
+ IdeFrame *frame);
+IDE_AVAILABLE_IN_ALL
+void ide_editor_page_addin_language_changed (IdeEditorPageAddin *self,
+ const gchar *language_id);
+IDE_AVAILABLE_IN_ALL
+IdeEditorPageAddin *ide_editor_page_addin_find_by_module_name (IdeEditorPage *page,
+ const gchar *module_name);
+
+G_END_DECLS
diff --git a/src/libide/editor/ide-editor-page-private.h b/src/libide/editor/ide-editor-page-private.h
index b7ec71431..9f580c638 100644
--- a/src/libide/editor/ide-editor-page-private.h
+++ b/src/libide/editor/ide-editor-page-private.h
@@ -20,26 +20,29 @@
#pragma once
+#include <libide-plugins.h>
+
#include "ide-editor-page.h"
G_BEGIN_DECLS
struct _IdeEditorPage
{
- IdePage parent_instance;
+ IdePage parent_instance;
/* Owned references */
- IdeBuffer *buffer;
+ IdeExtensionSetAdapter *addins;
+ IdeBuffer *buffer;
/* Settings Management */
- IdeBindingGroup *buffer_file_settings;
- IdeBindingGroup *view_file_settings;
+ IdeBindingGroup *buffer_file_settings;
+ IdeBindingGroup *view_file_settings;
/* Template widgets */
- IdeSourceView *view;
- GtkScrolledWindow *scroller;
- GtkSourceMap *map;
- GtkRevealer *map_revealer;
+ IdeSourceView *view;
+ GtkScrolledWindow *scroller;
+ GtkSourceMap *map;
+ GtkRevealer *map_revealer;
};
void _ide_editor_page_class_actions_init (IdeEditorPageClass *klass);
diff --git a/src/libide/editor/ide-editor-page.c b/src/libide/editor/ide-editor-page.c
index 66ed3ce94..292c50a18 100644
--- a/src/libide/editor/ide-editor-page.c
+++ b/src/libide/editor/ide-editor-page.c
@@ -22,6 +22,7 @@
#include "config.h"
+#include "ide-editor-page-addin.h"
#include "ide-editor-page-private.h"
enum {
@@ -113,11 +114,109 @@ ide_editor_page_focus_enter_cb (IdeEditorPage *self,
IDE_EXIT;
}
+static void
+ide_editor_page_notify_frame_set (IdeExtensionSetAdapter *set,
+ PeasPluginInfo *plugin_info,
+ PeasExtension *exten,
+ gpointer user_data)
+{
+ IdeFrame *frame = user_data;
+ IdeEditorPageAddin *addin = (IdeEditorPageAddin *)exten;
+
+ g_assert (IDE_IS_EXTENSION_SET_ADAPTER (set));
+ g_assert (plugin_info != NULL);
+ g_assert (IDE_IS_EDITOR_PAGE_ADDIN (addin));
+ g_assert (IDE_IS_FRAME (frame));
+
+ ide_editor_page_addin_frame_set (addin, frame);
+}
+
+static void
+ide_editor_page_addin_added (IdeExtensionSetAdapter *set,
+ PeasPluginInfo *plugin_info,
+ PeasExtension *exten,
+ gpointer user_data)
+{
+ IdeEditorPage *self = user_data;
+ IdeEditorPageAddin *addin = (IdeEditorPageAddin *)exten;
+
+ g_assert (IDE_IS_EXTENSION_SET_ADAPTER (set));
+ g_assert (plugin_info != NULL);
+ g_assert (IDE_IS_EDITOR_PAGE_ADDIN (addin));
+ g_assert (IDE_IS_EDITOR_PAGE (self));
+
+ ide_editor_page_addin_load (addin, self);
+}
+
+static void
+ide_editor_page_addin_removed (IdeExtensionSetAdapter *set,
+ PeasPluginInfo *plugin_info,
+ PeasExtension *exten,
+ gpointer user_data)
+{
+ IdeEditorPage *self = user_data;
+ IdeEditorPageAddin *addin = (IdeEditorPageAddin *)exten;
+
+ g_assert (IDE_IS_EXTENSION_SET_ADAPTER (set));
+ g_assert (plugin_info != NULL);
+ g_assert (IDE_IS_EDITOR_PAGE_ADDIN (addin));
+ g_assert (IDE_IS_EDITOR_PAGE (self));
+
+ ide_editor_page_addin_unload (addin, self);
+}
+
+static void
+ide_editor_page_root (GtkWidget *widget)
+{
+ IdeEditorPage *self = (IdeEditorPage *)widget;
+ IdeContext *context;
+ GtkWidget *frame;
+
+ IDE_ENTRY;
+
+ GTK_WIDGET_CLASS (ide_editor_page_parent_class)->root (widget);
+
+ context = ide_widget_get_context (widget);
+ frame = gtk_widget_get_ancestor (widget, IDE_TYPE_FRAME);
+
+ if (self->addins == NULL && context != NULL)
+ {
+ self->addins = ide_extension_set_adapter_new (IDE_OBJECT (context),
+ peas_engine_get_default (),
+ IDE_TYPE_EDITOR_PAGE_ADDIN,
+ "Editor-Page-Languages",
+ ide_buffer_get_language_id (self->buffer));
+
+ g_signal_connect (self->addins,
+ "extension-added",
+ G_CALLBACK (ide_editor_page_addin_added),
+ self);
+
+ g_signal_connect (self->addins,
+ "extension-removed",
+ G_CALLBACK (ide_editor_page_addin_removed),
+ self);
+
+ ide_extension_set_adapter_foreach (self->addins,
+ ide_editor_page_addin_added,
+ self);
+ }
+
+ if (self->addins != NULL && frame != NULL)
+ ide_extension_set_adapter_foreach (self->addins,
+ ide_editor_page_notify_frame_set,
+ frame);
+
+ IDE_EXIT;
+}
+
static void
ide_editor_page_dispose (GObject *object)
{
IdeEditorPage *self = (IdeEditorPage *)object;
+ ide_clear_and_destroy_object (&self->addins);
+
g_clear_object (&self->buffer_file_settings);
g_clear_object (&self->view_file_settings);
@@ -183,6 +282,7 @@ ide_editor_page_class_init (IdeEditorPageClass *klass)
object_class->set_property = ide_editor_page_set_property;
widget_class->grab_focus = ide_editor_page_grab_focus;
+ widget_class->root = ide_editor_page_root;
/**
* IdeEditorPage:buffer:
diff --git a/src/libide/editor/libide-editor.h b/src/libide/editor/libide-editor.h
index 2f564d66e..6712eac86 100644
--- a/src/libide/editor/libide-editor.h
+++ b/src/libide/editor/libide-editor.h
@@ -23,4 +23,5 @@
#define IDE_EDITOR_INSIDE
# include "ide-editor.h"
# include "ide-editor-page.h"
+# include "ide-editor-page-addin.h"
#undef IDE_EDITOR_INSIDE
diff --git a/src/libide/editor/meson.build b/src/libide/editor/meson.build
index 60acb502a..ff79b834d 100644
--- a/src/libide/editor/meson.build
+++ b/src/libide/editor/meson.build
@@ -13,6 +13,7 @@ libide_editor_generated_headers = []
libide_editor_public_headers = [
'ide-editor.h',
'ide-editor-page.h',
+ 'ide-editor-page-addin.h',
'libide-editor.h',
]
@@ -29,6 +30,7 @@ install_headers(libide_editor_public_headers, subdir: libide_editor_header_subdi
libide_editor_public_sources = [
'ide-editor.c',
'ide-editor-page.c',
+ 'ide-editor-page-addin.c',
]
@@ -64,6 +66,7 @@ libide_editor_deps = [
libide_core_dep,
libide_io_dep,
+ libide_plugins_dep,
libide_projects_dep,
libide_search_dep,
libide_sourceview_dep,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]