[gedit/wip/tabs] Notebook menu: fix menu population logic



commit 321f5448cf38bbf430b9cfd519445e0a3148e891
Author: Ryan Lortie <desrt desrt ca>
Date:   Thu Jul 11 15:25:08 2013 -0400

    Notebook menu: fix menu population logic
    
    There were a couple of problems with the logic for menu population.
    
    The biggest problem was that the menu was always being emptied and
    repopulated on both open and close, which was needless work.
    
    A more subtle problem, though, was that the menu was being emptied
    immediately on the menu being closed.  The "toggled" signal on the
    GtkMenuButton was being fired before the action activation had been
    delivered.  Removing all items from the menu at this point resulted in
    the menu item itself being destroyed, and the signal emission stopping
    (so that the action activation never arrived).  Remove the items from
    the idle in order to avoid this.
    
    This patch also fixes a leak of GMenuItems when constructing the menu.

 gedit/gedit-notebook.c |   19 ++++++++-----------
 1 files changed, 8 insertions(+), 11 deletions(-)
---
diff --git a/gedit/gedit-notebook.c b/gedit/gedit-notebook.c
index 4e852ab..a1a06c9 100644
--- a/gedit/gedit-notebook.c
+++ b/gedit/gedit-notebook.c
@@ -618,6 +618,13 @@ populate_menu (GeditNotebook *notebook)
        GList *l, *children;
        gint i;
 
+       g_menu_remove_all (priv->documents_menu);
+
+       if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->documents_button)))
+       {
+               return G_SOURCE_REMOVE;
+       }
+
        children = gtk_container_get_children (GTK_CONTAINER (notebook));
        for (l = children, i = 0; l != NULL; l = g_list_next (l), i++)
        {
@@ -641,6 +648,7 @@ populate_menu (GeditNotebook *notebook)
                }
 
                g_menu_append_item (priv->documents_menu, item);
+               g_object_unref (item);
        }
 
        g_list_free (children);
@@ -656,15 +664,6 @@ on_documents_button_toggled (GtkToggleButton *button,
 }
 
 static void
-on_documents_button_toggled_after (GtkToggleButton *button,
-                                   GeditNotebook   *notebook)
-{
-       GeditNotebookPrivate *priv = notebook->priv;
-
-       g_menu_remove_all (priv->documents_menu);
-}
-
-static void
 gedit_notebook_init (GeditNotebook *notebook)
 {
        GeditNotebookPrivate *priv;
@@ -706,8 +705,6 @@ gedit_notebook_init (GeditNotebook *notebook)
 
        g_signal_connect (priv->documents_button, "toggled",
                          G_CALLBACK (on_documents_button_toggled), notebook);
-       g_signal_connect_after (priv->documents_button, "toggled",
-                               G_CALLBACK (on_documents_button_toggled_after), notebook);
 }
 
 static GtkWidget *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]