Use g_slist_nth_data() with sorted_filetypes list instead of
filetypes_find() as it is neater. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/reorder-filetypes@3673 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
parent
4753e20394
commit
68928213df
@ -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>
|
||||
|
@ -71,14 +71,6 @@ static GtkWidget *add_file_open_extra_widget(void);
|
||||
|
||||
|
||||
#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 @@ on_file_open_dialog_response (GtkDialog *dialog,
|
||||
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 @@ on_file_open_dialog_response (GtkDialog *dialog,
|
||||
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 @@ on_file_open_check_hidden_toggled (GtkToggleButton *togglebutton,
|
||||
|
||||
|
||||
#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 @@ static void create_open_file_dialog(void)
|
||||
/* 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 */
|
||||
|
@ -70,7 +70,9 @@ GPtrArray *filetypes_array = NULL; /* Dynamic array of filetype pointers */
|
||||
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;
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user