From 8cf774d668da5983fa66c9b40b57e235e7e30208 Mon Sep 17 00:00:00 2001 From: Olof-Joachim Frahm Date: Sun, 26 Feb 2017 16:02:49 +0100 Subject: [PATCH] Move style change for popover creation. Creating with `gtk_popover_new_from_model` should be exactly the same as if via `gtk_popover_new` plus `gtk_popover_bind_model`. Also remove the style if the model is unbound at any point. --- gtk/gtkpopover.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/gtk/gtkpopover.c b/gtk/gtkpopover.c index 5f0f4434ff..e89ae3723c 100644 --- a/gtk/gtkpopover.c +++ b/gtk/gtkpopover.c @@ -2469,6 +2469,7 @@ gtk_popover_bind_model (GtkPopover *popover, { GtkWidget *child; GtkWidget *stack; + GtkStyleContext *style_context; g_return_if_fail (GTK_IS_POPOVER (popover)); g_return_if_fail (model == NULL || G_IS_MENU_MODEL (model)); @@ -2477,6 +2478,8 @@ gtk_popover_bind_model (GtkPopover *popover, if (child) gtk_widget_destroy (child); + style_context = gtk_widget_get_style_context (GTK_WIDGET (popover)); + if (model) { stack = gtk_stack_new (); @@ -2494,6 +2497,12 @@ gtk_popover_bind_model (GtkPopover *popover, g_signal_connect (popover, "unmap", G_CALLBACK (back_to_main), NULL); g_signal_connect (popover, "map", G_CALLBACK (back_to_main), NULL); + + gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_MENU); + } + else + { + gtk_style_context_remove_class (style_context, GTK_STYLE_CLASS_MENU); } } @@ -2522,7 +2531,6 @@ gtk_popover_new_from_model (GtkWidget *relative_to, GMenuModel *model) { GtkWidget *popover; - GtkStyleContext *style_context; g_return_val_if_fail (relative_to == NULL || GTK_IS_WIDGET (relative_to), NULL); g_return_val_if_fail (G_IS_MENU_MODEL (model), NULL); @@ -2530,9 +2538,6 @@ gtk_popover_new_from_model (GtkWidget *relative_to, popover = gtk_popover_new (relative_to); gtk_popover_bind_model (GTK_POPOVER (popover), model, NULL); - style_context = gtk_widget_get_style_context (GTK_WIDGET (popover)); - gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_MENU); - return popover; }