builder: Warn about dropped objects

Use GTK_DEBUG=builder-objects to make GtkBuilder warn
if a named object from a ui files doesn't get claimed
by gtk_builder_get_object(). This is useful for finding
dead wood in .ui files.
This commit is contained in:
Matthias Clasen 2020-06-27 09:36:45 -04:00
parent c447fa8442
commit 4fb495d0fe
3 changed files with 20 additions and 0 deletions

View File

@ -225,6 +225,8 @@
#include "gtkicontheme.h"
#include "gtkiconthemeprivate.h"
#include "gdkpixbufutilsprivate.h"
#include "gtkdebug.h"
static void gtk_builder_finalize (GObject *object);
static void gtk_builder_set_property (GObject *object,
@ -359,6 +361,22 @@ gtk_builder_finalize (GObject *object)
g_free (priv->filename);
g_free (priv->resource_prefix);
#ifdef G_ENABLE_DEBUG
if (GTK_DEBUG_CHECK (BUILDER_OBJECTS))
{
GHashTableIter iter;
gpointer key, value;
g_hash_table_iter_init (&iter, priv->objects);
while (g_hash_table_iter_next (&iter, &key, &value))
{
if (G_OBJECT (value)->ref_count == 1)
g_message ("builder: %s with id %s unused",
G_OBJECT_TYPE_NAME (value), (const char *)key);
}
}
#endif
g_hash_table_destroy (priv->objects);
g_slist_free_full (priv->signals, (GDestroyNotify)_free_signal_info);

View File

@ -53,6 +53,7 @@ typedef enum {
GTK_DEBUG_LAYOUT = 1 << 15,
GTK_DEBUG_SNAPSHOT = 1 << 16,
GTK_DEBUG_CONSTRAINTS = 1 << 17,
GTK_DEBUG_BUILDER_OBJECTS = 1 << 18,
} GtkDebugFlag;
#ifdef G_ENABLE_DEBUG

View File

@ -168,6 +168,7 @@ static const GDebugKey gtk_debug_keys[] = {
{ "icontheme", GTK_DEBUG_ICONTHEME },
{ "printing", GTK_DEBUG_PRINTING} ,
{ "builder", GTK_DEBUG_BUILDER },
{ "builder-objects", GTK_DEBUG_BUILDER_OBJECTS },
{ "size-request", GTK_DEBUG_SIZE_REQUEST },
{ "no-css-cache", GTK_DEBUG_NO_CSS_CACHE },
{ "shortcuts", GTK_DEBUG_SHORTCUTS },