[gtk/shortcuts-rebased-again: 104/135] inspector: Add a quick shortcuts page



commit c6d0b0ac1d2b641d893fe459d577a1224175c04e
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jun 19 04:28:56 2019 +0000

    inspector: Add a quick shortcuts page
    
    This shows the shortcuts for a GtkShortcutController
    object.

 gtk/inspector/init.c       |   2 +
 gtk/inspector/meson.build  |   1 +
 gtk/inspector/shortcuts.c  | 161 +++++++++++++++++++++++++++++++++++++++++++++
 gtk/inspector/shortcuts.h  |  40 +++++++++++
 gtk/inspector/shortcuts.ui |  66 +++++++++++++++++++
 gtk/inspector/window.c     |   3 +
 gtk/inspector/window.h     |   1 +
 gtk/inspector/window.ui    |   9 +++
 8 files changed, 283 insertions(+)
---
diff --git a/gtk/inspector/init.c b/gtk/inspector/init.c
index 6c9230fca5..112ec81538 100644
--- a/gtk/inspector/init.c
+++ b/gtk/inspector/init.c
@@ -40,6 +40,7 @@
 #include "prop-list.h"
 #include "recorder.h"
 #include "resource-list.h"
+#include "shortcuts.h"
 #include "size-groups.h"
 #include "statistics.h"
 #include "visual.h"
@@ -73,6 +74,7 @@ gtk_inspector_init (void)
   g_type_ensure (GTK_TYPE_INSPECTOR_PROP_LIST);
   g_type_ensure (GTK_TYPE_INSPECTOR_RECORDER);
   g_type_ensure (GTK_TYPE_INSPECTOR_RESOURCE_LIST);
+  g_type_ensure (GTK_TYPE_INSPECTOR_SHORTCUTS);
   g_type_ensure (GTK_TYPE_INSPECTOR_SIZE_GROUPS);
   g_type_ensure (GTK_TYPE_INSPECTOR_STATISTICS);
   g_type_ensure (GTK_TYPE_INSPECTOR_VISUAL);
