2014-05-14 00:36:02 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 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>
|
2014-07-12 03:14:04 +00:00
|
|
|
|
2014-05-14 00:36:02 +00:00
|
|
|
#include "actions.h"
|
2014-06-05 09:48:26 +00:00
|
|
|
#include "action-editor.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
|
|
|
|
#include "gtkapplication.h"
|
|
|
|
#include "gtkapplicationwindow.h"
|
|
|
|
#include "gtktreeview.h"
|
|
|
|
#include "gtkliststore.h"
|
2014-05-14 00:36:02 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "gtkpopover.h"
|
2014-11-22 20:40:24 +00:00
|
|
|
#include "gtklabel.h"
|
2019-04-02 23:24:57 +00:00
|
|
|
#include "gtkstack.h"
|
2019-05-08 02:20:18 +00:00
|
|
|
#include "gtklistbox.h"
|
|
|
|
#include "gtkstylecontext.h"
|
|
|
|
#include "gtksizegroup.h"
|
2014-05-14 00:36:02 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
COLUMN_PREFIX,
|
|
|
|
COLUMN_NAME,
|
|
|
|
COLUMN_ENABLED,
|
|
|
|
COLUMN_PARAMETER,
|
2014-05-16 02:36:48 +00:00
|
|
|
COLUMN_STATE,
|
|
|
|
COLUMN_GROUP
|
2014-05-14 00:36:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkInspectorActionsPrivate
|
|
|
|
{
|
2019-05-08 02:20:18 +00:00
|
|
|
GtkWidget *list;
|
|
|
|
GtkSizeGroup *prefix;
|
|
|
|
GtkSizeGroup *name;
|
|
|
|
GtkSizeGroup *enabled;
|
|
|
|
GtkSizeGroup *parameter;
|
|
|
|
GtkSizeGroup *state;
|
2019-05-08 03:34:14 +00:00
|
|
|
GtkSizeGroup *activate;
|
2014-05-16 02:36:48 +00:00
|
|
|
GHashTable *groups;
|
2014-05-14 00:36:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorActions, gtk_inspector_actions, GTK_TYPE_BOX)
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_inspector_actions_init (GtkInspectorActions *sl)
|
|
|
|
{
|
|
|
|
sl->priv = gtk_inspector_actions_get_instance_private (sl);
|
2014-05-16 02:36:48 +00:00
|
|
|
sl->priv->groups = g_hash_table_new_full (g_direct_hash,
|
|
|
|
g_direct_equal,
|
|
|
|
NULL,
|
|
|
|
g_free);
|
2014-05-14 00:36:02 +00:00
|
|
|
gtk_widget_init_template (GTK_WIDGET (sl));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-05-16 02:36:48 +00:00
|
|
|
add_action (GtkInspectorActions *sl,
|
|
|
|
GActionGroup *group,
|
|
|
|
const gchar *prefix,
|
|
|
|
const gchar *name)
|
2014-05-14 00:36:02 +00:00
|
|
|
{
|
|
|
|
gboolean enabled;
|
|
|
|
const gchar *parameter;
|
|
|
|
GVariant *state;
|
|
|
|
gchar *state_string;
|
2019-05-08 02:20:18 +00:00
|
|
|
GtkWidget *row;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *box;
|
|
|
|
char *key = g_strconcat (prefix, ".", name, NULL);
|
|
|
|
GtkWidget *editor;
|
2014-05-14 00:36:02 +00:00
|
|
|
|
2014-05-16 02:36:48 +00:00
|
|
|
enabled = g_action_group_get_action_enabled (group, name);
|
|
|
|
parameter = (const gchar *)g_action_group_get_action_parameter_type (group, name);
|
|
|
|
state = g_action_group_get_action_state (group, name);
|
|
|
|
if (state)
|
|
|
|
state_string = g_variant_print (state, FALSE);
|
|
|
|
else
|
|
|
|
state_string = g_strdup ("");
|
2019-05-08 02:20:18 +00:00
|
|
|
|
|
|
|
row = gtk_list_box_row_new ();
|
|
|
|
g_object_set_data_full (G_OBJECT (row), "key", key, g_free);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
label = gtk_label_new (prefix);
|
|
|
|
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->priv->prefix, label);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), label);
|
|
|
|
|
|
|
|
label = gtk_label_new (name);
|
|
|
|
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->priv->name, label);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), label);
|
|
|
|
|
|
|
|
label = gtk_label_new (enabled ? "+" : "-");
|
|
|
|
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->priv->enabled, label);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), label);
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (row), "enabled", label);
|
|
|
|
|
|
|
|
label = gtk_label_new (parameter);
|
|
|
|
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->priv->parameter, label);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), label);
|
|
|
|
|
|
|
|
label = gtk_label_new (state_string);
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0);
|
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context (label), "cell");
|
|
|
|
gtk_size_group_add_widget (sl->priv->state, label);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), label);
|
|
|
|
g_object_set_data (G_OBJECT (row), "state", label);
|
|
|
|
|
2019-05-08 03:34:14 +00:00
|
|
|
editor = gtk_inspector_action_editor_new (group, prefix, name, sl->priv->activate);
|
2019-05-08 02:20:18 +00:00
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context (editor), "cell");
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), editor);
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (sl->priv->list), row);
|
|
|
|
|
2014-05-16 02:36:48 +00:00
|
|
|
g_free (state_string);
|
|
|
|
}
|
|
|
|
|
2019-05-08 02:20:18 +00:00
|
|
|
static GtkWidget *
|
|
|
|
find_row (GtkInspectorActions *sl,
|
|
|
|
const char *prefix,
|
|
|
|
const char *action_name)
|
|
|
|
{
|
|
|
|
GtkWidget *row = NULL;
|
|
|
|
GtkWidget *widget;
|
|
|
|
char *key = g_strconcat (prefix, ".", action_name, NULL);
|
|
|
|
|
|
|
|
for (widget = gtk_widget_get_first_child (sl->priv->list);
|
|
|
|
widget;
|
|
|
|
widget = gtk_widget_get_next_sibling (widget))
|
|
|
|
{
|
|
|
|
const char *rkey = g_object_get_data (G_OBJECT (widget), "key");
|
|
|
|
if (g_str_equal (key, rkey))
|
|
|
|
{
|
|
|
|
row = widget;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (key);
|
|
|
|
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
|
2014-05-16 02:36:48 +00:00
|
|
|
static void
|
|
|
|
action_added_cb (GActionGroup *group,
|
|
|
|
const gchar *action_name,
|
|
|
|
GtkInspectorActions *sl)
|
|
|
|
{
|
|
|
|
const gchar *prefix;
|
|
|
|
prefix = g_hash_table_lookup (sl->priv->groups, group);
|
|
|
|
add_action (sl, group, prefix, action_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
action_removed_cb (GActionGroup *group,
|
|
|
|
const gchar *action_name,
|
|
|
|
GtkInspectorActions *sl)
|
|
|
|
{
|
|
|
|
const gchar *prefix;
|
2019-05-08 02:20:18 +00:00
|
|
|
GtkWidget *row;
|
|
|
|
|
2014-05-16 02:36:48 +00:00
|
|
|
prefix = g_hash_table_lookup (sl->priv->groups, group);
|
2019-05-08 02:20:18 +00:00
|
|
|
row = find_row (sl, prefix, action_name);
|
|
|
|
if (row)
|
|
|
|
gtk_container_remove (GTK_CONTAINER (sl->priv->list), row);
|
2014-05-16 02:36:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
action_enabled_changed_cb (GActionGroup *group,
|
|
|
|
const gchar *action_name,
|
|
|
|
gboolean enabled,
|
|
|
|
GtkInspectorActions *sl)
|
|
|
|
{
|
|
|
|
const gchar *prefix;
|
2019-05-08 02:20:18 +00:00
|
|
|
GtkWidget *row;
|
|
|
|
GtkWidget *label;
|
|
|
|
|
2014-05-16 02:36:48 +00:00
|
|
|
prefix = g_hash_table_lookup (sl->priv->groups, group);
|
2019-05-08 02:20:18 +00:00
|
|
|
|
|
|
|
row = find_row (sl, prefix, action_name);
|
|
|
|
label = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "enabled"));
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), enabled ? "+" : "-" );
|
2014-05-16 02:36:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
action_state_changed_cb (GActionGroup *group,
|
|
|
|
const gchar *action_name,
|
|
|
|
GVariant *state,
|
|
|
|
GtkInspectorActions *sl)
|
|
|
|
{
|
|
|
|
const gchar *prefix;
|
|
|
|
gchar *state_string;
|
2019-05-08 02:20:18 +00:00
|
|
|
GtkWidget *row;
|
|
|
|
GtkWidget *label;
|
|
|
|
|
2014-05-16 02:36:48 +00:00
|
|
|
prefix = g_hash_table_lookup (sl->priv->groups, group);
|
2019-05-08 02:20:18 +00:00
|
|
|
|
|
|
|
row = find_row (sl, prefix, action_name);
|
2014-05-16 02:36:48 +00:00
|
|
|
if (state)
|
|
|
|
state_string = g_variant_print (state, FALSE);
|
|
|
|
else
|
|
|
|
state_string = g_strdup ("");
|
2019-05-08 02:20:18 +00:00
|
|
|
label = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "state"));
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), state_string);
|
2014-05-16 02:36:48 +00:00
|
|
|
g_free (state_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_group (GtkInspectorActions *sl,
|
2019-04-02 23:24:57 +00:00
|
|
|
GtkStackPage *page,
|
2014-05-16 02:36:48 +00:00
|
|
|
GActionGroup *group,
|
|
|
|
const gchar *prefix)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
gchar **names;
|
|
|
|
|
2019-04-02 23:24:57 +00:00
|
|
|
g_object_set (page, "visible", TRUE, NULL);
|
2014-05-14 00:36:02 +00:00
|
|
|
|
2014-05-16 02:36:48 +00:00
|
|
|
g_signal_connect (group, "action-added", G_CALLBACK (action_added_cb), sl);
|
|
|
|
g_signal_connect (group, "action-removed", G_CALLBACK (action_removed_cb), sl);
|
|
|
|
g_signal_connect (group, "action-enabled-changed", G_CALLBACK (action_enabled_changed_cb), sl);
|
|
|
|
g_signal_connect (group, "action-state-changed", G_CALLBACK (action_state_changed_cb), sl);
|
|
|
|
g_hash_table_insert (sl->priv->groups, group, g_strdup (prefix));
|
|
|
|
|
2014-05-14 00:36:02 +00:00
|
|
|
names = g_action_group_list_actions (group);
|
|
|
|
for (i = 0; names[i]; i++)
|
2014-05-16 02:36:48 +00:00
|
|
|
add_action (sl, group, prefix, names[i]);
|
2014-05-14 00:36:02 +00:00
|
|
|
g_strfreev (names);
|
|
|
|
}
|
|
|
|
|
2014-05-16 02:36:48 +00:00
|
|
|
static void
|
|
|
|
disconnect_group (gpointer key, gpointer value, gpointer data)
|
|
|
|
{
|
|
|
|
GActionGroup *group = key;
|
|
|
|
GtkInspectorActions *sl = data;
|
|
|
|
|
|
|
|
g_signal_handlers_disconnect_by_func (group, action_added_cb, sl);
|
|
|
|
g_signal_handlers_disconnect_by_func (group, action_removed_cb, sl);
|
|
|
|
g_signal_handlers_disconnect_by_func (group, action_enabled_changed_cb, sl);
|
|
|
|
g_signal_handlers_disconnect_by_func (group, action_state_changed_cb, sl);
|
|
|
|
}
|
|
|
|
|
2014-05-14 00:36:02 +00:00
|
|
|
void
|
|
|
|
gtk_inspector_actions_set_object (GtkInspectorActions *sl,
|
|
|
|
GObject *object)
|
|
|
|
{
|
2019-04-02 23:24:57 +00:00
|
|
|
GtkWidget *stack;
|
|
|
|
GtkStackPage *page;
|
|
|
|
|
|
|
|
stack = gtk_widget_get_parent (GTK_WIDGET (sl));
|
|
|
|
page = gtk_stack_get_page (GTK_STACK (stack), GTK_WIDGET (sl));
|
|
|
|
|
|
|
|
g_object_set (page, "visible", FALSE, NULL);
|
2014-05-16 02:36:48 +00:00
|
|
|
g_hash_table_foreach (sl->priv->groups, disconnect_group, sl);
|
|
|
|
g_hash_table_remove_all (sl->priv->groups);
|
2019-05-02 01:53:57 +00:00
|
|
|
|
2014-05-14 00:36:02 +00:00
|
|
|
if (GTK_IS_APPLICATION (object))
|
2019-04-02 23:24:57 +00:00
|
|
|
add_group (sl, page, G_ACTION_GROUP (object), "app");
|
2014-05-14 00:36:02 +00:00
|
|
|
else if (GTK_IS_WIDGET (object))
|
|
|
|
{
|
2014-12-13 01:39:46 +00:00
|
|
|
const gchar **prefixes;
|
2014-05-14 00:36:02 +00:00
|
|
|
GActionGroup *group;
|
|
|
|
gint i;
|
|
|
|
|
2014-12-11 23:25:41 +00:00
|
|
|
prefixes = gtk_widget_list_action_prefixes (GTK_WIDGET (object));
|
2014-05-14 00:36:02 +00:00
|
|
|
if (prefixes)
|
|
|
|
{
|
|
|
|
for (i = 0; prefixes[i]; i++)
|
|
|
|
{
|
2014-12-11 23:25:41 +00:00
|
|
|
group = gtk_widget_get_action_group (GTK_WIDGET (object), prefixes[i]);
|
2019-04-02 23:24:57 +00:00
|
|
|
add_group (sl, page, group, prefixes[i]);
|
2014-05-14 00:36:02 +00:00
|
|
|
}
|
|
|
|
g_free (prefixes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_inspector_actions_class_init (GtkInspectorActionsClass *klass)
|
|
|
|
{
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
2014-11-30 20:59:53 +00:00
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/actions.ui");
|
2019-05-08 02:20:18 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorActions, list);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorActions, prefix);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorActions, name);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorActions, enabled);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorActions, parameter);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorActions, state);
|
2019-05-08 03:34:14 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorActions, activate);
|
2014-05-14 00:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// vim: set et sw=2 ts=2:
|