]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkuimanager.c
Updated Arabic translation
[~andy/gtk] / gtk / gtkuimanager.c
index bde6ccf8300306b286e7a14f5845dcfa0623ca34..c5c7794a954ed3930f2a9a63a02fa0ccd761b032 100644 (file)
  * Modified by the GTK+ Team and others 2003.  See the AUTHORS
  * file for a list of people on the GTK+ Team.  See the ChangeLog
  * files for a list of changes.  These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
  */
 
-#include <config.h>
+#include "config.h"
 
 #include <string.h>
+#include "gtkaccellabel.h"
+#include "gtkactivatable.h"
+#include "gtkbuildable.h"
+#include "gtkimagemenuitem.h"
 #include "gtkintl.h"
 #include "gtkmarshalers.h"
 #include "gtkmenu.h"
 #include "gtkmenubar.h"
-#include "gtkmenushell.h"
 #include "gtkmenutoolbutton.h"
 #include "gtkseparatormenuitem.h"
 #include "gtkseparatortoolitem.h"
 #include "gtktearoffmenuitem.h"
 #include "gtktoolbar.h"
 #include "gtkuimanager.h"
+#include "gtkwindow.h"
 #include "gtkprivate.h"
 #include "gtkalias.h"
 
 #undef DEBUG_UI_MANAGER
 
-typedef enum 
+typedef enum
 {
   NODE_TYPE_UNDECIDED,
   NODE_TYPE_ROOT,
@@ -79,6 +83,9 @@ struct _Node {
 
   guint dirty : 1;
   guint expand : 1;  /* used for separators */
+  guint popup_accels : 1;
+  guint always_show_image_set : 1; /* used for menu items */
+  guint always_show_image     : 1; /* used for menu items */
 };
 
 #define GTK_UI_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_UI_MANAGER, GtkUIManagerPrivate))
@@ -107,8 +114,6 @@ struct _NodeUIReference
   GQuark action_quark;
 };
 
