[gtk+] inspector: show GMenus



commit 2346ccde436b752061d0376b84dcbb663fc50ce8
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Jun 5 08:31:06 2014 -0400

    inspector: show GMenus
    
    This does not quite work yet, and I have no idea why.

 gtk/inspector/Makefile.am             |    3 +
 gtk/inspector/init.c                  |    2 +
 gtk/inspector/inspector.gresource.xml |    1 +
 gtk/inspector/menu.c                  |  118 +++++++++++++++++++++++++++++++++
 gtk/inspector/menu.ui                 |   83 +++++++++++++++++++++++
 gtk/inspector/window.c                |    5 +-
 gtk/inspector/window.h                |    1 +
 gtk/inspector/window.ui               |   14 ++++
 po/POTFILES.in                        |    1 +
 9 files changed, 227 insertions(+), 1 deletions(-)
---
diff --git a/gtk/inspector/Makefile.am b/gtk/inspector/Makefile.am
index 896da9c..72777d7 100644
--- a/gtk/inspector/Makefile.am
+++ b/gtk/inspector/Makefile.am
@@ -35,6 +35,8 @@ libgtkinspector_la_SOURCES =          \
        init.h                          \
        init.c                          \
        inspect-button.c                \
+       menu.h                          \
+       menu.c                          \
        object-hierarchy.h              \
        object-hierarchy.c              \
        prop-editor.h                   \
@@ -91,6 +93,7 @@ templates =                           \
        css-editor.ui                   \
        data-list.ui                    \
        general.ui                      \
+       menu.ui                         \
        object-hierarchy.ui             \
        prop-list.ui                    \
        resource-list.ui                \
diff --git a/gtk/inspector/init.c b/gtk/inspector/init.c
index 08952aa..4fdbbcd 100644
--- a/gtk/inspector/init.c
+++ b/gtk/inspector/init.c
@@ -29,6 +29,7 @@
 #include "data-list.h"
 #include "general.h"
 #include "gestures.h"
+#include "menu.h"
 #include "object-hierarchy.h"
 #include "prop-list.h"
 #include "python-hooks.h"
@@ -57,6 +58,7 @@ gtk_inspector_init (void)
   g_type_ensure (GTK_TYPE_INSPECTOR_DATA_LIST);
   g_type_ensure (GTK_TYPE_INSPECTOR_GENERAL);
   g_type_ensure (GTK_TYPE_INSPECTOR_GESTURES);
+  g_type_ensure (GTK_TYPE_INSPECTOR_MENU);
   g_type_ensure (GTK_TYPE_INSPECTOR_OBJECT_HIERARCHY);
   g_type_ensure (GTK_TYPE_INSPECTOR_PROP_LIST);
   g_type_ensure (GTK_TYPE_INSPECTOR_PYTHON_SHELL);
diff --git a/gtk/inspector/inspector.gresource.xml b/gtk/inspector/inspector.gresource.xml
index 135d2b0..774161b 100644
--- a/gtk/inspector/inspector.gresource.xml
+++ b/gtk/inspector/inspector.gresource.xml
@@ -7,6 +7,7 @@
     <file compressed="true">css-editor.ui</file>
     <file compressed="true">data-list.ui</file>
     <file compressed="true">general.ui</file>
+    <file compressed="true">menu.ui</file>
     <file compressed="true">object-hierarchy.ui</file>
     <file compressed="true">prop-list.ui</file>
     <file compressed="true">resource-list.ui</file>
