Bug 653907 - Help-browser fails to sort top-level items
Sort help-browser items by a new attribute "sort", if available (to be provided by the "gimp-help.xml" file).
This commit is contained in:
@ -360,38 +360,57 @@ browser_dialog_make_index_foreach (const gchar *help_id,
|
|||||||
GimpHelpItem *item,
|
GimpHelpItem *item,
|
||||||
GimpHelpLocale *locale)
|
GimpHelpLocale *locale)
|
||||||
{
|
{
|
||||||
#if 0
|
gchar *sort_key = item->title;
|
||||||
|
#if DEBUG_SORT_HELP_ITEMS
|
||||||
g_printerr ("%s: processing %s (parent %s)\n",
|
g_printerr ("%s: processing %s (parent %s)\n",
|
||||||
G_STRFUNC,
|
G_STRFUNC,
|
||||||
item->title ? item->title : "NULL",
|
item->title ? item->title : "NULL",
|
||||||
item->parent ? item->parent : "NULL");
|
item->parent ? item->parent : "NULL");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (item->title)
|
if (item->sort &&
|
||||||
|
g_regex_match_simple("^[0-9]+([.][0-9]+)*$", item->sort, 0, 0))
|
||||||
{
|
{
|
||||||
gchar **indices = g_strsplit (item->title, ".", -1);
|
sort_key = item->sort;
|
||||||
|
#if DEBUG_SORT_HELP_ITEMS
|
||||||
|
g_printerr("%s: sort key = %s\n", G_STRFUNC, sort_key);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
item->index = 0;
|
||||||
|
|
||||||
|
if (sort_key)
|
||||||
|
{
|
||||||
|
const gint max_tokens = GIMP_HELP_BROWSER_INDEX_MAX_DEPTH;
|
||||||
|
gchar* *indices = g_strsplit (sort_key, ".", max_tokens + 1);
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
for (i = 0; i < 5; i++)
|
for (i = 0; i < max_tokens; i++)
|
||||||
{
|
{
|
||||||
gunichar c;
|
gunichar c;
|
||||||
|
|
||||||
if (! indices[i])
|
if (! indices[i])
|
||||||
break;
|
{
|
||||||
|
/* make sure that all item->index's are comparable */
|
||||||
|
item->index <<= (8 * (max_tokens - i));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
item->index <<= 8; /* NOP if i = 0 */
|
||||||
c = g_utf8_get_char (indices[i]);
|
c = g_utf8_get_char (indices[i]);
|
||||||
|
|
||||||
if (g_unichar_isdigit (c))
|
if (g_unichar_isdigit (c))
|
||||||
{
|
{
|
||||||
item->index += atoi (indices[i]) << (8 * (5 - i));
|
item->index += atoi (indices[i]);
|
||||||
}
|
}
|
||||||
else if (g_utf8_strlen (indices[i], -1) == 1)
|
else if (g_utf8_strlen (indices[i], -1) == 1)
|
||||||
{
|
{
|
||||||
item->index += (c & 0xFF) << (8 * (5 - i));
|
item->index += (c & 0xFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_strfreev (indices);
|
g_strfreev (indices);
|
||||||
|
#if DEBUG_SORT_HELP_ITEMS
|
||||||
|
g_printerr("%s: index = %lu\n", G_STRFUNC, item->index);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item->parent && strlen (item->parent))
|
if (item->parent && strlen (item->parent))
|
||||||
|
@ -46,12 +46,14 @@
|
|||||||
GimpHelpItem *
|
GimpHelpItem *
|
||||||
gimp_help_item_new (const gchar *ref,
|
gimp_help_item_new (const gchar *ref,
|
||||||
const gchar *title,
|
const gchar *title,
|
||||||
|
const gchar *sort,
|
||||||
const gchar *parent)
|
const gchar *parent)
|
||||||
{
|
{
|
||||||
GimpHelpItem *item = g_slice_new0 (GimpHelpItem);
|
GimpHelpItem *item = g_slice_new0 (GimpHelpItem);
|
||||||
|
|
||||||
item->ref = g_strdup (ref);
|
item->ref = g_strdup (ref);
|
||||||
item->title = g_strdup (title);
|
item->title = g_strdup (title);
|
||||||
|
item->sort = g_strdup (sort);
|
||||||
item->parent = g_strdup (parent);
|
item->parent = g_strdup (parent);
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
@ -62,6 +64,7 @@ gimp_help_item_free (GimpHelpItem *item)
|
|||||||
{
|
{
|
||||||
g_free (item->ref);
|
g_free (item->ref);
|
||||||
g_free (item->title);
|
g_free (item->title);
|
||||||
|
g_free (item->sort);
|
||||||
g_free (item->parent);
|
g_free (item->parent);
|
||||||
|
|
||||||
g_list_free (item->children);
|
g_list_free (item->children);
|
||||||
|
@ -28,16 +28,18 @@ struct _GimpHelpItem
|
|||||||
{
|
{
|
||||||
gchar *ref;
|
gchar *ref;
|
||||||
gchar *title;
|
gchar *title;
|
||||||
|
gchar *sort; /* optional sort key provided by doc team */
|
||||||
gchar *parent;
|
gchar *parent;
|
||||||
|
|
||||||
/* extra fields used by the help-browser */
|
/* extra fields used by the help-browser */
|
||||||
GList *children;
|
GList *children;
|
||||||
gint index;
|
gulong index;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
GimpHelpItem * gimp_help_item_new (const gchar *ref,
|
GimpHelpItem * gimp_help_item_new (const gchar *ref,
|
||||||
const gchar *title,
|
const gchar *title,
|
||||||
|
const gchar *sort,
|
||||||
const gchar *parent);
|
const gchar *parent);
|
||||||
void gimp_help_item_free (GimpHelpItem *item);
|
void gimp_help_item_free (GimpHelpItem *item);
|
||||||
|
|
||||||
|
@ -451,6 +451,7 @@ locale_parser_parse_item (LocaleParser *parser,
|
|||||||
const gchar *id = NULL;
|
const gchar *id = NULL;
|
||||||
const gchar *ref = NULL;
|
const gchar *ref = NULL;
|
||||||
const gchar *title = NULL;
|
const gchar *title = NULL;
|
||||||
|
const gchar *sort = NULL; /* optional sort key provided by doc team */
|
||||||
const gchar *parent = NULL;
|
const gchar *parent = NULL;
|
||||||
|
|
||||||
for (; *names && *values; names++, values++)
|
for (; *names && *values; names++, values++)
|
||||||
@ -464,6 +465,9 @@ locale_parser_parse_item (LocaleParser *parser,
|
|||||||
if (! strcmp (*names, "title"))
|
if (! strcmp (*names, "title"))
|
||||||
title = *values;
|
title = *values;
|
||||||
|
|
||||||
|
if (! strcmp (*names, "sort"))
|
||||||
|
sort = *values;
|
||||||
|
|
||||||
if (! strcmp (*names, "parent"))
|
if (! strcmp (*names, "parent"))
|
||||||
parent = *values;
|
parent = *values;
|
||||||
}
|
}
|
||||||
@ -479,7 +483,7 @@ locale_parser_parse_item (LocaleParser *parser,
|
|||||||
|
|
||||||
g_hash_table_insert (parser->locale->help_id_mapping,
|
g_hash_table_insert (parser->locale->help_id_mapping,
|
||||||
g_strdup (id),
|
g_strdup (id),
|
||||||
gimp_help_item_new (ref, title, parent));
|
gimp_help_item_new (ref, title, sort, parent));
|
||||||
|
|
||||||
#ifdef GIMP_HELP_DEBUG
|
#ifdef GIMP_HELP_DEBUG
|
||||||
g_printerr ("help (%s): added mapping \"%s\" -> \"%s\"\n",
|
g_printerr ("help (%s): added mapping \"%s\" -> \"%s\"\n",
|
||||||
|
Reference in New Issue
Block a user