/* UndoNodesInsert.c generated by valac 0.56.19, the Vala compiler
 * generated from UndoNodesInsert.vala, do not modify */

/*
* Copyright (c) 2018-2026 (https://github.com/phase1geo/Minder)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* Authored by: Trevor Williams <phase1geo@gmail.com>
*/

#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define TYPE_UNDO_ITEM (undo_item_get_type ())
#define UNDO_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_UNDO_ITEM, UndoItem))
#define UNDO_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_UNDO_ITEM, UndoItemClass))
#define IS_UNDO_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_UNDO_ITEM))
#define IS_UNDO_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_UNDO_ITEM))
#define UNDO_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_UNDO_ITEM, UndoItemClass))

typedef struct _UndoItem UndoItem;
typedef struct _UndoItemClass UndoItemClass;
typedef struct _UndoItemPrivate UndoItemPrivate;

#define TYPE_MIND_MAP (mind_map_get_type ())
#define MIND_MAP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MIND_MAP, MindMap))
#define MIND_MAP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MIND_MAP, MindMapClass))
#define IS_MIND_MAP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MIND_MAP))
#define IS_MIND_MAP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MIND_MAP))
#define MIND_MAP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MIND_MAP, MindMapClass))

typedef struct _MindMap MindMap;
typedef struct _MindMapClass MindMapClass;

#define TYPE_UNDO_NODES_INSERT (undo_nodes_insert_get_type ())
#define UNDO_NODES_INSERT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_UNDO_NODES_INSERT, UndoNodesInsert))
#define UNDO_NODES_INSERT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_UNDO_NODES_INSERT, UndoNodesInsertClass))
#define IS_UNDO_NODES_INSERT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_UNDO_NODES_INSERT))
#define IS_UNDO_NODES_INSERT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_UNDO_NODES_INSERT))
#define UNDO_NODES_INSERT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_UNDO_NODES_INSERT, UndoNodesInsertClass))

typedef struct _UndoNodesInsert UndoNodesInsert;
typedef struct _UndoNodesInsertClass UndoNodesInsertClass;
typedef struct _UndoNodesInsertPrivate UndoNodesInsertPrivate;

#define UNDO_NODES_INSERT_TYPE_INSERTED_NODE (undo_nodes_insert_inserted_node_get_type ())
typedef struct _UndoNodesInsertInsertedNode UndoNodesInsertInsertedNode;

#define TYPE_NODE (node_get_type ())
#define NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_NODE, Node))
#define NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_NODE, NodeClass))
#define IS_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_NODE))
#define IS_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_NODE))
#define NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_NODE, NodeClass))

typedef struct _Node Node;
typedef struct _NodeClass NodeClass;
enum  {
	UNDO_NODES_INSERT_0_PROPERTY,
	UNDO_NODES_INSERT_NUM_PROPERTIES
};
static GParamSpec* undo_nodes_insert_properties[UNDO_NODES_INSERT_NUM_PROPERTIES];
#define _g_array_unref0(var) ((var == NULL) ? NULL : (var = (g_array_unref (var), NULL)))

#define TYPE_MAP_MODEL (map_model_get_type ())
#define MAP_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MAP_MODEL, MapModel))
#define MAP_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MAP_MODEL, MapModelClass))
#define IS_MAP_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MAP_MODEL))
#define IS_MAP_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MAP_MODEL))
#define MAP_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MAP_MODEL, MapModelClass))

typedef struct _MapModel MapModel;
typedef struct _MapModelClass MapModelClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef enum  {
	NODE_SIDE_LEFT = 1,
	NODE_SIDE_TOP = 2,
	NODE_SIDE_RIGHT = 4,
	NODE_SIDE_BOTTOM = 8
} NodeSide;

#define TYPE_NODE_SIDE (node_side_get_type ())
#define _undo_nodes_insert_inserted_node_free0(var) ((var == NULL) ? NULL : (var = (undo_nodes_insert_inserted_node_free (var), NULL)))

#define TYPE_THEME (theme_get_type ())
#define THEME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_THEME, Theme))
#define THEME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_THEME, ThemeClass))
#define IS_THEME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_THEME))
#define IS_THEME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_THEME))
#define THEME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_THEME, ThemeClass))

typedef struct _Theme Theme;
typedef struct _ThemeClass ThemeClass;

struct _UndoItem {
	GObject parent_instance;
	UndoItemPrivate * priv;
};

struct _UndoItemClass {
	GObjectClass parent_class;
	void (*undo) (UndoItem* self, MindMap* map);
	void (*redo) (UndoItem* self, MindMap* map);
	gboolean (*matches) (UndoItem* self, UndoItem* item);
	void (*replace_with_item) (UndoItem* self, UndoItem* item);
	gchar* (*to_string) (UndoItem* self);
};

struct _UndoNodesInsert {
	UndoItem parent_instance;
	UndoNodesInsertPrivate * priv;
};

struct _UndoNodesInsertClass {
	UndoItemClass parent_class;
};

struct _UndoNodesInsertInsertedNode {
	Node* parent;
	Node* n;
	gint index;
	gboolean parent_folded;
};

struct _UndoNodesInsertPrivate {
	GArray* _nodes;
};

static gint UndoNodesInsert_private_offset;
static gpointer undo_nodes_insert_parent_class = NULL;

VALA_EXTERN GType undo_item_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UndoItem, g_object_unref)
VALA_EXTERN gpointer mind_map_ref (gpointer instance);
VALA_EXTERN void mind_map_unref (gpointer instance);
VALA_EXTERN GParamSpec* param_spec_mind_map (const gchar* name,
                                 const gchar* nick,
                                 const gchar* blurb,
                                 GType object_type,
                                 GParamFlags flags);
VALA_EXTERN void value_set_mind_map (GValue* value,
                         gpointer v_object);
VALA_EXTERN void value_take_mind_map (GValue* value,
                          gpointer v_object);
VALA_EXTERN gpointer value_get_mind_map (const GValue* value);
VALA_EXTERN GType mind_map_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MindMap, mind_map_unref)
VALA_EXTERN GType undo_nodes_insert_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UndoNodesInsert, g_object_unref)
static GType undo_nodes_insert_inserted_node_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
VALA_EXTERN GType node_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Node, g_object_unref)
static UndoNodesInsertInsertedNode* undo_nodes_insert_inserted_node_dup (const UndoNodesInsertInsertedNode* self);
static void undo_nodes_insert_inserted_node_free (UndoNodesInsertInsertedNode* self);
static void undo_nodes_insert_inserted_node_copy (const UndoNodesInsertInsertedNode* self,
                                           UndoNodesInsertInsertedNode* dest);
static void undo_nodes_insert_inserted_node_destroy (UndoNodesInsertInsertedNode* self);
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC (UndoNodesInsertInsertedNode, undo_nodes_insert_inserted_node_destroy)
VALA_EXTERN void undo_item_undo (UndoItem* self,
                     MindMap* map);
VALA_EXTERN void undo_item_redo (UndoItem* self,
                     MindMap* map);
VALA_EXTERN UndoNodesInsert* undo_nodes_insert_new (MindMap* map,
                                        GArray* nodes);
VALA_EXTERN UndoNodesInsert* undo_nodes_insert_construct (GType object_type,
                                              MindMap* map,
                                              GArray* nodes);
VALA_EXTERN UndoItem* undo_item_new (const gchar* name);
VALA_EXTERN UndoItem* undo_item_construct (GType object_type,
                               const gchar* name);
static void _undo_nodes_insert_inserted_node_free0_ (gpointer var);
static void _vala_UndoNodesInsertInsertedNode_free_function_content_of (gpointer data);
VALA_EXTERN Node* node_get_parent (Node* self);
VALA_EXTERN gpointer map_model_ref (gpointer instance);
VALA_EXTERN void map_model_unref (gpointer instance);
VALA_EXTERN GParamSpec* param_spec_map_model (const gchar* name,
                                  const gchar* nick,
                                  const gchar* blurb,
                                  GType object_type,
                                  GParamFlags flags);
VALA_EXTERN void value_set_map_model (GValue* value,
                          gpointer v_object);
VALA_EXTERN void value_take_map_model (GValue* value,
                           gpointer v_object);
VALA_EXTERN gpointer value_get_map_model (const GValue* value);
VALA_EXTERN GType map_model_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MapModel, map_model_unref)
VALA_EXTERN MapModel* mind_map_get_model (MindMap* self);
VALA_EXTERN gint map_model_root_index (MapModel* self,
                           Node* root);
