#include <config.h>
#include <string.h>
+#include "gtkbuildable.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 "gtkprivate.h"
+#include "gtkalias.h"
#undef DEBUG_UI_MANAGER
GList *uifiles;
guint dirty : 1;
+ guint expand : 1; /* used for separators */
};
#define GTK_UI_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_UI_MANAGER, GtkUIManagerPrivate))
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,
- const GValue *value,
- GParamSpec *pspec);
-static void gtk_ui_manager_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-static void queue_update (GtkUIManager *self);
-static void dirty_all_nodes (GtkUIManager *self);
-static GNode * get_child_node (GtkUIManager *self,
- GNode *parent,
- const gchar *childname,
- gint childname_length,
- NodeType node_type,
- gboolean create,
- gboolean top);
-static GNode * get_node (GtkUIManager *self,
- const gchar *path,
- NodeType node_type,
- gboolean create);
-static gboolean free_node (GNode *node);
-static void node_prepend_ui_reference (Node *node,
- guint merge_id,
- GQuark action_quark);
-static void node_remove_ui_reference (Node *node,
- guint merge_id);
+static void gtk_ui_manager_finalize (GObject *object);
+static void gtk_ui_manager_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void gtk_ui_manager_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+static GtkWidget * gtk_ui_manager_real_get_widget (GtkUIManager *manager,
+ const gchar *path);
+static GtkAction * gtk_ui_manager_real_get_action (GtkUIManager *manager,
+ const gchar *path);
+static void queue_update (GtkUIManager *self);
+static void dirty_all_nodes (GtkUIManager *self);
+static void mark_node_dirty (GNode *node);
+static GNode * get_child_node (GtkUIManager *self,
+ GNode *parent,
+ GNode *sibling,
+ const gchar *childname,
+ gint childname_length,
+ NodeType node_type,
+ gboolean create,
+ gboolean top);
+static GNode * get_node (GtkUIManager *self,
+ const gchar *path,
+ NodeType node_type,
+ gboolean create);
+static gboolean free_node (GNode *node);
+static void node_prepend_ui_reference (GNode *node,
+ guint merge_id,
+ GQuark action_quark);
+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
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;
-
+ klass->get_widget = gtk_ui_manager_real_get_widget;
+ klass->get_action = gtk_ui_manager_real_get_action;
+
/**
* GtkUIManager:add-tearoffs:
*
*/
g_object_class_install_property (gobject_class,
PROP_ADD_TEAROFFS,
- g_param_spec_boolean ("add_tearoffs",
+ g_param_spec_boolean ("add-tearoffs",
P_("Add tearoffs to menus"),
P_("Whether tearoff menu items should be added to menus"),
FALSE,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_UI,
g_param_spec_string ("ui",
P_("Merged UI definition"),
P_("An XML string describing the merged UI"),
- NULL,
- G_PARAM_READABLE));
+ "<ui>\n</ui>\n",
+ GTK_PARAM_READABLE));
/**
* 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),
* 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),
G_TYPE_NONE, 0);
/**
- * GtkUIManager::connect_proxy:
+ * GtkUIManager::connect-proxy:
* @uimanager: the ui manager
* @action: the action
* @proxy: the proxy
* 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),
GTK_TYPE_WIDGET);
/**
- * GtkUIManager::disconnect_proxy:
+ * GtkUIManager::disconnect-proxy:
* @uimanager: the ui manager
* @action: the action
* @proxy: the proxy
* 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),
GTK_TYPE_WIDGET);
/**
- * GtkUIManager::pre_activate:
+ * GtkUIManager::pre-activate:
* @uimanager: the ui manager
* @action: the action
*
* 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),
GTK_TYPE_ACTION);
/**
- * GtkUIManager::post_activate:
+ * GtkUIManager::post-activate:
* @uimanager: the ui manager
* @action: the action
*
* 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),
self->private_data->add_tearoffs = FALSE;
merge_id = gtk_ui_manager_new_merge_id (self);
- node = get_child_node (self, NULL, "ui", 2,
+ node = get_child_node (self, NULL, NULL, "ui", 2,
NODE_TYPE_ROOT, TRUE, FALSE);
- node_prepend_ui_reference (NODE_INFO (node), merge_id, 0);
+ node_prepend_ui_reference (node, merge_id, 0);
}
static void
g_node_traverse (self->private_data->root_node,
G_POST_ORDER, G_TRAVERSE_ALL, -1,
- (GNodeTraverseFunc)free_node, 0);
+ (GNodeTraverseFunc)free_node, NULL);
g_node_destroy (self->private_data->root_node);
self->private_data->root_node = NULL;
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
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);
}
}
+static GtkWidget *
+gtk_ui_manager_real_get_widget (GtkUIManager *self,
+ const gchar *path)
+{
+ GNode *node;
+
+ /* ensure that there are no pending updates before we get the
+ * widget */
+ gtk_ui_manager_ensure_update (self);
+
+ node = get_node (self, path, NODE_TYPE_UNDECIDED, FALSE);
+
+ if (node == NULL)
+ return NULL;
+
+ return NODE_INFO (node)->proxy;
+}
+
+static GtkAction *
+gtk_ui_manager_real_get_action (GtkUIManager *self,
+ const gchar *path)
+{
+ GNode *node;
+
+ /* ensure that there are no pending updates before we get
+ * the action */
+ gtk_ui_manager_ensure_update (self);
+
+ node = get_node (self, path, NODE_TYPE_UNDECIDED, FALSE);
+
+ if (node == NULL)
+ return NULL;
+
+ return NODE_INFO (node)->action;
+}
+
/**
* gtk_ui_manager_new:
dirty_all_nodes (self);
- g_object_notify (G_OBJECT (self), "add_tearoffs");
+ g_object_notify (G_OBJECT (self), "add-tearoffs");
}
}
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);
* separated by '/'. Elements which don't have a name or action attribute in
* the XML (e.g. <popup>) can be addressed by their XML element name
* (e.g. "popup"). The root element ("/ui") can be omitted in the path.
+ *
+ * Note that the widget found by following a path that ends in a <menu>
+ * element is the menuitem to which the menu is attached, not the menu itself.
+ *
+ * Also note that the widgets constructed by a ui manager are not tied to
+ * 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
* was found.
* Since: 2.4
**/
GtkWidget *
-gtk_ui_manager_get_widget (GtkUIManager *self,
+gtk_ui_manager_get_widget (GtkUIManager *self,
const gchar *path)
{
- GNode *node;
-
g_return_val_if_fail (GTK_IS_UI_MANAGER (self), NULL);
g_return_val_if_fail (path != NULL, NULL);
- /* ensure that there are no pending updates before we get the
- * widget */
- gtk_ui_manager_ensure_update (self);
-
- if (strncmp ("/ui", path, 3) == 0)
- path += 3;
- node = get_node (self, path, NODE_TYPE_UNDECIDED, FALSE);
-
- if (node == NULL)
- return NULL;
-
- if (NODE_INFO (node)->type == NODE_TYPE_MENU)
- {
- GtkWidget *proxy = NODE_INFO (node)->proxy;
-
- return gtk_menu_item_get_submenu (GTK_MENU_ITEM (proxy));
- }
- else
- return NODE_INFO (node)->proxy;
+ 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: ;
+ }
+ }
}
/**
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 |
GTK_UI_MANAGER_TOOLBAR |
GTK_UI_MANAGER_POPUP) & types) == 0, NULL);
*
* Since: 2.4
**/
-GtkAction *
+GtkAction *
gtk_ui_manager_get_action (GtkUIManager *self,
const gchar *path)
{
- GNode *node;
-
g_return_val_if_fail (GTK_IS_UI_MANAGER (self), NULL);
g_return_val_if_fail (path != NULL, NULL);
-
- /* ensure that there are no pending updates before we get
- * the action */
- gtk_ui_manager_ensure_update (self);
-
- node = get_node (self, path, NODE_TYPE_UNDECIDED, FALSE);
-
- if (node == NULL)
- return NULL;
- return NODE_INFO (node)->action;
+ return GTK_UI_MANAGER_GET_CLASS (self)->get_action (self, path);
}
static GNode *
get_child_node (GtkUIManager *self,
GNode *parent,
+ GNode *sibling,
const gchar *childname,
gint childname_length,
NodeType node_type,
{
GNode *child = NULL;
- g_return_val_if_fail (parent == NULL ||
- (NODE_INFO (parent)->type != NODE_TYPE_MENUITEM &&
- NODE_INFO (parent)->type != NODE_TYPE_TOOLITEM),
- NULL);
-
if (parent)
{
if (childname)
{
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;
- if (top)
- child = g_node_prepend_data (parent, mnode);
+ if (sibling)
+ {
+ if (top)
+ child = g_node_insert_before (parent, sibling,
+ g_node_new (mnode));
+ else
+ child = g_node_insert_after (parent, sibling,
+ g_node_new (mnode));
+ }
else
- child = g_node_append_data (parent, mnode);
+ {
+ if (top)
+ child = g_node_prepend_data (parent, mnode);
+ else
+ child = g_node_append_data (parent, mnode);
+ }
+
+ mark_node_dirty (child);
}
}
else
{
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;
const gchar *pos, *end;
GNode *parent, *node;
+ if (strncmp ("/ui", path, 3) == 0)
+ path += 3;
+
end = path + strlen (path);
pos = path;
parent = node = NULL;
else
length = strlen (pos);
- node = get_child_node (self, parent, pos, length, NODE_TYPE_UNDECIDED,
+ node = get_child_node (self, parent, NULL, pos, length, NODE_TYPE_UNDECIDED,
create, FALSE);
if (!node)
return NULL;
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)
g_object_unref (info->action);
+ if (info->proxy)
+ g_object_unref (info->proxy);
+ 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;
}
}
static void
-node_prepend_ui_reference (Node *node,
+node_prepend_ui_reference (GNode *gnode,
guint merge_id,
GQuark action_quark)
{
- NodeUIReference *reference;
+ Node *node = NODE_INFO (gnode);
+ NodeUIReference *reference = NULL;
- reference = g_new (NodeUIReference, 1);
- reference->action_quark = action_quark;
- reference->merge_id = merge_id;
+ if (node->uifiles &&
+ ((NodeUIReference *)node->uifiles->data)->merge_id == merge_id)
+ reference = node->uifiles->data;
+ else
+ {
+ reference = g_slice_new (NodeUIReference);
+ node->uifiles = g_list_prepend (node->uifiles, reference);
+ }
- /* Prepend the reference */
- node->uifiles = g_list_prepend (node->uifiles, reference);
+ reference->merge_id = merge_id;
+ reference->action_quark = action_quark;
- node->dirty = TRUE;
+ mark_node_dirty (gnode);
}
static void
-node_remove_ui_reference (Node *node,
+node_remove_ui_reference (GNode *gnode,
guint merge_id)
{
+ Node *node = NODE_INFO (gnode);
GList *p;
for (p = node->uifiles; p != NULL; p = p->next)
if (reference->merge_id == merge_id)
{
+ if (p == node->uifiles)
+ mark_node_dirty (gnode);
node->uifiles = g_list_delete_link (node->uifiles, p);
- node->dirty = TRUE;
- g_free (reference);
+ g_slice_free (NodeUIReference, reference);
break;
}
const gchar *action;
GQuark action_quark;
gboolean top;
+ gboolean expand = FALSE;
gboolean raise_error = TRUE;
{
top = !strcmp (attribute_values[i], "top");
}
+ else if (!strcmp (attribute_names[i], "expand"))
+ {
+ expand = !strcmp (attribute_values[i], "true");
+ }
else
{
gint line_number, char_number;
if (ctx->state == STATE_ROOT && !strcmp (element_name, "accelerator"))
{
ctx->state = STATE_ACCELERATOR;
- ctx->current = get_child_node (self, ctx->current,
+ ctx->current = get_child_node (self, ctx->current, NULL,
node_name, strlen (node_name),
NODE_TYPE_ACCELERATOR,
TRUE, FALSE);
if (NODE_INFO (ctx->current)->action_name == 0)
NODE_INFO (ctx->current)->action_name = action_quark;
- node_prepend_ui_reference (NODE_INFO (ctx->current),
- ctx->merge_id, action_quark);
- NODE_INFO (ctx->current)->dirty = TRUE;
+ node_prepend_ui_reference (ctx->current, ctx->merge_id, action_quark);
raise_error = FALSE;
}
ctx->current = self->private_data->root_node;
raise_error = FALSE;
- node_prepend_ui_reference (NODE_INFO (ctx->current),
- ctx->merge_id, action_quark);
+ node_prepend_ui_reference (ctx->current, ctx->merge_id, action_quark);
}
break;
case 'm':
if (ctx->state == STATE_ROOT && !strcmp (element_name, "menubar"))
{
ctx->state = STATE_MENU;
- ctx->current = get_child_node (self, ctx->current,
+ ctx->current = get_child_node (self, ctx->current, NULL,
node_name, strlen (node_name),
NODE_TYPE_MENUBAR,
TRUE, FALSE);
if (NODE_INFO (ctx->current)->action_name == 0)
NODE_INFO (ctx->current)->action_name = action_quark;
- node_prepend_ui_reference (NODE_INFO (ctx->current),
- ctx->merge_id, action_quark);
- NODE_INFO (ctx->current)->dirty = TRUE;
+ node_prepend_ui_reference (ctx->current, ctx->merge_id, action_quark);
+ mark_node_dirty (ctx->current);
raise_error = FALSE;
}
else if (ctx->state == STATE_MENU && !strcmp (element_name, "menu"))
{
- ctx->current = get_child_node (self, ctx->current,
+ ctx->current = get_child_node (self, ctx->current, NULL,
+ node_name, strlen (node_name),
+ NODE_TYPE_MENU,
+ TRUE, top);
+ if (NODE_INFO (ctx->current)->action_name == 0)
+ NODE_INFO (ctx->current)->action_name = action_quark;
+
+ node_prepend_ui_reference (ctx->current, ctx->merge_id, action_quark);
+
+ raise_error = FALSE;
+ }
+ else if (ctx->state == STATE_TOOLITEM && !strcmp (element_name, "menu"))
+ {
+ ctx->state = STATE_MENU;
+
+ ctx->current = get_child_node (self, g_node_last_child (ctx->current), NULL,
node_name, strlen (node_name),
NODE_TYPE_MENU,
TRUE, top);
if (NODE_INFO (ctx->current)->action_name == 0)
NODE_INFO (ctx->current)->action_name = action_quark;
- node_prepend_ui_reference (NODE_INFO (ctx->current),
- ctx->merge_id, action_quark);
- NODE_INFO (ctx->current)->dirty = TRUE;
+ node_prepend_ui_reference (ctx->current, ctx->merge_id, action_quark);
raise_error = FALSE;
}
GNode *node;
ctx->state = STATE_MENUITEM;
- node = get_child_node (self, ctx->current,
+ node = get_child_node (self, ctx->current, NULL,
node_name, strlen (node_name),
NODE_TYPE_MENUITEM,
TRUE, top);
if (NODE_INFO (node)->action_name == 0)
NODE_INFO (node)->action_name = action_quark;
- node_prepend_ui_reference (NODE_INFO (node),
- ctx->merge_id, action_quark);
- NODE_INFO (node)->dirty = TRUE;
+ node_prepend_ui_reference (node, ctx->merge_id, action_quark);
raise_error = FALSE;
}
if (ctx->state == STATE_ROOT && !strcmp (element_name, "popup"))
{
ctx->state = STATE_MENU;
- ctx->current = get_child_node (self, ctx->current,
+ ctx->current = get_child_node (self, ctx->current, NULL,
node_name, strlen (node_name),
NODE_TYPE_POPUP,
TRUE, FALSE);
if (NODE_INFO (ctx->current)->action_name == 0)
NODE_INFO (ctx->current)->action_name = action_quark;
- node_prepend_ui_reference (NODE_INFO (ctx->current),
- ctx->merge_id, action_quark);
- NODE_INFO (ctx->current)->dirty = TRUE;
+ node_prepend_ui_reference (ctx->current, ctx->merge_id, action_quark);
raise_error = FALSE;
}
!strcmp (element_name, "placeholder"))
{
if (ctx->state == STATE_TOOLBAR)
- ctx->current = get_child_node (self, ctx->current,
+ ctx->current = get_child_node (self, ctx->current, NULL,
node_name, strlen (node_name),
NODE_TYPE_TOOLBAR_PLACEHOLDER,
TRUE, top);
else
- ctx->current = get_child_node (self, ctx->current,
+ ctx->current = get_child_node (self, ctx->current, NULL,
node_name, strlen (node_name),
NODE_TYPE_MENU_PLACEHOLDER,
TRUE, top);
- node_prepend_ui_reference (NODE_INFO (ctx->current),
- ctx->merge_id, action_quark);
- NODE_INFO (ctx->current)->dirty = TRUE;
+ node_prepend_ui_reference (ctx->current, ctx->merge_id, action_quark);
raise_error = FALSE;
}
if (!strcmp (node_name, "separator"))
{
node_name = NULL;
- length = -1;
+ length = 0;
}
else
length = strlen (node_name);
- node = get_child_node (self, ctx->current,
+ node = get_child_node (self, ctx->current, NULL,
node_name, length,
NODE_TYPE_SEPARATOR,
TRUE, top);
+ NODE_INFO (node)->expand = expand;
+
if (NODE_INFO (node)->action_name == 0)
NODE_INFO (node)->action_name = action_quark;
- node_prepend_ui_reference (NODE_INFO (node),
- ctx->merge_id, action_quark);
- NODE_INFO (node)->dirty = TRUE;
+ node_prepend_ui_reference (node, ctx->merge_id, action_quark);
raise_error = FALSE;
}
if (ctx->state == STATE_ROOT && !strcmp (element_name, "toolbar"))
{
ctx->state = STATE_TOOLBAR;
- ctx->current = get_child_node (self, ctx->current,
+ ctx->current = get_child_node (self, ctx->current, NULL,
node_name, strlen (node_name),
NODE_TYPE_TOOLBAR,
TRUE, FALSE);
if (NODE_INFO (ctx->current)->action_name == 0)
NODE_INFO (ctx->current)->action_name = action_quark;
- node_prepend_ui_reference (NODE_INFO (ctx->current),
- ctx->merge_id, action_quark);
- NODE_INFO (ctx->current)->dirty = TRUE;
+ node_prepend_ui_reference (ctx->current, ctx->merge_id, action_quark);
raise_error = FALSE;
}
GNode *node;
ctx->state = STATE_TOOLITEM;
- node = get_child_node (self, ctx->current,
+ node = get_child_node (self, ctx->current, NULL,
node_name, strlen (node_name),
NODE_TYPE_TOOLITEM,
TRUE, top);
if (NODE_INFO (node)->action_name == 0)
NODE_INFO (node)->action_name = action_quark;
- node_prepend_ui_reference (NODE_INFO (node),
- ctx->merge_id, action_quark);
- NODE_INFO (node)->dirty = TRUE;
+ node_prepend_ui_reference (node, ctx->merge_id, action_quark);
raise_error = FALSE;
}
ctx->current = ctx->current->parent;
if (NODE_INFO (ctx->current)->type == NODE_TYPE_ROOT)
ctx->state = STATE_ROOT;
+ else if (NODE_INFO (ctx->current)->type == NODE_TYPE_TOOLITEM)
+ {
+ ctx->current = ctx->current->parent;
+ ctx->state = STATE_TOOLITEM;
+ }
/* else, stay in same state */
break;
case STATE_MENUITEM:
}
-static GMarkupParser ui_parser = {
+static const GMarkupParser ui_parser = {
start_element_handler,
end_element_handler,
text_handler,
queue_update (self);
- g_object_notify (G_OBJECT (self), "ui");
+ g_object_notify (G_OBJECT (self), "ui");
return ctx.merge_id;
* separator if such an element can be inserted at the place determined by
* @path. Otherwise @type must indicate an element that can be inserted at
* the place determined by @path.
+ *
+ * If @path points to a menuitem or toolitem, the new element will be inserted
+ * before or after this item, depending on @top.
*
* Since: 2.4
**/
gboolean top)
{
GNode *node;
+ GNode *sibling;
GNode *child;
NodeType node_type;
GQuark action_quark = 0;
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;
+
if (node == NULL)
return;
node_type = NODE_TYPE_UNDECIDED;
+ reswitch:
switch (NODE_INFO (node)->type)
{
+ case NODE_TYPE_SEPARATOR:
+ case NODE_TYPE_MENUITEM:
+ case NODE_TYPE_TOOLITEM:
+ sibling = node;
+ node = node->parent;
+ goto reswitch;
case NODE_TYPE_MENUBAR:
case NODE_TYPE_MENU:
case NODE_TYPE_POPUP:
node_type = NODE_TYPE_SEPARATOR;
break;
case GTK_UI_MANAGER_PLACEHOLDER:
- node_type = NODE_TYPE_MENU_PLACEHOLDER;
+ node_type = NODE_TYPE_TOOLBAR_PLACEHOLDER;
break;
default: ;
/* do nothing */
}
if (node_type == NODE_TYPE_UNDECIDED)
- return;
+ {
+ g_warning ("item type %d not suitable for adding at '%s'",
+ type, path);
+ return;
+ }
- child = get_child_node (self, node,
- name, strlen (name),
+ child = get_child_node (self, node, sibling,
+ name, name ? strlen (name) : 0,
node_type, TRUE, top);
if (action != NULL)
action_quark = g_quark_from_string (action);
- node_prepend_ui_reference (NODE_INFO (child),
- merge_id, action_quark);
+ node_prepend_ui_reference (child, merge_id, action_quark);
- if (NODE_INFO (node)->action_name == 0)
+ if (NODE_INFO (child)->action_name == 0)
NODE_INFO (child)->action_name = action_quark;
- NODE_INFO (child)->dirty = TRUE;
-
queue_update (self);
g_object_notify (G_OBJECT (self), "ui");
{
guint merge_id = GPOINTER_TO_UINT (user_data);
- node_remove_ui_reference (NODE_INFO (node), merge_id);
+ node_remove_ui_reference (node, merge_id);
return FALSE; /* continue */
}
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));
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)
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;
}
}
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;
}
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)
{
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)
_gtk_menu_is_empty (GtkWidget *menu)
{
GList *children, *cur;
+ gboolean result = TRUE;
g_return_val_if_fail (menu == NULL || GTK_IS_MENU (menu), TRUE);
{
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 {
SEPARATOR_MODE_HIDDEN
};
-void _gtk_action_sync_menu_visible (GtkAction *action,
- GtkWidget *proxy,
- gboolean empty);
-
static void
update_smart_separators (GtkWidget *proxy)
{
else if (GTK_IS_MENU_ITEM (proxy) || GTK_IS_TOOL_ITEM (proxy))
parent = gtk_widget_get_parent (proxy);
-
if (parent)
{
gboolean visible;
gboolean empty;
GList *children, *cur, *last;
GtkWidget *filler;
- gint i;
children = gtk_container_get_children (GTK_CONTAINER (parent));
empty = TRUE;
filler = NULL;
- i = 0;
cur = children;
while (cur)
{
if (g_object_get_data (cur->data, "gtk-empty-menu-item"))
- filler = cur->data;
-
- if (GTK_IS_SEPARATOR_MENU_ITEM (cur->data) ||
- GTK_IS_SEPARATOR_TOOL_ITEM (cur->data))
+ {
+ filler = cur->data;
+ }
+ else if (GTK_IS_SEPARATOR_MENU_ITEM (cur->data) ||
+ GTK_IS_SEPARATOR_TOOL_ITEM (cur->data))
{
gint mode =
GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cur->data),
if (GTK_IS_MENU_ITEM (item))
_gtk_action_sync_menu_visible (NULL, item, empty);
if (GTK_IS_WIDGET (filler))
- g_object_set (G_OBJECT (filler), "visible", empty, NULL);
+ {
+ if (empty)
+ gtk_widget_show (filler);
+ else
+ gtk_widget_hide (filler);
+ }
}
g_list_free (children);
Node *info;
GNode *child;
GtkAction *action;
- gchar *tooltip;
+ const gchar *action_name;
+ NodeUIReference *ref;
+
#ifdef DEBUG_UI_MANAGER
GList *tmp;
#endif
-
+
g_return_if_fail (node != NULL);
g_return_if_fail (NODE_INFO (node) != NULL);
info = NODE_INFO (node);
+
+ if (!info->dirty)
+ return;
in_popup = in_popup || (info->type == NODE_TYPE_POPUP);
g_print (")\n");
#endif
- if (info->dirty)
+ if (info->uifiles == NULL) {
+ /* We may need to remove this node.
+ * This must be done in post order
+ */
+ goto recurse_children;
+ }
+
+ ref = info->uifiles->data;
+ action_name = g_quark_to_string (ref->action_quark);
+ action = get_action_by_name (self, action_name);
+
+ info->dirty = FALSE;
+
+ /* Check if the node doesn't have an action and must have an action */
+ if (action == NULL &&
+ info->type != NODE_TYPE_ROOT &&
+ info->type != NODE_TYPE_MENUBAR &&
+ info->type != NODE_TYPE_TOOLBAR &&
+ info->type != NODE_TYPE_POPUP &&
+ info->type != NODE_TYPE_SEPARATOR &&
+ info->type != NODE_TYPE_MENU_PLACEHOLDER &&
+ info->type != NODE_TYPE_TOOLBAR_PLACEHOLDER)
{
- const gchar *action_name;
- NodeUIReference *ref;
-
- if (info->uifiles == NULL) {
- /* We may need to remove this node.
- * This must be done in post order
- */
- goto recurse_children;
- }
-
- ref = info->uifiles->data;
- action_name = g_quark_to_string (ref->action_quark);
- action = get_action_by_name (self, action_name);
-
- info->dirty = FALSE;
-
- /* Check if the node doesn't have an action and must have an action */
- if (action == NULL &&
- info->type != NODE_TYPE_ROOT &&
- info->type != NODE_TYPE_MENUBAR &&
- info->type != NODE_TYPE_TOOLBAR &&
- info->type != NODE_TYPE_POPUP &&
- info->type != NODE_TYPE_SEPARATOR &&
- info->type != NODE_TYPE_MENU_PLACEHOLDER &&
- info->type != NODE_TYPE_TOOLBAR_PLACEHOLDER)
- {
- g_warning ("%s: missing action", info->name);
-
- goto recurse_children;
- }
-
- if (action)
- gtk_action_set_accel_group (action, self->private_data->accel_group);
-
- /* If the widget already has a proxy and the action hasn't changed, then
- * we only have to update the tearoff menu items.
- */
- if (info->proxy != NULL && action == info->action)
+ g_warning ("%s: missing action %s", info->name, action_name);
+
+ return;
+ }
+
+ if (action)
+ gtk_action_set_accel_group (action, self->private_data->accel_group);
+
+ /* If the widget already has a proxy and the action hasn't changed, then
+ * we only have to update the tearoff menu items.
+ */
+ if (info->proxy != NULL && action == info->action)
+ {
+ if (info->type == NODE_TYPE_MENU)
{
- if (info->type == NODE_TYPE_MENU)
+ GtkWidget *menu;
+ GList *siblings;
+
+ if (GTK_IS_MENU (info->proxy))
+ 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))
{
- GtkWidget *menu;
- GList *siblings;
-
- 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))
- g_object_set (G_OBJECT (siblings->data),
- "visible", self->private_data->add_tearoffs && !in_popup,
- NULL);
- g_list_free (siblings);
+ if (self->private_data->add_tearoffs && !in_popup)
+ gtk_widget_show (GTK_WIDGET (siblings->data));
+ else
+ gtk_widget_hide (GTK_WIDGET (siblings->data));
}
-
- goto recurse_children;
+ g_list_free (siblings);
}
- switch (info->type)
+ goto recurse_children;
+ }
+
+ switch (info->type)
+ {
+ case NODE_TYPE_MENUBAR:
+ if (info->proxy == NULL)
{
- case NODE_TYPE_MENUBAR:
- if (info->proxy == NULL)
- {
- info->proxy = gtk_menu_bar_new ();
- 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);
- }
- break;
- case NODE_TYPE_POPUP:
- if (info->proxy == NULL)
- info->proxy = gtk_menu_new ();
+ info->proxy = gtk_menu_bar_new ();
+ g_object_ref_sink (info->proxy);
gtk_widget_set_name (info->proxy, info->name);
- break;
- case NODE_TYPE_MENU:
+ gtk_widget_show (info->proxy);
+ g_signal_emit (self, ui_manager_signals[ADD_WIDGET], 0, info->proxy);
+ }
+ break;
+ case NODE_TYPE_POPUP:
+ if (info->proxy == NULL)
+ {
+ info->proxy = gtk_menu_new ();
+ 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 = 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)
{
- GtkWidget *prev_submenu = NULL;
- GtkWidget *menu;
- 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)
+ if (GTK_IS_MENU_ITEM (info->proxy))
{
prev_submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (info->proxy));
if (prev_submenu)
{
g_object_ref (prev_submenu);
gtk_menu_item_set_submenu (GTK_MENU_ITEM (info->proxy), NULL);
- }
- gtk_action_disconnect_proxy (info->action, info->proxy);
- gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
- info->proxy);
- info->proxy = NULL;
+ }
}
- /* create proxy if needed ... */
- if (info->proxy == NULL)
+
+ gtk_action_disconnect_proxy (info->action, info->proxy);
+ 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)
+ {
+ /* ... 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)
+ {
+ 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;
if (find_menu_position (node, &menushell, &pos))
- {
- GtkWidget *tearoff;
- GtkWidget *filler;
-
- info->proxy = gtk_action_create_menu_item (action);
- menu = gtk_menu_new ();
- gtk_widget_set_name (info->proxy, info->name);
- 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);
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (info->proxy), menu);
- gtk_menu_shell_insert (GTK_MENU_SHELL (menushell), info->proxy, 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);
+
+ if (prev_submenu)
+ {
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (info->proxy),
+ prev_submenu);
+ g_object_unref (prev_submenu);
+ }
+
+ if (GTK_IS_MENU (info->proxy))
+ 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))
+ {
+ if (self->private_data->add_tearoffs && !in_popup)
+ gtk_widget_show (GTK_WIDGET (siblings->data));
else
- gtk_action_connect_proxy (action, info->proxy);
-
- if (prev_submenu)
- {
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (info->proxy),
- prev_submenu);
- g_object_unref (prev_submenu);
- }
- 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))
- g_object_set (G_OBJECT (siblings->data),
- "visible", self->private_data->add_tearoffs && !in_popup,
- NULL);
- g_list_free (siblings);
+ gtk_widget_hide (GTK_WIDGET (siblings->data));
}
- break;
- case NODE_TYPE_UNDECIDED:
- g_warning ("found undecided node!");
- break;
- case NODE_TYPE_ROOT:
- break;
- case NODE_TYPE_TOOLBAR:
- if (info->proxy == NULL)
- {
- info->proxy = gtk_toolbar_new ();
- 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);
- }
- break;
- case NODE_TYPE_MENU_PLACEHOLDER:
- /* create menu items for placeholders if necessary ... */
- if (!GTK_IS_SEPARATOR_MENU_ITEM (info->proxy) ||
- !GTK_IS_SEPARATOR_MENU_ITEM (info->extra))
- {
- if (info->proxy)
- {
- gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
- info->proxy);
- info->proxy = NULL;
- }
- if (info->extra)
- {
- gtk_container_remove (GTK_CONTAINER (info->extra->parent),
- info->extra);
- info->extra = NULL;
- }
- }
- if (info->proxy == NULL)
- {
- GtkWidget *menushell;
- gint pos;
-
- if (find_menu_position (node, &menushell, &pos))
- {
- info->proxy = gtk_separator_menu_item_new ();
- g_object_set_data (G_OBJECT (info->proxy),
- "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);
-
- info->extra = gtk_separator_menu_item_new ();
- g_object_set_data (G_OBJECT (info->extra),
- "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);
- }
- }
- break;
- case NODE_TYPE_TOOLBAR_PLACEHOLDER:
- /* create toolbar items for placeholders if necessary ... */
- if (!GTK_IS_SEPARATOR_TOOL_ITEM (info->proxy) ||
- !GTK_IS_SEPARATOR_TOOL_ITEM (info->extra))
+ g_list_free (siblings);
+ }
+ break;
+ case NODE_TYPE_UNDECIDED:
+ g_warning ("found undecided node!");
+ break;
+ case NODE_TYPE_ROOT:
+ break;
+ case NODE_TYPE_TOOLBAR:
+ if (info->proxy == NULL)
+ {
+ info->proxy = gtk_toolbar_new ();
+ 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);
+ }
+ break;
+ case NODE_TYPE_MENU_PLACEHOLDER:
+ /* create menu items for placeholders if necessary ... */
+ if (!GTK_IS_SEPARATOR_MENU_ITEM (info->proxy) ||
+ !GTK_IS_SEPARATOR_MENU_ITEM (info->extra))
+ {
+ if (info->proxy)
{
- if (info->proxy)
- {
- gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
- info->proxy);
- info->proxy = NULL;
- }
- if (info->extra)
- {
- gtk_container_remove (GTK_CONTAINER (info->extra->parent),
- info->extra);
- info->extra = NULL;
- }
+ gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
+ info->proxy);
+ g_object_unref (info->proxy);
+ info->proxy = NULL;
}
- if (info->proxy == NULL)
+ if (info->extra)
{
- GtkWidget *toolbar;
- gint pos;
-
- 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_set_data (G_OBJECT (info->proxy),
- "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_set_data (G_OBJECT (info->extra),
- "gtk-separator-mode",
- GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN));
- gtk_widget_set_no_show_all (info->extra, TRUE);
- }
+ gtk_container_remove (GTK_CONTAINER (info->extra->parent),
+ info->extra);
+ g_object_unref (info->extra);
+ info->extra = NULL;
}
- break;
- case NODE_TYPE_MENUITEM:
- /* 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)
+ }
+ if (info->proxy == NULL)
+ {
+ GtkWidget *menushell;
+ gint pos;
+
+ if (find_menu_position (node, &menushell, &pos))
+ {
+ info->proxy = gtk_separator_menu_item_new ();
+ g_object_ref_sink (info->proxy);
+ g_object_set_data (G_OBJECT (info->proxy),
+ 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);
+
+ info->extra = gtk_separator_menu_item_new ();
+ g_object_ref_sink (info->extra);
+ g_object_set_data (G_OBJECT (info->extra),
+ 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);
+ }
+ }
+ break;
+ case NODE_TYPE_TOOLBAR_PLACEHOLDER:
+ /* create toolbar items for placeholders if necessary ... */
+ if (!GTK_IS_SEPARATOR_TOOL_ITEM (info->proxy) ||
+ !GTK_IS_SEPARATOR_TOOL_ITEM (info->extra))
+ {
+ if (info->proxy)
{
- g_signal_handlers_disconnect_by_func (info->proxy,
- G_CALLBACK (update_smart_separators),
- 0);
- gtk_action_disconnect_proxy (info->action, info->proxy);
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 (find_menu_position (node, &menushell, &pos))
- {
- info->proxy = gtk_action_create_menu_item (action);
- gtk_widget_set_name (info->proxy, info->name);
-
- gtk_menu_shell_insert (GTK_MENU_SHELL (menushell),
- info->proxy, pos);
- }
- }
- else
+ if (info->extra)
{
- g_signal_handlers_disconnect_by_func (info->proxy,
- G_CALLBACK (update_smart_separators),
- 0);
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (info->proxy), NULL);
- gtk_action_connect_proxy (action, info->proxy);
+ gtk_container_remove (GTK_CONTAINER (info->extra->parent),
+ info->extra);
+ g_object_unref (info->extra);
+ info->extra = NULL;
}
- g_signal_connect (info->proxy, "notify::visible",
- G_CALLBACK (update_smart_separators), 0);
- if (in_popup)
+ }
+ if (info->proxy == NULL)
+ {
+ GtkWidget *toolbar;
+ gint pos;
+ GtkToolItem *item;
+
+ if (find_toolbar_position (node, &toolbar, &pos))
+ {
+ item = gtk_separator_tool_item_new ();
+ gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, pos);
+ info->proxy = GTK_WIDGET (item);
+ g_object_ref_sink (info->proxy);
+ g_object_set_data (G_OBJECT (info->proxy),
+ 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_sink (info->extra);
+ g_object_set_data (G_OBJECT (info->extra),
+ I_("gtk-separator-mode"),
+ GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN));
+ gtk_widget_set_no_show_all (info->extra, TRUE);
+ }
+ }
+ break;
+ case NODE_TYPE_MENUITEM:
+ /* 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)
+ {
+ g_signal_handlers_disconnect_by_func (info->proxy,
+ G_CALLBACK (update_smart_separators),
+ NULL);
+ gtk_action_disconnect_proxy (info->action, info->proxy);
+ 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 (find_menu_position (node, &menushell, &pos))
+ {
+ info->proxy = gtk_action_create_menu_item (action);
+ g_object_ref_sink (info->proxy);
+ gtk_widget_set_name (info->proxy, info->name);
+
+ gtk_menu_shell_insert (GTK_MENU_SHELL (menushell),
+ info->proxy, pos);
+ }
+ }
+ else
+ {
+ g_signal_handlers_disconnect_by_func (info->proxy,
+ G_CALLBACK (update_smart_separators),
+ NULL);
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (info->proxy), NULL);
+ gtk_action_connect_proxy (action, info->proxy);
+ }
+
+ if (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 (G_OBJECT (label),
- "accel_closure", NULL,
- NULL);
+ g_object_set (label, "accel-closure", NULL, NULL);
}
+ }
+
+ break;
+ case NODE_TYPE_TOOLITEM:
+ /* remove the proxy if it is of the wrong type ... */
+ if (info->proxy &&
+ G_OBJECT_TYPE (info->proxy) != GTK_ACTION_GET_CLASS (action)->toolbar_item_type)
+ {
+ g_signal_handlers_disconnect_by_func (info->proxy,
+ G_CALLBACK (update_smart_separators),
+ NULL);
+ gtk_action_disconnect_proxy (info->action, info->proxy);
+ 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 *toolbar;
+ gint pos;
+
+ if (find_toolbar_position (node, &toolbar, &pos))
+ {
+ info->proxy = gtk_action_create_tool_item (action);
+ 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);
+ }
+ }
+ else
+ {
+ g_signal_handlers_disconnect_by_func (info->proxy,
+ G_CALLBACK (update_smart_separators),
+ NULL);
+ gtk_action_connect_proxy (action, info->proxy);
+ }
- break;
- case NODE_TYPE_TOOLITEM:
- /* remove the proxy if it is of the wrong type ... */
- if (info->proxy && G_OBJECT_TYPE (info->proxy) !=
- GTK_ACTION_GET_CLASS (action)->toolbar_item_type)
+ 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 ||
+ NODE_INFO (node->parent)->type == NODE_TYPE_TOOLBAR_PLACEHOLDER)
+ {
+ GtkWidget *toolbar;
+ gint pos;
+ gint separator_mode;
+ GtkToolItem *item;
+
+ if (GTK_IS_SEPARATOR_TOOL_ITEM (info->proxy))
{
- g_signal_handlers_disconnect_by_func (info->proxy,
- G_CALLBACK (update_smart_separators),
- 0);
- gtk_action_disconnect_proxy (info->action, info->proxy);
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 *toolbar;
- gint pos;
-
- if (find_toolbar_position (node, &toolbar, &pos))
- {
- info->proxy = gtk_action_create_tool_item (action);
- gtk_widget_set_name (info->proxy, info->name);
-
- gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
- GTK_TOOL_ITEM (info->proxy), pos);
-
- /* 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_get (G_OBJECT (action), "tooltip", &tooltip, NULL);
- g_object_set (G_OBJECT (action), "tooltip", tooltip, NULL);
- g_free (tooltip);
- }
- }
- else
- {
- g_signal_handlers_disconnect_by_func (info->proxy,
- G_CALLBACK (update_smart_separators),
- 0);
- gtk_action_connect_proxy (action, info->proxy);
- }
- g_signal_connect (info->proxy, "notify::visible",
- G_CALLBACK (update_smart_separators), 0);
- break;
- case NODE_TYPE_SEPARATOR:
- if (NODE_INFO (node->parent)->type == NODE_TYPE_TOOLBAR ||
- NODE_INFO (node->parent)->type == NODE_TYPE_TOOLBAR_PLACEHOLDER)
+
+ if (find_toolbar_position (node, &toolbar, &pos))
+ {
+ item = gtk_separator_tool_item_new ();
+ gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, pos);
+ info->proxy = GTK_WIDGET (item);
+ 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;
+
+ g_object_set_data (G_OBJECT (info->proxy),
+ I_("gtk-separator-mode"),
+ GINT_TO_POINTER (separator_mode));
+ gtk_widget_show (info->proxy);
+ }
+ }
+ else
+ {
+ GtkWidget *menushell;
+ gint pos;
+
+ if (GTK_IS_SEPARATOR_MENU_ITEM (info->proxy))
{
- GtkWidget *toolbar;
- gint pos;
-
- if (GTK_IS_SEPARATOR_TOOL_ITEM (info->proxy))
- {
- gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
- info->proxy);
- info->proxy = NULL;
- }
-
- if (find_toolbar_position (node, &toolbar, &pos))
- {
- GtkToolItem *item = gtk_separator_tool_item_new ();
- gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, pos);
- info->proxy = GTK_WIDGET (item);
- 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));
- gtk_widget_show (info->proxy);
- }
+ gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
+ info->proxy);
+ g_object_unref (info->proxy);
+ info->proxy = NULL;
}
- else
+
+ if (find_menu_position (node, &menushell, &pos))
{
- GtkWidget *menushell;
- gint pos;
-
- if (GTK_IS_SEPARATOR_MENU_ITEM (info->proxy))
- {
- gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
- info->proxy);
- info->proxy = NULL;
- }
-
- if (find_menu_position (node, &menushell, &pos))
- {
- info->proxy = gtk_separator_menu_item_new ();
- 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));
- gtk_menu_shell_insert (GTK_MENU_SHELL (menushell),
- info->proxy, pos);
- gtk_widget_show (info->proxy);
- }
- }
- break;
- case NODE_TYPE_ACCELERATOR:
- gtk_action_connect_accelerator (action);
- break;
+ 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),
+ 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);
+ }
}
-
- if (action)
- g_object_ref (action);
- if (info->action)
- g_object_unref (info->action);
- info->action = action;
+ break;
+ case NODE_TYPE_ACCELERATOR:
+ gtk_action_connect_accelerator (action);
+ break;
}
+
+ if (action)
+ g_object_ref (action);
+ if (info->action)
+ g_object_unref (info->action);
+ info->action = action;
recurse_children:
/* process children */
while (child)
{
GNode *current;
-
+
current = child;
child = current->next;
update_node (self, current, in_popup);
}
-
+
if (info->proxy)
{
- if (info->type == NODE_TYPE_MENU)
+ if (info->type == NODE_TYPE_MENU && GTK_IS_MENU_ITEM (info->proxy))
update_smart_separators (gtk_menu_item_get_submenu (GTK_MENU_ITEM (info->proxy)));
- else if (info->type == NODE_TYPE_TOOLBAR)
+ else if (info->type == NODE_TYPE_MENU ||
+ info->type == NODE_TYPE_TOOLBAR ||
+ info->type == NODE_TYPE_POPUP)
update_smart_separators (info->proxy);
}
-
+
/* handle cleanup of dead nodes */
if (node->children == NULL && info->uifiles == NULL)
{
static gboolean
do_updates (GtkUIManager *self)
{
- GDK_THREADS_ENTER ();
-
/* this function needs to check through the tree for dirty nodes.
* For such nodes, it needs to do the following:
*
self->private_data->update_tag = 0;
- GDK_THREADS_LEAVE ();
+ return FALSE;
+}
+
+static gboolean
+do_updates_idle (GtkUIManager *self)
+{
+ do_updates (self);
return FALSE;
}
if (self->private_data->update_tag != 0)
return;
- self->private_data->update_tag = g_idle_add ((GSourceFunc)do_updates, self);
+ self->private_data->update_tag = gdk_threads_add_idle (
+ (GSourceFunc)do_updates_idle,
+ 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_CALLBACK (add_widget), vbox);
* 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
**/
queue_update (self);
}
-static const gchar *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 void
+mark_node_dirty (GNode *node)
+{
+ GNode *p;
-static const gchar *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
-};
+ /* FIXME could optimize this */
+ for (p = node; p; p = p->parent)
+ NODE_INFO (p)->dirty = TRUE;
+}
+
+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 *
+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,
{
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);
- if (mnode->name)
- g_string_append_printf (buffer, " name=\"%s\"", mnode->name);
+ g_string_append_printf (buffer, open_fmt, indent_level, "");
- if (mnode->action_name)
- g_string_append_printf (buffer, " action=\"%s\"",
- g_quark_to_string (mnode->action_name));
+ if (mnode->type != NODE_TYPE_ROOT)
+ {
+ if (mnode->name)
+ g_string_append_printf (buffer, " name=\"%s\"", mnode->name);
+
+ if (mnode->action_name)
+ g_string_append_printf (buffer, " action=\"%s\"",
+ 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);
}
/**
return g_string_free (buffer, FALSE);
}
+#ifdef G_OS_WIN32
+
+#undef gtk_ui_manager_add_ui_from_file
+
+guint
+gtk_ui_manager_add_ui_from_file (GtkUIManager *self,
+ const gchar *filename,
+ GError **error)
+{
+ gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, error);
+ guint retval;
+
+ if (utf8_filename == NULL)
+ return 0;
+
+ retval = gtk_ui_manager_add_ui_from_file_utf8 (self, utf8_filename, error);
+
+ g_free (utf8_filename);
+
+ return retval;
+}
+
+#endif
+
+#define __GTK_UI_MANAGER_C__
+#include "gtkaliasdef.c"