1/* 2* Copyright (c) 2018 (https://github.com/phase1geo/Minder) 3* 4* This program is free software; you can redistribute it and/or 5* modify it under the terms of the GNU General Public 6* License as published by the Free Software Foundation; either 7* version 2 of the License, or (at your option) any later version. 8* 9* This program is distributed in the hope that it will be useful, 10* but WITHOUT ANY WARRANTY; without even the implied warranty of 11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12* General Public License for more details. 13* 14* You should have received a copy of the GNU General Public 15* License along with this program; if not, write to the 16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17* Boston, MA 02110-1301 USA 18* 19* Authored by: Trevor Williams <phase1geo@gmail.com> 20*/ 21 22using Gtk; 23 24public class UndoNodeReparent : UndoItem { 25 26 private Node _node; 27 private int _first_index; 28 private int _last_index; 29 30 /* Default constructor */ 31 public UndoNodeReparent( Node node, int first_index, int last_index ) { 32 base( _( "reparent children" ) ); 33 _node = node; 34 _first_index = first_index; 35 _last_index = last_index; 36 } 37 38 /* Performs an undo operation for this data */ 39 public override void undo( DrawArea da ) { 40 da.animator.add_nodes( da.get_nodes(), "undo_make_children_siblings" ); 41 for( int i=(_last_index - 1); i>=_first_index; i-- ) { 42 var child = _node.parent.children().index( i ); 43 child.detach( child.side ); 44 child.attach( _node, 0, null ); 45 } 46 da.animator.animate(); 47 da.auto_save(); 48 } 49 50 /* Performs a redo operation */ 51 public override void redo( DrawArea da ) { 52 _node.make_children_siblings( _node.parent, false ); 53 da.auto_save(); 54 } 55 56} 57