Merge branch 'matthiasc-for-master' into 'master'

Matthiasc for master

See merge request GNOME/gtk!943
This commit is contained in:
Matthias Clasen 2019-06-17 03:26:35 +00:00
commit 97ba872ef3
7 changed files with 177 additions and 71 deletions

View File

@ -140,8 +140,6 @@
#define POS_IS_VERTICAL(p) ((p) == GTK_POS_TOP || (p) == GTK_POS_BOTTOM)
static GListStore *popover_list = NULL;
typedef struct {
GdkSurface *surface;
GskRenderer *renderer;
@ -743,21 +741,8 @@ gtk_popover_dispose (GObject *object)
{
GtkPopover *popover = GTK_POPOVER (object);
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
guint i;
GtkWidget *child;
for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (popover_list)); i++)
{
gpointer item = g_list_model_get_item (G_LIST_MODEL (popover_list), i);
if (item == object)
{
g_list_store_remove (popover_list, i);
break;
}
else
g_object_unref (item);
}
child = gtk_bin_get_child (GTK_BIN (popover));
if (child)
@ -778,13 +763,6 @@ gtk_popover_finalize (GObject *object)
G_OBJECT_CLASS (gtk_popover_parent_class)->finalize (object);
}
static void
gtk_popover_constructed (GObject *object)
{
g_list_store_append (popover_list, object);
g_object_unref (object);
}
static void
gtk_popover_get_gap_coords (GtkPopover *popover,
gint *initial_x_out,
@ -1333,10 +1311,6 @@ gtk_popover_class_init (GtkPopoverClass *klass)
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
if (popover_list == NULL)
popover_list = g_list_store_new (GTK_TYPE_WIDGET);
object_class->constructed = gtk_popover_constructed;
object_class->dispose = gtk_popover_dispose;
object_class->finalize = gtk_popover_finalize;
object_class->set_property = gtk_popover_set_property;
@ -1446,22 +1420,6 @@ size_changed (GtkWidget *widget,
gtk_popover_move_resize (popover);
}
/**
* gtk_popover_get_popovers:
*
* Returns the list of all existing #GtkPopover widgets.
*
* Returns: (transfer none): The list of existing popovers.
*/
GListModel *
gtk_popover_get_popovers (void)
{
if (popover_list == NULL)
popover_list = g_list_store_new (GTK_TYPE_WIDGET);
return G_LIST_MODEL (popover_list);
}
void
gtk_popover_set_default_widget (GtkPopover *popover,
GtkWidget *widget)

View File

@ -101,8 +101,6 @@ GDK_AVAILABLE_IN_ALL
void gtk_popover_set_default_widget (GtkPopover *popover,
GtkWidget *widget);
GDK_AVAILABLE_IN_ALL
GListModel * gtk_popover_get_popovers (void);
G_END_DECLS

View File

@ -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);
}

View File

@ -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

View File

@ -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);

View File

@ -955,7 +955,6 @@ search (GtkInspectorObjectTree *wt,
result = search_children (child, text, forward);
if (result)
{
g_print ("selecting!\n");
gtk_inspector_object_tree_select_object (wt, result);
g_object_unref (result);
g_object_unref (child);
@ -1145,7 +1144,6 @@ create_root_model (void)
g_object_unref);
gtk_filter_list_model_set_model (filter, gtk_window_get_toplevels ());
g_list_store_append (list, filter);
g_list_store_append (list, gtk_popover_get_popovers ());
g_object_unref (filter);
flatten = gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (list));

View File

@ -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"/>
@ -240,6 +239,7 @@
</child>
<child>
<object class="GtkStack" id="object_start_stack">
<property name="homogeneous">0</property>
<child>
<object class="GtkStackPage">
<property name="name">empty</property>
@ -248,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>
@ -276,6 +290,7 @@
<property name="transition-type">crossfade</property>
<property name="hexpand">1</property>
<property name="halign">center</property>
<property name="homogeneous">0</property>
<child>
<object class="GtkStackPage">
<property name="name">title</property>
@ -382,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>