SF.net SVN: geany: [2577] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Wed May 14 11:31:09 UTC 2008


Revision: 2577
          http://geany.svn.sourceforge.net/geany/?rev=2577&view=rev
Author:   ntrel
Date:     2008-05-14 04:31:07 -0700 (Wed, 14 May 2008)

Log Message:
-----------
Sort custom template file menu items by filetype, with None
filetypes first.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/templates.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2008-05-13 17:30:28 UTC (rev 2576)
+++ trunk/ChangeLog	2008-05-14 11:31:07 UTC (rev 2577)
@@ -1,3 +1,10 @@
+2008-05-14  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>
+
+ * src/templates.c:
+   Sort custom template file menu items by filetype, with None
+   filetypes first.
+
+
 2008-05-13  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>
 
  * src/templates.c, src/utils.c, src/ui_utils.h, src/ui_utils.c,

Modified: trunk/src/templates.c
===================================================================
--- trunk/src/templates.c	2008-05-13 17:30:28 UTC (rev 2576)
+++ trunk/src/templates.c	2008-05-14 11:31:07 UTC (rev 2577)
@@ -430,6 +430,26 @@
 }
 
 
+static gint compare_filenames_by_filetype(gconstpointer a, gconstpointer b)
+{
+	filetype *ft_a = filetypes_detect_from_extension(a);
+	filetype *ft_b = filetypes_detect_from_extension(b);
+
+	/* sort by filetype name first */
+	if (ft_a != ft_b)
+	{
+		/* None filetypes should come first */
+		if (ft_a->id == GEANY_FILETYPES_NONE)
+			return -1;
+		if (ft_b->id == GEANY_FILETYPES_NONE)
+			return 1;
+
+		return g_strcasecmp(ft_a->name, ft_b->name);
+	}
+	return g_strcasecmp(a, b);
+}
+
+
 static gboolean add_custom_template_items(void)
 {
 	gchar *path = g_build_path(G_DIR_SEPARATOR_S, app->configdir, GEANY_TEMPLATES_SUBDIR,
@@ -441,6 +461,7 @@
 		utils_mkdir(path, FALSE);
 		return FALSE;
 	}
+	list = g_slist_sort(list, compare_filenames_by_filetype);
 	g_slist_foreach(list, add_file_item, NULL);
 	g_slist_foreach(list, (GFunc) g_free, NULL);
 	g_slist_free(list);


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