forked from AuroraMiddleware/gtk
inspector: Add a minimal Data tab
This will eventually show useful information about the content of tree models.
This commit is contained in:
parent
9655337407
commit
a089ccf5f0
@ -42,7 +42,9 @@ libgtkinspector_la_SOURCES = \
|
||||
themes.h \
|
||||
themes.c \
|
||||
signals-list.h \
|
||||
signals-list.c
|
||||
signals-list.c \
|
||||
data-list.h \
|
||||
data-list.c
|
||||
|
||||
libgtkinspector_la_CPPFLAGS = \
|
||||
-I$(top_srcdir) \
|
||||
|
110
modules/inspector/data-list.c
Normal file
110
modules/inspector/data-list.c
Normal file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <glib/gi18n-lib.h>
|
||||
#include "data-list.h"
|
||||
|
||||
enum
|
||||
{
|
||||
COLUMN_NUMBER,
|
||||
COLUMN_TYPE
|
||||
};
|
||||
|
||||
struct _GtkInspectorDataListPrivate
|
||||
{
|
||||
GtkListStore *model;
|
||||
GtkTreeViewColumn *number_column;
|
||||
GtkCellRenderer *number_renderer;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorDataList, gtk_inspector_data_list, GTK_TYPE_BOX)
|
||||
|
||||
static void
|
||||
render_number (GtkTreeViewColumn *column,
|
||||
GtkCellRenderer *renderer,
|
||||
GtkTreeModel *model,
|
||||
GtkTreeIter *iter,
|
||||
gpointer data)
|
||||
{
|
||||
gint number;
|
||||
gchar text[100];
|
||||
|
||||
gtk_tree_model_get (model, iter, COLUMN_NUMBER, &number, -1);
|
||||
g_snprintf (text, 100, "%d", number);
|
||||
g_object_set (renderer, "text", text, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_inspector_data_list_init (GtkInspectorDataList *sl)
|
||||
{
|
||||
sl->priv = gtk_inspector_data_list_get_instance_private (sl);
|
||||
gtk_widget_init_template (GTK_WIDGET (sl));
|
||||
gtk_tree_view_column_set_cell_data_func (sl->priv->number_column,
|
||||
sl->priv->number_renderer,
|
||||
render_number,
|
||||
NULL, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
gtk_inspector_data_list_set_object (GtkInspectorDataList *sl,
|
||||
GObject *object)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
gint i;
|
||||
|
||||
gtk_list_store_clear (sl->priv->model);
|
||||
|
||||
if (!GTK_IS_TREE_MODEL (object))
|
||||
{
|
||||
gtk_widget_hide (GTK_WIDGET (sl));
|
||||
return;
|
||||
}
|
||||
|
||||
gtk_widget_show (GTK_WIDGET (sl));
|
||||
|
||||
for (i = 0; i < gtk_tree_model_get_n_columns (GTK_TREE_MODEL (object)); i++)
|
||||
{
|
||||
GType type;
|
||||
type = gtk_tree_model_get_column_type (GTK_TREE_MODEL (object), i);
|
||||
|
||||
gtk_list_store_append (sl->priv->model, &iter);
|
||||
gtk_list_store_set (sl->priv->model, &iter,
|
||||
COLUMN_NUMBER, i,
|
||||
COLUMN_TYPE, g_type_name (type),
|
||||
-1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_inspector_data_list_class_init (GtkInspectorDataListClass *klass)
|
||||
{
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
|
||||
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/inspector/data-list.ui");
|
||||
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorDataList, model);
|
||||
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorDataList, number_column);
|
||||
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorDataList, number_renderer);
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
gtk_inspector_data_list_new (void)
|
||||
{
|
||||
return GTK_WIDGET (g_object_new (GTK_TYPE_INSPECTOR_DATA_LIST, NULL));
|
||||
}
|
||||
|
||||
// vim: set et sw=2 ts=2:
|
55
modules/inspector/data-list.h
Normal file
55
modules/inspector/data-list.h
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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/gtk.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);
|
||||
GtkWidget *gtk_inspector_data_list_new (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:
|
53
modules/inspector/data-list.ui
Normal file
53
modules/inspector/data-list.ui
Normal file
@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface domain="gtk30">
|
||||
<object class="GtkListStore" id="model">
|
||||
<columns>
|
||||
<column type="gint"/>
|
||||
<column type="gchararray"/>
|
||||
</columns>
|
||||
</object>
|
||||
<template class="GtkInspectorDataList" parent="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<property name="visible">True</property>
|
||||
<property name="expand">True</property>
|
||||
<property name="hscrollbar-policy">automatic</property>
|
||||
<property name="vscrollbar-policy">always</property>
|
||||
<property name="shadow-type">in</property>
|
||||
<child>
|
||||
<object class= "GtkTreeView">
|
||||
<property name="visible">True</property>
|
||||
<property name="model">model</property>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn" id="number_column">
|
||||
<property name="title" translatable="yes">Column</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText" id="number_renderer">
|
||||
<property name="scale">0.8</property>
|
||||
</object>
|
||||
<attributes>
|
||||
<attribute name="text">0</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="title" translatable="yes">Type</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText">
|
||||
<property name="scale">0.8</property>
|
||||
</object>
|
||||
<attributes>
|
||||
<attribute name="text">1</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</template>
|
||||
</interface>
|
@ -10,5 +10,6 @@
|
||||
<file>themes.ui</file>
|
||||
<file>window.ui</file>
|
||||
<file>signals-list.ui</file>
|
||||
<file>data-list.ui</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "button-path.h"
|
||||
#include "classes-list.h"
|
||||
#include "css-editor.h"
|
||||
#include "data-list.h"
|
||||
#include "object-hierarchy.h"
|
||||
#include "property-cell-renderer.h"
|
||||
#include "prop-list.h"
|
||||
@ -56,6 +57,7 @@ gtk_module_init (gint *argc, gchar ***argv)
|
||||
g_type_ensure (GTK_TYPE_INSPECTOR_PROPERTY_CELL_RENDERER);
|
||||
g_type_ensure (GTK_TYPE_INSPECTOR_WINDOW);
|
||||
g_type_ensure (GTK_TYPE_INSPECTOR_SIGNALS_LIST);
|
||||
g_type_ensure (GTK_TYPE_INSPECTOR_DATA_LIST);
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "python-hooks.h"
|
||||
#include "python-shell.h"
|
||||
#include "button-path.h"
|
||||
#include "data-list.h"
|
||||
#include "themes.h"
|
||||
#include "signals-list.h"
|
||||
|
||||
@ -78,6 +79,7 @@ on_widget_tree_selection_changed (GtkInspectorWidgetTree *wt,
|
||||
gtk_inspector_button_path_set_object (GTK_INSPECTOR_BUTTON_PATH (iw->button_path), selected);
|
||||
gtk_inspector_classes_list_set_object (GTK_INSPECTOR_CLASSES_LIST (iw->classes_list), selected);
|
||||
gtk_inspector_css_editor_set_object (GTK_INSPECTOR_CSS_EDITOR (iw->widget_css_editor), selected);
|
||||
gtk_inspector_data_list_set_object (GTK_INSPECTOR_DATA_LIST (iw->data_list), selected);
|
||||
|
||||
if (GTK_IS_WIDGET (selected))
|
||||
gtk_inspector_flash_widget (iw, GTK_WIDGET (selected));
|
||||
@ -176,6 +178,7 @@ gtk_inspector_window_class_init (GtkInspectorWindowClass *klass)
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, object_hierarchy);
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, python_shell);
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, widget_popup);
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, data_list);
|
||||
|
||||
gtk_widget_class_bind_template_callback (widget_class, on_inspect);
|
||||
gtk_widget_class_bind_template_callback (widget_class, on_graphic_updates_toggled);
|
||||
|
@ -50,6 +50,7 @@ typedef struct
|
||||
GtkWidget *classes_list;
|
||||
GtkWidget *widget_css_editor;
|
||||
GtkWidget *object_hierarchy;
|
||||
GtkWidget *data_list;
|
||||
|
||||
GtkWidget *widget_popup;
|
||||
|
||||
|
@ -185,6 +185,16 @@
|
||||
<property name="label" translatable="yes">Custom CSS</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkInspectorDataList" id="data_list">
|
||||
</object>
|
||||
</child>
|
||||
<child type="tab">
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Data</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="resize">True</property>
|
||||
|
Loading…
Reference in New Issue
Block a user