[gtk+] inspector: Show GAction information



commit 2d2f9861a6630668587f0d4f67098fc1ec2cf8e8
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue May 13 20:36:02 2014 -0400

    inspector: Show GAction information
    
    Show the actions that are added to GtkApplication and
    GtkApplicationWindows, as well as action groups that are
    inserted elsewhere with gtk_widget_insert_action_group.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=730095

 gtk/inspector/Makefile.am             |    3 +
 gtk/inspector/actions.c               |  131 +++++++++++++++++++++++++++++++++
 gtk/inspector/actions.h               |   55 ++++++++++++++
 gtk/inspector/actions.ui              |  103 ++++++++++++++++++++++++++
 gtk/inspector/init.c                  |    2 +
 gtk/inspector/inspector.gresource.xml |    1 +
 gtk/inspector/window.c                |    4 +
 gtk/inspector/window.h                |    1 +
 gtk/inspector/window.ui               |   10 +++
 po/POTFILES.in                        |    1 +
 10 files changed, 311 insertions(+), 0 deletions(-)
---
diff --git a/gtk/inspector/Makefile.am b/gtk/inspector/Makefile.am
index 4ca2cdd..d1d5706 100644
--- a/gtk/inspector/Makefile.am
+++ b/gtk/inspector/Makefile.am
@@ -15,6 +15,8 @@ BUILT_SOURCES =                       \
        resources.c
 
 libgtkinspector_la_SOURCES =           \
+       actions.h                       \
+       actions.c                       \
        button-path.h                   \
        button-path.c                   \
        classes-list.h                  \
@@ -74,6 +76,7 @@ libgtkinspector_la_LDFLAGS =          \
        $(LDFLAGS)
 
 templates =                            \
+       actions.ui                      \
        button-path.ui                  \
        classes-list.ui                 \
        css-editor.ui                   \
diff --git a/gtk/inspector/actions.c b/gtk/inspector/actions.c
new file mode 100644
index 0000000..8b1e31a
--- /dev/null
+++ b/gtk/inspector/actions.c
@@ -0,0 +1,131 @@
+/*
+ * 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 "actions.h"
+#include "gtkwidgetprivate.h"
+
+enum
+{
+  COLUMN_PREFIX,
+  COLUMN_NAME,
+  COLUMN_ENABLED,
+  COLUMN_PARAMETER,
+  COLUMN_STATE
+};
+
+struct _GtkInspectorActionsPrivate
+{
+  GtkListStore *model;
+  GtkWidget *prefix_label;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorActions, gtk_inspector_actions, GTK_TYPE_BOX)
+
+static void
+gtk_inspector_actions_init (GtkInspectorActions *sl)
+{
+  sl->priv = gtk_inspector_actions_get_instance_private (sl);
+  gtk_widget_init_template (GTK_WIDGET (sl));
+}
+
+static void
+add_actions (GtkInspectorActions *sl,
+             const gchar         *prefix,
+             GActionGroup        *group)
+{
+  GtkTreeIter iter;
+  gint i;
+  gchar **names;
+  gboolean enabled;
+  const gchar *parameter;
+  GVariant *state;
+  gchar *state_string;
+
+  gtk_widget_show (GTK_WIDGET (sl));
+
+  names = g_action_group_list_actions (group);
+  for (i = 0; names[i]; i++)
+    {
+      enabled = g_action_group_get_action_enabled (group, names[i]);
+      parameter = (const gchar *)g_action_group_get_action_parameter_type (group, names[i]);
+      state = g_action_group_get_action_state (group, names[i]);
+      if (state)
+        state_string = g_variant_print (state, FALSE);
+      else
+        state_string = g_strdup ("");
+      gtk_list_store_append (sl->priv->model, &iter);
+      gtk_list_store_set (sl->priv->model, &iter,
+                          COLUMN_PREFIX, prefix,
+                          COLUMN_NAME, names[i],
+                          COLUMN_ENABLED, enabled,
+                          COLUMN_PARAMETER, parameter,
+                          COLUMN_STATE, state_string,
+                          -1);
+      g_free (state_string);
+    }
+  g_strfreev (names);
+}
+
+void
+gtk_inspector_actions_set_object (GtkInspectorActions *sl,
+                                  GObject             *object)
+{
+  gtk_list_store_clear (sl->priv->model);
+  gtk_widget_hide (GTK_WIDGET (sl));
+
+  if (GTK_IS_APPLICATION (object))
+    add_actions (sl, "app", G_ACTION_GROUP (object));
+  else if (GTK_IS_APPLICATION_WINDOW (object))
+    add_actions (sl, "win", G_ACTION_GROUP (object));
+  else if (GTK_IS_WIDGET (object))
+    {
+      gchar **prefixes;
+      GActionGroup *group;
+      gint i;
+
+      prefixes = _gtk_widget_list_action_prefixes (GTK_WIDGET (object));
+      if (prefixes)
+        {
+          for (i = 0; prefixes[i]; i++)
+            {
+              group = _gtk_widget_get_action_group (GTK_WIDGET (object), prefixes[i]);
+              add_actions (sl, prefixes[i], group);
+            }
+          g_free (prefixes);
+        }
+    }
+}
+
+static void
+gtk_inspector_actions_class_init (GtkInspectorActionsClass *klass)
+{
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/inspector/actions.ui");
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorActions, model);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorActions, prefix_label);
+}
+
+GtkWidget *
+gtk_inspector_actions_new (void)
+{
+  return GTK_WIDGET (g_object_new (GTK_TYPE_INSPECTOR_ACTIONS, NULL));
+}
+
+// vim: set et sw=2 ts=2:
diff --git a/gtk/inspector/actions.h b/gtk/inspector/actions.h
new file mode 100644
index 0000000..050f3c2
--- /dev/null
+++ b/gtk/inspector/actions.h
@@ -0,0 +1,55 @@
+/*
+ * 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/>.
+ */
+
+#ifndef _GTK_INSPECTOR_ACTIONS_H_
+#define _GTK_INSPECTOR_ACTIONS_H_
+
+#include <gtk/gtk.h>
+
+#define GTK_TYPE_INSPECTOR_ACTIONS            (gtk_inspector_actions_get_type())
+#define GTK_INSPECTOR_ACTIONS(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_INSPECTOR_ACTIONS, 
GtkInspectorActions))
+#define GTK_INSPECTOR_ACTIONS_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), GTK_TYPE_INSPECTOR_ACTIONS, 
GtkInspectorActionsClass))
+#define GTK_INSPECTOR_IS_ACTIONS(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_TYPE_INSPECTOR_ACTIONS))
+#define GTK_INSPECTOR_IS_ACTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_TYPE_INSPECTOR_ACTIONS))
+#define GTK_INSPECTOR_ACTIONS_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_INSPECTOR_ACTIONS, 
GtkInspectorActionsClass))
+
+
+typedef struct _GtkInspectorActionsPrivate GtkInspectorActionsPrivate;
+
+typedef struct _GtkInspectorActions
+{
+  GtkBox parent;
+  GtkInspectorActionsPrivate *priv;
+} GtkInspectorActions;
+
+typedef struct _GtkInspectorActionsClass
+{
+  GtkBoxClass parent;
+} GtkInspectorActionsClass;
+
+G_BEGIN_DECLS
+
+GType      gtk_inspector_actions_get_type   (void);
+GtkWidget *gtk_inspector_actions_new        (void);
+void       gtk_inspector_actions_set_object (GtkInspectorActions *sl,
+                                             GObject              *object);
+
+G_END_DECLS
+
+#endif // _GTK_INSPECTOR_ACTIONS_H_
+
+// vim: set et sw=2 ts=2:
diff --git a/gtk/inspector/actions.ui b/gtk/inspector/actions.ui
new file mode 100644
index 0000000..cdc92b9
--- /dev/null
+++ b/gtk/inspector/actions.ui
@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="gtk30">
+  <object class="GtkListStore" id="model">
+    <columns>
+      <column type="gchararray"/>
+      <column type="gchararray"/>
+      <column type="gboolean"/>
+      <column type="gchararray"/>
+      <column type="gchararray"/>
+      <column type="gchararray"/>
+    </columns>
+  </object>
+  <template class="GtkInspectorActions" parent="GtkBox">
+    <property name="orientation">vertical</property>
+    <child>
+      <object class="GtkLabel" id="prefix_label">
+        <property name="visible">True</property>
+        <property name="halign">start</property>
+        <property name="margin">20</property>
+      </object>
+    </child>
+    <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>
+            <child>
+              <object class="GtkTreeViewColumn">
+                <property name="title" translatable="yes">Prefix</property>
+                <child>
+                  <object class="GtkCellRendererText">
+                    <property name="scale">0.8</property>
+                  </object>
+                  <attributes>
+                    <attribute name="text">0</attribute>
+                  </attributes>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="GtkTreeViewColumn">
+                <property name="title" translatable="yes">Name</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">Enabled</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">Parameter Type</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">State</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/init.c b/gtk/inspector/init.c
index 528e0eb..027f374 100644
--- a/gtk/inspector/init.c
+++ b/gtk/inspector/init.c
@@ -22,6 +22,7 @@
  */
 #include <glib.h>
 