VALA_EXTERN gint node_index (Node* self);
VALA_EXTERN gboolean node_get_folded (Node* self);
static void undo_nodes_insert_real_undo (UndoItem* base,
                                  MindMap* map);
VALA_EXTERN void map_model_remove_root (MapModel* self,
                            gint index);
VALA_EXTERN void node_set_folded (Node* self,
                      gboolean value);
VALA_EXTERN GType node_side_get_type (void) G_GNUC_CONST ;
VALA_EXTERN void node_detach (Node* self,
                  NodeSide side);
VALA_EXTERN NodeSide node_get_side (Node* self);
VALA_EXTERN void mind_map_set_current_node (MindMap* self,
                                Node* n);
VALA_EXTERN void mind_map_queue_draw (MindMap* self);
VALA_EXTERN void mind_map_auto_save (MindMap* self);
static void undo_nodes_insert_real_redo (UndoItem* base,
                                  MindMap* map);
VALA_EXTERN void map_model_add_root (MapModel* self,
                         Node* n,
                         gint index);
VALA_EXTERN GType theme_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Theme, g_object_unref)
VALA_EXTERN void node_attach (Node* self,
                  Node* parent,
                  gint idx,
                  Theme* theme,
                  gboolean set_side);
static void undo_nodes_insert_finalize (GObject * obj);
static GType undo_nodes_insert_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
undo_nodes_insert_get_instance_private (UndoNodesInsert* self)
{
	return G_STRUCT_MEMBER_P (self, UndoNodesInsert_private_offset);
}

static void
_undo_nodes_insert_inserted_node_free0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (undo_nodes_insert_inserted_node_free (var), NULL));
}

static void
_vala_UndoNodesInsertInsertedNode_free_function_content_of (gpointer data)
{
	UndoNodesInsertInsertedNode* self;
	self = *((UndoNodesInsertInsertedNode**) data);
	_undo_nodes_insert_inserted_node_free0_ (self);
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static gpointer
_undo_nodes_insert_inserted_node_dup0 (gpointer self)
{
	return self ? undo_nodes_insert_inserted_node_dup (self) : NULL;
}

UndoNodesInsert*
undo_nodes_insert_construct (GType object_type,
                             MindMap* map,
                             GArray* nodes)
{
	UndoNodesInsert * self = NULL;
	GArray* _tmp0_;
	g_return_val_if_fail (map != NULL, NULL);
	g_return_val_if_fail (nodes != NULL, NULL);
	self = (UndoNodesInsert*) undo_item_construct (object_type, _ ("insert nodes"));
	_tmp0_ = g_array_new (TRUE, TRUE, sizeof (UndoNodesInsertInsertedNode*));
	g_array_set_clear_func (_tmp0_, (GDestroyNotify) _vala_UndoNodesInsertInsertedNode_free_function_content_of);
	_g_array_unref0 (self->priv->_nodes);
	self->priv->_nodes = _tmp0_;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp1_ = FALSE;
			_tmp1_ = TRUE;
			while (TRUE) {
				Node* node = NULL;
				Node* _tmp3_;
				Node* _tmp4_;
				Node* _tmp5_;
				Node* _tmp6_;
				Node* _tmp7_;
				if (!_tmp1_) {
					gint _tmp2_;
					_tmp2_ = i;
					i = _tmp2_ + 1;
				}
				_tmp1_ = FALSE;
				if (!(((guint) i) < nodes->len)) {
					break;
				}
				_tmp3_ = g_array_index (nodes, Node*, (guint) i);
				_tmp4_ = _g_object_ref0 (_tmp3_);
				node = _tmp4_;
				_tmp5_ = node;
				_tmp6_ = node_get_parent (_tmp5_);
				_tmp7_ = _tmp6_;
				if (_tmp7_ == NULL) {
					GArray* _tmp8_;
					Node* _tmp9_;
					Node* _tmp10_;
					MapModel* _tmp11_;
					MapModel* _tmp12_;
					Node* _tmp13_;
					UndoNodesInsertInsertedNode _tmp14_ = {0};
					UndoNodesInsertInsertedNode _tmp15_;
					UndoNodesInsertInsertedNode* _tmp16_;
					_tmp8_ = self->priv->_nodes;
					_tmp9_ = node;
					_tmp10_ = _g_object_ref0 (_tmp9_);
					_tmp11_ = mind_map_get_model (map);
					_tmp12_ = _tmp11_;
					_tmp13_ = node;
					_g_object_unref0 (_tmp14_.parent);
					_tmp14_.parent = NULL;
					_g_object_unref0 (_tmp14_.n);
					_tmp14_.n = _tmp10_;
					_tmp14_.index = map_model_root_index (_tmp12_, _tmp13_);
					_tmp14_.parent_folded = FALSE;
					_tmp15_ = _tmp14_;
					_tmp16_ = _undo_nodes_insert_inserted_node_dup0 (&_tmp15_);
					g_array_append_val (_tmp8_, _tmp16_);
					undo_nodes_insert_inserted_node_destroy (&_tmp15_);
				} else {
					GArray* _tmp17_;
					Node* _tmp18_;
					Node* _tmp19_;
					Node* _tmp20_;
					Node* _tmp21_;
					Node* _tmp22_;
					Node* _tmp23_;
					Node* _tmp24_;
					Node* _tmp25_;
					Node* _tmp26_;
					Node* _tmp27_;
					gboolean _tmp28_;
					gboolean _tmp29_;
					UndoNodesInsertInsertedNode _tmp30_ = {0};
					UndoNodesInsertInsertedNode _tmp31_;
					UndoNodesInsertInsertedNode* _tmp32_;
					_tmp17_ = self->priv->_nodes;
					_tmp18_ = node;
					_tmp19_ = node_get_parent (_tmp18_);
					_tmp20_ = _tmp19_;
					_tmp21_ = _g_object_ref0 (_tmp20_);
					_tmp22_ = node;
					_tmp23_ = _g_object_ref0 (_tmp22_);
					_tmp24_ = node;
					_tmp25_ = node;
					_tmp26_ = node_get_parent (_tmp25_);
					_tmp27_ = _tmp26_;
					_tmp28_ = node_get_folded (_tmp27_);
					_tmp29_ = _tmp28_;
					_g_object_unref0 (_tmp30_.parent);
					_tmp30_.parent = _tmp21_;
					_g_object_unref0 (_tmp30_.n);
					_tmp30_.n = _tmp23_;
					_tmp30_.index = node_index (_tmp24_);
					_tmp30_.parent_folded = _tmp29_;
					_tmp31_ = _tmp30_;
					_tmp32_ = _undo_nodes_insert_inserted_node_dup0 (&_tmp31_);
					g_array_append_val (_tmp17_, _tmp32_);
					undo_nodes_insert_inserted_node_destroy (&_tmp31_);
				}
				_g_object_unref0 (node);
			}
		}
	}
	return self;
}

