forked from AuroraMiddleware/gtk
inspector: Add a refresh button for actions
Action state updates may not always be precise.
This commit is contained in:
parent
2457ed03c2
commit
3ad8797068
@ -43,7 +43,6 @@ enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_GROUP,
|
||||
PROP_PREFIX,
|
||||
PROP_NAME,
|
||||
PROP_SIZEGROUP
|
||||
};
|
||||
@ -231,6 +230,20 @@ state_changed (GtkWidget *editor,
|
||||
g_action_group_change_action_state (r->priv->group, r->priv->name, value);
|
||||
}
|
||||
|
||||
static void
|
||||
update_enabled (GtkInspectorActionEditor *r,
|
||||
gboolean enabled)
|
||||
{
|
||||
r->priv->enabled = enabled;
|
||||
if (r->priv->parameter_entry)
|
||||
{
|
||||
gtk_widget_set_sensitive (r->priv->parameter_entry, enabled);
|
||||
parameter_changed (r->priv->parameter_entry, r);
|
||||
}
|
||||
if (r->priv->activate_button)
|
||||
gtk_widget_set_sensitive (r->priv->activate_button, enabled);
|
||||
}
|
||||
|
||||
static void
|
||||
action_enabled_changed_cb (GActionGroup *group,
|
||||
const gchar *action_name,
|
||||
@ -240,12 +253,15 @@ action_enabled_changed_cb (GActionGroup *group,
|
||||
if (!g_str_equal (action_name, r->priv->name))
|
||||
return;
|
||||
|
||||
r->priv->enabled = enabled;
|
||||
if (r->priv->parameter_entry)
|
||||
{
|
||||
gtk_widget_set_sensitive (r->priv->parameter_entry, enabled);
|
||||
parameter_changed (r->priv->parameter_entry, r);
|
||||
}
|
||||
update_enabled (r, enabled);
|
||||
}
|
||||
|
||||
static void
|
||||
update_state (GtkInspectorActionEditor *r,
|
||||
GVariant *state)
|
||||
{
|
||||
if (r->priv->state_entry)
|
||||
variant_editor_set_value (r->priv->state_entry, state);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -257,8 +273,7 @@ action_state_changed_cb (GActionGroup *group,
|
||||
if (!g_str_equal (action_name, r->priv->name))
|
||||
return;
|
||||
|
||||
if (r->priv->state_entry)
|
||||
variant_editor_set_value (r->priv->state_entry, state);
|
||||
update_state (r, state);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -418,3 +433,12 @@ gtk_inspector_action_editor_new (GActionGroup *group,
|
||||
"sizegroup", activate,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void
|
||||
gtk_inspector_action_editor_update (GtkInspectorActionEditor *r,
|
||||
gboolean enabled,
|
||||
GVariant *state)
|
||||
{
|
||||
update_enabled (r, enabled);
|
||||
update_state (r, state);
|
||||
}
|
||||
|
@ -51,6 +51,9 @@ GType gtk_inspector_action_editor_get_type (void);
|
||||
GtkWidget *gtk_inspector_action_editor_new (GActionGroup *group,
|
||||
const gchar *name,
|
||||
GtkSizeGroup *activate);
|
||||
void gtk_inspector_action_editor_update (GtkInspectorActionEditor *r,
|
||||
gboolean enabled,
|
||||
GVariant *state);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -43,6 +43,12 @@ struct _GtkInspectorActionsPrivate
|
||||
GtkSizeGroup *state;
|
||||
GtkSizeGroup *activate;
|
||||
GActionGroup *group;
|
||||
GtkWidget *button;
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_BUTTON
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorActions, gtk_inspector_actions, GTK_TYPE_BOX)
|
||||
@ -93,6 +99,7 @@ add_action (GtkInspectorActions *sl,
|
||||
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_widget_set_halign (label, GTK_ALIGN_CENTER);
|
||||
gtk_size_group_add_widget (sl->priv->enabled, label);
|
||||
gtk_container_add (GTK_CONTAINER (box), label);
|
||||
|
||||
@ -114,6 +121,7 @@ add_action (GtkInspectorActions *sl,
|
||||
editor = gtk_inspector_action_editor_new (group, name, sl->priv->activate);
|
||||
gtk_style_context_add_class (gtk_widget_get_style_context (editor), "cell");
|
||||
gtk_container_add (GTK_CONTAINER (box), editor);
|
||||
g_object_set_data (G_OBJECT (row), "editor", editor);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (sl->priv->list), row);
|
||||
|
||||
@ -162,6 +170,16 @@ action_removed_cb (GActionGroup *group,
|
||||
gtk_widget_destroy (row);
|
||||
}
|
||||
|
||||
static void
|
||||
set_row_enabled (GtkWidget *row,
|
||||
gboolean enabled)
|
||||
{
|
||||
GtkWidget *label;
|
||||
|
||||
label = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "enabled"));
|
||||
gtk_label_set_label (GTK_LABEL (label), enabled ? "+" : "-" );
|
||||
}
|
||||
|
||||
static void
|
||||
action_enabled_changed_cb (GActionGroup *group,
|
||||
const gchar *action_name,
|
||||
@ -169,11 +187,25 @@ action_enabled_changed_cb (GActionGroup *group,
|
||||
GtkInspectorActions *sl)
|
||||
{
|
||||
GtkWidget *row;
|
||||
GtkWidget *label;
|
||||
|
||||
row = find_row (sl, action_name);
|
||||
label = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "enabled"));
|
||||
gtk_label_set_label (GTK_LABEL (label), enabled ? "+" : "-" );
|
||||
set_row_enabled (row, enabled);
|
||||
}
|
||||
|
||||
static void
|
||||
set_row_state (GtkWidget *row,
|
||||
GVariant *state)
|
||||
{
|
||||
gchar *state_string;
|
||||
GtkWidget *label;
|
||||
|
||||
if (state)
|
||||
state_string = g_variant_print (state, FALSE);
|
||||
else
|
||||
state_string = g_strdup ("");
|
||||
label = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "state"));
|
||||
gtk_label_set_label (GTK_LABEL (label), state_string);
|
||||
g_free (state_string);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -182,18 +214,35 @@ action_state_changed_cb (GActionGroup *group,
|
||||
GVariant *state,
|
||||
GtkInspectorActions *sl)
|
||||
{
|
||||
gchar *state_string;
|
||||
GtkWidget *row;
|
||||
GtkWidget *label;
|
||||
|
||||
row = find_row (sl, action_name);
|
||||
if (state)
|
||||
state_string = g_variant_print (state, FALSE);
|
||||
else
|
||||
state_string = g_strdup ("");
|
||||
label = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "state"));
|
||||
gtk_label_set_label (GTK_LABEL (label), state_string);
|
||||
g_free (state_string);
|
||||
set_row_state (row, state);
|
||||
}
|
||||
|
||||
static void
|
||||
refresh_all (GtkInspectorActions *sl)
|
||||
{
|
||||
GtkWidget *widget;
|
||||
|
||||
for (widget = gtk_widget_get_first_child (sl->priv->list);
|
||||
widget;
|
||||
widget = gtk_widget_get_next_sibling (widget))
|
||||
{
|
||||
const char *name = g_object_get_data (G_OBJECT (widget), "key");
|
||||
gboolean enabled;
|
||||
GVariant *state;
|
||||
GtkInspectorActionEditor *r;
|
||||
|
||||
enabled = g_action_group_get_action_enabled (sl->priv->group, name);
|
||||
state = g_action_group_get_action_state (sl->priv->group, name);
|
||||
|
||||
set_row_enabled (widget, enabled);
|
||||
set_row_state (widget, state);
|
||||
|
||||
r = (GtkInspectorActionEditor*)g_object_get_data (G_OBJECT (widget), "editor");
|
||||
gtk_inspector_action_editor_update (r, enabled, state);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@ -259,7 +308,8 @@ gtk_inspector_actions_set_object (GtkInspectorActions *sl,
|
||||
stack = gtk_widget_get_parent (GTK_WIDGET (sl));
|
||||
page = gtk_stack_get_page (GTK_STACK (stack), GTK_WIDGET (sl));
|
||||
|
||||
remove_group (sl, page, sl->priv->group);
|
||||
if (sl->priv->group)
|
||||
remove_group (sl, page, sl->priv->group);
|
||||
|
||||
while ((child = gtk_widget_get_first_child (sl->priv->list)))
|
||||
gtk_widget_destroy (child);
|
||||
@ -276,10 +326,68 @@ gtk_inspector_actions_set_object (GtkInspectorActions *sl,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
get_property (GObject *object,
|
||||
guint param_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkInspectorActions *sl = GTK_INSPECTOR_ACTIONS (object);
|
||||
|
||||
switch (param_id)
|
||||
{
|
||||
case PROP_BUTTON:
|
||||
g_value_set_object (value, sl->priv->button);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set_property (GObject *object,
|
||||
guint param_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkInspectorActions *sl = GTK_INSPECTOR_ACTIONS (object);
|
||||
|
||||
switch (param_id)
|
||||
{
|
||||
case PROP_BUTTON:
|
||||
sl->priv->button = g_value_get_object (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
constructed (GObject *object)
|
||||
{
|
||||
GtkInspectorActions *sl = GTK_INSPECTOR_ACTIONS (object);
|
||||
|
||||
g_signal_connect_swapped (sl->priv->button, "clicked",
|
||||
G_CALLBACK (refresh_all), sl);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_inspector_actions_class_init (GtkInspectorActionsClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
|
||||
object_class->get_property = get_property;
|
||||
object_class->set_property = set_property;
|
||||
object_class->constructed = constructed;
|
||||
|
||||
g_object_class_install_property (object_class, PROP_BUTTON,
|
||||
g_param_spec_object ("button", NULL, NULL,
|
||||
GTK_TYPE_WIDGET, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/actions.ui");
|
||||
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorActions, list);
|
||||
|
@ -226,13 +226,12 @@
|
||||
<object class="GtkCenterBox">
|
||||
<child type="start">
|
||||
<object class="GtkBox">
|
||||
<property name="spacing">10</property>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="icon-name">go-previous-symbolic</property>
|
||||
<property name="tooltip-text" translatable="yes">Toggle Sidebar</property>
|
||||
<property name="relief">none</property>
|
||||
<property name="margin-start">6</property>
|
||||
<property name="margin">6</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<signal name="clicked" handler="toggle_sidebar"/>
|
||||
@ -249,11 +248,25 @@
|
||||
</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkStackPage">
|
||||
<property name="name">actions</property>
|
||||
<property name="child">
|
||||
<object class="GtkButton" id="refresh_actions_button">
|
||||
<property name="margin">6</property>
|
||||
<property name="icon-name">view-refresh-symbolic</property>
|
||||
<property name="tooltip-text" translatable="yes">Refresh action state</property>
|
||||
<property name="relief">none</property>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkStackPage">
|
||||
<property name="name">magnifier</property>
|
||||
<property name="child">
|
||||
<object class="GtkScale">
|
||||
<property name="margin">6</property>
|
||||
<property name="width-request">150</property>
|
||||
<property name="draw-value">0</property>
|
||||
<property name="adjustment">magnification_adjustment</property>
|
||||
@ -384,7 +397,9 @@
|
||||
<property name="name">actions</property>
|
||||
<property name="title" translatable="yes">Actions</property>
|
||||
<property name="child">
|
||||
<object class="GtkInspectorActions" id="actions"/>
|
||||
<object class="GtkInspectorActions" id="actions">
|
||||
<property name="button">refresh_actions_button</property>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</child>
|
||||
|
Loading…
Reference in New Issue
Block a user