inspector: Add a visual tab

Move the show updates and flip text direction controls here,
and add controls for baseline and pixel cache debugging.
This commit is contained in:
Matthias Clasen 2014-05-10 21:19:21 -04:00
parent a145dd7097
commit 8475540103
9 changed files with 330 additions and 88 deletions

View File

@ -44,7 +44,9 @@ libgtkinspector_la_SOURCES = \
signals-list.h \
signals-list.c \
data-list.h \
data-list.c
data-list.c \
visual.h \
visual.c
libgtkinspector_la_CPPFLAGS = \
-I$(top_srcdir) \
@ -76,6 +78,7 @@ templates = \
prop-list.ui \
signals-list.ui \
themes.ui \
visual.ui \
widget-tree.ui \
window.ui

View File

@ -2,14 +2,15 @@
<gresources>
<gresource prefix="/org/gtk/inspector">
<file>button-path.ui</file>
<file>object-hierarchy.ui</file>
<file>css-editor.ui</file>
<file>classes-list.ui</file>
<file>widget-tree.ui</file>
<file>prop-list.ui</file>
<file>themes.ui</file>
<file>window.ui</file>
<file>signals-list.ui</file>
<file>css-editor.ui</file>
<file>data-list.ui</file>
<file>object-hierarchy.ui</file>
<file>prop-list.ui</file>
<file>signals-list.ui</file>
<file>themes.ui</file>
<file>visual.ui</file>
<file>widget-tree.ui</file>
<file>window.ui</file>
</gresource>
</gresources>

View File

@ -34,6 +34,7 @@
#include "resources.h"
#include "signals-list.h"
#include "themes.h"
#include "visual.h"
#include "widget-tree.h"
#include "window.h"
@ -46,18 +47,19 @@ gtk_module_init (gint *argc, gchar ***argv)
gtk_inspector_register_resource ();
g_type_ensure (GTK_TYPE_INSPECTOR_THEMES);
g_type_ensure (GTK_TYPE_INSPECTOR_CSS_EDITOR);
g_type_ensure (GTK_TYPE_INSPECTOR_BUTTON_PATH);
g_type_ensure (GTK_TYPE_INSPECTOR_WIDGET_TREE);
g_type_ensure (GTK_TYPE_INSPECTOR_PROP_LIST);
g_type_ensure (GTK_TYPE_INSPECTOR_OBJECT_HIERARCHY);
g_type_ensure (GTK_TYPE_INSPECTOR_CLASSES_LIST);
g_type_ensure (GTK_TYPE_INSPECTOR_PYTHON_SHELL);
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_CSS_EDITOR);
g_type_ensure (GTK_TYPE_INSPECTOR_DATA_LIST);
g_type_ensure (GTK_TYPE_INSPECTOR_OBJECT_HIERARCHY);
g_type_ensure (GTK_TYPE_INSPECTOR_PROPERTY_CELL_RENDERER);
g_type_ensure (GTK_TYPE_INSPECTOR_PROP_LIST);
g_type_ensure (GTK_TYPE_INSPECTOR_PYTHON_SHELL);
g_type_ensure (GTK_TYPE_INSPECTOR_SIGNALS_LIST);
g_type_ensure (GTK_TYPE_INSPECTOR_THEMES);
g_type_ensure (GTK_TYPE_INSPECTOR_VISUAL);
g_type_ensure (GTK_TYPE_INSPECTOR_WIDGET_TREE);
g_type_ensure (GTK_TYPE_INSPECTOR_WINDOW);
}

148
modules/inspector/visual.c Normal file
View File