UndoNodesInsert*
undo_nodes_insert_new (MindMap* map,
                       GArray* nodes)
{
	return undo_nodes_insert_construct (TYPE_UNDO_NODES_INSERT, map, nodes);
}

static void
undo_nodes_insert_real_undo (UndoItem* base,
                             MindMap* map)
{
	UndoNodesInsert * self;
	self = (UndoNodesInsert*) base;
	g_return_if_fail (map != NULL);
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				GArray* _tmp2_;
				UndoNodesInsertInsertedNode* node = NULL;
				GArray* _tmp3_;
				UndoNodesInsertInsertedNode* _tmp4_;
				UndoNodesInsertInsertedNode* _tmp5_;
				Node* _tmp6_;
				if (!_tmp0_) {
					gint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				_tmp2_ = self->priv->_nodes;
				if (!(((guint) i) < _tmp2_->len)) {
					break;
				}
				_tmp3_ = self->priv->_nodes;
				_tmp4_ = _undo_nodes_insert_inserted_node_dup0 (g_array_index (_tmp3_, UndoNodesInsertInsertedNode*, (guint) i));
				node = _tmp4_;
				_tmp5_ = node;
				_tmp6_ = (*_tmp5_).parent;
				if (_tmp6_ == NULL) {
					MapModel* _tmp7_;
					MapModel* _tmp8_;
					UndoNodesInsertInsertedNode* _tmp9_;
					_tmp7_ = mind_map_get_model (map);
					_tmp8_ = _tmp7_;
					_tmp9_ = node;
					map_model_remove_root (_tmp8_, (*_tmp9_).index);
				} else {
					UndoNodesInsertInsertedNode* _tmp10_;
					UndoNodesInsertInsertedNode* _tmp13_;
					Node* _tmp14_;
					UndoNodesInsertInsertedNode* _tmp15_;
					Node* _tmp16_;
					NodeSide _tmp17_;
					NodeSide _tmp18_;
					_tmp10_ = node;
					if ((*_tmp10_).parent_folded) {
						UndoNodesInsertInsertedNode* _tmp11_;
						Node* _tmp12_;
						_tmp11_ = node;
						_tmp12_ = (*_tmp11_).parent;
						node_set_folded (_tmp12_, TRUE);
					}
					_tmp13_ = node;
					_tmp14_ = (*_tmp13_).n;
					_tmp15_ = node;
					_tmp16_ = (*_tmp15_).n;
					_tmp17_ = node_get_side (_tmp16_);
					_tmp18_ = _tmp17_;
					node_detach (_tmp14_, _tmp18_);
				}
				_undo_nodes_insert_inserted_node_free0 (node);
			}
		}
	}
	mind_map_set_current_node (map, NULL);
	mind_map_queue_draw (map);
	mind_map_auto_save (map);
}

