SF.net SVN: geany:[4396] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Wed Nov 4 14:47:07 UTC 2009


Revision: 4396
          http://geany.svn.sourceforge.net/geany/?rev=4396&view=rev
Author:   ntrel
Date:     2009-11-04 14:47:07 +0000 (Wed, 04 Nov 2009)

Log Message:
-----------
Add utils_get_config_files().

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/highlighting.c
    trunk/src/templates.c
    trunk/src/utils.c
    trunk/src/utils.h

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2009-11-04 12:36:56 UTC (rev 4395)
+++ trunk/ChangeLog	2009-11-04 14:47:07 UTC (rev 4396)
@@ -6,6 +6,8 @@
    scheme files exist in a colorschemes config directory. Color scheme
    files must end in ".conf" and currently only the [named_styles]
    section is read.
+ * src/templates.c, src/utils.c, src/highlighting.c, src/utils.h:
+   Add utils_get_config_files().
 
 
 2009-10-30  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>

Modified: trunk/src/highlighting.c
===================================================================
--- trunk/src/highlighting.c	2009-11-04 12:36:56 UTC (rev 4395)
+++ trunk/src/highlighting.c	2009-11-04 14:47:07 UTC (rev 4396)
@@ -527,7 +527,7 @@
 }
 
 
-static void read_named_styles(GKeyFile *config, GKeyFile *config_home)
+static void load_named_styles(GKeyFile *config, GKeyFile *config_home)
 {
 	const gchar *scheme = editor_prefs.color_scheme;
 
@@ -562,7 +562,7 @@
 
 static void styleset_common_init(gint ft_id, GKeyFile *config, GKeyFile *config_home)
 {
-	read_named_styles(config, config_home);
+	load_named_styles(config, config_home);
 
 	get_keyfile_style(config, config_home, "default", &common_style_set.styling[GCS_DEFAULT]);
 	get_keyfile_style(config, config_home, "selection", &common_style_set.styling[GCS_SELECTION]);
@@ -3420,46 +3420,13 @@
 }
 
 
-/* TODO: move */
-static void utils_slist_remove_next(GSList *node)
-{
-	GSList *old = node->next;
-
-	g_return_if_fail(old);
-
-	node->next = old->next;
-	g_slist_free_1(old);
-}
-
-
-/* note: color scheme code adapted from custom file template code */
 static gboolean add_color_scheme_items(GtkWidget *menu)
 {
-	gchar *path = g_build_path(G_DIR_SEPARATOR_S, app->configdir, GEANY_COLORSCHEMES_SUBDIR, NULL);
-	GSList *list = utils_get_file_list_full(path, FALSE, FALSE, NULL);
-	GSList *syslist, *node;
+	GSList *list = utils_get_config_files(GEANY_COLORSCHEMES_SUBDIR);
+	GSList *node;
 
-	if (!list)
-	{
-		utils_mkdir(path, FALSE);
-	}
-	setptr(path, g_build_path(G_DIR_SEPARATOR_S, app->datadir, GEANY_COLORSCHEMES_SUBDIR, NULL));
-	syslist = utils_get_file_list_full(path, FALSE, FALSE, NULL);
-	/* merge lists */
-	list = g_slist_concat(list, syslist);
-
-	list = g_slist_sort(list, (GCompareFunc) utils_str_casecmp);
-	/* remove duplicates (next to each other after sorting) */
 	foreach_slist(node, list)
 	{
-		if (node->next && utils_str_equal(node->next->data, node->data))
-		{
-			g_free(node->next->data);
-			utils_slist_remove_next(node);
-		}
-	}
-	foreach_slist(node, list)
-	{
 		gchar *fname = node->data;
 
 		if (g_str_has_suffix(fname, ".conf"))
@@ -3467,7 +3434,6 @@
 		g_free(fname);
 	}
 	g_slist_free(list);
-	g_free(path);
 	return list != NULL;
 }
 

Modified: trunk/src/templates.c
===================================================================
--- trunk/src/templates.c	2009-11-04 12:36:56 UTC (rev 4395)
+++ trunk/src/templates.c	2009-11-04 14:47:07 UTC (rev 4396)
@@ -364,53 +364,19 @@
 }
 
 
