Kaydet (Commit) 58c8144a authored tarafından Thomas Martitz's avatar Thomas Martitz

plugins: Pass pdata to PluginCallback function by default

If the plugin did not set its own user_data we set it to whatever it set
with geany_plugin_register_full() or geany_plugin_set_data().
This is particularly convinient because PluginCallback is usually statically
allocated, at which point dynamically allocated plugin data doesn't exists yet.
üst 43c58e0f
......@@ -43,7 +43,11 @@ static gchar *welcome_text = NULL;
static gboolean on_editor_notify(GObject *object, GeanyEditor *editor,
SCNotification *nt, gpointer data)
{
GeanyData *geany_data = data;
/* data == GeanyPlugin because the data member of PluginCallback was set to NULL
* and this plugin has called geany_plugin_set_data() with the GeanyPlugin pointer as
* data */
GeanyPlugin *plugin = data;
GeanyData *geany_data = plugin->geany_data;
/* For detailed documentation about the SCNotification struct, please see
* http://www.scintilla.org/ScintillaDoc.html#Notifications. */
......@@ -137,8 +141,14 @@ static gboolean demo_init(GeanyPlugin *plugin, gpointer data)
welcome_text = g_strdup(_("Hello World!"));
demo_callbacks[0].user_data = geany_data;
/* This might seem strange but is a method to get the GeanyPlugin pointer passed to
* on_editor_notify(). PluginCallback functions get the same data that was set via
* GEANY_PLUING_REGISTER_FULL() or geany_plugin_set_data() by default (unless the data pointer
* was set to non-NULL at compile time).
* This is really only done for demoing PluginCallback. Actual plugins will use real custom
* data and perhaps embed the GeanyPlugin or GeanyData pointer their if they also use
* PluginCallback. */
geany_plugin_set_data(plugin, plugin, NULL);
return TRUE;
}
......
......@@ -185,7 +185,9 @@ typedef struct PluginCallback
GCallback callback;
/** Set to TRUE to connect your handler with g_signal_connect_after(). */
gboolean after;
/** The user data passed to the signal handler. */
/** The user data passed to the signal handler. If set to NULL then the signal
* handler will receive the data set with geany_plugin_register_full() or
* geany_plugin_set_data() */
gpointer user_data;
}
PluginCallback;
......
......@@ -206,8 +206,9 @@ static void add_callbacks(Plugin *plugin, PluginCallback *callbacks)
{
cb = &callbacks[i];
/* Pass the callback data as default user_data if none was set by the plugin itself */
plugin_signal_connect(&plugin->public, NULL, cb->signal_name, cb->after,
cb->callback, cb->user_data);
cb->callback, cb->user_data ? cb->user_data : plugin->cb_data);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment