forked from AuroraMiddleware/gtk
Inspector: Support extending the inspector using GIOModules
This allows external modules to add a page to the Gtk Inspector. https://bugzilla.gnome.org/show_bug.cgi?id=740983
This commit is contained in:
parent
eed1831caf
commit
2d6ae59d7f
@ -46,9 +46,13 @@
|
||||
#include "visual.h"
|
||||
#include "window.h"
|
||||
|
||||
#include "gtkmodulesprivate.h"
|
||||
|
||||
void
|
||||
gtk_inspector_init (void)
|
||||
{
|
||||
static GIOExtensionPoint *extension_point = NULL;
|
||||
|
||||
g_type_ensure (GTK_TYPE_CELL_RENDERER_GRAPH);
|
||||
g_type_ensure (GTK_TYPE_GRAPH_DATA);
|
||||
g_type_ensure (GTK_TYPE_INSPECTOR_ACTIONS);
|
||||
@ -70,7 +74,25 @@ gtk_inspector_init (void)
|
||||
g_type_ensure (GTK_TYPE_INSPECTOR_STYLE_PROP_LIST);
|
||||
g_type_ensure (GTK_TYPE_INSPECTOR_VISUAL);
|
||||
g_type_ensure (GTK_TYPE_INSPECTOR_WINDOW);
|
||||
|
||||
if (extension_point == NULL)
|
||||
{
|
||||
GIOModuleScope *scope;
|
||||
gchar **paths;
|
||||
int i;
|
||||
|
||||
extension_point = g_io_extension_point_register ("gtk-inspector-page");
|
||||
g_io_extension_point_set_required_type (extension_point, GTK_TYPE_WIDGET);
|
||||
|
||||
paths = _gtk_get_module_path ("inspector");
|
||||
scope = g_io_module_scope_new (G_IO_MODULE_SCOPE_BLOCK_DUPLICATES);
|
||||
|
||||
for (i = 0; paths[i] != NULL; i++)
|
||||
g_io_modules_load_all_in_directory_with_scope (paths[i], scope);
|
||||
|
||||
g_strfreev (paths);
|
||||
g_io_module_scope_free (scope);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// vim: set et sw=2 ts=2:
|
||||
|
@ -47,6 +47,7 @@
|
||||
#include "gtkbutton.h"
|
||||
#include "gtkstack.h"
|
||||
#include "gtktreeviewcolumn.h"
|
||||
#include "gtkmodulesprivate.h"
|
||||
#include "gtkwindow.h"
|
||||
#include "gtkwindowgroup.h"
|
||||
|
||||
@ -56,6 +57,8 @@ static gboolean
|
||||
set_selected_object (GtkInspectorWindow *iw,
|
||||
GObject *selected)
|
||||
{
|
||||
GList *l;
|
||||
|
||||
if (!gtk_inspector_prop_list_set_object (GTK_INSPECTOR_PROP_LIST (iw->prop_list), selected))
|
||||
return FALSE;
|
||||
|
||||
@ -73,6 +76,9 @@ set_selected_object (GtkInspectorWindow *iw,
|
||||
gtk_inspector_menu_set_object (GTK_INSPECTOR_MENU (iw->menu), selected);
|
||||
gtk_inspector_gestures_set_object (GTK_INSPECTOR_GESTURES (iw->gestures), selected);
|
||||
|
||||
for (l = iw->extra_pages; l != NULL; l = l->next)
|
||||
g_object_set (l->data, "object", selected, NULL);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -129,9 +135,42 @@ open_object_details (GtkWidget *button, GtkInspectorWindow *iw)
|
||||
static void
|
||||
gtk_inspector_window_init (GtkInspectorWindow *iw)
|
||||
{
|
||||
GIOExtensionPoint *extension_point;
|
||||
GList *l, *extensions;
|
||||
|
||||
gtk_widget_init_template (GTK_WIDGET (iw));
|
||||
|
||||
gtk_window_group_add_window (gtk_window_group_new (), GTK_WINDOW (iw));
|
||||
|
||||
extension_point = g_io_extension_point_lookup ("gtk-inspector-page");
|
||||
extensions = g_io_extension_point_get_extensions (extension_point);
|
||||
|
||||
for (l = extensions; l != NULL; l = l->next)
|
||||
{
|
||||
GIOExtension *extension = l->data;
|
||||
GType type;
|
||||
GtkWidget *widget;
|
||||
char *title;
|
||||
GtkWidget *box;
|
||||
|
||||
type = g_io_extension_get_type (extension);
|
||||
|
||||
widget = g_object_new (type, NULL);
|
||||
|
||||
iw->extra_pages = g_list_prepend (iw->extra_pages, widget);
|
||||
|
||||
g_object_get (widget, "title", &title, NULL);
|
||||
gtk_stack_add_titled (GTK_STACK (iw->top_stack), widget,
|
||||
g_io_extension_get_name (extension),
|
||||
title);
|
||||
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
||||
gtk_stack_add_named (GTK_STACK (iw->button_stack), box,
|
||||
g_io_extension_get_name (extension));
|
||||
|
||||
gtk_widget_show (box);
|
||||
gtk_widget_show (widget);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
@ -155,6 +194,7 @@ gtk_inspector_window_class_init (GtkInspectorWindowClass *klass)
|
||||
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/window.ui");
|
||||
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, top_stack);
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, button_stack);
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, object_stack);
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, object_tree);
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, object_details);
|
||||
|
@ -43,6 +43,7 @@ typedef struct
|
||||
|
||||
GtkWidget *top_stack;
|
||||
GtkWidget *object_stack;
|
||||
GtkWidget *button_stack;
|
||||
GtkWidget *object_tree;
|
||||
GtkWidget *object_id;
|
||||
GtkWidget *object_details;
|
||||
@ -68,6 +69,8 @@ typedef struct
|
||||
GtkWidget *selected_widget;
|
||||
GtkWidget *flash_widget;
|
||||
|
||||
GList *extra_pages;
|
||||
|
||||
gboolean grabbed;
|
||||
|
||||
gint flash_count;
|
||||
|
Loading…
Reference in New Issue
Block a user