1/* Copyright 2015 Red Hat, Inc.
2 *
3 * GTK+ is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU Lesser General Public License as
5 * published by the Free Software Foundation; either version 2 of the
6 * License, or (at your option) any later version.
7 *
8 * GLib is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with GTK+; see the file COPYING. If not,
15 * see <http://www.gnu.org/licenses/>.
16 *
17 * Author: Matthias Clasen
18 */
19
20#include <stdlib.h>
21#include <string.h>
22#include <errno.h>
23
24#include <glib/gi18n.h>
25#include <glib/gprintf.h>
26#include <glib/gstdio.h>
27#include <gtk/gtk.h>
28#include "gtkbuilderprivate.h"
29#include "gtk-builder-tool.h"
30
31static const char *
32object_get_id (GObject *object)
33{
34 if (GTK_IS_BUILDABLE (object))
35 return gtk_buildable_get_buildable_id (GTK_BUILDABLE (object));
36 else
37 return g_object_get_data (object, key: "gtk-builder-id");
38}
39
40void
41do_enumerate (int *argc, const char ***argv)
42{
43 GtkBuilder *builder;
44 GError *error = NULL;
45 int ret;
46 GSList *list, *l;
47 GObject *object;
48 const char *name;
49 const char *filename;
50
51 filename = (*argv)[1];
52
53 builder = gtk_builder_new ();
54 ret = gtk_builder_add_from_file (builder, filename, error: &error);
55
56 if (ret == 0)
57 {
58 g_printerr (format: "%s\n", error->message);
59 exit (status: 1);
60 }
61
62 list = gtk_builder_get_objects (builder);
63 for (l = list; l; l = l->next)
64 {
65 object = l->data;
66 name = object_get_id (object);
67 if (g_str_has_prefix (str: name, prefix: "___") && g_str_has_suffix (str: name, suffix: "___"))
68 continue;
69
70 g_printf (format: "%s (%s)\n", name, g_type_name_from_instance (instance: (GTypeInstance*)object));
71 }
72 g_slist_free (list);
73
74 g_object_unref (object: builder);
75}
76

source code of gtk/tools/gtk-builder-tool-enumerate.c