2003-08-24 19:58:30 +00:00
|
|
|
/*
|
|
|
|
* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 1998, 1999 Red Hat, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This Library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This Library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with the Gnome Library; see the file COPYING.LIB. If not,
|
|
|
|
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Author: James Henstridge <james@daa.com.au>
|
|
|
|
*
|
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
2003-08-25 23:13:47 +00:00
|
|
|
#include "gtkuimanager.h"
|
2003-08-24 19:58:30 +00:00
|
|
|
#include "gtktoolbar.h"
|
|
|
|
#include "gtkseparatortoolitem.h"
|
|
|
|
#include "gtkmenushell.h"
|
|
|
|
#include "gtkmenu.h"
|
|
|
|
#include "gtkmenubar.h"
|
|
|
|
#include "gtkseparatormenuitem.h"
|
2003-08-29 22:42:37 +00:00
|
|
|
#include "gtktearoffmenuitem.h"
|
2003-08-24 19:58:30 +00:00
|
|
|
#include "gtkintl.h"
|
|
|
|
|
2003-08-25 23:13:47 +00:00
|
|
|
#undef DEBUG_UI_MANAGER
|
2003-08-24 19:58:30 +00:00
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
2003-09-04 00:15:59 +00:00
|
|
|
NODE_TYPE_UNDECIDED,
|
|
|
|
NODE_TYPE_ROOT,
|
|
|
|
NODE_TYPE_MENUBAR,
|
|
|
|
NODE_TYPE_MENU,
|
|
|
|
NODE_TYPE_TOOLBAR,
|
|
|
|
NODE_TYPE_MENU_PLACEHOLDER,
|
|
|
|
NODE_TYPE_TOOLBAR_PLACEHOLDER,
|
|
|
|
NODE_TYPE_POPUP,
|
|
|
|
NODE_TYPE_MENUITEM,
|
|
|
|
NODE_TYPE_TOOLITEM,
|
|
|
|
NODE_TYPE_SEPARATOR,
|
2003-09-17 23:58:28 +00:00
|
|
|
NODE_TYPE_ACCELERATOR
|
2003-09-04 00:15:59 +00:00
|
|
|
} NodeType;
|
2003-08-24 19:58:30 +00:00
|
|
|
|
|
|
|
|
2003-09-04 00:15:59 +00:00
|
|
|
typedef struct _Node Node;
|
2003-08-24 19:58:30 +00:00
|
|
|
|
2003-09-04 00:15:59 +00:00
|
|
|
struct _Node {
|
|
|
|
NodeType type;
|
2003-08-24 19:58:30 +00:00
|
|
|
|
2003-09-11 21:02:24 +00:00
|
|
|
gchar *name;
|
2003-08-24 19:58:30 +00:00
|
|
|
|
|
|
|
GQuark action_name;
|
|
|
|
GtkAction *action;
|
|
|
|
GtkWidget *proxy;
|
|
|
|
GtkWidget *extra; /*GtkMenu for submenus, second separator for placeholders*/
|
|
|
|
|
|
|
|
GList *uifiles;
|
|
|
|
|
|
|
|
guint dirty : 1;
|
|
|
|
};
|
|
|
|
|
2003-08-25 23:13:47 +00:00
|
|
|
#define GTK_UI_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_UI_MANAGER, GtkUIManagerPrivate))
|
2003-08-24 19:58:30 +00:00
|
|
|
|
2003-08-25 23:13:47 +00:00
|
|
|
struct _GtkUIManagerPrivate
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
|
|
|
GtkAccelGroup *accel_group;
|
|
|
|
|
|
|
|
GNode *root_node;
|
|
|
|
GList *action_groups;
|
|
|
|
|
|
|
|
guint last_merge_id;
|
|
|
|
|
|
|
|
guint update_tag;
|
2003-08-29 22:42:37 +00:00
|
|
|
|
|
|
|
gboolean add_tearoffs;
|
2003-08-24 19:58:30 +00:00
|
|
|
};
|
|
|
|
|
2003-09-04 00:15:59 +00:00
|
|
|
#define NODE_INFO(node) ((Node *)node->data)
|
2003-08-24 19:58:30 +00:00
|
|
|
|
|
|
|
typedef struct _NodeUIReference NodeUIReference;
|
|
|
|
|
|
|
|
struct _NodeUIReference
|
|
|
|
{
|
|
|
|
guint merge_id;
|
|
|
|
GQuark action_quark;
|
|
|
|
};
|
|
|
|
|
2003-09-15 20:35:28 +00:00
|
|
|
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);
|
|
|
|
|
2003-08-24 19:58:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ADD_WIDGET,
|
2003-08-29 23:33:54 +00:00
|
|
|
CHANGED,
|
2003-08-24 19:58:30 +00:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2003-08-29 22:42:37 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_ADD_TEAROFFS
|
|
|
|
};
|
|
|
|
|
2003-08-24 19:58:30 +00:00
|
|
|
static guint merge_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
static GMemChunk *merge_node_chunk = NULL;
|
|
|
|
|
|
|
|
GType
|
2003-08-25 23:13:47 +00:00
|
|
|
gtk_ui_manager_get_type (void)
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
|
|
|
static GtkType type = 0;
|
|
|
|
|
|
|
|
if (!type)
|
|
|
|
{
|
|
|
|
static const GTypeInfo type_info =
|
|
|
|
{
|
2003-08-25 23:13:47 +00:00
|
|
|
sizeof (GtkUIManagerClass),
|
2003-08-24 19:58:30 +00:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
2003-08-25 23:13:47 +00:00
|
|
|
(GClassInitFunc) gtk_ui_manager_class_init,
|
2003-08-24 19:58:30 +00:00
|
|
|
(GClassFinalizeFunc) NULL,
|
|
|
|
NULL,
|
|
|
|
|
2003-08-25 23:13:47 +00:00
|
|
|
sizeof (GtkUIManager),
|
2003-08-24 19:58:30 +00:00
|
|
|
0, /* n_preallocs */
|
2003-08-25 23:13:47 +00:00
|
|
|
(GInstanceInitFunc) gtk_ui_manager_init,
|
2003-08-24 19:58:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
type = g_type_register_static (G_TYPE_OBJECT,
|
2003-08-25 23:13:47 +00:00
|
|
|
"GtkUIManager",
|
2003-08-24 19:58:30 +00:00
|
|
|
&type_info, 0);
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-08-25 23:13:47 +00:00
|
|
|
gtk_ui_manager_class_init (GtkUIManagerClass *klass)
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
if (!merge_node_chunk)
|
2003-09-04 00:15:59 +00:00
|
|
|
merge_node_chunk = g_mem_chunk_create (Node, 64,
|
2003-08-24 19:58:30 +00:00
|
|
|
G_ALLOC_AND_FREE);
|
|
|
|
|
2003-08-31 22:29:42 +00:00
|
|
|
gobject_class->finalize = gtk_ui_manager_finalize;
|
2003-08-29 22:42:37 +00:00
|
|
|
gobject_class->set_property = gtk_ui_manager_set_property;
|
|
|
|
gobject_class->get_property = gtk_ui_manager_get_property;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkUIManager:add-tearoffs:
|
|
|
|
*
|
2003-09-01 22:15:16 +00:00
|
|
|
* The "add-tearoffs" property controls whether generated menus
|
2003-08-29 22:42:37 +00:00
|
|
|
* have tearoff menu items.
|
|
|
|
*
|
|
|
|
* Note that this only affects regular menus. Generated popup
|
|
|
|
* menus never have tearoff menu items.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_ADD_TEAROFFS,
|
|
|
|
g_param_spec_boolean ("add_tearoffs",
|
|
|
|
_("Add tearoffs to menus"),
|
|
|
|
_("Whether tearoff menu items should be added to menus"),
|
|
|
|
FALSE,
|
|
|
|
G_PARAM_READABLE | G_PARAM_WRITABLE));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkUIManager::add-widget:
|
|
|
|
* @merge: a #GtkUIManager
|
|
|
|
* @widget: the added widget
|
|
|
|
*
|
|
|
|
* The add_widget signal is emitted for each generated menubar and toolbar.
|
|
|
|
* It is not emitted for generated popup menus, which can be obtained by
|
|
|
|
* gtk_ui_manager_get_widget().
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
2003-08-24 19:58:30 +00:00
|
|
|
merge_signals[ADD_WIDGET] =
|
|
|
|
g_signal_new ("add_widget",
|
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
|
2003-08-25 23:13:47 +00:00
|
|
|
G_STRUCT_OFFSET (GtkUIManagerClass, add_widget), NULL, NULL,
|
2003-08-24 19:58:30 +00:00
|
|
|
g_cclosure_marshal_VOID__OBJECT,
|
2003-08-29 23:33:54 +00:00
|
|
|
G_TYPE_NONE, 1,
|
2003-08-24 19:58:30 +00:00
|
|
|
GTK_TYPE_WIDGET);
|
2003-08-29 22:42:37 +00:00
|
|
|
|
2003-08-29 23:33:54 +00:00
|
|
|
/**
|
|
|
|
* GtkUIManager::changed:
|
|
|
|
* @merge: a #GtkUIManager
|
|
|
|
*
|
2003-09-01 22:15:16 +00:00
|
|
|
* The "changed" signal is emitted whenever the merged UI changes.
|
2003-08-29 23:33:54 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
|
|
|
merge_signals[CHANGED] =
|
|
|
|
g_signal_new ("changed",
|
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
|
|
|
|
G_STRUCT_OFFSET (GtkUIManagerClass, changed), NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
2003-08-24 19:58:30 +00:00
|
|
|
|
2003-08-25 23:13:47 +00:00
|
|
|
g_type_class_add_private (gobject_class, sizeof (GtkUIManagerPrivate));
|
2003-08-24 19:58:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2003-08-25 23:13:47 +00:00
|
|
|
gtk_ui_manager_init (GtkUIManager *self)
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
|
|
|
guint merge_id;
|
|
|
|
GNode *node;
|
|
|
|
|
2003-08-25 23:13:47 +00:00
|
|
|
self->private_data = GTK_UI_MANAGER_GET_PRIVATE (self);
|
2003-08-24 19:58:30 +00:00
|
|
|
|
|
|
|
self->private_data->accel_group = gtk_accel_group_new ();
|
|
|
|
|
|
|
|
self->private_data->root_node = NULL;
|
|
|
|
self->private_data->action_groups = NULL;
|
|
|
|
|
|
|
|
self->private_data->last_merge_id = 0;
|
2003-08-29 22:42:37 +00:00
|
|
|
self->private_data->add_tearoffs = FALSE;
|
2003-08-24 19:58:30 +00:00
|
|
|
|
2003-09-01 22:15:16 +00:00
|
|
|
merge_id = gtk_ui_manager_new_merge_id (self);
|
2003-09-11 21:02:24 +00:00
|
|
|
node = get_child_node (self, NULL, "ui", 2,
|
|
|
|
NODE_TYPE_ROOT, TRUE, FALSE);
|
2003-09-01 22:15:16 +00:00
|
|
|
node_prepend_ui_reference (NODE_INFO (node), merge_id, 0);
|
2003-08-24 19:58:30 +00:00
|
|
|
}
|
|
|
|
|
2003-08-31 22:29:42 +00:00
|
|
|
static void
|
|
|
|
gtk_ui_manager_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkUIManager *self = GTK_UI_MANAGER (object);
|
|
|
|
|
|
|
|
if (self->private_data->update_tag != 0)
|
|
|
|
{
|
|
|
|
g_source_remove (self->private_data->update_tag);
|
|
|
|
self->private_data->update_tag = 0;
|
|
|
|
}
|
2003-09-11 21:02:24 +00:00
|
|
|
|
|
|
|
g_node_traverse (self->private_data->root_node,
|
|
|
|
G_POST_ORDER, G_TRAVERSE_ALL, -1,
|
|
|
|
(GNodeTraverseFunc)free_node, 0);
|
|
|
|
g_node_destroy (self->private_data->root_node);
|
|
|
|
self->private_data->root_node = NULL;
|
|
|
|
|
|
|
|
g_list_foreach (self->private_data->action_groups,
|
|
|
|
(GFunc) g_object_unref, NULL);
|
|
|
|
g_list_free (self->private_data->action_groups);
|
|
|
|
self->private_data->action_groups = NULL;
|
|
|
|
|
|
|
|
g_object_unref (self->private_data->accel_group);
|
|
|
|
self->private_data->accel_group = NULL;
|
2003-08-31 22:29:42 +00:00
|
|
|
}
|
|
|
|
|
2003-08-29 22:42:37 +00:00
|
|
|
static void
|
|
|
|
gtk_ui_manager_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkUIManager *self = GTK_UI_MANAGER (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_ADD_TEAROFFS:
|
|
|
|
gtk_ui_manager_set_add_tearoffs (self, g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_ui_manager_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkUIManager *self = GTK_UI_MANAGER (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_ADD_TEAROFFS:
|
|
|
|
g_value_set_boolean (value, self->private_data->add_tearoffs);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-24 19:58:30 +00:00
|
|
|
|
|
|
|
/**
|
2003-08-25 23:13:47 +00:00
|
|
|
* gtk_ui_manager_new:
|
2003-08-24 19:58:30 +00:00
|
|
|
*
|
2003-08-31 00:27:15 +00:00
|
|
|
* Creates a new ui manager object.
|
2003-08-24 19:58:30 +00:00
|
|
|
*
|
2003-08-31 00:27:15 +00:00
|
|
|
* Return value: a new ui manager object.
|
2003-08-24 19:58:30 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
**/
|
2003-08-25 23:13:47 +00:00
|
|
|
GtkUIManager*
|
|
|
|
gtk_ui_manager_new (void)
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
2003-08-25 23:13:47 +00:00
|
|
|
return g_object_new (GTK_TYPE_UI_MANAGER, NULL);
|
2003-08-24 19:58:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-29 22:42:37 +00:00
|
|
|
/**
|
|
|
|
* gtk_ui_manager_get_add_tearoffs:
|
|
|
|
* @self: a #GtkUIManager
|
|
|
|
*
|
|
|
|
* Returns whether menus generated by this #GtkUIManager
|
|
|
|
* will have tearoff menu items.
|
|
|
|
*
|
|
|
|
* Return value: whether tearoff menu items are added
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gtk_ui_manager_get_add_tearoffs (GtkUIManager *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_UI_MANAGER (self), FALSE);
|
|
|
|
|
|
|
|
return self->private_data->add_tearoffs;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_ui_manager_set_add_tearoffs:
|
|
|
|
* @self: a #GtkUIManager
|
|
|
|
* @add_tearoffs: whether tearoff menu items are added
|
|
|
|
*
|
2003-09-01 22:15:16 +00:00
|
|
|
* Sets the "add_tearoffs" property, which controls whether menus
|
2003-08-29 22:42:37 +00:00
|
|
|
* generated by this #GtkUIManager will have tearoff menu items.
|
|
|
|
*
|
|
|
|
* Note that this only affects regular menus. Generated popup
|
|
|
|
* menus never have tearoff menu items.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_ui_manager_set_add_tearoffs (GtkUIManager *self,
|
|
|
|
gboolean add_tearoffs)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_UI_MANAGER (self));
|
|
|
|
|
|
|
|
add_tearoffs = add_tearoffs != FALSE;
|
|
|
|
|
|
|
|
if (add_tearoffs != self->private_data->add_tearoffs)
|
|
|
|
{
|
|
|
|
self->private_data->add_tearoffs = add_tearoffs;
|
|
|
|
|
2003-09-01 22:15:16 +00:00
|
|
|
dirty_all_nodes (self);
|
2003-08-29 22:42:37 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (self), "add_tearoffs");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-24 19:58:30 +00:00
|
|
|
/**
|
2003-08-25 23:13:47 +00:00
|
|
|
* gtk_ui_manager_insert_action_group:
|
|
|
|
* @self: a #GtkUIManager object
|
2003-08-24 19:58:30 +00:00
|
|
|
* @action_group: the action group to be inserted
|
2003-08-31 13:49:15 +00:00
|
|
|
* @pos: the position at which the group will be inserted.
|
2003-08-24 19:58:30 +00:00
|
|
|
*
|
2003-08-29 22:42:37 +00:00
|
|
|
* Inserts an action group into the list of action groups associated
|
2003-09-15 22:21:26 +00:00
|
|
|
* with @self. Actions in earlier groups hide actions with the same
|
|
|
|
* name in later groups.
|
2003-08-24 19:58:30 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
**/
|
|
|
|
void
|
2003-08-25 23:13:47 +00:00
|
|
|
gtk_ui_manager_insert_action_group (GtkUIManager *self,
|
2003-08-24 19:58:30 +00:00
|
|
|
GtkActionGroup *action_group,
|
|
|
|
gint pos)
|
|
|
|
{
|
2003-08-25 23:13:47 +00:00
|
|
|
g_return_if_fail (GTK_IS_UI_MANAGER (self));
|
2003-08-24 19:58:30 +00:00
|
|
|
g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
|
2003-08-29 22:42:37 +00:00
|
|
|
g_return_if_fail (g_list_find (self->private_data->action_groups,
|
|
|
|
action_group) == NULL);
|
2003-08-24 19:58:30 +00:00
|
|
|
|
|
|
|
g_object_ref (action_group);
|
2003-08-29 22:42:37 +00:00
|
|
|
self->private_data->action_groups =
|
|
|
|
g_list_insert (self->private_data->action_groups, action_group, pos);
|
2003-08-24 19:58:30 +00:00
|
|
|
|
|
|
|
/* dirty all nodes, as action bindings may change */
|
2003-09-01 22:15:16 +00:00
|
|
|
dirty_all_nodes (self);
|
2003-08-24 19:58:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2003-08-25 23:13:47 +00:00
|
|
|
* gtk_ui_manager_remove_action_group:
|
|
|
|
* @self: a #GtkUIManager object
|
2003-08-24 19:58:30 +00:00
|
|
|
* @action_group: the action group to be removed
|
|
|
|
*
|
2003-08-29 22:42:37 +00:00
|
|
|
* Removes an action group from the list of action groups associated
|
|
|
|
* with @self.
|
2003-08-24 19:58:30 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
**/
|
|
|
|
void
|
2003-08-25 23:13:47 +00:00
|
|
|
gtk_ui_manager_remove_action_group (GtkUIManager *self,
|
2003-08-24 19:58:30 +00:00
|
|
|
GtkActionGroup *action_group)
|
|
|
|
{
|
2003-08-25 23:13:47 +00:00
|
|
|
g_return_if_fail (GTK_IS_UI_MANAGER (self));
|
2003-08-24 19:58:30 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
self->private_data->action_groups =
|
|
|
|
g_list_remove (self->private_data->action_groups, action_group);
|
|
|
|
g_object_unref (action_group);
|
|
|
|
|
|
|
|
/* dirty all nodes, as action bindings may change */
|
2003-09-01 22:15:16 +00:00
|
|
|
dirty_all_nodes (self);
|
2003-08-24 19:58:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2003-08-25 23:13:47 +00:00
|
|
|
* gtk_ui_manager_get_action_groups:
|
|
|
|
* @self: a #GtkUIManager object
|
2003-08-24 19:58:30 +00:00
|
|
|
*
|
|
|
|
* Returns the list of action groups associated with @self.
|
|
|
|
*
|
|
|
|
* Return value: a #GList of action groups. The list is owned by GTK+
|
|
|
|
* and should not be modified.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
**/
|
|
|
|
GList *
|
2003-09-11 21:02:24 +00:00
|
|
|
gtk_ui_manager_get_action_groups (GtkUIManager *self)
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
2003-08-25 23:13:47 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_UI_MANAGER (self), NULL);
|
2003-08-24 19:58:30 +00:00
|
|
|
|
|
|
|
return self->private_data->action_groups;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2003-08-25 23:13:47 +00:00
|
|
|
* gtk_ui_manager_get_accel_group:
|
|
|
|
* @self: a #GtkUIManager object
|
2003-08-24 19:58:30 +00:00
|
|
|
*
|
|
|
|
* Returns the #GtkAccelGroup associated with @self.
|
|
|
|
*
|
|
|
|
* Return value: the #GtkAccelGroup.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
**/
|
|
|
|
GtkAccelGroup *
|
2003-09-11 21:02:24 +00:00
|
|
|
gtk_ui_manager_get_accel_group (GtkUIManager *self)
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
2003-08-25 23:13:47 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_UI_MANAGER (self), NULL);
|
2003-08-24 19:58:30 +00:00
|
|
|
|
|
|
|
return self->private_data->accel_group;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2003-08-25 23:13:47 +00:00
|
|
|
* gtk_ui_manager_get_widget:
|
|
|
|
* @self: a #GtkUIManager
|
2003-08-24 19:58:30 +00:00
|
|
|
* @path: a path
|
|
|
|
*
|
2003-09-04 00:00:14 +00:00
|
|
|
* Looks up a widget by following a path.
|
|
|
|
* The path consists of the names specified in the XML description of the UI.
|
|
|
|
* 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
|
2003-09-15 22:21:26 +00:00
|
|
|
* (e.g. "popup"). The root element ("/ui") can be omitted in the path.
|
2003-08-24 19:58:30 +00:00
|
|
|
*
|
|
|
|
* Return value: the widget found by following the path, or %NULL if no widget
|
|
|
|
* was found.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
**/
|
|
|
|
GtkWidget *
|
2003-08-25 23:13:47 +00:00
|
|
|
gtk_ui_manager_get_widget (GtkUIManager *self,
|
2003-08-24 19:58:30 +00:00
|
|
|
const gchar *path)
|
|
|
|
{
|
|
|
|
GNode *node;
|
|
|
|
|
2003-08-30 21:18:43 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_UI_MANAGER (self), NULL);
|
2003-08-31 22:29:42 +00:00
|
|
|
g_return_val_if_fail (path != NULL, NULL);
|
2003-08-30 21:18:43 +00:00
|
|
|
|
2003-08-24 19:58:30 +00:00
|
|
|
/* ensure that there are no pending updates before we get the
|
|
|
|
* widget */
|
2003-08-25 23:13:47 +00:00
|
|
|
gtk_ui_manager_ensure_update (self);
|
2003-08-24 19:58:30 +00:00
|
|
|
|
2003-09-04 00:15:59 +00:00
|
|
|
node = get_node (self, path, NODE_TYPE_UNDECIDED, FALSE);
|
2003-08-24 19:58:30 +00:00
|
|
|
|
|
|
|
if (node == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return NODE_INFO (node)->proxy;
|
|
|
|
}
|
|
|
|
|
2003-08-31 13:49:15 +00:00
|
|
|
/**
|
|
|
|
* gtk_ui_manager_get_action:
|
|
|
|
* @self: a #GtkUIManager
|
|
|
|
* @path: a path
|
|
|
|
*
|
2003-09-04 00:00:14 +00:00
|
|
|
* Looks up an action by following a path. See gtk_ui_manager_get_widget()
|
|
|
|
* for more information about paths.
|
2003-08-31 13:49:15 +00:00
|
|
|
*
|
|
|
|
* Return value: the action whose proxy widget is found by following the path,
|
|
|
|
* or %NULL if no widget was found.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
**/
|
|
|
|
GtkAction *
|
2003-09-11 21:02:24 +00:00
|
|
|
gtk_ui_manager_get_action (GtkUIManager *self,
|
|
|
|
const gchar *path)
|
2003-08-31 13:49:15 +00:00
|
|
|
{
|
|
|
|
GNode *node;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_UI_MANAGER (self), NULL);
|
2003-08-31 22:29:42 +00:00
|
|
|
g_return_val_if_fail (path != NULL, NULL);
|
2003-08-31 13:49:15 +00:00
|
|
|
|
|
|
|
/* ensure that there are no pending updates before we get
|
|
|
|
* the action */
|
|
|
|
gtk_ui_manager_ensure_update (self);
|
|
|
|
|
2003-09-04 00:15:59 +00:00
|
|
|
node = get_node (self, path, NODE_TYPE_UNDECIDED, FALSE);
|
2003-08-31 13:49:15 +00:00
|
|
|
|
|
|
|
if (node == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return NODE_INFO (node)->action;
|
|
|
|
}
|
|
|
|
|
2003-08-24 19:58:30 +00:00
|
|
|
static GNode *
|
2003-09-11 21:02:24 +00:00
|
|
|
get_child_node (GtkUIManager *self,
|
|
|
|
GNode *parent,
|
|
|
|
const gchar *childname,
|
|
|
|
gint childname_length,
|
|
|
|
NodeType node_type,
|
|
|
|
gboolean create,
|
|
|
|
gboolean top)
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
|
|
|
GNode *child = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (parent == NULL ||
|
2003-09-04 00:15:59 +00:00
|
|
|
(NODE_INFO (parent)->type != NODE_TYPE_MENUITEM &&
|
|
|
|
NODE_INFO (parent)->type != NODE_TYPE_TOOLITEM),
|
2003-08-24 19:58:30 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
if (childname)
|
|
|
|
{
|
|
|
|
for (child = parent->children; child != NULL; child = child->next)
|
|
|
|
{
|
|
|
|
if (strlen (NODE_INFO (child)->name) == childname_length &&
|
|
|
|
!strncmp (NODE_INFO (child)->name, childname, childname_length))
|
|
|
|
{
|
|
|
|
/* if undecided about node type, set it */
|
2003-09-04 00:15:59 +00:00
|
|
|
if (NODE_INFO (child)->type == NODE_TYPE_UNDECIDED)
|
2003-08-24 19:58:30 +00:00
|
|
|
NODE_INFO (child)->type = node_type;
|
|
|
|
|
|
|
|
/* warn about type mismatch */
|
2003-09-04 00:15:59 +00:00
|
|
|
if (NODE_INFO (child)->type != NODE_TYPE_UNDECIDED &&
|
|
|
|
node_type != NODE_TYPE_UNDECIDED &&
|
2003-08-24 19:58:30 +00:00
|
|
|
NODE_INFO (child)->type != node_type)
|
|
|
|
g_warning ("node type doesn't match %d (%s is type %d)",
|
|
|
|
node_type,
|
|
|
|
NODE_INFO (child)->name,
|
|
|
|
NODE_INFO (child)->type);
|
|
|
|
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!child && create)
|
|
|
|
{
|
2003-09-04 00:15:59 +00:00
|
|
|
Node *mnode;
|
2003-08-24 19:58:30 +00:00
|
|
|
|
2003-09-04 00:15:59 +00:00
|
|
|
mnode = g_chunk_new0 (Node, merge_node_chunk);
|
2003-08-24 19:58:30 +00:00
|
|
|
mnode->type = node_type;
|
|
|
|
mnode->name = g_strndup (childname, childname_length);
|
|
|
|
mnode->dirty = TRUE;
|
|
|
|
|
|
|
|
if (top)
|
|
|
|
child = g_node_prepend_data (parent, mnode);
|
|
|
|
else
|
|
|
|
child = g_node_append_data (parent, mnode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* handle root node */
|
|
|
|
if (self->private_data->root_node)
|
|
|
|
{
|
|
|
|
child = self->private_data->root_node;
|
|
|
|
if (strncmp (NODE_INFO (child)->name, childname, childname_length) != 0)
|
|
|
|
g_warning ("root node name '%s' doesn't match '%s'",
|
|
|
|
childname, NODE_INFO (child)->name);
|
2003-09-04 00:15:59 +00:00
|
|
|
if (NODE_INFO (child)->type != NODE_TYPE_ROOT)
|
2003-08-24 19:58:30 +00:00
|
|
|
g_warning ("base element must be of type ROOT");
|
|
|
|
}
|
|
|
|
else if (create)
|
|
|
|
{
|
2003-09-04 00:15:59 +00:00
|
|
|
Node *mnode;
|
2003-08-24 19:58:30 +00:00
|
|
|
|
2003-09-04 00:15:59 +00:00
|
|
|
mnode = g_chunk_new0 (Node, merge_node_chunk);
|
2003-08-24 19:58:30 +00:00
|
|
|
mnode->type = node_type;
|
|
|
|
mnode->name = g_strndup (childname, childname_length);
|
|
|
|
mnode->dirty = TRUE;
|
|
|
|
|
|
|
|
child = self->private_data->root_node = g_node_new (mnode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GNode *
|
2003-09-11 21:02:24 +00:00
|
|
|
get_node (GtkUIManager *self,
|
|
|
|
const gchar *path,
|
|
|
|
NodeType node_type,
|
|
|
|
gboolean create)
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
|
|
|
const gchar *pos, *end;
|
|
|
|
GNode *parent, *node;
|
|
|
|
|
|
|
|
end = path + strlen (path);
|
|
|
|
pos = path;
|
|
|
|
parent = node = NULL;
|
|
|
|
while (pos < end)
|
|
|
|
{
|
|
|
|
const gchar *slash;
|
|
|
|
gsize length;
|
|
|
|
|
|
|
|
slash = strchr (pos, '/');
|
|
|
|
if (slash)
|
|
|
|
length = slash - pos;
|
|
|
|
else
|
|
|
|
length = strlen (pos);
|
|
|
|
|
2003-09-04 00:15:59 +00:00
|
|
|
node = get_child_node (self, parent, pos, length, NODE_TYPE_UNDECIDED,
|
2003-08-24 19:58:30 +00:00
|
|
|
create, FALSE);
|
|
|
|
if (!node)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
pos += length + 1; /* move past the node name and the slash too */
|
|
|
|
parent = node;
|
|
|
|
}
|
|
|
|
|
2003-09-04 00:15:59 +00:00
|
|
|
if (node != NULL && NODE_INFO (node)->type == NODE_TYPE_UNDECIDED)
|
2003-08-24 19:58:30 +00:00
|
|
|
NODE_INFO (node)->type = node_type;
|
2003-09-11 21:02:24 +00:00
|
|
|
|
2003-08-24 19:58:30 +00:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2003-09-11 21:02:24 +00:00
|
|
|
static gboolean
|
|
|
|
free_node (GNode *node)
|
|
|
|
{
|
|
|
|
Node *info = NODE_INFO (node);
|
|
|
|
|
|
|
|
g_list_foreach (info->uifiles, (GFunc) g_free, NULL);
|
|
|
|
g_list_free (info->uifiles);
|
|
|
|
|
|
|
|
if (info->action)
|
|
|
|
g_object_unref (info->action);
|
|
|
|
g_free (info->name);
|
|
|
|
g_chunk_free (info, merge_node_chunk);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-09-01 22:15:16 +00:00
|
|
|
/**
|
|
|
|
* gtk_ui_manager_new_merge_id:
|
|
|
|
* @self: a #GtkUIManager
|
|
|
|
*
|
|
|
|
* Returns an unused merge id, suitable for use with
|
|
|
|
* gtk_ui_manager_add_ui().
|
|
|
|
*
|
|
|
|
* Return value: an unused merge id.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
**/
|
|
|
|
guint
|
|
|
|
gtk_ui_manager_new_merge_id (GtkUIManager *self)
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
|
|
|
self->private_data->last_merge_id++;
|
|
|
|
|
|
|
|
return self->private_data->last_merge_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-09-11 21:02:24 +00:00
|
|
|
node_prepend_ui_reference (Node *node,
|
|
|
|
guint merge_id,
|
|
|
|
GQuark action_quark)
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
|
|
|
NodeUIReference *reference;
|
|
|
|
|
|
|
|
reference = g_new (NodeUIReference, 1);
|
|
|
|
reference->action_quark = action_quark;
|
|
|
|
reference->merge_id = merge_id;
|
|
|
|
|
|
|
|
/* Prepend the reference */
|
|
|
|
node->uifiles = g_list_prepend (node->uifiles, reference);
|
|
|
|
|
|
|
|
node->dirty = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-09-11 21:02:24 +00:00
|
|
|
node_remove_ui_reference (Node *node,
|
|
|
|
guint merge_id)
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
|
|
|
GList *p;
|
|
|
|
|
|
|
|
for (p = node->uifiles; p != NULL; p = p->next)
|
|
|
|
{
|
|
|
|
NodeUIReference *reference = p->data;
|
|
|
|
|
|
|
|
if (reference->merge_id == merge_id)
|
|
|
|
{
|
|
|
|
node->uifiles = g_list_remove_link (node->uifiles, p);
|
|
|
|
node->dirty = TRUE;
|
|
|
|
g_free (reference);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------- The UI file parser -------------------- */
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
STATE_START,
|
|
|
|
STATE_ROOT,
|
|
|
|
STATE_MENU,
|
|
|
|
STATE_TOOLBAR,
|
|
|
|
STATE_MENUITEM,
|
|
|
|
STATE_TOOLITEM,
|
|
|
|
STATE_END
|
|
|
|
} ParseState;
|
|
|
|
|
|
|
|
typedef struct _ParseContext ParseContext;
|
|
|
|
struct _ParseContext
|
|
|
|
{
|
|
|
|
ParseState state;
|
|
|
|
ParseState prev_state;
|
|
|
|
|
2003-08-25 23:13:47 +00:00
|
|
|
GtkUIManager *self;
|
2003-08-24 19:58:30 +00:00
|
|
|
|
|
|
|
GNode *current;
|
|
|
|
|
|
|
|
guint merge_id;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
start_element_handler (GMarkupParseContext *context,
|
|
|
|
const gchar *element_name,
|
|
|
|
const gchar **attribute_names,
|
|
|
|
const gchar **attribute_values,
|
|
|
|
gpointer user_data,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
ParseContext *ctx = user_data;
|
2003-08-25 23:13:47 +00:00
|
|
|
GtkUIManager *self = ctx->self;
|
2003-08-24 19:58:30 +00:00
|
|
|
|
|
|
|
gint i;
|
|
|
|
const gchar *node_name;
|
Change the XML format: <Root> element is replaced by <ui>, <menu> element
2003-08-28 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Change the XML format:
<Root> element is replaced by <ui>,
<menu> element is replaced by <menubar>,
<submenu> element is replaced by <menu>,
<dockitem> element is replaced by <toolbar>,
<popups> element is gone,
verb attribute is replaced by action,
name defaults to action or the element name.
* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
and GtkRadioActionEntry. GtkActionEntry is simplified by removing
the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
further simplified by removing the callback. The user_data can now be
specified as an argument to gtk_action_group_add_actions(). There is
a new method gtk_action_group_add_radio_actions(), which is similar
to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
and a callback parameter in addition to the user_data. The callback
is connected to the ::changed signal of the first group member.
There are _full() variants taking a GDestroyNotify of
gtk_action_group_add_[radio_]actions().
* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
on every member of the radio group when the active member is changed.
Add an integer property "value", and a getter for the value of "value"
on the currently active group member.
* tests/testactions.c:
* tests/testmerge.c:
* tests/merge-[123].ui:
* demos/gtk-demo/appwindow.c: Adjust to these changes.
* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
2003-08-27 22:22:28 +00:00
|
|
|
const gchar *action;
|
2003-08-26 00:13:59 +00:00
|
|
|
GQuark action_quark;
|
2003-08-24 19:58:30 +00:00
|
|
|
gboolean top;
|
|
|
|
|
|
|
|
gboolean raise_error = TRUE;
|
|
|
|
|
Change the XML format: <Root> element is replaced by <ui>, <menu> element
2003-08-28 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Change the XML format:
<Root> element is replaced by <ui>,
<menu> element is replaced by <menubar>,
<submenu> element is replaced by <menu>,
<dockitem> element is replaced by <toolbar>,
<popups> element is gone,
verb attribute is replaced by action,
name defaults to action or the element name.
* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
and GtkRadioActionEntry. GtkActionEntry is simplified by removing
the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
further simplified by removing the callback. The user_data can now be
specified as an argument to gtk_action_group_add_actions(). There is
a new method gtk_action_group_add_radio_actions(), which is similar
to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
and a callback parameter in addition to the user_data. The callback
is connected to the ::changed signal of the first group member.
There are _full() variants taking a GDestroyNotify of
gtk_action_group_add_[radio_]actions().
* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
on every member of the radio group when the active member is changed.
Add an integer property "value", and a getter for the value of "value"
on the currently active group member.
* tests/testactions.c:
* tests/testmerge.c:
* tests/merge-[123].ui:
* demos/gtk-demo/appwindow.c: Adjust to these changes.
* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
2003-08-27 22:22:28 +00:00
|
|
|
node_name = NULL;
|
|
|
|
action = NULL;
|
2003-08-26 00:13:59 +00:00
|
|
|
action_quark = 0;
|
2003-08-24 19:58:30 +00:00
|
|
|
top = FALSE;
|
|
|
|
for (i = 0; attribute_names[i] != NULL; i++)
|
|
|
|
{
|
|
|
|
if (!strcmp (attribute_names[i], "name"))
|
|
|
|
{
|
|
|
|
node_name = attribute_values[i];
|
|
|
|
}
|
2003-08-26 00:13:59 +00:00
|
|
|
else if (!strcmp (attribute_names[i], "action"))
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
Change the XML format: <Root> element is replaced by <ui>, <menu> element
2003-08-28 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Change the XML format:
<Root> element is replaced by <ui>,
<menu> element is replaced by <menubar>,
<submenu> element is replaced by <menu>,
<dockitem> element is replaced by <toolbar>,
<popups> element is gone,
verb attribute is replaced by action,
name defaults to action or the element name.
* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
and GtkRadioActionEntry. GtkActionEntry is simplified by removing
the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
further simplified by removing the callback. The user_data can now be
specified as an argument to gtk_action_group_add_actions(). There is
a new method gtk_action_group_add_radio_actions(), which is similar
to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
and a callback parameter in addition to the user_data. The callback
is connected to the ::changed signal of the first group member.
There are _full() variants taking a GDestroyNotify of
gtk_action_group_add_[radio_]actions().
* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
on every member of the radio group when the active member is changed.
Add an integer property "value", and a getter for the value of "value"
on the currently active group member.
* tests/testactions.c:
* tests/testmerge.c:
* tests/merge-[123].ui:
* demos/gtk-demo/appwindow.c: Adjust to these changes.
* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
2003-08-27 22:22:28 +00:00
|
|
|
action = attribute_values[i];
|
2003-08-26 00:13:59 +00:00
|
|
|
action_quark = g_quark_from_string (attribute_values[i]);
|
2003-08-24 19:58:30 +00:00
|
|
|
}
|
2003-09-04 09:07:23 +00:00
|
|
|
else if (!strcmp (attribute_names[i], "position"))
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
|
|
|
top = !strcmp (attribute_values[i], "top");
|
|
|
|
}
|
2003-09-04 00:00:14 +00:00
|
|
|
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;
|
|
|
|
}
|
2003-08-24 19:58:30 +00:00
|
|
|
}
|
Change the XML format: <Root> element is replaced by <ui>, <menu> element
2003-08-28 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Change the XML format:
<Root> element is replaced by <ui>,
<menu> element is replaced by <menubar>,
<submenu> element is replaced by <menu>,
<dockitem> element is replaced by <toolbar>,
<popups> element is gone,
verb attribute is replaced by action,
name defaults to action or the element name.
* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
and GtkRadioActionEntry. GtkActionEntry is simplified by removing
the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
further simplified by removing the callback. The user_data can now be
specified as an argument to gtk_action_group_add_actions(). There is
a new method gtk_action_group_add_radio_actions(), which is similar
to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
and a callback parameter in addition to the user_data. The callback
is connected to the ::changed signal of the first group member.
There are _full() variants taking a GDestroyNotify of
gtk_action_group_add_[radio_]actions().
* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
on every member of the radio group when the active member is changed.
Add an integer property "value", and a getter for the value of "value"
on the currently active group member.
* tests/testactions.c:
* tests/testmerge.c:
* tests/merge-[123].ui:
* demos/gtk-demo/appwindow.c: Adjust to these changes.
* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
2003-08-27 22:22:28 +00:00
|
|
|
|
|
|
|
/* Work out a name for this node. Either the name attribute, or
|
|
|
|
* the action, or the element name */
|
|
|
|
if (node_name == NULL)
|
|
|
|
{
|
|
|
|
if (action != NULL)
|
|
|
|
node_name = action;
|
|
|
|
else
|
|
|
|
node_name = element_name;
|
|
|
|
}
|
2003-08-24 19:58:30 +00:00
|
|
|
|
|
|
|
switch (element_name[0])
|
|
|
|
{
|
2003-09-17 23:58:28 +00:00
|
|
|
case 'a':
|
|
|
|
if (ctx->state == STATE_ROOT && !strcmp (element_name, "accelerator"))
|
|
|
|
{
|
|
|
|
ctx->state = STATE_ROOT;
|
|
|
|
ctx->current = get_child_node (self, ctx->current,
|
|
|
|
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;
|
|
|
|
|
|
|
|
raise_error = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
2003-08-26 00:13:59 +00:00
|
|
|
case 'u':
|
|
|
|
if (ctx->state == STATE_START && !strcmp (element_name, "ui"))
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
|
|
|
ctx->state = STATE_ROOT;
|
|
|
|
ctx->current = self->private_data->root_node;
|
|
|
|
raise_error = FALSE;
|
|
|
|
|
2003-09-01 22:15:16 +00:00
|
|
|
node_prepend_ui_reference (NODE_INFO (ctx->current),
|
|
|
|
ctx->merge_id, action_quark);
|
2003-08-24 19:58:30 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'm':
|
2003-08-26 00:13:59 +00:00
|
|
|
if (ctx->state == STATE_ROOT && !strcmp (element_name, "menubar"))
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
|
|
|
ctx->state = STATE_MENU;
|
|
|
|
ctx->current = get_child_node (self, ctx->current,
|
|
|
|
node_name, strlen (node_name),
|
2003-09-04 00:15:59 +00:00
|
|
|
NODE_TYPE_MENUBAR,
|
2003-08-24 19:58:30 +00:00
|
|
|
TRUE, FALSE);
|
|
|
|
if (NODE_INFO (ctx->current)->action_name == 0)
|
2003-08-26 00:13:59 +00:00
|
|
|
NODE_INFO (ctx->current)->action_name = action_quark;
|
2003-08-24 19:58:30 +00:00
|
|
|
|
2003-09-01 22:15:16 +00:00
|
|
|
node_prepend_ui_reference (NODE_INFO (ctx->current),
|
|
|
|
ctx->merge_id, action_quark);
|
2003-08-24 19:58:30 +00:00
|
|
|
NODE_INFO (ctx->current)->dirty = TRUE;
|
|
|
|
|
2003-08-26 00:13:59 +00:00
|
|
|
raise_error = FALSE;
|
|
|
|
}
|
|
|
|
else if (ctx->state == STATE_MENU && !strcmp (element_name, "menu"))
|
|
|
|
{
|
|
|
|
ctx->current = get_child_node (self, ctx->current,
|
|
|
|
node_name, strlen (node_name),
|
2003-09-04 00:15:59 +00:00
|
|
|
NODE_TYPE_MENU,
|
2003-08-26 00:13:59 +00:00
|
|
|
TRUE, top);
|
|
|
|
if (NODE_INFO (ctx->current)->action_name == 0)
|
|
|
|
NODE_INFO (ctx->current)->action_name = action_quark;
|
|
|
|
|
2003-09-01 22:15:16 +00:00
|
|
|
node_prepend_ui_reference (NODE_INFO (ctx->current),
|
|
|
|
ctx->merge_id, action_quark);
|
2003-08-26 00:13:59 +00:00
|
|
|
NODE_INFO (ctx->current)->dirty = TRUE;
|
|
|
|
|
2003-08-24 19:58:30 +00:00
|
|
|
raise_error = FALSE;
|
|
|
|
}
|
|
|
|
else if (ctx->state == STATE_MENU && !strcmp (element_name, "menuitem"))
|
|
|
|
{
|
|
|
|
GNode *node;
|
|
|
|
|
|
|
|
ctx->state = STATE_MENUITEM;
|
|
|
|
node = get_child_node (self, ctx->current,
|
|
|
|
node_name, strlen (node_name),
|
2003-09-04 00:15:59 +00:00
|
|
|
NODE_TYPE_MENUITEM,
|
2003-08-24 19:58:30 +00:00
|
|
|
TRUE, top);
|
|
|
|
if (NODE_INFO (node)->action_name == 0)
|
2003-08-26 00:13:59 +00:00
|
|
|
NODE_INFO (node)->action_name = action_quark;
|
2003-08-24 19:58:30 +00:00
|
|
|
|
2003-09-01 22:15:16 +00:00
|
|
|
node_prepend_ui_reference (NODE_INFO (node),
|
|
|
|
ctx->merge_id, action_quark);
|
2003-08-24 19:58:30 +00:00
|
|
|
NODE_INFO (node)->dirty = TRUE;
|
|
|
|
|
|
|
|
raise_error = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'p':
|
Change the XML format: <Root> element is replaced by <ui>, <menu> element
2003-08-28 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Change the XML format:
<Root> element is replaced by <ui>,
<menu> element is replaced by <menubar>,
<submenu> element is replaced by <menu>,
<dockitem> element is replaced by <toolbar>,
<popups> element is gone,
verb attribute is replaced by action,
name defaults to action or the element name.
* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
and GtkRadioActionEntry. GtkActionEntry is simplified by removing
the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
further simplified by removing the callback. The user_data can now be
specified as an argument to gtk_action_group_add_actions(). There is
a new method gtk_action_group_add_radio_actions(), which is similar
to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
and a callback parameter in addition to the user_data. The callback
is connected to the ::changed signal of the first group member.
There are _full() variants taking a GDestroyNotify of
gtk_action_group_add_[radio_]actions().
* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
on every member of the radio group when the active member is changed.
Add an integer property "value", and a getter for the value of "value"
on the currently active group member.
* tests/testactions.c:
* tests/testmerge.c:
* tests/merge-[123].ui:
* demos/gtk-demo/appwindow.c: Adjust to these changes.
* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
2003-08-27 22:22:28 +00:00
|
|
|
if (ctx->state == STATE_ROOT && !strcmp (element_name, "popup"))
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
|
|
|
ctx->state = STATE_MENU;
|
|
|
|
ctx->current = get_child_node (self, ctx->current,
|
|
|
|
node_name, strlen (node_name),
|
2003-09-04 00:15:59 +00:00
|
|
|
NODE_TYPE_POPUP,
|
2003-08-24 19:58:30 +00:00
|
|
|
TRUE, FALSE);
|
|
|
|
if (NODE_INFO (ctx->current)->action_name == 0)
|
2003-08-26 00:13:59 +00:00
|
|
|
NODE_INFO (ctx->current)->action_name = action_quark;
|
2003-08-24 19:58:30 +00:00
|
|
|
|
2003-09-01 22:15:16 +00:00
|
|
|
node_prepend_ui_reference (NODE_INFO (ctx->current),
|
|
|
|
ctx->merge_id, action_quark);
|
2003-08-24 19:58:30 +00:00
|
|
|
NODE_INFO (ctx->current)->dirty = TRUE;
|
|
|
|
|
|
|
|
raise_error = FALSE;
|
|
|
|
}
|
|
|
|
else if ((ctx->state == STATE_MENU || ctx->state == STATE_TOOLBAR) &&
|
|
|
|
!strcmp (element_name, "placeholder"))
|
|
|
|
{
|
2003-08-29 22:42:37 +00:00
|
|
|
if (ctx->state == STATE_TOOLBAR)
|
2003-08-24 19:58:30 +00:00
|
|
|
ctx->current = get_child_node (self, ctx->current,
|
|
|
|
node_name, strlen (node_name),
|
2003-09-04 00:15:59 +00:00
|
|
|
NODE_TYPE_TOOLBAR_PLACEHOLDER,
|
2003-08-24 19:58:30 +00:00
|
|
|
TRUE, top);
|
|
|
|
else
|
|
|
|
ctx->current = get_child_node (self, ctx->current,
|
|
|
|
node_name, strlen (node_name),
|
2003-09-04 00:15:59 +00:00
|
|
|
NODE_TYPE_MENU_PLACEHOLDER,
|
2003-08-24 19:58:30 +00:00
|
|
|
TRUE, top);
|
|
|
|
|
2003-09-01 22:15:16 +00:00
|
|
|
node_prepend_ui_reference (NODE_INFO (ctx->current),
|
|
|
|
ctx->merge_id, action_quark);
|
2003-08-24 19:58:30 +00:00
|
|
|
NODE_INFO (ctx->current)->dirty = TRUE;
|
|
|
|
|
|
|
|
raise_error = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 's':
|
2003-08-26 00:13:59 +00:00
|
|
|
if ((ctx->state == STATE_MENU || ctx->state == STATE_TOOLBAR) &&
|
2003-08-29 22:42:37 +00:00
|
|
|
!strcmp (element_name, "separator"))
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
|
|
|
GNode *node;
|
|
|
|
|
2003-08-29 22:42:37 +00:00
|
|
|
if (ctx->state == STATE_TOOLBAR)
|
2003-08-24 19:58:30 +00:00
|
|
|
ctx->state = STATE_TOOLITEM;
|
2003-08-29 22:42:37 +00:00
|
|
|
else
|
|
|
|
ctx->state = STATE_MENUITEM;
|
2003-08-24 19:58:30 +00:00
|
|
|
node = get_child_node (self, ctx->current,
|
|
|
|
node_name, strlen (node_name),
|
2003-09-04 00:15:59 +00:00
|
|
|
NODE_TYPE_SEPARATOR,
|
2003-08-24 19:58:30 +00:00
|
|
|
TRUE, top);
|
|
|
|
if (NODE_INFO (node)->action_name == 0)
|
2003-08-26 00:13:59 +00:00
|
|
|
NODE_INFO (node)->action_name = action_quark;
|
2003-08-24 19:58:30 +00:00
|
|
|
|
2003-09-01 22:15:16 +00:00
|
|
|
node_prepend_ui_reference (NODE_INFO (node),
|
|
|
|
ctx->merge_id, action_quark);
|
2003-08-24 19:58:30 +00:00
|
|
|
NODE_INFO (node)->dirty = TRUE;
|
|
|
|
|
|
|
|
raise_error = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 't':
|
2003-08-26 00:13:59 +00:00
|
|
|
if (ctx->state == STATE_ROOT && !strcmp (element_name, "toolbar"))
|
|
|
|
{
|
|
|
|
ctx->state = STATE_TOOLBAR;
|
|
|
|
ctx->current = get_child_node (self, ctx->current,
|
|
|
|
node_name, strlen (node_name),
|
2003-09-04 00:15:59 +00:00
|
|
|
NODE_TYPE_TOOLBAR,
|
2003-08-26 00:13:59 +00:00
|
|
|
TRUE, FALSE);
|
|
|
|
if (NODE_INFO (ctx->current)->action_name == 0)
|
|
|
|
NODE_INFO (ctx->current)->action_name = action_quark;
|
|
|
|
|
2003-09-01 22:15:16 +00:00
|
|
|
node_prepend_ui_reference (NODE_INFO (ctx->current),
|
|
|
|
ctx->merge_id, action_quark);
|
2003-08-26 00:13:59 +00:00
|
|
|
NODE_INFO (ctx->current)->dirty = TRUE;
|
|
|
|
|
|
|
|
raise_error = FALSE;
|
|
|
|
}
|
|
|
|
else if (ctx->state == STATE_TOOLBAR && !strcmp (element_name, "toolitem"))
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
|
|
|
GNode *node;
|
|
|
|
|
|
|
|
ctx->state = STATE_TOOLITEM;
|
|
|
|
node = get_child_node (self, ctx->current,
|
|
|
|
node_name, strlen (node_name),
|
2003-09-04 00:15:59 +00:00
|
|
|
NODE_TYPE_TOOLITEM,
|
2003-08-24 19:58:30 +00:00
|
|
|
TRUE, top);
|
|
|
|
if (NODE_INFO (node)->action_name == 0)
|
2003-08-26 00:13:59 +00:00
|
|
|
NODE_INFO (node)->action_name = action_quark;
|
2003-08-24 19:58:30 +00:00
|
|
|
|
2003-09-01 22:15:16 +00:00
|
|
|
node_prepend_ui_reference (NODE_INFO (node),
|
|
|
|
ctx->merge_id, action_quark);
|
2003-08-24 19:58:30 +00:00
|
|
|
NODE_INFO (node)->dirty = TRUE;
|
|
|
|
|
|
|
|
raise_error = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (raise_error)
|
|
|
|
{
|
|
|
|
gint line_number, char_number;
|
|
|
|
|
|
|
|
g_markup_parse_context_get_position (context,
|
|
|
|
&line_number, &char_number);
|
2003-09-04 00:00:14 +00:00
|
|
|
g_set_error (error,
|
|
|
|
G_MARKUP_ERROR,
|
|
|
|
G_MARKUP_ERROR_UNKNOWN_ELEMENT,
|
|
|
|
_("Unexpected start tag '%s' on line %d char %d"),
|
|
|
|
element_name,
|
|
|
|
line_number, char_number);
|
2003-08-24 19:58:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
end_element_handler (GMarkupParseContext *context,
|
|
|
|
const gchar *element_name,
|
|
|
|
gpointer user_data,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
ParseContext *ctx = user_data;
|
|
|
|
|
|
|
|
switch (ctx->state)
|
|
|
|
{
|
|
|
|
case STATE_START:
|
2003-09-04 00:00:14 +00:00
|
|
|
case STATE_END:
|
|
|
|
/* no need to GError here, GMarkup already catches this */
|
2003-08-24 19:58:30 +00:00
|
|
|
break;
|
|
|
|
case STATE_ROOT:
|
|
|
|
ctx->current = NULL;
|
|
|
|
ctx->state = STATE_END;
|
|
|
|
break;
|
|
|
|
case STATE_MENU:
|
2003-09-04 00:00:14 +00:00
|
|
|
case STATE_TOOLBAR:
|
2003-08-24 19:58:30 +00:00
|
|
|
ctx->current = ctx->current->parent;
|
2003-09-04 00:15:59 +00:00
|
|
|
if (NODE_INFO (ctx->current)->type == NODE_TYPE_ROOT)
|
2003-08-24 19:58:30 +00:00
|
|
|
ctx->state = STATE_ROOT;
|
2003-08-29 22:42:37 +00:00
|
|
|
/* else, stay in same state */
|
2003-08-24 19:58:30 +00:00
|
|
|
break;
|
|
|
|
case STATE_MENUITEM:
|
|
|
|
ctx->state = STATE_MENU;
|
|
|
|
break;
|
|
|
|
case STATE_TOOLITEM:
|
|
|
|
ctx->state = STATE_TOOLBAR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cleanup (GMarkupParseContext *context,
|
|
|
|
GError *error,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
ParseContext *ctx = user_data;
|
|
|
|
|
|
|
|
ctx->current = NULL;
|
|
|
|
/* should also walk through the tree and get rid of nodes related to
|
|
|
|
* this UI file's tag */
|
|
|
|
|
2003-09-04 00:00:14 +00:00
|
|
|
gtk_ui_manager_remove_ui (ctx->self, ctx->merge_id);
|
2003-08-24 19:58:30 +00:00
|
|
|
}
|
|
|
|
|
2003-09-17 19:18:45 +00:00
|
|
|
static gboolean
|
|
|
|
xml_isspace (char c)
|
|
|
|
{
|
|
|
|
return c == ' ' || c == '\t' || c == '\n' || c == '\r';
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
text_handler (GMarkupParseContext *context,
|
|
|
|
const gchar *text,
|
|
|
|
gsize text_len,
|
|
|
|
gpointer user_data,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
const gchar *p;
|
|
|
|
const gchar *end;
|
|
|
|
|
|
|
|
p = text;
|
|
|
|
end = text + text_len;
|
|
|
|
while (p != end && xml_isspace (*p))
|
|
|
|
++p;
|
|
|
|
|
|
|
|
if (p != end)
|
|
|
|
{
|
|
|
|
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_INVALID_CONTENT,
|
|
|
|
_("Unexpected character data on line %d char %d"),
|
|
|
|
line_number, char_number);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-24 19:58:30 +00:00
|
|
|
static GMarkupParser ui_parser = {
|
|
|
|
start_element_handler,
|
|
|
|
end_element_handler,
|
2003-09-17 19:18:45 +00:00
|
|
|
text_handler,
|
2003-08-24 19:58:30 +00:00
|
|
|
NULL,
|
|
|
|
cleanup
|
|
|
|
};
|
|
|
|
|
2003-08-26 00:13:59 +00:00
|
|
|
static guint
|
|
|
|
add_ui_from_string (GtkUIManager *self,
|
|
|
|
const gchar *buffer,
|
|
|
|
gssize length,
|
|
|
|
gboolean needs_root,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
ParseContext ctx = { 0 };
|
|
|
|
GMarkupParseContext *context;
|
|
|
|
|
|
|
|
ctx.state = STATE_START;
|
|
|
|
ctx.self = self;
|
|
|
|
ctx.current = NULL;
|
2003-09-01 22:15:16 +00:00
|
|
|
ctx.merge_id = gtk_ui_manager_new_merge_id (self);
|
2003-08-26 00:13:59 +00:00
|
|
|
|
|
|
|
context = g_markup_parse_context_new (&ui_parser, 0, &ctx, NULL);
|
|
|
|
|
|
|
|
if (needs_root)
|
|
|
|
if (!g_markup_parse_context_parse (context, "<ui>", -1, error))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!g_markup_parse_context_parse (context, buffer, length, error))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (needs_root)
|
|
|
|
if (!g_markup_parse_context_parse (context, "</ui>", -1, error))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!g_markup_parse_context_end_parse (context, error))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
g_markup_parse_context_free (context);
|
|
|
|
|
2003-09-01 22:15:16 +00:00
|
|
|
queue_update (self);
|
2003-08-26 00:13:59 +00:00
|
|
|
|
2003-08-29 23:33:54 +00:00
|
|
|
g_signal_emit (self, merge_signals[CHANGED], 0);
|
|
|
|
|
2003-08-26 00:13:59 +00:00
|
|
|
return ctx.merge_id;
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
|
|
|
g_markup_parse_context_free (context);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-08-24 19:58:30 +00:00
|
|
|
/**
|
2003-08-25 23:13:47 +00:00
|
|
|
* gtk_ui_manager_add_ui_from_string:
|
|
|
|
* @self: a #GtkUIManager object
|
2003-08-24 19:58:30 +00:00
|
|
|
* @buffer: the string to parse
|
|
|
|
* @length: the length of @buffer (may be -1 if @buffer is nul-terminated)
|
|
|
|
* @error: return location for an error
|
|
|
|
*
|
2003-09-15 22:21:26 +00:00
|
|
|
* Parses a string containing a <link linkend="XML-UI">UI definition</link> and
|
|
|
|
* merges it with the current contents of @self. An enclosing <ui>
|
2003-08-31 00:27:15 +00:00
|
|
|
* element is added if it is missing.
|
2003-08-24 19:58:30 +00:00
|
|
|
*
|
|
|
|
* Return value: The merge id for the merged UI. The merge id can be used
|
2003-08-25 23:13:47 +00:00
|
|
|
* to unmerge the UI with gtk_ui_manager_remove_ui(). If an error occurred,
|
2003-08-24 19:58:30 +00:00
|
|
|
* the return value is 0.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
**/
|
|
|
|
guint
|
2003-08-25 23:13:47 +00:00
|
|
|
gtk_ui_manager_add_ui_from_string (GtkUIManager *self,
|
2003-08-24 19:58:30 +00:00
|
|
|
const gchar *buffer,
|
2003-08-26 00:13:59 +00:00
|
|
|
gssize length,
|
2003-08-24 19:58:30 +00:00
|
|
|
GError **error)
|
|
|
|
{
|
2003-08-26 00:13:59 +00:00
|
|
|
gboolean needs_root = TRUE;
|
|
|
|
const gchar *p;
|
|
|
|
const gchar *end;
|
2003-08-24 19:58:30 +00:00
|
|
|
|
2003-09-17 23:58:28 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_UI_MANAGER (self), 0);
|
|
|
|
g_return_val_if_fail (buffer != NULL, 0);
|
2003-08-24 19:58:30 +00:00
|
|
|
|
|
|
|
if (length < 0)
|
|
|
|
length = strlen (buffer);
|
|
|
|
|
2003-08-26 00:13:59 +00:00
|
|
|
p = buffer;
|
|
|
|
end = buffer + length;
|
|
|
|
while (p != end && xml_isspace (*p))
|
|
|
|
++p;
|
2003-08-24 19:58:30 +00:00
|
|
|
|
2003-08-26 00:13:59 +00:00
|
|
|
if (end - p >= 4 && strncmp (p, "<ui>", 4) == 0)
|
|
|
|
needs_root = FALSE;
|
|
|
|
|
|
|
|
return add_ui_from_string (self, buffer, length, needs_root, error);
|
2003-08-24 19:58:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2003-08-25 23:13:47 +00:00
|
|
|
* gtk_ui_manager_add_ui_from_file:
|
|
|
|
* @self: a #GtkUIManager object
|
2003-08-24 19:58:30 +00:00
|
|
|
* @filename: the name of the file to parse
|
|
|
|
* @error: return location for an error
|
|
|
|
*
|
2003-09-15 22:21:26 +00:00
|
|
|
* Parses a file containing a <link linkend="XML-UI">UI definition</link> and
|
2003-08-31 00:27:15 +00:00
|
|
|
* merges it with the current contents of @self.
|
2003-08-24 19:58:30 +00:00
|
|
|
*
|
|
|
|
* Return value: The merge id for the merged UI. The merge id can be used
|
2003-08-25 23:13:47 +00:00
|
|
|
* to unmerge the UI with gtk_ui_manager_remove_ui(). If an error occurred,
|
2003-08-24 19:58:30 +00:00
|
|
|
* the return value is 0.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
**/
|
|
|
|
guint
|
2003-08-25 23:13:47 +00:00
|
|
|
gtk_ui_manager_add_ui_from_file (GtkUIManager *self,
|
2003-08-24 19:58:30 +00:00
|
|
|
const gchar *filename,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
gchar *buffer;
|
|
|
|
gint length;
|
|
|
|
guint res;
|
|
|
|
|
2003-09-17 23:58:28 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_UI_MANAGER (self), 0);
|
|
|
|
|
2003-08-24 19:58:30 +00:00
|
|
|
if (!g_file_get_contents (filename, &buffer, &length, error))
|
|
|
|
return 0;
|
|
|
|
|
2003-08-26 00:13:59 +00:00
|
|
|
res = add_ui_from_string (self, buffer, length, FALSE, error);
|
2003-08-24 19:58:30 +00:00
|
|
|
g_free (buffer);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2003-09-01 22:15:16 +00:00
|
|
|
/**
|
|
|
|
* gtk_ui_manager_add_ui:
|
|
|
|
* @self: a #GtkUIManager
|
|
|
|
* @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
|
2003-09-04 20:39:15 +00:00
|
|
|
* @type: the type of UI element to add.
|
|
|
|
* @top: if %TRUE, the UI element is added before its siblings, otherwise it
|
|
|
|
* is added after its siblings.
|
2003-09-01 22:15:16 +00:00
|
|
|
*
|
2003-09-04 20:39:15 +00:00
|
|
|
* Adds a UI element to the current contents of @self.
|
|
|
|
*
|
|
|
|
* If @type is %GTK_UI_MANAGER_AUTO, GTK+ inserts a menuitem, toolitem or
|
|
|
|
* 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.
|
2003-09-01 22:15:16 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
**/
|
|
|
|
void
|
2003-09-04 20:39:15 +00:00
|
|
|
gtk_ui_manager_add_ui (GtkUIManager *self,
|
|
|
|
guint merge_id,
|
|
|
|
const gchar *path,
|
|
|
|
const gchar *name,
|
|
|
|
const gchar *action,
|
|
|
|
GtkUIManagerItemType type,
|
|
|
|
gboolean top)
|
2003-09-01 22:15:16 +00:00
|
|
|
{
|
|
|
|
GNode *node;
|
|
|
|
GNode *child;
|
2003-09-04 20:39:15 +00:00
|
|
|
NodeType node_type;
|
2003-09-01 22:15:16 +00:00
|
|
|
GQuark action_quark = 0;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_UI_MANAGER (self));
|
|
|
|
g_return_if_fail (merge_id > 0);
|
2003-09-04 20:39:15 +00:00
|
|
|
g_return_if_fail (name != NULL);
|
2003-09-01 22:15:16 +00:00
|
|
|
|
2003-09-04 00:15:59 +00:00
|
|
|
node = get_node (self, path, NODE_TYPE_UNDECIDED, FALSE);
|
2003-09-01 22:15:16 +00:00
|
|
|
|
|
|
|
if (node == NULL)
|
|
|
|
return;
|
|
|
|
|
2003-09-04 20:39:15 +00:00
|
|
|
node_type = NODE_TYPE_UNDECIDED;
|
|
|
|
|
2003-09-01 22:15:16 +00:00
|
|
|
switch (NODE_INFO (node)->type)
|
|
|
|
{
|
2003-09-04 20:39:15 +00:00
|
|
|
case NODE_TYPE_MENUBAR:
|
2003-09-04 00:15:59 +00:00
|
|
|
case NODE_TYPE_MENU:
|
|
|
|
case NODE_TYPE_POPUP:
|
|
|
|
case NODE_TYPE_MENU_PLACEHOLDER:
|
2003-09-04 20:39:15 +00:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case GTK_UI_MANAGER_AUTO:
|
|
|
|
if (action != NULL)
|
|
|
|
node_type = NODE_TYPE_MENUITEM;
|
|
|
|
else
|
|
|
|
node_type = NODE_TYPE_SEPARATOR;
|
|
|
|
break;
|
|
|
|
case GTK_UI_MANAGER_MENU:
|
|
|
|
node_type = NODE_TYPE_MENU;
|
|
|
|
break;
|
|
|
|
case GTK_UI_MANAGER_MENUITEM:
|
|
|
|
node_type = NODE_TYPE_MENUITEM;
|
|
|
|
break;
|
|
|
|
case GTK_UI_MANAGER_SEPARATOR:
|
|
|
|
node_type = NODE_TYPE_SEPARATOR;
|
|
|
|
break;
|
|
|
|
case GTK_UI_MANAGER_PLACEHOLDER:
|
|
|
|
node_type = NODE_TYPE_MENU_PLACEHOLDER;
|
|
|
|
break;
|
|
|
|
default: ;
|
|
|
|
/* do nothing */
|
|
|
|
}
|
2003-09-01 22:15:16 +00:00
|
|
|
break;
|
2003-09-04 00:15:59 +00:00
|
|
|
case NODE_TYPE_TOOLBAR:
|
|
|
|
case NODE_TYPE_TOOLBAR_PLACEHOLDER:
|
2003-09-04 20:39:15 +00:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case GTK_UI_MANAGER_AUTO:
|
|
|
|
if (action != NULL)
|
|
|
|
node_type = NODE_TYPE_TOOLITEM;
|
|
|
|
else
|
|
|
|
node_type = NODE_TYPE_SEPARATOR;
|
|
|
|
break;
|
|
|
|
case GTK_UI_MANAGER_TOOLITEM:
|
|
|
|
node_type = NODE_TYPE_TOOLITEM;
|
|
|
|
break;
|
|
|
|
case GTK_UI_MANAGER_SEPARATOR:
|
|
|
|
node_type = NODE_TYPE_SEPARATOR;
|
|
|
|
break;
|
|
|
|
case GTK_UI_MANAGER_PLACEHOLDER:
|
|
|
|
node_type = NODE_TYPE_MENU_PLACEHOLDER;
|
|
|
|
break;
|
|
|
|
default: ;
|
|
|
|
/* do nothing */
|
|
|
|
}
|
2003-09-01 22:15:16 +00:00
|
|
|
break;
|
2003-09-04 20:39:15 +00:00
|
|
|
case NODE_TYPE_ROOT:
|
|
|
|
switch (type)
|
2003-09-01 22:15:16 +00:00
|
|
|
{
|
2003-09-04 20:39:15 +00:00
|
|
|
case GTK_UI_MANAGER_MENUBAR:
|
|
|
|
node_type = NODE_TYPE_MENUBAR;
|
2003-09-01 22:15:16 +00:00
|
|
|
break;
|
2003-09-04 20:39:15 +00:00
|
|
|
case GTK_UI_MANAGER_TOOLBAR:
|
|
|
|
node_type = NODE_TYPE_TOOLBAR;
|
2003-09-01 22:15:16 +00:00
|
|
|
break;
|
2003-09-04 20:39:15 +00:00
|
|
|
case GTK_UI_MANAGER_POPUP:
|
|
|
|
node_type = NODE_TYPE_POPUP;
|
2003-09-01 22:15:16 +00:00
|
|
|
break;
|
2003-09-17 23:58:28 +00:00
|
|
|
case GTK_UI_MANAGER_ACCELERATOR:
|
|
|
|
node_type = NODE_TYPE_ACCELERATOR;
|
|
|
|
break;
|
2003-09-04 20:39:15 +00:00
|
|
|
default: ;
|
|
|
|
/* do nothing */
|
2003-09-01 22:15:16 +00:00
|
|
|
}
|
2003-09-04 20:39:15 +00:00
|
|
|
break;
|
|
|
|
default: ;
|
|
|
|
/* do nothing */
|
2003-09-01 22:15:16 +00:00
|
|
|
}
|
2003-09-04 20:39:15 +00:00
|
|
|
|
|
|
|
if (node_type == NODE_TYPE_UNDECIDED)
|
|
|
|
return;
|
|
|
|
|
2003-09-01 22:15:16 +00:00
|
|
|
child = get_child_node (self, node,
|
|
|
|
name, strlen (name),
|
2003-09-04 20:39:15 +00:00
|
|
|
node_type, TRUE, top);
|
2003-09-01 22:15:16 +00:00
|
|
|
|
|
|
|
if (action != NULL)
|
|
|
|
action_quark = g_quark_from_string (action);
|
|
|
|
|
|
|
|
node_prepend_ui_reference (NODE_INFO (child),
|
|
|
|
merge_id, action_quark);
|
|
|
|
|
|
|
|
if (NODE_INFO (node)->action_name == 0)
|
|
|
|
NODE_INFO (child)->action_name = action_quark;
|
|
|
|
|
|
|
|
NODE_INFO (child)->dirty = TRUE;
|
|
|
|
|
|
|
|
queue_update (self);
|
2003-09-04 20:39:15 +00:00
|
|
|
|
|
|
|
g_signal_emit (self, merge_signals[CHANGED], 0);
|
2003-09-01 22:15:16 +00:00
|
|
|
}
|
|
|
|
|
2003-08-24 19:58:30 +00:00
|
|
|
static gboolean
|
|
|
|
remove_ui (GNode *node,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
guint merge_id = GPOINTER_TO_UINT (user_data);
|
|
|
|
|
2003-09-01 22:15:16 +00:00
|
|
|
node_remove_ui_reference (NODE_INFO (node), merge_id);
|
2003-08-24 19:58:30 +00:00
|
|
|
|
|
|
|
return FALSE; /* continue */
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2003-08-25 23:13:47 +00:00
|
|
|
* gtk_ui_manager_remove_ui:
|
|
|
|
* @self: a #GtkUIManager object
|
|
|
|
* @merge_id: a merge id as returned by gtk_ui_manager_add_ui_from_string()
|
2003-08-24 19:58:30 +00:00
|
|
|
*
|
|
|
|
* Unmerges the part of @self<!-- -->s content identified by @merge_id.
|
2003-08-24 20:48:27 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-08-24 19:58:30 +00:00
|
|
|
**/
|
|
|
|
void
|
2003-08-25 23:13:47 +00:00
|
|
|
gtk_ui_manager_remove_ui (GtkUIManager *self,
|
2003-08-24 19:58:30 +00:00
|
|
|
guint merge_id)
|
|
|
|
{
|
2003-09-01 22:15:16 +00:00
|
|
|
g_node_traverse (self->private_data->root_node,
|
|
|
|
G_POST_ORDER, G_TRAVERSE_ALL, -1,
|
2003-08-24 19:58:30 +00:00
|
|
|
remove_ui, GUINT_TO_POINTER (merge_id));
|
|
|
|
|
2003-09-01 22:15:16 +00:00
|
|
|
queue_update (self);
|
2003-08-29 23:33:54 +00:00
|
|
|
|
|
|
|
g_signal_emit (self, merge_signals[CHANGED], 0);
|
2003-08-24 19:58:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------- Updates -------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
static GtkAction *
|
2003-08-25 23:13:47 +00:00
|
|
|
get_action_by_name (GtkUIManager *merge,
|
2003-08-24 19:58:30 +00:00
|
|
|
const char *action_name)
|
|
|
|
{
|
|
|
|
GList *tmp;
|
|
|
|
|
|
|
|
if (!action_name)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* lookup name */
|
|
|
|
for (tmp = merge->private_data->action_groups; tmp != NULL; tmp = tmp->next)
|
|
|
|
{
|
|
|
|
GtkActionGroup *action_group = tmp->data;
|
|
|
|
GtkAction *action;
|
|
|
|
|
|
|
|
action = gtk_action_group_get_action (action_group, action_name);
|
|
|
|
|
|
|
|
if (action)
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
find_menu_position (GNode *node,
|
|
|
|
GtkWidget **menushell_p,
|
|
|
|
gint *pos_p)
|
|
|
|
{
|
|
|
|
GtkWidget *menushell;
|
|
|
|
gint pos;
|
|
|
|
|
|
|
|
g_return_val_if_fail (node != NULL, FALSE);
|
2003-09-04 00:15:59 +00:00
|
|
|
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,
|
2003-08-24 19:58:30 +00:00
|
|
|
FALSE);
|
|
|
|
|
|
|
|
/* first sibling -- look at parent */
|
|
|
|
if (node->prev == NULL)
|
|
|
|
{
|
|
|
|
GNode *parent;
|
2003-08-29 22:42:37 +00:00
|
|
|
GList *siblings;
|
2003-08-24 19:58:30 +00:00
|
|
|
|
|
|
|
parent = node->parent;
|
|
|
|
switch (NODE_INFO (parent)->type)
|
|
|
|
{
|
2003-09-04 00:15:59 +00:00
|
|
|
case NODE_TYPE_MENUBAR:
|
|
|
|
case NODE_TYPE_POPUP:
|
2003-08-24 19:58:30 +00:00
|
|
|
menushell = NODE_INFO (parent)->proxy;
|
|
|
|
pos = 0;
|
|
|
|
break;
|
2003-09-04 00:15:59 +00:00
|
|
|
case NODE_TYPE_MENU:
|
2003-08-24 19:58:30 +00:00
|
|
|
menushell = NODE_INFO (parent)->proxy;
|
|
|
|
if (GTK_IS_MENU_ITEM (menushell))
|
|
|
|
menushell = gtk_menu_item_get_submenu (GTK_MENU_ITEM (menushell));
|
2003-08-29 22:42:37 +00:00
|
|
|
siblings = gtk_container_get_children (GTK_CONTAINER (menushell));
|
|
|
|
if (siblings != NULL && GTK_IS_TEAROFF_MENU_ITEM (siblings->data))
|
|
|
|
pos = 1;
|
|
|
|
else
|
|
|
|
pos = 0;
|
2003-08-24 19:58:30 +00:00
|
|
|
break;
|
2003-09-04 00:15:59 +00:00
|
|
|
case NODE_TYPE_MENU_PLACEHOLDER:
|
2003-08-24 19:58:30 +00:00
|
|
|
menushell = gtk_widget_get_parent (NODE_INFO (parent)->proxy);
|
|
|
|
g_return_val_if_fail (GTK_IS_MENU_SHELL (menushell), FALSE);
|
|
|
|
pos = g_list_index (GTK_MENU_SHELL (menushell)->children,
|
|
|
|
NODE_INFO (parent)->proxy) + 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_warning("%s: bad parent node type %d", G_STRLOC,
|
|
|
|
NODE_INFO (parent)->type);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkWidget *prev_child;
|
|
|
|
GNode *sibling;
|
|
|
|
|
|
|
|
sibling = node->prev;
|
2003-09-04 00:15:59 +00:00
|
|
|
if (NODE_INFO (sibling)->type == NODE_TYPE_MENU_PLACEHOLDER)
|
2003-08-24 19:58:30 +00:00
|
|
|
prev_child = NODE_INFO (sibling)->extra; /* second Separator */
|
|
|
|
else
|
|
|
|
prev_child = NODE_INFO (sibling)->proxy;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_WIDGET (prev_child), FALSE);
|
|
|
|
menushell = gtk_widget_get_parent (prev_child);
|
|
|
|
g_return_val_if_fail (GTK_IS_MENU_SHELL (menushell), FALSE);
|
|
|
|
|
|
|
|
pos = g_list_index (GTK_MENU_SHELL (menushell)->children, prev_child) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (menushell_p)
|
|
|
|
*menushell_p = menushell;
|
|
|
|
if (pos_p)
|
|
|
|
*pos_p = pos;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
find_toolbar_position (GNode *node,
|
|
|
|
GtkWidget **toolbar_p,
|
|
|
|
gint *pos_p)
|
|
|
|
{
|
|
|
|
GtkWidget *toolbar;
|
|
|
|
gint pos;
|
|
|
|
|
|
|
|
g_return_val_if_fail (node != NULL, FALSE);
|
2003-09-04 00:15:59 +00:00
|
|
|
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,
|
2003-08-24 19:58:30 +00:00
|
|
|
FALSE);
|
|
|
|
|
|
|
|
/* first sibling -- look at parent */
|
|
|
|
if (node->prev == NULL)
|
|
|
|
{
|
|
|
|
GNode *parent;
|
|
|
|
|
|
|
|
parent = node->parent;
|
|
|
|
switch (NODE_INFO (parent)->type)
|
|
|
|
{
|
2003-09-04 00:15:59 +00:00
|
|
|
case NODE_TYPE_TOOLBAR:
|
2003-08-24 19:58:30 +00:00
|
|
|
toolbar = NODE_INFO (parent)->proxy;
|
|
|
|
pos = 0;
|
|
|
|
break;
|
2003-09-04 00:15:59 +00:00
|
|
|
case NODE_TYPE_TOOLBAR_PLACEHOLDER:
|
2003-08-24 19:58:30 +00:00
|
|
|
toolbar = gtk_widget_get_parent (NODE_INFO (parent)->proxy);
|
|
|
|
g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
|
|
|
|
pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (toolbar),
|
|
|
|
GTK_TOOL_ITEM (NODE_INFO (parent)->proxy)) + 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_warning ("%s: bad parent node type %d", G_STRLOC,
|
|
|
|
NODE_INFO (parent)->type);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkWidget *prev_child;
|
|
|
|
GNode *sibling;
|
|
|
|
|
|
|
|
sibling = node->prev;
|
2003-09-04 00:15:59 +00:00
|
|
|
if (NODE_INFO (sibling)->type == NODE_TYPE_TOOLBAR_PLACEHOLDER)
|
2003-08-24 19:58:30 +00:00
|
|
|
prev_child = NODE_INFO (sibling)->extra; /* second Separator */
|
|
|
|
else
|
|
|
|
prev_child = NODE_INFO (sibling)->proxy;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_WIDGET (prev_child), FALSE);
|
|
|
|
toolbar = gtk_widget_get_parent (prev_child);
|
|
|
|
g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), 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)
|
|
|
|
*pos_p = pos;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-09-15 20:35:28 +00:00
|
|
|
enum {
|
|
|
|
SEPARATOR_MODE_SMART,
|
|
|
|
SEPARATOR_MODE_VISIBLE,
|
|
|
|
SEPARATOR_MODE_HIDDEN
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_smart_separators (GtkWidget *proxy)
|
|
|
|
{
|
|
|
|
GtkWidget *parent = NULL;
|
|
|
|
|
|
|
|
if (GTK_IS_MENU (proxy) || GTK_IS_TOOLBAR (proxy))
|
|
|
|
parent = proxy;
|
|
|
|
else if (GTK_IS_MENU_ITEM (proxy) || GTK_IS_TOOL_ITEM (proxy))
|
|
|
|
parent = gtk_widget_get_parent (proxy);
|
|
|
|
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
gboolean visible;
|
|
|
|
GList *children, *cur, *last;
|
|
|
|
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (parent));
|
|
|
|
|
|
|
|
visible = FALSE;
|
|
|
|
last = NULL;
|
|
|
|
cur = children;
|
|
|
|
while (cur)
|
|
|
|
{
|
|
|
|
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),
|
|
|
|
"gtk-separator-mode"));
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case SEPARATOR_MODE_VISIBLE:
|
|
|
|
gtk_widget_show (GTK_WIDGET (cur->data));
|
|
|
|
last = NULL;
|
|
|
|
visible = FALSE;
|
|
|
|
break;
|
|
|
|
case SEPARATOR_MODE_HIDDEN:
|
|
|
|
gtk_widget_hide (GTK_WIDGET (cur->data));
|
|
|
|
break;
|
|
|
|
case SEPARATOR_MODE_SMART:
|
|
|
|
if (visible)
|
|
|
|
{
|
|
|
|
gtk_widget_show (GTK_WIDGET (cur->data));
|
|
|
|
last = cur;
|
|
|
|
visible = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gtk_widget_hide (GTK_WIDGET (cur->data));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (GTK_WIDGET_VISIBLE (cur->data))
|
|
|
|
{
|
|
|
|
last = NULL;
|
|
|
|
if (GTK_IS_TEAROFF_MENU_ITEM (cur->data))
|
|
|
|
visible = FALSE;
|
|
|
|
else
|
|
|
|
visible = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last)
|
|
|
|
gtk_widget_hide (GTK_WIDGET (last->data));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-24 19:58:30 +00:00
|
|
|
static void
|
2003-08-25 23:13:47 +00:00
|
|
|
update_node (GtkUIManager *self,
|
2003-08-29 22:42:37 +00:00
|
|
|
GNode *node,
|
|
|
|
gboolean add_tearoffs)
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
2003-09-04 00:15:59 +00:00
|
|
|
Node *info;
|
2003-08-24 19:58:30 +00:00
|
|
|
GNode *child;
|
|
|
|
GtkAction *action;
|
2003-08-25 23:13:47 +00:00
|
|
|
#ifdef DEBUG_UI_MANAGER
|
2003-08-24 19:58:30 +00:00
|
|
|
GList *tmp;
|
|
|
|
#endif
|
2003-08-29 22:42:37 +00:00
|
|
|
|
2003-08-24 19:58:30 +00:00
|
|
|
g_return_if_fail (node != NULL);
|
|
|
|
g_return_if_fail (NODE_INFO (node) != NULL);
|
|
|
|
|
|
|
|
info = NODE_INFO (node);
|
|
|
|
|
2003-08-25 23:13:47 +00:00
|
|
|
#ifdef DEBUG_UI_MANAGER
|
2003-08-24 19:58:30 +00:00
|
|
|
g_print ("update_node name=%s dirty=%d (", info->name, info->dirty);
|
|
|
|
for (tmp = info->uifiles; tmp != NULL; tmp = tmp->next)
|
|
|
|
{
|
|
|
|
NodeUIReference *ref = tmp->data;
|
|
|
|
g_print("%s:%u", g_quark_to_string (ref->action_quark), ref->merge_id);
|
|
|
|
if (tmp->next)
|
|
|
|
g_print (", ");
|
|
|
|
}
|
|
|
|
g_print (")\n");
|
|
|
|
#endif
|
|
|
|
|
2003-08-29 22:42:37 +00:00
|
|
|
if (info->dirty)
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
2003-08-29 22:42:37 +00:00
|
|
|
info->dirty = FALSE;
|
2003-08-24 19:58:30 +00:00
|
|
|
|
|
|
|
/* Check if the node doesn't have an action and must have an action */
|
|
|
|
if (action == NULL &&
|
2003-09-17 22:44:01 +00:00
|
|
|
info->type != NODE_TYPE_ROOT &&
|
2003-09-04 00:15:59 +00:00
|
|
|
info->type != NODE_TYPE_MENUBAR &&
|
|
|
|
info->type != NODE_TYPE_TOOLBAR &&
|
|
|
|
info->type != NODE_TYPE_SEPARATOR &&
|
|
|
|
info->type != NODE_TYPE_MENU_PLACEHOLDER &&
|
|
|
|
info->type != NODE_TYPE_TOOLBAR_PLACEHOLDER)
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
2003-09-17 22:44:01 +00:00
|
|
|
g_warning ("%s: missing action", info->name);
|
|
|
|
|
2003-08-24 19:58:30 +00:00
|
|
|
goto recurse_children;
|
|
|
|
}
|
|
|
|
|
2003-09-17 23:58:28 +00:00
|
|
|
if (action)
|
|
|
|
gtk_action_set_accel_group (action, self->private_data->accel_group);
|
|
|
|
|
2003-08-24 19:58:30 +00:00
|
|
|
/* If the widget already has a proxy and the action hasn't changed, then
|
2003-08-29 22:42:37 +00:00
|
|
|
* we only have to update the tearoff menu items.
|
2003-08-24 19:58:30 +00:00
|
|
|
*/
|
2003-08-29 22:42:37 +00:00
|
|
|
if (info->proxy != NULL && action == info->action)
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
2003-09-04 00:15:59 +00:00
|
|
|
if (info->type == NODE_TYPE_MENU)
|
2003-08-29 22:42:37 +00:00
|
|
|
{
|
|
|
|
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", add_tearoffs, 0);
|
|
|
|
}
|
|
|
|
|
2003-08-24 19:58:30 +00:00
|
|
|
goto recurse_children;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (info->type)
|
|
|
|
{
|
2003-09-04 00:15:59 +00:00
|
|
|
case NODE_TYPE_MENUBAR:
|
2003-08-24 19:58:30 +00:00
|
|
|
if (info->proxy == NULL)
|
|
|
|
{
|
|
|
|
info->proxy = gtk_menu_bar_new ();
|
|
|
|
gtk_widget_show (info->proxy);
|
|
|
|
g_signal_emit (self, merge_signals[ADD_WIDGET], 0, info->proxy);
|
|
|
|
}
|
|
|
|
break;
|
2003-09-04 00:15:59 +00:00
|
|
|
case NODE_TYPE_POPUP:
|
Change the XML format: <Root> element is replaced by <ui>, <menu> element
2003-08-28 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Change the XML format:
<Root> element is replaced by <ui>,
<menu> element is replaced by <menubar>,
<submenu> element is replaced by <menu>,
<dockitem> element is replaced by <toolbar>,
<popups> element is gone,
verb attribute is replaced by action,
name defaults to action or the element name.
* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
and GtkRadioActionEntry. GtkActionEntry is simplified by removing
the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
further simplified by removing the callback. The user_data can now be
specified as an argument to gtk_action_group_add_actions(). There is
a new method gtk_action_group_add_radio_actions(), which is similar
to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
and a callback parameter in addition to the user_data. The callback
is connected to the ::changed signal of the first group member.
There are _full() variants taking a GDestroyNotify of
gtk_action_group_add_[radio_]actions().
* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
on every member of the radio group when the active member is changed.
Add an integer property "value", and a getter for the value of "value"
on the currently active group member.
* tests/testactions.c:
* tests/testmerge.c:
* tests/merge-[123].ui:
* demos/gtk-demo/appwindow.c: Adjust to these changes.
* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
2003-08-27 22:22:28 +00:00
|
|
|
if (info->proxy == NULL)
|
2003-09-17 23:58:28 +00:00
|
|
|
info->proxy = gtk_menu_new ();
|
2003-08-24 19:58:30 +00:00
|
|
|
break;
|
2003-09-04 00:15:59 +00:00
|
|
|
case NODE_TYPE_MENU:
|
Change the XML format: <Root> element is replaced by <ui>, <menu> element
2003-08-28 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Change the XML format:
<Root> element is replaced by <ui>,
<menu> element is replaced by <menubar>,
<submenu> element is replaced by <menu>,
<dockitem> element is replaced by <toolbar>,
<popups> element is gone,
verb attribute is replaced by action,
name defaults to action or the element name.
* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
and GtkRadioActionEntry. GtkActionEntry is simplified by removing
the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
further simplified by removing the callback. The user_data can now be
specified as an argument to gtk_action_group_add_actions(). There is
a new method gtk_action_group_add_radio_actions(), which is similar
to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
and a callback parameter in addition to the user_data. The callback
is connected to the ::changed signal of the first group member.
There are _full() variants taking a GDestroyNotify of
gtk_action_group_add_[radio_]actions().
* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
on every member of the radio group when the active member is changed.
Add an integer property "value", and a getter for the value of "value"
on the currently active group member.
* tests/testactions.c:
* tests/testmerge.c:
* tests/merge-[123].ui:
* demos/gtk-demo/appwindow.c: Adjust to these changes.
* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
2003-08-27 22:22:28 +00:00
|
|
|
{
|
|
|
|
GtkWidget *prev_submenu = NULL;
|
2003-08-29 22:42:37 +00:00
|
|
|
GtkWidget *menu;
|
|
|
|
GList *siblings;
|
Change the XML format: <Root> element is replaced by <ui>, <menu> element
2003-08-28 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Change the XML format:
<Root> element is replaced by <ui>,
<menu> element is replaced by <menubar>,
<submenu> element is replaced by <menu>,
<dockitem> element is replaced by <toolbar>,
<popups> element is gone,
verb attribute is replaced by action,
name defaults to action or the element name.
* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
and GtkRadioActionEntry. GtkActionEntry is simplified by removing
the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
further simplified by removing the callback. The user_data can now be
specified as an argument to gtk_action_group_add_actions(). There is
a new method gtk_action_group_add_radio_actions(), which is similar
to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
and a callback parameter in addition to the user_data. The callback
is connected to the ::changed signal of the first group member.
There are _full() variants taking a GDestroyNotify of
gtk_action_group_add_[radio_]actions().
* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
on every member of the radio group when the active member is changed.
Add an integer property "value", and a getter for the value of "value"
on the currently active group member.
* tests/testactions.c:
* tests/testmerge.c:
* tests/merge-[123].ui:
* demos/gtk-demo/appwindow.c: Adjust to these changes.
* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
2003-08-27 22:22:28 +00:00
|
|
|
/* remove the proxy if it is of the wrong type ... */
|
|
|
|
if (info->proxy && G_OBJECT_TYPE (info->proxy) !=
|
2003-09-06 23:52:00 +00:00
|
|
|
GTK_ACTION_GET_CLASS (action)->menu_item_type)
|
Change the XML format: <Root> element is replaced by <ui>, <menu> element
2003-08-28 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Change the XML format:
<Root> element is replaced by <ui>,
<menu> element is replaced by <menubar>,
<submenu> element is replaced by <menu>,
<dockitem> element is replaced by <toolbar>,
<popups> element is gone,
verb attribute is replaced by action,
name defaults to action or the element name.
* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
and GtkRadioActionEntry. GtkActionEntry is simplified by removing
the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
further simplified by removing the callback. The user_data can now be
specified as an argument to gtk_action_group_add_actions(). There is
a new method gtk_action_group_add_radio_actions(), which is similar
to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
and a callback parameter in addition to the user_data. The callback
is connected to the ::changed signal of the first group member.
There are _full() variants taking a GDestroyNotify of
gtk_action_group_add_[radio_]actions().
* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
on every member of the radio group when the active member is changed.
Add an integer property "value", and a getter for the value of "value"
on the currently active group member.
* tests/testactions.c:
* tests/testmerge.c:
* tests/merge-[123].ui:
* demos/gtk-demo/appwindow.c: Adjust to these changes.
* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
2003-08-27 22:22:28 +00:00
|
|
|
{
|
|
|
|
prev_submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (info->proxy));
|
|
|
|
if (prev_submenu)
|
|
|
|
{
|
|
|
|
g_object_ref (prev_submenu);
|
2003-08-29 22:42:37 +00:00
|
|
|
gtk_menu_item_set_submenu (GTK_MENU_ITEM (info->proxy), NULL);
|
Change the XML format: <Root> element is replaced by <ui>, <menu> element
2003-08-28 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Change the XML format:
<Root> element is replaced by <ui>,
<menu> element is replaced by <menubar>,
<submenu> element is replaced by <menu>,
<dockitem> element is replaced by <toolbar>,
<popups> element is gone,
verb attribute is replaced by action,
name defaults to action or the element name.
* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
and GtkRadioActionEntry. GtkActionEntry is simplified by removing
the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
further simplified by removing the callback. The user_data can now be
specified as an argument to gtk_action_group_add_actions(). There is
a new method gtk_action_group_add_radio_actions(), which is similar
to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
and a callback parameter in addition to the user_data. The callback
is connected to the ::changed signal of the first group member.
There are _full() variants taking a GDestroyNotify of
gtk_action_group_add_[radio_]actions().
* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
on every member of the radio group when the active member is changed.
Add an integer property "value", and a getter for the value of "value"
on the currently active group member.
* tests/testactions.c:
* tests/testmerge.c:
* tests/merge-[123].ui:
* demos/gtk-demo/appwindow.c: Adjust to these changes.
* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
2003-08-27 22:22:28 +00:00
|
|
|
}
|
2003-09-06 23:52:00 +00:00
|
|
|
gtk_action_disconnect_proxy (info->action, info->proxy);
|
Change the XML format: <Root> element is replaced by <ui>, <menu> element
2003-08-28 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Change the XML format:
<Root> element is replaced by <ui>,
<menu> element is replaced by <menubar>,
<submenu> element is replaced by <menu>,
<dockitem> element is replaced by <toolbar>,
<popups> element is gone,
verb attribute is replaced by action,
name defaults to action or the element name.
* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
and GtkRadioActionEntry. GtkActionEntry is simplified by removing
the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
further simplified by removing the callback. The user_data can now be
specified as an argument to gtk_action_group_add_actions(). There is
a new method gtk_action_group_add_radio_actions(), which is similar
to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
and a callback parameter in addition to the user_data. The callback
is connected to the ::changed signal of the first group member.
There are _full() variants taking a GDestroyNotify of
gtk_action_group_add_[radio_]actions().
* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
on every member of the radio group when the active member is changed.
Add an integer property "value", and a getter for the value of "value"
on the currently active group member.
* tests/testactions.c:
* tests/testmerge.c:
* tests/merge-[123].ui:
* demos/gtk-demo/appwindow.c: Adjust to these changes.
* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
2003-08-27 22:22:28 +00:00
|
|
|
gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
|
|
|
|
info->proxy);
|
|
|
|
info->proxy = NULL;
|
|
|
|
}
|
|
|
|
/* create proxy if needed ... */
|
|
|
|
if (info->proxy == NULL)
|
|
|
|
{
|
|
|
|
GtkWidget *menushell;
|
|
|
|
gint pos;
|
|
|
|
|
|
|
|
if (find_menu_position (node, &menushell, &pos))
|
|
|
|
{
|
2003-09-06 23:52:00 +00:00
|
|
|
GtkWidget *tearoff;
|
|
|
|
|
|
|
|
info->proxy = gtk_action_create_menu_item (action);
|
Change the XML format: <Root> element is replaced by <ui>, <menu> element
2003-08-28 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Change the XML format:
<Root> element is replaced by <ui>,
<menu> element is replaced by <menubar>,
<submenu> element is replaced by <menu>,
<dockitem> element is replaced by <toolbar>,
<popups> element is gone,
verb attribute is replaced by action,
name defaults to action or the element name.
* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
and GtkRadioActionEntry. GtkActionEntry is simplified by removing
the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
further simplified by removing the callback. The user_data can now be
specified as an argument to gtk_action_group_add_actions(). There is
a new method gtk_action_group_add_radio_actions(), which is similar
to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
and a callback parameter in addition to the user_data. The callback
is connected to the ::changed signal of the first group member.
There are _full() variants taking a GDestroyNotify of
gtk_action_group_add_[radio_]actions().
* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
on every member of the radio group when the active member is changed.
Add an integer property "value", and a getter for the value of "value"
on the currently active group member.
* tests/testactions.c:
* tests/testmerge.c:
* tests/merge-[123].ui:
* demos/gtk-demo/appwindow.c: Adjust to these changes.
* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
2003-08-27 22:22:28 +00:00
|
|
|
menu = gtk_menu_new ();
|
2003-09-06 23:52:00 +00:00
|
|
|
tearoff = gtk_tearoff_menu_item_new ();
|
2003-08-29 22:42:37 +00:00
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), tearoff);
|
Change the XML format: <Root> element is replaced by <ui>, <menu> element
2003-08-28 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Change the XML format:
<Root> element is replaced by <ui>,
<menu> element is replaced by <menubar>,
<submenu> element is replaced by <menu>,
<dockitem> element is replaced by <toolbar>,
<popups> element is gone,
verb attribute is replaced by action,
name defaults to action or the element name.
* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
and GtkRadioActionEntry. GtkActionEntry is simplified by removing
the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
further simplified by removing the callback. The user_data can now be
specified as an argument to gtk_action_group_add_actions(). There is
a new method gtk_action_group_add_radio_actions(), which is similar
to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
and a callback parameter in addition to the user_data. The callback
is connected to the ::changed signal of the first group member.
There are _full() variants taking a GDestroyNotify of
gtk_action_group_add_[radio_]actions().
* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
on every member of the radio group when the active member is changed.
Add an integer property "value", and a getter for the value of "value"
on the currently active group member.
* tests/testactions.c:
* tests/testmerge.c:
* tests/merge-[123].ui:
* demos/gtk-demo/appwindow.c: Adjust to these changes.
* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
2003-08-27 22:22:28 +00:00
|
|
|
gtk_menu_item_set_submenu (GTK_MENU_ITEM (info->proxy), menu);
|
|
|
|
gtk_menu_shell_insert (GTK_MENU_SHELL (menushell), info->proxy, pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2003-09-06 23:52:00 +00:00
|
|
|
gtk_action_connect_proxy (action, info->proxy);
|
Change the XML format: <Root> element is replaced by <ui>, <menu> element
2003-08-28 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Change the XML format:
<Root> element is replaced by <ui>,
<menu> element is replaced by <menubar>,
<submenu> element is replaced by <menu>,
<dockitem> element is replaced by <toolbar>,
<popups> element is gone,
verb attribute is replaced by action,
name defaults to action or the element name.
* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
and GtkRadioActionEntry. GtkActionEntry is simplified by removing
the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
further simplified by removing the callback. The user_data can now be
specified as an argument to gtk_action_group_add_actions(). There is
a new method gtk_action_group_add_radio_actions(), which is similar
to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
and a callback parameter in addition to the user_data. The callback
is connected to the ::changed signal of the first group member.
There are _full() variants taking a GDestroyNotify of
gtk_action_group_add_[radio_]actions().
* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
on every member of the radio group when the active member is changed.
Add an integer property "value", and a getter for the value of "value"
on the currently active group member.
* tests/testactions.c:
* tests/testmerge.c:
* tests/merge-[123].ui:
* demos/gtk-demo/appwindow.c: Adjust to these changes.
* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
2003-08-27 22:22:28 +00:00
|
|
|
if (prev_submenu)
|
|
|
|
{
|
|
|
|
gtk_menu_item_set_submenu (GTK_MENU_ITEM (info->proxy),
|
|
|
|
prev_submenu);
|
|
|
|
g_object_unref (prev_submenu);
|
|
|
|
}
|
2003-08-29 22:42:37 +00:00
|
|
|
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", add_tearoffs, 0);
|
Change the XML format: <Root> element is replaced by <ui>, <menu> element
2003-08-28 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Change the XML format:
<Root> element is replaced by <ui>,
<menu> element is replaced by <menubar>,
<submenu> element is replaced by <menu>,
<dockitem> element is replaced by <toolbar>,
<popups> element is gone,
verb attribute is replaced by action,
name defaults to action or the element name.
* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
and GtkRadioActionEntry. GtkActionEntry is simplified by removing
the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
further simplified by removing the callback. The user_data can now be
specified as an argument to gtk_action_group_add_actions(). There is
a new method gtk_action_group_add_radio_actions(), which is similar
to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
and a callback parameter in addition to the user_data. The callback
is connected to the ::changed signal of the first group member.
There are _full() variants taking a GDestroyNotify of
gtk_action_group_add_[radio_]actions().
* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
on every member of the radio group when the active member is changed.
Add an integer property "value", and a getter for the value of "value"
on the currently active group member.
* tests/testactions.c:
* tests/testmerge.c:
* tests/merge-[123].ui:
* demos/gtk-demo/appwindow.c: Adjust to these changes.
* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
2003-08-27 22:22:28 +00:00
|
|
|
}
|
|
|
|
break;
|
2003-09-04 00:15:59 +00:00
|
|
|
case NODE_TYPE_UNDECIDED:
|
2003-08-24 19:58:30 +00:00
|
|
|
g_warning ("found 'undecided node!");
|
|
|
|
break;
|
2003-09-04 00:15:59 +00:00
|
|
|
case NODE_TYPE_ROOT:
|
2003-08-24 19:58:30 +00:00
|
|
|
break;
|
2003-09-04 00:15:59 +00:00
|
|
|
case NODE_TYPE_TOOLBAR:
|
2003-08-24 19:58:30 +00:00
|
|
|
if (info->proxy == NULL)
|
|
|
|
{
|
|
|
|
info->proxy = gtk_toolbar_new ();
|
|
|
|
gtk_widget_show (info->proxy);
|
|
|
|
g_signal_emit (self, merge_signals[ADD_WIDGET], 0, info->proxy);
|
|
|
|
}
|
|
|
|
break;
|
2003-09-04 00:15:59 +00:00
|
|
|
case NODE_TYPE_MENU_PLACEHOLDER:
|
2003-08-24 19:58:30 +00:00
|
|
|
/* 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)
|
2003-09-06 23:52:00 +00:00
|
|
|
{
|
|
|
|
gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
|
|
|
|
info->proxy);
|
|
|
|
info->proxy = NULL;
|
|
|
|
}
|
2003-08-24 19:58:30 +00:00
|
|
|
if (info->extra)
|
2003-09-06 23:52:00 +00:00
|
|
|
{
|
|
|
|
gtk_container_remove (GTK_CONTAINER (info->extra->parent),
|
|
|
|
info->extra);
|
|
|
|
info->extra = NULL;
|
|
|
|
}
|
2003-08-24 19:58:30 +00:00
|
|
|
}
|
|
|
|
if (info->proxy == NULL)
|
|
|
|
{
|
|
|
|
GtkWidget *menushell;
|
|
|
|
gint pos;
|
|
|
|
|
|
|
|
if (find_menu_position (node, &menushell, &pos))
|
|
|
|
{
|
2003-09-15 20:35:28 +00:00
|
|
|
info->proxy = gtk_separator_menu_item_new ();
|
|
|
|
g_object_set_data (G_OBJECT (info->proxy),
|
|
|
|
"gtk-separator-mode",
|
|
|
|
GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN));
|
2003-08-24 19:58:30 +00:00
|
|
|
gtk_menu_shell_insert (GTK_MENU_SHELL (menushell),
|
|
|
|
NODE_INFO (node)->proxy, pos);
|
|
|
|
|
2003-09-15 20:35:28 +00:00
|
|
|
info->extra = gtk_separator_menu_item_new ();
|
|
|
|
g_object_set_data (G_OBJECT (info->extra),
|
|
|
|
"gtk-separator-mode",
|
|
|
|
GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN));
|
2003-08-24 19:58:30 +00:00
|
|
|
gtk_menu_shell_insert (GTK_MENU_SHELL (menushell),
|
|
|
|
NODE_INFO (node)->extra, pos+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2003-09-04 00:15:59 +00:00
|
|
|
case NODE_TYPE_TOOLBAR_PLACEHOLDER:
|
2003-08-24 19:58:30 +00:00
|
|
|
/* 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)
|
2003-09-06 23:52:00 +00:00
|
|
|
{
|
|
|
|
gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
|
|
|
|
info->proxy);
|
|
|
|
info->proxy = NULL;
|
|
|
|
}
|
2003-08-24 19:58:30 +00:00
|
|
|
if (info->extra)
|
2003-09-06 23:52:00 +00:00
|
|
|
{
|
|
|
|
gtk_container_remove (GTK_CONTAINER (info->extra->parent),
|
|
|
|
info->extra);
|
|
|
|
info->extra = NULL;
|
|
|
|
}
|
2003-08-24 19:58:30 +00:00
|
|
|
}
|
|
|
|
if (info->proxy == NULL)
|
|
|
|
{
|
|
|
|
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);
|
2003-09-15 20:35:28 +00:00
|
|
|
info->proxy = GTK_WIDGET (item);
|
|
|
|
g_object_set_data (G_OBJECT (info->proxy),
|
|
|
|
"gtk-separator-mode",
|
|
|
|
GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN));
|
2003-08-24 19:58:30 +00:00
|
|
|
|
|
|
|
item = gtk_separator_tool_item_new ();
|
|
|
|
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, pos+1);
|
2003-09-15 20:35:28 +00:00
|
|
|
info->extra = GTK_WIDGET (item);
|
|
|
|
g_object_set_data (G_OBJECT (info->extra),
|
|
|
|
"gtk-separator-mode",
|
|
|
|
GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN));
|
2003-08-24 19:58:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2003-09-04 00:15:59 +00:00
|
|
|
case NODE_TYPE_MENUITEM:
|
2003-08-24 19:58:30 +00:00
|
|
|
/* remove the proxy if it is of the wrong type ... */
|
|
|
|
if (info->proxy && G_OBJECT_TYPE (info->proxy) !=
|
2003-09-06 23:52:00 +00:00
|
|
|
GTK_ACTION_GET_CLASS (action)->menu_item_type)
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
2003-09-15 20:35:28 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (info->proxy,
|
|
|
|
G_CALLBACK (update_smart_separators),
|
|
|
|
0);
|
2003-09-06 23:52:00 +00:00
|
|
|
gtk_action_disconnect_proxy (info->action, info->proxy);
|
2003-08-24 19:58:30 +00:00
|
|
|
gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
|
|
|
|
info->proxy);
|
|
|
|
info->proxy = NULL;
|
|
|
|
}
|
|
|
|
/* create proxy if needed ... */
|
|
|
|
if (info->proxy == NULL)
|
|
|
|
{
|
|
|
|
GtkWidget *menushell;
|
|
|
|
gint pos;
|
|
|
|
|
|
|
|
if (find_menu_position (node, &menushell, &pos))
|
|
|
|
{
|
2003-09-06 23:52:00 +00:00
|
|
|
info->proxy = gtk_action_create_menu_item (action);
|
2003-08-24 19:58:30 +00:00
|
|
|
|
|
|
|
gtk_menu_shell_insert (GTK_MENU_SHELL (menushell),
|
|
|
|
info->proxy, pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-09-15 20:35:28 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (info->proxy,
|
|
|
|
G_CALLBACK (update_smart_separators),
|
|
|
|
0);
|
2003-08-24 19:58:30 +00:00
|
|
|
gtk_menu_item_set_submenu (GTK_MENU_ITEM (info->proxy), NULL);
|
2003-09-06 23:52:00 +00:00
|
|
|
gtk_action_connect_proxy (action, info->proxy);
|
2003-08-24 19:58:30 +00:00
|
|
|
}
|
2003-09-15 20:35:28 +00:00
|
|
|
g_signal_connect (info->proxy, "notify::visible",
|
|
|
|
G_CALLBACK (update_smart_separators), 0);
|
2003-08-24 19:58:30 +00:00
|
|
|
break;
|
2003-09-04 00:15:59 +00:00
|
|
|
case NODE_TYPE_TOOLITEM:
|
2003-08-24 19:58:30 +00:00
|
|
|
/* remove the proxy if it is of the wrong type ... */
|
|
|
|
if (info->proxy && G_OBJECT_TYPE (info->proxy) !=
|
2003-09-06 23:52:00 +00:00
|
|
|
GTK_ACTION_GET_CLASS (action)->toolbar_item_type)
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
2003-09-15 20:35:28 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (info->proxy,
|
|
|
|
G_CALLBACK (update_smart_separators),
|
|
|
|
0);
|
2003-09-06 23:52:00 +00:00
|
|
|
gtk_action_disconnect_proxy (info->action, info->proxy);
|
2003-08-24 19:58:30 +00:00
|
|
|
gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
|
|
|
|
info->proxy);
|
|
|
|
info->proxy = NULL;
|
|
|
|
}
|
|
|
|
/* create proxy if needed ... */
|
|
|
|
if (info->proxy == NULL)
|
|
|
|
{
|
|
|
|
GtkWidget *toolbar;
|
|
|
|
gint pos;
|
|
|
|
|
|
|
|
if (find_toolbar_position (node, &toolbar, &pos))
|
|
|
|
{
|
2003-09-06 23:52:00 +00:00
|
|
|
info->proxy = gtk_action_create_tool_item (action);
|
2003-08-24 19:58:30 +00:00
|
|
|
|
|
|
|
gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
|
|
|
|
GTK_TOOL_ITEM (info->proxy), pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-09-15 20:35:28 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (info->proxy,
|
|
|
|
G_CALLBACK (update_smart_separators),
|
|
|
|
0);
|
2003-09-06 23:52:00 +00:00
|
|
|
gtk_action_connect_proxy (action, info->proxy);
|
2003-08-24 19:58:30 +00:00
|
|
|
}
|
2003-09-15 20:35:28 +00:00
|
|
|
g_signal_connect (info->proxy, "notify::visible",
|
|
|
|
G_CALLBACK (update_smart_separators), 0);
|
2003-08-24 19:58:30 +00:00
|
|
|
break;
|
2003-09-04 00:15:59 +00:00
|
|
|
case NODE_TYPE_SEPARATOR:
|
|
|
|
if (NODE_INFO (node->parent)->type == NODE_TYPE_TOOLBAR ||
|
|
|
|
NODE_INFO (node->parent)->type == NODE_TYPE_TOOLBAR_PLACEHOLDER)
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
|
|
|
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);
|
2003-09-15 20:35:28 +00:00
|
|
|
g_object_set_data (G_OBJECT (info->proxy),
|
|
|
|
"gtk-separator-mode",
|
|
|
|
GINT_TO_POINTER (SEPARATOR_MODE_SMART));
|
2003-08-24 19:58:30 +00:00
|
|
|
gtk_widget_show (info->proxy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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 ();
|
2003-09-15 20:35:28 +00:00
|
|
|
g_object_set_data (G_OBJECT (info->proxy),
|
|
|
|
"gtk-separator-mode",
|
|
|
|
GINT_TO_POINTER (SEPARATOR_MODE_SMART));
|
2003-08-24 19:58:30 +00:00
|
|
|
gtk_menu_shell_insert (GTK_MENU_SHELL (menushell),
|
|
|
|
info->proxy, pos);
|
|
|
|
gtk_widget_show (info->proxy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2003-09-17 23:58:28 +00:00
|
|
|
case NODE_TYPE_ACCELERATOR:
|
|
|
|
gtk_action_connect_accelerator (action);
|
|
|
|
break;
|
2003-08-24 19:58:30 +00:00
|
|
|
}
|
|
|
|
|
2003-09-06 23:52:00 +00:00
|
|
|
if (action)
|
|
|
|
g_object_ref (action);
|
|
|
|
if (info->action)
|
|
|
|
g_object_unref (info->action);
|
|
|
|
info->action = action;
|
2003-08-24 19:58:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
recurse_children:
|
|
|
|
/* process children */
|
|
|
|
child = node->children;
|
|
|
|
while (child)
|
|
|
|
{
|
|
|
|
GNode *current;
|
|
|
|
|
|
|
|
current = child;
|
|
|
|
child = current->next;
|
2003-09-04 00:15:59 +00:00
|
|
|
update_node (self, current, add_tearoffs && (info->type != NODE_TYPE_POPUP));
|
2003-08-24 19:58:30 +00:00
|
|
|
}
|
2003-09-17 23:58:28 +00:00
|
|
|
|
|
|
|
if (info->proxy)
|
2003-09-17 22:44:01 +00:00
|
|
|
{
|
2003-09-17 23:58:28 +00:00
|
|
|
if (info->type == NODE_TYPE_MENU)
|
2003-09-17 22:44:01 +00:00
|
|
|
update_smart_separators (gtk_menu_item_get_submenu (GTK_MENU_ITEM (info->proxy)));
|
|
|
|
else if (info->type == NODE_TYPE_TOOLBAR)
|
|
|
|
update_smart_separators (info->proxy);
|
|
|
|
}
|
2003-09-15 20:35:28 +00:00
|
|
|
|
2003-08-24 19:58:30 +00:00
|
|
|
/* handle cleanup of dead nodes */
|
2003-08-29 23:33:54 +00:00
|
|
|
if (node->children == NULL && info->uifiles == NULL)
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
2003-08-29 23:33:54 +00:00
|
|
|
if (info->proxy)
|
|
|
|
gtk_widget_destroy (info->proxy);
|
2003-09-11 21:02:24 +00:00
|
|
|
if (info->extra)
|
2003-08-29 23:33:54 +00:00
|
|
|
gtk_widget_destroy (info->extra);
|
2003-09-17 23:58:28 +00:00
|
|
|
if (info->type == NODE_TYPE_ACCELERATOR)
|
|
|
|
gtk_action_disconnect_accelerator (info->action);
|
2003-09-11 21:02:24 +00:00
|
|
|
free_node (node);
|
2003-08-24 19:58:30 +00:00
|
|
|
g_node_destroy (node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2003-08-25 23:13:47 +00:00
|
|
|
do_updates (GtkUIManager *self)
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
|
|
|
/* this function needs to check through the tree for dirty nodes.
|
|
|
|
* For such nodes, it needs to do the following:
|
|
|
|
*
|
|
|
|
* 1) check if they are referenced by any loaded UI files anymore.
|
|
|
|
* In which case, the proxy widget should be destroyed, unless
|
|
|
|
* there are any subnodes.
|
|
|
|
*
|
|
|
|
* 2) lookup the action for this node again. If it is different to
|
|
|
|
* the current one (or if no previous action has been looked up),
|
|
|
|
* the proxy is reconnected to the new action (or a new proxy widget
|
|
|
|
* is created and added to the parent container).
|
|
|
|
*/
|
2003-08-29 22:42:37 +00:00
|
|
|
update_node (self, self->private_data->root_node,
|
|
|
|
self->private_data->add_tearoffs);
|
2003-08-24 19:58:30 +00:00
|
|
|
|
|
|
|
self->private_data->update_tag = 0;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-09-01 22:15:16 +00:00
|
|
|
queue_update (GtkUIManager *self)
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
|
|
|
if (self->private_data->update_tag != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
self->private_data->update_tag = g_idle_add ((GSourceFunc)do_updates, self);
|
|
|
|
}
|
|
|
|
|
2003-08-31 23:36:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_ui_manager_ensure_update:
|
|
|
|
* @self: a #GtkUIManager
|
|
|
|
*
|
|
|
|
* Makes sure that all pending updates to the UI have been completed.
|
|
|
|
*
|
|
|
|
* This may occasionally be necessary, since #GtkUIManager updates the
|
|
|
|
* 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-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
|
|
|
|
**/
|
|
|
|
void
|
2003-08-25 23:13:47 +00:00
|
|
|
gtk_ui_manager_ensure_update (GtkUIManager *self)
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
|
|
|
if (self->private_data->update_tag != 0)
|
|
|
|
{
|
|
|
|
g_source_remove (self->private_data->update_tag);
|
|
|
|
do_updates (self);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
dirty_traverse_func (GNode *node,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
NODE_INFO (node)->dirty = TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-09-01 22:15:16 +00:00
|
|
|
dirty_all_nodes (GtkUIManager *self)
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
2003-09-01 22:15:16 +00:00
|
|
|
g_node_traverse (self->private_data->root_node,
|
|
|
|
G_PRE_ORDER, G_TRAVERSE_ALL, -1,
|
2003-08-24 19:58:30 +00:00
|
|
|
dirty_traverse_func, NULL);
|
2003-09-01 22:15:16 +00:00
|
|
|
queue_update (self);
|
2003-08-24 19:58:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const gchar *open_tag_format[] = {
|
|
|
|
"%*s<UNDECIDED>\n",
|
2003-08-26 00:13:59 +00:00
|
|
|
"%*s<ui>\n",
|
|
|
|
"%*s<menubar name=\"%s\">\n",
|
Change the XML format: <Root> element is replaced by <ui>, <menu> element
2003-08-28 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Change the XML format:
<Root> element is replaced by <ui>,
<menu> element is replaced by <menubar>,
<submenu> element is replaced by <menu>,
<dockitem> element is replaced by <toolbar>,
<popups> element is gone,
verb attribute is replaced by action,
name defaults to action or the element name.
* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
and GtkRadioActionEntry. GtkActionEntry is simplified by removing
the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
further simplified by removing the callback. The user_data can now be
specified as an argument to gtk_action_group_add_actions(). There is
a new method gtk_action_group_add_radio_actions(), which is similar
to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
and a callback parameter in addition to the user_data. The callback
is connected to the ::changed signal of the first group member.
There are _full() variants taking a GDestroyNotify of
gtk_action_group_add_[radio_]actions().
* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
on every member of the radio group when the active member is changed.
Add an integer property "value", and a getter for the value of "value"
on the currently active group member.
* tests/testactions.c:
* tests/testmerge.c:
* tests/merge-[123].ui:
* demos/gtk-demo/appwindow.c: Adjust to these changes.
* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
2003-08-27 22:22:28 +00:00
|
|
|
"%*s<menu name='%s' action=\"%s\">\n",
|
2003-08-26 00:13:59 +00:00
|
|
|
"%*s<toolbar name=\"%s\">\n",
|
2003-08-24 19:58:30 +00:00
|
|
|
"%*s<placeholder name=\"%s\">\n",
|
|
|
|
"%*s<placeholder name=\"%s\">\n",
|
Change the XML format: <Root> element is replaced by <ui>, <menu> element
2003-08-28 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Change the XML format:
<Root> element is replaced by <ui>,
<menu> element is replaced by <menubar>,
<submenu> element is replaced by <menu>,
<dockitem> element is replaced by <toolbar>,
<popups> element is gone,
verb attribute is replaced by action,
name defaults to action or the element name.
* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
and GtkRadioActionEntry. GtkActionEntry is simplified by removing
the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
further simplified by removing the callback. The user_data can now be
specified as an argument to gtk_action_group_add_actions(). There is
a new method gtk_action_group_add_radio_actions(), which is similar
to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
and a callback parameter in addition to the user_data. The callback
is connected to the ::changed signal of the first group member.
There are _full() variants taking a GDestroyNotify of
gtk_action_group_add_[radio_]actions().
* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
on every member of the radio group when the active member is changed.
Add an integer property "value", and a getter for the value of "value"
on the currently active group member.
* tests/testactions.c:
* tests/testmerge.c:
* tests/merge-[123].ui:
* demos/gtk-demo/appwindow.c: Adjust to these changes.
* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
2003-08-27 22:22:28 +00:00
|
|
|
"%*s<popup name='%s' action=\"%s\">\n",
|
2003-08-26 00:13:59 +00:00
|
|
|
"%*s<menuitem name=\"%s\" action=\"%s\"/>\n",
|
|
|
|
"%*s<toolitem name=\"%s\" action=\"%s\"/>\n",
|
2003-09-17 23:58:28 +00:00
|
|
|
"%*s<separator name=\"%s\"/>\n",
|
|
|
|
"%*s<accelerator name=\"%s\" action=\"%s\"/>\n",
|
2003-08-24 19:58:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const gchar *close_tag_format[] = {
|
|
|
|
"%*s</UNDECIDED>\n",
|
2003-08-26 00:13:59 +00:00
|
|
|
"%*s</ui>\n",
|
|
|
|
"%*s</menubar>\n",
|
2003-08-24 19:58:30 +00:00
|
|
|
"%*s</menu>\n",
|
2003-08-26 00:13:59 +00:00
|
|
|
"%*s</toolbar>\n",
|
2003-08-24 19:58:30 +00:00
|
|
|
"%*s</placeholder>\n",
|
|
|
|
"%*s</placeholder>\n",
|
Change the XML format: <Root> element is replaced by <ui>, <menu> element
2003-08-28 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Change the XML format:
<Root> element is replaced by <ui>,
<menu> element is replaced by <menubar>,
<submenu> element is replaced by <menu>,
<dockitem> element is replaced by <toolbar>,
<popups> element is gone,
verb attribute is replaced by action,
name defaults to action or the element name.
* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
and GtkRadioActionEntry. GtkActionEntry is simplified by removing
the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
further simplified by removing the callback. The user_data can now be
specified as an argument to gtk_action_group_add_actions(). There is
a new method gtk_action_group_add_radio_actions(), which is similar
to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
and a callback parameter in addition to the user_data. The callback
is connected to the ::changed signal of the first group member.
There are _full() variants taking a GDestroyNotify of
gtk_action_group_add_[radio_]actions().
* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
on every member of the radio group when the active member is changed.
Add an integer property "value", and a getter for the value of "value"
on the currently active group member.
* tests/testactions.c:
* tests/testmerge.c:
* tests/merge-[123].ui:
* demos/gtk-demo/appwindow.c: Adjust to these changes.
* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
2003-08-27 22:22:28 +00:00
|
|
|
"%*s</popup>\n",
|
2003-08-24 19:58:30 +00:00
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
2003-09-17 23:58:28 +00:00
|
|
|
"",
|
2003-08-24 19:58:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2003-08-25 23:13:47 +00:00
|
|
|
print_node (GtkUIManager *self,
|
2003-08-24 19:58:30 +00:00
|
|
|
GNode *node,
|
|
|
|
gint indent_level,
|
|
|
|
GString *buffer)
|
|
|
|
{
|
2003-09-04 00:15:59 +00:00
|
|
|
Node *mnode;
|
2003-08-24 19:58:30 +00:00
|
|
|
GNode *child;
|
2003-08-29 22:42:37 +00:00
|
|
|
|
2003-08-24 19:58:30 +00:00
|
|
|
mnode = node->data;
|
|
|
|
|
Change the XML format: <Root> element is replaced by <ui>, <menu> element
2003-08-28 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Change the XML format:
<Root> element is replaced by <ui>,
<menu> element is replaced by <menubar>,
<submenu> element is replaced by <menu>,
<dockitem> element is replaced by <toolbar>,
<popups> element is gone,
verb attribute is replaced by action,
name defaults to action or the element name.
* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
and GtkRadioActionEntry. GtkActionEntry is simplified by removing
the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
further simplified by removing the callback. The user_data can now be
specified as an argument to gtk_action_group_add_actions(). There is
a new method gtk_action_group_add_radio_actions(), which is similar
to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
and a callback parameter in addition to the user_data. The callback
is connected to the ::changed signal of the first group member.
There are _full() variants taking a GDestroyNotify of
gtk_action_group_add_[radio_]actions().
* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
on every member of the radio group when the active member is changed.
Add an integer property "value", and a getter for the value of "value"
on the currently active group member.
* tests/testactions.c:
* tests/testmerge.c:
* tests/merge-[123].ui:
* demos/gtk-demo/appwindow.c: Adjust to these changes.
* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
2003-08-27 22:22:28 +00:00
|
|
|
g_string_append_printf (buffer, open_tag_format[mnode->type],
|
2003-08-24 19:58:30 +00:00
|
|
|
indent_level, "",
|
|
|
|
mnode->name,
|
|
|
|
g_quark_to_string (mnode->action_name));
|
|
|
|
|
|
|
|
for (child = node->children; child != NULL; child = child->next)
|
|
|
|
print_node (self, child, indent_level + 2, buffer);
|
|
|
|
|
Change the XML format: <Root> element is replaced by <ui>, <menu> element
2003-08-28 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Change the XML format:
<Root> element is replaced by <ui>,
<menu> element is replaced by <menubar>,
<submenu> element is replaced by <menu>,
<dockitem> element is replaced by <toolbar>,
<popups> element is gone,
verb attribute is replaced by action,
name defaults to action or the element name.
* gtk/gtkactiongroup.[hc]: Replace GtkActionGroupEntry by GtkActionEntry
and GtkRadioActionEntry. GtkActionEntry is simplified by removing
the user_data, entry_type and extra_data fields, GtkRadioActionEntry is
further simplified by removing the callback. The user_data can now be
specified as an argument to gtk_action_group_add_actions(). There is
a new method gtk_action_group_add_radio_actions(), which is similar
to gtk_action_group_add_actions(), but takes GtkRadioActionEntrys
and a callback parameter in addition to the user_data. The callback
is connected to the ::changed signal of the first group member.
There are _full() variants taking a GDestroyNotify of
gtk_action_group_add_[radio_]actions().
* gtk/gtkradioaction.[hc]: Add a ::changed signal which gets emitted
on every member of the radio group when the active member is changed.
Add an integer property "value", and a getter for the value of "value"
on the currently active group member.
* tests/testactions.c:
* tests/testmerge.c:
* tests/merge-[123].ui:
* demos/gtk-demo/appwindow.c: Adjust to these changes.
* gtk/gtktoolbar.c (gtk_toolbar_append_element): Trivial doc fix.
2003-08-27 22:22:28 +00:00
|
|
|
g_string_append_printf (buffer, close_tag_format[mnode->type],
|
2003-08-24 19:58:30 +00:00
|
|
|
indent_level, "");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2003-08-25 23:13:47 +00:00
|
|
|
* gtk_ui_manager_get_ui:
|
|
|
|
* @self: a #GtkUIManager
|
2003-08-24 19:58:30 +00:00
|
|
|
*
|
2003-09-15 22:21:26 +00:00
|
|
|
* Creates a <link linkend="XML-UI">UI definition</link> of the merged UI.
|
2003-08-24 19:58:30 +00:00
|
|
|
*
|
|
|
|
* Return value: A newly allocated string containing an XML representation of
|
2003-09-01 22:15:16 +00:00
|
|
|
* the merged UI.
|
2003-08-24 20:48:27 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-08-24 19:58:30 +00:00
|
|
|
**/
|
2003-09-11 21:02:24 +00:00
|
|
|
gchar *
|
|
|
|
gtk_ui_manager_get_ui (GtkUIManager *self)
|
2003-08-24 19:58:30 +00:00
|
|
|
{
|
|
|
|
GString *buffer;
|
|
|
|
|
|
|
|
buffer = g_string_new (NULL);
|
|
|
|
|
2003-08-25 23:13:47 +00:00
|
|
|
gtk_ui_manager_ensure_update (self);
|
2003-08-24 19:58:30 +00:00
|
|
|
|
|
|
|
print_node (self, self->private_data->root_node, 0, buffer);
|
|
|
|
|
|
|
|
return g_string_free (buffer, FALSE);
|
|
|
|
}
|
2003-08-30 21:18:43 +00:00
|
|
|
|