diff --git a/gtk/inspector/menu.c b/gtk/inspector/menu.c
new file mode 100644
index 0000000..d73d3f2
--- /dev/null
+++ b/gtk/inspector/menu.c
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2014 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include <glib/gi18n-lib.h>
+#include "menu.h"
+#include "gtkwidgetprivate.h"
+
+enum
+{
+  COLUMN_TYPE,
+  COLUMN_LABEL,
+  COLUMN_ACTION,
+  COLUMN_TARGET,
+  COLUMN_ICON
+};
+
+struct _GtkInspectorMenuPrivate
+{
+  GtkTreeStore *model;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorMenu, gtk_inspector_menu, GTK_TYPE_BOX)
+
+static void
+gtk_inspector_menu_init (GtkInspectorMenu *sl)
+{
+  sl->priv = gtk_inspector_menu_get_instance_private (sl);
+  gtk_widget_init_template (GTK_WIDGET (sl));
+}
+
+static void
+add_item (GtkInspectorMenu *sl,
+          GMenuModel       *menu,
+          gint              idx,
+          GtkTreeIter      *parent)
+{
+  GtkTreeIter iter;
+  GVariant *value;
+  gchar *label = NULL;
+  gchar *action = NULL;
+  gchar *target = NULL;
+  gchar *icon = NULL;
+
+  g_menu_model_get_item_attribute (menu, idx, G_MENU_ATTRIBUTE_LABEL, "s", &label);
+  g_menu_model_get_item_attribute (menu, idx, G_MENU_ATTRIBUTE_ACTION, "s", &action);
+  value = g_menu_model_get_item_attribute_value (menu, idx, G_MENU_ATTRIBUTE_TARGET, NULL);
+  if (value)
+    {
+      target = g_variant_print (value, FALSE);
+      g_variant_unref (value);
+    }
+
+  gtk_tree_store_append (sl->priv->model, &iter, parent);
+  gtk_tree_store_set (sl->priv->model, &iter,
+                      COLUMN_TYPE, "item",
+                      COLUMN_LABEL, label,
+                      COLUMN_ACTION, action,
+                      COLUMN_TARGET, target,
+                      COLUMN_ICON, icon,
+                      -1);
+
+  g_free (label);
+  g_free (action);
+  g_free (target);
+  g_free (icon);
+}
+
+static void
+add_menu (GtkInspectorMenu *sl,
+          GMenuModel       *menu,
+          GtkTreeIter      *parent)
+{
+  gint n_items;
+  gint i;
+
+  gtk_widget_show (GTK_WIDGET (sl));
+
+  n_items = g_menu_model_get_n_items (menu);
+  for (i = 0; i < n_items; i++)
+    add_item (sl, menu, i, parent);
+}
+
+void
+gtk_inspector_menu_set_object (GtkInspectorMenu *sl,
+                               GObject          *object)
+{
+  gtk_widget_hide (GTK_WIDGET (sl));
+  gtk_tree_store_clear (sl->priv->model);
+  
+  if (G_IS_MENU_MODEL (object))
+    add_menu (sl, G_MENU_MODEL (object), NULL);
+}
+
+static void
+gtk_inspector_menu_class_init (GtkInspectorMenuClass *klass)
+{
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/inspector/menu.ui");
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMenu, model);
+}
+
+// vim: set et sw=2 ts=2:
diff --git a/gtk/inspector/menu.ui b/gtk/inspector/menu.ui
new file mode 100644
index 0000000..b63ee92
--- /dev/null
+++ b/gtk/inspector/menu.ui
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="gtk30">
+  <object class="GtkTreeStore" id="model">
+    <columns>
+      <column type="gchararray"/> <!-- type -->
+      <column type="gchararray"/> <!-- label -->
+      <column type="gchararray"/> <!-- action -->
+      <column type="gchararray"/> <!-- target -->
+      <column type="gchararray"/> <!-- icon -->
+    </columns>
+  </object>
+  <template class="GtkInspectorMenu" parent="GtkBox">
+    <property name="orientation">vertical</property>
+    <child>
+      <object class="GtkScrolledWindow">
+        <property name="visible">True</property>
+        <property name="expand">True</property>
+        <property name="hscrollbar-policy">automatic</property>
+        <property name="vscrollbar-policy">always</property>
+        <property name="shadow-type">in</property>
+        <child>
+          <object class= "GtkTreeView">
+            <property name="visible">True</property>
+            <property name="model">model</property>
+            <property name="activate-on-single-click">True</property>
+            <child>
+              <object class="GtkTreeViewColumn">
+                <property name="title" translatable="yes">Label</property>
+                <child>
+                  <object class="GtkCellRendererText">
+                    <property name="scale">0.8</property>
+                  </object>
+                  <attributes>
+                    <attribute name="text">1</attribute>
+                  </attributes>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="GtkTreeViewColumn">
+                <property name="title" translatable="yes">Action</property>
+                <child>
+                  <object class="GtkCellRendererText">
+                    <property name="scale">0.8</property>
+                  </object>
+                  <attributes>
+                    <attribute name="text">2</attribute>
+                  </attributes>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="GtkTreeViewColumn">
+                <property name="title" translatable="yes">Target</property>
+                <child>
+                  <object class="GtkCellRendererText">
+                    <property name="scale">0.8</property>
+                  </object>
+                  <attributes>
+                    <attribute name="text">3</attribute>
+                  </attributes>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="GtkTreeViewColumn">
+                <property name="title" translatable="yes">Icon</property>
+                <child>
+                  <object class="GtkCellRendererText">
+                    <property name="scale">0.8</property>
+                  </object>
+                  <attributes>
+                    <attribute name="text">4</attribute>
+                  </attributes>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/gtk/inspector/window.c b/gtk/inspector/window.c
index ff0f9b2..eee2712 100644
--- a/gtk/inspector/window.c
+++ b/gtk/inspector/window.c
@@ -36,9 +36,10 @@
 #include "button-path.h"
 #include "size-groups.h"
 #include "data-list.h"
