[geany/geany] 13ec6f: Add new API function plugin_builder_connect_signals()
Matthew Brush
git-noreply at xxxxx
Sun Jun 9 22:22:25 UTC 2013
Branch: refs/heads/master
Author: Matthew Brush <matt at geany.org>
Committer: Matthew Brush <matt at geany.org>
Date: Sun, 09 Jun 2013 22:22:25 UTC
Commit: 13ec6ffbea8155f563a8a6b5a86a5b674684697a
https://github.com/geany/geany/commit/13ec6ffbea8155f563a8a6b5a86a5b674684697a
Log Message:
-----------
Add new API function plugin_builder_connect_signals()
Modified Paths:
--------------
plugins/geanyfunctions.h
src/plugindata.h
src/plugins.c
src/pluginutils.c
src/pluginutils.h
Modified: plugins/geanyfunctions.h
2 files changed, 2 insertions(+), 0 deletions(-)
===================================================================
@@ -32,6 +32,8 @@
geany_functions->p_plugin->plugin_timeout_add_seconds
#define plugin_idle_add \
geany_functions->p_plugin->plugin_idle_add
+#define plugin_builder_connect_signals \
+ geany_functions->p_plugin->plugin_builder_connect_signals
#define document_new_file \
geany_functions->p_document->document_new_file
#define document_get_current \
Modified: src/plugindata.h
3 files changed, 2 insertions(+), 1 deletions(-)
===================================================================
@@ -55,7 +55,7 @@
* @warning You should not test for values below 200 as previously
* @c GEANY_API_VERSION was defined as an enum value, not a macro.
*/
-#define GEANY_API_VERSION 216
+#define GEANY_API_VERSION 217
/* hack to have a different ABI when built with GTK3 because loading GTK2-linked plugins
* with GTK3-linked Geany leads to crash */
@@ -666,6 +666,7 @@
guint (*plugin_timeout_add_seconds) (GeanyPlugin *plugin, guint interval,
GSourceFunc function, gpointer data);
guint (*plugin_idle_add) (GeanyPlugin *plugin, GSourceFunc function, gpointer data);
+ void (*plugin_builder_connect_signals) (GeanyPlugin *plugin, GtkBuilder *builder, gpointer user_data);
}
PluginFuncs;
Modified: src/plugins.c
3 files changed, 2 insertions(+), 1 deletions(-)
===================================================================
@@ -86,7 +86,8 @@
&plugin_show_configure,
&plugin_timeout_add,
&plugin_timeout_add_seconds,
- &plugin_idle_add
+ &plugin_idle_add,
+ &plugin_builder_connect_signals
};
static DocumentFuncs doc_funcs = {
Modified: src/pluginutils.c
82 files changed, 82 insertions(+), 0 deletions(-)
===================================================================
@@ -395,4 +395,86 @@ void plugin_show_configure(GeanyPlugin *plugin)
}
+struct BuilderConnectData
+{
+ gpointer user_data;
+ GeanyPlugin *plugin;
+};
+
+
+static void connect_plugin_signals(GtkBuilder *builder, GObject *object,
+ const gchar *signal_name, const gchar *handler_name,
+ GObject *connect_object, GConnectFlags flags, gpointer user_data)
+{
+ gpointer symbol = NULL;
+ struct BuilderConnectData *data = user_data;
+
+ if (!g_module_symbol(data->plugin->priv->module, handler_name, &symbol))
+ {
+ g_warning("Failed to locate signal handler for '%s': %s",
+ signal_name, g_module_error());
+ return;
+ }
+
+ plugin_signal_connect(data->plugin, object, signal_name, FALSE,
+ G_CALLBACK(symbol) /*ub?*/, data->user_data);
+}
+
+
+/**
+ * Allows auto-connecting Glade/GtkBuilder signals in plugins.
+ *
+ * When a plugin uses GtkBuilder to load some UI from file/string,
+ * the gtk_builder_connect_signals() function is unable to automatically
+ * connect to the plugin's signal handlers. A plugin could itself use
+ * the gtk_builder_connect_signals_full() function to automatically
+ * connect to the signal handler functions by loading it's GModule
+ * and retrieving pointers to the handler functions, but rather than
+ * each plugin having to do that, this function handles it automatically.
+ *
+ * @code
+ * ...
+ * GeanyPlugin *geany_plugin;
+ *
+ * G_MODULE_EXPORT void
+ * myplugin_button_clicked(GtkButton *button, gpointer user_data)
+ * {
+ * g_print("Button pressed\n");
+ * }
+ *
+ * void plugin_init(GeanyData *data)
+ * {
+ * GtkBuilder *builder = gtk_builder_new();
+ * gtk_builder_add_from_file(builder, "gui.glade", NULL);
+ * plugin_builder_connect_signals(geany_plugin, builder, NULL);
+ * ...
+ * }
+ * @endcode
+ *
+ * @note It's important that you prefix your callback handlers with
+ * a plugin-specific prefix to avoid clashing with other plugins since
+ * the function symbols will be exported process-wide.
+ *
+ * @param plugin Must be @ref geany_plugin.
+ * @param builder The GtkBuilder to connect signals with.
+ * @param user_data User data to pass to the connected signal handlers.
+ *
+ * @since 1.24, plugin API 217.
+ */
+void plugin_builder_connect_signals(GeanyPlugin *plugin,
+ GtkBuilder *builder, gpointer user_data)
+{
+ struct BuilderConnectData data = { NULL };
+
+ g_return_if_fail(plugin != NULL && plugin->priv != NULL);
+ g_return_if_fail(plugin->priv->module != NULL);
+ g_return_if_fail(GTK_IS_BUILDER(builder));
+
+ data.user_data = user_data;
+ data.plugin = plugin;
+
+ gtk_builder_connect_signals_full(builder, connect_plugin_signals, &data);
+}
+
+
#endif
Modified: src/pluginutils.h
3 files changed, 3 insertions(+), 0 deletions(-)
===================================================================
@@ -53,5 +53,8 @@ struct GeanyKeyGroup *plugin_set_key_group(struct GeanyPlugin *plugin,
void plugin_show_configure(struct GeanyPlugin *plugin);
+void plugin_builder_connect_signals(struct GeanyPlugin *plugin,
+ GtkBuilder *builder, gpointer user_data);
+
#endif /* HAVE_PLUGINS */
#endif /* GEANY_PLUGINUTILS_H */
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
More information about the Commits
mailing list