static void
undo_nodes_insert_real_redo (UndoItem* base,
                             MindMap* map)
{
	UndoNodesInsert * self;
	GArray* _tmp20_;
	Node* _tmp21_;
	self = (UndoNodesInsert*) base;
	g_return_if_fail (map != NULL);
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				GArray* _tmp2_;
				UndoNodesInsertInsertedNode* node = NULL;
				GArray* _tmp3_;
				UndoNodesInsertInsertedNode* _tmp4_;
				UndoNodesInsertInsertedNode* _tmp5_;
				Node* _tmp6_;
				if (!_tmp0_) {
					gint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				_tmp2_ = self->priv->_nodes;
				if (!(((guint) i) < _tmp2_->len)) {
					break;
				}
				_tmp3_ = self->priv->_nodes;
				_tmp4_ = _undo_nodes_insert_inserted_node_dup0 (g_array_index (_tmp3_, UndoNodesInsertInsertedNode*, (guint) i));
				node = _tmp4_;
				_tmp5_ = node;
				_tmp6_ = (*_tmp5_).parent;
				if (_tmp6_ == NULL) {
					MapModel* _tmp7_;
					MapModel* _tmp8_;
					UndoNodesInsertInsertedNode* _tmp9_;
					Node* _tmp10_;
					UndoNodesInsertInsertedNode* _tmp11_;
					_tmp7_ = mind_map_get_model (map);
					_tmp8_ = _tmp7_;
					_tmp9_ = node;
					_tmp10_ = (*_tmp9_).n;
					_tmp11_ = node;
					map_model_add_root (_tmp8_, _tmp10_, (*_tmp11_).index);
				} else {
					UndoNodesInsertInsertedNode* _tmp12_;
					Node* _tmp13_;
					UndoNodesInsertInsertedNode* _tmp14_;
					UndoNodesInsertInsertedNode* _tmp15_;
					Node* _tmp16_;
					UndoNodesInsertInsertedNode* _tmp17_;
					Node* _tmp18_;
					UndoNodesInsertInsertedNode* _tmp19_;
					_tmp12_ = node;
					_tmp13_ = (*_tmp12_).parent;
					_tmp14_ = node;
					node_set_folded (_tmp13_, (*_tmp14_).parent_folded);
					_tmp15_ = node;
					_tmp16_ = (*_tmp15_).n;
					_tmp17_ = node;
					_tmp18_ = (*_tmp17_).parent;
					_tmp19_ = node;
					node_attach (_tmp16_, _tmp18_, (*_tmp19_).index, NULL, TRUE);
				}
				_undo_nodes_insert_inserted_node_free0 (node);
			}
		}
	}
	_tmp20_ = self->priv->_nodes;
	_tmp21_ = (*g_array_index (_tmp20_, UndoNodesInsertInsertedNode*, (guint) 0)).n;
	mind_map_set_current_node (map, _tmp21_);
	mind_map_queue_draw (map);
	mind_map_auto_save (map);
}

static void
undo_nodes_insert_inserted_node_copy (const UndoNodesInsertInsertedNode* self,
                                      UndoNodesInsertInsertedNode* dest)
{
	Node* _tmp0_;
	Node* _tmp1_;
	Node* _tmp2_;
	Node* _tmp3_;
	_tmp0_ = (*self).parent;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 ((*dest).parent);
	(*dest).parent = _tmp1_;
	_tmp2_ = (*self).n;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	_g_object_unref0 ((*dest).n);
	(*dest).n = _tmp3_;
	(*dest).index = (*self).index;
	(*dest).parent_folded = (*self).parent_folded;
}