-static void        gtk_ui_manager_class_init      (GtkUIManagerClass *class);
-static void        gtk_ui_manager_init            (GtkUIManager      *self);
 static void        gtk_ui_manager_finalize        (GObject           *object);
 static void        gtk_ui_manager_set_property    (GObject           *object,
                                                    guint              prop_id,
@@ -144,6 +149,28 @@ static void        node_prepend_ui_reference      (GNode             *node,
 static void        node_remove_ui_reference       (GNode             *node,
                                                    guint              merge_id);
 
+/* GtkBuildable */
+static void gtk_ui_manager_buildable_init      (GtkBuildableIface *iface);
+static void gtk_ui_manager_buildable_add_child (GtkBuildable  *buildable,
+                                               GtkBuilder    *builder,
+                                               GObject       *child,
+                                               const gchar   *type);
+static GObject* gtk_ui_manager_buildable_construct_child (GtkBuildable *buildable,
+                                                         GtkBuilder   *builder,
+                                                         const gchar  *name);
+static gboolean gtk_ui_manager_buildable_custom_tag_start (GtkBuildable  *buildable,
+                                                          GtkBuilder    *builder,
+                                                          GObject       *child,
+                                                          const gchar   *tagname,
+                                                          GMarkupParser *parser,
+                                                          gpointer      *data);
+static void     gtk_ui_manager_buildable_custom_tag_end (GtkBuildable   *buildable,
+                                                        GtkBuilder      *builder,
+                                                        GObject         *child,
+                                                        const gchar     *tagname,
+                                                        gpointer        *data);
+
+
 
 enum 
 {
@@ -163,52 +190,19 @@ enum
   PROP_UI
 };
 
-static GObjectClass *parent_class = NULL;
 static guint ui_manager_signals[LAST_SIGNAL] = { 0 };
 
-static GMemChunk *merge_node_chunk = NULL;
-
-GType
-gtk_ui_manager_get_type (void)
-{
-  static GtkType type = 0;
-
-  if (!type)
-    {
-      static const GTypeInfo type_info =
-      {
-        sizeof (GtkUIManagerClass),
-        (GBaseInitFunc) NULL,
-        (GBaseFinalizeFunc) NULL,
-        (GClassInitFunc) gtk_ui_manager_class_init,
-        (GClassFinalizeFunc) NULL,
-        NULL,
-        
-        sizeof (GtkUIManager),
-        0, /* n_preallocs */
-        (GInstanceInitFunc) gtk_ui_manager_init,
-      };
-
-      type = g_type_register_static (G_TYPE_OBJECT,
-                                    "GtkUIManager",
-                                    &type_info, 0);
-    }
-  return type;
-}
+G_DEFINE_TYPE_WITH_CODE (GtkUIManager, gtk_ui_manager, G_TYPE_OBJECT,
+                        G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
+                                               gtk_ui_manager_buildable_init))
 
 static void
 gtk_ui_manager_class_init (GtkUIManagerClass *klass)
 {
   GObjectClass *gobject_class;
 
-  parent_class = g_type_class_peek_parent (klass);
-
   gobject_class = G_OBJECT_CLASS (klass);
 
-  if (!merge_node_chunk)
-    merge_node_chunk = g_mem_chunk_create (Node, 64,
-                                          G_ALLOC_AND_FREE);
-
   gobject_class->finalize = gtk_ui_manager_finalize;
   gobject_class->set_property = gtk_ui_manager_set_property;
   gobject_class->get_property = gtk_ui_manager_get_property;
@@ -255,7 +249,7 @@ gtk_ui_manager_class_init (GtkUIManagerClass *klass)
    * Since: 2.4
    */
   ui_manager_signals[ADD_WIDGET] =
-    g_signal_new ("add_widget",
+    g_signal_new (I_("add-widget"),
                  G_OBJECT_CLASS_TYPE (klass),
                  G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
                  G_STRUCT_OFFSET (GtkUIManagerClass, add_widget),
@@ -274,7 +268,7 @@ gtk_ui_manager_class_init (GtkUIManagerClass *klass)
    * Since: 2.4
    */
   ui_manager_signals[ACTIONS_CHANGED] =
-    g_signal_new ("actions_changed",
+    g_signal_new (I_("actions-changed"),
                  G_OBJECT_CLASS_TYPE (klass),
                  G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
                  G_STRUCT_OFFSET (GtkUIManagerClass, actions_changed),  
@@ -298,7 +292,7 @@ gtk_ui_manager_class_init (GtkUIManagerClass *klass)
    * Since: 2.4
    */
   ui_manager_signals[CONNECT_PROXY] =
-    g_signal_new ("connect_proxy",
+    g_signal_new (I_("connect-proxy"),
                  G_OBJECT_CLASS_TYPE (klass),
                  G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
                  G_STRUCT_OFFSET (GtkUIManagerClass, connect_proxy),
@@ -320,7 +314,7 @@ gtk_ui_manager_class_init (GtkUIManagerClass *klass)
    * Since: 2.4
    */
   ui_manager_signals[DISCONNECT_PROXY] =
-    g_signal_new ("disconnect_proxy",
+    g_signal_new (I_("disconnect-proxy"),
                  G_OBJECT_CLASS_TYPE (klass),
                  G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
                  G_STRUCT_OFFSET (GtkUIManagerClass, disconnect_proxy),
@@ -344,7 +338,7 @@ gtk_ui_manager_class_init (GtkUIManagerClass *klass)
    * Since: 2.4
    */
   ui_manager_signals[PRE_ACTIVATE] =
-    g_signal_new ("pre_activate",
+    g_signal_new (I_("pre-activate"),
                  G_OBJECT_CLASS_TYPE (klass),
                  G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
                  G_STRUCT_OFFSET (GtkUIManagerClass, pre_activate),
@@ -367,7 +361,7 @@ gtk_ui_manager_class_init (GtkUIManagerClass *klass)
    * Since: 2.4
    */
   ui_manager_signals[POST_ACTIVATE] =
-    g_signal_new ("post_activate",
+    g_signal_new (I_("post-activate"),
                  G_OBJECT_CLASS_TYPE (klass),
                  G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
                  G_STRUCT_OFFSET (GtkUIManagerClass, post_activate),
@@ -434,7 +428,82 @@ gtk_ui_manager_finalize (GObject *object)
   g_object_unref (self->private_data->accel_group);
   self->private_data->accel_group = NULL;
 
-  G_OBJECT_CLASS (parent_class)->finalize (object);
+  G_OBJECT_CLASS (gtk_ui_manager_parent_class)->finalize (object);
+}
+
+static void
+gtk_ui_manager_buildable_init (GtkBuildableIface *iface)
+{
+  iface->add_child = gtk_ui_manager_buildable_add_child;
+  iface->construct_child = gtk_ui_manager_buildable_construct_child;
+  iface->custom_tag_start = gtk_ui_manager_buildable_custom_tag_start;
+  iface->custom_tag_end = gtk_ui_manager_buildable_custom_tag_end;
+}
+
+static void
+gtk_ui_manager_buildable_add_child (GtkBuildable  *buildable,
+                                   GtkBuilder    *builder,
+                                   GObject       *child,
+                                   const gchar   *type)
+{
+  GtkUIManager *self = GTK_UI_MANAGER (buildable);
+  guint pos;
+
+  g_return_if_fail (GTK_IS_ACTION_GROUP (child));
+
+  pos = g_list_length (self->private_data->action_groups);
+
+  g_object_ref (child);
+  gtk_ui_manager_insert_action_group (self,
+                                     GTK_ACTION_GROUP (child),
+                                     pos);
+}
+
+static void
+child_hierarchy_changed_cb (GtkWidget *widget,
+                           GtkWidget *unused,
+                           GtkUIManager *uimgr)
+{
+  GtkWidget *toplevel;
+  GtkAccelGroup *group;
+  GSList *groups;
+
+  toplevel = gtk_widget_get_toplevel (widget);
+  if (!toplevel || !GTK_IS_WINDOW (toplevel))
+    return;
+  
+  group = gtk_ui_manager_get_accel_group (uimgr);
+  groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
+  if (g_slist_find (groups, group) == NULL)
+    gtk_window_add_accel_group (GTK_WINDOW (toplevel), group);
+
+  g_signal_handlers_disconnect_by_func (widget,
+                                       child_hierarchy_changed_cb,
+                                       uimgr);
+}
+
+static GObject *
+gtk_ui_manager_buildable_construct_child (GtkBuildable *buildable,
+                                         GtkBuilder   *builder,
+                                         const gchar  *id)
+{
+  GtkWidget *widget;
+  char *name;
+
+  name = g_strdup_printf ("ui/%s", id);
+  widget = gtk_ui_manager_get_widget (GTK_UI_MANAGER (buildable), name);
+  if (!widget)
+    {
+      g_error ("Unknown ui manager child: %s\n", name);
+      g_free (name);
+      return NULL;
+    }
+  g_free (name);
+
+  g_signal_connect (widget, "hierarchy-changed",
+                   G_CALLBACK (child_hierarchy_changed_cb),
+                   GTK_UI_MANAGER (buildable));
+  return g_object_ref (widget);
 }
 
 static void
@@ -470,7 +539,7 @@ gtk_ui_manager_get_property (GObject         *object,
       g_value_set_boolean (value, self->private_data->add_tearoffs);
       break;
     case PROP_UI:
-      g_value_set_string (value, gtk_ui_manager_get_ui (self));
+      g_value_take_string (value, gtk_ui_manager_get_ui (self));
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -633,19 +702,40 @@ gtk_ui_manager_insert_action_group (GtkUIManager   *self,
                                    GtkActionGroup *action_group, 
                                    gint            pos)
 {
+#ifdef G_ENABLE_DEBUG
+  GList *l;
+  const char *group_name;
+#endif 
+
   g_return_if_fail (GTK_IS_UI_MANAGER (self));
   g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
   g_return_if_fail (g_list_find (self->private_data->action_groups, 
                                 action_group) == NULL);
 
+#ifdef G_ENABLE_DEBUG
+  group_name  = gtk_action_group_get_name (action_group);
+
+  for (l = self->private_data->action_groups; l; l = l->next) 
+    {
+      GtkActionGroup *group = l->data;
+
+      if (strcmp (gtk_action_group_get_name (group), group_name) == 0)
+        {
+          g_warning ("Inserting action group '%s' into UI manager which "
+                    "already has a group with this name\n", group_name);
+          break;
+        }
+    }
+#endif /* G_ENABLE_DEBUG */
+
   g_object_ref (action_group);
   self->private_data->action_groups = 
     g_list_insert (self->private_data->action_groups, action_group, pos);
   g_object_connect (action_group,
-                   "object_signal::connect_proxy", G_CALLBACK (cb_proxy_connect_proxy), self,
-                   "object_signal::disconnect_proxy", G_CALLBACK (cb_proxy_disconnect_proxy), self,
-                   "object_signal::pre_activate", G_CALLBACK (cb_proxy_pre_activate), self,
-                   "object_signal::post_activate", G_CALLBACK (cb_proxy_post_activate), self,
+                   "object-signal::connect-proxy", G_CALLBACK (cb_proxy_connect_proxy), self,
+                   "object-signal::disconnect-proxy", G_CALLBACK (cb_proxy_disconnect_proxy), self,
+                   "object-signal::pre-activate", G_CALLBACK (cb_proxy_pre_activate), self,
+                   "object-signal::post-activate", G_CALLBACK (cb_proxy_post_activate), self,
                    NULL);
 
   /* dirty all nodes, as action bindings may change */
@@ -677,10 +767,10 @@ gtk_ui_manager_remove_action_group (GtkUIManager   *self,
     g_list_remove (self->private_data->action_groups, action_group);
 
   g_object_disconnect (action_group,
-                       "any_signal::connect_proxy", G_CALLBACK (cb_proxy_connect_proxy), self,
-                       "any_signal::disconnect_proxy", G_CALLBACK (cb_proxy_disconnect_proxy), self,
-                       "any_signal::pre_activate", G_CALLBACK (cb_proxy_pre_activate), self,
-                       "any_signal::post_activate", G_CALLBACK (cb_proxy_post_activate), self, 
+                       "any-signal::connect-proxy", G_CALLBACK (cb_proxy_connect_proxy), self,
+                       "any-signal::disconnect-proxy", G_CALLBACK (cb_proxy_disconnect_proxy), self,
+                       "any-signal::pre-activate", G_CALLBACK (cb_proxy_pre_activate), self,
+                       "any-signal::post-activate", G_CALLBACK (cb_proxy_post_activate), self, 
                        NULL);
   g_object_unref (action_group);
 
@@ -696,7 +786,8 @@ gtk_ui_manager_remove_action_group (GtkUIManager   *self,
  * 
  * Returns the list of action groups associated with @self.
  *
- * Return value: a #GList of action groups. The list is owned by GTK+ 
+ * Return value:  (element-type GtkActionGroup) (transfer none): a #GList of
+ *   action groups. The list is owned by GTK+
  *   and should not be modified.
  *
  * Since: 2.4
@@ -715,7 +806,7 @@ gtk_ui_manager_get_action_groups (GtkUIManager *self)
  * 
  * Returns the #GtkAccelGroup associated with @self.
  *
- * Return value: the #GtkAccelGroup.
+ * Return value: (transfer none): the #GtkAccelGroup.
  *
  * Since: 2.4
  **/
@@ -745,8 +836,8 @@ gtk_ui_manager_get_accel_group (GtkUIManager *self)
  * the lifecycle of the ui manager. If you add the widgets returned by this 
  * function to some container or explicitly ref them, they will survive the
  * destruction of the ui manager.
- * 
- * Return value: the widget found by following the path, or %NULL if no widget
+ *
+ * Return value: (transfer none): the widget found by following the path, or %NULL if no widget
  *   was found.
  *
  * Since: 2.4
@@ -761,30 +852,36 @@ gtk_ui_manager_get_widget (GtkUIManager *self,
   return GTK_UI_MANAGER_GET_CLASS (self)->get_widget (self, path);
 }
 
+typedef struct {
+  GtkUIManagerItemType types;
+  GSList *list;
+} ToplevelData;
+
 static void
 collect_toplevels (GNode   *node, 
                   gpointer user_data)
 {
-  struct {
-    GtkUIManagerItemType types;
-    GSList *list;
-  } *data = user_data;
-
-  switch (NODE_INFO (node)->type) {
-  case NODE_TYPE_MENUBAR:
-    if (data->types & GTK_UI_MANAGER_MENUBAR)
-      data->list = g_slist_prepend (data->list, NODE_INFO (node)->proxy);
-    break;
-  case NODE_TYPE_TOOLBAR:
-    if (data->types & GTK_UI_MANAGER_TOOLBAR)
-      data->list = g_slist_prepend (data->list, NODE_INFO (node)->proxy);
-    break;
-  case NODE_TYPE_POPUP:
-    if (data->types & GTK_UI_MANAGER_POPUP)
-      data->list = g_slist_prepend (data->list, NODE_INFO (node)->proxy);
-    break;
-  default: ;
-  }
+  ToplevelData *data = user_data;
+
+  if (NODE_INFO (node)->proxy)
+    {
+      switch (NODE_INFO (node)->type) 
+       {
+       case NODE_TYPE_MENUBAR:
+         if (data->types & GTK_UI_MANAGER_MENUBAR)
+       data->list = g_slist_prepend (data->list, NODE_INFO (node)->proxy);
+         break;
+       case NODE_TYPE_TOOLBAR:
+      if (data->types & GTK_UI_MANAGER_TOOLBAR)
+       data->list = g_slist_prepend (data->list, NODE_INFO (node)->proxy);
+      break;
+       case NODE_TYPE_POPUP:
+         if (data->types & GTK_UI_MANAGER_POPUP)
+           data->list = g_slist_prepend (data->list, NODE_INFO (node)->proxy);
+         break;
+       default: ;
+       }
+    }
 }
 
 /**
@@ -795,9 +892,9 @@ collect_toplevels (GNode   *node,
  *   #GTK_UI_MANAGER_POPUP.
  * 
  * Obtains a list of all toplevel widgets of the requested types.
- * 
- * Return value: a newly-allocated of all toplevel widgets of the requested 
- * types. 
+ *
+ * Return value: (element-type GtkWidget) (transfer container): a newly-allocated #GSList of
+ * all toplevel widgets of the requested types.  Free the returned list with g_slist_free().
  *
  * Since: 2.4
  **/
@@ -805,10 +902,7 @@ GSList *
 gtk_ui_manager_get_toplevels (GtkUIManager         *self,
                              GtkUIManagerItemType  types)
 {
-  struct {
-    GtkUIManagerItemType types;
-    GSList *list;
-  } data;
+  ToplevelData data;
 
   g_return_val_if_fail (GTK_IS_UI_MANAGER (self), NULL);
   g_return_val_if_fail ((~(GTK_UI_MANAGER_MENUBAR | 
@@ -850,6 +944,23 @@ gtk_ui_manager_get_action (GtkUIManager *self,
   return GTK_UI_MANAGER_GET_CLASS (self)->get_action (self, path);
 }
 
+static gboolean
+node_is_dead (GNode *node)
+{
+  GNode *child;
+
+  if (NODE_INFO (node)->uifiles != NULL)
+    return FALSE;
+
+  for (child = node->children; child != NULL; child = child->next)
+    {
+      if (!node_is_dead (child))
+       return FALSE;
+    }
+
+  return TRUE;
+}
+
 static GNode *
 get_child_node (GtkUIManager *self, 
                GNode        *parent,
@@ -884,7 +995,18 @@ get_child_node (GtkUIManager *self,
                               node_type, 
                               NODE_INFO (child)->name,
                               NODE_INFO (child)->type);
-                 
+
+                    if (node_is_dead (child))
+                      {
+                        /* This node was removed but is still dirty so
+                         * it is still in the tree. We want to treat this
+                         * as if it didn't exist, which means we move it
+                         * to the position it would have been created at.
+                         */
+                        g_node_unlink (child);
+                        goto insert_child;
+                      }
+
                  return child;
                }
            }
@@ -893,25 +1015,25 @@ get_child_node (GtkUIManager *self,
        {
          Node *mnode;
          
-         mnode = g_chunk_new0 (Node, merge_node_chunk);
+         mnode = g_slice_new0 (Node);
          mnode->type = node_type;
          mnode->name = g_strndup (childname, childname_length);
 
+         child = g_node_new (mnode);
+       insert_child:
          if (sibling)
            {
              if (top)
-               child = g_node_insert_before (parent, sibling, 
-                                             g_node_new (mnode));
+               g_node_insert_before (parent, sibling, child);
              else
-               child = g_node_insert_after (parent, sibling, 
-                                            g_node_new (mnode));
+               g_node_insert_after (parent, sibling, child);
            }
          else
            {
              if (top)
-               child = g_node_prepend_data (parent, mnode);
+               g_node_prepend (parent, child);
              else
-               child = g_node_append_data (parent, mnode);
+               g_node_append (parent, child);
            }
 
          mark_node_dirty (child);
@@ -933,7 +1055,7 @@ get_child_node (GtkUIManager *self,
        {
          Node *mnode;
 
-         mnode = g_chunk_new0 (Node, merge_node_chunk);
+         mnode = g_slice_new0 (Node);
          mnode->type = node_type;
          mnode->name = g_strndup (childname, childname_length);
          mnode->dirty = TRUE;
@@ -986,12 +1108,18 @@ get_node (GtkUIManager *self,
   return node;
 }
 
+static void
+node_ui_reference_free (gpointer data)
+{
+  g_slice_free (NodeUIReference, data);
+}
+
 static gboolean
 free_node (GNode *node)
 {
   Node *info = NODE_INFO (node);
   
-  g_list_foreach (info->uifiles, (GFunc) g_free, NULL);
+  g_list_foreach (info->uifiles, (GFunc) node_ui_reference_free, NULL);
   g_list_free (info->uifiles);
 
   if (info->action)
@@ -1001,7 +1129,7 @@ free_node (GNode *node)
   if (info->extra)
     g_object_unref (info->extra);
   g_free (info->name);
-  g_chunk_free (info, merge_node_chunk);
+  g_slice_free (Node, info);
 
   return FALSE;
 }
@@ -1038,7 +1166,7 @@ node_prepend_ui_reference (GNode  *gnode,
     reference = node->uifiles->data;
   else
     {
-      reference = g_new (NodeUIReference, 1);
+      reference = g_slice_new (NodeUIReference);
       node->uifiles = g_list_prepend (node->uifiles, reference);
     }
 
@@ -1064,7 +1192,7 @@ node_remove_ui_reference (GNode  *gnode,
          if (p == node->uifiles)
            mark_node_dirty (gnode);
          node->uifiles = g_list_delete_link (node->uifiles, p);
-         g_free (reference);
+         g_slice_free (NodeUIReference, reference);
 
          break;
        }
@@ -1115,7 +1243,9 @@ start_element_handler (GMarkupParseContext *context,
   GQuark action_quark;
   gboolean top;
   gboolean expand = FALSE;
-  
+  gboolean accelerators = FALSE;
+  gboolean always_show_image_set = FALSE, always_show_image = FALSE;
+
   gboolean raise_error = TRUE;
 
   node_name = NULL;
@@ -1142,20 +1272,18 @@ start_element_handler (GMarkupParseContext *context,
        {
          expand = !strcmp (attribute_values[i], "true");
        }
-      else
-       {
-         gint line_number, char_number;
-         
-         g_markup_parse_context_get_position (context,
-                                              &line_number, &char_number);
-         g_set_error (error,
-                      G_MARKUP_ERROR,
-                      G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
-                      _("Unknown attribute '%s' on line %d char %d"),
-                      attribute_names[i],
-                      line_number, char_number);
-         return;
-       }
+      else if (!strcmp (attribute_names[i], "accelerators"))
+        {
+          accelerators = !strcmp (attribute_values[i], "true");
+        }
+      else if (!strcmp (attribute_names[i], "always-show-image"))
+        {
+          always_show_image_set = TRUE;
+          always_show_image = !strcmp (attribute_values[i], "true");
+        }
+      /*  else silently skip unknown attributes to be compatible with
+       *  future additional attributes.
+       */
     }
 
   /* Work out a name for this node.  Either the name attribute, or
@@ -1251,7 +1379,10 @@ start_element_handler (GMarkupParseContext *context,
                                 TRUE, top);
          if (NODE_INFO (node)->action_name == 0)
            NODE_INFO (node)->action_name = action_quark;
-         
+
+         NODE_INFO (node)->always_show_image_set = always_show_image_set;
+         NODE_INFO (node)->always_show_image = always_show_image;
+
          node_prepend_ui_reference (node, ctx->merge_id, action_quark);
          
          raise_error = FALSE;
@@ -1265,6 +1396,9 @@ start_element_handler (GMarkupParseContext *context,
                                         node_name, strlen (node_name),
                                         NODE_TYPE_POPUP,
                                         TRUE, FALSE);
+
+          NODE_INFO (ctx->current)->popup_accels = accelerators;
+
          if (NODE_INFO (ctx->current)->action_name == 0)
            NODE_INFO (ctx->current)->action_name = action_quark;
          
@@ -1305,7 +1439,7 @@ start_element_handler (GMarkupParseContext *context,
          if (!strcmp (node_name, "separator"))
            {
              node_name = NULL;
-             length = -1;
+             length = 0;
            }
          else
            length = strlen (node_name);
@@ -1464,7 +1598,7 @@ text_handler (GMarkupParseContext *context,
 }
 
 
-static GMarkupParser ui_parser = {
+static const GMarkupParser ui_parser = {
   start_element_handler,
   end_element_handler,
   text_handler,
@@ -1507,7 +1641,7 @@ add_ui_from_string (GtkUIManager *self,
 
   queue_update (self);
 
-  g_object_notify (G_OBJECT (self), "ui");      
+  g_object_notify (G_OBJECT (self), "ui");
 
   return ctx.merge_id;
 
@@ -1603,11 +1737,11 @@ gtk_ui_manager_add_ui_from_file (GtkUIManager *self,
  * @merge_id: the merge id for the merged UI, see gtk_ui_manager_new_merge_id()
  * @path: a path
  * @name: the name for the added UI element
- * @action: the name of the action to be proxied, or %NULL to add a separator
+ * @action: (allow-none): the name of the action to be proxied, or %NULL to add a separator
  * @type: the type of UI element to add.
- * @top: if %TRUE, the UI element is added before its siblings, otherwise it 
+ * @top: if %TRUE, the UI element is added before its siblings, otherwise it
  *   is added after its siblings.
- * 
+ *
  * Adds a UI element to the current contents of @self. 
  *
  * If @type is %GTK_UI_MANAGER_AUTO, GTK+ inserts a menuitem, toolitem or 
@@ -1637,7 +1771,7 @@ gtk_ui_manager_add_ui (GtkUIManager        *self,
 
   g_return_if_fail (GTK_IS_UI_MANAGER (self));  
   g_return_if_fail (merge_id > 0);
-  g_return_if_fail (name != NULL);
+  g_return_if_fail (name != NULL || type == GTK_UI_MANAGER_SEPARATOR);
 
   node = get_node (self, path, NODE_TYPE_UNDECIDED, FALSE);
   sibling = NULL;
@@ -1717,6 +1851,7 @@ gtk_ui_manager_add_ui (GtkUIManager        *self,
          node_type = NODE_TYPE_TOOLBAR;
          break;
        case GTK_UI_MANAGER_POPUP:
+       case GTK_UI_MANAGER_POPUP_WITH_ACCELS:
          node_type = NODE_TYPE_POPUP;
          break;
        case GTK_UI_MANAGER_ACCELERATOR:
@@ -1738,9 +1873,12 @@ gtk_ui_manager_add_ui (GtkUIManager        *self,
     }
    
   child = get_child_node (self, node, sibling,
-                         name, strlen (name),
+                         name, name ? strlen (name) : 0,
                          node_type, TRUE, top);
 
+  if (type == GTK_UI_MANAGER_POPUP_WITH_ACCELS)
+    NODE_INFO (child)->popup_accels = TRUE;
+
   if (action != NULL)
     action_quark = g_quark_from_string (action);
 
@@ -1778,6 +1916,8 @@ void
 gtk_ui_manager_remove_ui (GtkUIManager *self, 
                          guint         merge_id)
 {
+  g_return_if_fail (GTK_IS_UI_MANAGER (self));
+
   g_node_traverse (self->private_data->root_node, 
                   G_POST_ORDER, G_TRAVERSE_ALL, -1,
                   remove_ui, GUINT_TO_POINTER (merge_id));
@@ -1820,15 +1960,15 @@ find_menu_position (GNode      *node,
                    gint       *pos_p)
 {
   GtkWidget *menushell;
-  gint pos;
+  gint pos = 0;
 
   g_return_val_if_fail (node != NULL, FALSE);
   g_return_val_if_fail (NODE_INFO (node)->type == NODE_TYPE_MENU ||
-                       NODE_INFO (node)->type == NODE_TYPE_POPUP ||
-                       NODE_INFO (node)->type == NODE_TYPE_MENU_PLACEHOLDER ||
-                       NODE_INFO (node)->type == NODE_TYPE_MENUITEM ||
-                       NODE_INFO (node)->type == NODE_TYPE_SEPARATOR,
-                       FALSE);
+                       NODE_INFO (node)->type == NODE_TYPE_POPUP ||
+                       NODE_INFO (node)->type == NODE_TYPE_MENU_PLACEHOLDER ||
+                       NODE_INFO (node)->type == NODE_TYPE_MENUITEM ||
+                       NODE_INFO (node)->type == NODE_TYPE_SEPARATOR,
+                        FALSE);
 
   /* first sibling -- look at parent */
   if (node->prev == NULL)
@@ -1862,8 +2002,8 @@ find_menu_position (GNode      *node,
                              NODE_INFO (parent)->proxy) + 1;
          break;
        default:
-         g_warning("%s: bad parent node type %d", G_STRLOC,
-                   NODE_INFO (parent)->type);
+         g_warning ("%s: bad parent node type %d", G_STRLOC,
+                    NODE_INFO (parent)->type);
          return FALSE;
        }
     }
@@ -1878,9 +2018,12 @@ find_menu_position (GNode      *node,
       else
        prev_child = NODE_INFO (sibling)->proxy;
 
-      g_return_val_if_fail (GTK_IS_WIDGET (prev_child), FALSE);
+      if (!GTK_IS_WIDGET (prev_child))
+        return FALSE;
+
       menushell = gtk_widget_get_parent (prev_child);
-      g_return_val_if_fail (GTK_IS_MENU_SHELL (menushell), FALSE);
+      if (!GTK_IS_MENU_SHELL (menushell))
+        return FALSE;
 
       pos = g_list_index (GTK_MENU_SHELL (menushell)->children, prev_child) + 1;
     }
@@ -1903,11 +2046,11 @@ find_toolbar_position (GNode      *node,
 
   g_return_val_if_fail (node != NULL, FALSE);
   g_return_val_if_fail (NODE_INFO (node)->type == NODE_TYPE_TOOLBAR ||
-                       NODE_INFO (node)->type == NODE_TYPE_TOOLBAR_PLACEHOLDER ||
-                       NODE_INFO (node)->type == NODE_TYPE_TOOLITEM ||
-                       NODE_INFO (node)->type == NODE_TYPE_SEPARATOR,
-                       FALSE);
-
+                       NODE_INFO (node)->type == NODE_TYPE_TOOLBAR_PLACEHOLDER ||
+                       NODE_INFO (node)->type == NODE_TYPE_TOOLITEM ||
+                       NODE_INFO (node)->type == NODE_TYPE_SEPARATOR,
+                        FALSE);
+  
   /* first sibling -- look at parent */
   if (node->prev == NULL)
     {
@@ -1943,14 +2086,17 @@ find_toolbar_position (GNode      *node,
       else
        prev_child = NODE_INFO (sibling)->proxy;
 
-      g_return_val_if_fail (GTK_IS_WIDGET (prev_child), FALSE);
+      if (!GTK_IS_WIDGET (prev_child))
+        return FALSE;
+
       toolbar = gtk_widget_get_parent (prev_child);
-      g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
+      if (!GTK_IS_TOOLBAR (toolbar))
+        return FALSE;
 
       pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (toolbar),
                                        GTK_TOOL_ITEM (prev_child)) + 1;
     }
-
+  
   if (toolbar_p)
     *toolbar_p = toolbar;
   if (pos_p)
@@ -1961,7 +2107,7 @@ find_toolbar_position (GNode      *node,
 
 /**
  * _gtk_menu_is_empty:
- * @menu: a #GtkMenu or %NULL
+ * @menu: (allow-none): a #GtkMenu or %NULL
  * 
  * Determines whether @menu is empty. A menu is considered empty if it
  * the only visible children are tearoff menu items or "filler" menu 
@@ -1975,6 +2121,7 @@ gboolean
 _gtk_menu_is_empty (GtkWidget *menu)
 {
   GList *children, *cur;
+  gboolean result = TRUE;
 
   g_return_val_if_fail (menu == NULL || GTK_IS_MENU (menu), TRUE);
 
@@ -1990,13 +2137,16 @@ _gtk_menu_is_empty (GtkWidget *menu)
        {
          if (!GTK_IS_TEAROFF_MENU_ITEM (cur->data) &&
              !g_object_get_data (cur->data, "gtk-empty-menu-item"))
-           return FALSE;
+            {
+             result = FALSE;
+              break;
+            }
        }
       cur = cur->next;
     }
   g_list_free (children);
 
-  return TRUE;
+  return result;
 }
 
 enum {
@@ -2005,10 +2155,6 @@ enum {
   SEPARATOR_MODE_HIDDEN
 };
 
-void _gtk_action_sync_menu_visible (GtkAction *action,
-                                   GtkWidget *proxy,
-                                   gboolean   empty);
-
 static void
 update_smart_separators (GtkWidget *proxy)
 {
@@ -2025,7 +2171,6 @@ update_smart_separators (GtkWidget *proxy)
       gboolean empty;
       GList *children, *cur, *last;
       GtkWidget *filler;
-      gint i;
 
       children = gtk_container_get_children (GTK_CONTAINER (parent));
       
@@ -2034,7 +2179,6 @@ update_smart_separators (GtkWidget *proxy)
       empty = TRUE;
       filler = NULL;
 
-      i = 0;
       cur = children;
       while (cur) 
        {
@@ -2111,7 +2255,8 @@ update_smart_separators (GtkWidget *proxy)
 static void
 update_node (GtkUIManager *self, 
             GNode        *node,
-            gboolean      in_popup)
+            gboolean      in_popup,
+             gboolean      popup_accels)
 {
   Node *info;
   GNode *child;
@@ -2131,7 +2276,11 @@ update_node (GtkUIManager *self,
   if (!info->dirty)
     return;
 
-  in_popup = in_popup || (info->type == NODE_TYPE_POPUP);
+  if (info->type == NODE_TYPE_POPUP)
+    {
+      in_popup = TRUE;
+      popup_accels = info->popup_accels;
+    }
 
 #ifdef DEBUG_UI_MANAGER
   g_print ("update_node name=%s dirty=%d popup %d (", 
@@ -2169,9 +2318,9 @@ update_node (GtkUIManager *self,
       info->type != NODE_TYPE_MENU_PLACEHOLDER &&
       info->type != NODE_TYPE_TOOLBAR_PLACEHOLDER)
     {
-      g_warning ("%s: missing action", info->name);
+      g_warning ("%s: missing action %s", info->name, action_name);
       
-      goto recurse_children;
+      return;
     }
   
   if (action)
@@ -2211,8 +2360,7 @@ update_node (GtkUIManager *self,
       if (info->proxy == NULL)
        {
          info->proxy = gtk_menu_bar_new ();
-         g_object_ref (info->proxy);
-         gtk_object_sink (GTK_OBJECT (info->proxy));
+         g_object_ref_sink (info->proxy);
          gtk_widget_set_name (info->proxy, info->name);
          gtk_widget_show (info->proxy);
          g_signal_emit (self, ui_manager_signals[ADD_WIDGET], 0, info->proxy);
@@ -2222,16 +2370,16 @@ update_node (GtkUIManager *self,
       if (info->proxy == NULL) 
        {
          info->proxy = gtk_menu_new ();
-         g_object_ref (info->proxy);
-         gtk_object_sink (GTK_OBJECT (info->proxy));
+         g_object_ref_sink (info->proxy);
        }
       gtk_widget_set_name (info->proxy, info->name);
       break;
     case NODE_TYPE_MENU:
       {
        GtkWidget *prev_submenu = NULL;
-       GtkWidget *menu;
+       GtkWidget *menu = NULL;
        GList *siblings;
+
        /* remove the proxy if it is of the wrong type ... */
        if (info->proxy &&  
            G_OBJECT_TYPE (info->proxy) != GTK_ACTION_GET_CLASS (action)->menu_item_type)
@@ -2246,61 +2394,72 @@ update_node (GtkUIManager *self,
                }
              }
 
-           gtk_action_disconnect_proxy (info->action, info->proxy);
+            gtk_activatable_set_related_action (GTK_ACTIVATABLE (info->proxy), NULL);
            gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
                                  info->proxy);
            g_object_unref (info->proxy);
            info->proxy = NULL;
          }
+
        /* create proxy if needed ... */
        if (info->proxy == NULL)
          {
-           GtkWidget *menushell;
-           gint pos;
+            /* ... if the action already provides a menu, then use
+             * that menu instead of creating an empty one
+             */
+            if ((NODE_INFO (node->parent)->type == NODE_TYPE_TOOLITEM ||
+                 NODE_INFO (node->parent)->type == NODE_TYPE_MENUITEM) &&
+                GTK_ACTION_GET_CLASS (action)->create_menu)
+              {
+                menu = gtk_action_create_menu (action);
+              }
+
+            if (!menu)
+              {
+                GtkWidget *tearoff;
+                GtkWidget *filler;
+           
+                menu = gtk_menu_new ();
+                gtk_widget_set_name (menu, info->name);
+                tearoff = gtk_tearoff_menu_item_new ();
+                gtk_widget_set_no_show_all (tearoff, TRUE);
+                gtk_menu_shell_append (GTK_MENU_SHELL (menu), tearoff);
+                filler = gtk_menu_item_new_with_label (_("Empty"));
+                g_object_set_data (G_OBJECT (filler),
+                                   I_("gtk-empty-menu-item"),
+                                   GINT_TO_POINTER (TRUE));
+                gtk_widget_set_sensitive (filler, FALSE);
+                gtk_widget_set_no_show_all (filler, TRUE);
+                gtk_menu_shell_append (GTK_MENU_SHELL (menu), filler);
+              }
            
-           if (NODE_INFO (node->parent)->type == NODE_TYPE_TOOLITEM ||
-               find_menu_position (node, &menushell, &pos))
+            if (NODE_INFO (node->parent)->type == NODE_TYPE_TOOLITEM)
              {
-               GtkWidget *tearoff;
-               GtkWidget *filler;
+               info->proxy = menu;
+               g_object_ref_sink (info->proxy);
+               gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (NODE_INFO (node->parent)->proxy),
+                                              menu);
+             }
+           else
+             {
+               GtkWidget *menushell;
+               gint pos;
                
-               menu = gtk_menu_new ();
-               gtk_widget_set_name (menu, info->name);
-               tearoff = gtk_tearoff_menu_item_new ();
-               gtk_widget_set_no_show_all (tearoff, TRUE);
-               gtk_menu_shell_append (GTK_MENU_SHELL (menu), tearoff);
-               filler = gtk_menu_item_new_with_label (_("Empty"));
-               g_object_set_data (G_OBJECT (filler),
-                                  "gtk-empty-menu-item",
-                                  GINT_TO_POINTER (TRUE));
-               gtk_widget_set_sensitive (filler, FALSE);
-               gtk_widget_set_no_show_all (filler, TRUE);
-               gtk_menu_shell_append (GTK_MENU_SHELL (menu), filler);
-
-               if (NODE_INFO (node->parent)->type == NODE_TYPE_TOOLITEM)
-                 {
-                   info->proxy = menu;
-                   g_object_ref (info->proxy);
-                   gtk_object_sink (GTK_OBJECT (info->proxy));
-                   gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (NODE_INFO (node->parent)->proxy),
-                                                  menu);
-                 }
-               else
-                 {
-                   info->proxy = gtk_action_create_menu_item (action);
-                   g_object_ref (info->proxy);
-                   gtk_object_sink (GTK_OBJECT (info->proxy));
-                   g_signal_connect (info->proxy, "notify::visible",
-                                     G_CALLBACK (update_smart_separators), NULL);
-                   gtk_widget_set_name (info->proxy, info->name);
-                   
-                   gtk_menu_item_set_submenu (GTK_MENU_ITEM (info->proxy), menu);
-                   gtk_menu_shell_insert (GTK_MENU_SHELL (menushell), info->proxy, pos);
-                 }
+               if (find_menu_position (node, &menushell, &pos))
+                  {
+                    info->proxy = gtk_action_create_menu_item (action);
+                    g_object_ref_sink (info->proxy);
+                    g_signal_connect (info->proxy, "notify::visible",
+                                      G_CALLBACK (update_smart_separators), NULL);
+                    gtk_widget_set_name (info->proxy, info->name);
+               
+                    gtk_menu_item_set_submenu (GTK_MENU_ITEM (info->proxy), menu);
+                    gtk_menu_shell_insert (GTK_MENU_SHELL (menushell), info->proxy, pos);
+                 }
              }
          }
        else
-         gtk_action_connect_proxy (action, info->proxy);
+          gtk_activatable_set_related_action (GTK_ACTIVATABLE (info->proxy), action);
        
        if (prev_submenu)
          {
@@ -2313,6 +2472,7 @@ update_node (GtkUIManager *self,
          menu = info->proxy;
        else
          menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (info->proxy));
+
        siblings = gtk_container_get_children (GTK_CONTAINER (menu));
        if (siblings != NULL && GTK_IS_TEAROFF_MENU_ITEM (siblings->data))
          {
@@ -2333,8 +2493,7 @@ update_node (GtkUIManager *self,
       if (info->proxy == NULL)
        {
          info->proxy = gtk_toolbar_new ();
-         g_object_ref (info->proxy);
-         gtk_object_sink (GTK_OBJECT (info->proxy));
+         g_object_ref_sink (info->proxy);
          gtk_widget_set_name (info->proxy, info->name);
          gtk_widget_show (info->proxy);
          g_signal_emit (self, ui_manager_signals[ADD_WIDGET], 0, info->proxy);
@@ -2366,27 +2525,25 @@ update_node (GtkUIManager *self,
          gint pos;
          
          if (find_menu_position (node, &menushell, &pos))
-           {
+            {
              info->proxy = gtk_separator_menu_item_new ();
-             g_object_ref (info->proxy);
-             gtk_object_sink (GTK_OBJECT (info->proxy));
+             g_object_ref_sink (info->proxy);
              g_object_set_data (G_OBJECT (info->proxy),
-                                "gtk-separator-mode",
-                                GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN));
+                                I_("gtk-separator-mode"),
+                                GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN));
              gtk_widget_set_no_show_all (info->proxy, TRUE);
              gtk_menu_shell_insert (GTK_MENU_SHELL (menushell),
-                                    NODE_INFO (node)->proxy, pos);
-             
+                                    NODE_INFO (node)->proxy, pos);
+         
              info->extra = gtk_separator_menu_item_new ();
-             g_object_ref (info->extra);
-             gtk_object_sink (GTK_OBJECT (info->extra));
+             g_object_ref_sink (info->extra);
              g_object_set_data (G_OBJECT (info->extra),
-                                "gtk-separator-mode",
-                                GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN));
+                                I_("gtk-separator-mode"),
+                                GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN));
              gtk_widget_set_no_show_all (info->extra, TRUE);
              gtk_menu_shell_insert (GTK_MENU_SHELL (menushell),
-                                    NODE_INFO (node)->extra, pos+1);
-           }
+                                    NODE_INFO (node)->extra, pos + 1);
+            }
        }
       break;
     case NODE_TYPE_TOOLBAR_PLACEHOLDER:
@@ -2413,31 +2570,28 @@ update_node (GtkUIManager *self,
        {
          GtkWidget *toolbar;
          gint pos;
+         GtkToolItem *item;    
          
          if (find_toolbar_position (node, &toolbar, &pos))
-           {
-             GtkToolItem *item;
-             
+            {
              item = gtk_separator_tool_item_new ();
              gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, pos);
              info->proxy = GTK_WIDGET (item);
-             g_object_ref (info->proxy);
-             gtk_object_sink (GTK_OBJECT (info->proxy));
+             g_object_ref_sink (info->proxy);
              g_object_set_data (G_OBJECT (info->proxy),
-                                "gtk-separator-mode",
-                                GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN));
+                                I_("gtk-separator-mode"),
+                                GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN));
              gtk_widget_set_no_show_all (info->proxy, TRUE);
-             
+         
              item = gtk_separator_tool_item_new ();
              gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, pos+1);
              info->extra = GTK_WIDGET (item);
-             g_object_ref (info->extra);
-             gtk_object_sink (GTK_OBJECT (info->extra));
+             g_object_ref_sink (info->extra);
              g_object_set_data (G_OBJECT (info->extra),
-                                "gtk-separator-mode",
-                                GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN));
+                                I_("gtk-separator-mode"),
+                                GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN));
              gtk_widget_set_no_show_all (info->extra, TRUE);
-           }
+            }
        }
       break;
     case NODE_TYPE_MENUITEM:
@@ -2448,7 +2602,7 @@ update_node (GtkUIManager *self,
          g_signal_handlers_disconnect_by_func (info->proxy,
                                                G_CALLBACK (update_smart_separators),
                                                NULL);  
-         gtk_action_disconnect_proxy (info->action, info->proxy);
+          gtk_activatable_set_related_action (GTK_ACTIVATABLE (info->proxy), NULL);
          gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
                                info->proxy);
          g_object_unref (info->proxy);
@@ -2461,15 +2615,19 @@ update_node (GtkUIManager *self,
          gint pos;
          
          if (find_menu_position (node, &menushell, &pos))
-           {
+            {
              info->proxy = gtk_action_create_menu_item (action);
-             g_object_ref (info->proxy);
-             gtk_object_sink (GTK_OBJECT (info->proxy));
+             g_object_ref_sink (info->proxy);
              gtk_widget_set_name (info->proxy, info->name);
-             
+
+              if (info->always_show_image_set &&
+                  GTK_IS_IMAGE_MENU_ITEM (info->proxy))
+                gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (info->proxy),
+                                                           info->always_show_image);
+
              gtk_menu_shell_insert (GTK_MENU_SHELL (menushell),
                                     info->proxy, pos);
-           }
+           }
        }
       else
        {
@@ -2477,18 +2635,21 @@ update_node (GtkUIManager *self,
                                                G_CALLBACK (update_smart_separators),
                                                NULL);
          gtk_menu_item_set_submenu (GTK_MENU_ITEM (info->proxy), NULL);
-         gtk_action_connect_proxy (action, info->proxy);
-       }
-      g_signal_connect (info->proxy, "notify::visible",
-                       G_CALLBACK (update_smart_separators), NULL);
-      if (in_popup) 
-       {
-         /* don't show accels in popups */
-         GtkWidget *label = GTK_BIN (info->proxy)->child;
-         g_object_set (label,
-                       "accel_closure", NULL,
-                       NULL);
+          gtk_activatable_set_related_action (GTK_ACTIVATABLE (info->proxy), action);
        }
+
+      if (info->proxy)
+        {
+          g_signal_connect (info->proxy, "notify::visible",
+                           G_CALLBACK (update_smart_separators), NULL);
+          if (in_popup && !popup_accels)
+           {
+             /* don't show accels in popups */
+             GtkWidget *child = gtk_bin_get_child (GTK_BIN (info->proxy));
+             if (GTK_IS_ACCEL_LABEL (child))
+               g_object_set (child, "accel-closure", NULL, NULL);
+           }
+        }
       
       break;
     case NODE_TYPE_TOOLITEM:
@@ -2499,7 +2660,7 @@ update_node (GtkUIManager *self,
          g_signal_handlers_disconnect_by_func (info->proxy,
                                                G_CALLBACK (update_smart_separators),
                                                NULL);
-         gtk_action_disconnect_proxy (info->action, info->proxy);
+          gtk_activatable_set_related_action (GTK_ACTIVATABLE (info->proxy), NULL);
          gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
                                info->proxy);
          g_object_unref (info->proxy);
@@ -2512,32 +2673,28 @@ update_node (GtkUIManager *self,
          gint pos;
          
          if (find_toolbar_position (node, &toolbar, &pos))
-           {
+            {
              info->proxy = gtk_action_create_tool_item (action);
-             g_object_ref (info->proxy);
-             gtk_object_sink (GTK_OBJECT (info->proxy));
+             g_object_ref_sink (info->proxy);
              gtk_widget_set_name (info->proxy, info->name);
              
              gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
-                                 GTK_TOOL_ITEM (info->proxy), pos);
-           }
+                                 GTK_TOOL_ITEM (info->proxy), pos);
+            }
        }
       else
        {
          g_signal_handlers_disconnect_by_func (info->proxy,
                                                G_CALLBACK (update_smart_separators),
                                                NULL);
-         gtk_action_connect_proxy (action, info->proxy);
+         gtk_activatable_set_related_action (GTK_ACTIVATABLE (info->proxy), action);
        }
 
-      /* FIXME: we must trigger the notify::tooltip handler, since 
-       * tooltips on toolitems can't be set before the toolitem 
-       * is added to the toolbar.
-       */
-      g_object_notify (G_OBJECT (action), "tooltip");
-
-      g_signal_connect (info->proxy, "notify::visible",
-                       G_CALLBACK (update_smart_separators), NULL);
+      if (info->proxy)
+        {
+          g_signal_connect (info->proxy, "notify::visible",
+                           G_CALLBACK (update_smart_separators), NULL);
+        }
       break;
     case NODE_TYPE_SEPARATOR:
       if (NODE_INFO (node->parent)->type == NODE_TYPE_TOOLBAR ||
@@ -2546,7 +2703,8 @@ update_node (GtkUIManager *self,
          GtkWidget *toolbar;
          gint pos;
          gint separator_mode;
-         
+         GtkToolItem *item;
+
          if (GTK_IS_SEPARATOR_TOOL_ITEM (info->proxy))
            {
              gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
@@ -2556,28 +2714,26 @@ update_node (GtkUIManager *self,
            }
          
          if (find_toolbar_position (node, &toolbar, &pos))
-           {
-             GtkToolItem *item = gtk_separator_tool_item_new ();
+            {
+             item  = gtk_separator_tool_item_new ();
              gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, pos);
              info->proxy = GTK_WIDGET (item);
-             g_object_ref (info->proxy);
-             gtk_object_sink (GTK_OBJECT (info->proxy));
+             g_object_ref_sink (info->proxy);
              gtk_widget_set_no_show_all (info->proxy, TRUE);
              if (info->expand)
-               {
-                 gtk_tool_item_set_expand (GTK_TOOL_ITEM (item), TRUE);
-                 gtk_separator_tool_item_set_draw
-                   (GTK_SEPARATOR_TOOL_ITEM (item), FALSE);
-                 separator_mode = SEPARATOR_MODE_VISIBLE;
-               }
-               else
-                 separator_mode = SEPARATOR_MODE_SMART;
-
+               {
+                 gtk_tool_item_set_expand (GTK_TOOL_ITEM (item), TRUE);
+                 gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (item), FALSE);
+                 separator_mode = SEPARATOR_MODE_VISIBLE;
+               }
+             else
+               separator_mode = SEPARATOR_MODE_SMART;
+         
              g_object_set_data (G_OBJECT (info->proxy),
-                                "gtk-separator-mode",
-                                GINT_TO_POINTER (separator_mode));
+                                I_("gtk-separator-mode"),
+                                GINT_TO_POINTER (separator_mode));
              gtk_widget_show (info->proxy);
-           }
+            }
        }
       else
        {
@@ -2594,17 +2750,16 @@ update_node (GtkUIManager *self,
          
          if (find_menu_position (node, &menushell, &pos))
            {
-             info->proxy = gtk_separator_menu_item_new ();
-             g_object_ref (info->proxy);
-             gtk_object_sink (GTK_OBJECT (info->proxy));
+              info->proxy = gtk_separator_menu_item_new ();
+             g_object_ref_sink (info->proxy);
              gtk_widget_set_no_show_all (info->proxy, TRUE);
              g_object_set_data (G_OBJECT (info->proxy),
-                                "gtk-separator-mode",
-                                GINT_TO_POINTER (SEPARATOR_MODE_SMART));
+                                I_("gtk-separator-mode"),
+                                GINT_TO_POINTER (SEPARATOR_MODE_SMART));
              gtk_menu_shell_insert (GTK_MENU_SHELL (menushell),
                                     info->proxy, pos);
              gtk_widget_show (info->proxy);
-           }
+            }
        }
       break;
     case NODE_TYPE_ACCELERATOR:
@@ -2627,7 +2782,7 @@ update_node (GtkUIManager *self,
       
       current = child;
       child = current->next;
-      update_node (self, current, in_popup);
+      update_node (self, current, in_popup, popup_accels);
     }
   
   if (info->proxy) 
@@ -2647,7 +2802,7 @@ update_node (GtkUIManager *self,
        gtk_widget_destroy (info->proxy);
       if (info->extra)
        gtk_widget_destroy (info->extra);
-      if (info->type == NODE_TYPE_ACCELERATOR)
+      if (info->type == NODE_TYPE_ACCELERATOR && info->action != NULL)
        gtk_action_disconnect_accelerator (info->action);
       free_node (node);
       g_node_destroy (node);
@@ -2669,7 +2824,7 @@ do_updates (GtkUIManager *self)
    *    the proxy is reconnected to the new action (or a new proxy widget
    *    is created and added to the parent container).
    */
-  update_node (self, self->private_data->root_node, FALSE);
+  update_node (self, self->private_data->root_node, FALSE, FALSE);
 
   self->private_data->update_tag = 0;
 
@@ -2679,9 +2834,7 @@ do_updates (GtkUIManager *self)
 static gboolean
 do_updates_idle (GtkUIManager *self)
 {
-  GDK_THREADS_ENTER ();
   do_updates (self);
-  GDK_THREADS_LEAVE ();
 
   return FALSE;
 }
@@ -2692,7 +2845,8 @@ queue_update (GtkUIManager *self)
   if (self->private_data->update_tag != 0)
     return;
 
-  self->private_data->update_tag = g_idle_add ((GSourceFunc)do_updates_idle, 
+  self->private_data->update_tag = gdk_threads_add_idle (
+                                              (GSourceFunc)do_updates_idle, 
                                               self);
 }
 
@@ -2707,17 +2861,15 @@ queue_update (GtkUIManager *self)
  * UI in an idle function. A typical example where this function is
  * useful is to enforce that the menubar and toolbar have been added to 
  * the main window before showing it:
- * <informalexample>
- * <programlisting>
+ * |[
  * gtk_container_add (GTK_CONTAINER (window), vbox); 
- * g_signal_connect (merge, "add_widget", 
+ * g_signal_connect (merge, "add-widget", 
  *                   G_CALLBACK (add_widget), vbox);
  * gtk_ui_manager_add_ui_from_file (merge, "my-menus");
  * gtk_ui_manager_add_ui_from_file (merge, "my-toolbars");
  * gtk_ui_manager_ensure_update (merge);  
  * gtk_widget_show (window);
- * </programlisting>
- * </informalexample>
+ * ]|
  *
  * Since: 2.4
  **/
@@ -2758,35 +2910,43 @@ mark_node_dirty (GNode *node)
     NODE_INFO (p)->dirty = TRUE;  
 }
 
-static const gchar *const open_tag_format[] = {
-  "%*s<UNDECIDED",
-  "%*s<ui",
-  "%*s<menubar",
-  "%*s<menu",
-  "%*s<toolbar",
-  "%*s<placeholder",
-  "%*s<placeholder",
-  "%*s<popup",
-  "%*s<menuitem",
-  "%*s<toolitem",
-  "%*s<separator",
-  "%*s<accelerator"
-};
+static const gchar *
+open_tag_format (NodeType type)
+{
+  switch (type)
+    {
+    case NODE_TYPE_UNDECIDED: return "%*s<UNDECIDED"; 
+    case NODE_TYPE_ROOT: return "%*s<ui"; 
+    case NODE_TYPE_MENUBAR: return "%*s<menubar";
+    case NODE_TYPE_MENU: return "%*s<menu";
+    case NODE_TYPE_TOOLBAR: return "%*s<toolbar";
+    case NODE_TYPE_MENU_PLACEHOLDER:
+    case NODE_TYPE_TOOLBAR_PLACEHOLDER: return "%*s<placeholder";
+    case NODE_TYPE_POPUP: return "%*s<popup";
+    case NODE_TYPE_MENUITEM: return "%*s<menuitem";
+    case NODE_TYPE_TOOLITEM: return "%*s<toolitem";
+    case NODE_TYPE_SEPARATOR: return "%*s<separator";
+    case NODE_TYPE_ACCELERATOR: return "%*s<accelerator";
+    default: return NULL;
+    }
+}
 
-static const gchar *const close_tag_format[] = {
-  "%*s</UNDECIDED>\n",
-  "%*s</ui>\n",
-  "%*s</menubar>\n",
-  "%*s</menu>\n",
-  "%*s</toolbar>\n",
-  "%*s</placeholder>\n",
-  "%*s</placeholder>\n",
-  "%*s</popup>\n",
-  NULL,
-  NULL,
-  NULL,
-  NULL
-};
+static const gchar *
+close_tag_format (NodeType type)
+{
+  switch (type)
+    {
+    case NODE_TYPE_UNDECIDED: return "%*s</UNDECIDED>\n";
+    case NODE_TYPE_ROOT: return "%*s</ui>\n";
+    case NODE_TYPE_MENUBAR: return "%*s</menubar>\n";
+    case NODE_TYPE_MENU: return "%*s</menu>\n";
+    case NODE_TYPE_TOOLBAR: return "%*s</toolbar>\n";
+    case NODE_TYPE_MENU_PLACEHOLDER:
+    case NODE_TYPE_TOOLBAR_PLACEHOLDER: return "%*s</placeholder>\n";
+    case NODE_TYPE_POPUP: return "%*s</popup>\n";
+    default: return NULL;
+    }
+}
 
 static void
 print_node (GtkUIManager *self,
@@ -2796,11 +2956,15 @@ print_node (GtkUIManager *self,
 {
   Node  *mnode;
   GNode *child;
+  const gchar *open_fmt;
+  const gchar *close_fmt;
 
   mnode = node->data;
 
-  g_string_append_printf (buffer, open_tag_format[mnode->type],
-                         indent_level, "");
+  open_fmt = open_tag_format (mnode->type);
+  close_fmt = close_tag_format (mnode->type);
+
+  g_string_append_printf (buffer, open_fmt, indent_level, "");
 
   if (mnode->type != NODE_TYPE_ROOT)
     {
@@ -2812,15 +2976,56 @@ print_node (GtkUIManager *self,
                                g_quark_to_string (mnode->action_name));
     }
 
-  g_string_append (buffer,
-                   close_tag_format[mnode->type] ? ">\n" : "/>\n");
+  g_string_append (buffer, close_fmt ? ">\n" : "/>\n");
 
   for (child = node->children; child != NULL; child = child->next)
     print_node (self, child, indent_level + 2, buffer);
 
-  if (close_tag_format[mnode->type])
-    g_string_append_printf (buffer, close_tag_format[mnode->type],
-                            indent_level, "");
+  if (close_fmt)
+    g_string_append_printf (buffer, close_fmt, indent_level, "");
+}
+
+static gboolean
+gtk_ui_manager_buildable_custom_tag_start (GtkBuildable  *buildable,
+                                          GtkBuilder    *builder,
+                                          GObject       *child,
+                                          const gchar   *tagname,
+                                          GMarkupParser *parser,
+                                          gpointer      *data)
+{
+  if (child)
+    return FALSE;
+
+  if (strcmp (tagname, "ui") == 0)
+    {
+      ParseContext *ctx;
+
+      ctx = g_new0 (ParseContext, 1);
+      ctx->state = STATE_START;
+      ctx->self = GTK_UI_MANAGER (buildable);
+      ctx->current = NULL;
+      ctx->merge_id = gtk_ui_manager_new_merge_id (GTK_UI_MANAGER (buildable));
+
+      *data = ctx;
+      *parser = ui_parser;
+
+      return TRUE;
+    }
+
+  return FALSE;
+
+}
+
+static void
+gtk_ui_manager_buildable_custom_tag_end (GtkBuildable *buildable,
+                                        GtkBuilder   *builder,
+                                        GObject      *child,
+                                        const gchar  *tagname,
+                                        gpointer     *data)
+{
+  queue_update (GTK_UI_MANAGER (buildable));
+  g_object_notify (G_OBJECT (buildable), "ui");
+  g_free (data);
 }
 
 /**
@@ -2848,7 +3053,7 @@ gtk_ui_manager_get_ui (GtkUIManager *self)
   return g_string_free (buffer, FALSE);
 }
 
-#ifdef G_OS_WIN32
+#if defined (G_OS_WIN32) && !defined (_WIN64)
 
 #undef gtk_ui_manager_add_ui_from_file