forked from AuroraMiddleware/gtk
Fix GtkComboBoxText GtkBuildable <items> parsing to handle incomming text accumulatively
This commit is contained in:
parent
8397a79b7d
commit
e8157126d8
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user