Kaydet (Commit) 22038400 authored tarafından Nick Treleaven's avatar Nick Treleaven

Add filetypes_get_sorted_by_name() to API.

Fix --ft-names sorting to print in name order, not title order.



git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5649 ea778897-0a13-0410-b9d1-a72fbfd435f5
üst acc3e96e
......@@ -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>
......
......@@ -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 \
......
......@@ -56,7 +56,8 @@ static GHashTable *filetypes_hash = NULL; /* Hash of filetype pointers based on
/** 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 GeanyFiletype *filetype_new(void)
}
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,7 +510,28 @@ static gint cmp_filetype(gconstpointer pft1, gconstpointer pft2)
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;
}
......@@ -607,7 +630,8 @@ void filetypes_init_types()
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));
}
......
......@@ -182,6 +182,8 @@ void filetypes_reload(void);
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);
......
......@@ -472,12 +472,13 @@ void main_locale_init(const gchar *locale_dir, const gchar *package)
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;
......
......@@ -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 @@ typedef struct FiletypeFuncs
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 */
}
......
......@@ -305,7 +305,8 @@ static FiletypeFuncs filetype_funcs = {
&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 = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment