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-07-12 03:14:04 +00:00
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
#include <stdlib.h>
|
2014-07-12 03:14:04 +00:00
|
|
|
|
2014-05-05 03:47:11 +00:00
|
|
|
#include "window.h"
|
2014-05-03 01:48:33 +00:00
|
|
|
#include "prop-list.h"
|
|
|
|
#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"
|
2014-05-21 01:44:48 +00:00
|
|
|
#include "size-groups.h"
|
2014-07-06 16:18:09 +00:00
|
|
|
#include "style-prop-list.h"
|
2014-05-10 04:50:21 +00:00
|
|
|
#include "data-list.h"
|
2014-05-08 05:04:16 +00:00
|
|
|
#include "signals-list.h"
|
2014-05-14 00:36:02 +00:00
|
|
|
#include "actions.h"
|
2014-06-05 12:31:06 +00:00
|
|
|
#include "menu.h"
|
2014-07-19 06:47:36 +00:00
|
|
|
#include "misc-info.h"
|
2014-06-05 12:31:06 +00:00
|
|
|
#include "gestures.h"
|
2014-05-14 00:36:02 +00:00
|
|
|
|
2014-07-12 03:45:18 +00:00
|
|
|
#include "gtknotebook.h"
|
|
|
|
#include "gtkwindowgroup.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
|
|
|
|
|
|
|
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-31 03:21:13 +00:00
|
|
|
GtkWidget *notebook;
|
|
|
|
const gchar *tab;
|
|
|
|
gint page_num;
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-10 16:26:22 +00:00
|
|
|
if (!gtk_inspector_prop_list_set_object (GTK_INSPECTOR_PROP_LIST (iw->prop_list), selected))
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_inspector_prop_list_set_object (GTK_INSPECTOR_PROP_LIST (iw->child_prop_list), selected);
|
2014-07-06 16:18:09 +00:00
|
|
|
gtk_inspector_style_prop_list_set_object (GTK_INSPECTOR_STYLE_PROP_LIST (iw->style_prop_list), selected);
|
2014-05-10 16:26:22 +00:00
|
|
|
gtk_inspector_signals_list_set_object (GTK_INSPECTOR_SIGNALS_LIST (iw->signals_list), selected);
|
|
|
|
gtk_inspector_object_hierarchy_set_object (GTK_INSPECTOR_OBJECT_HIERARCHY (iw->object_hierarchy), selected);
|
2014-07-19 06:47:36 +00:00
|
|
|
gtk_inspector_misc_info_set_object (GTK_INSPECTOR_MISC_INFO (iw->misc_info), selected);
|
2014-05-10 16:26:22 +00:00
|
|
|
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);
|
2014-05-21 01:44:48 +00:00
|
|
|
gtk_inspector_size_groups_set_object (GTK_INSPECTOR_SIZE_GROUPS (iw->size_groups), selected);
|
2014-05-10 16:26:22 +00:00
|
|
|
gtk_inspector_data_list_set_object (GTK_INSPECTOR_DATA_LIST (iw->data_list), selected);
|
2014-05-14 00:36:02 +00:00
|
|
|
gtk_inspector_actions_set_object (GTK_INSPECTOR_ACTIONS (iw->actions), selected);
|
2014-06-05 12:31:06 +00:00
|
|
|
gtk_inspector_menu_set_object (GTK_INSPECTOR_MENU (iw->menu), selected);
|
2014-05-16 23:44:43 +00:00
|
|
|
gtk_inspector_gestures_set_object (GTK_INSPECTOR_GESTURES (iw->gestures), selected);
|
|
|
|
|
2014-05-31 03:21:13 +00:00
|
|
|
notebook = gtk_widget_get_parent (iw->prop_list);
|
2014-06-04 23:28:24 +00:00
|
|
|
tab = g_object_get_data (G_OBJECT (wt), "next-tab");
|
2014-05-31 03:21:13 +00:00
|
|
|
if (g_strcmp0 (tab, "properties") == 0)
|
|
|
|
{
|
|
|
|
page_num = gtk_notebook_page_num (GTK_NOTEBOOK (notebook), iw->prop_list);
|
|
|
|
gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), page_num);
|
|
|
|
}
|
|
|
|
else if (g_strcmp0 (tab, "data") == 0)
|
|
|
|
{
|
|
|
|
page_num = gtk_notebook_page_num (GTK_NOTEBOOK (notebook), iw->data_list);
|
|
|
|
gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), page_num);
|
|
|
|
}
|
|
|
|
else if (g_strcmp0 (tab, "actions") == 0)
|
|
|
|
{
|
|
|
|
page_num = gtk_notebook_page_num (GTK_NOTEBOOK (notebook), iw->actions);
|
|
|
|
gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), page_num);
|
|
|
|
}
|
|
|
|
|
2014-05-10 16:26:22 +00:00
|
|
|
if (GTK_IS_WIDGET (selected))
|
|
|
|
gtk_inspector_flash_widget (iw, GTK_WIDGET (selected));
|
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-06-27 22:43:59 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_inspector_window_parent_class)->constructed (object);
|
2014-05-07 10:34:23 +00:00
|
|
|
}
|
|
|
|
|
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-06-05 00:12:42 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, top_notebook);
|
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);
|
2014-07-06 16:18:09 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, style_prop_list);
|
2014-05-07 03:24:20 +00:00
|
|
|
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-21 01:44:48 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, size_groups);
|
2014-05-10 04:50:21 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, data_list);
|
2014-05-14 00:36:02 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, actions);
|
2014-06-05 12:31:06 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, menu);
|
2014-07-19 06:47:36 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, misc_info);
|
2014-05-16 23:44:43 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, gestures);
|
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_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:
|