[gtk/wip/matthiasc/popup4: 128/140] popover: Add the same activate-default action
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/popup4: 128/140] popover: Add the same activate-default action
- Date: Mon, 29 Apr 2019 02:52:27 +0000 (UTC)
commit 3d486cac86d98f3524d4fc04c8c3bd8d4e5d886a
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Apr 27 03:14:04 2019 +0000
popover: Add the same activate-default action
gtk/gtkpopover.c | 40 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 39 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkpopover.c b/gtk/gtkpopover.c
index d0c73bb759..003aebb737 100644
--- a/gtk/gtkpopover.c
+++ b/gtk/gtkpopover.c
@@ -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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]