diff --git a/gtk/inspector/init.c b/gtk/inspector/init.c index 2681e62e81..126ce44b31 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" @@ -74,6 +75,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 c945386d2d..4f32b75639 100644 --- a/gtk/inspector/meson.build +++ b/gtk/inspector/meson.build @@ -28,6 +28,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..3f708371cd --- /dev/null +++ b/gtk/inspector/shortcuts.c @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2020 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 . + */ + +#include "config.h" +#include + +#include "shortcuts.h" +#include "gtklabel.h" +#include "gtklistbox.h" +#include "gtksizegroup.h" +#include "gtkstack.h" +#include "gtkshortcut.h" +#include "gtkshortcuttrigger.h" +#include "gtkshortcutcontroller.h" + +struct _GtkInspectorShortcuts +{ + GtkWidget parent; + + GtkWidget *box; + GtkWidget *list; + + GtkSizeGroup *trigger; + GtkSizeGroup *action; +}; + +G_DEFINE_TYPE (GtkInspectorShortcuts, gtk_inspector_shortcuts, GTK_TYPE_WIDGET) + +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 = GTK_SHORTCUT (item); + GtkInspectorShortcuts *sl = GTK_INSPECTOR_SHORTCUTS (user_data); + GtkShortcutTrigger *trigger; + GtkShortcutAction *action; + char *s; + GtkWidget *row; + GtkWidget *label; + + trigger = gtk_shortcut_get_trigger (shortcut); + action = gtk_shortcut_get_action (shortcut); + + row = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10); + + s = gtk_shortcut_trigger_to_string (trigger); + label = gtk_label_new (s); + gtk_label_set_xalign (GTK_LABEL (label), 0.0); + g_free (s); + gtk_container_add (GTK_CONTAINER (row), label); + gtk_size_group_add_widget (sl->trigger, label); + + s = gtk_shortcut_action_to_string (action); + label = gtk_label_new (s); + gtk_label_set_xalign (GTK_LABEL (label), 0.0); + g_free (s); + gtk_container_add (GTK_CONTAINER (row), label); + gtk_size_group_add_widget (sl->action, 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 (GTK_IS_SHORTCUT_CONTROLLER (object)) + { + g_object_set (page, "visible", TRUE, NULL); + gtk_list_box_bind_model (GTK_LIST_BOX (sl->list), + G_LIST_MODEL (object), + create_row, + sl, + NULL); + } + else + { + g_object_set (page, "visible", FALSE, NULL); + gtk_list_box_bind_model (GTK_LIST_BOX (sl->list), + NULL, + NULL, + NULL, + NULL); + } +} + +static void +gtk_inspector_shortcuts_measure (GtkWidget *widget, + GtkOrientation orientation, + int for_size, + int *minimum, + int *natural, + int *minimum_baseline, + int *natural_baseline) +{ + GtkInspectorShortcuts *shortcuts = GTK_INSPECTOR_SHORTCUTS (widget); + + gtk_widget_measure (shortcuts->box, + orientation, + for_size, + minimum, natural, + minimum_baseline, natural_baseline); +} + +static void +gtk_inspector_shortcuts_size_allocate (GtkWidget *widget, + int width, + int height, + int baseline) +{ + GtkInspectorShortcuts *shortcuts = GTK_INSPECTOR_SHORTCUTS (widget); + + gtk_widget_size_allocate (shortcuts->box, + &(GtkAllocation) { 0, 0, width, height }, + baseline); +} + + +static void +gtk_inspector_shortcuts_class_init (GtkInspectorShortcutsClass *klass) +{ + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + widget_class->measure = gtk_inspector_shortcuts_measure; + widget_class->size_allocate = gtk_inspector_shortcuts_size_allocate; + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/shortcuts.ui"); + gtk_widget_class_bind_template_child (widget_class, GtkInspectorShortcuts, box); + 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); +} diff --git a/gtk/inspector/shortcuts.h b/gtk/inspector/shortcuts.h new file mode 100644 index 0000000000..145cb86408 --- /dev/null +++ b/gtk/inspector/shortcuts.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 . + */ + +#ifndef _GTK_INSPECTOR_SHORTCUTS_H_ +#define _GTK_INSPECTOR_SHORTCUTS_H_ + +#include + +#define GTK_TYPE_INSPECTOR_SHORTCUTS (gtk_inspector_shortcuts_get_type ()) + +G_DECLARE_FINAL_TYPE (GtkInspectorShortcuts, gtk_inspector_shortcuts, GTK, INSPECTOR_SHORTCUTS, GtkWidget) + + +void gtk_inspector_shortcuts_set_object (GtkInspectorShortcuts *sl, + GObject *object); + +#endif diff --git a/gtk/inspector/shortcuts.ui b/gtk/inspector/shortcuts.ui new file mode 100644 index 0000000000..7ac55eb17a --- /dev/null +++ b/gtk/inspector/shortcuts.ui @@ -0,0 +1,59 @@ + + + + + horizontal + + + + + + horizontal + + + + + diff --git a/gtk/inspector/window.c b/gtk/inspector/window.c index 6b4b2524d5..2b86655b43 100644 --- a/gtk/inspector/window.c +++ b/gtk/inspector/window.c @@ -37,6 +37,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" @@ -91,6 +92,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); @@ -421,6 +423,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 3f29706141..6ac9a7eafc 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 963464be7a..4623a72229 100644 --- a/gtk/inspector/window.ui +++ b/gtk/inspector/window.ui @@ -449,6 +449,16 @@ + + + shortcuts + Shortcuts + + + + + +