Author: toshok
Date: 2008-02-05 13:24:23 -0500 (Tue, 05 Feb 2008)
New Revision: 94918
Added:
trunk/moon/plugin/plugin-debug.cpp
trunk/moon/plugin/plugin-debug.h
Modified:
trunk/moon/plugin/ChangeLog
trunk/moon/plugin/Makefile.am
trunk/moon/plugin/plugin.cpp
Log:
2008-02-05 Chris Toshok <[EMAIL PROTECTED]>
* Makefile.am (libmoonplugin_la_SOURCES): add plugin-debug.h/cpp
* plugin-debug.h, plugin.cpp: for now, just a gtk treeview with a
snapshot of the xaml hierarchy. selecting an item in the tree
puts a rectangle around the element in the plugin.
* plugin.cpp (plugin_show_menu): if debug is enabled, add the
debug menu item.
Modified: trunk/moon/plugin/ChangeLog
===================================================================
--- trunk/moon/plugin/ChangeLog 2008-02-05 18:18:45 UTC (rev 94917)
+++ trunk/moon/plugin/ChangeLog 2008-02-05 18:24:23 UTC (rev 94918)
@@ -1,5 +1,16 @@
2008-02-05 Chris Toshok <[EMAIL PROTECTED]>
+ * Makefile.am (libmoonplugin_la_SOURCES): add plugin-debug.h/cpp
+
+ * plugin-debug.h, plugin.cpp: for now, just a gtk treeview with a
+ snapshot of the xaml hierarchy. selecting an item in the tree
+ puts a rectangle around the element in the plugin.
+
+ * plugin.cpp (plugin_show_menu): if debug is enabled, add the
+ debug menu item.
+
+2008-02-05 Chris Toshok <[EMAIL PROTECTED]>
+
* moonlight.h: don't #define DEBUG here. it's a config.h deal.
2008-02-04 Jackson Harper <[EMAIL PROTECTED]>
Modified: trunk/moon/plugin/Makefile.am
===================================================================
--- trunk/moon/plugin/Makefile.am 2008-02-05 18:18:45 UTC (rev 94917)
+++ trunk/moon/plugin/Makefile.am 2008-02-05 18:24:23 UTC (rev 94918)
@@ -49,8 +49,10 @@
plugin-entry.cpp \
plugin-glue.cpp \
plugin-class.cpp \
- plugin-class.h \
- browser-http.h \
+ plugin-class.h \
+ plugin-debug.cpp \
+ plugin-debug.h \
+ browser-http.h \
browser-http.cpp
if PLUGIN_INSTALL
Added: trunk/moon/plugin/plugin-debug.cpp
===================================================================
--- trunk/moon/plugin/plugin-debug.cpp 2008-02-05 18:18:45 UTC (rev 94917)
+++ trunk/moon/plugin/plugin-debug.cpp 2008-02-05 18:24:23 UTC (rev 94918)
@@ -0,0 +1,125 @@
+
+#include "plugin-debug.h"
+#include <gtk/gtkmessagedialog.h>
+
+#ifdef DEBUG
+
+static void
+populate_tree_from_xaml (UIElement *el, GtkTreeStore *store, GtkTreeIter
*parent)
+{
+ if (el == NULL)
+ return;
+
+ GtkTreeIter iter;
+
+ gtk_tree_store_insert_with_values (store, &iter, parent, -1,
+ 0, el->GetName() ? el->GetName() :
"",
+ 1, el->GetTypeName(),
+ 2, el,
+ -1);
+
+ if (el->Is(Type::PANEL)) {
+ VisualCollection *children = ((Panel*)el)->GetChildren ();
+ if (children != NULL) {
+ Collection::Node *cn;
+ cn = (Collection::Node *) children->list->First ();
+ for ( ; cn != NULL; cn = (Collection::Node *) cn->next)
{
+ UIElement *item = (UIElement *) cn->obj;
+ populate_tree_from_xaml (item, store, &iter);
+ }
+ }
+ }
+}
+
+static void
+selection_changed (GtkTreeSelection *selection, PluginInstance *plugin)
+{
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ UIElement *el;
+
+ if (plugin->surface->debug_selected_element) {
+ plugin->surface->debug_selected_element->Invalidate ();
+ plugin->surface->debug_selected_element->unref ();
+ plugin->surface->debug_selected_element = NULL;
+ }
+
+ if (!gtk_tree_selection_get_selected (selection,
+ &model,
+ &iter)) {
+ return;
+ }
+
+ gtk_tree_model_get (model, &iter,
+ 2, &el,
+ -1);
+
+ if (el) {
+ printf ("%p selected, name = %s, type = %s\n", el,
el->GetName(), el->GetTypeName());
+ el->Invalidate ();
+ el->ref ();
+ plugin->surface->debug_selected_element = el;
+ }
+}
+
+void
+plugin_debug (PluginInstance *plugin)
+{
+ if (!plugin->getIsLoaded() || !plugin->surface) {
+ GtkWidget *d = gtk_message_dialog_new (NULL,
+ GTK_DIALOG_NO_SEPARATOR,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "The plugin hasn't been
initialized with xaml content yet");
+ gtk_dialog_run (GTK_DIALOG (d));
+ g_object_unref (d);
+ return;
+ }
+
+ GtkWidget *tree_win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title (GTK_WINDOW (tree_win), "Xaml contents");
+
+ GtkTreeStore *tree_store = gtk_tree_store_new (3,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_POINTER);
+
+ populate_tree_from_xaml (plugin->surface->GetToplevel (), tree_store,
NULL);
+
+ GtkWidget* tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL
(tree_store));
+
+ GtkTreeSelection *selection = gtk_tree_view_get_selection
(GTK_TREE_VIEW (tree_view));
+
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
+
+ g_signal_connect (G_OBJECT (selection), "changed",
+ G_CALLBACK (selection_changed), plugin);
+
+ GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
+ GtkTreeViewColumn *col;
+
+ /* The Name column */
+ col = gtk_tree_view_column_new();
+ gtk_tree_view_column_set_title(col, "Name");
+ gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), col);
+
+ gtk_tree_view_column_pack_start(col, renderer, TRUE);
+ gtk_tree_view_column_add_attribute (col, renderer, "text", 0);
+
+ /* The Type column */
+ col = gtk_tree_view_column_new();
+ gtk_tree_view_column_set_title(col, "Type");
+ gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), col);
+
+ gtk_tree_view_column_pack_start(col, renderer, TRUE);
+ gtk_tree_view_column_add_attribute (col, renderer, "text", 1);
+
+ GtkWidget *scrolled = gtk_scrolled_window_new (NULL, NULL);
+
+ gtk_container_add (GTK_CONTAINER (scrolled), tree_view);
+ gtk_container_add (GTK_CONTAINER (tree_win), scrolled);
+
+ gtk_widget_show_all (tree_win);
+}
+
+#endif
Added: trunk/moon/plugin/plugin-debug.h
===================================================================
--- trunk/moon/plugin/plugin-debug.h 2008-02-05 18:18:45 UTC (rev 94917)
+++ trunk/moon/plugin/plugin-debug.h 2008-02-05 18:24:23 UTC (rev 94918)
@@ -0,0 +1,21 @@
+/*
+ * plugin-debug.h: debugging/inspection support in the plugin
+ *
+ * Copyright 2008 Novell, Inc. (http://www.novell.com)
+ *
+ * See the LICENSE file included with the distribution for details.
+ *
+ */
+
+#ifndef __MOON_PLUGIN_DEBUG_H__
+#define __MOON_PLUGIN_DEBUG_H__
+
+#include "plugin.h"
+
+G_BEGIN_DECLS
+
+void plugin_debug (PluginInstance *plugin);
+
+G_END_DECLS
+
+#endif /* __MOON_PLUGIN_DEBUG_H__ */
Modified: trunk/moon/plugin/plugin.cpp
===================================================================
--- trunk/moon/plugin/plugin.cpp 2008-02-05 18:18:45 UTC (rev 94917)
+++ trunk/moon/plugin/plugin.cpp 2008-02-05 18:24:23 UTC (rev 94918)
@@ -12,6 +12,7 @@
#include "plugin.h"
#include "plugin-class.h"
+#include "plugin-debug.h"
#include "moon-mono.h"
#include "downloader.h"
#include "plugin-downloader.h"
@@ -86,6 +87,12 @@
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
g_signal_connect_swapped (G_OBJECT(menu_item), "activate", G_CALLBACK
(plugin_properties), plugin);
+#ifdef DEBUG
+ menu_item = gtk_menu_item_new_with_label ("Debug");
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+ g_signal_connect_swapped (G_OBJECT(menu_item), "activate", G_CALLBACK
(plugin_debug), plugin);
+#endif
+
gtk_widget_show_all (menu);
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 0,
gtk_get_current_event_time());
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches