[gtk-doc/gtk-doc-for-gtk4: 16/25] scangobj: Introspect GTK4 actions




commit c755ff3ba0889d3da7f8097f9175f482d78c56fe
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Jun 22 04:38:16 2019 +0000

    scangobj: Introspect GTK4 actions
    
    GTK4 can define actions for widget classes.
    Write these out to a .actions file.

 gtkdoc/scangobj.py | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
---
diff --git a/gtkdoc/scangobj.py b/gtkdoc/scangobj.py
index 003c5179..296fd850 100644
--- a/gtkdoc/scangobj.py
+++ b/gtkdoc/scangobj.py
@@ -100,6 +100,7 @@ const gchar *hierarchy_filename = "${new_hierarchy_filename}";
 const gchar *interfaces_filename = "${new_interfaces_filename}";
 const gchar *prerequisites_filename = "${new_prerequisites_filename}";
 const gchar *args_filename = "${new_args_filename}";
+const gchar *actions_filename = "${new_actions_filename}";
 
 static void output_signals (void);
 static void output_object_signals (FILE *fp,
@@ -125,6 +126,9 @@ static void output_prerequisites (FILE *fp,
 static void output_args (void);
 static void output_object_args (FILE *fp, GType object_type);
 
+static void output_actions (void);
+static void output_object_actions (FILE *fp, GType object_type);
+
 int
 main (${main_func_params})
 {
@@ -137,6 +141,7 @@ main (${main_func_params})
   output_object_interfaces ();
   output_interface_prerequisites ();
   output_args ();
+  output_actions ();
 
   return 0;
 }
@@ -565,6 +570,71 @@ output_prerequisites (FILE  *fp,
 #endif
 }
 
+static void
+output_actions (void)
+{
+  FILE *fp;
+  gint i;
+
+  fp = fopen (actions_filename, "w");
+  if (fp == NULL) {
+    g_warning ("Couldn't open output file: %s : %s", actions_filename, g_strerror(errno));
+    return;
+  }
+
+  for (i = 0; object_types[i]; i++) {
+    output_object_actions (fp, object_types[i]);
+  }
+
+  fclose (fp);
+}
+
+static void
+output_object_actions (FILE *fp, GType object_type)
+{
+  gpointer class;
+
+  if (!G_TYPE_IS_OBJECT (object_type))
+    return;
+
+  class = g_type_class_peek (object_type);
+  if (!class)
+    return;
+
+#ifdef GTK_IS_WIDGET_CLASS
+#if GTK_CHECK_VERSION(3,96,0)
+  if (GTK_IS_WIDGET_CLASS (class)) {
+    guint i = 0;
+    const char *action_name;
+    GType owner;
+    const GVariantType *parameter_type;
+    const char *property_name;
+    const gchar *object_class_name;
+
+    object_class_name = g_type_name (object_type);
+    while (gtk_widget_class_query_action (GTK_WIDGET_CLASS (class),
+                                          i,
+                                          &owner,
+                                          &action_name,
+                                          &parameter_type,
+                                          &property_name)) {
+      i++;
+      if (owner == G_TYPE_FROM_CLASS (class))
+        fprintf (fp, "<ACTION>\\n"
+                     "<NAME>%s:::%s</NAME>\\n"
+                     "<PARAMETER>%s</PARAMETER>\\n"
+                     "<PROPERTY>%s</PROPERTY>\\n"
+                     "</ACTION>\\n\\n",
+                 object_class_name,
+                 action_name,
+                 parameter_type ? g_variant_type_peek_string (parameter_type) : "",
+                 property_name ? property_name : "");
+    }
+  }
+#endif
+#endif
+}
+
 static void
 output_args (void)
 {
@@ -1225,6 +1295,8 @@ def run(options):
     new_prerequisites_filename = base_filename + '.prerequisites.new'
     old_args_filename = base_filename + '.args'
     new_args_filename = base_filename + '.args.new'
+    old_actions_filename = base_filename + '.actions'
+    new_actions_filename = base_filename + '.actions.new'
 
     # generate a C program to scan the types
 
@@ -1335,5 +1407,6 @@ def run(options):
     common.UpdateFileIfChanged(old_interfaces_filename, new_interfaces_filename, False)
     common.UpdateFileIfChanged(old_prerequisites_filename, new_prerequisites_filename, False)
     common.UpdateFileIfChanged(old_args_filename, new_args_filename, False)
+    common.UpdateFileIfChanged(old_actions_filename, new_actions_filename, False)
 
     return 0


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