-#include "gestures.h"
 #include "signals-list.h"
 #include "actions.h"
+#include "menu.h"
+#include "gestures.h"
 
 
 G_DEFINE_TYPE (GtkInspectorWindow, gtk_inspector_window, GTK_TYPE_WINDOW)
@@ -78,6 +79,7 @@ on_widget_tree_selection_changed (GtkInspectorWidgetTree *wt,
   gtk_inspector_size_groups_set_object (GTK_INSPECTOR_SIZE_GROUPS (iw->size_groups), selected);
   gtk_inspector_data_list_set_object (GTK_INSPECTOR_DATA_LIST (iw->data_list), selected);
   gtk_inspector_actions_set_object (GTK_INSPECTOR_ACTIONS (iw->actions), selected);
+  gtk_inspector_menu_set_object (GTK_INSPECTOR_MENU (iw->menu), selected);
   gtk_inspector_gestures_set_object (GTK_INSPECTOR_GESTURES (iw->gestures), selected);
 
   notebook = gtk_widget_get_parent (iw->prop_list);
@@ -198,6 +200,7 @@ gtk_inspector_window_class_init (GtkInspectorWindowClass *klass)
   gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, size_groups);
   gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, data_list);
   gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, actions);
+  gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, menu);
   gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, gestures);
 
   gtk_widget_class_bind_template_callback (widget_class, on_inspect);
diff --git a/gtk/inspector/window.h b/gtk/inspector/window.h
index f7d531d..6b0e9d0 100644
--- a/gtk/inspector/window.h
+++ b/gtk/inspector/window.h
@@ -54,6 +54,7 @@ typedef struct
   GtkWidget *size_groups;
   GtkWidget *data_list;
   GtkWidget *actions;
+  GtkWidget *menu;
   GtkWidget *gestures;
 
   GtkWidget *widget_popup;
diff --git a/gtk/inspector/window.ui b/gtk/inspector/window.ui
index 81b6516..a38dc9e 100644
--- a/gtk/inspector/window.ui
+++ b/gtk/inspector/window.ui
@@ -240,6 +240,20 @@
                       </object>
                     </child>
                     <child>
+                      <object class="GtkInspectorMenu" id="menu">
+                      </object>
+                      <packing>
+                        <property name="tab_expand">True</property>
+                        <property name="tab_fill">True</property>
+                      </packing>
+                    </child>
+                    <child type="tab">
+                      <object class="GtkLabel">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">Menu</property>
+                      </object>
+                    </child>
+                    <child>
                       <object class="GtkInspectorGestures" id="gestures">
                         <property name="widget-tree">widget_tree</property>
                       </object>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5427a23..4cc08c2 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -281,6 +281,7 @@ gtk/inspector/data-list.ui.h
 gtk/inspector/general.ui.h
 gtk/inspector/gestures.c
 gtk/inspector/inspect-button.c
+gtk/inspector/menu.ui.h
 gtk/inspector/object-hierarchy.ui.h
 gtk/inspector/prop-editor.c
 gtk/inspector/prop-list.ui.h


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]