[gnome-builder] plugins: add helper to get extension by plugin_info
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] plugins: add helper to get extension by plugin_info
- Date: Wed, 19 Jul 2017 11:18:38 +0000 (UTC)
commit 4d2ed17eaab95022ff459586b8ac5cc83e9f122f
Author: Christian Hergert <chergert redhat com>
Date: Fri Jul 14 15:42:34 2017 -0700
plugins: add helper to get extension by plugin_info
This is convenient in PeasExtensionSet, and so our adapter
helper should have it too.
libide/plugins/ide-extension-set-adapter.c | 43 ++++++++++++++++++++++++++++
libide/plugins/ide-extension-set-adapter.h | 2 +
2 files changed, 45 insertions(+), 0 deletions(-)
---
diff --git a/libide/plugins/ide-extension-set-adapter.c b/libide/plugins/ide-extension-set-adapter.c
index afc3811..7a30843 100644
--- a/libide/plugins/ide-extension-set-adapter.c
+++ b/libide/plugins/ide-extension-set-adapter.c
@@ -550,3 +550,46 @@ ide_extension_set_adapter_new (IdeContext *context,
"value", value,
NULL);
}
+
+static void
+locate_extension_by_plugin_info (IdeExtensionSetAdapter *self,
+ PeasPluginInfo *plugin_info,
+ PeasExtension *exten,
+ gpointer user_data)
+{
+ struct {
+ PeasPluginInfo *plugin_info;
+ PeasExtension *exten;
+ } *lookup = user_data;
+
+ if (lookup->plugin_info == plugin_info)
+ lookup->exten = exten;
+}
+
+/**
+ * ide_extension_set_adapter_get_extension:
+ * @self: a #IdeExtensionSetAdapter
+ * @plugin_info: a #PeasPluginInfo
+ *
+ * Locates the extension owned by @plugin_info if such extension exists.
+ *
+ * Returns: (transfer none) (nullable): A #PeasExtension or %NULL
+ */
+PeasExtension *
+ide_extension_set_adapter_get_extension (IdeExtensionSetAdapter *self,
+ PeasPluginInfo *plugin_info)
+{
+ struct {
+ PeasPluginInfo *plugin_info;
+ PeasExtension *exten;
+ } lookup = { 0 };
+
+ g_return_val_if_fail (IDE_IS_EXTENSION_SET_ADAPTER (self), NULL);
+ g_return_val_if_fail (plugin_info != NULL, NULL);
+
+ ide_extension_set_adapter_foreach (self,
+ locate_extension_by_plugin_info,
+ &lookup);
+
+ return lookup.exten;
+}
diff --git a/libide/plugins/ide-extension-set-adapter.h b/libide/plugins/ide-extension-set-adapter.h
index 27ace5f..13a3ec4 100644
--- a/libide/plugins/ide-extension-set-adapter.h
+++ b/libide/plugins/ide-extension-set-adapter.h
@@ -51,6 +51,8 @@ guint ide_extension_set_adapter_get_n_extensions (IdeExtensi
void ide_extension_set_adapter_foreach (IdeExtensionSetAdapter
*self,
IdeExtensionSetAdapterForeachFunc
foreach_func,
gpointer
user_data);
+PeasExtension *ide_extension_set_adapter_get_extension (IdeExtensionSetAdapter
*self,
+ PeasPluginInfo
*plugin_info);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]