Merge branch 'inspector-list-model' into 'master'

Inspector list model support

See merge request GNOME/gtk!2176
This commit is contained in:
Matthias Clasen 2020-06-30 22:17:29 +00:00
commit 9650236b23
14 changed files with 494 additions and 160 deletions

View File

@ -1,54 +0,0 @@
/*
* Copyright (c) 2014 Red Hat, Inc.
*
* 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_DATA_LIST_H_
#define _GTK_INSPECTOR_DATA_LIST_H_
#include <gtk/gtkbox.h>
#define GTK_TYPE_INSPECTOR_DATA_LIST (gtk_inspector_data_list_get_type())
#define GTK_INSPECTOR_DATA_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_INSPECTOR_DATA_LIST, GtkInspectorDataList))
#define GTK_INSPECTOR_DATA_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GTK_TYPE_INSPECTOR_DATA_LIST, GtkInspectorDataListClass))
#define GTK_INSPECTOR_IS_DATA_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_TYPE_INSPECTOR_DATA_LIST))
#define GTK_INSPECTOR_IS_DATA_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_TYPE_INSPECTOR_DATA_LIST))
#define GTK_INSPECTOR_DATA_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_INSPECTOR_DATA_LIST, GtkInspectorDataListClass))
typedef struct _GtkInspectorDataListPrivate GtkInspectorDataListPrivate;
typedef struct _GtkInspectorDataList
{
GtkBox parent;
GtkInspectorDataListPrivate *priv;
} GtkInspectorDataList;
typedef struct _GtkInspectorDataListClass
{
GtkBoxClass parent;
} GtkInspectorDataListClass;
G_BEGIN_DECLS
GType gtk_inspector_data_list_get_type (void);
void gtk_inspector_data_list_set_object (GtkInspectorDataList *sl,
GObject *object);
G_END_DECLS
#endif // _GTK_INSPECTOR_DATA_LIST_H_
// vim: set et sw=2 ts=2:

View File

@ -29,9 +29,9 @@
#include "controllers.h"
#include "css-editor.h"
#include "css-node-tree.h"
#include "data-list.h"
#include "general.h"
#include "graphdata.h"
#include "list-data.h"
#include "logs.h"
#include "magnifier.h"
#include "menu.h"
@ -43,6 +43,7 @@
#include "shortcuts.h"
#include "size-groups.h"
#include "statistics.h"
#include "tree-data.h"
#include "visual.h"
#include "window.h"
@ -64,8 +65,8 @@ gtk_inspector_init (void)
g_type_ensure (GTK_TYPE_INSPECTOR_CONTROLLERS);
g_type_ensure (GTK_TYPE_INSPECTOR_CSS_EDITOR);
g_type_ensure (GTK_TYPE_INSPECTOR_CSS_NODE_TREE);
g_type_ensure (GTK_TYPE_INSPECTOR_DATA_LIST);
g_type_ensure (GTK_TYPE_INSPECTOR_GENERAL);
g_type_ensure (GTK_TYPE_INSPECTOR_LIST_DATA);
g_type_ensure (GTK_TYPE_INSPECTOR_LOGS);
g_type_ensure (GTK_TYPE_MAGNIFIER);
g_type_ensure (GTK_TYPE_INSPECTOR_MAGNIFIER);
@ -78,6 +79,7 @@ gtk_inspector_init (void)
g_type_ensure (GTK_TYPE_INSPECTOR_SHORTCUTS);
g_type_ensure (GTK_TYPE_INSPECTOR_SIZE_GROUPS);
g_type_ensure (GTK_TYPE_INSPECTOR_STATISTICS);
g_type_ensure (GTK_TYPE_INSPECTOR_TREE_DATA);
g_type_ensure (GTK_TYPE_INSPECTOR_VISUAL);
g_type_ensure (GTK_TYPE_INSPECTOR_WINDOW);

274
gtk/inspector/list-data.c Normal file
View File

@ -0,0 +1,274 @@
/*
* Copyright (c) 2020 Red Hat, Inc.
*
* 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 "list-data.h"
#include "object-tree.h"
#include "gtkcolumnview.h"
#include "gtktogglebutton.h"
#include "gtklabel.h"
#include "gtkstack.h"
#include "gtkboxlayout.h"
#include "gtkorientable.h"
#include "gtknoselection.h"
#include "gtksignallistitemfactory.h"
#include "gtklistitem.h"
struct _GtkInspectorListData
{
GtkWidget parent_instance;
GtkInspectorObjectTree *object_tree;
GListModel *object;
GtkColumnView *view;
GtkWidget *items_label;
};
struct _GtkInspectorListDataClass
{
GtkWidgetClass parent_class;
};
enum
{
PROP_0,
PROP_OBJECT_TREE,
};
G_DEFINE_TYPE (GtkInspectorListData, gtk_inspector_list_data, GTK_TYPE_WIDGET)
static void
gtk_inspector_list_data_init (GtkInspectorListData *sl)
{
gtk_widget_init_template (GTK_WIDGET (sl));
gtk_orientable_set_orientation (GTK_ORIENTABLE (gtk_widget_get_layout_manager (GTK_WIDGET (sl))),
GTK_ORIENTATION_VERTICAL);
}
void
gtk_inspector_list_data_set_object (GtkInspectorListData *sl,
GObject *object)
{
GtkWidget *stack;
GtkStackPage *page;
char *text;
GtkNoSelection *selection;
stack = gtk_widget_get_parent (GTK_WIDGET (sl));
page = gtk_stack_get_page (GTK_STACK (stack), GTK_WIDGET (sl));
gtk_column_view_set_model (sl->view, NULL);
sl->object = NULL;
if (!G_IS_LIST_MODEL (object))
{
g_object_set (page, "visible", FALSE, NULL);
return;
}
text = g_strdup_printf ("%u items", g_list_model_get_n_items (G_LIST_MODEL (object)));
gtk_label_set_label (GTK_LABEL (sl->items_label), text);
g_free (text);
g_object_set (page, "visible", TRUE, NULL);
sl->object = G_LIST_MODEL (object);
selection = gtk_no_selection_new (sl->object);
gtk_column_view_set_model (sl->view, G_LIST_MODEL (selection));
g_object_unref (selection);
}
static void
setup_object (GtkSignalListItemFactory *factory,
GtkListItem *item)
{
GtkWidget *label;
label = gtk_label_new ("");
gtk_label_set_xalign (GTK_LABEL (label), 0);
gtk_widget_add_css_class (label, "cell");
gtk_list_item_set_child (item, label);
}
static void
bind_object (GtkSignalListItemFactory *factory,
GtkListItem *item)
{
GtkWidget *label;
gpointer obj;
char *text;
label = gtk_list_item_get_child (item);
obj = gtk_list_item_get_item (item);
text = g_strdup_printf ("%p", obj);
gtk_label_set_label (GTK_LABEL (label), text);
g_free (text);
}
static void
setup_type (GtkSignalListItemFactory *factory,
GtkListItem *item)
{
GtkWidget *label;
label = gtk_label_new ("");
gtk_label_set_xalign (GTK_LABEL (label), 0);
gtk_widget_add_css_class (label, "cell");
gtk_list_item_set_child (item, label);
}
static void
bind_type (GtkSignalListItemFactory *factory,
GtkListItem *item)
{
GtkWidget *label;
gpointer obj;
label = gtk_list_item_get_child (item);
obj = gtk_list_item_get_item (item);
gtk_label_set_label (GTK_LABEL (label), G_OBJECT_TYPE_NAME (obj));
}
static void
setup_props (GtkSignalListItemFactory *factory,
GtkListItem *item)
{
GtkWidget *button;
button = gtk_button_new_with_label ("Properties");
gtk_widget_add_css_class (button, "cell");
gtk_widget_set_halign (button, GTK_ALIGN_START);
gtk_list_item_set_child (item, button);
}
static void
object_properties (GtkWidget *button,
GtkListItem *item)
{
GtkInspectorListData *sl;
gpointer obj;
sl = GTK_INSPECTOR_LIST_DATA (gtk_widget_get_ancestor (button, GTK_TYPE_INSPECTOR_LIST_DATA));
obj = gtk_list_item_get_item (item);
g_object_set_data (G_OBJECT (sl->object_tree), "next-tab", (gpointer)"properties");
gtk_inspector_object_tree_activate_object (sl->object_tree, obj);
}
static void
bind_props (GtkSignalListItemFactory *factory,
GtkListItem *item,
GtkInspectorListData *sl)
{
g_signal_connect (gtk_list_item_get_child (item), "clicked",
G_CALLBACK (object_properties), item);
}
static void
unbind_props (GtkSignalListItemFactory *factory,
GtkListItem *item)
{
g_signal_handlers_disconnect_by_func (gtk_list_item_get_child (item), object_properties, item);
}
static void
get_property (GObject *object,
guint param_id,
GValue *value,
GParamSpec *pspec)
{
GtkInspectorListData *sl = GTK_INSPECTOR_LIST_DATA (object);
switch (param_id)
{
case PROP_OBJECT_TREE:
g_value_take_object (value, sl->object_tree);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
}
static void
set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec)
{
GtkInspectorListData *sl = GTK_INSPECTOR_LIST_DATA (object);
switch (param_id)
{
case PROP_OBJECT_TREE:
sl->object_tree = g_value_get_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
}
static void
finalize (GObject *object)
{
GtkInspectorListData *sl = GTK_INSPECTOR_LIST_DATA (object);
gtk_inspector_list_data_set_object (sl, NULL);
G_OBJECT_CLASS (gtk_inspector_list_data_parent_class)->finalize (object);
}
static void
gtk_inspector_list_data_class_init (GtkInspectorListDataClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->finalize = finalize;
object_class->get_property = get_property;
object_class->set_property = set_property;
g_object_class_install_property (object_class, PROP_OBJECT_TREE,
g_param_spec_object ("object-tree", "Object Tree", "Object tree",
GTK_TYPE_WIDGET, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/list-data.ui");
gtk_widget_class_bind_template_child (widget_class, GtkInspectorListData, view);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorListData, items_label);
gtk_widget_class_bind_template_callback (widget_class, setup_object);
gtk_widget_class_bind_template_callback (widget_class, bind_object);
gtk_widget_class_bind_template_callback (widget_class, setup_type);
gtk_widget_class_bind_template_callback (widget_class, bind_type);
gtk_widget_class_bind_template_callback (widget_class, setup_props);
gtk_widget_class_bind_template_callback (widget_class, bind_props);
gtk_widget_class_bind_template_callback (widget_class, unbind_props);
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
}
// vim: set et sw=2 ts=2:

38
gtk/inspector/list-data.h Normal file
View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2020 Red Hat, Inc.
*
* 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_LIST_DATA_H_
#define _GTK_INSPECTOR_LIST_DATA_H_
#include <gtk/gtkbox.h>
#define GTK_TYPE_INSPECTOR_LIST_DATA (gtk_inspector_list_data_get_type())
G_DECLARE_FINAL_TYPE (GtkInspectorListData, gtk_inspector_list_data, GTK, INSPECTOR_LIST_DATA, GtkWidget)
typedef struct _GtkInspectorListData GtkInspectorListData;
G_BEGIN_DECLS
void gtk_inspector_list_data_set_object (GtkInspectorListData *sl,
GObject *object);
G_END_DECLS
#endif // _GTK_INSPECTOR_LIST_DATA_H_
// vim: set et sw=2 ts=2:

View File

@ -0,0 +1,68 @@
<interface domain="gtk40">
<template class="GtkInspectorListData" parent="GtkWidget">
<child>
<object class="GtkBox">
<property name="spacing">6</property>
<property name="margin-start">6</property>
<property name="margin-end">6</property>
<property name="margin-top">6</property>
<property name="margin-bottom">6</property>
<child>
<object class="GtkLabel" id="items_label">
<property name="hexpand">1</property>
<property name="halign">end</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="hexpand">1</property>
<property name="vexpand">1</property>
<property name="vscrollbar-policy">always</property>
<child>
<object class="GtkColumnView" id="view">
<style>
<class name="list"/>
</style>
<child>
<object class="GtkColumnViewColumn">
<property name="title">Object</property>
<property name="factory">
<object class="GtkSignalListItemFactory">
<signal name="setup" handler="setup_object"/>
<signal name="bind" handler="bind_object"/>
</object>
</property>
</object>
</child>
<child>
<object class="GtkColumnViewColumn">
<property name="title">Type</property>
<property name="factory">
<object class="GtkSignalListItemFactory">
<signal name="setup" handler="setup_type"/>
<signal name="bind" handler="bind_type"/>
</object>
</property>
</object>
</child>
<child>
<object class="GtkColumnViewColumn">
<property name="title"></property>
<property name="expand">1</property>
<property name="factory">
<object class="GtkSignalListItemFactory">
<signal name="setup" handler="setup_props"/>
<signal name="bind" handler="bind_props"/>
<signal name="unbind" handler="unbind_props"/>
</object>
</property>
</object>
</child>
</object>
</child>
</object>
</child>
</template>
</interface>

View File

@ -6,7 +6,6 @@ inspector_sources = files(
'controllers.c',
'css-editor.c',
'css-node-tree.c',
'data-list.c',
'focusoverlay.c',
'fpsoverlay.c',
'general.c',
@ -16,6 +15,7 @@ inspector_sources = files(
'init.c',
'inspect-button.c',
'inspectoroverlay.c',
'list-data.c',
'layoutoverlay.c',
'logs.c',
'magnifier.c',
@ -33,6 +33,7 @@ inspector_sources = files(
'startrecording.c',
'statistics.c',
'strv-editor.c',
'tree-data.c',
'treewalk.c',
'type-info.c',
'updatesoverlay.c',

View File

@ -769,36 +769,6 @@ font_changed (GObject *object, GParamSpec *pspec, gpointer data)
pango_font_description_free (fb_font_desc);
}
static void
item_properties (GtkButton *button, GtkInspectorPropEditor *self)
{
GObject *item;
item = g_object_get_data (G_OBJECT (button), "item");
g_signal_emit (self, signals[SHOW_OBJECT], 0, item, "Item", "properties");
}
static GtkWidget *
create_row (gpointer item,
gpointer user_data)
{
GtkWidget *row, *label, *button;
char *name;
name = object_label (G_OBJECT (item), NULL);
label = gtk_label_new (name);
g_free (name);
button = gtk_button_new_with_label (_("Properties"));
g_object_set_data (G_OBJECT (button), "item", item);
g_signal_connect (button, "clicked", G_CALLBACK (item_properties), user_data);
row = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
gtk_box_append (GTK_BOX (row), label);
gtk_box_append (GTK_BOX (row), button);
return row;
}
static GtkWidget *
property_editor (GObject *object,
GParamSpec *spec,
@ -1003,39 +973,6 @@ property_editor (GObject *object,
G_CALLBACK (pointer_changed),
prop_edit, G_OBJECT (prop_edit));
}
else if (type == G_TYPE_PARAM_OBJECT &&
g_type_is_a (G_PARAM_SPEC_VALUE_TYPE (spec), G_TYPE_LIST_MODEL))
{
GtkWidget *popover;
GtkWidget *box;
GtkWidget *sw;
GListModel *model;
popover = gtk_popover_new ();
prop_edit = gtk_menu_button_new ();
gtk_menu_button_set_popover (GTK_MENU_BUTTON (prop_edit), popover);
sw = gtk_scrolled_window_new ();
gtk_popover_set_child (GTK_POPOVER (popover), sw);
g_object_set (sw,
"hexpand", TRUE,
"vexpand", TRUE,
"hscrollbar-policy", GTK_POLICY_NEVER,
"vscrollbar-policy", GTK_POLICY_NEVER,
NULL);
g_object_get (object, spec->name, &model, NULL);
if (g_list_model_get_n_items (model) >= 10)
g_object_set (prop_edit, "vscrollbar-policy", GTK_POLICY_AUTOMATIC, NULL);
box = gtk_list_box_new ();
gtk_list_box_set_selection_mode (GTK_LIST_BOX (box), GTK_SELECTION_NONE);
gtk_list_box_bind_model (GTK_LIST_BOX (box), model, create_row, self, NULL);
g_object_unref (model);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), box);
}
else if (type == G_TYPE_PARAM_OBJECT)
{
GtkWidget *label, *button;

View File

@ -408,7 +408,7 @@ bind_value_cb (GtkSignalListItemFactory *factory,
widget = gtk_inspector_prop_editor_new (object, name, NULL);
g_signal_connect (widget, "show-object", G_CALLBACK (show_object), data);
gtk_list_item_set_child (list_item, widget);
gtk_style_context_add_class (gtk_widget_get_style_context (widget), "cell");
gtk_widget_add_css_class (widget, "cell");
}
static void

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014 Red Hat, Inc.
* Copyright (c) 2014, 2020 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -18,7 +18,7 @@
#include "config.h"
#include <glib/gi18n-lib.h>
#include "data-list.h"
#include "tree-data.h"
#include "object-tree.h"
@ -27,10 +27,14 @@
#include "gtktogglebutton.h"
#include "gtklabel.h"
#include "gtkstack.h"
#include "gtkboxlayout.h"
#include "gtkorientable.h"
struct _GtkInspectorDataListPrivate
struct _GtkInspectorTreeData
{
GtkWidget parent_instance;
GtkTreeModel *object;
GtkTreeModel *types;
GtkTreeView *view;
@ -38,13 +42,22 @@ struct _GtkInspectorDataListPrivate
gboolean show_data;
};
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorDataList, gtk_inspector_data_list, GTK_TYPE_BOX)
typedef struct _GtkInspectorTreeDataClass GtkInspectorTreeDataClass;
struct _GtkInspectorTreeDataClass
{
GtkWidgetClass parent_class;
};
G_DEFINE_TYPE (GtkInspectorTreeData, gtk_inspector_tree_data, GTK_TYPE_WIDGET)
static void
gtk_inspector_data_list_init (GtkInspectorDataList *sl)
gtk_inspector_tree_data_init (GtkInspectorTreeData *sl)
{
sl->priv = gtk_inspector_data_list_get_instance_private (sl);
gtk_widget_init_template (GTK_WIDGET (sl));
gtk_orientable_set_orientation (GTK_ORIENTABLE (gtk_widget_get_layout_manager (GTK_WIDGET (sl))),
GTK_ORIENTATION_VERTICAL);
}
static void
@ -67,7 +80,7 @@ cell_data_func (GtkTreeViewColumn *col,
}
static void
add_columns (GtkInspectorDataList *sl)
add_columns (GtkInspectorTreeData *sl)
{
gint n_columns;
GtkCellRenderer *cell;
@ -76,45 +89,45 @@ add_columns (GtkInspectorDataList *sl)
GtkTreeViewColumn *col;
gint i;
n_columns = gtk_tree_model_get_n_columns (sl->priv->object);
n_columns = gtk_tree_model_get_n_columns (sl->object);
for (i = 0; i < n_columns; i++)
{
cell = gtk_cell_renderer_text_new ();
type = gtk_tree_model_get_column_type (sl->priv->object, i);
type = gtk_tree_model_get_column_type (sl->object, i);
title = g_strdup_printf ("%d: %s", i, g_type_name (type));
col = gtk_tree_view_column_new_with_attributes (title, cell, NULL);
g_object_set_data (G_OBJECT (col), "num", GINT_TO_POINTER (i));
gtk_tree_view_column_set_cell_data_func (col, cell, cell_data_func, sl, NULL);
gtk_tree_view_append_column (sl->priv->view, col);
gtk_tree_view_append_column (sl->view, col);
g_free (title);
}
}
static void
show_types (GtkInspectorDataList *sl)
show_types (GtkInspectorTreeData *sl)
{
gtk_tree_view_set_model (sl->priv->view, NULL);
sl->priv->show_data = FALSE;
gtk_tree_view_set_model (sl->view, NULL);
sl->show_data = FALSE;
}
static void
show_data (GtkInspectorDataList *sl)
show_data (GtkInspectorTreeData *sl)
{
gtk_tree_view_set_model (sl->priv->view, sl->priv->object);
sl->priv->show_data = TRUE;
gtk_tree_view_set_model (sl->view, sl->object);
sl->show_data = TRUE;
}
static void
clear_view (GtkInspectorDataList *sl)
clear_view (GtkInspectorTreeData *sl)
{
gtk_tree_view_set_model (sl->priv->view, NULL);
while (gtk_tree_view_get_n_columns (sl->priv->view) > 0)
gtk_tree_view_remove_column (sl->priv->view,
gtk_tree_view_get_column (sl->priv->view, 0));
gtk_tree_view_set_model (sl->view, NULL);
while (gtk_tree_view_get_n_columns (sl->view) > 0)
gtk_tree_view_remove_column (sl->view,
gtk_tree_view_get_column (sl->view, 0));
}
void
gtk_inspector_data_list_set_object (GtkInspectorDataList *sl,
gtk_inspector_tree_data_set_object (GtkInspectorTreeData *sl,
GObject *object)
{
GtkWidget *stack;
@ -125,8 +138,8 @@ gtk_inspector_data_list_set_object (GtkInspectorDataList *sl,
page = gtk_stack_get_page (GTK_STACK (stack), GTK_WIDGET (sl));
clear_view (sl);
sl->priv->object = NULL;
sl->priv->show_data = FALSE;
sl->object = NULL;
sl->show_data = FALSE;
if (!GTK_IS_TREE_MODEL (object))
{
@ -135,21 +148,21 @@ gtk_inspector_data_list_set_object (GtkInspectorDataList *sl,
}
title = gtk_inspector_get_object_title (object);
gtk_label_set_label (GTK_LABEL (sl->priv->object_title), title);
gtk_label_set_label (GTK_LABEL (sl->object_title), title);
g_free (title);
g_object_set (page, "visible", TRUE, NULL);
sl->priv->object = GTK_TREE_MODEL (object);
sl->object = GTK_TREE_MODEL (object);
add_columns (sl);
show_types (sl);
}
static void
toggle_show (GtkToggleButton *button,
GtkInspectorDataList *sl)
GtkInspectorTreeData *sl)
{
if (gtk_toggle_button_get_active (button) == sl->priv->show_data)
if (gtk_toggle_button_get_active (button) == sl->show_data)
return;
if (gtk_toggle_button_get_active (button))
@ -159,14 +172,16 @@ toggle_show (GtkToggleButton *button,
}
static void
gtk_inspector_data_list_class_init (GtkInspectorDataListClass *klass)
gtk_inspector_tree_data_class_init (GtkInspectorTreeDataClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/data-list.ui");
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorDataList, view);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorDataList, object_title);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/tree-data.ui");
gtk_widget_class_bind_template_child (widget_class, GtkInspectorTreeData, view);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorTreeData, object_title);
gtk_widget_class_bind_template_callback (widget_class, toggle_show);
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
}
// vim: set et sw=2 ts=2:

39
gtk/inspector/tree-data.h Normal file
View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2014, 2020 Red Hat, Inc.
*
* 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_TREE_DATA_H_
#define _GTK_INSPECTOR_TREE_DATA_H_
#include <gtk/gtkwidget.h>
#define GTK_TYPE_INSPECTOR_TREE_DATA (gtk_inspector_tree_data_get_type ())
#define GTK_INSPECTOR_TREE_DATA(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_INSPECTOR_TREE_DATA, GtkInspectorTreeData))
#define GTK_INSPECTOR_IS_TREE_DATA(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_TYPE_INSPECTOR_TREE_DATA))
typedef struct _GtkInspectorTreeData GtkInspectorTreeData;
G_BEGIN_DECLS
GType gtk_inspector_tree_data_get_type (void) G_GNUC_CONST;
void gtk_inspector_tree_data_set_object (GtkInspectorTreeData *sl,
GObject *object);
G_END_DECLS
#endif // _GTK_INSPECTOR_TREE_DATA_H_
// vim: set et sw=2 ts=2:

View File

@ -1,6 +1,5 @@
<interface domain="gtk40">
<template class="GtkInspectorDataList" parent="GtkBox">
<property name="orientation">vertical</property>
<template class="GtkInspectorTreeData" parent="GtkWidget">
<child>
<object class="GtkBox">
<property name="spacing">6</property>

View File

@ -35,13 +35,14 @@
#include "css-node-tree.h"
#include "object-tree.h"
#include "size-groups.h"
#include "data-list.h"
#include "actions.h"
#include "shortcuts.h"
#include "list-data.h"
#include "menu.h"
#include "misc-info.h"
#include "magnifier.h"
#include "recorder.h"
#include "tree-data.h"
#include "visual.h"
#include "general.h"
#include "logs.h"
@ -100,7 +101,8 @@ set_selected_object (GtkInspectorWindow *iw,
gtk_inspector_misc_info_set_object (GTK_INSPECTOR_MISC_INFO (iw->misc_info), selected);
gtk_inspector_css_node_tree_set_object (GTK_INSPECTOR_CSS_NODE_TREE (iw->widget_css_node_tree), selected);
gtk_inspector_size_groups_set_object (GTK_INSPECTOR_SIZE_GROUPS (iw->size_groups), selected);
gtk_inspector_data_list_set_object (GTK_INSPECTOR_DATA_LIST (iw->data_list), selected);
gtk_inspector_tree_data_set_object (GTK_INSPECTOR_TREE_DATA (iw->tree_data), selected);
gtk_inspector_list_data_set_object (GTK_INSPECTOR_LIST_DATA (iw->list_data), selected);
gtk_inspector_actions_set_object (GTK_INSPECTOR_ACTIONS (iw->actions), selected);
gtk_inspector_shortcuts_set_object (GTK_INSPECTOR_SHORTCUTS (iw->shortcuts), selected);
gtk_inspector_menu_set_object (GTK_INSPECTOR_MENU (iw->menu), selected);
@ -445,7 +447,8 @@ gtk_inspector_window_class_init (GtkInspectorWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, widget_recorder);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, object_title);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, size_groups);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, data_list);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, tree_data);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, list_data);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, actions);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, shortcuts);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, menu);

View File

@ -64,7 +64,8 @@ typedef struct
GtkWidget *widget_recorder;
GtkWidget *object_hierarchy;
GtkWidget *size_groups;
GtkWidget *data_list;
GtkWidget *tree_data;
GtkWidget *list_data;
GtkWidget *actions;
GtkWidget *shortcuts;
GtkWidget *menu;

View File

@ -405,7 +405,18 @@
<property name="name">data</property>
<property name="title" translatable="yes">Data</property>
<property name="child">
<object class="GtkInspectorDataList" id="data_list"/>
<object class="GtkInspectorTreeData" id="tree_data"/>
</property>
</object>
</child>
<child>
<object class="GtkStackPage">
<property name="name">list-data</property>
<property name="title" translatable="yes">Data</property>
<property name="child">
<object class="GtkInspectorListData" id="list_data">
<property name="object-tree">object_tree</property>
</object>
</property>
</object>
</child>