Revision: 1749 http://geany.svn.sourceforge.net/geany/?rev=1749&view=rev Author: ntrel Date: 2007-07-27 03:37:22 -0700 (Fri, 27 Jul 2007)
Log Message: ----------- Add GeanyData* geany_data symbol for plugins so they don't have to keep a copy of the init() argument. Rename PluginData GeanyData (but use a typedef for backward compatibility). Update plugins to use newer API symbols.
Modified Paths: -------------- trunk/ChangeLog trunk/plugins/classbuilder.c trunk/plugins/demoplugin.c trunk/plugins/htmlchars.c trunk/src/plugindata.h trunk/src/plugins.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-07-26 12:12:54 UTC (rev 1748) +++ trunk/ChangeLog 2007-07-27 10:37:22 UTC (rev 1749) @@ -1,3 +1,14 @@ +2007-07-27 Nick Treleaven nick.treleaven@btinternet.com + + * plugins/demoplugin.c, plugins/htmlchars.c, plugins/classbuilder.c, + src/plugindata.h, src/plugins.c: + Add GeanyData* geany_data symbol for plugins so they don't have to + keep a copy of the init() argument. + Rename PluginData GeanyData (but use a typedef for backward + compatibility). + Update plugins to use newer API symbols. + + 2007-07-26 Nick Treleaven nick.treleaven@btinternet.com
* src/highlighting.c:
Modified: trunk/plugins/classbuilder.c =================================================================== --- trunk/plugins/classbuilder.c 2007-07-26 12:12:54 UTC (rev 1748) +++ trunk/plugins/classbuilder.c 2007-07-27 10:37:22 UTC (rev 1749) @@ -32,26 +32,20 @@ #include "document.h"
-static PluginData *plugin_data; +PluginFields *plugin_fields; +GeanyData *geany_data;
-#define doc_array plugin_data->doc_array +#define doc_array geany_data->doc_array // can't use document as a macro because it's currently a typename -#define documents plugin_data->document -#define scintilla plugin_data->sci -#define templates plugin_data->templates -#define utils plugin_data->utils -#define ui plugin_data->ui +#define documents geany_data->document +#define scintilla geany_data->sci +#define templates geany_data->templates +#define utils geany_data->utils +#define ui geany_data->ui
-static struct -{ - GtkWidget *menu_item; -} -local_data; +VERSION_CHECK(7)
- -VERSION_CHECK(4) - PLUGIN_INFO(_("Class Builder"), _("Creates source files for new class types."))
@@ -369,7 +363,7 @@ cc_dlg->class_type = type;
cc_dlg->dialog = gtk_dialog_new_with_buttons(_("Create Class"), - GTK_WINDOW(plugin_data->app->window), + GTK_WINDOW(geany_data->app->window), GTK_DIALOG_MODAL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, @@ -783,7 +777,7 @@ }
-void init(PluginData *data) +void init(GeanyData *data) { GtkWidget *menu_create_class1; GtkWidget *image1861; @@ -791,8 +785,6 @@ GtkWidget *menu_create_cpp_class; GtkWidget *menu_create_gtk_class;
- plugin_data = data; - menu_create_class1 = gtk_image_menu_item_new_with_mnemonic (_("Create Cla_ss")); gtk_container_add (GTK_CONTAINER (data->tools_menu), menu_create_class1);
@@ -817,11 +809,11 @@
gtk_widget_show_all(menu_create_class1);
- local_data.menu_item = menu_create_class1; + plugin_fields->menu_item = menu_create_class1; }
void cleanup() { - gtk_widget_destroy(local_data.menu_item); + gtk_widget_destroy(plugin_fields->menu_item); }
Modified: trunk/plugins/demoplugin.c =================================================================== --- trunk/plugins/demoplugin.c 2007-07-26 12:12:54 UTC (rev 1748) +++ trunk/plugins/demoplugin.c 2007-07-27 10:37:22 UTC (rev 1749) @@ -29,18 +29,13 @@ #include "plugindata.h"
-static PluginData *plugin_data; +PluginFields *plugin_fields; +GeanyData *geany_data;
-static struct -{ - GtkWidget *menu_item; -} -local_data;
- /* Check that Geany supports plugin API version 2 or later, and check * for binary compatibility. */ -VERSION_CHECK(2) +VERSION_CHECK(7)
/* All plugins must set name and description */ PLUGIN_INFO(_("Demo"), _("Example plugin.")) @@ -53,7 +48,7 @@ GtkWidget *dialog;
dialog = gtk_message_dialog_new( - GTK_WINDOW(plugin_data->app->window), + GTK_WINDOW(geany_data->app->window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, @@ -67,20 +62,18 @@
/* Called by Geany to initialize the plugin */ -void init(PluginData *data) +void init(GeanyData *data) { GtkWidget *demo_item;
- plugin_data = data; // keep a pointer to the main application fields & functions - // Add an item to the Tools menu demo_item = gtk_menu_item_new_with_mnemonic(_("_Demo Plugin")); gtk_widget_show(demo_item); - gtk_container_add(GTK_CONTAINER(plugin_data->tools_menu), demo_item); + gtk_container_add(GTK_CONTAINER(geany_data->tools_menu), demo_item); g_signal_connect(G_OBJECT(demo_item), "activate", G_CALLBACK(item_activate), NULL);
// keep a pointer to the menu item, so we can remove it when the plugin is unloaded - local_data.menu_item = demo_item; + plugin_fields->menu_item = demo_item; }
@@ -89,5 +82,5 @@ void cleanup() { // remove the menu item added in init() - gtk_widget_destroy(local_data.menu_item); + gtk_widget_destroy(plugin_fields->menu_item); }
Modified: trunk/plugins/htmlchars.c =================================================================== --- trunk/plugins/htmlchars.c 2007-07-26 12:12:54 UTC (rev 1748) +++ trunk/plugins/htmlchars.c 2007-07-27 10:37:22 UTC (rev 1749) @@ -30,18 +30,17 @@ #include "document.h"
-PluginFields *plugin_fields; +PluginFields *plugin_fields; +GeanyData *geany_data;
-static PluginData *plugin_data; - -#define doc_array plugin_data->doc_array +#define doc_array geany_data->doc_array // can't use document as a macro because it's currently a typename -#define documents plugin_data->document -#define scintilla plugin_data->sci -#define ui plugin_data->ui +#define documents geany_data->document +#define scintilla geany_data->sci +#define ui geany_data->ui
-VERSION_CHECK(5) +VERSION_CHECK(7)
PLUGIN_INFO(_("HTML Characters"), _("Inserts HTML character entities like '&'."))
@@ -76,7 +75,7 @@ GtkWidget *swin, *vbox, *label;
sc_dialog = gtk_dialog_new_with_buttons( - _("Special Characters"), GTK_WINDOW(plugin_data->app->window), + _("Special Characters"), GTK_WINDOW(geany_data->app->window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, _("_Insert"), GTK_RESPONSE_OK, NULL); vbox = ui->dialog_vbox_new(GTK_DIALOG(sc_dialog)); @@ -509,16 +508,14 @@
/* Called by Geany to initialize the plugin */ -void init(PluginData *data) +void init(GeanyData *data) { GtkWidget *demo_item;
- plugin_data = data; // keep a pointer to the main application fields & functions - // Add an item to the Tools menu demo_item = gtk_menu_item_new_with_mnemonic(_("_Insert Special HTML Characters")); gtk_widget_show(demo_item); - gtk_container_add(GTK_CONTAINER(plugin_data->tools_menu), demo_item); + gtk_container_add(GTK_CONTAINER(geany_data->tools_menu), demo_item); g_signal_connect(G_OBJECT(demo_item), "activate", G_CALLBACK(item_activate), NULL);
// disable menu_item when there are no documents open
Modified: trunk/src/plugindata.h =================================================================== --- trunk/src/plugindata.h 2007-07-26 12:12:54 UTC (rev 1748) +++ trunk/src/plugindata.h 2007-07-27 10:37:22 UTC (rev 1749) @@ -34,11 +34,14 @@ * PluginInfo* info() * Use PLUGIN_INFO() macro to define it. Required by Geany. * + * GeanyData* geany_data + * Geany owned fields and functions. + * * PluginFields* plugin_fields * Plugin owned fields, including flags. * - * void init(PluginData *data) - * Called after loading the plugin. + * void init(GeanyData *data) + * Called after loading the plugin. data is the same as geany_data. * * void cleanup() * Called before unloading the plugin. Required for normal plugins - it should undo @@ -48,7 +51,7 @@
/* The API version should be incremented whenever any plugin data types below are * modified. */ -static const gint api_version = 6; +static const gint api_version = 7;
/* The ABI version should be incremented whenever existing fields in the plugin * data types below have to be changed or reordered. It should stay the same if fields @@ -95,7 +98,9 @@ } PluginFlags;
-/* Fields set and owned by the plugin */ +/* Fields set and owned by the plugin. + * Note: Remember to increment api_version (and abi_version if necessary) when + * making changes. */ typedef struct PluginFields { PluginFlags flags; @@ -111,10 +116,10 @@ typedef struct UIUtilsFuncs UIUtilsFuncs;
/* These are fields and functions owned by Geany. - * Fields will be appended when needed by plugin authors. + * Fields and functions will be appended when needed by plugin authors. * Note: Remember to increment api_version (and abi_version if necessary) when * making changes. */ -typedef struct PluginData +typedef struct GeanyData { MyApp *app; // Geany application data fields GtkWidget *tools_menu; // Almost all plugins should add menu items to the Tools menu only @@ -126,11 +131,13 @@ UtilsFuncs *utils; UIUtilsFuncs *ui; } -PluginData; +GeanyData;
+typedef GeanyData PluginData; // for compatibility with API < 7
+ /* For more info about these functions, see the main source code. - * E.g. for PluginData::document->new_file(), see document_new_file() in document.[hc]. */ + * E.g. for GeanyData::document->new_file(), see document_new_file() in document.[hc]. */
struct filetype;
Modified: trunk/src/plugins.c =================================================================== --- trunk/src/plugins.c 2007-07-26 12:12:54 UTC (rev 1748) +++ trunk/src/plugins.c 2007-07-27 10:37:22 UTC (rev 1749) @@ -45,7 +45,7 @@ PluginFields fields;
PluginInfo* (*info) (); /* Returns plugin name, description */ - void (*init) (PluginData *data); /* Called when the plugin is enabled */ + void (*init) (GeanyData *data); /* Called when the plugin is enabled */ void (*cleanup) (); /* Called when the plugin is disabled or when Geany exits */ } Plugin; @@ -85,7 +85,8 @@ &ui_frame_new_with_alignment };
-static PluginData geany_data = { + +static GeanyData geany_data = { NULL, NULL, NULL, @@ -162,6 +163,7 @@ GModule *module; PluginInfo* (*info)(); PluginFields **plugin_fields; + GeanyData **p_geany_data;
g_return_val_if_fail(fname, NULL); g_return_val_if_fail(g_module_supported(), NULL); @@ -211,6 +213,9 @@ plugin->filename = g_strdup(fname); plugin->module = module;
+ g_module_symbol(module, "geany_data", (void *) &p_geany_data); + if (p_geany_data) + *p_geany_data = &geany_data; g_module_symbol(module, "plugin_fields", (void *) &plugin_fields); if (plugin_fields) *plugin_fields = &plugin->fields;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.