inspector: Rename DataList -> TreeData

Rename the DataList object to TreeData, in preparation
for adding a ListData object for list models. While
we are touching it, modernize it a bit (drop the Private
struct, use a layout manager, etc).
This commit is contained in:
Matthias Clasen 2020-06-30 15:17:14 -04:00
parent bbb28196e5
commit 52666d6fe5
9 changed files with 95 additions and 96 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,7 +29,6 @@
#include "controllers.h" #include "controllers.h"
#include "css-editor.h" #include "css-editor.h"
#include "css-node-tree.h" #include "css-node-tree.h"
#include "data-list.h"
#include "general.h" #include "general.h"
#include "graphdata.h" #include "graphdata.h"
#include "logs.h" #include "logs.h"
@ -43,6 +42,7 @@
#include "shortcuts.h" #include "shortcuts.h"
#include "size-groups.h" #include "size-groups.h"
#include "statistics.h" #include "statistics.h"
#include "tree-data.h"
#include "visual.h" #include "visual.h"
#include "window.h" #include "window.h"
@ -64,7 +64,6 @@ gtk_inspector_init (void)
g_type_ensure (GTK_TYPE_INSPECTOR_CONTROLLERS); g_type_ensure (GTK_TYPE_INSPECTOR_CONTROLLERS);
g_type_ensure (GTK_TYPE_INSPECTOR_CSS_EDITOR); g_type_ensure (GTK_TYPE_INSPECTOR_CSS_EDITOR);
g_type_ensure (GTK_TYPE_INSPECTOR_CSS_NODE_TREE); 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_GENERAL);
g_type_ensure (GTK_TYPE_INSPECTOR_LOGS); g_type_ensure (GTK_TYPE_INSPECTOR_LOGS);
g_type_ensure (GTK_TYPE_MAGNIFIER); g_type_ensure (GTK_TYPE_MAGNIFIER);
@ -78,6 +77,7 @@ gtk_inspector_init (void)
g_type_ensure (GTK_TYPE_INSPECTOR_SHORTCUTS); g_type_ensure (GTK_TYPE_INSPECTOR_SHORTCUTS);
g_type_ensure (GTK_TYPE_INSPECTOR_SIZE_GROUPS); g_type_ensure (GTK_TYPE_INSPECTOR_SIZE_GROUPS);
g_type_ensure (GTK_TYPE_INSPECTOR_STATISTICS); 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_VISUAL);
g_type_ensure (GTK_TYPE_INSPECTOR_WINDOW); g_type_ensure (GTK_TYPE_INSPECTOR_WINDOW);

View File

