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 UndoNodeMove : UndoItem { 25 26 private Node _n; 27 private NodeSide _old_side; 28 private int _old_index; 29 private NodeSide _new_side; 30 private int _new_index; 31 32 /* Default constructor */ 33 public UndoNodeMove( Node n, NodeSide old_side, int old_index ) { 34 base( _( "move node" ) ); 35 _n = n; 36 _old_side = old_side; 37 _old_index = old_index; 38 _new_side = n.side; 39 _new_index = n.index(); 40 } 41 42 /* Perform the node move change */ 43 public void change( DrawArea da, NodeSide old_side, NodeSide new_side, int new_index ) { 44 Node parent = _n.parent; 45 da.animator.add_nodes( da.get_nodes(), "undo move" ); 46 _n.detach( old_side ); 47 _n.side = new_side; 48 _n.layout.propagate_side( _n, new_side ); 49 _n.attach( parent, new_index, null, false ); 50 da.animator.animate(); 51 } 52 53 /* Performs an undo operation for this data */ 54 public override void undo( DrawArea da ) { 55 change( da, _new_side, _old_side, _old_index ); 56 } 57 58 /* Performs a redo operation */ 59 public override void redo( DrawArea da ) { 60 change( da, _old_side, _new_side, _new_index ); 61 } 62 63} 64