Revision: 2547 http://geany.svn.sourceforge.net/geany/?rev=2547&view=rev Author: ntrel Date: 2008-05-01 10:25:18 -0700 (Thu, 01 May 2008)
Log Message: ----------- Add filetypes_array to GeanyData for plugins to access a dynamic array of filetype pointers.
Modified Paths: -------------- branches/custom-filetypes/ChangeLog branches/custom-filetypes/src/filetypes.c branches/custom-filetypes/src/filetypes.h branches/custom-filetypes/src/plugindata.h branches/custom-filetypes/src/plugins.c
Modified: branches/custom-filetypes/ChangeLog =================================================================== --- branches/custom-filetypes/ChangeLog 2008-05-01 17:01:32 UTC (rev 2546) +++ branches/custom-filetypes/ChangeLog 2008-05-01 17:25:18 UTC (rev 2547) @@ -14,6 +14,9 @@ Remove filetypes_find(), which will be replaced with a dynamic array of filetype pointers (more flexible and backwards compatible with existing code). + * src/plugindata.h, src/filetypes.c, src/filetypes.h, src/plugins.c: + Add filetypes_array to GeanyData for plugins to access a dynamic + array of filetype pointers.
2008-04-29 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
Modified: branches/custom-filetypes/src/filetypes.c =================================================================== --- branches/custom-filetypes/src/filetypes.c 2008-05-01 17:01:32 UTC (rev 2546) +++ branches/custom-filetypes/src/filetypes.c 2008-05-01 17:25:18 UTC (rev 2547) @@ -40,10 +40,10 @@ #include "ui_utils.h"
+GPtrArray *filetypes_array = NULL; /* Dynamic array of filetype pointers */ + GHashTable *filetypes_hash = NULL; /* Hash of filetype pointers based on name keys */
-/* built-in filetypes only */ -filetype *built_in_filetypes[GEANY_MAX_BUILT_IN_FILETYPES] = {NULL};
static GtkWidget *radio_items[GEANY_MAX_FILE_TYPES];
@@ -420,13 +420,15 @@ }
-/* Create the filetype array and fill it with the known filetypes. */ +/* Create the filetypes array and fill it with the known filetypes. */ void filetypes_init_types() { filetype_id ft_id;
+ g_return_if_fail(filetypes_array == NULL); g_return_if_fail(filetypes_hash == NULL);
+ filetypes_array = g_ptr_array_sized_new(GEANY_MAX_BUILT_IN_FILETYPES); filetypes_hash = g_hash_table_new(g_str_hash, g_str_equal);
/* Create built-in filetypes */ @@ -436,7 +438,7 @@ } init_builtin_filetypes();
- /* Add built-in filetypes to the hash */ + /* Add built-in filetypes to the hash now the name fields are set */ for (ft_id = 0; ft_id < GEANY_MAX_BUILT_IN_FILETYPES; ft_id++) { filetypes_add(filetypes[ft_id]); @@ -725,10 +727,9 @@ }
-static void free_filetype(G_GNUC_UNUSED gpointer key, gpointer value, - G_GNUC_UNUSED gpointer user_data) +static void free_filetype(gpointer data, G_GNUC_UNUSED gpointer user_data) { - filetype *ft = value; + filetype *ft = data;
g_return_if_fail(ft != NULL);
@@ -753,9 +754,11 @@ /* frees the array and all related pointers */ void filetypes_free_types() { + g_return_if_fail(filetypes_array != NULL); g_return_if_fail(filetypes_hash != NULL);
- g_hash_table_foreach(filetypes_hash, free_filetype, NULL); + g_ptr_array_foreach(filetypes_array, free_filetype, NULL); + g_ptr_array_free(filetypes_array, TRUE); g_hash_table_destroy(filetypes_hash); }
@@ -1012,6 +1015,7 @@ g_return_if_fail(ft); g_return_if_fail(ft->name);
+ g_ptr_array_add(filetypes_array, ft); g_hash_table_insert(filetypes_hash, ft->name, ft); }
@@ -1021,6 +1025,8 @@ { g_return_if_fail(ft);
+ g_ptr_array_remove(filetypes_array, ft); + if (!g_hash_table_remove(filetypes_hash, ft)) g_warning("Could not remove filetype %p!", ft); }
Modified: branches/custom-filetypes/src/filetypes.h =================================================================== --- branches/custom-filetypes/src/filetypes.h 2008-05-01 17:01:32 UTC (rev 2546) +++ branches/custom-filetypes/src/filetypes.h 2008-05-01 17:25:18 UTC (rev 2547) @@ -121,10 +121,13 @@ struct build_actions *actions; };
-#define filetypes built_in_filetypes -extern filetype *built_in_filetypes[GEANY_MAX_BUILT_IN_FILETYPES]; +extern GPtrArray *filetypes_array;
+/* Wrap filetypes_array so it can be used with C array syntax. + * Example: filetypes[GEANY_FILETYPES_C]->name = ...; */ +#define filetypes ((filetype **)filetypes_array->pdata)
+ void filetypes_add(filetype *ft);
void filetypes_remove(filetype *ft);
Modified: branches/custom-filetypes/src/plugindata.h =================================================================== --- branches/custom-filetypes/src/plugindata.h 2008-05-01 17:01:32 UTC (rev 2546) +++ branches/custom-filetypes/src/plugindata.h 2008-05-01 17:25:18 UTC (rev 2547) @@ -30,17 +30,17 @@ **/
-#ifndef PLUGIN_H -#define PLUGIN_H +#ifndef PLUGINDATA_H +#define PLUGINDATA_H
/* The API version should be incremented whenever any plugin data types below are * modified or appended to. */ -static const gint api_version = 55; +static const gint api_version = 56;
/* 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 * are only appended, as this doesn't affect existing fields. */ -static const gint abi_version = 26; +static const gint abi_version = 27;
/** Check the plugin can be loaded by Geany. * This performs runtime checks that try to ensure: @@ -156,6 +156,7 @@ GeanyApp *app; /**< Geany application data fields */ GtkWidget *tools_menu; /**< Most plugins should add menu items to the Tools menu only */ GArray *doc_array; /**< Dynamic array of document structs */ + GPtrArray *filetypes_array; /**< Dynamic array of filetype pointers */ struct GeanyPrefs *prefs; /* Note: this will be split up in future versions */ struct EditorPrefs *editor_prefs; /**< Editor settings */ struct BuildInfo *build_info; /**< Current build information */
Modified: branches/custom-filetypes/src/plugins.c =================================================================== --- branches/custom-filetypes/src/plugins.c 2008-05-01 17:01:32 UTC (rev 2546) +++ branches/custom-filetypes/src/plugins.c 2008-05-01 17:25:18 UTC (rev 2547) @@ -241,6 +241,7 @@ NULL, NULL, NULL, + NULL,
&doc_funcs, &sci_funcs, @@ -266,6 +267,7 @@ geany_data.app = app; geany_data.tools_menu = lookup_widget(app->window, "tools1_menu"); geany_data.doc_array = doc_array; + geany_data.filetypes_array = filetypes_array; geany_data.prefs = &prefs; geany_data.editor_prefs = &editor_prefs; geany_data.build_info = &build_info;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.