From 5ddc129829313de7d7e263f51bffa0ff06d806ad Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Fri, 20 Mar 2009 16:18:32 +0000 Subject: [PATCH 02/14] Make GEANY_FILETYPES_NONE = 0; other things are now broken, e.g. setting Open dialog filetypes. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/reorder-filetypes@3640 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 8 ++++++++ src/dialogs.c | 2 +- src/filetypes.c | 26 +++++++++++++------------- src/filetypes.h | 22 +++++++--------------- src/highlighting.c | 2 +- src/plugindata.h | 2 +- src/symbols.c | 7 ++++--- 7 files changed, 35 insertions(+), 34 deletions(-) diff --git a/ChangeLog b/ChangeLog index 88f0516e..b31fb519 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2009-03-20 Nick Treleaven + + * src/highlighting.c, src/dialogs.c, src/plugindata.h, + src/filetypes.c, src/filetypes.h, src/symbols.c: + Make GEANY_FILETYPES_NONE = 0; other things are now broken, e.g. + setting Open dialog filetypes. + + 2009-03-19 Enrico Tröger * src/build.c: diff --git a/src/dialogs.c b/src/dialogs.c index f53adde5..1841ec37 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -90,7 +90,7 @@ on_file_open_dialog_response (GtkDialog *dialog, gboolean ro = (response == GEANY_RESPONSE_VIEW); /* View clicked */ /* ignore detect from file item */ - if (filetype_idx >= 0 && filetype_idx < GEANY_FILETYPES_NONE) + if (filetype_idx > 0 && filetype_idx < GEANY_MAX_BUILT_IN_FILETYPES) ft = filetypes[filetype_idx]; if (encoding_idx >= 0 && encoding_idx < GEANY_ENCODINGS_MAX) charset = encodings[encoding_idx].charset; diff --git a/src/filetypes.c b/src/filetypes.c index c7136fb4..0421fff3 100644 --- a/src/filetypes.c +++ b/src/filetypes.c @@ -78,7 +78,18 @@ static void init_builtin_filetypes(void) { GeanyFiletype *ft; -#define C /* these macros are only to ease navigation */ +#define NONE /* these macros are only to ease navigation */ + ft = filetypes[GEANY_FILETYPES_NONE]; + ft->lang = -2; + ft->name = g_strdup("None"); + ft->title = g_strdup(_("All files")); + ft->extension = g_strdup("*"); + ft->pattern = utils_strv_new("*", NULL); + ft->comment_open = NULL; + ft->comment_close = NULL; + ft->group = GEANY_FILETYPE_GROUP_NONE; + +#define C ft = filetypes[GEANY_FILETYPES_C]; ft->lang = 0; ft->name = g_strdup("C"); @@ -560,17 +571,6 @@ static void init_builtin_filetypes(void) ft->comment_open = g_strdup("--"); ft->comment_close = NULL; ft->group = GEANY_FILETYPE_GROUP_COMPILED; - -#define ALL - ft = filetypes[GEANY_FILETYPES_NONE]; - ft->lang = -2; - ft->name = g_strdup("None"); - ft->title = g_strdup(_("All files")); - ft->extension = g_strdup("*"); - ft->pattern = utils_strv_new("*", NULL); - ft->comment_open = NULL; - ft->comment_close = NULL; - ft->group = GEANY_FILETYPE_GROUP_NONE; } @@ -1240,7 +1240,7 @@ void filetypes_save_commands() G_DIR_SEPARATOR_S GEANY_FILEDEFS_SUBDIR G_DIR_SEPARATOR_S "filetypes.", NULL); gint i; - for (i = 0; i < GEANY_FILETYPES_NONE; i++) + for (i = 1; i < GEANY_MAX_BUILT_IN_FILETYPES; i++) { struct build_programs *bp = filetypes[i]->programs; GKeyFile *config_home; diff --git a/src/filetypes.h b/src/filetypes.h index fa96e909..ea335455 100644 --- a/src/filetypes.h +++ b/src/filetypes.h @@ -29,14 +29,11 @@ #include "ScintillaWidget.h" -/* Each group should be alpha-sorted, based on filetype::name (not enum name). - * Warning: remember to break the plugin ABI when adding items. */ -/* TODO: for a stable ABI put GEANY_FILETYPES_NONE first, and use a sorted duplicate - * filetypes array for GUI elements. */ typedef enum { - /* normally compiled languages */ - GEANY_FILETYPES_ADA = 0, + GEANY_FILETYPES_NONE = 0, /* first filetype */ + + GEANY_FILETYPES_ADA, GEANY_FILETYPES_AS, GEANY_FILETYPES_ASM, GEANY_FILETYPES_C, @@ -54,8 +51,6 @@ typedef enum GEANY_FILETYPES_PASCAL, GEANY_FILETYPES_VALA, GEANY_FILETYPES_VHDL, - - /* script languages */ GEANY_FILETYPES_FERITE, GEANY_FILETYPES_JS, GEANY_FILETYPES_LUA, @@ -68,14 +63,10 @@ typedef enum GEANY_FILETYPES_RUBY, GEANY_FILETYPES_SH, GEANY_FILETYPES_TCL, - - /* markup languages */ GEANY_FILETYPES_CSS, GEANY_FILETYPES_DOCBOOK, GEANY_FILETYPES_HTML, GEANY_FILETYPES_XML, - - /* miscellaneous languages */ GEANY_FILETYPES_CMAKE, GEANY_FILETYPES_CONF, GEANY_FILETYPES_DIFF, @@ -86,9 +77,10 @@ typedef enum GEANY_FILETYPES_SQL, GEANY_FILETYPES_YAML, - GEANY_FILETYPES_NONE, /* must be last filetype */ - GEANY_MAX_BUILT_IN_FILETYPES /* Use filetypes_array->len instead */ -} filetype_id; + /* ^ append items here */ + GEANY_MAX_BUILT_IN_FILETYPES /* Don't use this, use filetypes_array->len instead */ +} +filetype_id; typedef enum { diff --git a/src/highlighting.c b/src/highlighting.c index 32b756ca..e6912f79 100644 --- a/src/highlighting.c +++ b/src/highlighting.c @@ -3433,7 +3433,7 @@ void highlighting_set_styles(ScintillaObject *sci, gint filetype_idx) filetypes_load_config(filetype_idx, FALSE); /* load filetypes.ext */ /* load tags files (some lexers highlight global typenames) */ - if (filetype_idx < GEANY_FILETYPES_NONE) + if (filetype_idx != GEANY_FILETYPES_NONE) symbols_global_tags_loaded(filetype_idx); switch (filetype_idx) diff --git a/src/plugindata.h b/src/plugindata.h index 8b1aaeab..bc7bfe53 100644 --- a/src/plugindata.h +++ b/src/plugindata.h @@ -51,7 +51,7 @@ enum { * existing fields in the plugin data types have to be changed or reordered. */ /* This should usually stay the same if fields are only appended, assuming only pointers to * structs and not structs themselves are declared by plugins. */ - GEANY_ABI_VERSION = 59 + GEANY_ABI_VERSION = 60 }; /** Check the plugin can be loaded by Geany. diff --git a/src/symbols.c b/src/symbols.c index 1641e5de..3495f7a1 100644 --- a/src/symbols.c +++ b/src/symbols.c @@ -1381,7 +1381,7 @@ static GHashTable *get_tagfile_hash(const GSList *file_list) g_free(utf8_fname); - if (FILETYPE_ID(ft) < GEANY_FILETYPES_NONE) + if (FILETYPE_ID(ft) != GEANY_FILETYPES_NONE) { fnames = g_hash_table_lookup(hash, ft); /* may be NULL */ fnames = g_list_append(fnames, fname); @@ -1417,13 +1417,14 @@ static GHashTable *init_user_tags(void) static void load_user_tags(filetype_id ft_id) { - static guchar tags_loaded[GEANY_FILETYPES_NONE] = {0}; + static guchar tags_loaded[GEANY_MAX_BUILT_IN_FILETYPES - 1] = {0}; static GHashTable *lang_hash = NULL; GList *fnames; const GList *node; const GeanyFiletype *ft = filetypes[ft_id]; - g_return_if_fail(ft_id < GEANY_FILETYPES_NONE); + g_return_if_fail(ft_id > 0); + g_return_if_fail(ft_id < GEANY_MAX_BUILT_IN_FILETYPES); if (tags_loaded[ft_id]) return; From 2cc65983d2f6bbfde492c32c6c4df2fa247e37f7 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Fri, 20 Mar 2009 16:33:59 +0000 Subject: [PATCH 03/14] Fix setting Open dialog filetype on opening a file. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/reorder-filetypes@3641 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 2 ++ src/dialogs.c | 9 +++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index b31fb519..3810ccc8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ src/filetypes.c, src/filetypes.h, src/symbols.c: Make GEANY_FILETYPES_NONE = 0; other things are now broken, e.g. setting Open dialog filetypes. + * src/dialogs.c: + Fix setting Open dialog filetype on opening a file. 2009-03-19 Enrico Tröger diff --git a/src/dialogs.c b/src/dialogs.c index 1841ec37..f042cb46 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -207,23 +207,20 @@ static void create_open_file_dialog(void) add_file_open_extra_widget()); filetype_combo = ui_lookup_widget(ui_widgets.open_filesel, "filetype_combo"); + gtk_combo_box_append_text(GTK_COMBO_BOX(filetype_combo), _("Detect by file extension")); /* add FileFilters(start with "All Files") */ gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(ui_widgets.open_filesel), filetypes_create_file_filter(filetypes[GEANY_FILETYPES_NONE])); /* now create meta filter "All Source" */ gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(ui_widgets.open_filesel), filetypes_create_file_filter_all_source()); - for (i = 0; i < filetypes_array->len; i++) + for (i = 1; i < filetypes_array->len; i++) { - if (i == GEANY_FILETYPES_NONE) - continue; - gtk_combo_box_append_text(GTK_COMBO_BOX(filetype_combo), filetypes[i]->title); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(ui_widgets.open_filesel), filetypes_create_file_filter(filetypes[i])); } - gtk_combo_box_append_text(GTK_COMBO_BOX(filetype_combo), _("Detect by file extension")); - gtk_combo_box_set_active(GTK_COMBO_BOX(filetype_combo), filetypes_array->len - 1); + gtk_combo_box_set_active(GTK_COMBO_BOX(filetype_combo), 0); /* fill encoding combo box */ encoding_combo = ui_lookup_widget(ui_widgets.open_filesel, "encoding_combo"); From 305707906cab812562ada0fe1e310f9d38366d25 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Fri, 20 Mar 2009 16:41:12 +0000 Subject: [PATCH 04/14] Move ActionScript to the Script group. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/reorder-filetypes@3642 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- src/filetypes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/filetypes.c b/src/filetypes.c index 0421fff3..b74aca28 100644 --- a/src/filetypes.c +++ b/src/filetypes.c @@ -492,7 +492,7 @@ static void init_builtin_filetypes(void) ft->pattern = utils_strv_new("*.as", NULL); ft->comment_open = g_strdup("//"); ft->comment_close = NULL; - ft->group = GEANY_FILETYPE_GROUP_COMPILED; + ft->group = GEANY_FILETYPE_GROUP_SCRIPT; #define R ft = filetypes[GEANY_FILETYPES_R]; From 0cd1683ca6807be096876755440066f71c0f1b59 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Fri, 27 Mar 2009 14:06:11 +0000 Subject: [PATCH 05/14] Sort open dialog filetypes in combo boxes by title. Add filetypes_foreach_sorted(), filetypes_find(). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/reorder-filetypes@3658 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 7 +++++++ src/dialogs.c | 38 ++++++++++++++++++++++++++++---------- src/filetypes.c | 44 +++++++++++++++++++++++++++++++++++--------- src/filetypes.h | 4 ++++ 4 files changed, 74 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3810ccc8..090a0337 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2009-03-27 Nick Treleaven + + * src/dialogs.c, src/filetypes.c, src/filetypes.h: + Sort open dialog filetypes in combo boxes by title. + Add filetypes_foreach_sorted(), filetypes_find(). + + 2009-03-20 Nick Treleaven * src/highlighting.c, src/dialogs.c, src/plugindata.h, diff --git a/src/dialogs.c b/src/dialogs.c index f042cb46..ec511fdb 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -71,6 +71,14 @@ 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, @@ -81,8 +89,8 @@ on_file_open_dialog_response (GtkDialog *dialog, if (response == GTK_RESPONSE_ACCEPT || response == GEANY_RESPONSE_VIEW) { GSList *filelist; - gint filetype_idx = gtk_combo_box_get_active(GTK_COMBO_BOX( - ui_lookup_widget(GTK_WIDGET(dialog), "filetype_combo"))); + GtkComboBox *filecombo = 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; @@ -90,8 +98,12 @@ on_file_open_dialog_response (GtkDialog *dialog, gboolean ro = (response == GEANY_RESPONSE_VIEW); /* View clicked */ /* ignore detect from file item */ - if (filetype_idx > 0 && filetype_idx < GEANY_MAX_BUILT_IN_FILETYPES) - ft = filetypes[filetype_idx]; + 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 (encoding_idx >= 0 && encoding_idx < GEANY_ENCODINGS_MAX) charset = encodings[encoding_idx].charset; @@ -171,6 +183,17 @@ 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; @@ -214,12 +237,7 @@ 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()); - for (i = 1; i < filetypes_array->len; i++) - { - gtk_combo_box_append_text(GTK_COMBO_BOX(filetype_combo), filetypes[i]->title); - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(ui_widgets.open_filesel), - filetypes_create_file_filter(filetypes[i])); - } + filetypes_foreach_sorted(add_opendlg_filetype, filetype_combo); gtk_combo_box_set_active(GTK_COMBO_BOX(filetype_combo), 0); /* fill encoding combo box */ diff --git a/src/filetypes.c b/src/filetypes.c index b74aca28..39ee77f6 100644 --- a/src/filetypes.c +++ b/src/filetypes.c @@ -712,11 +712,8 @@ void filetypes_init() } -typedef gboolean FileTypesPredicate(GeanyFiletype *ft, gpointer user_data); - /* Find a filetype that predicate returns TRUE for, otherwise return NULL. */ -static GeanyFiletype *filetypes_find(gboolean source_only, - FileTypesPredicate predicate, gpointer user_data) +GeanyFiletype *filetypes_find(GCompareFunc predicate, gpointer user_data) { guint i; @@ -724,9 +721,6 @@ static GeanyFiletype *filetypes_find(gboolean source_only, { GeanyFiletype *ft = filetypes[i]; - if (source_only && i == GEANY_FILETYPES_NONE) - continue; /* None is not for source files */ - if (predicate(ft, user_data)) return ft; } @@ -734,12 +728,16 @@ static GeanyFiletype *filetypes_find(gboolean source_only, } -static gboolean match_basename(GeanyFiletype *ft, gpointer user_data) +static gboolean match_basename(gconstpointer pft, gconstpointer user_data) { + const GeanyFiletype *ft = pft; const gchar *base_filename = user_data; gint j; gboolean ret = FALSE; + if (ft->id == GEANY_FILETYPES_NONE) + return FALSE; + for (j = 0; ft->pattern[j] != NULL; j++) { GPatternSpec *pattern = g_pattern_spec_new(ft->pattern[j]); @@ -770,7 +768,7 @@ GeanyFiletype *filetypes_detect_from_extension(const gchar *utf8_filename) setptr(base_filename, g_utf8_strdown(base_filename, -1)); #endif - ft = filetypes_find(TRUE, match_basename, base_filename); + ft = filetypes_find(match_basename, base_filename); if (ft == NULL) ft = filetypes[GEANY_FILETYPES_NONE]; @@ -1480,3 +1478,31 @@ 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. */ +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); +} + diff --git a/src/filetypes.h b/src/filetypes.h index ea335455..e80619fa 100644 --- a/src/filetypes.h +++ b/src/filetypes.h @@ -146,6 +146,10 @@ extern GPtrArray *filetypes_array; GeanyFiletype *filetypes_lookup_by_name(const gchar *name); +void filetypes_foreach_sorted(GFunc callback, gpointer user_data); + +GeanyFiletype *filetypes_find(GCompareFunc predicate, gpointer user_data); + void filetypes_init(void); From bc9639e800185405e236f9a7ba09eaf6d73b79f2 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Fri, 27 Mar 2009 14:14:46 +0000 Subject: [PATCH 06/14] 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); } From ed5f4ecb83afd8698c24d224f920eaa219f1a8cf Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Fri, 27 Mar 2009 15:33:52 +0000 Subject: [PATCH 07/14] Sort filetype IDs randomly (so we can append randomly). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/reorder-filetypes@3660 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 2 ++ src/filetypes.h | 82 ++++++++++++++++++++++++------------------------ src/plugindata.h | 2 +- 3 files changed, 44 insertions(+), 42 deletions(-) diff --git a/ChangeLog b/ChangeLog index 090a0337..e4d88ab2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,8 @@ * src/dialogs.c, src/filetypes.c, src/filetypes.h: Sort open dialog filetypes in combo boxes by title. Add filetypes_foreach_sorted(), filetypes_find(). + * src/filetypes.h, src/plugindata.h: + Sort filetype IDs randomly (so we can append randomly). 2009-03-20 Nick Treleaven diff --git a/src/filetypes.h b/src/filetypes.h index e80619fa..653780be 100644 --- a/src/filetypes.h +++ b/src/filetypes.h @@ -31,51 +31,51 @@ typedef enum { - GEANY_FILETYPES_NONE = 0, /* first filetype */ + GEANY_FILETYPES_NONE = 0, /* first filetype is always None */ - GEANY_FILETYPES_ADA, - GEANY_FILETYPES_AS, - GEANY_FILETYPES_ASM, - GEANY_FILETYPES_C, - GEANY_FILETYPES_CPP, - GEANY_FILETYPES_CS, - GEANY_FILETYPES_CAML, - GEANY_FILETYPES_D, - GEANY_FILETYPES_F77, - GEANY_FILETYPES_FORTRAN, - GEANY_FILETYPES_BASIC, /* FreeBasic */ - GEANY_FILETYPES_GLSL, - GEANY_FILETYPES_HASKELL, - GEANY_FILETYPES_HAXE, - GEANY_FILETYPES_JAVA, - GEANY_FILETYPES_PASCAL, - GEANY_FILETYPES_VALA, - GEANY_FILETYPES_VHDL, - GEANY_FILETYPES_FERITE, - GEANY_FILETYPES_JS, - GEANY_FILETYPES_LUA, - GEANY_FILETYPES_MAKE, - GEANY_FILETYPES_MATLAB, - GEANY_FILETYPES_PERL, GEANY_FILETYPES_PHP, - GEANY_FILETYPES_PYTHON, - GEANY_FILETYPES_R, + GEANY_FILETYPES_BASIC, /* FreeBasic */ + GEANY_FILETYPES_MATLAB, GEANY_FILETYPES_RUBY, - GEANY_FILETYPES_SH, - GEANY_FILETYPES_TCL, - GEANY_FILETYPES_CSS, - GEANY_FILETYPES_DOCBOOK, - GEANY_FILETYPES_HTML, - GEANY_FILETYPES_XML, - GEANY_FILETYPES_CMAKE, - GEANY_FILETYPES_CONF, - GEANY_FILETYPES_DIFF, - GEANY_FILETYPES_NSIS, - GEANY_FILETYPES_PO, - GEANY_FILETYPES_LATEX, - GEANY_FILETYPES_REST, - GEANY_FILETYPES_SQL, + GEANY_FILETYPES_LUA, + GEANY_FILETYPES_FERITE, GEANY_FILETYPES_YAML, + GEANY_FILETYPES_C, + GEANY_FILETYPES_NSIS, + GEANY_FILETYPES_GLSL, + GEANY_FILETYPES_PO, + GEANY_FILETYPES_MAKE, + GEANY_FILETYPES_TCL, + GEANY_FILETYPES_XML, + GEANY_FILETYPES_CSS, + GEANY_FILETYPES_REST, + GEANY_FILETYPES_HASKELL, + GEANY_FILETYPES_JAVA, + GEANY_FILETYPES_CAML, + GEANY_FILETYPES_AS, + GEANY_FILETYPES_R, + GEANY_FILETYPES_DIFF, + GEANY_FILETYPES_HTML, + GEANY_FILETYPES_PYTHON, + GEANY_FILETYPES_CS, + GEANY_FILETYPES_PERL, + GEANY_FILETYPES_VALA, + GEANY_FILETYPES_PASCAL, + GEANY_FILETYPES_LATEX, + GEANY_FILETYPES_ASM, + GEANY_FILETYPES_CONF, + GEANY_FILETYPES_HAXE, + GEANY_FILETYPES_CPP, + GEANY_FILETYPES_SH, + GEANY_FILETYPES_FORTRAN, + GEANY_FILETYPES_SQL, + GEANY_FILETYPES_F77, + GEANY_FILETYPES_DOCBOOK, + GEANY_FILETYPES_D, + GEANY_FILETYPES_JS, + GEANY_FILETYPES_VHDL, + GEANY_FILETYPES_ADA, + GEANY_FILETYPES_CMAKE, /* ^ append items here */ GEANY_MAX_BUILT_IN_FILETYPES /* Don't use this, use filetypes_array->len instead */ diff --git a/src/plugindata.h b/src/plugindata.h index bc7bfe53..88e9e22c 100644 --- a/src/plugindata.h +++ b/src/plugindata.h @@ -51,7 +51,7 @@ enum { * existing fields in the plugin data types have to be changed or reordered. */ /* This should usually stay the same if fields are only appended, assuming only pointers to * structs and not structs themselves are declared by plugins. */ - GEANY_ABI_VERSION = 60 + GEANY_ABI_VERSION = 61 }; /** Check the plugin can be loaded by Geany. From ba6b5c81e984eb31fad97e7eee0f1f2124199a73 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Fri, 27 Mar 2009 15:36:10 +0000 Subject: [PATCH 08/14] Fix sorting Document menu filetype names. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/reorder-filetypes@3661 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 3 ++ src/filetypes.c | 80 +++++++++++++++++++------------------------------ 2 files changed, 33 insertions(+), 50 deletions(-) diff --git a/ChangeLog b/ChangeLog index e4d88ab2..4be94be1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,9 @@ Add filetypes_foreach_sorted(), filetypes_find(). * src/filetypes.h, src/plugindata.h: Sort filetype IDs randomly (so we can append randomly). + * src/filetypes.c: + Fix sorting Document menu filetype names. + 2009-03-20 Nick Treleaven diff --git a/src/filetypes.c b/src/filetypes.c index 3e3fc8a2..20776f40 100644 --- a/src/filetypes.c +++ b/src/filetypes.c @@ -74,7 +74,7 @@ GHashTable *filetypes_hash = NULL; /* Hash of filetype pointers based on name ke static GSList *sorted_filetypes = NULL; -static void create_radio_menu_item(GtkWidget *menu, const gchar *label, GeanyFiletype *ftype); +static void create_radio_menu_item(GtkWidget *menu, GeanyFiletype *ftype); /* Note: remember to update HACKING if this function is renamed. */ @@ -660,61 +660,41 @@ static void setup_config_file_menus(void) } -#define create_sub_menu(menu, item, title) \ - (menu) = gtk_menu_new(); \ - (item) = gtk_menu_item_new_with_mnemonic((title)); \ - gtk_menu_item_set_submenu(GTK_MENU_ITEM((item)), (menu)); \ - gtk_container_add(GTK_CONTAINER(filetype_menu), (item)); \ - gtk_widget_show((item)); +static GtkWidget *group_menus[GEANY_FILETYPE_GROUP_NONE]; + +static void create_sub_menu(GtkWidget *parent, gsize group_id, const gchar *title) +{ + GtkWidget *menu, *item; + + menu = gtk_menu_new(); + item = gtk_menu_item_new_with_mnemonic((title)); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu); + gtk_container_add(GTK_CONTAINER(parent), item); + gtk_widget_show(item); + group_menus[group_id] = menu; +} + + +static void add_ft_menu_item(gpointer pft, gpointer user_data) +{ + GeanyFiletype *ft = pft; + + create_radio_menu_item(group_menus[ft->group], ft); +} static void create_set_filetype_menu(void) { - filetype_id ft_id; GtkWidget *filetype_menu = ui_lookup_widget(main_widgets.window, "set_filetype1_menu"); - GtkWidget *sub_menu = filetype_menu; - GtkWidget *sub_menu_programming, *sub_menu_scripts, *sub_menu_markup, *sub_menu_misc; - GtkWidget *sub_item_programming, *sub_item_scripts, *sub_item_markup, *sub_item_misc; - create_sub_menu(sub_menu_programming, sub_item_programming, _("_Programming Languages")); - create_sub_menu(sub_menu_scripts, sub_item_scripts, _("_Scripting Languages")); - create_sub_menu(sub_menu_markup, sub_item_markup, _("_Markup Languages")); - create_sub_menu(sub_menu_misc, sub_item_misc, _("M_iscellaneous Languages")); + create_sub_menu(filetype_menu, GEANY_FILETYPE_GROUP_COMPILED, _("_Programming Languages")); + create_sub_menu(filetype_menu, GEANY_FILETYPE_GROUP_SCRIPT, _("_Scripting Languages")); + create_sub_menu(filetype_menu, GEANY_FILETYPE_GROUP_MARKUP, _("_Markup Languages")); + create_sub_menu(filetype_menu, GEANY_FILETYPE_GROUP_MISC, _("M_iscellaneous Languages")); /* Append all filetypes to the filetype menu */ - for (ft_id = 0; ft_id < filetypes_array->len; ft_id++) - { - GeanyFiletype *ft = filetypes[ft_id]; - const gchar *title = ft->title; - - /* insert separators for different filetype groups */ - switch (ft->group) - { - case GEANY_FILETYPE_GROUP_COMPILED: /* programming */ - sub_menu = sub_menu_programming; - break; - - case GEANY_FILETYPE_GROUP_SCRIPT: /* scripts */ - sub_menu = sub_menu_scripts; - break; - - case GEANY_FILETYPE_GROUP_MARKUP: /* markup */ - sub_menu = sub_menu_markup; - break; - - case GEANY_FILETYPE_GROUP_MISC: /* misc */ - sub_menu = sub_menu_misc; - break; - - case GEANY_FILETYPE_GROUP_NONE: /* none */ - sub_menu = filetype_menu; - title = _("None"); - break; - - default: break; - } - create_radio_menu_item(sub_menu, title, ft); - } + filetypes_foreach_sorted(add_ft_menu_item, NULL); + create_radio_menu_item(filetype_menu, filetypes[GEANY_FILETYPES_NONE]); } @@ -994,12 +974,12 @@ on_filetype_change (GtkMenuItem *menuitem, } -static void create_radio_menu_item(GtkWidget *menu, const gchar *label, GeanyFiletype *ftype) +static void create_radio_menu_item(GtkWidget *menu, GeanyFiletype *ftype) { static GSList *group = NULL; GtkWidget *tmp; - tmp = gtk_radio_menu_item_new_with_label(group, label); + tmp = gtk_radio_menu_item_new_with_label(group, ftype->title); group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(tmp)); ftype->priv->menu_item = tmp; gtk_widget_show(tmp); From 127cef3c9f98cc577dd6ceeffb5f5e742e88fc0d Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Fri, 27 Mar 2009 15:52:38 +0000 Subject: [PATCH 09/14] Fix Gtk warnings & sort by filetype title, not name. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/reorder-filetypes@3664 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- src/filetypes.c | 7 ++++--- src/filetypes.h | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/filetypes.c b/src/filetypes.c index 20776f40..4136349b 100644 --- a/src/filetypes.c +++ b/src/filetypes.c @@ -596,7 +596,7 @@ static gint cmp_filetype(gconstpointer pft1, gconstpointer pft2) { const GeanyFiletype *ft1 = pft1, *ft2 = pft2; - return utils_str_casecmp(ft1->name, ft2->name); + return utils_str_casecmp(ft1->title, ft2->title); } @@ -611,7 +611,8 @@ static void filetype_add(GeanyFiletype *ft) 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); + if (ft->id != GEANY_FILETYPES_NONE) + sorted_filetypes = g_slist_insert_sorted(sorted_filetypes, ft, cmp_filetype); } @@ -660,7 +661,7 @@ static void setup_config_file_menus(void) } -static GtkWidget *group_menus[GEANY_FILETYPE_GROUP_NONE]; +static GtkWidget *group_menus[GEANY_FILETYPE_GROUP_COUNT]; static void create_sub_menu(GtkWidget *parent, gsize group_id, const gchar *title) { diff --git a/src/filetypes.h b/src/filetypes.h index 653780be..49ee3b67 100644 --- a/src/filetypes.h +++ b/src/filetypes.h @@ -88,7 +88,8 @@ typedef enum GEANY_FILETYPE_GROUP_COMPILED, GEANY_FILETYPE_GROUP_SCRIPT, GEANY_FILETYPE_GROUP_MARKUP, - GEANY_FILETYPE_GROUP_MISC + GEANY_FILETYPE_GROUP_MISC, + GEANY_FILETYPE_GROUP_COUNT } GeanyFiletypeGroupID; From c220fadc9e0972c23f2687ade00d851b3eb8b376 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Fri, 27 Mar 2009 16:14:29 +0000 Subject: [PATCH 10/14] Make None filetype name = title = _("None"). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/reorder-filetypes@3665 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 3 ++- src/filetypes.c | 8 +++++--- src/templates.c | 2 -- src/ui_utils.c | 16 +++++++++------- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4be94be1..c49feefa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,7 +7,8 @@ Sort filetype IDs randomly (so we can append randomly). * src/filetypes.c: Fix sorting Document menu filetype names. - + * src/templates.c, src/filetypes.c, src/ui_utils.c: + Make None filetype name = title = _("None"). 2009-03-20 Nick Treleaven diff --git a/src/filetypes.c b/src/filetypes.c index 4136349b..86a6782c 100644 --- a/src/filetypes.c +++ b/src/filetypes.c @@ -85,8 +85,8 @@ static void init_builtin_filetypes(void) #define NONE /* these macros are only to ease navigation */ ft = filetypes[GEANY_FILETYPES_NONE]; ft->lang = -2; - ft->name = g_strdup("None"); - ft->title = g_strdup(_("All files")); + ft->name = g_strdup(_("None")); + ft->title = g_strdup(_("None")); ft->extension = g_strdup("*"); ft->pattern = utils_strv_new("*", NULL); ft->comment_open = NULL; @@ -1294,11 +1294,13 @@ GtkFileFilter *filetypes_create_file_filter(const GeanyFiletype *ft) { GtkFileFilter *new_filter; gint i; + const gchar *title; g_return_val_if_fail(ft != NULL, NULL); new_filter = gtk_file_filter_new(); - gtk_file_filter_set_name(new_filter, ft->title); + title = ft->id == GEANY_FILETYPES_NONE ? _("All files") : ft->title; + gtk_file_filter_set_name(new_filter, title); for (i = 0; ft->pattern[i]; i++) { diff --git a/src/templates.c b/src/templates.c index eb14ce22..ea528b33 100644 --- a/src/templates.c +++ b/src/templates.c @@ -372,8 +372,6 @@ static void create_new_menu_items(void) if (ft_templates[ft_id] == NULL) continue; - if (ft_id == GEANY_FILETYPES_NONE) - label = _("None"); tmp_menu = gtk_menu_item_new_with_label(label); gtk_widget_show(tmp_menu); diff --git a/src/ui_utils.c b/src/ui_utils.c index 9d96ac2b..5ef1170a 100644 --- a/src/ui_utils.c +++ b/src/ui_utils.c @@ -134,6 +134,14 @@ void ui_set_statusbar(gboolean log, const gchar *format, ...) } +static GeanyFiletype *document_get_filetype(GeanyDocument *doc) +{ + g_return_val_if_fail(doc, NULL); + + return filetypes[FILETYPE_ID(doc->file_type)]; +} + + /* updates the status bar document statistics */ void ui_update_statusbar(GeanyDocument *doc, gint pos) { @@ -149,13 +157,7 @@ void ui_update_statusbar(GeanyDocument *doc, gint pos) const gchar sp[] = " "; guint line, col; const gchar *cur_tag; - gchar *filetype_name; - - /* workaround to make the name of filetype GEANY_FILETYPES_NONE translatable */ - if (doc->file_type == NULL || doc->file_type->id == GEANY_FILETYPES_NONE) - filetype_name = _("None"); - else - filetype_name = doc->file_type->name; + gchar *filetype_name = document_get_filetype(doc)->name; if (stats_str == NULL) stats_str = g_string_sized_new(120); From 4753e203946204dfb1880c803269f2d7759409e0 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Tue, 31 Mar 2009 14:32:03 +0000 Subject: [PATCH 11/14] 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. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/reorder-filetypes@3672 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 11 +++++++++++ src/dialogs.c | 2 +- src/filetypes.c | 30 +++++++++++++++++++----------- src/filetypes.h | 4 +++- src/templates.c | 7 ++++--- src/utils.h | 5 +++++ 6 files changed, 43 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index c49feefa..bd151af5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2009-03-31 Nick Treleaven + + * 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 * src/dialogs.c, src/filetypes.c, src/filetypes.h: diff --git a/src/dialogs.c b/src/dialogs.c index ec511fdb..66d36841 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -237,7 +237,7 @@ 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_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 */ diff --git a/src/filetypes.c b/src/filetypes.c index 86a6782c..764abe68 100644 --- a/src/filetypes.c +++ b/src/filetypes.c @@ -67,11 +67,11 @@ GeanyFiletypePrivate; 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 @@ static gint cmp_filetype(gconstpointer pft1, gconstpointer pft2) { 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 @@ static void filetype_add(GeanyFiletype *ft) 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 void setup_config_file_menus(void) } -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 @@ static void create_set_filetype_menu(void) 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 @@ GeanyFiletype *filetypes_index(gint idx) /* 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); + } } diff --git a/src/filetypes.h b/src/filetypes.h index 49ee3b67..d4fc6eab 100644 --- a/src/filetypes.h +++ b/src/filetypes.h @@ -144,10 +144,12 @@ extern GPtrArray *filetypes_array; * 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); diff --git a/src/templates.c b/src/templates.c index ea528b33..7957f736 100644 --- a/src/templates.c +++ b/src/templates.c @@ -362,12 +362,13 @@ on_new_with_template (GtkMenuItem *menuitem, /* 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) diff --git a/src/utils.h b/src/utils.h index e0edd316..2bc3c0f0 100644 --- a/src/utils.h +++ b/src/utils.h @@ -57,6 +57,11 @@ 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); From 68928213dfaac772ee5baf7adbc0264df9639fc7 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Tue, 31 Mar 2009 15:07:27 +0000 Subject: [PATCH 12/14] 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 --- ChangeLog | 3 +++ src/dialogs.c | 42 ++++++++++++++---------------------------- src/filetypes.c | 4 +++- 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index bd151af5..b9b2cb14 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/src/dialogs.c b/src/dialogs.c index 66d36841..7124e933 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -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 */ diff --git a/src/filetypes.c b/src/filetypes.c index 764abe68..0e8cd01c 100644 --- a/src/filetypes.c +++ b/src/filetypes.c @@ -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; From 6d3450805958ef70e3139d5a884cb5767f5db315 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Tue, 31 Mar 2009 15:11:58 +0000 Subject: [PATCH 13/14] Fix wording & typo. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/reorder-filetypes@3674 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- doc/geany.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/geany.txt b/doc/geany.txt index e42d7e0a..8e356f46 100644 --- a/doc/geany.txt +++ b/doc/geany.txt @@ -3378,8 +3378,8 @@ For example:: Then edit it and add any of the available elements listed in the file or remove any of the existing elements. Of course, you can also reorder the elements as you wish and add or remove additional separators. -This file must be valid XML unless it can't be loaded and the global toolbar -UI definition is used. +This file must be valid XML, otherwise the global toolbar UI definition +will be used instead. .. note:: (1) You cannot add new actions which are not listed below. @@ -3423,7 +3423,7 @@ SearchEntry The search field belonging to the 'Search' element (can be us Search Find the entered text in the current file (only useful if you also use 'SearchEntry') GotoEntry The goto field belonging to the 'Goto' element (can be used alone) -Goto Jump to the entered line number (only useful if you also use 'SearchEntry') +Goto Jump to the entered line number (only useful if you also use 'GotoEntry') Preferences Show the preferences dialog Quit Quit Geany ================== ============================================================================== From 26d27cbd2e9ef08346ff2b9c3d1c6905bb5ab275 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Thu, 2 Apr 2009 15:00:17 +0000 Subject: [PATCH 14/14] Rename sorted_filetypes filetypes_by_title, and add to GeanyData for plugin API access. Fix order of filetypes in Save Actions Instant Save configuration dialog. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/reorder-filetypes@3677 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 10 ++++++++++ plugins/saveactions.c | 8 +++++--- src/dialogs.c | 4 ++-- src/filetypes.c | 14 +++++++------- src/filetypes.h | 2 +- src/plugindata.h | 3 ++- src/plugins.c | 3 ++- src/templates.c | 2 +- 8 files changed, 30 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index b9b2cb14..587b26dd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-04-02 Nick Treleaven + + * src/templates.c, src/dialogs.c, src/plugindata.h, src/filetypes.c, + src/filetypes.h, src/plugins.c, plugins/saveactions.c: + Rename sorted_filetypes filetypes_by_title, and add to GeanyData + for plugin API access. + Fix order of filetypes in Save Actions Instant Save configuration + dialog. + + 2009-03-31 Nick Treleaven * src/templates.c, src/utils.h, src/dialogs.c, src/filetypes.c, diff --git a/plugins/saveactions.c b/plugins/saveactions.c index 666eda2f..6e263765 100644 --- a/plugins/saveactions.c +++ b/plugins/saveactions.c @@ -603,6 +603,8 @@ GtkWidget *plugin_configure(GtkDialog *dialog) { GtkWidget *combo; guint i; + GSList *node; + GeanyFiletype *ft; notebook_vbox = gtk_vbox_new(FALSE, 2); inner_vbox = gtk_vbox_new(FALSE, 5); @@ -624,14 +626,14 @@ GtkWidget *plugin_configure(GtkDialog *dialog) gtk_box_pack_start(GTK_BOX(inner_vbox), label, FALSE, FALSE, 0); pref_widgets.instantsave_ft_combo = combo = gtk_combo_box_new_text(); - for (i = 0; i < geany->filetypes_array->len; i++) + i = 0; + foreach_slist(ft, node, geany->filetypes_by_title) { - GeanyFiletype *ft = filetypes_index(i); - gtk_combo_box_append_text(GTK_COMBO_BOX(combo), ft->name); if (utils_str_equal(ft->name, instantsave_default_ft)) gtk_combo_box_set_active(GTK_COMBO_BOX(combo), i); + i++; } gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(combo), 3); gtk_label_set_mnemonic_widget(GTK_LABEL(label), combo); diff --git a/src/dialogs.c b/src/dialogs.c index 7124e933..3377fc6e 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -91,7 +91,7 @@ on_file_open_dialog_response (GtkDialog *dialog, /* ignore detect from file item */ if (filetype_idx > 0 && filetype_idx < GEANY_MAX_BUILT_IN_FILETYPES) - ft = g_slist_nth_data(sorted_filetypes, filetype_idx); + ft = g_slist_nth_data(filetypes_by_title, filetype_idx); if (encoding_idx >= 0 && encoding_idx < GEANY_ENCODINGS_MAX) charset = encodings[encoding_idx].charset; @@ -216,7 +216,7 @@ 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()); - foreach_slist(ft, node, sorted_filetypes) + foreach_slist(ft, node, filetypes_by_title) { if (ft->id == GEANY_FILETYPES_NONE) continue; diff --git a/src/filetypes.c b/src/filetypes.c index 0e8cd01c..684ac858 100644 --- a/src/filetypes.c +++ b/src/filetypes.c @@ -69,11 +69,11 @@ 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. - * 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; +/** List of filetype pointers sorted by name, but with @c filetypes_index(GEANY_FILETYPES_NONE) + * first, as this is usually treated specially. + * The list does not change (after filetypes have been initialized), so you can use + * @code g_slist_nth_data(filetypes_by_title, n) @endcode and expect the same result at different times. */ +GSList *filetypes_by_title = NULL; static void create_radio_menu_item(GtkWidget *menu, GeanyFiletype *ftype); @@ -618,7 +618,7 @@ static void filetype_add(GeanyFiletype *ft) 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); + filetypes_by_title = g_slist_insert_sorted(filetypes_by_title, ft, cmp_filetype); } @@ -1487,7 +1487,7 @@ void filetypes_foreach_named(GFunc callback, gpointer user_data) GSList *node; GeanyFiletype *ft; - foreach_slist(ft, node, sorted_filetypes) + foreach_slist(ft, node, filetypes_by_title) { if (ft->id != GEANY_FILETYPES_NONE) callback(ft, user_data); diff --git a/src/filetypes.h b/src/filetypes.h index d4fc6eab..b54bdffb 100644 --- a/src/filetypes.h +++ b/src/filetypes.h @@ -144,7 +144,7 @@ extern GPtrArray *filetypes_array; * Example: filetypes[GEANY_FILETYPES_C]->name = ...; */ #define filetypes ((GeanyFiletype **)filetypes_array->pdata) -extern GSList *sorted_filetypes; +extern GSList *filetypes_by_title; GeanyFiletype *filetypes_lookup_by_name(const gchar *name); diff --git a/src/plugindata.h b/src/plugindata.h index 88e9e22c..7b0322b2 100644 --- a/src/plugindata.h +++ b/src/plugindata.h @@ -45,7 +45,7 @@ enum { /** The Application Programming Interface (API) version, incremented * whenever any plugin data types are modified or appended to. */ - GEANY_API_VERSION = 135, + GEANY_API_VERSION = 136, /** The Application Binary Interface (ABI) version, incremented whenever * existing fields in the plugin data types have to be changed or reordered. */ @@ -188,6 +188,7 @@ typedef struct GeanyData struct GeanyToolPrefs *tool_prefs; /**< Tool settings */ struct GeanyTemplatePrefs *template_prefs; /**< Template settings */ struct GeanyBuildInfo *build_info; /**< Current build information */ + GSList *filetypes_by_title; /**< See filetypes.h#filetypes_by_title. */ } GeanyData; diff --git a/src/plugins.c b/src/plugins.c index 7847fcc3..dc3ff4da 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -347,7 +347,8 @@ geany_data_init(void) &search_prefs, &tool_prefs, &template_prefs, - &build_info + &build_info, + filetypes_by_title }; memcpy(&geany_data, &gd, sizeof(GeanyData)); } diff --git a/src/templates.c b/src/templates.c index 7957f736..7754d0a3 100644 --- a/src/templates.c +++ b/src/templates.c @@ -365,7 +365,7 @@ static void create_new_menu_items(void) GeanyFiletype *ft; GSList *node; - foreach_slist(ft, node, sorted_filetypes) + foreach_slist(ft, node, filetypes_by_title) { filetype_id ft_id = ft->id; GtkWidget *tmp_menu, *tmp_button;