[totem] main: Correctly remove multiple menu items



commit 755266dd11d25b4387f0de04ac272d51d29228df
Author: Bastien Nocera <hadess hadess net>
Date:   Wed May 15 17:30:43 2013 +0200

    main: Correctly remove multiple menu items
    
    We can't just iterate over the menu model when removing menu items,
    as the item 1 because item 0, when item 0 is removed, etc.
    
    Also make sure that we don't remove associated actions if there is
    a target value set, as this is likely to mean that the action is
    used by some other menu items.

 src/totem-object.c |   23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)
---
diff --git a/src/totem-object.c b/src/totem-object.c
index d3b4706..9ae2905 100644
--- a/src/totem-object.c
+++ b/src/totem-object.c
@@ -550,25 +550,36 @@ totem_object_get_menu_section (TotemObject *totem,
  * @totem: a #TotemObject
  * @id: the ID for the menu section to empty
  *
- * Empty the GMenu section pointed to by @id.
+ * Empty the GMenu section pointed to by @id, and remove any
+ * related actions. Note that menu items with specific target
+ * will not have the associated action removed.
  **/
 void
 totem_object_empty_menu_section (TotemObject *totem,
                                 const char  *id)
 {
        GMenu *menu;
-       gint i;
 
        g_return_val_if_fail (TOTEM_IS_OBJECT (totem), NULL);
 
        menu = G_MENU (gtk_builder_get_object (totem->xml, id));
        g_return_if_fail (menu != NULL);
 
-       for (i = 0; i < g_menu_model_get_n_items (G_MENU_MODEL (menu)); i++) {
+       while (g_menu_model_get_n_items (G_MENU_MODEL (menu)) > 0) {
                const char *action;
-               g_menu_model_get_item_attribute (G_MENU_MODEL (menu), i, G_MENU_ATTRIBUTE_ACTION, "s", 
&action);
-               g_action_map_remove_action (G_ACTION_MAP (totem), action);
-               g_menu_remove (G_MENU (menu), i);
+               g_menu_model_get_item_attribute (G_MENU_MODEL (menu), 0, G_MENU_ATTRIBUTE_ACTION, "s", 
&action);
+               if (g_str_has_prefix (action, "app.")) {
+                       GVariant *target;
+
+                       target = g_menu_model_get_item_attribute_value (G_MENU_MODEL (menu), 0, 
G_MENU_ATTRIBUTE_TARGET, NULL);
+
+                       /* Don't remove actions that have a specific target */
+                       if (target == NULL)
+                               g_action_map_remove_action (G_ACTION_MAP (totem), action + strlen ("app."));
+                       else
+                               g_variant_unref (target);
+               }
+               g_menu_remove (G_MENU (menu), 0);
        }
 }
 


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