-static void utils_slist_remove_next(GSList *node)
-{
-	GSList *old = node->next;
-
-	g_return_if_fail(old);
-
-	node->next = old->next;
-	g_slist_free_1(old);
-}
-
-
 static gboolean add_custom_template_items(void)
 {
-	gchar *path = g_build_path(G_DIR_SEPARATOR_S, app->configdir, GEANY_TEMPLATES_SUBDIR,
-		"files", NULL);
-	GSList *list = utils_get_file_list_full(path, FALSE, FALSE, NULL);
-	GSList *syslist, *node;
+	GSList *list = utils_get_config_files(GEANY_TEMPLATES_SUBDIR G_DIR_SEPARATOR_S "files");
+	GSList *node;
 
-	if (!list)
-	{
-		utils_mkdir(path, FALSE);
-	}
-	setptr(path, g_build_path(G_DIR_SEPARATOR_S, app->datadir, GEANY_TEMPLATES_SUBDIR,
-		"files", NULL));
-	syslist = utils_get_file_list_full(path, FALSE, FALSE, NULL);
-	/* merge lists */
-	list = g_slist_concat(list, syslist);
-
-	list = g_slist_sort(list, (GCompareFunc) utils_str_casecmp);
-	/* remove duplicates (next to each other after sorting) */
 	foreach_slist(node, list)
 	{
-		if (node->next && utils_str_equal(node->next->data, node->data))
-		{
-			g_free(node->next->data);
-			utils_slist_remove_next(node);
-		}
-	}
-	foreach_slist(node, list)
-	{
 		gchar *fname = node->data;
 
 		add_file_item(fname, new_with_template_menu);
 		g_free(fname);
 	}
 	g_slist_free(list);
-	g_free(path);
 	return list != NULL;
 }
 

Modified: trunk/src/utils.c
===================================================================
--- trunk/src/utils.c	2009-11-04 12:36:56 UTC (rev 4395)
+++ trunk/src/utils.c	2009-11-04 14:47:07 UTC (rev 4396)
@@ -1822,3 +1822,45 @@
 }
 
 
+static void utils_slist_remove_next(GSList *node)
+{
+	GSList *old = node->next;
+
+	g_return_if_fail(old);
+
+	node->next = old->next;
+	g_slist_free_1(old);
+}
+
+
+/* Gets list of sorted filenames with no path and no duplicates from user and system config */
+GSList *utils_get_config_files(const gchar *subdir)
+{
+	gchar *path = g_build_path(G_DIR_SEPARATOR_S, app->configdir, subdir, NULL);
+	GSList *list = utils_get_file_list_full(path, FALSE, FALSE, NULL);
+	GSList *syslist, *node;
+
+	if (!list)
+	{
+		utils_mkdir(path, FALSE);
+	}
+	setptr(path, g_build_path(G_DIR_SEPARATOR_S, app->datadir, subdir, NULL));
+	syslist = utils_get_file_list_full(path, FALSE, FALSE, NULL);
+	/* merge lists */
+	list = g_slist_concat(list, syslist);
+
+	list = g_slist_sort(list, (GCompareFunc) utils_str_casecmp);
+	/* remove duplicates (next to each other after sorting) */
+	foreach_slist(node, list)
+	{
+		if (node->next && utils_str_equal(node->next->data, node->data))
+		{
+			g_free(node->next->data);
+			utils_slist_remove_next(node);
+		}
+	}
+	g_free(path);
+	return list;
+}
+
+

Modified: trunk/src/utils.h
===================================================================
--- trunk/src/utils.h	2009-11-04 12:36:56 UTC (rev 4395)
+++ trunk/src/utils.h	2009-11-04 14:47:07 UTC (rev 4396)
@@ -196,6 +196,10 @@
 
 GSList *utils_get_file_list(const gchar *path, guint *length, GError **error);
 
+GSList *utils_get_file_list_full(const gchar *path, gboolean full_path, gboolean sort, GError **error);
+
+GSList *utils_get_config_files(const gchar *subdir);
+
 gboolean utils_str_has_upper(const gchar *str);
 
 gint utils_is_file_writeable(const gchar *locale_filename);
@@ -223,6 +227,4 @@
 
 gchar *utils_str_remove_chars(gchar *string, const gchar *chars);
 
-GSList *utils_get_file_list_full(const gchar *path, gboolean full_path, gboolean sort, GError **error);
-
 #endif


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list