Revision: 5740 http://geany.svn.sourceforge.net/geany/?rev=5740&view=rev Author: ntrel Date: 2011-04-26 15:01:04 +0000 (Tue, 26 Apr 2011)
Log Message: ----------- Make filetype groups configurable using [Groups] in filetype_extensions.conf. Read filetype_extensions.conf when calling filetypes_init_types(), don't require doclist initialization.
Modified Paths: -------------- trunk/ChangeLog trunk/data/filetype_extensions.conf trunk/src/filetypes.c trunk/src/filetypes.h trunk/src/main.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2011-04-26 13:52:43 UTC (rev 5739) +++ trunk/ChangeLog 2011-04-26 15:01:04 UTC (rev 5740) @@ -1,3 +1,13 @@ +2011-04-26 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com> + + * src/filetypes.c, src/filetypes.h, src/main.c, + data/filetype_extensions.conf: + Make filetype groups configurable using [Groups] in + filetype_extensions.conf. + Read filetype_extensions.conf when calling filetypes_init_types(), + don't require doclist initialization. + + 2011-04-26 Colomban Wendling <colomban(at)geany(dot)org>
* src/callbacks.c, src/document.c, src/document.h,
Modified: trunk/data/filetype_extensions.conf =================================================================== --- trunk/data/filetype_extensions.conf 2011-04-26 13:52:43 UTC (rev 5739) +++ trunk/data/filetype_extensions.conf 2011-04-26 15:01:04 UTC (rev 5740) @@ -56,3 +56,11 @@ XML=*.xml;*.sgml;*.xsl;*.xslt;*.xsd;*.xhtml; YAML=*.yaml;*.yml; None=*; + +# Note: restarting is required after editing groups +[Groups] +Compiled=Genie;Scala; +Script=Typoscript; +Markup= +Misc= +None=
Modified: trunk/src/filetypes.c =================================================================== --- trunk/src/filetypes.c 2011-04-26 13:52:43 UTC (rev 5739) +++ trunk/src/filetypes.c 2011-04-26 15:01:04 UTC (rev 5740) @@ -64,6 +64,7 @@ static void create_radio_menu_item(GtkWidget *menu, GeanyFiletype *ftype);
static gchar *filetypes_get_conf_extension(gint filetype_idx); +static void read_filetype_config(void);
enum TitleType @@ -637,6 +638,8 @@ /* sort last instead of on insertion to prevent exponential time */ filetypes_by_title = g_slist_sort_with_data(filetypes_by_title, cmp_filetype, GINT_TO_POINTER(FALSE)); + + read_filetype_config(); }
@@ -648,7 +651,7 @@
f = utils_build_path(app->configdir, "filetype_extensions.conf", NULL); if (utils_str_equal(doc->real_path, f)) - filetypes_read_extensions(); + filetypes_reload_extensions();
g_free(f); f = utils_build_path(app->configdir, GEANY_FILEDEFS_SUBDIR, "filetypes.common", NULL); @@ -725,6 +728,7 @@ GSList *node;
filetypes_init_types(); + /* this has to be here as GTK isn't initialized in filetypes_init_types(). */ foreach_slist(node, filetypes_by_title) { @@ -1601,20 +1605,11 @@ #endif
-void filetypes_read_extensions(void) +static void read_extensions(GKeyFile *sysconfig, GKeyFile *userconfig) { guint i; gsize len = 0; - gchar *sysconfigfile = g_strconcat(app->datadir, G_DIR_SEPARATOR_S, - "filetype_extensions.conf", NULL); - gchar *userconfigfile = g_strconcat(app->configdir, G_DIR_SEPARATOR_S, - "filetype_extensions.conf", NULL); - GKeyFile *sysconfig = g_key_file_new(); - GKeyFile *userconfig = g_key_file_new();
- g_key_file_load_from_file(sysconfig, sysconfigfile, G_KEY_FILE_NONE, NULL); - g_key_file_load_from_file(userconfig, userconfigfile, G_KEY_FILE_NONE, NULL); - /* read the keys */ for (i = 0; i < filetypes_array->len; i++) { @@ -1633,12 +1628,65 @@ convert_filetype_extensions_to_lower_case(filetypes[i]->pattern, len); #endif } +}
+ +static void read_group(GKeyFile *config, const gchar *group_name, gint group_id) +{ + gchar **names = g_key_file_get_string_list(config, "Groups", group_name, NULL, NULL); + gchar **name; + + foreach_strv(name, names) + { + GeanyFiletype *ft = filetypes_lookup_by_name(*name); + + if (ft) + ft->group = group_id; + else + geany_debug("Filetype '%s' not found for group '%s'!", *name, group_name); + } +} + + +static void read_groups(GKeyFile *config) +{ + read_group(config, "Compiled", GEANY_FILETYPE_GROUP_COMPILED); + read_group(config, "Script", GEANY_FILETYPE_GROUP_SCRIPT); + read_group(config, "Markup", GEANY_FILETYPE_GROUP_MARKUP); + read_group(config, "Misc", GEANY_FILETYPE_GROUP_MISC); + read_group(config, "None", GEANY_FILETYPE_GROUP_NONE); +} + + +static void read_filetype_config(void) +{ + gchar *sysconfigfile = g_strconcat(app->datadir, G_DIR_SEPARATOR_S, + "filetype_extensions.conf", NULL); + gchar *userconfigfile = g_strconcat(app->configdir, G_DIR_SEPARATOR_S, + "filetype_extensions.conf", NULL); + GKeyFile *sysconfig = g_key_file_new(); + GKeyFile *userconfig = g_key_file_new(); + + g_key_file_load_from_file(sysconfig, sysconfigfile, G_KEY_FILE_NONE, NULL); + g_key_file_load_from_file(userconfig, userconfigfile, G_KEY_FILE_NONE, NULL); + + read_extensions(sysconfig, userconfig); + read_groups(sysconfig); + read_groups(userconfig); + g_free(sysconfigfile); g_free(userconfigfile); g_key_file_free(sysconfig); g_key_file_free(userconfig); +}
+ +void filetypes_reload_extensions(void) +{ + guint i; + + read_filetype_config(); + /* Redetect filetype of any documents with none set */ foreach_document(i) {
Modified: trunk/src/filetypes.h =================================================================== --- trunk/src/filetypes.h 2011-04-26 13:52:43 UTC (rev 5739) +++ trunk/src/filetypes.h 2011-04-26 15:01:04 UTC (rev 5740) @@ -175,7 +175,7 @@
void filetypes_init_types(void);
-void filetypes_read_extensions(void); +void filetypes_reload_extensions(void);
void filetypes_reload(void);
Modified: trunk/src/main.c =================================================================== --- trunk/src/main.c 2011-04-26 13:52:43 UTC (rev 5739) +++ trunk/src/main.c 2011-04-26 15:01:04 UTC (rev 5740) @@ -564,12 +564,9 @@ { gboolean ret;
- document_init_doclist(); filetypes_init_types(); - filetypes_read_extensions(); /* needed for *.lang.tags filetype matching */ ret = symbols_generate_global_tags(*argc, *argv, ! no_preprocessing); filetypes_free_types(); - document_finalize(); exit(ret); }
@@ -1044,7 +1041,6 @@ navqueue_init(); document_init_doclist(); symbols_init(); - filetypes_read_extensions(); editor_snippets_init();
/* set window icon */ @@ -1277,9 +1273,7 @@ editor_snippets_free(); editor_snippets_init();
- /* reload filetype extensions */ - filetypes_read_extensions(); - + filetypes_reload_extensions(); filetypes_reload();
/* C tag names to ignore */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.