SF.net SVN: geany:[5649] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Tue Mar 29 18:06:26 UTC 2011


Revision: 5649
          http://geany.svn.sourceforge.net/geany/?rev=5649&view=rev
Author:   ntrel
Date:     2011-03-29 18:06:26 +0000 (Tue, 29 Mar 2011)

Log Message:
-----------
Add filetypes_get_sorted_by_name() to API.
Fix --ft-names sorting to print in name order, not title order.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/plugins/geanyfunctions.h
    trunk/src/filetypes.c
    trunk/src/filetypes.h
    trunk/src/main.c
    trunk/src/plugindata.h
    trunk/src/plugins.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2011-03-29 17:55:26 UTC (rev 5648)
+++ trunk/ChangeLog	2011-03-29 18:06:26 UTC (rev 5649)
@@ -6,6 +6,10 @@
  * doc/geany.txt, doc/geany.html:
    Add #filenames subsection for filetype definition files explaining
    the filename extensions and special cases.
+ * src/plugindata.h, src/filetypes.c, src/filetypes.h, src/plugins.c,
+   src/main.c, plugins/geanyfunctions.h:
+   Add filetypes_get_sorted_by_name() to API.
+   Fix --ft-names sorting to print in name order, not title order.
 
 
 2011-03-28  Colomban Wendling  <colomban(at)geany(dot)org>

Modified: trunk/plugins/geanyfunctions.h
===================================================================
--- trunk/plugins/geanyfunctions.h	2011-03-29 17:55:26 UTC (rev 5648)
+++ trunk/plugins/geanyfunctions.h	2011-03-29 18:06:26 UTC (rev 5649)
@@ -352,6 +352,8 @@
 	geany_functions->p_filetypes->filetypes_index
 #define filetypes_get_display_name \
 	geany_functions->p_filetypes->filetypes_get_display_name
+#define filetypes_get_sorted_by_name \
+	geany_functions->p_filetypes->filetypes_get_sorted_by_name
 #define navqueue_goto_line \
 	geany_functions->p_navqueue->navqueue_goto_line
 #define main_reload_configuration \

Modified: trunk/src/filetypes.c
===================================================================
--- trunk/src/filetypes.c	2011-03-29 17:55:26 UTC (rev 5648)
+++ trunk/src/filetypes.c	2011-03-29 18:06:26 UTC (rev 5649)
@@ -56,7 +56,8 @@
 /** 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. */
+ * @code g_slist_nth_data(filetypes_by_title, n) @endcode and expect the same result at different times.
+ * @see filetypes_get_sorted_by_name(). */
 GSList *filetypes_by_title = NULL;
 
 
@@ -499,8 +500,9 @@
 }
 
 
-static gint cmp_filetype(gconstpointer pft1, gconstpointer pft2)
+static gint cmp_filetype(gconstpointer pft1, gconstpointer pft2, gpointer data)
 {
+	gboolean by_name = GPOINTER_TO_INT(data);
 	const GeanyFiletype *ft1 = pft1, *ft2 = pft2;
 
 	if (G_UNLIKELY(ft1->id == GEANY_FILETYPES_NONE))
@@ -508,10 +510,31 @@
 	if (G_UNLIKELY(ft2->id == GEANY_FILETYPES_NONE))
 		return 1;
 
-	return utils_str_casecmp(ft1->title, ft2->title);
+	return by_name ?
+		utils_str_casecmp(ft1->name, ft2->name) :
+		utils_str_casecmp(ft1->title, ft2->title);
 }
 
 
+/** Gets a list of filetype pointers sorted by name.
+ * The list does not change on subsequent calls.
+ * @return The list - do not free.
+ * @see filetypes_by_title. */
+const GSList *filetypes_get_sorted_by_name(void)
+{
+	static GSList *list = NULL;
+
+	g_return_val_if_fail(filetypes_by_title, NULL);
+
+	if (!list)
+	{
+		list = g_slist_copy(filetypes_by_title);
+		list = g_slist_sort_with_data(list, cmp_filetype, GINT_TO_POINTER(TRUE));
+	}
+	return list;
+}
+
+
 /* Add a filetype pointer to the lists of available filetypes,
  * and set the filetype::id field. */
 static void filetype_add(GeanyFiletype *ft)
@@ -607,7 +630,8 @@
 	init_custom_filetypes(utils_build_path(app->configdir, GEANY_FILEDEFS_SUBDIR, NULL));
 
 	/* sort last instead of on insertion to prevent exponential time */
-	filetypes_by_title = g_slist_sort(filetypes_by_title, cmp_filetype);
+	filetypes_by_title = g_slist_sort_with_data(filetypes_by_title,
+		cmp_filetype, GINT_TO_POINTER(FALSE));
 }
 
 

Modified: trunk/src/filetypes.h
===================================================================
--- trunk/src/filetypes.h	2011-03-29 17:55:26 UTC (rev 5648)
+++ trunk/src/filetypes.h	2011-03-29 18:06:26 UTC (rev 5649)
@@ -182,6 +182,8 @@
 
 GeanyFiletype *filetypes_index(gint idx);
 
+const GSList *filetypes_get_sorted_by_name(void);
+
 const gchar *filetypes_get_display_name(GeanyFiletype *ft);
 
 GeanyFiletype *filetypes_detect_from_document(GeanyDocument *doc);

Modified: trunk/src/main.c
===================================================================
--- trunk/src/main.c	2011-03-29 17:55:26 UTC (rev 5648)
+++ trunk/src/main.c	2011-03-29 18:06:26 UTC (rev 5649)
@@ -472,12 +472,13 @@
 
 static void print_filetypes(void)
 {
-	GSList *node;
+	const GSList *list, *node;
 
 	filetypes_init_types();
 	printf("Geany's filetype names:\n");
 
-	foreach_slist(node, filetypes_by_title)
+	list = filetypes_get_sorted_by_name();
+	foreach_slist(node, list)
 	{
 		GeanyFiletype *ft = node->data;
 

Modified: trunk/src/plugindata.h
===================================================================
--- trunk/src/plugindata.h	2011-03-29 17:55:26 UTC (rev 5648)
+++ trunk/src/plugindata.h	2011-03-29 18:06:26 UTC (rev 5649)
@@ -54,7 +54,7 @@
  * @warning You should not test for values below 200 as previously
  * @c GEANY_API_VERSION was defined as an enum value, not a macro.
  */
-#define GEANY_API_VERSION 203
+#define GEANY_API_VERSION 204
 
 /** The Application Binary Interface (ABI) version, incremented whenever
  * existing fields in the plugin data types have to be changed or reordered.
@@ -561,6 +561,7 @@
 	GeanyFiletype*	(*filetypes_lookup_by_name) (const gchar *name);
 	GeanyFiletype*	(*filetypes_index)(gint idx);
 	const gchar*	(*filetypes_get_display_name)(GeanyFiletype *ft);
+	const GSList*	(*filetypes_get_sorted_by_name)(void);
 	/* Remember to convert any filetype_id arguments to GeanyFiletype pointers in any
 	 * appended functions */
 }

Modified: trunk/src/plugins.c
===================================================================
--- trunk/src/plugins.c	2011-03-29 17:55:26 UTC (rev 5648)
+++ trunk/src/plugins.c	2011-03-29 18:06:26 UTC (rev 5649)
@@ -305,7 +305,8 @@
 	&filetypes_detect_from_file,
 	&filetypes_lookup_by_name,
 	&filetypes_index,
-	&filetypes_get_display_name
+	&filetypes_get_display_name,
+	&filetypes_get_sorted_by_name
 };
 
 static NavQueueFuncs navqueue_funcs = {


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