inspector: Type info for misc pane

Replaces the class hierarchy page with a button/popover on the misc page
This commit is contained in:
Zander Brown 2019-04-03 23:50:24 +01:00
parent 528f1f085e
commit e493b9b702
No known key found for this signature in database
GPG Key ID: 25EE3C36E31E5F84
6 changed files with 354 additions and 0 deletions

View File

@ -31,6 +31,7 @@ inspector_sources = files(
'statistics.c',
'strv-editor.c',
'treewalk.c',
'type-info.c',
'updatesoverlay.c',
'visual.c',
'window.c',

View File

@ -21,6 +21,7 @@
#include "misc-info.h"
#include "window.h"
#include "object-tree.h"
#include "type-info.h"
#include "gtktypebuiltins.h"
#include "gtktreeview.h"
@ -28,6 +29,7 @@
#include "gtklabel.h"
#include "gtkframe.h"
#include "gtkbutton.h"
#include "gtkmenubutton.h"
#include "gtkwidgetprivate.h"
@ -37,6 +39,8 @@ struct _GtkInspectorMiscInfoPrivate {
GObject *object;
GtkWidget *address;
GtkWidget *type;
GtkWidget *type_popover;
GtkWidget *refcount_row;
GtkWidget *refcount;
GtkWidget *state_row;
@ -260,11 +264,18 @@ update_info (gpointer data)
{
GtkInspectorMiscInfo *sl = data;
gchar *tmp;
GType gtype;
tmp = g_strdup_printf ("%p", sl->priv->object);
gtk_label_set_text (GTK_LABEL (sl->priv->address), tmp);
g_free (tmp);
gtype = G_TYPE_FROM_INSTANCE (sl->priv->object);
gtk_button_set_label (GTK_BUTTON (sl->priv->type), g_type_name (gtype));
gtk_inspector_type_popover_set_gtype (GTK_INSPECTOR_TYPE_POPOVER (sl->priv->type_popover),
gtype);
if (G_IS_OBJECT (sl->priv->object))
{
tmp = g_strdup_printf ("%d", sl->priv->object->ref_count);
@ -458,6 +469,11 @@ gtk_inspector_misc_info_init (GtkInspectorMiscInfo *sl)
{
sl->priv = gtk_inspector_misc_info_get_instance_private (sl);
gtk_widget_init_template (GTK_WIDGET (sl));
sl->priv->type_popover = g_object_new (GTK_TYPE_INSPECTOR_TYPE_POPOVER, NULL);
gtk_menu_button_set_popover (GTK_MENU_BUTTON (sl->priv->type),
sl->priv->type_popover);
}
static void
@ -540,6 +556,7 @@ gtk_inspector_misc_info_class_init (GtkInspectorMiscInfoClass *klass)
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/misc-info.ui");
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, address);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, type);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, refcount_row);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, refcount);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, state_row);

View File

@ -41,6 +41,32 @@
</child>
</object>
</child>
<child>
<object class="GtkListBoxRow" id="type_row">
<property name="activatable">0</property>
<child>
<object class="GtkBox">
<property name="margin">10</property>
<property name="spacing">40</property>
<child>
<object class="GtkLabel" id="type_label">
<property name="label" translatable="yes">Type</property>
<property name="halign">start</property>
<property name="valign">baseline</property>
<property name="xalign">0.0</property>
<property name="hexpand">1</property>
</object>
</child>
<child>
<object class="GtkMenuButton" id="type">
<property name="halign">end</property>
<property name="valign">baseline</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkListBoxRow" id="refcount_row">
<property name="activatable">0</property>

216
gtk/inspector/type-info.c Normal file
View File

