Commit e8157126 authored by Tristan Van Berkom's avatar Tristan Van Berkom

Fix GtkComboBoxText GtkBuildable <items> parsing to handle incomming text accumulatively

parent 8397a79b
......@@ -151,8 +151,9 @@ typedef struct {
GObject *object;
const gchar *domain;
GString *string;
gchar *context;
gchar *string;
guint translatable : 1;
guint is_text : 1;
......@@ -211,23 +212,8 @@ item_text (GMarkupParseContext *context,
return;
string = g_strndup (text, text_len);
if (data->translatable && text_len)
{
gchar *translated;
/* FIXME: This will not use the domain set in the .ui file,
* since the parser is not telling the builder about the domain.
* However, it will work for gtk_builder_set_translation_domain() calls.
*/
translated = _gtk_builder_parser_translate (data->domain,
data->context,
string);
g_free (string);
string = translated;
}
data->string = string;
g_string_append (data->string, string);
g_free (string);
}
static void
......@@ -239,14 +225,30 @@ item_end_element (GMarkupParseContext *context,
ItemParserData *data = (ItemParserData*)user_data;
/* Append the translated strings */
if (data->string)
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (data->object), data->string);
if (data->string->len)
{
if (data->translatable)
{
gchar *translated;
/* FIXME: This will not use the domain set in the .ui file,
* since the parser is not telling the builder about the domain.
* However, it will work for gtk_builder_set_translation_domain() calls.
*/
translated = _gtk_builder_parser_translate (data->domain,
data->context,
data->string->str);
g_string_set_size (data->string, 0);
g_string_append (data->string, translated);
}
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (data->object), data->string->str);
}
data->translatable = FALSE;
g_string_set_size (data->string, 0);
g_free (data->context);
g_free (data->string);
data->context = NULL;
data->string = NULL;
data->is_text = FALSE;
}
......@@ -277,6 +279,7 @@ gtk_combo_box_text_buildable_custom_tag_start (GtkBuildable *buildable,
parser_data->builder = g_object_ref (builder);
parser_data->object = g_object_ref (buildable);
parser_data->domain = gtk_builder_get_translation_domain (builder);
parser_data->string = g_string_new ("");
*parser = item_parser;
*data = parser_data;
return TRUE;
......@@ -302,6 +305,7 @@ gtk_combo_box_text_buildable_custom_finished (GtkBuildable *buildable,
g_object_unref (data->object);
g_object_unref (data->builder);
g_string_free (data->string, TRUE);
g_slice_free (ItemParserData, data);
}
}
......
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