Revision: 3673 http://geany.svn.sourceforge.net/geany/?rev=3673&view=rev Author: ntrel Date: 2009-03-31 15:07:27 +0000 (Tue, 31 Mar 2009)
Log Message: ----------- Use g_slist_nth_data() with sorted_filetypes list instead of filetypes_find() as it is neater.
Modified Paths: -------------- branches/reorder-filetypes/ChangeLog branches/reorder-filetypes/src/dialogs.c branches/reorder-filetypes/src/filetypes.c
Modified: branches/reorder-filetypes/ChangeLog =================================================================== --- branches/reorder-filetypes/ChangeLog 2009-03-31 14:32:03 UTC (rev 3672) +++ branches/reorder-filetypes/ChangeLog 2009-03-31 15:07:27 UTC (rev 3673) @@ -7,6 +7,9 @@ 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. + * src/dialogs.c, src/filetypes.c: + Use g_slist_nth_data() with sorted_filetypes list instead of + filetypes_find() as it is neater.
2009-03-27 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
Modified: branches/reorder-filetypes/src/dialogs.c =================================================================== --- branches/reorder-filetypes/src/dialogs.c 2009-03-31 14:32:03 UTC (rev 3672) +++ branches/reorder-filetypes/src/dialogs.c 2009-03-31 15:07:27 UTC (rev 3673) @@ -71,14 +71,6 @@
#if ! GEANY_USE_WIN32_DIALOG -static gboolean cmp_ft_title(gconstpointer pft, gconstpointer user_data) -{ - const GeanyFiletype *ft = pft; - - return (strcmp(ft->title, user_data) == 0); -} - - static void on_file_open_dialog_response (GtkDialog *dialog, gint response, @@ -89,8 +81,8 @@ if (response == GTK_RESPONSE_ACCEPT || response == GEANY_RESPONSE_VIEW) { GSList *filelist; - GtkComboBox *filecombo = GTK_COMBO_BOX( - ui_lookup_widget(GTK_WIDGET(dialog), "filetype_combo")); + gint filetype_idx = gtk_combo_box_get_active(GTK_COMBO_BOX( + ui_lookup_widget(GTK_WIDGET(dialog), "filetype_combo"))); gint encoding_idx = gtk_combo_box_get_active(GTK_COMBO_BOX( ui_lookup_widget(GTK_WIDGET(dialog), "encoding_combo"))); GeanyFiletype *ft = NULL; @@ -98,12 +90,8 @@ gboolean ro = (response == GEANY_RESPONSE_VIEW); /* View clicked */
/* ignore detect from file item */ - if (gtk_combo_box_get_active(filecombo) > 0) - { - gchar *title = gtk_combo_box_get_active_text(filecombo); - ft = filetypes_find(cmp_ft_title, title); - g_free(title); - } + if (filetype_idx > 0 && filetype_idx < GEANY_MAX_BUILT_IN_FILETYPES) + ft = g_slist_nth_data(sorted_filetypes, filetype_idx); if (encoding_idx >= 0 && encoding_idx < GEANY_ENCODINGS_MAX) charset = encodings[encoding_idx].charset;
@@ -183,23 +171,14 @@
#if ! GEANY_USE_WIN32_DIALOG -static void add_opendlg_filetype(gpointer pft, gpointer filetype_combo) -{ - GeanyFiletype *ft = pft; - - gtk_combo_box_append_text(GTK_COMBO_BOX(filetype_combo), ft->title); - - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(ui_widgets.open_filesel), - filetypes_create_file_filter(ft)); -} - - static void create_open_file_dialog(void) { GtkWidget *filetype_combo, *encoding_combo; GtkWidget *viewbtn; guint i; gchar *encoding_string; + GeanyFiletype *ft; + GSList *node;
ui_widgets.open_filesel = gtk_file_chooser_dialog_new(_("Open File"), GTK_WINDOW(main_widgets.window), GTK_FILE_CHOOSER_ACTION_OPEN, NULL, NULL); @@ -237,7 +216,14 @@ /* 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_named(add_opendlg_filetype, filetype_combo); + foreach_slist(ft, node, sorted_filetypes) + { + if (ft->id == GEANY_FILETYPES_NONE) + continue; + gtk_combo_box_append_text(GTK_COMBO_BOX(filetype_combo), ft->title); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(ui_widgets.open_filesel), + filetypes_create_file_filter(ft)); + } 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-31 14:32:03 UTC (rev 3672) +++ branches/reorder-filetypes/src/filetypes.c 2009-03-31 15:07:27 UTC (rev 3673) @@ -70,7 +70,9 @@ static GHashTable *filetypes_hash = NULL; /* Hash of filetype pointers based on name keys */
/* List of filetype pointers sorted by name, with ft[GEANY_FILETYPES_NONE] first, as this - * is usually treated specially. */ + * is usually treated specially. + * The list does not change after filetypes have been initialized, so you can use + * @code g_slist_nth_data(sorted_filetypes, n) @endcode and expect the same result at different times. */ GSList *sorted_filetypes = NULL;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.