forked from AuroraMiddleware/gtk
Test gtk_ui_manager_add_ui().
2003-09-04 Matthias Clasen <maclas@gmx.de> * tests/testmerge.c (toggle_dynamic): Test gtk_ui_manager_add_ui(). * gtk/gtkuimanager.h: Add GtkUIManagerItemType enum which is needed for the 'type' argument of gtk_ui_manager_add_ui(). * gtk/gtkuimanager.[hc] (gtk_ui_manager_add_ui): Add 'type' and 'top' arguments to make this function as powerful as the XML methods of adding UI. (#120647) * gtk/gtk-sections.txt: Add GtkUIManagerItemType.
This commit is contained in:
parent
563746c795
commit
02a963e15b
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
||||
2003-09-04 Matthias Clasen <maclas@gmx.de>
|
||||
|
||||
* tests/testmerge.c (toggle_dynamic): Test gtk_ui_manager_add_ui().
|
||||
|
||||
* gtk/gtkuimanager.h: Add GtkUIManagerItemType enum which is needed for the
|
||||
'type' argument of gtk_ui_manager_add_ui().
|
||||
|
||||
* gtk/gtkuimanager.[hc] (gtk_ui_manager_add_ui): Add 'type' and 'top' arguments
|
||||
to make this function as powerful as the XML methods of adding UI. (#120647)
|
||||
|
||||
Thu Sep 4 19:11:23 2003 Kristian Rietveld <kris@gtk.org>
|
||||
|
||||
Merge from stable.
|
||||
|
@ -1,3 +1,13 @@
|
||||
2003-09-04 Matthias Clasen <maclas@gmx.de>
|
||||
|
||||
* tests/testmerge.c (toggle_dynamic): Test gtk_ui_manager_add_ui().
|
||||
|
||||
* gtk/gtkuimanager.h: Add GtkUIManagerItemType enum which is needed for the
|
||||
'type' argument of gtk_ui_manager_add_ui().
|
||||
|
||||
* gtk/gtkuimanager.[hc] (gtk_ui_manager_add_ui): Add 'type' and 'top' arguments
|
||||
to make this function as powerful as the XML methods of adding UI. (#120647)
|
||||
|
||||
Thu Sep 4 19:11:23 2003 Kristian Rietveld <kris@gtk.org>
|
||||
|
||||
Merge from stable.
|
||||
|
@ -1,3 +1,13 @@
|
||||
2003-09-04 Matthias Clasen <maclas@gmx.de>
|
||||
|
||||
* tests/testmerge.c (toggle_dynamic): Test gtk_ui_manager_add_ui().
|
||||
|
||||
* gtk/gtkuimanager.h: Add GtkUIManagerItemType enum which is needed for the
|
||||
'type' argument of gtk_ui_manager_add_ui().
|
||||
|
||||
* gtk/gtkuimanager.[hc] (gtk_ui_manager_add_ui): Add 'type' and 'top' arguments
|
||||
to make this function as powerful as the XML methods of adding UI. (#120647)
|
||||
|
||||
Thu Sep 4 19:11:23 2003 Kristian Rietveld <kris@gtk.org>
|
||||
|
||||
Merge from stable.
|
||||
|
@ -1,3 +1,13 @@
|
||||
2003-09-04 Matthias Clasen <maclas@gmx.de>
|
||||
|
||||
* tests/testmerge.c (toggle_dynamic): Test gtk_ui_manager_add_ui().
|
||||
|
||||
* gtk/gtkuimanager.h: Add GtkUIManagerItemType enum which is needed for the
|
||||
'type' argument of gtk_ui_manager_add_ui().
|
||||
|
||||
* gtk/gtkuimanager.[hc] (gtk_ui_manager_add_ui): Add 'type' and 'top' arguments
|
||||
to make this function as powerful as the XML methods of adding UI. (#120647)
|
||||
|
||||
Thu Sep 4 19:11:23 2003 Kristian Rietveld <kris@gtk.org>
|
||||
|
||||
Merge from stable.
|
||||
|
@ -1,3 +1,13 @@
|
||||
2003-09-04 Matthias Clasen <maclas@gmx.de>
|
||||
|
||||
* tests/testmerge.c (toggle_dynamic): Test gtk_ui_manager_add_ui().
|
||||
|
||||
* gtk/gtkuimanager.h: Add GtkUIManagerItemType enum which is needed for the
|
||||
'type' argument of gtk_ui_manager_add_ui().
|
||||
|
||||
* gtk/gtkuimanager.[hc] (gtk_ui_manager_add_ui): Add 'type' and 'top' arguments
|
||||
to make this function as powerful as the XML methods of adding UI. (#120647)
|
||||
|
||||
Thu Sep 4 19:11:23 2003 Kristian Rietveld <kris@gtk.org>
|
||||
|
||||
Merge from stable.
|
||||
|
@ -1,5 +1,7 @@
|
||||
2003-09-04 Matthias Clasen <maclas@gmx.de>
|
||||
|
||||
* gtk/gtk-sections.txt: Add GtkUIManagerItemType.
|
||||
|
||||
* gtk/tmpl/gtkuimanager.sgml: Change the name of the "pos"
|
||||
attribute to "position".
|
||||
|
||||
|
@ -1200,75 +1200,123 @@ gtk_ui_manager_add_ui_from_file (GtkUIManager *self,
|
||||
* @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
|
||||
* @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.
|
||||
*
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* Since: 2.4
|
||||
**/
|
||||
void
|
||||
gtk_ui_manager_add_ui (GtkUIManager *self,
|
||||
guint merge_id,
|
||||
const gchar *path,
|
||||
const gchar *name,
|
||||
const gchar *action)
|
||||
gtk_ui_manager_add_ui (GtkUIManager *self,
|
||||
guint merge_id,
|
||||
const gchar *path,
|
||||
const gchar *name,
|
||||
const gchar *action,
|
||||
GtkUIManagerItemType type,
|
||||
gboolean top)
|
||||
{
|
||||
GNode *node;
|
||||
GNode *child;
|
||||
NodeType type;
|
||||
NodeType node_type;
|
||||
GQuark action_quark = 0;
|
||||
|
||||
g_return_if_fail (GTK_IS_UI_MANAGER (self));
|
||||
g_return_if_fail (merge_id > 0);
|
||||
g_return_if_fail (name != NULL);
|
||||
|
||||
node = get_node (self, path, NODE_TYPE_UNDECIDED, FALSE);
|
||||
|
||||
if (node == NULL)
|
||||
return;
|
||||
|
||||
node_type = NODE_TYPE_UNDECIDED;
|
||||
|
||||
switch (NODE_INFO (node)->type)
|
||||
{
|
||||
case NODE_TYPE_MENUBAR:
|
||||
case NODE_TYPE_MENU:
|
||||
case NODE_TYPE_POPUP:
|
||||
case NODE_TYPE_MENU_PLACEHOLDER:
|
||||
if (action != NULL)
|
||||
type = NODE_TYPE_MENUITEM;
|
||||
else
|
||||
type = NODE_TYPE_SEPARATOR;
|
||||
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 */
|
||||
}
|
||||
break;
|
||||
case NODE_TYPE_TOOLBAR:
|
||||
case NODE_TYPE_TOOLBAR_PLACEHOLDER:
|
||||
if (action != NULL)
|
||||
type = NODE_TYPE_TOOLITEM;
|
||||
else
|
||||
type = NODE_TYPE_SEPARATOR;
|
||||
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 */
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
case NODE_TYPE_ROOT:
|
||||
switch (type)
|
||||
{
|
||||
case GTK_UI_MANAGER_MENUBAR:
|
||||
node_type = NODE_TYPE_MENUBAR;
|
||||
break;
|
||||
case GTK_UI_MANAGER_TOOLBAR:
|
||||
node_type = NODE_TYPE_TOOLBAR;
|
||||
break;
|
||||
case GTK_UI_MANAGER_POPUP:
|
||||
node_type = NODE_TYPE_POPUP;
|
||||
break;
|
||||
default: ;
|
||||
/* do nothing */
|
||||
}
|
||||
break;
|
||||
default: ;
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
if (name == NULL)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case NODE_TYPE_MENUITEM:
|
||||
name = "menuitem";
|
||||
break;
|
||||
case NODE_TYPE_TOOLITEM:
|
||||
name = "toolitem";
|
||||
break;
|
||||
case NODE_TYPE_SEPARATOR:
|
||||
name = "separator";
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
}
|
||||
|
||||
if (node_type == NODE_TYPE_UNDECIDED)
|
||||
return;
|
||||
|
||||
child = get_child_node (self, node,
|
||||
name, strlen (name),
|
||||
type, TRUE, FALSE);
|
||||
node_type, TRUE, top);
|
||||
|
||||
if (action != NULL)
|
||||
action_quark = g_quark_from_string (action);
|
||||
@ -1282,6 +1330,8 @@ gtk_ui_manager_add_ui (GtkUIManager *self,
|
||||
NODE_INFO (child)->dirty = TRUE;
|
||||
|
||||
queue_update (self);
|
||||
|
||||
g_signal_emit (self, merge_signals[CHANGED], 0);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -72,49 +72,54 @@ struct _GtkUIManagerClass {
|
||||
void (*_gtk_reserved4) (void);
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
GTK_UI_MANAGER_AUTO,
|
||||
GTK_UI_MANAGER_MENUBAR,
|
||||
GTK_UI_MANAGER_MENU,
|
||||
GTK_UI_MANAGER_TOOLBAR,
|
||||
GTK_UI_MANAGER_PLACEHOLDER,
|
||||
GTK_UI_MANAGER_POPUP,
|
||||
GTK_UI_MANAGER_MENUITEM,
|
||||
GTK_UI_MANAGER_TOOLITEM,
|
||||
GTK_UI_MANAGER_SEPARATOR
|
||||
} GtkUIManagerItemType;
|
||||
|
||||
GType gtk_ui_manager_get_type (void);
|
||||
GtkUIManager *gtk_ui_manager_new (void);
|
||||
|
||||
void gtk_ui_manager_set_add_tearoffs (GtkUIManager *self,
|
||||
gboolean add_tearoffs);
|
||||
gboolean gtk_ui_manager_get_add_tearoffs (GtkUIManager *self);
|
||||
|
||||
void gtk_ui_manager_insert_action_group (GtkUIManager *self,
|
||||
GtkActionGroup *action_group,
|
||||
gint pos);
|
||||
void gtk_ui_manager_remove_action_group (GtkUIManager *self,
|
||||
GtkActionGroup *action_group);
|
||||
GList *gtk_ui_manager_get_action_groups (GtkUIManager *self);
|
||||
GtkAccelGroup *gtk_ui_manager_get_accel_group (GtkUIManager *self);
|
||||
void gtk_ui_manager_set_add_tearoffs (GtkUIManager *self,
|
||||
gboolean add_tearoffs);
|
||||
gboolean gtk_ui_manager_get_add_tearoffs (GtkUIManager *self);
|
||||
void gtk_ui_manager_insert_action_group (GtkUIManager *self,
|
||||
GtkActionGroup *action_group,
|
||||
gint pos);
|
||||
void gtk_ui_manager_remove_action_group (GtkUIManager *self,
|
||||
GtkActionGroup *action_group);
|
||||
GList *gtk_ui_manager_get_action_groups (GtkUIManager *self);
|
||||
GtkAccelGroup *gtk_ui_manager_get_accel_group (GtkUIManager *self);
|
||||
GtkWidget *gtk_ui_manager_get_widget (GtkUIManager *self,
|
||||
const gchar *path);
|
||||
GtkAction *gtk_ui_manager_get_action (GtkUIManager *self,
|
||||
const gchar *path);
|
||||
guint gtk_ui_manager_add_ui_from_string (GtkUIManager *self,
|
||||
const gchar *buffer,
|
||||
gssize length,
|
||||
GError **error);
|
||||
guint gtk_ui_manager_add_ui_from_file (GtkUIManager *self,
|
||||
const gchar *filename,
|
||||
GError **error);
|
||||
void gtk_ui_manager_add_ui (GtkUIManager *self,
|
||||
guint merge_id,
|
||||
const gchar *path,
|
||||
const gchar *name,
|
||||
const gchar *action,
|
||||
GtkUIManagerItemType type,
|
||||
gboolean top);
|
||||
void gtk_ui_manager_remove_ui (GtkUIManager *self,
|
||||
guint merge_id);
|
||||
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);
|
||||
|
||||
|
||||
GtkWidget *gtk_ui_manager_get_widget (GtkUIManager *self,
|
||||
const gchar *path);
|
||||
GtkAction *gtk_ui_manager_get_action (GtkUIManager *self,
|
||||
const gchar *path);
|
||||
|
||||
/* these two functions are for adding UI elements to the merged user
|
||||
* interface */
|
||||
guint gtk_ui_manager_add_ui_from_string (GtkUIManager *self,
|
||||
const gchar *buffer,
|
||||
gssize length,
|
||||
GError **error);
|
||||
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);
|
||||
|
||||
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__ */
|
||||
|
@ -30,6 +30,57 @@ toggle_tearoffs (GtkWidget *button,
|
||||
gtk_ui_manager_set_add_tearoffs (merge, !add_tearoffs);
|
||||
}
|
||||
|
||||
static void
|
||||
toggle_dynamic (GtkWidget *button,
|
||||
GtkUIManager *merge)
|
||||
{
|
||||
GtkAction *dyn;
|
||||
static GtkActionGroup *dynamic = NULL;
|
||||
static guint merge_id = 0;
|
||||
|
||||
if (!dynamic)
|
||||
{
|
||||
dynamic = gtk_action_group_new ("dynamic");
|
||||
gtk_ui_manager_insert_action_group (merge, dynamic, 0);
|
||||
dyn = g_object_new (GTK_TYPE_ACTION,
|
||||
"name", "dyn1",
|
||||
"label", "Dynamic action 1",
|
||||
"stock_id", GTK_STOCK_COPY,
|
||||
NULL);
|
||||
gtk_action_group_add_action (dynamic, dyn);
|
||||
dyn = g_object_new (GTK_TYPE_ACTION,
|
||||
"name", "dyn2",
|
||||
"label", "Dynamic action 2",
|
||||
"stock_id", GTK_STOCK_EXECUTE,
|
||||
NULL);
|
||||
gtk_action_group_add_action (dynamic, dyn);
|
||||
}
|
||||
|
||||
if (merge_id == 0)
|
||||
{
|
||||
merge_id = gtk_ui_manager_new_merge_id (merge);
|
||||
gtk_ui_manager_add_ui (merge, merge_id, "/toolbar1/ToolbarPlaceholder",
|
||||
"dyn1", "dyn1", 0, 0);
|
||||
gtk_ui_manager_add_ui (merge, merge_id, "/toolbar1/ToolbarPlaceholder",
|
||||
"dynsep", NULL, GTK_UI_MANAGER_SEPARATOR, 0);
|
||||
gtk_ui_manager_add_ui (merge, merge_id, "/toolbar1/ToolbarPlaceholder",
|
||||
"dyn2", "dyn2", 0, 0);
|
||||
|
||||
gtk_ui_manager_add_ui (merge, merge_id, "/menubar/EditMenu",
|
||||
"dyn1menu", "dyn1", GTK_UI_MANAGER_MENU, 0);
|
||||
gtk_ui_manager_add_ui (merge, merge_id, "/menubar/EditMenu/dyn1menu",
|
||||
"dyn1", "dyn1", GTK_UI_MANAGER_MENUITEM, 0);
|
||||
gtk_ui_manager_add_ui (merge, merge_id, "/menubar/EditMenu/dyn1menu",
|
||||
"dyn2", "dyn2", GTK_UI_MANAGER_AUTO, TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_ui_manager_remove_ui (merge, merge_id);
|
||||
merge_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
activate_action (GtkAction *action)
|
||||
{
|
||||
@ -60,7 +111,6 @@ radio_action_changed (GtkAction *action, GtkRadioAction *current)
|
||||
gtk_radio_action_get_current_value (current));
|
||||
}
|
||||
|
||||
|
||||
static GtkActionEntry entries[] = {
|
||||
{ "FileMenuAction", NULL, "_File" },
|
||||
{ "EditMenuAction", NULL, "_Edit" },
|
||||
@ -452,6 +502,10 @@ main (int argc, char **argv)
|
||||
g_signal_connect (button, "clicked", G_CALLBACK (toggle_tearoffs), merge);
|
||||
gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);
|
||||
|
||||
button = gtk_check_button_new_with_label ("Dynamic");
|
||||
g_signal_connect (button, "clicked", G_CALLBACK (toggle_dynamic), merge);
|
||||
gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);
|
||||
|
||||
button = gtk_button_new_with_label ("Activate path");
|
||||
g_signal_connect (button, "clicked", G_CALLBACK (activate_path), merge);
|
||||
gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user