+static guint
+psppire_data_window_add_ui (PsppireDataWindow *pdw, GtkUIManager *uim)
+{
+ gchar *ui_string;
+ guint merge_id;
+ GList *list;
+
+ ui_string = gtk_ui_manager_get_ui (uim);
+ merge_id = gtk_ui_manager_add_ui_from_string (pdw->ui_manager, ui_string,
+ -1, NULL);
+ g_free (ui_string);
+
+ g_return_val_if_fail (merge_id != 0, 0);
+
+ list = gtk_ui_manager_get_action_groups (uim);
+ for (; list != NULL; list = list->next)
+ {
+ GtkActionGroup *action_group = list->data;
+ GList *actions = gtk_action_group_list_actions (action_group);
+ GList *action;
+
+ for (action = actions; action != NULL; action = action->next)
+ {
+ GtkAction *a = action->data;
+
+ if (PSPPIRE_IS_DIALOG_ACTION (a))
+ g_object_set (a, "manager", pdw->ui_manager, NULL);
+ }
+
+ gtk_ui_manager_insert_action_group (pdw->ui_manager, action_group, 0);
+ }
+
+ gtk_window_add_accel_group (GTK_WINDOW (pdw),
+ gtk_ui_manager_get_accel_group (uim));
+
+ return merge_id;
+}
+
+static void
+psppire_data_window_remove_ui (PsppireDataWindow *pdw,
+ GtkUIManager *uim, guint merge_id)
+{
+ GList *list;
+
+ g_return_if_fail (merge_id != 0);
+
+ gtk_ui_manager_remove_ui (pdw->ui_manager, merge_id);
+
+ list = gtk_ui_manager_get_action_groups (uim);
+ for (; list != NULL; list = list->next)
+ {
+ GtkActionGroup *action_group = list->data;
+ gtk_ui_manager_remove_action_group (pdw->ui_manager, action_group);
+ }
+
+ gtk_window_remove_accel_group (GTK_WINDOW (pdw),
+ gtk_ui_manager_get_accel_group (uim));
+
+ /* Our caller unrefs 'uim', possibly causing 'uim' to be freed. The
+ following call appears to be necessary to ensure that pdw->ui_manager
+ drops all references to 'uim'. Otherwise, I get valgrind complaints about
+ access to freed memory (and segfaults) on e.g. Windows|Split View. */
+ gtk_ui_manager_ensure_update (pdw->ui_manager);
+}
+