2020-03-16 00:48:31 +00:00
|
|
|
/*
|
|
|
|
* 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 "gtksizegroup.h"
|
|
|
|
#include "gtkstack.h"
|
|
|
|
#include "gtkshortcut.h"
|
|
|
|
#include "gtkshortcuttrigger.h"
|
|
|
|
#include "gtkshortcutcontroller.h"
|
2021-01-21 00:27:38 +00:00
|
|
|
#include "gtksignallistitemfactory.h"
|
|
|
|
#include "gtklistitem.h"
|
|
|
|
#include "gtkcolumnview.h"
|
|
|
|
#include "gtkcolumnviewcolumn.h"
|
|
|
|
#include "gtkscrolledwindow.h"
|
|
|
|
#include "gtknoselection.h"
|
|
|
|
#include "gtkbinlayout.h"
|
|
|
|
|
2020-03-16 00:48:31 +00:00
|
|
|
|
|
|
|
struct _GtkInspectorShortcuts
|
|
|
|
{
|
|
|
|
GtkWidget parent;
|
|
|
|
|
2021-01-21 00:27:38 +00:00
|
|
|
GtkWidget *view;
|
2020-03-16 00:48:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GtkInspectorShortcuts, gtk_inspector_shortcuts, GTK_TYPE_WIDGET)
|
|
|
|
|
|
|
|
static void
|
2021-01-21 00:27:38 +00:00
|
|
|
setup_row (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item,
|
|
|
|
gpointer data)
|
2020-03-16 00:48:31 +00:00
|
|
|
{
|
2021-01-21 00:27:38 +00:00
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
label = gtk_label_new ("");
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0);
|
|
|
|
gtk_list_item_set_child (list_item, label);
|
2020-03-16 00:48:31 +00:00
|
|
|
}
|
|
|
|
|
2021-01-21 00:27:38 +00:00
|
|
|
static void
|
|
|
|
bind_trigger (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item,
|
|
|
|
gpointer data)
|
2020-03-16 00:48:31 +00:00
|
|
|
{
|
|
|
|
GtkWidget *label;
|
2021-01-21 00:27:38 +00:00
|
|
|
GtkShortcut *shortcut;
|
|
|
|
GtkShortcutTrigger *trigger;
|
|
|
|
char *str;
|
2020-03-16 00:48:31 +00:00
|
|
|
|
2021-01-21 00:27:38 +00:00
|
|
|
label = gtk_list_item_get_child (list_item);
|
|
|
|
shortcut = gtk_list_item_get_item (list_item);
|
2020-03-16 00:48:31 +00:00
|
|
|
trigger = gtk_shortcut_get_trigger (shortcut);
|
2021-01-21 00:27:38 +00:00
|
|
|
str = gtk_shortcut_trigger_to_label (trigger, gtk_widget_get_display (label));
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), str);
|
|
|
|
g_free (str);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bind_action (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkShortcut *shortcut;
|
|
|
|
GtkShortcutAction *action;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
label = gtk_list_item_get_child (list_item);
|
|
|
|
shortcut = gtk_list_item_get_item (list_item);
|
2020-03-16 00:48:31 +00:00
|
|
|
action = gtk_shortcut_get_action (shortcut);
|
2021-01-21 00:27:38 +00:00
|
|
|
str = gtk_shortcut_action_to_string (action);
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), str);
|
|
|
|
g_free (str);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_inspector_shortcuts_init (GtkInspectorShortcuts *self)
|
|
|
|
{
|
|
|
|
GtkWidget *sw;
|
|
|
|
GtkListItemFactory *factory;
|
|
|
|
GtkColumnViewColumn *column;
|
|
|
|
|
|
|
|
sw = gtk_scrolled_window_new ();
|
|
|
|
|
|
|
|
self->view = gtk_column_view_new (NULL);
|
|
|
|
|
|
|
|
factory = gtk_signal_list_item_factory_new ();
|
|
|
|
g_signal_connect (factory, "setup", G_CALLBACK (setup_row), NULL);
|
|
|
|
g_signal_connect (factory, "bind", G_CALLBACK (bind_trigger), NULL);
|
2020-03-16 00:48:31 +00:00
|
|
|
|
2021-01-21 00:27:38 +00:00
|
|
|
column = gtk_column_view_column_new ("Trigger", factory);
|
|
|
|
gtk_column_view_append_column (GTK_COLUMN_VIEW (self->view), column);
|
|
|
|
g_object_unref (column);
|
2020-03-16 00:48:31 +00:00
|
|
|
|
2021-01-21 00:27:38 +00:00
|
|
|
factory = gtk_signal_list_item_factory_new ();
|
|
|
|
g_signal_connect (factory, "setup", G_CALLBACK (setup_row), NULL);
|
|
|
|
g_signal_connect (factory, "bind", G_CALLBACK (bind_action), NULL);
|
2020-03-16 00:48:31 +00:00
|
|
|
|
2021-01-21 00:27:38 +00:00
|
|
|
column = gtk_column_view_column_new ("Action", factory);
|
|
|
|
gtk_column_view_append_column (GTK_COLUMN_VIEW (self->view), column);
|
|
|
|
g_object_unref (column);
|
2020-03-16 00:48:31 +00:00
|
|
|
|
2021-01-21 00:27:38 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), self->view);
|
|
|
|
|
|
|
|
gtk_widget_set_parent (sw, GTK_WIDGET (self));
|
2020-03-16 00:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-01-21 00:27:38 +00:00
|
|
|
gtk_inspector_shortcuts_set_object (GtkInspectorShortcuts *self,
|
2020-03-16 00:48:31 +00:00
|
|
|
GObject *object)
|
|
|
|
{
|
|
|
|
GtkWidget *stack;
|
|
|
|
GtkStackPage *page;
|
2021-01-21 00:27:38 +00:00
|
|
|
GtkNoSelection *no_selection;
|
2020-03-16 00:48:31 +00:00
|
|
|
|
2021-01-21 00:27:38 +00:00
|
|
|
stack = gtk_widget_get_parent (GTK_WIDGET (self));
|
|
|
|
page = gtk_stack_get_page (GTK_STACK (stack), GTK_WIDGET (self));
|
2020-03-16 00:48:31 +00:00
|
|
|
|
2021-01-21 00:27:38 +00:00
|
|
|
if (!GTK_IS_SHORTCUT_CONTROLLER (object))
|
2020-03-16 00:48:31 +00:00
|
|
|
{
|
2021-01-21 00:27:38 +00:00
|
|
|
gtk_column_view_set_model (GTK_COLUMN_VIEW (self->view), NULL);
|
2020-03-16 00:48:31 +00:00
|
|
|
g_object_set (page, "visible", FALSE, NULL);
|
2021-01-21 00:27:38 +00:00
|
|
|
return;
|
2020-03-16 00:48:31 +00:00
|
|
|
}
|
|
|
|
|
2021-01-21 00:27:38 +00:00
|
|
|
g_object_set (page, "visible", TRUE, NULL);
|
2020-03-16 00:48:31 +00:00
|
|
|
|
2021-01-21 00:27:38 +00:00
|
|
|
no_selection = gtk_no_selection_new (g_object_ref (G_LIST_MODEL (object)));
|
|
|
|
gtk_column_view_set_model (GTK_COLUMN_VIEW (self->view), GTK_SELECTION_MODEL (no_selection));
|
|
|
|
g_object_unref (no_selection);
|
2020-03-16 00:48:31 +00:00
|
|
|
}
|
|
|
|
|
2020-07-18 03:13:29 +00:00
|
|
|
static void
|
|
|
|
dispose (GObject *object)
|
|
|
|
{
|
2021-01-21 00:27:38 +00:00
|
|
|
GtkInspectorShortcuts *self = GTK_INSPECTOR_SHORTCUTS (object);
|
2020-07-18 03:13:29 +00:00
|
|
|
|
2021-01-21 00:27:38 +00:00
|
|
|
gtk_widget_unparent (gtk_widget_get_first_child (GTK_WIDGET (self)));
|
2020-07-18 03:13:29 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_inspector_shortcuts_parent_class)->dispose (object);
|
|
|
|
}
|
2020-03-16 00:48:31 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_inspector_shortcuts_class_init (GtkInspectorShortcutsClass *klass)
|
|
|
|
{
|
2020-07-18 03:13:29 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2020-03-16 00:48:31 +00:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
2020-07-18 03:13:29 +00:00
|
|
|
object_class->dispose = dispose;
|
|
|
|
|
2021-01-21 00:27:38 +00:00
|
|
|
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
|
2020-03-16 00:48:31 +00:00
|
|
|
}
|