Shorten the names of some static functions.

2003-09-02  Matthias Clasen  <maclas@gmx.de>

	* gtk/gtkuimanager.c: Shorten the names of some static
	functions.

	Support adding and removing merge nodes dynamically (#120647,
	Anders Carlsson):

	* gtk/gtkuimanager.[ch] (gtk_ui_manager_new_merge_id): Renamed
	gtk_ui_manager_next_merge_id to gtk_ui_manager_new_merge_id
	and made it public.
	(gtk_ui_manager_add_ui): New function to add UI elements
	without juggling XML fragments, currently restricted to menuitems,
	toolitems and separators. Actions still come from registered
	action groups.
This commit is contained in:
Matthias Clasen 2003-09-01 22:15:16 +00:00 committed by Matthias Clasen
parent 7c95897892
commit cbbe97abf5
9 changed files with 278 additions and 82 deletions

View File

@ -1,3 +1,19 @@
2003-09-02 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Shorten the names of some static
functions.
Support adding and removing merge nodes dynamically (#120647,
Anders Carlsson):
* gtk/gtkuimanager.[ch] (gtk_ui_manager_new_merge_id): Renamed
gtk_ui_manager_next_merge_id to gtk_ui_manager_new_merge_id
and made it public.
(gtk_ui_manager_add_ui): New function to add UI elements
without juggling XML fragments, currently restricted to menuitems,
toolitems and separators. Actions still come from registered
action groups.
Mon Sep 1 19:39:14 2003 Soeren Sandmann <sandmann@daimi.au.dk>
* gdk/gdkwindow.c (gdk_window_get_bg_gc): Fix bug where the

View File

@ -1,3 +1,19 @@
2003-09-02 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Shorten the names of some static
functions.
Support adding and removing merge nodes dynamically (#120647,
Anders Carlsson):
* gtk/gtkuimanager.[ch] (gtk_ui_manager_new_merge_id): Renamed
gtk_ui_manager_next_merge_id to gtk_ui_manager_new_merge_id
and made it public.
(gtk_ui_manager_add_ui): New function to add UI elements
without juggling XML fragments, currently restricted to menuitems,
toolitems and separators. Actions still come from registered
action groups.
Mon Sep 1 19:39:14 2003 Soeren Sandmann <sandmann@daimi.au.dk>
* gdk/gdkwindow.c (gdk_window_get_bg_gc): Fix bug where the

View File

@ -1,3 +1,19 @@
2003-09-02 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Shorten the names of some static
functions.
Support adding and removing merge nodes dynamically (#120647,
Anders Carlsson):
* gtk/gtkuimanager.[ch] (gtk_ui_manager_new_merge_id): Renamed
gtk_ui_manager_next_merge_id to gtk_ui_manager_new_merge_id
and made it public.
(gtk_ui_manager_add_ui): New function to add UI elements
without juggling XML fragments, currently restricted to menuitems,
toolitems and separators. Actions still come from registered
action groups.
Mon Sep 1 19:39:14 2003 Soeren Sandmann <sandmann@daimi.au.dk>
* gdk/gdkwindow.c (gdk_window_get_bg_gc): Fix bug where the

View File

@ -1,3 +1,19 @@
2003-09-02 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Shorten the names of some static
functions.
Support adding and removing merge nodes dynamically (#120647,
Anders Carlsson):
* gtk/gtkuimanager.[ch] (gtk_ui_manager_new_merge_id): Renamed
gtk_ui_manager_next_merge_id to gtk_ui_manager_new_merge_id
and made it public.
(gtk_ui_manager_add_ui): New function to add UI elements
without juggling XML fragments, currently restricted to menuitems,
toolitems and separators. Actions still come from registered
action groups.
Mon Sep 1 19:39:14 2003 Soeren Sandmann <sandmann@daimi.au.dk>
* gdk/gdkwindow.c (gdk_window_get_bg_gc): Fix bug where the

View File

@ -1,3 +1,19 @@
2003-09-02 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.c: Shorten the names of some static
functions.
Support adding and removing merge nodes dynamically (#120647,
Anders Carlsson):
* gtk/gtkuimanager.[ch] (gtk_ui_manager_new_merge_id): Renamed
gtk_ui_manager_next_merge_id to gtk_ui_manager_new_merge_id
and made it public.
(gtk_ui_manager_add_ui): New function to add UI elements
without juggling XML fragments, currently restricted to menuitems,
toolitems and separators. Actions still come from registered
action groups.
Mon Sep 1 19:39:14 2003 Soeren Sandmann <sandmann@daimi.au.dk>
* gdk/gdkwindow.c (gdk_window_get_bg_gc): Fix bug where the

