From bc9639e800185405e236f9a7ba09eaf6d73b79f2 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Fri, 27 Mar 2009 14:14:46 +0000 Subject: [PATCH] Move sorted_filetypes list insertion to filetype_add(). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/reorder-filetypes@3659 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- src/filetypes.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/filetypes.c b/src/filetypes.c index 39ee77f6..3e3fc8a2 100644 --- a/src/filetypes.c +++ b/src/filetypes.c @@ -69,6 +69,10 @@ GPtrArray *filetypes_array = NULL; /* Dynamic array of filetype pointers */ GHashTable *filetypes_hash = NULL; /* Hash of filetype pointers based on name keys */ +/* List of filetype pointers sorted by name, without ft[GEANY_FILETYPES_NONE], as this + * is usually treated specially. */ +static GSList *sorted_filetypes = NULL; + static void create_radio_menu_item(GtkWidget *menu, const gchar *label, GeanyFiletype *ftype); @@ -588,7 +592,15 @@ static GeanyFiletype *filetype_new(void) } -/* Add a filetype pointer to the list of available filetypes, +static gint cmp_filetype(gconstpointer pft1, gconstpointer pft2) +{ + const GeanyFiletype *ft1 = pft1, *ft2 = pft2; + + return utils_str_casecmp(ft1->name, ft2->name); +} + + +/* Add a filetype pointer to the lists of available filetypes, * and set the filetype::id field. */ static void filetype_add(GeanyFiletype *ft) { @@ -598,6 +610,8 @@ static void filetype_add(GeanyFiletype *ft) ft->id = filetypes_array->len; /* len will be the index for filetype_array */ g_ptr_array_add(filetypes_array, ft); g_hash_table_insert(filetypes_hash, ft->name, ft); + + sorted_filetypes = g_slist_insert_sorted(sorted_filetypes, ft, cmp_filetype); } @@ -1478,30 +1492,11 @@ GeanyFiletype *filetypes_index(gint idx) } -static gint cmp_filetype(gconstpointer pft1, gconstpointer pft2) -{ - const GeanyFiletype *ft1 = pft1, *ft2 = pft2; - - return utils_str_casecmp(ft1->name, ft2->name); -} - - -/* TODO: insert when adding filetypes properly */ -static GSList *sorted_filetypes = NULL; - -/* Does not include GEANY_FILETYPES_NONE, as this is usually treated specially. */ +/* Does not include ft[GEANY_FILETYPES_NONE], as this is usually treated specially. */ void filetypes_foreach_sorted(GFunc callback, gpointer user_data) { - guint i; GSList *item; - if (sorted_filetypes == NULL) - { - for (i = 1; i < filetypes_array->len; i++) - sorted_filetypes = g_slist_insert_sorted(sorted_filetypes, filetypes[i], - cmp_filetype); - } - for (item = sorted_filetypes; item != NULL; item = g_slist_next(item)) callback(item->data, user_data); }