@ -6,7 +6,6 @@ inspector_sources = files(
'controllers.c', 'controllers.c',
'css-editor.c', 'css-editor.c',
'css-node-tree.c', 'css-node-tree.c',
'data-list.c',
'focusoverlay.c', 'focusoverlay.c',
'fpsoverlay.c', 'fpsoverlay.c',
'general.c', 'general.c',
@ -33,6 +32,7 @@ inspector_sources = files(
'startrecording.c', 'startrecording.c',
'statistics.c', 'statistics.c',
'strv-editor.c', 'strv-editor.c',
'tree-data.c',
'treewalk.c', 'treewalk.c',
'type-info.c', 'type-info.c',
'updatesoverlay.c', 'updatesoverlay.c',

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 * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,7 +18,7 @@
#include "config.h" #include "config.h"
#include <glib/gi18n-lib.h> #include <glib/gi18n-lib.h>
#include "data-list.h" #include "tree-data.h"
#include "object-tree.h" #include "object-tree.h"
@ -27,10 +27,14 @@
#include "gtktogglebutton.h" #include "gtktogglebutton.h"
#include "gtklabel.h" #include "gtklabel.h"
#include "gtkstack.h" #include "gtkstack.h"
#include "gtkboxlayout.h"
#include "gtkorientable.h"
struct _GtkInspectorDataListPrivate struct _GtkInspectorTreeData
{ {
GtkWidget parent_instance;
GtkTreeModel *object; GtkTreeModel *object;
GtkTreeModel *types; GtkTreeModel *types;
GtkTreeView *view; GtkTreeView *view;
@ -38,13 +42,22 @@ struct _GtkInspectorDataListPrivate
gboolean show_data; 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 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_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 static void
@ -67,7 +80,7 @@ cell_data_func (GtkTreeViewColumn *col,
} }
static void static void
add_columns (GtkInspectorDataList *sl) add_columns (GtkInspectorTreeData *sl)
{ {
gint n_columns; gint n_columns;
GtkCellRenderer *cell; GtkCellRenderer *cell;
@ -76,45 +89,45 @@ add_columns (GtkInspectorDataList *sl)
GtkTreeViewColumn *col; GtkTreeViewColumn *col;
gint i; 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++) for (i = 0; i < n_columns; i++)
{ {
cell = gtk_cell_renderer_text_new (); 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)); title = g_strdup_printf ("%d: %s", i, g_type_name (type));
col = gtk_tree_view_column_new_with_attributes (title, cell, NULL); col = gtk_tree_view_column_new_with_attributes (title, cell, NULL);
g_object_set_data (G_OBJECT (col), "num", GINT_TO_POINTER (i)); 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_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); g_free (title);
} }
} }
static void static void
show_types (GtkInspectorDataList *sl) show_types (GtkInspectorTreeData *sl)
{ {
gtk_tree_view_set_model (sl->priv->view, NULL); gtk_tree_view_set_model (sl->view, NULL);
sl->priv->show_data = FALSE; sl->show_data = FALSE;
} }
static void static void
show_data (GtkInspectorDataList *sl) show_data (GtkInspectorTreeData *sl)
{ {
gtk_tree_view_set_model (sl->priv->view, sl->priv->object); gtk_tree_view_set_model (sl->view, sl->object);
sl->priv->show_data = TRUE; sl->show_data = TRUE;
} }
static void static void
clear_view (GtkInspectorDataList *sl) clear_view (GtkInspectorTreeData *sl)
{ {
gtk_tree_view_set_model (sl->priv->view, NULL); gtk_tree_view_set_model (sl->view, NULL);
while (gtk_tree_view_get_n_columns (sl->priv->view) > 0) while (gtk_tree_view_get_n_columns (sl->view) > 0)
gtk_tree_view_remove_column (sl->priv->view, gtk_tree_view_remove_column (sl->view,
gtk_tree_view_get_column (sl->priv->view, 0)); gtk_tree_view_get_column (sl->view, 0));
} }
void void
gtk_inspector_data_list_set_object (GtkInspectorDataList *sl, gtk_inspector_tree_data_set_object (GtkInspectorTreeData *sl,
GObject *object) GObject *object)
{ {
GtkWidget *stack; 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)); page = gtk_stack_get_page (GTK_STACK (stack), GTK_WIDGET (sl));
clear_view (sl); clear_view (sl);
sl->priv->object = NULL; sl->object = NULL;
sl->priv->show_data = FALSE; sl->show_data = FALSE;
if (!GTK_IS_TREE_MODEL (object)) 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); 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_free (title);
g_object_set (page, "visible", TRUE, NULL); g_object_set (page, "visible", TRUE, NULL);
sl->priv->object = GTK_TREE_MODEL (object); sl->object = GTK_TREE_MODEL (object);
add_columns (sl); add_columns (sl);
show_types (sl); show_types (sl);
} }
static void static void
toggle_show (GtkToggleButton *button, 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; return;
if (gtk_toggle_button_get_active (button)) if (gtk_toggle_button_get_active (button))
@ -159,14 +172,16 @@ toggle_show (GtkToggleButton *button,
} }
static void 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); 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_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/tree-data.ui");
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorDataList, view); gtk_widget_class_bind_template_child (widget_class, GtkInspectorTreeData, view);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorDataList, object_title); gtk_widget_class_bind_template_child (widget_class, GtkInspectorTreeData, object_title);
gtk_widget_class_bind_template_callback (widget_class, toggle_show); 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: // 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"> <interface domain="gtk40">
<template class="GtkInspectorDataList" parent="GtkBox"> <template class="GtkInspectorTreeData" parent="GtkWidget">
<property name="orientation">vertical</property>
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
<property name="spacing">6</property> <property name="spacing">6</property>

View File

@ -35,13 +35,13 @@
#include "css-node-tree.h" #include "css-node-tree.h"
#include "object-tree.h" #include "object-tree.h"
#include "size-groups.h" #include "size-groups.h"
#include "data-list.h"
#include "actions.h" #include "actions.h"
#include "shortcuts.h" #include "shortcuts.h"
#include "menu.h" #include "menu.h"
#include "misc-info.h" #include "misc-info.h"
#include "magnifier.h" #include "magnifier.h"
#include "recorder.h" #include "recorder.h"
#include "tree-data.h"
#include "visual.h" #include "visual.h"
#include "general.h" #include "general.h"
#include "logs.h" #include "logs.h"
@ -100,7 +100,7 @@ set_selected_object (GtkInspectorWindow *iw,
gtk_inspector_misc_info_set_object (GTK_INSPECTOR_MISC_INFO (iw->misc_info), selected); 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_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_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_actions_set_object (GTK_INSPECTOR_ACTIONS (iw->actions), 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_shortcuts_set_object (GTK_INSPECTOR_SHORTCUTS (iw->shortcuts), selected);
gtk_inspector_menu_set_object (GTK_INSPECTOR_MENU (iw->menu), selected); gtk_inspector_menu_set_object (GTK_INSPECTOR_MENU (iw->menu), selected);
@ -445,7 +445,7 @@ 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, widget_recorder);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, object_title); 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, 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, actions); 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, shortcuts);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, menu); gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, menu);

View File

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

View File

@ -405,7 +405,7 @@
<property name="name">data</property> <property name="name">data</property>
<property name="title" translatable="yes">Data</property> <property name="title" translatable="yes">Data</property>
<property name="child"> <property name="child">
<object class="GtkInspectorDataList" id="data_list"/> <object class="GtkInspectorTreeData" id="tree_data"/>
</property> </property>
</object> </object>
</child> </child>