@ -0,0 +1,216 @@
/*
* Copyright © 2019 Zander Brown
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <glib/gi18n-lib.h>
#include "type-info.h"
#include "gtkpopover.h"
struct _GtkInspectorTypePopover
{
GtkPopover parent_instance;
};
typedef struct _GtkInspectorTypePopoverPrivate GtkInspectorTypePopoverPrivate;
struct _GtkInspectorTypePopoverPrivate
{
GType type;
GtkWidget *parents;
GtkWidget *interfaces;
};
enum
{
PROP_0,
PROP_TYPE
};
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorTypePopover, gtk_inspector_type_popover,
GTK_TYPE_POPOVER)
static void
add_row (GtkContainer *box,
const gchar *name)
{
GtkWidget *row;
GtkWidget *label;
row = g_object_new (GTK_TYPE_LIST_BOX_ROW,
"selectable", FALSE,
"activatable", FALSE,
"can-focus", FALSE,
NULL);
label = g_object_new (GTK_TYPE_LABEL,
"margin", 6,
"label", name,
"selectable", TRUE,
"xalign", 0.0,
NULL);
gtk_container_add (GTK_CONTAINER (row), label);
gtk_container_add (box, row);
}
static void
remove_row (GtkWidget *item,
gpointer data)
{
if (GTK_IS_LIST_BOX_ROW (item))
gtk_container_remove (GTK_CONTAINER (data), item);
}
void
gtk_inspector_type_popover_set_gtype (GtkInspectorTypePopover *self,
GType gtype)
{
GtkInspectorTypePopoverPrivate *priv;
GHashTable *implements;
GHashTableIter iter;
const gchar *name;
GType *interfaces;
GType tmp;
gint i;
g_return_if_fail (GTK_IS_INSPECTOR_TYPE_POPOVER (self));
priv = gtk_inspector_type_popover_get_instance_private (self);
if (priv->type == gtype)
return;
priv->type = gtype;
gtk_container_foreach (GTK_CONTAINER (priv->parents),
remove_row, priv->parents);
gtk_container_foreach (GTK_CONTAINER (priv->interfaces),
remove_row, priv->interfaces);
implements = g_hash_table_new (g_str_hash, g_str_equal);
tmp = gtype;
do
{
add_row (GTK_CONTAINER (priv->parents), g_type_name (tmp));
interfaces = g_type_interfaces (tmp, NULL);
for (i = 0; interfaces[i]; i++)
g_hash_table_add (implements, (gchar *) g_type_name (interfaces[i]));
g_free (interfaces);
}
while ((tmp = g_type_parent (tmp)));
g_hash_table_iter_init (&iter, implements);
while (g_hash_table_iter_next (&iter, (gpointer *) &name, NULL))
add_row (GTK_CONTAINER (priv->interfaces), name);
g_hash_table_unref (implements);
}
static void
gtk_inspector_type_popover_init (GtkInspectorTypePopover *self)
{
GtkInspectorTypePopoverPrivate *priv;
GtkWidget *label;
gtk_widget_init_template (GTK_WIDGET (self));
priv = gtk_inspector_type_popover_get_instance_private (self);
priv->type = G_TYPE_NONE;
label = g_object_new (GTK_TYPE_LABEL,
"margin", 12,
"label", "None",
NULL);
gtk_list_box_set_placeholder (GTK_LIST_BOX (priv->parents), label);
label = g_object_new (GTK_TYPE_LABEL,
"margin", 12,
"label", "None",
NULL);
gtk_list_box_set_placeholder (GTK_LIST_BOX (priv->interfaces), label);
}
static void
gtk_inspector_type_popover_get_property (GObject *object,
guint param_id,
GValue *value,
GParamSpec *pspec)
{
GtkInspectorTypePopover *self = GTK_INSPECTOR_TYPE_POPOVER (object);
GtkInspectorTypePopoverPrivate *priv = gtk_inspector_type_popover_get_instance_private (self);
switch (param_id)
{
case PROP_TYPE:
g_value_set_gtype (value, priv->type);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
}
static void
gtk_inspector_type_popover_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec)
{
GtkInspectorTypePopover *self = GTK_INSPECTOR_TYPE_POPOVER (object);
switch (param_id)
{
case PROP_TYPE:
gtk_inspector_type_popover_set_gtype (self, g_value_get_gtype (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
}
static void
gtk_inspector_type_popover_class_init (GtkInspectorTypePopoverClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->get_property = gtk_inspector_type_popover_get_property;
object_class->set_property = gtk_inspector_type_popover_set_property;
g_object_class_install_property (object_class, PROP_TYPE,
g_param_spec_gtype ("type", "Type", "Type",
G_TYPE_NONE, G_PARAM_READWRITE));
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/type-info.ui");
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorTypePopover, parents);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorTypePopover, interfaces);
}

35
gtk/inspector/type-info.h Normal file
View File

@ -0,0 +1,35 @@
/*
* Copyright © 2019 Zander Brown
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _GTK_INSPECTOR_TYPE_INFO_H_
#define _GTK_INSPECTOR_TYPE_INFO_H_
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GTK_TYPE_INSPECTOR_TYPE_POPOVER (gtk_inspector_type_popover_get_type ())
G_DECLARE_FINAL_TYPE (GtkInspectorTypePopover, gtk_inspector_type_popover,
GTK, INSPECTOR_TYPE_POPOVER, GtkPopover)
void gtk_inspector_type_popover_set_gtype (GtkInspectorTypePopover *self,
GType gtype);
G_END_DECLS
#endif

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="gtk40">
<template class="GtkInspectorTypePopover" parent="GtkPopover">
<child>
<object class="GtkBox">
<property name="margin-start">6</property>
<property name="margin-end">6</property>
<property name="margin-top">6</property>
<property name="margin-bottom">6</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Hierarchy</property>
<property name="xalign">0</property>
</object>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="can-focus">1</property>
<property name="shadow-type">etched-in</property>
<property name="min-content-width">200</property>
<property name="max-content-height">200</property>
<property name="propagate-natural-width">1</property>
<property name="propagate-natural-height">1</property>
<child>
<object class="GtkListBox" id="parents">
<property name="selection-mode">none</property>
<property name="activate-on-single-click">0</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Implements</property>
<property name="xalign">0</property>
</object>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="can-focus">1</property>
<property name="shadow-type">etched-in</property>
<property name="min-content-width">200</property>
<property name="max-content-height">150</property>
<property name="propagate-natural-width">1</property>
<property name="propagate-natural-height">1</property>
<child>
<object class="GtkListBox" id="interfaces">
<property name="selection-mode">none</property>
<property name="activate-on-single-click">0</property>
</object>
</child>
</object>
</child>
</object>
</child>
</template>
</interface>