## GtkUIManager

GtkUIManager

## Functions

GtkUIManager * | gtk_ui_manager_new ()
void | gtk_ui_manager_set_add_tearoffs ()
gboolean | gtk_ui_manager_get_add_tearoffs ()
void | gtk_ui_manager_insert_action_group ()
void | gtk_ui_manager_remove_action_group ()
GList * | gtk_ui_manager_get_action_groups ()
GtkAccelGroup * | gtk_ui_manager_get_accel_group ()
GtkWidget * | gtk_ui_manager_get_widget ()
GSList * | gtk_ui_manager_get_toplevels ()
GtkAction * | gtk_ui_manager_get_action ()
guint | gtk_ui_manager_add_ui_from_string ()
guint | gtk_ui_manager_new_merge_id ()
void | gtk_ui_manager_add_ui ()
void | gtk_ui_manager_remove_ui ()
gchar * | gtk_ui_manager_get_ui ()
void | gtk_ui_manager_ensure_update ()

## Properties

gboolean | add-tearoffs | Read / Write
char * | ui | Read

## Signals

void | actions-changed | No Recursion
void | add-widget | No Recursion
void | connect-proxy | No Recursion
void | disconnect-proxy | No Recursion
void | post-activate | No Recursion
void | pre-activate | No Recursion

## Types and Values

struct | GtkUIManager
#define | gtk_ui_manager_add_ui_from_file
enum | GtkUIManagerItemType

## Object Hierarchy

        GObject
        ╰── GtkUIManager

## Implemented Interfaces

GtkUIManager implements GtkBuildable.

## Includes

    #include <gtk/gtk.h>

## Description

## Functions

### gtk_ui_manager_new ()

    GtkUIManager *
    gtk_ui_manager_new (void);

Creates a new ui manager object.

#### Returns

a new ui manager object.

Since: 2.4

### gtk_ui_manager_set_add_tearoffs ()

    void
    gtk_ui_manager_set_add_tearoffs (GtkUIManager *self,
                                     gboolean add_tearoffs);

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 menus never have tearoff menu items.

#### Parameters

self | a GtkUIManager |
add_tearoffs | whether tearoff menu items are added |

Since: 2.4

### gtk_ui_manager_get_add_tearoffs ()

    gboolean
    gtk_ui_manager_get_add_tearoffs (GtkUIManager *self);

Returns whether menus generated by this GtkUIManager will have tearoff menu items.

#### Parameters

self | a GtkUIManager |

#### Returns

whether tearoff menu items are added

Since: 2.4

### gtk_ui_manager_insert_action_group ()

    void
    gtk_ui_manager_insert_action_group (GtkUIManager *self,
                                        GtkActionGroup *action_group,
                                        gint pos);

Inserts an action group into the list of action groups associated with `self` . Actions in earlier groups hide actions with the same name in later groups.

#### Parameters

self | a GtkUIManager object |
action_group | the action group to be inserted |
pos | the position at which the group will be inserted. |

Since: 2.4

### gtk_ui_manager_remove_action_group ()

    void
    gtk_ui_manager_remove_action_group (GtkUIManager *self,
                                        GtkActionGroup *action_group);

Removes an action group from the list of action groups associated with `self` .

#### Parameters

self | a GtkUIManager object |
action_group | the action group to be removed |

Since: 2.4

### gtk_ui_manager_get_action_groups ()

    GList *
    gtk_ui_manager_get_action_groups (GtkUIManager *self);

Returns the list of action groups associated with `self` .

#### Parameters

self | a GtkUIManager object |

#### Returns

a GList of action groups. The list is owned by GTK+ and should not be modified.

[element-type GtkActionGroup][transfer none]

Since: 2.4

### gtk_ui_manager_get_accel_group ()

    GtkAccelGroup *
    gtk_ui_manager_get_accel_group (GtkUIManager *self);

Returns the GtkAccelGroup associated with `self` .

#### Parameters

self | a GtkUIManager object |

#### Returns

the GtkAccelGroup.

[transfer none]

Since: 2.4

