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;
23using Gdk;
24
25public class UndoNodeAddParent : UndoItem {
26
27  private Node _parent;
28  private Node _child;
29
30  /* Default constructor */
31  public UndoNodeAddParent( Node parent, Node child ) {
32    base( _( "add parent node" ) );
33    _parent = parent;
34    _child  = child;
35  }
36
37  /* Performs an undo operation for this data */
38  public override void undo( DrawArea da ) {
39    var parent = _parent.parent;
40    var index  = _parent.index();
41    _child.detach( _child.side );
42    _parent.detach( _parent.side );
43    _child.attach( parent, index, null );
44    da.set_current_node( _child );
45    da.queue_draw();
46    da.auto_save();
47  }
48
49  /* Performs a redo operation */
50  public override void redo( DrawArea da ) {
51    var parent = _child.parent;
52    var index  = _child.index();
53    _child.detach( _child.side );
54    _parent.attach( parent, index, null );
55    _child.attach( _parent, -1, null );
56    da.set_current_node( _parent );
57    da.queue_draw();
58    da.auto_save();
59  }
60
61}
62