static void
undo_nodes_insert_inserted_node_destroy (UndoNodesInsertInsertedNode* self)
{
	_g_object_unref0 ((*self).parent);
	_g_object_unref0 ((*self).n);
}

static UndoNodesInsertInsertedNode*
undo_nodes_insert_inserted_node_dup (const UndoNodesInsertInsertedNode* self)
{
	UndoNodesInsertInsertedNode* dup;
	dup = g_new0 (UndoNodesInsertInsertedNode, 1);
	undo_nodes_insert_inserted_node_copy (self, dup);
	return dup;
}

static void
undo_nodes_insert_inserted_node_free (UndoNodesInsertInsertedNode* self)
{
	undo_nodes_insert_inserted_node_destroy (self);
	g_free (self);
}

static GType
undo_nodes_insert_inserted_node_get_type_once (void)
{
	GType undo_nodes_insert_inserted_node_type_id;
	undo_nodes_insert_inserted_node_type_id = g_boxed_type_register_static ("UndoNodesInsertInsertedNode", (GBoxedCopyFunc) undo_nodes_insert_inserted_node_dup, (GBoxedFreeFunc) undo_nodes_insert_inserted_node_free);
	return undo_nodes_insert_inserted_node_type_id;
}

static GType
undo_nodes_insert_inserted_node_get_type (void)
{
	static volatile gsize undo_nodes_insert_inserted_node_type_id__once = 0;
	if (g_once_init_enter (&undo_nodes_insert_inserted_node_type_id__once)) {
		GType undo_nodes_insert_inserted_node_type_id;
		undo_nodes_insert_inserted_node_type_id = undo_nodes_insert_inserted_node_get_type_once ();
		g_once_init_leave (&undo_nodes_insert_inserted_node_type_id__once, undo_nodes_insert_inserted_node_type_id);
	}
	return undo_nodes_insert_inserted_node_type_id__once;
}

static void
undo_nodes_insert_class_init (UndoNodesInsertClass * klass,
                              gpointer klass_data)
{
	undo_nodes_insert_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &UndoNodesInsert_private_offset);
	((UndoItemClass *) klass)->undo = (void (*) (UndoItem*, MindMap*)) undo_nodes_insert_real_undo;
	((UndoItemClass *) klass)->redo = (void (*) (UndoItem*, MindMap*)) undo_nodes_insert_real_redo;
	G_OBJECT_CLASS (klass)->finalize = undo_nodes_insert_finalize;
}

static void
undo_nodes_insert_instance_init (UndoNodesInsert * self,
                                 gpointer klass)
{
	self->priv = undo_nodes_insert_get_instance_private (self);
}

static void
undo_nodes_insert_finalize (GObject * obj)
{
	UndoNodesInsert * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_UNDO_NODES_INSERT, UndoNodesInsert);
	_g_array_unref0 (self->priv->_nodes);
	G_OBJECT_CLASS (undo_nodes_insert_parent_class)->finalize (obj);
}

static GType
undo_nodes_insert_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (UndoNodesInsertClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) undo_nodes_insert_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (UndoNodesInsert), 0, (GInstanceInitFunc) undo_nodes_insert_instance_init, NULL };
	GType undo_nodes_insert_type_id;
	undo_nodes_insert_type_id = g_type_register_static (TYPE_UNDO_ITEM, "UndoNodesInsert", &g_define_type_info, 0);
	UndoNodesInsert_private_offset = g_type_add_instance_private (undo_nodes_insert_type_id, sizeof (UndoNodesInsertPrivate));
	return undo_nodes_insert_type_id;
}

GType
undo_nodes_insert_get_type (void)
{
	static volatile gsize undo_nodes_insert_type_id__once = 0;
	if (g_once_init_enter (&undo_nodes_insert_type_id__once)) {
		GType undo_nodes_insert_type_id;
		undo_nodes_insert_type_id = undo_nodes_insert_get_type_once ();
		g_once_init_leave (&undo_nodes_insert_type_id__once, undo_nodes_insert_type_id);
	}
	return undo_nodes_insert_type_id__once;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