@ -0,0 +1,148 @@
/*
* 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 "visual.h"
struct _GtkInspectorVisualPrivate
{
GtkWidget *updates_switch;
GtkWidget *direction_combo;
GtkWidget *baselines_switch;
GtkWidget *pixelcache_switch;
};
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorVisual, gtk_inspector_visual, GTK_TYPE_LIST_BOX)
static void
updates_activate (GtkSwitch *sw)
{
gdk_window_set_debug_updates (gtk_switch_get_active (sw));
}
static void
fix_direction_recurse (GtkWidget *widget, gpointer data)
{
GtkTextDirection dir = GPOINTER_TO_INT (data);
g_object_ref (widget);
gtk_widget_set_direction (widget, dir);
if (GTK_IS_CONTAINER (widget))
gtk_container_forall (GTK_CONTAINER (widget), fix_direction_recurse, data);
g_object_unref (widget);
}
static GtkTextDirection initial_direction;
static void
fix_direction (GtkWidget *iw)
{
fix_direction_recurse (iw, GINT_TO_POINTER (initial_direction));
}
static void
direction_changed (GtkComboBox *combo)
{
GtkWidget *iw;
const gchar *direction;
iw = gtk_widget_get_toplevel (GTK_WIDGET (combo));
fix_direction (iw);
direction = gtk_combo_box_get_active_id (combo);
if (g_strcmp0 (direction, "ltr") == 0)
gtk_widget_set_default_direction (GTK_TEXT_DIR_LTR);
else
gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
}
static void
init_direction (GtkInspectorVisual *vis)
{
const gchar *direction;
initial_direction = gtk_widget_get_default_direction ();
if (initial_direction == GTK_TEXT_DIR_LTR)
direction = "ltr";
else
direction = "rtl";
gtk_combo_box_set_active_id (GTK_COMBO_BOX (vis->priv->direction_combo), direction);
}
static void
baselines_activate (GtkSwitch *sw)
{
guint flags;
flags = gtk_get_debug_flags ();
if (gtk_switch_get_active (sw))
flags |= GTK_DEBUG_BASELINES;
else
flags &= ~GTK_DEBUG_BASELINES;
gtk_set_debug_flags (flags);
}
static void
pixelcache_activate (GtkSwitch *sw)
{
guint flags;
flags = gtk_get_debug_flags ();
if (gtk_switch_get_active (sw))
flags |= GTK_DEBUG_PIXEL_CACHE;
else
flags &= ~GTK_DEBUG_PIXEL_CACHE;
gtk_set_debug_flags (flags);
}
static void
gtk_inspector_visual_init (GtkInspectorVisual *pt)
{
pt->priv = gtk_inspector_visual_get_instance_private (pt);
gtk_widget_init_template (GTK_WIDGET (pt));
init_direction (pt);
}
static void
gtk_inspector_visual_class_init (GtkInspectorVisualClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/inspector/visual.ui");
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, updates_switch);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, direction_combo);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, baselines_switch);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, pixelcache_switch);
gtk_widget_class_bind_template_callback (widget_class, updates_activate);
gtk_widget_class_bind_template_callback (widget_class, direction_changed);
gtk_widget_class_bind_template_callback (widget_class, baselines_activate);
gtk_widget_class_bind_template_callback (widget_class, pixelcache_activate);
}
GtkWidget *
gtk_inspector_visual_new (void)
{
return GTK_WIDGET (g_object_new (GTK_TYPE_INSPECTOR_VISUAL, NULL));
}
// vim: set et sw=2 ts=2:

View File

@ -0,0 +1,53 @@
/*
* 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_VISUAL_H_
#define _GTK_INSPECTOR_VISUAL_H_
#include <gtk/gtk.h>
#define GTK_TYPE_INSPECTOR_VISUAL (gtk_inspector_visual_get_type())
#define GTK_INSPECTOR_VISUAL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_INSPECTOR_VISUAL, GtkInspectorVisual))
#define GTK_INSPECTOR_VISUAL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GTK_TYPE_INSPECTOR_VISUAL, GtkInspectorVisualClass))
#define GTK_INSPECTOR_IS_VISUAL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_TYPE_INSPECTOR_VISUAL))
#define GTK_INSPECTOR_IS_VISUAL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_TYPE_INSPECTOR_VISUAL))
#define GTK_INSPECTOR_VISUAL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_INSPECTOR_VISUAL, GtkInspectorVisualClass))
typedef struct _GtkInspectorVisualPrivate GtkInspectorVisualPrivate;
typedef struct _GtkInspectorVisual
{
GtkListBox parent;
GtkInspectorVisualPrivate *priv;
} GtkInspectorVisual;
typedef struct _GtkInspectorVisualClass
{
GtkListBoxClass parent;
} GtkInspectorVisualClass;
G_BEGIN_DECLS
GType gtk_inspector_visual_get_type (void);
GtkWidget *gtk_inspector_visual_new (void);
G_END_DECLS
#endif // _GTK_INSPECTOR_VISUAL_H_
// vim: set et sw=2 ts=2:

View File

@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="gtk30">
<template class="GtkInspectorVisual" parent="GtkListBox">
<property name="selection-mode">none</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">horizontal</property>
<property name="margin">10</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">Text Direction</property>
<property name="hexpand">True</property>
<property name="xalign">0.0</property>
</object>
</child>
<child>
<object class="GtkComboBoxText" id="direction_combo">
<property name="visible">True</property>
<signal name="changed" handler="direction_changed"/>
<items>
<item translatable="yes" id="ltr">Left-to-Right</item>
<item translatable="yes" id="rtl">Right-to-Left</item>
</items>
</object>
</child>
</object>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">horizontal</property>
<property name="margin">10</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">Show Graphic Updates</property>
<property name="hexpand">True</property>
<property name="xalign">0.0</property>
</object>
</child>
<child>
<object class="GtkSwitch" id="updates_switch">
<property name="visible">True</property>
<signal name="notify::active" handler="updates_activate"/>
</object>
</child>
</object>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">horizontal</property>
<property name="margin">10</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">Show Baselines</property>
<property name="hexpand">True</property>
<property name="xalign">0.0</property>
</object>
</child>
<child>
<object class="GtkSwitch" id="baselines_switch">
<property name="visible">True</property>
<signal name="notify::active" handler="baselines_activate"/>
</object>
</child>
</object>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">horizontal</property>
<property name="margin">10</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">Show Pixel Cache</property>
<property name="hexpand">True</property>
<property name="xalign">0.0</property>
</object>
</child>
<child>
<object class="GtkSwitch" id="pixelcache_switch">
<property name="visible">True</property>
<signal name="notify::active" handler="pixelcache_activate"/>
</object>
</child>
</object>
</child>
</template>
</interface>

View File

@ -43,47 +43,6 @@ G_DEFINE_TYPE (GtkInspectorWindow, gtk_inspector_window, GTK_TYPE_WINDOW)
extern void on_inspect (GtkWidget *button, GtkInspectorWindow *iw);
static void
on_graphic_updates_toggled (GtkToggleButton *button,
GtkInspectorWindow *iw)
{
gdk_window_set_debug_updates (gtk_toggle_button_get_active (button));
}
static void
fix_direction_recurse (GtkWidget *widget, gpointer data)
{
GtkTextDirection dir = GPOINTER_TO_INT (data);
g_object_ref (widget);
gtk_widget_set_direction (widget, dir);
if (GTK_IS_CONTAINER (widget))
gtk_container_forall (GTK_CONTAINER (widget), fix_direction_recurse, data);
g_object_unref (widget);
}
static GtkTextDirection initial_direction;
static void
fix_direction (GtkInspectorWindow *iw)
{
fix_direction_recurse (GTK_WIDGET (iw), GINT_TO_POINTER (initial_direction));
}
static void
on_flip (GtkButton *button,
GtkInspectorWindow *iw)
{
fix_direction (iw);
if (gtk_widget_get_default_direction () == GTK_TEXT_DIR_LTR)
gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
else
gtk_widget_set_default_direction (GTK_TEXT_DIR_LTR);
}
static gboolean
on_widget_tree_button_press (GtkInspectorWidgetTree *wt,
GdkEventButton *event,
@ -156,8 +115,6 @@ gtk_inspector_window_init (GtkInspectorWindow *iw)
g_signal_connect (G_OBJECT (iw->widget_tree), "button-press-event",
G_CALLBACK (on_widget_tree_button_press), iw);
}
initial_direction = gtk_widget_get_default_direction ();
}
static void
@ -213,8 +170,6 @@ gtk_inspector_window_class_init (GtkInspectorWindowClass *klass)
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);
gtk_widget_class_bind_template_callback (widget_class, on_flip);
gtk_widget_class_bind_template_callback (widget_class, on_widget_tree_selection_changed);
gtk_widget_class_bind_template_callback (widget_class, on_send_widget_to_shell_activate);
}

View File

@ -5,16 +5,6 @@
<property name="icon-name">edit-find</property>
<property name="icon-size">4</property>
</object>
<object class="GtkImage" id="update_image">
<property name="visible">True</property>
<property name="icon-name">view-refresh</property>
<property name="icon-size">4</property>
</object>
<object class="GtkImage" id="flip_image">
<property name="visible">True</property>
<property name="icon-name">object-flip-horizontal</property>
<property name="icon-size">4</property>
</object>
<object class="GtkMenu" id="widget_popup">
<property name="visible">True</property>
<child>
@ -46,22 +36,6 @@
<signal name="clicked" handler="on_inspect"/>
</object>
</child>
<child>
<object class="GtkToggleButton">
<property name="visible">True</property>
<property name="image">update_image</property>
<property name="tooltip-text" translatable="yes">Show Graphic Updates</property>
<signal name="toggled" handler="on_graphic_updates_toggled"/>
</object>
</child>
<child>
<object class="GtkButton">
<property name="visible">True</property>
<property name="image">flip_image</property>
<property name="tooltip-text" translatable="yes">Change Text Direction</property>
<signal name="clicked" handler="on_flip"/>
</object>
</child>
</object>
<packing>
<property name="pack-type">start</property>
@ -224,6 +198,17 @@
<property name="label" translatable="yes">Objects</property>
</object>
</child>
<child>
<object class="GtkInspectorVisual">
<property name="visible">True</property>
</object>
</child>
<child type="tab">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">Visual</property>
</object>
</child>
<child>
<object class="GtkInspectorThemes">
<property name="visible">True</property>

View File

@ -294,6 +294,7 @@ modules/inspector/object-hierarchy.ui.h
modules/inspector/prop-list.ui.h
modules/inspector/signals-list.ui.h
modules/inspector/themes.ui.h
modules/inspector/visual.ui.h
modules/inspector/widget-tree.ui.h
modules/inspector/window.ui.h
modules/printbackends/cloudprint/gtkprintbackendcloudprint.c