[gnome-builder] command-gaction-provider: add debug helper
- From: Sebastien Lafargue <slafargue src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] command-gaction-provider: add debug helper
- Date: Wed, 29 Apr 2015 20:54:58 +0000 (UTC)
commit 4748af93fd84cbe906bde5345d599990b90ffa4c
Author: Sebastien Lafargue <slafargue gnome org>
Date: Wed Apr 29 16:49:16 2015 +0200
command-gaction-provider: add debug helper
To better trace the existing GAction for the entire
application, we can use this helper : show_prefix_actions ()
Change #if 0 by #if 1 to activate it
( you can find them at the top of gb-command-gaction-provider.c file :
#if 0
#define GB_DEBUG_ACTIONS
To get the result in your terminal, show the command bar with ':'
then hit 'tab' ( like you do to list all the possible commands )
The result can be nicely seen as a .yaml file with syntax highlight
in all GtkSourceVIew based application.
https://bugzilla.gnome.org/show_bug.cgi?id=748652
src/commands/gb-command-gaction-provider.c | 79 ++++++++++++++++++++++++++++
1 files changed, 79 insertions(+), 0 deletions(-)
---
diff --git a/src/commands/gb-command-gaction-provider.c b/src/commands/gb-command-gaction-provider.c
index e0be5be..901ffb3 100644
--- a/src/commands/gb-command-gaction-provider.c
+++ b/src/commands/gb-command-gaction-provider.c
@@ -31,6 +31,16 @@
G_DEFINE_TYPE (GbCommandGactionProvider, gb_command_gaction_provider, GB_TYPE_COMMAND_PROVIDER)
+/* Set this to 1 to enable the debug helper which prints the
+ * content of Action groups to standard output :
+ *
+ * it's triggered by going to the command bar then hitting 'tab'
+ */
+
+#if 0
+#define GB_DEBUG_ACTIONS
+#endif
+
typedef struct
{
GActionGroup *group;
@@ -44,6 +54,67 @@ typedef struct
const gchar *action_name;
} GbActionCommandMap;
+/* Used to print discovered prefixes and GActions for a GObject */
+G_GNUC_UNUSED static void
+show_prefix_actions (GObject *object)
+{
+ const gchar **prefixes;
+ gchar **names;
+ guint i, n;
+ GActionGroup *group;
+
+ if (GTK_IS_WIDGET (object))
+ printf ("type: GtkWidget\n");
+ else if (G_IS_OBJECT (object))
+ printf ("type: GObject\n");
+ else
+ {
+ printf ("type: Unknow\n");
+ return;
+ }
+
+ printf (" type name: %s\n", G_OBJECT_TYPE_NAME (object));
+
+ if (GTK_IS_WIDGET (object))
+ {
+ prefixes = gtk_widget_list_action_prefixes (GTK_WIDGET (object));
+ if (prefixes [0] != NULL)
+ printf (" prefixes:\n");
+
+ for (i = 0; prefixes [i]; i++)
+ {
+ printf (" - %s:\n", prefixes [i]);
+ group = gtk_widget_get_action_group (GTK_WIDGET (object), prefixes [i]);
+ if (group)
+ {
+ names = g_action_group_list_actions (group);
+ if (names [0] != NULL)
+ printf (" names:\n");
+
+ for (n = 0; names [n]; n++)
+ printf (" - %s\n", names [n]);
+
+ printf ("\n");
+ }
+ else
+ {
+ printf (" names: no names - group is NULL\n");
+ }
+ }
+
+ printf ("\n");
+ }
+ else
+ {
+ names = g_action_group_list_actions (G_ACTION_GROUP (object));
+ if (names [0] != NULL)
+ printf (" names:\n");
+
+ for (n = 0; names [n]; n++)
+ printf (" - %s\n", names [n]);
+ }
+}
+
GbCommandProvider *
gb_command_gaction_provider_new (GbWorkbench *workbench)
{
@@ -98,6 +169,10 @@ discover_groups (GbCommandGactionProvider *provider)
const gchar **prefixes;
guint i;
+#ifdef GB_DEBUG_ACTIONS
+ show_prefix_actions (G_OBJECT (widget));
+#endif
+
/* We exclude these types, they're already in the widgets hierarchy */
type = G_OBJECT_TYPE (widget);
if (type == GB_TYPE_EDITOR_WORKSPACE || type == GB_TYPE_EDITOR_VIEW)
@@ -126,6 +201,10 @@ discover_groups (GbCommandGactionProvider *provider)
gb_group = gb_group_new (G_ACTION_GROUP (application), "app");
list = g_list_append (list, gb_group);
+#ifdef GB_DEBUG_ACTIONS
+ show_prefix_actions (G_OBJECT (application));
+#endif
+
return list;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]