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 UndoNodesLink : UndoItem {
25
26  Array<Node>  _nodes;
27  Array<Node?> _linked;
28
29  /* Constructor for a node name change */
30  public UndoNodesLink( Array<Node> nodes ) {
31    base( _( "node link changes" ) );
32    _nodes  = new Array<Node>();
33    _linked = new Array<Node>();
34    for( int i=0; i<nodes.length; i++ ) {
35      _nodes.append_val( nodes.index( i ) );
36      _linked.append_val( nodes.index( i ).linked_node );
37    }
38  }
39
40  /* Undoes a node image change */
41  public override void undo( DrawArea da ) {
42    for( int i=0; i<_nodes.length; i++ ) {
43      _nodes.index( i ).linked_node = _linked.index( i );
44    }
45    da.queue_draw();
46    da.auto_save();
47  }
48
49  /* Redoes a node image change */
50  public override void redo( DrawArea da ) {
51    for( int i=0; i<(_nodes.length - 1); i++ ) {
52      _nodes.index( i ).linked_node = _nodes.index( i + 1 );
53    }
54    da.queue_draw();
55    da.auto_save();
56  }
57
58}
59