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

/*
* Copyright (c) 2025-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_ATTACH (undo_nodes_attach_get_type ())
#define UNDO_NODES_ATTACH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_UNDO_NODES_ATTACH, UndoNodesAttach))
#define UNDO_NODES_ATTACH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_UNDO_NODES_ATTACH, UndoNodesAttachClass))
#define IS_UNDO_NODES_ATTACH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_UNDO_NODES_ATTACH))
#define IS_UNDO_NODES_ATTACH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_UNDO_NODES_ATTACH))
#define UNDO_NODES_ATTACH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_UNDO_NODES_ATTACH, UndoNodesAttachClass))

typedef struct _UndoNodesAttach UndoNodesAttach;
typedef struct _UndoNodesAttachClass UndoNodesAttachClass;
typedef struct _UndoNodesAttachPrivate UndoNodesAttachPrivate;

#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_ATTACH_0_PROPERTY,
	UNDO_NODES_ATTACH_NUM_PROPERTIES
};
static GParamSpec* undo_nodes_attach_properties[UNDO_NODES_ATTACH_NUM_PROPERTIES];
#define _g_array_unref0(var) ((var == NULL) ? NULL : (var = (g_array_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef enum  {
	NODE_MODE_NONE = 0,
	NODE_MODE_CURRENT,
	NODE_MODE_SELECTED,
	NODE_MODE_EDITABLE,
	NODE_MODE_ATTACHABLE,
	NODE_MODE_DROPPABLE,
	NODE_MODE_HIGHLIGHTED
} NodeMode;

#define TYPE_NODE_MODE (node_mode_get_type ())

#define TYPE_ANIMATOR (animator_get_type ())
#define ANIMATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_ANIMATOR, Animator))
#define ANIMATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_ANIMATOR, AnimatorClass))
#define IS_ANIMATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_ANIMATOR))
#define IS_ANIMATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_ANIMATOR))
#define ANIMATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_ANIMATOR, AnimatorClass))

typedef struct _Animator Animator;
typedef struct _AnimatorClass AnimatorClass;
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 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;

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

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 _UndoNodesAttach {
	UndoItem parent_instance;
	UndoNodesAttachPrivate * priv;
};

struct _UndoNodesAttachClass {
	UndoItemClass parent_class;
};

struct _UndoNodesAttachPrivate {
	GArray* _nodes;
	GArray* _indices;
	GArray* _parents;
	GArray* _children;
	Node* _parent;
};

static gint UndoNodesAttach_private_offset;
static gpointer undo_nodes_attach_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_attach_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UndoNodesAttach, g_object_unref)
VALA_EXTERN GType node_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Node, g_object_unref)
VALA_EXTERN void undo_item_undo (UndoItem* self,
                     MindMap* map);
VALA_EXTERN void undo_item_redo (UndoItem* self,
                     MindMap* map);
VALA_EXTERN UndoNodesAttach* undo_nodes_attach_new (GArray* nodes,
                                        Node* parent);
VALA_EXTERN UndoNodesAttach* undo_nodes_attach_construct (GType object_type,
                                              GArray* nodes,
                                              Node* parent);
VALA_EXTERN UndoItem* undo_item_new (const gchar* name);
VALA_EXTERN UndoItem* undo_item_construct (GType object_type,
                               const gchar* name);
static void _g_object_unref0_ (gpointer var);
static void _vala_Node_free_function_content_of (gpointer data);
VALA_EXTERN gint node_index (Node* self);
VALA_EXTERN Node* node_get_parent (Node* self);
VALA_EXTERN GArray* node_children (Node* self);
VALA_EXTERN GType node_mode_get_type (void) G_GNUC_CONST ;
VALA_EXTERN NodeMode node_get_mode (Node* self);
static void undo_nodes_attach_real_undo (UndoItem* base,
                                  MindMap* map);
VALA_EXTERN GType animator_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Animator, g_object_unref)
VALA_EXTERN Animator* mind_map_get_animator (MindMap* self);
VALA_EXTERN void animator_add_nodes (Animator* self,
                         GArray* n,
                         gboolean exclude_selected,
                         const gchar* name);
VALA_EXTERN GArray* mind_map_get_nodes (MindMap* self);
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 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);
VALA_EXTERN void animator_animate (Animator* self);
VALA_EXTERN void mind_map_auto_save (MindMap* self);
static void undo_nodes_attach_real_redo (UndoItem* base,
                                  MindMap* map);
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 void map_model_attach_nodes (MapModel* self,
                             GArray* nodes,
                             Node* parent);
static void undo_nodes_attach_finalize (GObject * obj);
static GType undo_nodes_attach_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
undo_nodes_attach_get_instance_private (UndoNodesAttach* self)
{
	return G_STRUCT_MEMBER_P (self, UndoNodesAttach_private_offset);
}

static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}

static void
_vala_Node_free_function_content_of (gpointer data)
{
	Node* self;
	self = *((Node**) data);
	_g_object_unref0_ (self);
}

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

UndoNodesAttach*
undo_nodes_attach_construct (GType object_type,
                             GArray* nodes,
                             Node* parent)
{
	UndoNodesAttach * self = NULL;
	GArray* _tmp0_;
	GArray* _tmp1_;
	GArray* _tmp2_;
	GArray* _tmp3_;
	Node* _tmp4_;
	g_return_val_if_fail (nodes != NULL, NULL);
	g_return_val_if_fail (parent != NULL, NULL);
	self = (UndoNodesAttach*) undo_item_construct (object_type, _ ("nodes attach"));
	_tmp0_ = g_array_new (TRUE, TRUE, sizeof (Node*));
	g_array_set_clear_func (_tmp0_, (GDestroyNotify) _vala_Node_free_function_content_of);
	_g_array_unref0 (self->priv->_nodes);
	self->priv->_nodes = _tmp0_;
	_tmp1_ = g_array_new (TRUE, TRUE, sizeof (gint));
	_g_array_unref0 (self->priv->_indices);
	self->priv->_indices = _tmp1_;
	_tmp2_ = g_array_new (TRUE, TRUE, sizeof (Node*));
	g_array_set_clear_func (_tmp2_, (GDestroyNotify) _vala_Node_free_function_content_of);
	_g_array_unref0 (self->priv->_parents);
	self->priv->_parents = _tmp2_;
	_tmp3_ = g_array_new (TRUE, TRUE, sizeof (gint));
	_g_array_unref0 (self->priv->_children);
	self->priv->_children = _tmp3_;
	_tmp4_ = _g_object_ref0 (parent);
	_g_object_unref0 (self->priv->_parent);
	self->priv->_parent = _tmp4_;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp5_ = FALSE;
			_tmp5_ = TRUE;
			while (TRUE) {
				Node* node = NULL;
				Node* _tmp7_;
				Node* _tmp8_;
				gint index = 0;
				Node* _tmp9_;
				Node* par = NULL;
				Node* _tmp10_;
				Node* _tmp11_;
				Node* _tmp12_;
				Node* _tmp13_;
				gint children = 0;
				GArray* _tmp30_;
				Node* _tmp31_;
				Node* _tmp32_;
				GArray* _tmp33_;
				GArray* _tmp34_;
				Node* _tmp35_;
				Node* _tmp36_;
				GArray* _tmp37_;
				if (!_tmp5_) {
					gint _tmp6_;
					_tmp6_ = i;
					i = _tmp6_ + 1;
				}
				_tmp5_ = FALSE;
				if (!(((guint) i) < nodes->len)) {
					break;
				}
				_tmp7_ = g_array_index (nodes, Node*, (guint) i);
				_tmp8_ = _g_object_ref0 (_tmp7_);
				node = _tmp8_;
				_tmp9_ = node;
				index = node_index (_tmp9_);
				_tmp10_ = node;
				_tmp11_ = node_get_parent (_tmp10_);
				_tmp12_ = _tmp11_;
				_tmp13_ = _g_object_ref0 (_tmp12_);
				par = _tmp13_;
				children = 0;
				{
					gint j = 0;
					j = 0;
					{
						gboolean _tmp14_ = FALSE;
						_tmp14_ = TRUE;
						while (TRUE) {
							Node* _tmp16_;
							GArray* _tmp17_;
							GArray* _tmp18_;
							gboolean _tmp19_;
							Node* child = NULL;
							Node* _tmp20_;
							GArray* _tmp21_;
							GArray* _tmp22_;
							Node* _tmp23_;
							Node* _tmp24_;
							Node* _tmp25_;
							gint _tmp26_ = 0;
							Node* _tmp27_;
							NodeMode _tmp28_;
							NodeMode _tmp29_;
							if (!_tmp14_) {
								gint _tmp15_;
								_tmp15_ = j;
								j = _tmp15_ + 1;
							}
							_tmp14_ = FALSE;
							_tmp16_ = node;
							_tmp17_ = node_children (_tmp16_);
							_tmp18_ = _tmp17_;
							_tmp19_ = !(((guint) j) < _tmp18_->len);
							_g_array_unref0 (_tmp18_);
							if (_tmp19_) {
								break;
							}
							_tmp20_ = node;
							_tmp21_ = node_children (_tmp20_);
							_tmp22_ = _tmp21_;
							_tmp23_ = g_array_index (_tmp22_, Node*, (guint) j);
							_tmp24_ = _g_object_ref0 (_tmp23_);
							_tmp25_ = _tmp24_;
							_g_array_unref0 (_tmp22_);
							child = _tmp25_;
							_tmp27_ = child;
							_tmp28_ = node_get_mode (_tmp27_);
							_tmp29_ = _tmp28_;
							if (_tmp29_ != NODE_MODE_SELECTED) {
								_tmp26_ = 1;
							} else {
								_tmp26_ = 0;
							}
							children += _tmp26_;
							_g_object_unref0 (child);
						}
					}
				}
				_tmp30_ = self->priv->_nodes;
				_tmp31_ = node;
				_tmp32_ = _g_object_ref0 (_tmp31_);
				g_array_append_val (_tmp30_, _tmp32_);
				_tmp33_ = self->priv->_indices;
				g_array_append_val (_tmp33_, index);
				_tmp34_ = self->priv->_parents;
				_tmp35_ = par;
				_tmp36_ = _g_object_ref0 (_tmp35_);
				g_array_append_val (_tmp34_, _tmp36_);
				_tmp37_ = self->priv->_children;
				g_array_append_val (_tmp37_, children);
				_g_object_unref0 (par);
				_g_object_unref0 (node);
			}
		}
	}
	return self;
}

UndoNodesAttach*
undo_nodes_attach_new (GArray* nodes,
                       Node* parent)
{
	return undo_nodes_attach_construct (TYPE_UNDO_NODES_ATTACH, nodes, parent);
}

static void
undo_nodes_attach_real_undo (UndoItem* base,
                             MindMap* map)
{
	UndoNodesAttach * self;
	Animator* _tmp0_;
	Animator* _tmp1_;
	GArray* _tmp2_;
	GArray* _tmp3_;
	Animator* _tmp35_;
	Animator* _tmp36_;
	self = (UndoNodesAttach*) base;
	g_return_if_fail (map != NULL);
	_tmp0_ = mind_map_get_animator (map);
	_tmp1_ = _tmp0_;
	_tmp2_ = mind_map_get_nodes (map);
	_tmp3_ = _tmp2_;
	animator_add_nodes (_tmp1_, _tmp3_, FALSE, "attach_nodes_undo");
	_g_array_unref0 (_tmp3_);
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp4_ = FALSE;
			_tmp4_ = TRUE;
			while (TRUE) {
				GArray* _tmp6_;
				Node* node = NULL;
				GArray* _tmp7_;
				Node* _tmp8_;
				Node* _tmp9_;
				gint index = 0;
				GArray* _tmp10_;
				Node* parent = NULL;
				GArray* _tmp11_;
				Node* _tmp12_;
				Node* _tmp13_;
				Node* _tmp14_;
				Node* _tmp15_;
				NodeSide _tmp16_;
				NodeSide _tmp17_;
				Node* _tmp18_;
				Node* _tmp19_;
				if (!_tmp4_) {
					gint _tmp5_;
					_tmp5_ = i;
					i = _tmp5_ + 1;
				}
				_tmp4_ = FALSE;
				_tmp6_ = self->priv->_nodes;
				if (!(((guint) i) < _tmp6_->len)) {
					break;
				}
				_tmp7_ = self->priv->_nodes;
				_tmp8_ = g_array_index (_tmp7_, Node*, (guint) i);
				_tmp9_ = _g_object_ref0 (_tmp8_);
				node = _tmp9_;
				_tmp10_ = self->priv->_indices;
				index = g_array_index (_tmp10_, gint, (guint) i);
				_tmp11_ = self->priv->_parents;
				_tmp12_ = g_array_index (_tmp11_, Node*, (guint) i);
				_tmp13_ = _g_object_ref0 (_tmp12_);
				parent = _tmp13_;
				_tmp14_ = node;
				_tmp15_ = node;
				_tmp16_ = node_get_side (_tmp15_);
				_tmp17_ = _tmp16_;
				node_detach (_tmp14_, _tmp17_);
				_tmp18_ = node;
				_tmp19_ = parent;
				node_attach (_tmp18_, _tmp19_, index, NULL, TRUE);
				{
					gint j = 0;
					j = 0;
					{
						gboolean _tmp20_ = FALSE;
						_tmp20_ = TRUE;
						while (TRUE) {
							GArray* _tmp22_;
							Node* child = NULL;
							Node* _tmp23_;
							GArray* _tmp24_;
							GArray* _tmp25_;
							Node* _tmp26_;
							Node* _tmp27_;
							Node* _tmp28_;
							Node* _tmp29_;
							Node* _tmp30_;
							NodeSide _tmp31_;
							NodeSide _tmp32_;
							Node* _tmp33_;
							Node* _tmp34_;
							if (!_tmp20_) {
								gint _tmp21_;
								_tmp21_ = j;
								j = _tmp21_ + 1;
							}
							_tmp20_ = FALSE;
							_tmp22_ = self->priv->_children;
							if (!(j < g_array_index (_tmp22_, gint, (guint) i))) {
								break;
							}
							_tmp23_ = parent;
							_tmp24_ = node_children (_tmp23_);
							_tmp25_ = _tmp24_;
							_tmp26_ = g_array_index (_tmp25_, Node*, (guint) (index + 1));
							_tmp27_ = _g_object_ref0 (_tmp26_);
							_tmp28_ = _tmp27_;
							_g_array_unref0 (_tmp25_);
							child = _tmp28_;
							_tmp29_ = child;
							_tmp30_ = child;
							_tmp31_ = node_get_side (_tmp30_);
							_tmp32_ = _tmp31_;
							node_detach (_tmp29_, _tmp32_);
							_tmp33_ = child;
							_tmp34_ = node;
							node_attach (_tmp33_, _tmp34_, -1, NULL, TRUE);
							_g_object_unref0 (child);
						}
					}
				}
				_g_object_unref0 (parent);
				_g_object_unref0 (node);
			}
		}
	}
	_tmp35_ = mind_map_get_animator (map);
	_tmp36_ = _tmp35_;
	animator_animate (_tmp36_);
	mind_map_auto_save (map);
}

static void
undo_nodes_attach_real_redo (UndoItem* base,
                             MindMap* map)
{
	UndoNodesAttach * self;
	Animator* _tmp0_;
	Animator* _tmp1_;
	GArray* _tmp2_;
	GArray* _tmp3_;
	MapModel* _tmp4_;
	MapModel* _tmp5_;
	GArray* _tmp6_;
	Node* _tmp7_;
	Animator* _tmp8_;
	Animator* _tmp9_;
	self = (UndoNodesAttach*) base;
	g_return_if_fail (map != NULL);
	_tmp0_ = mind_map_get_animator (map);
	_tmp1_ = _tmp0_;
	_tmp2_ = mind_map_get_nodes (map);
	_tmp3_ = _tmp2_;
	animator_add_nodes (_tmp1_, _tmp3_, FALSE, "attach_nodes_redo");
	_g_array_unref0 (_tmp3_);
	_tmp4_ = mind_map_get_model (map);
	_tmp5_ = _tmp4_;
	_tmp6_ = self->priv->_nodes;
	_tmp7_ = self->priv->_parent;
	map_model_attach_nodes (_tmp5_, _tmp6_, _tmp7_);
	_tmp8_ = mind_map_get_animator (map);
	_tmp9_ = _tmp8_;
	animator_animate (_tmp9_);
	mind_map_auto_save (map);
}

static void
undo_nodes_attach_class_init (UndoNodesAttachClass * klass,
                              gpointer klass_data)
{
	undo_nodes_attach_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &UndoNodesAttach_private_offset);
	((UndoItemClass *) klass)->undo = (void (*) (UndoItem*, MindMap*)) undo_nodes_attach_real_undo;
	((UndoItemClass *) klass)->redo = (void (*) (UndoItem*, MindMap*)) undo_nodes_attach_real_redo;
	G_OBJECT_CLASS (klass)->finalize = undo_nodes_attach_finalize;
}

static void
undo_nodes_attach_instance_init (UndoNodesAttach * self,
                                 gpointer klass)
{
	self->priv = undo_nodes_attach_get_instance_private (self);
}

static void
undo_nodes_attach_finalize (GObject * obj)
{
	UndoNodesAttach * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_UNDO_NODES_ATTACH, UndoNodesAttach);
	_g_array_unref0 (self->priv->_nodes);
	_g_array_unref0 (self->priv->_indices);
	_g_array_unref0 (self->priv->_parents);
	_g_array_unref0 (self->priv->_children);
	_g_object_unref0 (self->priv->_parent);
	G_OBJECT_CLASS (undo_nodes_attach_parent_class)->finalize (obj);
}

static GType
undo_nodes_attach_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (UndoNodesAttachClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) undo_nodes_attach_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (UndoNodesAttach), 0, (GInstanceInitFunc) undo_nodes_attach_instance_init, NULL };
	GType undo_nodes_attach_type_id;
	undo_nodes_attach_type_id = g_type_register_static (TYPE_UNDO_ITEM, "UndoNodesAttach", &g_define_type_info, 0);
	UndoNodesAttach_private_offset = g_type_add_instance_private (undo_nodes_attach_type_id, sizeof (UndoNodesAttachPrivate));
	return undo_nodes_attach_type_id;
}

GType
undo_nodes_attach_get_type (void)
{
	static volatile gsize undo_nodes_attach_type_id__once = 0;
	if (g_once_init_enter (&undo_nodes_attach_type_id__once)) {
		GType undo_nodes_attach_type_id;
		undo_nodes_attach_type_id = undo_nodes_attach_get_type_once ();
		g_once_init_leave (&undo_nodes_attach_type_id__once, undo_nodes_attach_type_id);
	}
	return undo_nodes_attach_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;
}

