[gtk+] inspector: Add a minimal Data tab



commit a089ccf5f0f0b439f4f2a8d6fac7c3d47913462a
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat May 10 00:50:21 2014 -0400

    inspector: Add a minimal Data tab
    
    This will eventually show useful information about the content
    of tree models.

 modules/inspector/Makefile.am             |    4 +-
 modules/inspector/data-list.c             |  110 +++++++++++++++++++++++++++++
 modules/inspector/data-list.h             |   55 ++++++++++++++
 modules/inspector/data-list.ui            |   53 ++++++++++++++
 modules/inspector/inspector.gresource.xml |    1 +
 modules/inspector/module.c                |    2 +
 modules/inspector/window.c                |    3 +
 modules/inspector/window.h                |    1 +
 modules/inspector/window.ui               |   10 +++
 9 files changed, 238 insertions(+), 1 deletions(-)
---
diff --git a/modules/inspector/Makefile.am b/modules/inspector/Makefile.am
index 2ab2bb5..e673bfc 100644
--- a/modules/inspector/Makefile.am
+++ b/modules/inspector/Makefile.am
@@ -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)                 \
diff --git a/modules/inspector/data-list.c b/modules/inspector/data-list.c
new file mode 100644
index 0000000..9ccc86d
--- /dev/null
+++ b/modules/inspector/data-list.c
@@ -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:
diff --git a/modules/inspector/data-list.h b/modules/inspector/data-list.h
new file mode 100644
index 0000000..c27ab99
--- /dev/null
+++ b/modules/inspector/data-list.h
@@ -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:
diff --git a/modules/inspector/data-list.ui b/modules/inspector/data-list.ui
new file mode 100644
index 0000000..bd2786d
--- /dev/null
+++ b/modules/inspector/data-list.ui
@@ -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>
diff --git a/modules/inspector/inspector.gresource.xml b/modules/inspector/inspector.gresource.xml
index 0feec7c..752d2cd 100644
--- a/modules/inspector/inspector.gresource.xml
+++ b/modules/inspector/inspector.gresource.xml
@@ -10,5 +10,6 @@
     <file>themes.ui</file>
     <file>window.ui</file>
     <file>signals-list.ui</file>
+    <file>data-list.ui</file>
   </gresource>
 </gresources>
diff --git a/modules/inspector/module.c b/modules/inspector/module.c
index 31b4a1c..0e7a25f 100644
--- a/modules/inspector/module.c
+++ b/modules/inspector/module.c
@@ -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);
 }
 
 
diff --git a/modules/inspector/window.c b/modules/inspector/window.c
index d93d204..479c4e5 100644
--- a/modules/inspector/window.c
+++ b/modules/inspector/window.c
@@ -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);
diff --git a/modules/inspector/window.h b/modules/inspector/window.h
index 1e9bd69..da2742f 100644
--- a/modules/inspector/window.h
+++ b/modules/inspector/window.h
@@ -50,6 +50,7 @@ typedef struct
   GtkWidget *classes_list;
   GtkWidget *widget_css_editor;
   GtkWidget *object_hierarchy;
+  GtkWidget *data_list;
 
   GtkWidget *widget_popup;
 
diff --git a/modules/inspector/window.ui b/modules/inspector/window.ui
index 75044c2..e6f643b 100644
--- a/modules/inspector/window.ui
+++ b/modules/inspector/window.ui
@@ -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>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]