[gtk+] Inspector: Support extending the inspector using GIOModules
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Inspector: Support extending the inspector using GIOModules
- Date: Mon, 8 Dec 2014 23:27:40 +0000 (UTC)
commit 2d6ae59d7f0d1bf396e7544d7f211f26bebba074
Author: Alexander Larsson <alexl redhat com>
Date: Mon Dec 1 15:37:05 2014 +0100
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
gtk/inspector/init.c | 24 +++++++++++++++++++++++-
gtk/inspector/window.c | 40 ++++++++++++++++++++++++++++++++++++++++
gtk/inspector/window.h | 3 +++
3 files changed, 66 insertions(+), 1 deletions(-)
---
diff --git a/gtk/inspector/init.c b/gtk/inspector/init.c
index 433fc8d..c930948 100644
--- a/gtk/inspector/init.c
+++ b/gtk/inspector/init.c
@@ -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:
diff --git a/gtk/inspector/window.c b/gtk/inspector/window.c
index 5892ca5..a7b5f82 100644
--- a/gtk/inspector/window.c
+++ b/gtk/inspector/window.c
@@ -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);
diff --git a/gtk/inspector/window.h b/gtk/inspector/window.h
index e2aa87c..8560e0c 100644
--- a/gtk/inspector/window.h
+++ b/gtk/inspector/window.h
@@ -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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]