mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-10 02:40:11 +00:00
buildable: Rename set_name() to set_buildable_id()
GtkBuildable's get_name()/set_name() methods may shadow GtkWidget's methods. Avoid that by renaming the API to get_buildable_id()/set_buildable_id(), which also reflects the name of the XML attribute the API refers to. https://gitlab.gnome.org/GNOME/gtk/-/issues/3191
This commit is contained in:
parent
a9de1d702e
commit
12189bc10f
@ -1398,7 +1398,7 @@ handle_insert (GtkWidget *button, GtkWidget *textview)
|
||||
const char *id;
|
||||
const char *text;
|
||||
|
||||
id = gtk_buildable_get_name (GTK_BUILDABLE (button));
|
||||
id = gtk_buildable_get_buildable_id (GTK_BUILDABLE (button));
|
||||
|
||||
if (strcmp (id, "toolbutton1") == 0)
|
||||
text = "⌘";
|
||||
@ -1424,7 +1424,7 @@ handle_cutcopypaste (GtkWidget *button, GtkWidget *textview)
|
||||
|
||||
clipboard = gtk_widget_get_clipboard (textview);
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));
|
||||
id = gtk_buildable_get_name (GTK_BUILDABLE (button));
|
||||
id = gtk_buildable_get_buildable_id (GTK_BUILDABLE (button));
|
||||
|
||||
if (strcmp (id, "cutbutton") == 0)
|
||||
gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
|
||||
@ -1442,7 +1442,7 @@ clipboard_formats_notify (GdkClipboard *clipboard, GdkEvent *event, GtkWidget *b
|
||||
const char *id;
|
||||
gboolean has_text;
|
||||
|
||||
id = gtk_buildable_get_name (GTK_BUILDABLE (button));
|
||||
id = gtk_buildable_get_buildable_id (GTK_BUILDABLE (button));
|
||||
has_text = gdk_content_formats_contain_gtype (gdk_clipboard_get_formats (clipboard), GTK_TYPE_TEXT_BUFFER);
|
||||
|
||||
if (strcmp (id, "pastebutton") == 0)
|
||||
@ -1455,7 +1455,7 @@ textbuffer_notify_selection (GObject *object, GParamSpec *pspec, GtkWidget *butt
|
||||
const char *id;
|
||||
gboolean has_selection;
|
||||
|
||||
id = gtk_buildable_get_name (GTK_BUILDABLE (button));
|
||||
id = gtk_buildable_get_buildable_id (GTK_BUILDABLE (button));
|
||||
has_selection = gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (object));
|
||||
|
||||
if (strcmp (id, "cutbutton") == 0 ||
|
||||
|
@ -617,8 +617,8 @@ gtk_grid_view_get_type
|
||||
GtkBuildable
|
||||
GtkBuildableIface
|
||||
GtkBuildableParser
|
||||
gtk_buildable_set_name
|
||||
gtk_buildable_get_name
|
||||
gtk_buildable_set_buildable_id
|
||||
gtk_buildable_get_buildable_id
|
||||
gtk_buildable_add_child
|
||||
gtk_buildable_set_buildable_property
|
||||
gtk_buildable_construct_child
|
||||
|
@ -49,46 +49,46 @@ gtk_buildable_default_init (GtkBuildableInterface *iface)
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_buildable_set_name:
|
||||
* gtk_buildable_set_buildable_id:
|
||||
* @buildable: a #GtkBuildable
|
||||
* @name: name to set
|
||||
* @id: name to set
|
||||
*
|
||||
* Sets the name of the @buildable object.
|
||||
* Sets the ID of the @buildable object.
|
||||
**/
|
||||
void
|
||||
gtk_buildable_set_name (GtkBuildable *buildable,
|
||||
const char *name)
|
||||
gtk_buildable_set_buildable_id (GtkBuildable *buildable,
|
||||
const char *id)
|
||||
{
|
||||
GtkBuildableIface *iface;
|
||||
|
||||
g_return_if_fail (GTK_IS_BUILDABLE (buildable));
|
||||
g_return_if_fail (name != NULL);
|
||||
g_return_if_fail (id != NULL);
|
||||
|
||||
iface = GTK_BUILDABLE_GET_IFACE (buildable);
|
||||
|
||||
if (iface->set_name)
|
||||
(* iface->set_name) (buildable, name);
|
||||
if (iface->set_id)
|
||||
(* iface->set_id) (buildable, id);
|
||||
else
|
||||
g_object_set_data_full (G_OBJECT (buildable),
|
||||
"gtk-builder-name",
|
||||
g_strdup (name),
|
||||
"gtk-builder-id",
|
||||
g_strdup (id),
|
||||
g_free);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_buildable_get_name:
|
||||
* gtk_buildable_get_buildable_id:
|
||||
* @buildable: a #GtkBuildable
|
||||
*
|
||||
* Gets the name of the @buildable object.
|
||||
* Gets the ID of the @buildable object.
|
||||
*
|
||||
* #GtkBuilder sets the name based on the
|
||||
* [GtkBuilder UI definition][BUILDER-UI]
|
||||
* used to construct the @buildable.
|
||||
*
|
||||
* Returns: the name set with gtk_buildable_set_name()
|
||||
* Returns: the ID set with gtk_buildable_set_buildable_id()
|
||||
**/
|
||||
const char *
|
||||
gtk_buildable_get_name (GtkBuildable *buildable)
|
||||
gtk_buildable_get_buildable_id (GtkBuildable *buildable)
|
||||
{
|
||||
GtkBuildableIface *iface;
|
||||
|
||||
@ -96,11 +96,11 @@ gtk_buildable_get_name (GtkBuildable *buildable)
|
||||
|
||||
iface = GTK_BUILDABLE_GET_IFACE (buildable);
|
||||
|
||||
if (iface->get_name)
|
||||
return (* iface->get_name) (buildable);
|
||||
if (iface->get_id)
|
||||
return (* iface->get_id) (buildable);
|
||||
else
|
||||
return (const char *)g_object_get_data (G_OBJECT (buildable),
|
||||
"gtk-builder-name");
|
||||
"gtk-builder-id");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,12 +76,12 @@ struct _GtkBuildableParser
|
||||
/**
|
||||
* GtkBuildableIface:
|
||||
* @g_iface: the parent class
|
||||
* @set_name: Stores the name attribute given in the GtkBuilder UI definition.
|
||||
* @set_id: Stores the id attribute given in the GtkBuilder UI definition.
|
||||
* #GtkWidget stores the name as object data. Implement this method if your
|
||||
* object has some notion of “name” and it makes sense to map the XML name
|
||||
* object has some notion of “ID” and it makes sense to map the XML id
|
||||
* attribute to it.
|
||||
* @get_name: The getter corresponding to @set_name. Implement this
|
||||
* if you implement @set_name.
|
||||
* @get_id: The getter corresponding to @set_id. Implement this
|
||||
* if you implement @set_id.
|
||||
* @add_child: Adds a child. The @type parameter can be used to
|
||||
* differentiate the kind of child. #GtkWidget implements this
|
||||
* to add event controllers to the widget, #GtkNotebook uses
|
||||
@ -126,9 +126,9 @@ struct _GtkBuildableIface
|
||||
GTypeInterface g_iface;
|
||||
|
||||
/* virtual table */
|
||||
void (* set_name) (GtkBuildable *buildable,
|
||||
const char *name);
|
||||
const char * (* get_name) (GtkBuildable *buildable);
|
||||
void (* set_id) (GtkBuildable *buildable,
|
||||
const char *id);
|
||||
const char * (* get_id) (GtkBuildable *buildable);
|
||||
void (* add_child) (GtkBuildable *buildable,
|
||||
GtkBuilder *builder,
|
||||
GObject *child,
|
||||
@ -169,10 +169,10 @@ GDK_AVAILABLE_IN_ALL
|
||||
GType gtk_buildable_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_buildable_set_name (GtkBuildable *buildable,
|
||||
const char *name);
|
||||
void gtk_buildable_set_buildable_id (GtkBuildable *buildable,
|
||||
const char *id);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
const char * gtk_buildable_get_name (GtkBuildable *buildable);
|
||||
const char * gtk_buildable_get_buildable_id (GtkBuildable *buildable);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_buildable_add_child (GtkBuildable *buildable,
|
||||
GtkBuilder *builder,
|
||||
|
@ -623,12 +623,12 @@ gtk_builder_get_parameters (GtkBuilder *builder,
|
||||
}
|
||||
|
||||
static const char *
|
||||
object_get_name (GObject *object)
|
||||
object_get_id (GObject *object)
|
||||
{
|
||||
if (GTK_IS_BUILDABLE (object))
|
||||
return gtk_buildable_get_name (GTK_BUILDABLE (object));
|
||||
return gtk_buildable_get_buildable_id (GTK_BUILDABLE (object));
|
||||
else
|
||||
return g_object_get_data (object, "gtk-builder-name");
|
||||
return g_object_get_data (object, "gtk-builder-id");
|
||||
}
|
||||
|
||||
static GObject *
|
||||
@ -650,7 +650,7 @@ gtk_builder_get_internal_child (GtkBuilder *builder,
|
||||
|
||||
GTK_NOTE (BUILDER,
|
||||
g_message ("Trying to get internal child %s from %s",
|
||||
childname, object_get_name (info->object)));
|
||||
childname, object_get_id (info->object)));
|
||||
|
||||
if (GTK_IS_BUILDABLE (info->object))
|
||||
obj = gtk_buildable_get_internal_child (GTK_BUILDABLE (info->object),
|
||||
@ -669,13 +669,13 @@ gtk_builder_get_internal_child (GtkBuilder *builder,
|
||||
}
|
||||
|
||||
static inline void
|
||||
object_set_name (GObject *object,
|
||||
const char *name)
|
||||
object_set_id (GObject *object,
|
||||
const char *id)
|
||||
{
|
||||
if (GTK_IS_BUILDABLE (object))
|
||||
gtk_buildable_set_name (GTK_BUILDABLE (object), name);
|
||||
gtk_buildable_set_buildable_id (GTK_BUILDABLE (object), id);
|
||||
else
|
||||
g_object_set_data_full (object, "gtk-builder-name", g_strdup (name), g_free);
|
||||
g_object_set_data_full (object, "gtk-builder-id", g_strdup (id), g_free);
|
||||
}
|
||||
|
||||
void
|
||||
@ -685,7 +685,7 @@ _gtk_builder_add_object (GtkBuilder *builder,
|
||||
{
|
||||
GtkBuilderPrivate *priv = gtk_builder_get_instance_private (builder);
|
||||
|
||||
object_set_name (object, id);
|
||||
object_set_id (object, id);
|
||||
g_hash_table_insert (priv->objects, g_strdup (id), g_object_ref (object));
|
||||
}
|
||||
|
||||
@ -984,7 +984,7 @@ _gtk_builder_add (GtkBuilder *builder,
|
||||
|
||||
if (!child_info->parent)
|
||||
{
|
||||
g_warning ("%s: Not adding, No parent", object_get_name (object));
|
||||
g_warning ("%s: Not adding, No parent", object_get_id (object));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -993,7 +993,7 @@ _gtk_builder_add (GtkBuilder *builder,
|
||||
parent = ((ObjectInfo*)child_info->parent)->object;
|
||||
|
||||
GTK_NOTE (BUILDER,
|
||||
g_message ("adding %s to %s", object_get_name (object), object_get_name (parent)));
|
||||
g_message ("adding %s to %s", object_get_id (object), object_get_id (parent)));
|
||||
|
||||
if (G_IS_LIST_STORE (parent))
|
||||
{
|
||||
@ -1735,7 +1735,7 @@ gtk_builder_expose_object (GtkBuilder *builder,
|
||||
g_return_if_fail (name && name[0]);
|
||||
g_return_if_fail (!g_hash_table_contains (priv->objects, name));
|
||||
|
||||
object_set_name (object, name);
|
||||
object_set_id (object, name);
|
||||
g_hash_table_insert (priv->objects,
|
||||
g_strdup (name),
|
||||
g_object_ref (object));
|
||||
|
@ -2511,7 +2511,7 @@ list_store_end_element (GtkBuildableParseContext *context,
|
||||
{
|
||||
g_warning ("Unknown type %s specified in treemodel %s",
|
||||
(const char *)l->data,
|
||||
gtk_buildable_get_name (GTK_BUILDABLE (data->object)));
|
||||
gtk_buildable_get_buildable_id (GTK_BUILDABLE (data->object)));
|
||||
continue;
|
||||
}
|
||||
column_types[i] = type;
|
||||
|
@ -3389,7 +3389,7 @@ tree_model_end_element (GtkBuildableParseContext *context,
|
||||
{
|
||||
g_warning ("Unknown type %s specified in treemodel %s",
|
||||
(const char *)l->data,
|
||||
gtk_buildable_get_name (GTK_BUILDABLE (data->object)));
|
||||
gtk_buildable_get_buildable_id (GTK_BUILDABLE (data->object)));
|
||||
continue;
|
||||
}
|
||||
types[i] = type;
|
||||
|
@ -604,9 +604,9 @@ static void gtk_widget_real_state_flags_changed (GtkWidget
|
||||
static void gtk_widget_accessible_interface_init (GtkAccessibleInterface *iface);
|
||||
|
||||
static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
|
||||
static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
|
||||
const char *name);
|
||||
static const char * gtk_widget_buildable_get_name (GtkBuildable *buildable);
|
||||
static void gtk_widget_buildable_set_id (GtkBuildable *buildable,
|
||||
const char *id);
|
||||
static const char * gtk_widget_buildable_get_id (GtkBuildable *buildable);
|
||||
static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
|
||||
GtkBuilder *builder,
|
||||
const char *childname);
|
||||
@ -8113,7 +8113,7 @@ gtk_widget_accessible_interface_init (GtkAccessibleInterface *iface)
|
||||
/*
|
||||
* GtkBuildable implementation
|
||||
*/
|
||||
static GQuark quark_builder_set_name = 0;
|
||||
static GQuark quark_builder_set_id = 0;
|
||||
|
||||
static void
|
||||
gtk_widget_buildable_add_child (GtkBuildable *buildable,
|
||||
@ -8143,10 +8143,10 @@ gtk_widget_buildable_add_child (GtkBuildable *buildable,
|
||||
static void
|
||||
gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
|
||||
{
|
||||
quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
|
||||
quark_builder_set_id = g_quark_from_static_string ("gtk-builder-set-id");
|
||||
|
||||
iface->set_name = gtk_widget_buildable_set_name;
|
||||
iface->get_name = gtk_widget_buildable_get_name;
|
||||
iface->set_id = gtk_widget_buildable_set_id;
|
||||
iface->get_id = gtk_widget_buildable_get_id;
|
||||
iface->get_internal_child = gtk_widget_buildable_get_internal_child;
|
||||
iface->parser_finished = gtk_widget_buildable_parser_finished;
|
||||
iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
|
||||
@ -8156,17 +8156,17 @@ gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_widget_buildable_set_name (GtkBuildable *buildable,
|
||||
const char *name)
|
||||
gtk_widget_buildable_set_id (GtkBuildable *buildable,
|
||||
const char *id)
|
||||
{
|
||||
g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
|
||||
g_strdup (name), g_free);
|
||||
g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_id,
|
||||
g_strdup (id), g_free);
|
||||
}
|
||||
|
||||
static const char *
|
||||
gtk_widget_buildable_get_name (GtkBuildable *buildable)
|
||||
gtk_widget_buildable_get_id (GtkBuildable *buildable)
|
||||
{
|
||||
return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
|
||||
return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_id);
|
||||
}
|
||||
|
||||
static GObject *
|
||||
|
@ -353,7 +353,7 @@ update_info (gpointer data)
|
||||
if (GTK_IS_BUILDABLE (sl->object))
|
||||
{
|
||||
gtk_label_set_text (GTK_LABEL (sl->buildable_id),
|
||||
gtk_buildable_get_name (GTK_BUILDABLE (sl->object)));
|
||||
gtk_buildable_get_buildable_id (GTK_BUILDABLE (sl->object)));
|
||||
}
|
||||
|
||||
if (GDK_IS_FRAME_CLOCK (sl->object))
|
||||
|
@ -633,7 +633,7 @@ gtk_inspector_get_object_name (GObject *object)
|
||||
{
|
||||
const char *id;
|
||||
|
||||
id = gtk_buildable_get_name (GTK_BUILDABLE (object));
|
||||
id = gtk_buildable_get_buildable_id (GTK_BUILDABLE (object));
|
||||
if (id != NULL && !g_str_has_prefix (id, "___object_"))
|
||||
return id;
|
||||
}
|
||||
|
@ -29,12 +29,12 @@
|
||||
#include "gtk-builder-tool.h"
|
||||
|
||||
static const char *
|
||||
object_get_name (GObject *object)
|
||||
object_get_id (GObject *object)
|
||||
{
|
||||
if (GTK_IS_BUILDABLE (object))
|
||||
return gtk_buildable_get_name (GTK_BUILDABLE (object));
|
||||
return gtk_buildable_get_buildable_id (GTK_BUILDABLE (object));
|
||||
else
|
||||
return g_object_get_data (object, "gtk-builder-name");
|
||||
return g_object_get_data (object, "gtk-builder-id");
|
||||
}
|
||||
|
||||
void
|
||||
@ -63,7 +63,7 @@ do_enumerate (int *argc, const char ***argv)
|
||||
for (l = list; l; l = l->next)
|
||||
{
|
||||
object = l->data;
|
||||
name = object_get_name (object);
|
||||
name = object_get_id (object);
|
||||
if (g_str_has_prefix (name, "___") && g_str_has_suffix (name, "___"))
|
||||
continue;
|
||||
|
||||
|
@ -144,7 +144,7 @@ preview_file (const char *filename,
|
||||
window = gtk_window_new ();
|
||||
|
||||
if (GTK_IS_BUILDABLE (object))
|
||||
id = gtk_buildable_get_name (GTK_BUILDABLE (object));
|
||||
id = gtk_buildable_get_buildable_id (GTK_BUILDABLE (object));
|
||||
|
||||
set_window_title (GTK_WINDOW (window), filename, id);
|
||||
|
||||
|
@ -944,7 +944,7 @@ test_children (void)
|
||||
g_assert (button != NULL);
|
||||
g_assert (GTK_IS_BUTTON (button));
|
||||
g_assert (gtk_widget_get_parent (GTK_WIDGET(button)) != NULL);
|
||||
g_assert (strcmp (gtk_buildable_get_name (GTK_BUILDABLE (gtk_widget_get_parent (GTK_WIDGET (button)))), "window1") == 0);
|
||||
g_assert (strcmp (gtk_buildable_get_buildable_id (GTK_BUILDABLE (gtk_widget_get_parent (GTK_WIDGET (button)))), "window1") == 0);
|
||||
|
||||
gtk_window_destroy (GTK_WINDOW (window));
|
||||
g_object_unref (builder);
|
||||
@ -965,14 +965,14 @@ test_children (void)
|
||||
g_assert (vbox != NULL);
|
||||
g_assert (GTK_IS_BOX (vbox));
|
||||
g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (vbox)) == GTK_ORIENTATION_VERTICAL);
|
||||
g_assert (strcmp (gtk_buildable_get_name (GTK_BUILDABLE (content_area)), "dialog1-vbox") == 0);
|
||||
g_assert (strcmp (gtk_buildable_get_buildable_id (GTK_BUILDABLE (content_area)), "dialog1-vbox") == 0);
|
||||
|
||||
action_area = gtk_builder_get_object (builder, "dialog1-action_area");
|
||||
g_assert (action_area != NULL);
|
||||
g_assert (GTK_IS_BOX (action_area));
|
||||
g_assert (gtk_orientable_get_orientation (GTK_ORIENTABLE (action_area)) == GTK_ORIENTATION_HORIZONTAL);
|
||||
g_assert (gtk_widget_get_parent (GTK_WIDGET (action_area)) != NULL);
|
||||
g_assert (gtk_buildable_get_name (GTK_BUILDABLE (action_area)) != NULL);
|
||||
g_assert (gtk_buildable_get_buildable_id (GTK_BUILDABLE (action_area)) != NULL);
|
||||
gtk_window_destroy (GTK_WINDOW (dialog));
|
||||
g_object_unref (builder);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user