[gtk/wip/matthiasc/popup4: 87/94] 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: 87/94] popover: Add the same activate-default action
- Date: Sat, 27 Apr 2019 04:48:43 +0000 (UTC)
commit 08fd6e44480d2721d85fe63112b530a6a9317b19
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 2ec0e85dab..69ed170aba 100644
--- a/gtk/gtkpopover.c
+++ b/gtk/gtkpopover.c
@@ -373,6 +373,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)
{
@@ -401,6 +435,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
@@ -1252,5 +1288,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]