### gtk_ui_manager_get_widget ()

    GtkWidget *
    gtk_ui_manager_get_widget (GtkUIManager *self,
                               const gchar *path);

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 (e.g. "popup"). The root element ("/ui") can be omitted in the path.

Note that the widget found by following a path that ends in a <menu> element is the menuitem to which the menu is attached, not the menu itself.

Also note that the widgets constructed by a ui manager are not tied to the lifecycle of the ui manager. If you add the widgets returned by this function to some container or explicitly ref them, they will survive the destruction of the ui manager.

#### Parameters

self | a GtkUIManager |
path | a path |

#### Returns

the widget found by following the path, or `NULL` if no widget was found.

[transfer none]

Since: 2.4

### gtk_ui_manager_get_toplevels ()

    GSList *
    gtk_ui_manager_get_toplevels (GtkUIManager *self,
                                  GtkUIManagerItemType types);

Obtains a list of all toplevel widgets of the requested types.

#### Parameters

self | a GtkUIManager |
types | specifies the types of toplevel widgets to include. Allowed types are GTK_UI_MANAGER_MENUBAR, GTK_UI_MANAGER_TOOLBAR and GTK_UI_MANAGER_POPUP. |

#### Returns

a newly-allocated GSList of all toplevel widgets of the requested types. Free the returned list with `g_slist_free()`.

[element-type GtkWidget][transfer container]

Since: 2.4

### gtk_ui_manager_get_action ()

    GtkAction *
    gtk_ui_manager_get_action (GtkUIManager *self,
                               const gchar *path);

Looks up an action by following a path. See `gtk_ui_manager_get_widget()` for more information about paths.

#### Parameters

self | a GtkUIManager |
path | a path |

#### Returns

the action whose proxy widget is found by following the path, or `NULL` if no widget was found.

[transfer none]

Since: 2.4

### gtk_ui_manager_add_ui_from_string ()

    guint
    gtk_ui_manager_add_ui_from_string (GtkUIManager *self,
                                       const gchar *buffer,
                                       gssize length,
                                       GError **error);

Parses a string containing a UI definition and merges it with the current contents of `self` . An enclosing <ui> element is added if it is missing.

#### Parameters

self | a GtkUIManager object |
buffer | the string to parse |
length | the length of `buffer` (may be -1 if `buffer` is nul-terminated) |
error | return location for an error |

#### Returns

The merge id for the merged UI. The merge id can be used to unmerge the UI with `gtk_ui_manager_remove_ui()`. If an error occurred, the return value is 0.

Since: 2.4

### gtk_ui_manager_new_merge_id ()

    guint
    gtk_ui_manager_new_merge_id (GtkUIManager *self);

Returns an unused merge id, suitable for use with `gtk_ui_manager_add_ui()`.

#### Parameters

self | a GtkUIManager |

#### Returns

an unused merge id.

Since: 2.4

