popover: Add the same activate-default action
This commit is contained in:
@@ -379,6 +379,40 @@ allocate_contents (GtkGizmo *gizmo,
|
||||
}, -1);
|
||||
}
|
||||
|
||||
static void
|
||||
activate_default_cb (GSimpleAction *action,
|
||||
GVariant *parameter,
|
||||
gpointer data)
|
||||
{
|
||||
GtkPopover *popover = data;
|
||||
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
|
||||
GtkWidget *focus_widget;
|
||||
|
||||
focus_widget = gtk_root_get_focus (gtk_widget_get_root (priv->relative_to));
|
||||
if (priv->default_widget && gtk_widget_is_sensitive (priv->default_widget) &&
|
||||
(!focus_widget || !gtk_widget_get_receives_default (focus_widget)))
|
||||
gtk_widget_activate (priv->default_widget);
|
||||
else if (focus_widget && gtk_widget_is_sensitive (focus_widget))
|
||||
gtk_widget_activate (focus_widget);
|
||||
}
|
||||
|
||||
static void
|
||||
add_actions (GtkPopover *popover)
|
||||
{
|
||||
GActionEntry entries[] = {
|
||||
{ "activate-default", activate_default_cb, NULL, NULL, NULL },
|
||||
};
|
||||
|
||||
GActionGroup *actions;
|
||||
|
||||
actions = G_ACTION_GROUP (g_simple_action_group_new ());
|
||||
g_action_map_add_action_entries (G_ACTION_MAP (actions),
|
||||
entries, G_N_ELEMENTS (entries),
|
||||
popover);
|
||||
gtk_widget_insert_action_group (GTK_WIDGET (popover), "gtk", actions);
|
||||
g_object_unref (actions);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_popover_init (GtkPopover *popover)
|
||||
{
|
||||
@@ -407,6 +441,8 @@ gtk_popover_init (GtkPopover *popover)
|
||||
|
||||
context = gtk_widget_get_style_context (GTK_WIDGET (popover));
|
||||
gtk_style_context_add_class (context, GTK_STYLE_CLASS_BACKGROUND);
|
||||
|
||||
add_actions (popover);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1259,5 +1295,7 @@ void
|
||||
gtk_popover_set_default_widget (GtkPopover *popover,
|
||||
GtkWidget *widget)
|
||||
{
|
||||
// FIXME
|
||||
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
|
||||
|
||||
priv->default_widget = widget;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user