mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-29 15:01:23 +00:00
inspector: Show shortcuts
At a tab that lists the shortcuts contained in a GtkShortcutController.
This commit is contained in:
parent
f7021e80a7
commit
f5134a833c
@ -40,6 +40,7 @@
|
|||||||
#include "prop-list.h"
|
#include "prop-list.h"
|
||||||
#include "recorder.h"
|
#include "recorder.h"
|
||||||
#include "resource-list.h"
|
#include "resource-list.h"
|
||||||
|
#include "shortcuts.h"
|
||||||
#include "size-groups.h"
|
#include "size-groups.h"
|
||||||
#include "statistics.h"
|
#include "statistics.h"
|
||||||
#include "visual.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_PROP_LIST);
|
||||||
g_type_ensure (GTK_TYPE_INSPECTOR_RECORDER);
|
g_type_ensure (GTK_TYPE_INSPECTOR_RECORDER);
|
||||||
g_type_ensure (GTK_TYPE_INSPECTOR_RESOURCE_LIST);
|
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_SIZE_GROUPS);
|
||||||
g_type_ensure (GTK_TYPE_INSPECTOR_STATISTICS);
|
g_type_ensure (GTK_TYPE_INSPECTOR_STATISTICS);
|
||||||
g_type_ensure (GTK_TYPE_INSPECTOR_VISUAL);
|
g_type_ensure (GTK_TYPE_INSPECTOR_VISUAL);
|
||||||
|
@ -28,6 +28,7 @@ inspector_sources = files(
|
|||||||
'recording.c',
|
'recording.c',
|
||||||
'renderrecording.c',
|
'renderrecording.c',
|
||||||
'resource-list.c',
|
'resource-list.c',
|
||||||
|
'shortcuts.c',
|
||||||
'size-groups.c',
|
'size-groups.c',
|
||||||
'startrecording.c',
|
'startrecording.c',
|
||||||
'statistics.c',
|
'statistics.c',
|
||||||
|
158
gtk/inspector/shortcuts.c
Normal file
158
gtk/inspector/shortcuts.c
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include <glib/gi18n-lib.h>
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
31
gtk/inspector/shortcuts.h
Normal file
31
gtk/inspector/shortcuts.h
Normal file
@ -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 <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 ())
|
||||||
|
|
||||||
|
G_DECLARE_FINAL_TYPE (GtkInspectorShortcuts, gtk_inspector_shortcuts, GTK, INSPECTOR_SHORTCUTS, GtkWidget)
|
||||||
|
|
||||||
|
|
||||||
|
void gtk_inspector_shortcuts_set_object (GtkInspectorShortcuts *sl,
|
||||||
|
GObject *object);
|
||||||
|
|
||||||
|
#endif
|
59
gtk/inspector/shortcuts.ui
Normal file
59
gtk/inspector/shortcuts.ui
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<interface domain="gtk40">
|
||||||
|
<template class="GtkInspectorShortcuts" parent="GtkWidget">
|
||||||
|
<style>
|
||||||
|
<class name="view"/>
|
||||||
|
</style>
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox" id="box">
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
|
<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>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkScrolledWindow">
|
||||||
|
<property name="hexpand">1</property>
|
||||||
|
<property name="vexpand">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>
|
||||||
|
</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>
|
||||||
|
</interface>
|
@ -37,6 +37,7 @@
|
|||||||
#include "size-groups.h"
|
#include "size-groups.h"
|
||||||
#include "data-list.h"
|
#include "data-list.h"
|
||||||
#include "actions.h"
|
#include "actions.h"
|
||||||
|
#include "shortcuts.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "misc-info.h"
|
#include "misc-info.h"
|
||||||
#include "magnifier.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_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_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_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_menu_set_object (GTK_INSPECTOR_MENU (iw->menu), selected);
|
||||||
gtk_inspector_controllers_set_object (GTK_INSPECTOR_CONTROLLERS (iw->controllers), selected);
|
gtk_inspector_controllers_set_object (GTK_INSPECTOR_CONTROLLERS (iw->controllers), selected);
|
||||||
gtk_inspector_magnifier_set_object (GTK_INSPECTOR_MAGNIFIER (iw->magnifier), 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, size_groups);
|
||||||
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, data_list);
|
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, 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, menu);
|
||||||
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, misc_info);
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, misc_info);
|
||||||
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, controllers);
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, controllers);
|
||||||
|
@ -66,6 +66,7 @@ typedef struct
|
|||||||
GtkWidget *size_groups;
|
GtkWidget *size_groups;
|
||||||
GtkWidget *data_list;
|
GtkWidget *data_list;
|
||||||
GtkWidget *actions;
|
GtkWidget *actions;
|
||||||
|
GtkWidget *shortcuts;
|
||||||
GtkWidget *menu;
|
GtkWidget *menu;
|
||||||
GtkWidget *misc_info;
|
GtkWidget *misc_info;
|
||||||
GtkWidget *controllers;
|
GtkWidget *controllers;
|
||||||
|
@ -449,6 +449,16 @@
|
|||||||
</property>
|
</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</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">
|
||||||
|
</object>
|
||||||
|
</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
Loading…
Reference in New Issue
Block a user