Revision: 3672 http://geany.svn.sourceforge.net/geany/?rev=3672&view=rev Author: ntrel Date: 2009-03-31 14:32:03 +0000 (Tue, 31 Mar 2009)
Log Message: ----------- Fix sorting filetype template menu items. Add foreach_slist() macro. Make sorted_filetypes list public, and include None filetype first. Rename filetypes_foreach_sorted() to filetypes_foreach_named() to show it doesn't include the None filetype.
Modified Paths: -------------- branches/reorder-filetypes/ChangeLog branches/reorder-filetypes/src/dialogs.c branches/reorder-filetypes/src/filetypes.c branches/reorder-filetypes/src/filetypes.h branches/reorder-filetypes/src/templates.c branches/reorder-filetypes/src/utils.h
Modified: branches/reorder-filetypes/ChangeLog =================================================================== --- branches/reorder-filetypes/ChangeLog 2009-03-30 18:46:37 UTC (rev 3671) +++ branches/reorder-filetypes/ChangeLog 2009-03-31 14:32:03 UTC (rev 3672) @@ -1,3 +1,14 @@ +2009-03-31 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com> + + * src/templates.c, src/utils.h, src/dialogs.c, src/filetypes.c, + src/filetypes.h: + Fix sorting filetype template menu items. + Add foreach_slist() macro. + Make sorted_filetypes list public, and include None filetype first. + Rename filetypes_foreach_sorted() to filetypes_foreach_named() to + show it doesn't include the None filetype. + + 2009-03-27 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* src/dialogs.c, src/filetypes.c, src/filetypes.h:
Modified: branches/reorder-filetypes/src/dialogs.c =================================================================== --- branches/reorder-filetypes/src/dialogs.c 2009-03-30 18:46:37 UTC (rev 3671) +++ branches/reorder-filetypes/src/dialogs.c 2009-03-31 14:32:03 UTC (rev 3672) @@ -237,7 +237,7 @@ /* now create meta filter "All Source" */ gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(ui_widgets.open_filesel), filetypes_create_file_filter_all_source()); - filetypes_foreach_sorted(add_opendlg_filetype, filetype_combo); + filetypes_foreach_named(add_opendlg_filetype, filetype_combo); gtk_combo_box_set_active(GTK_COMBO_BOX(filetype_combo), 0);
/* fill encoding combo box */
Modified: branches/reorder-filetypes/src/filetypes.c =================================================================== --- branches/reorder-filetypes/src/filetypes.c 2009-03-30 18:46:37 UTC (rev 3671) +++ branches/reorder-filetypes/src/filetypes.c 2009-03-31 14:32:03 UTC (rev 3672) @@ -67,11 +67,11 @@
GPtrArray *filetypes_array = NULL; /* Dynamic array of filetype pointers */
-GHashTable *filetypes_hash = NULL; /* Hash of filetype pointers based on name keys */ +static 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 +/* List of filetype pointers sorted by name, with ft[GEANY_FILETYPES_NONE] first, as this * is usually treated specially. */ -static GSList *sorted_filetypes = NULL; +GSList *sorted_filetypes = NULL;
static void create_radio_menu_item(GtkWidget *menu, GeanyFiletype *ftype); @@ -596,6 +596,11 @@ { const GeanyFiletype *ft1 = pft1, *ft2 = pft2;
+ if (ft1->id == GEANY_FILETYPES_NONE) + return -1; + if (ft2->id == GEANY_FILETYPES_NONE) + return 1; + return utils_str_casecmp(ft1->title, ft2->title); }
@@ -611,8 +616,7 @@ g_ptr_array_add(filetypes_array, ft); g_hash_table_insert(filetypes_hash, ft->name, ft);
- if (ft->id != GEANY_FILETYPES_NONE) - sorted_filetypes = g_slist_insert_sorted(sorted_filetypes, ft, cmp_filetype); + sorted_filetypes = g_slist_insert_sorted(sorted_filetypes, ft, cmp_filetype); }
@@ -661,7 +665,7 @@ }
-static GtkWidget *group_menus[GEANY_FILETYPE_GROUP_COUNT]; +static GtkWidget *group_menus[GEANY_FILETYPE_GROUP_COUNT] = {NULL};
static void create_sub_menu(GtkWidget *parent, gsize group_id, const gchar *title) { @@ -694,7 +698,7 @@ create_sub_menu(filetype_menu, GEANY_FILETYPE_GROUP_MISC, _("M_iscellaneous Languages"));
/* Append all filetypes to the filetype menu */ - filetypes_foreach_sorted(add_ft_menu_item, NULL); + filetypes_foreach_named(add_ft_menu_item, NULL); create_radio_menu_item(filetype_menu, filetypes[GEANY_FILETYPES_NONE]); }
@@ -1476,11 +1480,15 @@
/* Does not include ft[GEANY_FILETYPES_NONE], as this is usually treated specially. */ -void filetypes_foreach_sorted(GFunc callback, gpointer user_data) +void filetypes_foreach_named(GFunc callback, gpointer user_data) { - GSList *item; + GSList *node; + GeanyFiletype *ft;
- for (item = sorted_filetypes; item != NULL; item = g_slist_next(item)) - callback(item->data, user_data); + foreach_slist(ft, node, sorted_filetypes) + { + if (ft->id != GEANY_FILETYPES_NONE) + callback(ft, user_data); + } }
Modified: branches/reorder-filetypes/src/filetypes.h =================================================================== --- branches/reorder-filetypes/src/filetypes.h 2009-03-30 18:46:37 UTC (rev 3671) +++ branches/reorder-filetypes/src/filetypes.h 2009-03-31 14:32:03 UTC (rev 3672) @@ -144,10 +144,12 @@ * Example: filetypes[GEANY_FILETYPES_C]->name = ...; */ #define filetypes ((GeanyFiletype **)filetypes_array->pdata)
+extern GSList *sorted_filetypes;
+ GeanyFiletype *filetypes_lookup_by_name(const gchar *name);
-void filetypes_foreach_sorted(GFunc callback, gpointer user_data); +void filetypes_foreach_named(GFunc callback, gpointer user_data);
GeanyFiletype *filetypes_find(GCompareFunc predicate, gpointer user_data);
Modified: branches/reorder-filetypes/src/templates.c =================================================================== --- branches/reorder-filetypes/src/templates.c 2009-03-30 18:46:37 UTC (rev 3671) +++ branches/reorder-filetypes/src/templates.c 2009-03-31 14:32:03 UTC (rev 3672) @@ -362,12 +362,13 @@ /* template items for the new file menu */ static void create_new_menu_items(void) { - filetype_id ft_id; + GeanyFiletype *ft; + GSList *node;
- for (ft_id = 0; ft_id < GEANY_MAX_BUILT_IN_FILETYPES; ft_id++) + foreach_slist(ft, node, sorted_filetypes) { + filetype_id ft_id = ft->id; GtkWidget *tmp_menu, *tmp_button; - GeanyFiletype *ft = filetypes[ft_id]; const gchar *label = ft->title;
if (ft_templates[ft_id] == NULL)
Modified: branches/reorder-filetypes/src/utils.h =================================================================== --- branches/reorder-filetypes/src/utils.h 2009-03-30 18:46:37 UTC (rev 3671) +++ branches/reorder-filetypes/src/utils.h 2009-03-31 14:32:03 UTC (rev 3672) @@ -57,7 +57,12 @@ for (ptr = ptr_array->pdata, item = *ptr; \ ptr < &ptr_array->pdata[ptr_array->len]; ++ptr, item = *ptr)
+/* @param node should be a (GSList*), needed for implementation. */ +#define foreach_slist(data_ptr, node, list) \ + for (node = list, data_ptr = node ? node->data : NULL; node != NULL; \ + node = g_slist_next(node), data_ptr = node ? node->data : NULL)
+ void utils_open_browser(const gchar *uri);
gint utils_get_line_endings(const gchar* buffer, glong size);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.