+#include "actions.h"
 #include "button-path.h"
 #include "classes-list.h"
 #include "css-editor.h"
@@ -47,6 +48,7 @@ gtk_inspector_init (void)
 
   gtk_inspector_register_resource ();
 
+  g_type_ensure (GTK_TYPE_INSPECTOR_ACTIONS);
   g_type_ensure (GTK_TYPE_INSPECTOR_BUTTON_PATH);
   g_type_ensure (GTK_TYPE_INSPECTOR_CLASSES_LIST);
   g_type_ensure (GTK_TYPE_INSPECTOR_CSS_EDITOR);
diff --git a/gtk/inspector/inspector.gresource.xml b/gtk/inspector/inspector.gresource.xml
index fb65fad..74081fb 100644
--- a/gtk/inspector/inspector.gresource.xml
+++ b/gtk/inspector/inspector.gresource.xml
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
   <gresource prefix="/org/gtk/inspector">
+    <file>actions.ui</file>
     <file>button-path.ui</file>
     <file>classes-list.ui</file>
     <file>css-editor.ui</file>
diff --git a/gtk/inspector/window.c b/gtk/inspector/window.c
index f1928b6..0bcf066 100644
--- a/gtk/inspector/window.c
+++ b/gtk/inspector/window.c
@@ -38,6 +38,8 @@
 #include "data-list.h"
 #include "themes.h"
 #include "signals-list.h"
+#include "actions.h"
+
 
 G_DEFINE_TYPE (GtkInspectorWindow, gtk_inspector_window, GTK_TYPE_WINDOW)
 
@@ -71,6 +73,7 @@ on_widget_tree_selection_changed (GtkInspectorWidgetTree *wt,
   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);
   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);
   if (GTK_IS_WIDGET (selected))
     gtk_inspector_flash_widget (iw, GTK_WIDGET (selected));
 }
@@ -168,6 +171,7 @@ gtk_inspector_window_class_init (GtkInspectorWindowClass *klass)
   gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, python_shell);
   gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, widget_popup);
   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_callback (widget_class, on_inspect);
   gtk_widget_class_bind_template_callback (widget_class, on_widget_tree_selection_changed);
diff --git a/gtk/inspector/window.h b/gtk/inspector/window.h
index da2742f..2621f26 100644
--- a/gtk/inspector/window.h
+++ b/gtk/inspector/window.h
@@ -51,6 +51,7 @@ typedef struct
   GtkWidget *widget_css_editor;
   GtkWidget *object_hierarchy;
   GtkWidget *data_list;
+  GtkWidget *actions;
 
   GtkWidget *widget_popup;
 
diff --git a/gtk/inspector/window.ui b/gtk/inspector/window.ui
index f8007b2..238bd36 100644
--- a/gtk/inspector/window.ui
+++ b/gtk/inspector/window.ui
@@ -182,6 +182,16 @@
                         <property name="label" translatable="yes">Data</property>
                       </object>
                     </child> 
+                    <child>
+                      <object class="GtkInspectorActions" id="actions">
+                      </object>
+                    </child>
+                    <child type="tab">
+                      <object class="GtkLabel">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">Actions</property>
+                      </object>
+                    </child>
                   </object>
                   <packing>
                     <property name="resize">True</property>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 3e33f4e..574db4b 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -268,6 +268,7 @@ gtk/gtkviewport.c
 gtk/gtkvolumebutton.c
 gtk/gtkwidget.c
 gtk/gtkwindow.c
+gtk/inspector/actions.ui.h
 gtk/inspector/button-path.ui.h
 gtk/inspector/classes-list.c
 gtk/inspector/classes-list.ui.h


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