[gtk/stringlist] dropdown: Drop the buildable implementation
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/stringlist] dropdown: Drop the buildable implementation
- Date: Tue, 23 Jun 2020 02:34:57 +0000 (UTC)
commit 4ec39655f7be6bc06052ede34cd48aa74fc4260e
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Jun 22 22:28:35 2020 -0400
dropdown: Drop the buildable implementation
Remove the buildable implementation, since we
can just create a string list now and use it as
the model. Update existing users to do this.
gtk/gtkdropdown.c | 210 +------------------------------------------
gtk/gtkstringlist.c | 20 +++++
gtk/ui/gtkprintunixdialog.ui | 30 ++++---
3 files changed, 40 insertions(+), 220 deletions(-)
---
diff --git a/gtk/gtkdropdown.c b/gtk/gtkdropdown.c
index 7cdaea644b..f8f42985bb 100644
--- a/gtk/gtkdropdown.c
+++ b/gtk/gtkdropdown.c
@@ -70,26 +70,6 @@
* useful if the list of options is long. To enable the search entry,
* use gtk_drop_down_set_enable_search().
*
- * # GtkDropDown as GtkBuildable
- *
- * The GtkDropDown implementation of the GtkBuildable interface supports
- * adding items directly using the <items> element and specifying <item>
- * elements for each item. Using <items> is equivalent to calling
- * gtk_drop_down_set_from_strings(). Each <item> element supports
- * the regular translation attributes “translatable”, “context”
- * and “comments”.
- *
- * Here is a UI definition fragment specifying GtkDropDown items:
- * |[
- * <object class="GtkDropDown">
- * <items>
- * <item translatable="yes">Factory</item>
- * <item translatable="yes">Home</item>
- * <item translatable="yes">Subway</item>
- * </items>
- * </object>
- * ]|
- *
* * # CSS nodes
*
* GtkDropDown has a single CSS node with name dropdown,
@@ -139,13 +119,7 @@ enum
N_PROPS
};
-static void gtk_drop_down_buildable_interface_init (GtkBuildableIface *iface);
-
-static GtkBuildableIface *buildable_parent_iface = NULL;
-
-G_DEFINE_TYPE_WITH_CODE (GtkDropDown, gtk_drop_down, GTK_TYPE_WIDGET,
- G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
- gtk_drop_down_buildable_interface_init))
+G_DEFINE_TYPE (GtkDropDown, gtk_drop_down, GTK_TYPE_WIDGET)
static GParamSpec *properties[N_PROPS] = { NULL, };
@@ -973,185 +947,3 @@ gtk_drop_down_set_from_strings (GtkDropDown *self,
gtk_drop_down_set_model (self, model);
g_object_unref (model);
}
-
-typedef struct {
- GtkBuilder *builder;
- GObject *object;
- const gchar *domain;
-
- gchar *context;
- guint translatable : 1;
- guint is_text : 1;
-
- GString *string;
- GPtrArray *strings;
-} ItemParserData;
-
-static void
-item_start_element (GtkBuildableParseContext *context,
- const gchar *element_name,
- const gchar **names,
- const gchar **values,
- gpointer user_data,
- GError **error)
-{
- ItemParserData *data = (ItemParserData*)user_data;
-
- if (strcmp (element_name, "items") == 0)
- {
- if (!_gtk_builder_check_parent (data->builder, context, "object", error))
- return;
-
- if (!g_markup_collect_attributes (element_name, names, values, error,
- G_MARKUP_COLLECT_INVALID, NULL, NULL,
- G_MARKUP_COLLECT_INVALID))
- _gtk_builder_prefix_error (data->builder, context, error);
- }
- else if (strcmp (element_name, "item") == 0)
- {
- gboolean translatable = FALSE;
- const gchar *msg_context = NULL;
-
- if (!_gtk_builder_check_parent (data->builder, context, "items", error))
- return;
-
- if (!g_markup_collect_attributes (element_name, names, values, error,
- G_MARKUP_COLLECT_BOOLEAN|G_MARKUP_COLLECT_OPTIONAL, "translatable",
&translatable,
- G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "comments", NULL,
- G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "context",
&msg_context,
- G_MARKUP_COLLECT_INVALID))
- {
- _gtk_builder_prefix_error (data->builder, context, error);
- return;
- }
-
- data->is_text = TRUE;
- data->translatable = translatable;
- data->context = g_strdup (msg_context);
- }
- else
- {
- _gtk_builder_error_unhandled_tag (data->builder, context,
- "GtkDropDown", element_name,
- error);
- }
-}
-
-static void
-item_text (GtkBuildableParseContext *context,
- const gchar *text,
- gsize text_len,
- gpointer user_data,
- GError **error)
-{
- ItemParserData *data = (ItemParserData*)user_data;
-
- if (data->is_text)
- g_string_append_len (data->string, text, text_len);
-}
-
-static void
-item_end_element (GtkBuildableParseContext *context,
- const gchar *element_name,
- gpointer user_data,
- GError **error)
-{
- ItemParserData *data = (ItemParserData*)user_data;
-
- /* Append the translated strings */
- if (data->string->len)
- {
- if (data->translatable)
- {
- const gchar *translated;
-
- translated = _gtk_builder_parser_translate (data->domain,
- data->context,
- data->string->str);
- g_string_assign (data->string, translated);
- }
-
- g_ptr_array_add (data->strings, g_strdup (data->string->str));
- }
-
- data->translatable = FALSE;
- g_string_set_size (data->string, 0);
- g_clear_pointer (&data->context, g_free);
- data->is_text = FALSE;
-}
-
-static const GtkBuildableParser item_parser =
-{
- item_start_element,
- item_end_element,
- item_text
-};
-
-static gboolean
-gtk_drop_down_buildable_custom_tag_start (GtkBuildable *buildable,
- GtkBuilder *builder,
- GObject *child,
- const gchar *tagname,
- GtkBuildableParser *parser,
- gpointer *parser_data)
-{
- if (buildable_parent_iface->custom_tag_start (buildable, builder, child,
- tagname, parser, parser_data))
- return TRUE;
-
- if (strcmp (tagname, "items") == 0)
- {
- ItemParserData *data;
-
- data = g_slice_new0 (ItemParserData);
- data->builder = g_object_ref (builder);
- data->object = g_object_ref (G_OBJECT (buildable));
- data->domain = gtk_builder_get_translation_domain (builder);
- data->string = g_string_new ("");
- data->strings = g_ptr_array_new_with_free_func (g_free);
-
- *parser = item_parser;
- *parser_data = data;
-
- return TRUE;
- }
-
- return FALSE;
-}
-
-static void
-gtk_drop_down_buildable_custom_finished (GtkBuildable *buildable,
- GtkBuilder *builder,
- GObject *child,
- const gchar *tagname,
- gpointer user_data)
-{
- ItemParserData *data;
-
- buildable_parent_iface->custom_finished (buildable, builder, child,
- tagname, user_data);
-
- if (strcmp (tagname, "items") == 0)
- {
- data = (ItemParserData*)user_data;
-
- g_ptr_array_add (data->strings, NULL);
-
- gtk_drop_down_set_from_strings (GTK_DROP_DOWN (data->object), (const char **)data->strings->pdata);
-
- g_object_unref (data->object);
- g_object_unref (data->builder);
- g_string_free (data->string, TRUE);
- g_ptr_array_unref (data->strings);
- g_slice_free (ItemParserData, data);
- }
-}
-
-static void
-gtk_drop_down_buildable_interface_init (GtkBuildableIface *iface)
-{
- buildable_parent_iface = g_type_interface_peek_parent (iface);
-
- iface->custom_tag_start = gtk_drop_down_buildable_custom_tag_start;
- iface->custom_finished = gtk_drop_down_buildable_custom_finished;
-}
diff --git a/gtk/gtkstringlist.c b/gtk/gtkstringlist.c
index ea6fea0c5b..58a36ec85a 100644
--- a/gtk/gtkstringlist.c
+++ b/gtk/gtkstringlist.c
@@ -35,6 +35,26 @@
* #GtkStringList is a list model that wraps an array of strings.
*
* The objects in the model have a "string" property.
+ *
+ * # GtkStringList as GtkBuildable
+ *
+ * The GtkStringList implementation of the GtkBuildable interface
+ * supports adding items directly using the <items> element and
+ * specifying <item> elements for each item. Each <item> element
+ * supports the regular translation attributes “translatable”,
+ * “context” and “comments”.
+ *
+ * Here is a UI definition fragment specifying a GtkStringList
+ * |[
+ * <object class="GtkStringList">
+ * <items>
+ * <item translatable="yes">Factory</item>
+ * <item translatable="yes">Home</item>
+ * <item translatable="yes">Subway</item>
+ * </items>
+ * </object>
+ * ]|
+
*/
struct _GtkStringObject
diff --git a/gtk/ui/gtkprintunixdialog.ui b/gtk/ui/gtkprintunixdialog.ui
index 2910e526ea..6d086c9da8 100644
--- a/gtk/ui/gtkprintunixdialog.ui
+++ b/gtk/ui/gtkprintunixdialog.ui
@@ -511,11 +511,15 @@
<object class="GtkDropDown" id="page_set_combo">
<property name="valign">baseline</property>
<property name="selected">0</property>
- <items>
- <item translatable="yes">All sheets</item>
- <item translatable="yes">Even sheets</item>
- <item translatable="yes">Odd sheets</item>
- </items>
+ <property name="model">
+ <object class="GtkStringList">
+ <items>
+ <item translatable="yes">All sheets</item>
+ <item translatable="yes">Even sheets</item>
+ <item translatable="yes">Odd sheets</item>
+ </items>
+ </object>
+ </property>
<layout>
<property name="left-attach">1</property>
<property name="top-attach">3</property>
@@ -695,12 +699,16 @@
<property name="sensitive">0</property>
<property name="selected">0</property>
<property name="valign">baseline</property>
- <items>
- <item translatable="yes">Portrait</item>
- <item translatable="yes">Landscape</item>
- <item translatable="yes">Reverse portrait</item>
- <item translatable="yes">Reverse landscape</item>
- </items>
+ <property name="model">
+ <object class="GtkStringList">
+ <items>
+ <item translatable="yes">Portrait</item>
+ <item translatable="yes">Landscape</item>
+ <item translatable="yes">Reverse portrait</item>
+ <item translatable="yes">Reverse landscape</item>
+ </items>
+ </object>
+ </property>
<layout>
<property name="left-attach">1</property>
<property name="top-attach">4</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]