diff --git a/gtk/inspector/meson.build b/gtk/inspector/meson.build
index a26d67ed87..cdbadf84a9 100644
--- a/gtk/inspector/meson.build
+++ b/gtk/inspector/meson.build
@@ -26,6 +26,7 @@ inspector_sources = files(
   'recording.c',
   'renderrecording.c',
   'resource-list.c',
+  'shortcuts.c',
   'size-groups.c',
   'startrecording.c',
   'statistics.c',
diff --git a/gtk/inspector/shortcuts.c b/gtk/inspector/shortcuts.c
new file mode 100644
index 0000000000..b1630ab31e
--- /dev/null
+++ b/gtk/inspector/shortcuts.c
@@ -0,0 +1,161 @@
+/*
+ * Copyright (c) 2019 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 "shortcuts.h"
+
+#include "gtkliststore.h"
+#include "gtkwidgetprivate.h"
+#include "gtkpopover.h"
+#include "gtklabel.h"
+#include "gtkstack.h"
+#include "gtklistbox.h"
+#include "gtkstylecontext.h"
+#include "gtksizegroup.h"
+#include "gtkshortcutaction.h"
+#include "gtkshortcuttrigger.h"
+#include "gtkshortcutcontroller.h"
+#include "gtkshortcut.h"
+
+struct _GtkInspectorShortcuts
+{
+  GtkBox parent;
+  GtkWidget *list;
+  GtkSizeGroup *name;
+  GtkSizeGroup *trigger;
+  GtkSizeGroup *action;
+  GtkSizeGroup *arguments;
+  GtkShortcutController *controller;
+};
+
+typedef GtkBoxClass GtkInspectorShortcutsClass;
+
+G_DEFINE_TYPE (GtkInspectorShortcuts, gtk_inspector_shortcuts, GTK_TYPE_BOX)
+
+static void
+gtk_inspector_shortcuts_init (GtkInspectorShortcuts *sl)
+{
+  gtk_widget_init_template (GTK_WIDGET (sl));
+}
+
+static GtkWidget *
+create_row (gpointer item,
+            gpointer user_data)
+{
+  GtkShortcut *shortcut = item;
+  GtkInspectorShortcuts *sl = user_data;
+  GtkShortcutTrigger *trigger;
+  GtkShortcutAction *action;
+  GVariant *arguments;
+  GtkWidget *row;
+  GtkWidget *box;
+  GtkWidget *label;
+  char *str;
+
+  trigger = gtk_shortcut_get_trigger (shortcut);
+  action = gtk_shortcut_get_action (shortcut);
+  arguments = gtk_shortcut_get_arguments (shortcut);
+
+  row = gtk_list_box_row_new ();
+  gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (row), FALSE);
+  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+  gtk_container_add (GTK_CONTAINER (row), box);
+
+  if (trigger)
+    str = gtk_shortcut_trigger_to_string (trigger);
+  else
+    str = NULL;
+  label = gtk_label_new (str);
+  gtk_style_context_add_class (gtk_widget_get_style_context (label), "cell");
+  gtk_label_set_xalign (GTK_LABEL (label), 0);
+  gtk_size_group_add_widget (sl->trigger, label);
+  gtk_container_add (GTK_CONTAINER (box), label);
+  g_free (str);
+
+  if (action)
+    str = gtk_shortcut_action_to_string (action);
+  else
+    str = NULL;
+  label = gtk_label_new (str);
+  gtk_style_context_add_class (gtk_widget_get_style_context (label), "cell");
+  gtk_label_set_xalign (GTK_LABEL (label), 0);
+  gtk_widget_set_halign (label, GTK_ALIGN_CENTER);
+  gtk_size_group_add_widget (sl->action, label);
+  gtk_container_add (GTK_CONTAINER (box), label);
+
+  if (arguments)
+    str = g_variant_print (arguments, FALSE);
+  else
+    str = NULL;
+  label = gtk_label_new (str);
+  gtk_style_context_add_class (gtk_widget_get_style_context (label), "cell");
+  gtk_label_set_xalign (GTK_LABEL (label), 0);
+  gtk_size_group_add_widget (sl->arguments, label);
+  gtk_container_add (GTK_CONTAINER (box), label);
+
+  return row;
+}
+
+void
+gtk_inspector_shortcuts_set_object (GtkInspectorShortcuts *sl,
+                                    GObject               *object)
+{
+  GtkWidget *stack;
+  GtkStackPage *page;
+
+  stack = gtk_widget_get_parent (GTK_WIDGET (sl));
+  page = gtk_stack_get_page (GTK_STACK (stack), GTK_WIDGET (sl));
+
+  if (sl->controller)
+    {
+      g_object_set (page, "visible", FALSE, NULL);
+      gtk_list_box_bind_model (GTK_LIST_BOX (sl->list),
+                               NULL,
+                               create_row,
+                               sl,
+                               NULL);
+      g_clear_object (&sl->controller);
+    }
+
+  if (GTK_IS_SHORTCUT_CONTROLLER (object))
+    {
+      g_set_object (&sl->controller, GTK_SHORTCUT_CONTROLLER (object));
+      gtk_list_box_bind_model (GTK_LIST_BOX (sl->list),
+                               G_LIST_MODEL (sl->controller),
+                               create_row,
+                               sl,
+                               NULL);
+      g_object_set (page, "visible", TRUE, NULL);
+    }
+}
+
+static void
+gtk_inspector_shortcuts_class_init (GtkInspectorShortcutsClass *klass)
+{
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/shortcuts.ui");
+
+  gtk_widget_class_bind_template_child (widget_class, GtkInspectorShortcuts, list);
+  gtk_widget_class_bind_template_child (widget_class, GtkInspectorShortcuts, trigger);
+  gtk_widget_class_bind_template_child (widget_class, GtkInspectorShortcuts, action);
+  gtk_widget_class_bind_template_child (widget_class, GtkInspectorShortcuts, arguments);
+}
+
+// vim: set et sw=2 ts=2:
diff --git a/gtk/inspector/shortcuts.h b/gtk/inspector/shortcuts.h
new file mode 100644
index 0000000000..472022b477
--- /dev/null
+++ b/gtk/inspector/shortcuts.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2019 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_SHORTCUTS_H_
+#define _GTK_INSPECTOR_SHORTCUTS_H_
+
+#include <gtk/gtkbox.h>
+
+#define GTK_TYPE_INSPECTOR_SHORTCUTS            (gtk_inspector_shortcuts_get_type())
+#define GTK_INSPECTOR_SHORTCUTS(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), 
GTK_TYPE_INSPECTOR_SHORTCUTS, GtkInspectorShortcuts))
+#define GTK_INSPECTOR_IS_SHORTCUTS(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), 
GTK_TYPE_INSPECTOR_SHORTCUTS))
+
+
+typedef struct _GtkInspectorShortcuts GtkInspectorShortcuts;
+
+G_BEGIN_DECLS
+
+GType      gtk_inspector_shortcuts_get_type   (void);
+void       gtk_inspector_shortcuts_set_object (GtkInspectorShortcuts *sl,
+                                               GObject             *object);
+
+G_END_DECLS
+
+#endif // _GTK_INSPECTOR_SHORTCUTS_H_
+
+// vim: set et sw=2 ts=2:
diff --git a/gtk/inspector/shortcuts.ui b/gtk/inspector/shortcuts.ui
new file mode 100644
index 0000000000..481dcfd2ad
--- /dev/null
+++ b/gtk/inspector/shortcuts.ui
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="gtk40">
+  <template class="GtkInspectorShortcuts" parent="GtkBox">
+    <property name="orientation">vertical</property>
+    <style>
+      <class name="view"/>
+    </style>
+    <child>
+      <object class="GtkBox">
+        <style>
+          <class name="header"/>
+        </style>
+        <child>
+          <object class="GtkLabel" id="trigger_heading">
+            <property name="label" translatable="yes">Trigger</property>
+            <property name="xalign">0</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel" id="action_heading">
+            <property name="label" translatable="yes">Action</property>
+            <property name="xalign">0</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel" id="arguments_heading">
+            <property name="label" translatable="yes">Arguments</property>
+            <property name="xalign">0</property>
+          </object>
+        </child>
+      </object>
+    </child>
+    <child>
+      <object class="GtkScrolledWindow">
+        <property name="expand">1</property>
+        <property name="hscrollbar-policy">never</property>
+        <child>
+          <object class="GtkListBox" id="list">
+            <style>
+              <class name="list"/>
+            </style>
+            <property name="selection-mode">none</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+  <object class="GtkSizeGroup" id="trigger">
+    <property name="mode">horizontal</property>
+    <widgets>
+      <widget name="trigger_heading"/>
+    </widgets>
+  </object>
+  <object class="GtkSizeGroup" id="action">
+    <property name="mode">horizontal</property>
+    <widgets>
+      <widget name="action_heading"/>
+    </widgets>
+  </object>
+  <object class="GtkSizeGroup" id="arguments">
+    <property name="mode">horizontal</property>
+    <widgets>
+      <widget name="arguments_heading"/>
+    </widgets>
+  </object>
+</interface>
diff --git a/gtk/inspector/window.c b/gtk/inspector/window.c
index 71aeec9f69..03d5b1ebb0 100644
--- a/gtk/inspector/window.c
+++ b/gtk/inspector/window.c
@@ -36,6 +36,7 @@
 #include "size-groups.h"
 #include "data-list.h"
 #include "actions.h"
+#include "shortcuts.h"
 #include "menu.h"
 #include "misc-info.h"
 #include "magnifier.h"
@@ -80,6 +81,7 @@ set_selected_object (GtkInspectorWindow *iw,
   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_shortcuts_set_object (GTK_INSPECTOR_SHORTCUTS (iw->shortcuts), selected);
   gtk_inspector_menu_set_object (GTK_INSPECTOR_MENU (iw->menu), selected);
   gtk_inspector_controllers_set_object (GTK_INSPECTOR_CONTROLLERS (iw->controllers), selected);
   gtk_inspector_magnifier_set_object (GTK_INSPECTOR_MAGNIFIER (iw->magnifier), selected);
@@ -349,6 +351,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, shortcuts);
   gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, menu);
   gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, misc_info);
   gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, controllers);
diff --git a/gtk/inspector/window.h b/gtk/inspector/window.h
index c227782cc2..ba36deb28c 100644
--- a/gtk/inspector/window.h
+++ b/gtk/inspector/window.h
@@ -66,6 +66,7 @@ typedef struct
   GtkWidget *size_groups;
   GtkWidget *data_list;
   GtkWidget *actions;
+  GtkWidget *shortcuts;
   GtkWidget *menu;
   GtkWidget *misc_info;
   GtkWidget *controllers;
diff --git a/gtk/inspector/window.ui b/gtk/inspector/window.ui
index e55f36a8cb..77672ba182 100644
--- a/gtk/inspector/window.ui
+++ b/gtk/inspector/window.ui
@@ -403,6 +403,15 @@
                                     </property>
                                   </object>
                                 </child>
+                                <child>
+                                  <object class="GtkStackPage">
+                                    <property name="name">shortcuts</property>
+                                    <property name="title" translatable="yes">Shortcuts</property>
+                                    <property name="child">
+                                      <object class="GtkInspectorShortcuts" id="shortcuts"/>
+                                    </property>
+                                  </object>
+                                </child>
                                 <child>
                                   <object class="GtkStackPage">
                                     <property name="name">menu</property>


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