View File

@ -1,3 +1,8 @@
2003-09-02 Matthias Clasen <maclas@gmx.de>
* gtk/gtk-sections.txt: Add gtk_ui_manager_new_merge_id and
gtk_ui_manager_add_ui.
2003-09-01 Matthias Clasen <maclas@gmx.de>
* gtk/tmpl/gtkuimanager.sgml: Add an example UI description.

View File

@ -1733,6 +1733,8 @@ gtk_ui_manager_get_widget
gtk_ui_manager_get_action
gtk_ui_manager_add_ui_from_string
gtk_ui_manager_add_ui_from_file
gtk_ui_manager_new_merge_id
gtk_ui_manager_add_ui
gtk_ui_manager_remove_ui
gtk_ui_manager_get_ui
gtk_ui_manager_ensure_update

View File

@ -102,38 +102,36 @@ struct _NodeUIReference
GQuark action_quark;
};
static void gtk_ui_manager_class_init (GtkUIManagerClass *class);
static void gtk_ui_manager_init (GtkUIManager *self);
static void gtk_ui_manager_finalize (GObject *object);
static void gtk_ui_manager_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void gtk_ui_manager_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void gtk_ui_manager_queue_update (GtkUIManager *self);
static void gtk_ui_manager_dirty_all (GtkUIManager *self);
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,
GtkUIManagerNodeType node_type,
gboolean create,
gboolean top);
static GNode *get_node (GtkUIManager *self,
const gchar *path,
GtkUIManagerNodeType node_type,
gboolean create);
static GNode *get_child_node (GtkUIManager *self,
GNode *parent,
const gchar *childname,
gint childname_length,
GtkUIManagerNodeType node_type,
gboolean create,
gboolean top);
static GNode *gtk_ui_manager_get_node (GtkUIManager *self,
const gchar *path,
GtkUIManagerNodeType node_type,
gboolean create);
static guint gtk_ui_manager_next_merge_id (GtkUIManager *self);
static void gtk_ui_manager_node_prepend_ui_reference (GtkUIManagerNode *node,
guint merge_id,
GQuark action_quark);
static void gtk_ui_manager_node_remove_ui_reference (GtkUIManagerNode *node,
guint merge_id);
static void node_prepend_ui_reference (GtkUIManagerNode *node,
guint merge_id,
GQuark action_quark);
static void node_remove_ui_reference (GtkUIManagerNode *node,
guint merge_id);
enum
@ -199,7 +197,7 @@ gtk_ui_manager_class_init (GtkUIManagerClass *klass)
/**
* GtkUIManager:add-tearoffs:
*
* The add-tearoffs property controls whether generated menus
* The "add-tearoffs" property controls whether generated menus
* have tearoff menu items.
*
* Note that this only affects regular menus. Generated popup
@ -239,7 +237,7 @@ gtk_ui_manager_class_init (GtkUIManagerClass *klass)
* GtkUIManager::changed:
* @merge: a #GtkUIManager
*
* The changed signal is emitted whenever the merged UI changes.
* The "changed" signal is emitted whenever the merged UI changes.
*
* Since: 2.4
*/
@ -272,10 +270,10 @@ gtk_ui_manager_init (GtkUIManager *self)
self->private_data->add_tearoffs = FALSE;
merge_id = gtk_ui_manager_next_merge_id (self);
merge_id = gtk_ui_manager_new_merge_id (self);
node = get_child_node (self, NULL, "ui", 4,
GTK_UI_MANAGER_ROOT, TRUE, FALSE);
gtk_ui_manager_node_prepend_ui_reference (NODE_INFO (node), merge_id, 0);
node_prepend_ui_reference (NODE_INFO (node), merge_id, 0);
}
static void
@ -370,7 +368,7 @@ gtk_ui_manager_get_add_tearoffs (GtkUIManager *self)
* @self: a #GtkUIManager
* @add_tearoffs: whether tearoff menu items are added
*
* Sets the add_tearoffs property, which controls whether menus
* Sets the "add_tearoffs" property, which controls whether menus
* generated by this #GtkUIManager will have tearoff menu items.
*
* Note that this only affects regular menus. Generated popup
@ -390,8 +388,7 @@ gtk_ui_manager_set_add_tearoffs (GtkUIManager *self,
{
self->private_data->add_tearoffs = add_tearoffs;
/* dirty all nodes */
gtk_ui_manager_dirty_all (self);
dirty_all_nodes (self);
g_object_notify (G_OBJECT (self), "add_tearoffs");
}
@ -423,7 +420,7 @@ gtk_ui_manager_insert_action_group (GtkUIManager *self,
g_list_insert (self->private_data->action_groups, action_group, pos);
/* dirty all nodes, as action bindings may change */
gtk_ui_manager_dirty_all (self);
dirty_all_nodes (self);
}
/**
@ -450,7 +447,7 @@ gtk_ui_manager_remove_action_group (GtkUIManager *self,
g_object_unref (action_group);
/* dirty all nodes, as action bindings may change */
gtk_ui_manager_dirty_all (self);
dirty_all_nodes (self);
}
/**
@ -519,7 +516,7 @@ gtk_ui_manager_get_widget (GtkUIManager *self,
* widget */
gtk_ui_manager_ensure_update (self);
node = gtk_ui_manager_get_node (self, path, GTK_UI_MANAGER_UNDECIDED, FALSE);
node = get_node (self, path, GTK_UI_MANAGER_UNDECIDED, FALSE);
if (node == NULL)
return NULL;
@ -556,7 +553,7 @@ gtk_ui_manager_get_action (GtkUIManager *self,
* the action */
gtk_ui_manager_ensure_update (self);
node = gtk_ui_manager_get_node (self, path, GTK_UI_MANAGER_UNDECIDED, FALSE);
node = get_node (self, path, GTK_UI_MANAGER_UNDECIDED, FALSE);
if (node == NULL)
return NULL;
@ -650,10 +647,10 @@ get_child_node (GtkUIManager *self,
}
static GNode *
gtk_ui_manager_get_node (GtkUIManager *self,
const gchar *path,
GtkUIManagerNodeType node_type,
gboolean create)
get_node (GtkUIManager *self,
const gchar *path,
GtkUIManagerNodeType node_type,
gboolean create)
{
const gchar *pos, *end;
GNode *parent, *node;
@ -686,8 +683,19 @@ gtk_ui_manager_get_node (GtkUIManager *self,
return node;
}
static guint
gtk_ui_manager_next_merge_id (GtkUIManager *self)
/**
* 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)
{
self->private_data->last_merge_id++;
@ -695,9 +703,9 @@ gtk_ui_manager_next_merge_id (GtkUIManager *self)
}
static void
gtk_ui_manager_node_prepend_ui_reference (GtkUIManagerNode *node,
guint merge_id,
GQuark action_quark)
node_prepend_ui_reference (GtkUIManagerNode *node,
guint merge_id,
GQuark action_quark)
{
NodeUIReference *reference;
@ -712,8 +720,8 @@ gtk_ui_manager_node_prepend_ui_reference (GtkUIManagerNode *node,
}
static void
gtk_ui_manager_node_remove_ui_reference (GtkUIManagerNode *node,
guint merge_id)
node_remove_ui_reference (GtkUIManagerNode *node,
guint merge_id)
{
GList *p;
@ -818,8 +826,8 @@ start_element_handler (GMarkupParseContext *context,
ctx->current = self->private_data->root_node;
raise_error = FALSE;
gtk_ui_manager_node_prepend_ui_reference (NODE_INFO (ctx->current),
ctx->merge_id, action_quark);
node_prepend_ui_reference (NODE_INFO (ctx->current),
ctx->merge_id, action_quark);
}
break;
case 'm':
@ -833,8 +841,8 @@ start_element_handler (GMarkupParseContext *context,
if (NODE_INFO (ctx->current)->action_name == 0)
NODE_INFO (ctx->current)->action_name = action_quark;
gtk_ui_manager_node_prepend_ui_reference (NODE_INFO (ctx->current),
ctx->merge_id, action_quark);
node_prepend_ui_reference (NODE_INFO (ctx->current),
ctx->merge_id, action_quark);
NODE_INFO (ctx->current)->dirty = TRUE;
raise_error = FALSE;
@ -848,8 +856,8 @@ start_element_handler (GMarkupParseContext *context,
if (NODE_INFO (ctx->current)->action_name == 0)
NODE_INFO (ctx->current)->action_name = action_quark;
gtk_ui_manager_node_prepend_ui_reference (NODE_INFO (ctx->current),
ctx->merge_id, action_quark);
node_prepend_ui_reference (NODE_INFO (ctx->current),
ctx->merge_id, action_quark);
NODE_INFO (ctx->current)->dirty = TRUE;
raise_error = FALSE;
@ -866,8 +874,8 @@ start_element_handler (GMarkupParseContext *context,
if (NODE_INFO (node)->action_name == 0)
NODE_INFO (node)->action_name = action_quark;
gtk_ui_manager_node_prepend_ui_reference (NODE_INFO (node),
ctx->merge_id, action_quark);
node_prepend_ui_reference (NODE_INFO (node),
ctx->merge_id, action_quark);
NODE_INFO (node)->dirty = TRUE;
raise_error = FALSE;
@ -884,8 +892,8 @@ start_element_handler (GMarkupParseContext *context,
if (NODE_INFO (ctx->current)->action_name == 0)
NODE_INFO (ctx->current)->action_name = action_quark;
gtk_ui_manager_node_prepend_ui_reference (NODE_INFO (ctx->current),
ctx->merge_id, action_quark);
node_prepend_ui_reference (NODE_INFO (ctx->current),
ctx->merge_id, action_quark);
NODE_INFO (ctx->current)->dirty = TRUE;
raise_error = FALSE;
@ -904,8 +912,8 @@ start_element_handler (GMarkupParseContext *context,
GTK_UI_MANAGER_MENU_PLACEHOLDER,
TRUE, top);
gtk_ui_manager_node_prepend_ui_reference (NODE_INFO (ctx->current),
ctx->merge_id, action_quark);
node_prepend_ui_reference (NODE_INFO (ctx->current),
ctx->merge_id, action_quark);
NODE_INFO (ctx->current)->dirty = TRUE;
raise_error = FALSE;
@ -928,8 +936,8 @@ start_element_handler (GMarkupParseContext *context,
if (NODE_INFO (node)->action_name == 0)
NODE_INFO (node)->action_name = action_quark;
gtk_ui_manager_node_prepend_ui_reference (NODE_INFO (node),
ctx->merge_id, action_quark);
node_prepend_ui_reference (NODE_INFO (node),
ctx->merge_id, action_quark);
NODE_INFO (node)->dirty = TRUE;
raise_error = FALSE;
@ -946,8 +954,8 @@ start_element_handler (GMarkupParseContext *context,
if (NODE_INFO (ctx->current)->action_name == 0)
NODE_INFO (ctx->current)->action_name = action_quark;
gtk_ui_manager_node_prepend_ui_reference (NODE_INFO (ctx->current),
ctx->merge_id, action_quark);
node_prepend_ui_reference (NODE_INFO (ctx->current),
ctx->merge_id, action_quark);
NODE_INFO (ctx->current)->dirty = TRUE;
raise_error = FALSE;
@ -964,8 +972,8 @@ start_element_handler (GMarkupParseContext *context,
if (NODE_INFO (node)->action_name == 0)
NODE_INFO (node)->action_name = action_quark;
gtk_ui_manager_node_prepend_ui_reference (NODE_INFO (node),
ctx->merge_id, action_quark);
node_prepend_ui_reference (NODE_INFO (node),
ctx->merge_id, action_quark);
NODE_INFO (node)->dirty = TRUE;
raise_error = FALSE;
@ -1088,7 +1096,7 @@ add_ui_from_string (GtkUIManager *self,
ctx.state = STATE_START;
ctx.self = self;
ctx.current = NULL;
ctx.merge_id = gtk_ui_manager_next_merge_id (self);
ctx.merge_id = gtk_ui_manager_new_merge_id (self);
context = g_markup_parse_context_new (&ui_parser, 0, &ctx, NULL);
@ -1108,7 +1116,7 @@ add_ui_from_string (GtkUIManager *self,
g_markup_parse_context_free (context);
gtk_ui_manager_queue_update (self);
queue_update (self);
g_signal_emit (self, merge_signals[CHANGED], 0);
@ -1198,13 +1206,104 @@ gtk_ui_manager_add_ui_from_file (GtkUIManager *self,
return res;
}
/**
* 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
*
* Adds a UI element to the current contents of @self. The path must lead to
* a place where a menuitem or toolitem can be inserted. If @action is %NULL,
* a separator is inserted, otherwise a menuitem or toolitem.
*
* Since: 2.4
**/
void
gtk_ui_manager_add_ui (GtkUIManager *self,
guint merge_id,
const gchar *path,
const gchar *name,
const gchar *action)
{
GNode *node;
GNode *child;
GtkUIManagerNodeType type;
GQuark action_quark = 0;
g_return_if_fail (GTK_IS_UI_MANAGER (self));
g_return_if_fail (merge_id > 0);
node = get_node (self, path, GTK_UI_MANAGER_UNDECIDED, FALSE);
if (node == NULL)
return;
switch (NODE_INFO (node)->type)
{
case GTK_UI_MANAGER_MENU:
case GTK_UI_MANAGER_POPUP:
case GTK_UI_MANAGER_MENU_PLACEHOLDER:
if (action != NULL)
type = GTK_UI_MANAGER_MENUITEM;
else
type = GTK_UI_MANAGER_SEPARATOR;
break;
case GTK_UI_MANAGER_TOOLBAR:
case GTK_UI_MANAGER_TOOLBAR_PLACEHOLDER:
if (action != NULL)
type = GTK_UI_MANAGER_TOOLITEM;
else
type = GTK_UI_MANAGER_SEPARATOR;
break;
default:
return;
}
if (name == NULL)
{
switch (type)
{
case GTK_UI_MANAGER_MENUITEM:
name = "menuitem";
break;
case GTK_UI_MANAGER_TOOLITEM:
name = "toolitem";
break;
case GTK_UI_MANAGER_SEPARATOR:
name = "separator";
break;
default:
g_assert_not_reached ();
}
}
child = get_child_node (self, node,
name, strlen (name),
type, TRUE, FALSE);
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);
}
static gboolean
remove_ui (GNode *node,
gpointer user_data)
{
guint merge_id = GPOINTER_TO_UINT (user_data);
gtk_ui_manager_node_remove_ui_reference (NODE_INFO (node), merge_id);
node_remove_ui_reference (NODE_INFO (node), merge_id);
return FALSE; /* continue */
}
@ -1222,10 +1321,11 @@ void
gtk_ui_manager_remove_ui (GtkUIManager *self,
guint merge_id)
{
g_node_traverse (self->private_data->root_node, G_POST_ORDER, G_TRAVERSE_ALL, -1,
g_node_traverse (self->private_data->root_node,
G_POST_ORDER, G_TRAVERSE_ALL, -1,
remove_ui, GUINT_TO_POINTER (merge_id));
gtk_ui_manager_queue_update (self);
queue_update (self);
g_signal_emit (self, merge_signals[CHANGED], 0);
}
@ -1785,7 +1885,7 @@ do_updates (GtkUIManager *self)
}
static void
gtk_ui_manager_queue_update (GtkUIManager *self)
queue_update (GtkUIManager *self)
{
if (self->private_data->update_tag != 0)
return;
@ -1837,11 +1937,12 @@ dirty_traverse_func (GNode *node,
}
static void
gtk_ui_manager_dirty_all (GtkUIManager *self)
dirty_all_nodes (GtkUIManager *self)
{
g_node_traverse (self->private_data->root_node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
g_node_traverse (self->private_data->root_node,
G_PRE_ORDER, G_TRAVERSE_ALL, -1,
dirty_traverse_func, NULL);
gtk_ui_manager_queue_update (self);
queue_update (self);
}
static const gchar *open_tag_format[] = {
@ -1900,10 +2001,10 @@ print_node (GtkUIManager *self,
* gtk_ui_manager_get_ui:
* @self: a #GtkUIManager
*
* Creates an XML representation of the merged ui.
* Creates a <link linkend="XML-UI">description</link> of the merged UI.
*
* Return value: A newly allocated string containing an XML representation of
* the merged ui.
* the merged UI.
*
* Since: 2.4
**/

View File

@ -102,6 +102,12 @@ guint gtk_ui_manager_add_ui_from_string (GtkUIManager *self,
guint gtk_ui_manager_add_ui_from_file (GtkUIManager *self,
const gchar *filename,
GError **error);
guint gtk_ui_manager_new_merge_id (GtkUIManager *self);
void gtk_ui_manager_add_ui (GtkUIManager *self,
guint merge_id,
const gchar *path,
const gchar *name,
const gchar *action);
void gtk_ui_manager_remove_ui (GtkUIManager *self,
guint merge_id);
@ -109,4 +115,6 @@ gchar *gtk_ui_manager_get_ui (GtkUIManager *self);
void gtk_ui_manager_ensure_update (GtkUIManager *self);
guint gtk_ui_manager_new_merge_id (GtkUIManager *self);
#endif /* __GTK_UI_MANAGER_H__ */