### gtk_ui_manager_add_ui ()

    void
    gtk_ui_manager_add_ui (GtkUIManager *self,
                           guint merge_id,
                           const gchar *path,
                           const gchar *name,
                           const gchar *action,
                           GtkUIManagerItemType type,
                           gboolean top);

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` .

If `path` points to a menuitem or toolitem, the new element will be inserted before or after this item, depending on `top` .

#### Parameters

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. | [allow-none]
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. |

Since: 2.4

### gtk_ui_manager_remove_ui ()

    void
    gtk_ui_manager_remove_ui (GtkUIManager *self,
                              guint merge_id);

Unmerges the part of `self` s content identified by `merge_id` .

#### Parameters

self | a GtkUIManager object |
merge_id | a merge id as returned by `gtk_ui_manager_add_ui_from_string()` |

Since: 2.4

### gtk_ui_manager_get_ui ()

    gchar *
    gtk_ui_manager_get_ui (GtkUIManager *self);

Creates a UI definition of the merged UI.

#### Parameters

self | a GtkUIManager |

#### Returns

A newly allocated string containing an XML representation of the merged UI.

Since: 2.4

### gtk_ui_manager_ensure_update ()

    void
    gtk_ui_manager_ensure_update (GtkUIManager *self);

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:

    1
    2
    3
    4
    5
    6
    7

    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);

#### Parameters

self | a GtkUIManager |

Since: 2.4

## Types and Values

### struct GtkUIManager

    struct GtkUIManager;

### gtk_ui_manager_add_ui_from_file

    #define gtk_ui_manager_add_ui_from_file gtk_ui_manager_add_ui_from_file_utf8

Parses a file containing a UI definition and merges it with the current contents of `self` .

#### Parameters

self | a GtkUIManager object |
filename | the name of the file to parse |
error | return location for an error |

#### Returns

The merge id for the merged UI. The merge id can be used to unmerge the UI with `gtk_ui_manager_remove_ui()`. If an error occurred, the return value is 0.

Since: 2.4

### enum GtkUIManagerItemType

#### Members

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 |  |
GTK_UI_MANAGER_ACCELERATOR |  |
GTK_UI_MANAGER_POPUP_WITH_ACCELS |  |

## Property Details

### The `“add-tearoffs”` property

      “add-tearoffs”             gboolean

The "add-tearoffs" property controls whether generated menus have tearoff menu items.

Note that this only affects regular menus. Generated popup menus never have tearoff menu items.

Owner: GtkUIManager

Flags: Read / Write

Default value: FALSE

Since: 2.4

### The `“ui”` property

      “ui”                       char *

An XML string describing the merged UI.

Owner: GtkUIManager

Flags: Read

Default value: "<ui>\n</ui>\n"

## Signal Details

### The `“actions-changed”` signal

    void
    user_function (GtkUIManager *merge,
                   gpointer      user_data)

The "actions-changed" signal is emitted whenever the set of actions changes.

#### Parameters

merge | a GtkUIManager |
user_data | user data set when the signal handler was connected. |

Flags: No Recursion

Since: 2.4

### The `“add-widget”` signal

    void
    user_function (GtkUIManager *merge,
                   GtkWidget    *widget,
                   gpointer      user_data)

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()`.

#### Parameters

merge | a GtkUIManager |
widget | the added widget |
user_data | user data set when the signal handler was connected. |

Flags: No Recursion

Since: 2.4

### The `“connect-proxy”` signal

    void
    user_function (GtkUIManager *uimanager,
                   GtkAction    *action,
                   GtkWidget    *proxy,
                   gpointer      user_data)

The connect_proxy signal is emitted after connecting a proxy to an action in the group.

This is intended for simple customizations for which a custom action class would be too clumsy, e.g. showing tooltips for menuitems in the statusbar.

#### Parameters

uimanager | the ui manager |
action | the action |
proxy | the proxy |
user_data | user data set when the signal handler was connected. |

Flags: No Recursion

Since: 2.4

### The `“disconnect-proxy”` signal

    void
    user_function (GtkUIManager *uimanager,
                   GtkAction    *action,
                   GtkWidget    *proxy,
                   gpointer      user_data)

The disconnect_proxy signal is emitted after disconnecting a proxy from an action in the group.

#### Parameters

uimanager | the ui manager |
action | the action |
proxy | the proxy |
user_data | user data set when the signal handler was connected. |

Flags: No Recursion

Since: 2.4

### The `“post-activate”` signal

    void
    user_function (GtkUIManager *uimanager,
                   GtkAction    *action,
                   gpointer      user_data)

The post_activate signal is emitted just after the `action` is activated.

This is intended for applications to get notification just after any action is activated.

#### Parameters

uimanager | the ui manager |
action | the action |
user_data | user data set when the signal handler was connected. |

Flags: No Recursion

Since: 2.4

### The `“pre-activate”` signal

    void
    user_function (GtkUIManager *uimanager,
                   GtkAction    *action,
                   gpointer      user_data)

The pre_activate signal is emitted just before the `action` is activated.

This is intended for applications to get notification just before any action is activated.

#### Parameters

uimanager | the ui manager |
action | the action |
user_data | user data set when the signal handler was connected. |

Flags: No Recursion

Since: 2.4