2014-05-03 01:48:33 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008-2009 Christian Hammond
|
|
|
|
* Copyright (c) 2008-2009 David Trowbridge
|
|
|
|
* Copyright (c) 2013 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2014-05-07 04:13:00 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include <glib/gi18n-lib.h>
|
2014-05-03 01:48:33 +00:00
|
|
|
#include <stdlib.h>
|
2014-05-05 03:47:11 +00:00
|
|
|
#include "window.h"
|
2014-05-03 01:48:33 +00:00
|
|
|
#include "prop-list.h"
|
2014-05-05 03:47:11 +00:00
|
|
|
#include "property-cell-renderer.h"
|
2014-05-03 01:48:33 +00:00
|
|
|
#include "classes-list.h"
|
|
|
|
#include "css-editor.h"
|
|
|
|
#include "object-hierarchy.h"
|
|
|
|
#include "widget-tree.h"
|
|
|
|
#include "python-hooks.h"
|
|
|
|
#include "python-shell.h"
|
|
|
|
#include "button-path.h"
|
|
|
|
#include "themes.h"
|
2014-05-08 05:04:16 +00:00
|
|
|
#include "signals-list.h"
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-07 03:24:20 +00:00
|
|
|
G_DEFINE_TYPE (GtkInspectorWindow, gtk_inspector_window, GTK_TYPE_WINDOW)
|
2014-05-05 03:47:11 +00:00
|
|
|
|
2014-05-07 03:24:20 +00:00
|
|
|
extern void on_inspect (GtkWidget *button, GtkInspectorWindow *iw);
|
2014-05-05 03:47:11 +00:00
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
static void
|
2014-05-07 03:24:20 +00:00
|
|
|
on_graphic_updates_toggled (GtkToggleButton *button,
|
|
|
|
GtkInspectorWindow *iw)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-05-05 03:47:11 +00:00
|
|
|
gdk_window_set_debug_updates (gtk_toggle_button_get_active (button));
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-05-07 03:24:20 +00:00
|
|
|
on_widget_tree_button_press (GtkInspectorWidgetTree *wt,
|
|
|
|
GdkEventButton *event,
|
|
|
|
GtkInspectorWindow *iw)
|
2014-05-05 03:47:11 +00:00
|
|
|
{
|
|
|
|
if (event->button == 3)
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_menu_popup (GTK_MENU (iw->widget_popup), NULL, NULL,
|
2014-05-05 03:47:11 +00:00
|
|
|
NULL, NULL, event->button, event->time);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-05-07 03:24:20 +00:00
|
|
|
on_widget_tree_selection_changed (GtkInspectorWidgetTree *wt,
|
|
|
|
GtkInspectorWindow *iw)
|
2014-05-05 03:47:11 +00:00
|
|
|
{
|
2014-05-07 03:24:20 +00:00
|
|
|
GObject *selected = gtk_inspector_widget_tree_get_selected_object (wt);
|
2014-05-03 01:48:33 +00:00
|
|
|
|
|
|
|
if (selected != NULL)
|
|
|
|
{
|
2014-05-07 03:24:20 +00:00
|
|
|
if (!gtk_inspector_prop_list_set_object (GTK_INSPECTOR_PROP_LIST (iw->prop_list), selected))
|
2014-05-03 20:43:04 +00:00
|
|
|
return;
|
|
|
|
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_inspector_prop_list_set_object (GTK_INSPECTOR_PROP_LIST (iw->child_prop_list), selected);
|
2014-05-08 05:04:16 +00:00
|
|
|
gtk_inspector_signals_list_set_object (GTK_INSPECTOR_SIGNALS_LIST (iw->signals_list), selected);
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_inspector_object_hierarchy_set_object (GTK_INSPECTOR_OBJECT_HIERARCHY (iw->object_hierarchy), selected);
|
2014-05-03 01:48:33 +00:00
|
|
|
|
|
|
|
if (GTK_IS_WIDGET (selected))
|
|
|
|
{
|
|
|
|
GtkWidget *widget = GTK_WIDGET (selected);
|
|
|
|
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_inspector_flash_widget (iw, widget);
|
|
|
|
gtk_inspector_button_path_set_widget (GTK_INSPECTOR_BUTTON_PATH (iw->button_path), widget);
|
|
|
|
gtk_inspector_classes_list_set_widget (GTK_INSPECTOR_CLASSES_LIST (iw->classes_list), widget);
|
|
|
|
gtk_inspector_css_editor_set_widget (GTK_INSPECTOR_CSS_EDITOR (iw->widget_css_editor), widget);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_widget_set_sensitive (iw->classes_list, FALSE);
|
|
|
|
gtk_widget_set_sensitive (iw->widget_css_editor, FALSE);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-05-07 03:24:20 +00:00
|
|
|
on_send_widget_to_shell_activate (GtkWidget *menuitem,
|
|
|
|
GtkInspectorWindow *iw)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-05-05 03:47:11 +00:00
|
|
|
gchar *str;
|
2014-05-03 01:48:33 +00:00
|
|
|
GObject *object;
|
|
|
|
|
2014-05-07 03:24:20 +00:00
|
|
|
object = gtk_inspector_widget_tree_get_selected_object (GTK_INSPECTOR_WIDGET_TREE (iw->widget_tree));
|
2014-05-03 01:48:33 +00:00
|
|
|
|
|
|
|
if (!object)
|
|
|
|
return;
|
|
|
|
|
2014-05-07 03:24:20 +00:00
|
|
|
str = g_strdup_printf ("gtk_inspector.gobj(%p)", object);
|
|
|
|
gtk_inspector_python_shell_append_text (GTK_INSPECTOR_PYTHON_SHELL (iw->python_shell),
|
2014-05-07 10:34:23 +00:00
|
|
|
str,
|
|
|
|
NULL);
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-05 03:47:11 +00:00
|
|
|
g_free (str);
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_inspector_python_shell_focus (GTK_INSPECTOR_PYTHON_SHELL (iw->python_shell));
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2014-05-05 03:47:11 +00:00
|
|
|
static void
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_inspector_window_init (GtkInspectorWindow *iw)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-05-05 03:47:11 +00:00
|
|
|
gchar *title;
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_widget_init_template (GTK_WIDGET (iw));
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_window_group_add_window (gtk_window_group_new (), GTK_WINDOW (iw));
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-07 04:13:00 +00:00
|
|
|
title = g_strdup_printf (_("GTK+ Inspector — %s"), g_get_application_name ());
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (iw), title);
|
2014-05-05 03:47:11 +00:00
|
|
|
g_free (title);
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-07 03:24:20 +00:00
|
|
|
if (gtk_inspector_python_is_enabled ())
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_widget_show (iw->python_shell);
|
|
|
|
g_signal_connect (G_OBJECT (iw->widget_tree), "button-press-event",
|
|
|
|
G_CALLBACK (on_widget_tree_button_press), iw);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-07 10:34:23 +00:00
|
|
|
static void
|
|
|
|
gtk_inspector_window_select_initially (GtkInspectorWindow *iw)
|
|
|
|
{
|
|
|
|
GList *toplevels, *l;
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
toplevels = gtk_window_list_toplevels ();
|
|
|
|
widget = NULL;
|
|
|
|
for (l = toplevels; l; l = l->next)
|
|
|
|
{
|
|
|
|
if (gtk_widget_get_mapped (GTK_WIDGET (l->data)) &&
|
|
|
|
GTK_IS_WINDOW (l->data) &&
|
|
|
|
!GTK_INSPECTOR_IS_WINDOW (l->data))
|
|
|
|
{
|
|
|
|
widget = l->data;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_list_free (toplevels);
|
|
|
|
|
|
|
|
if (widget)
|
2014-05-09 00:31:50 +00:00
|
|
|
gtk_inspector_widget_tree_scan (GTK_INSPECTOR_WIDGET_TREE (iw->widget_tree), widget);
|
2014-05-07 10:34:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_inspector_window_constructed (GObject *object)
|
|
|
|
{
|
|
|
|
gtk_inspector_window_select_initially (GTK_INSPECTOR_WINDOW (object));
|
|
|
|
}
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
static void
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_inspector_window_class_init (GtkInspectorWindowClass *klass)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-05-07 10:34:23 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2014-05-05 03:47:11 +00:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
2014-05-07 10:34:23 +00:00
|
|
|
object_class->constructed = gtk_inspector_window_constructed;
|
|
|
|
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/inspector/window.ui");
|
2014-05-05 03:47:11 +00:00
|
|
|
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, widget_tree);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, prop_list);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, child_prop_list);
|
2014-05-08 05:04:16 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, signals_list);
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, button_path);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, classes_list);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, widget_css_editor);
|
|
|
|
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);
|
2014-05-05 03:47:11 +00:00
|
|
|
|
|
|
|
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_widget_tree_selection_changed);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, on_send_widget_to_shell_activate);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2014-05-05 03:47:11 +00:00
|
|
|
GtkWidget *
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_inspector_window_new (void)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-05-07 03:24:20 +00:00
|
|
|
return GTK_WIDGET (g_object_new (GTK_TYPE_INSPECTOR_WINDOW, NULL));
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2014-05-05 03:47:11 +00:00
|
|
|
// vim: set et sw=2 ts=2:
|