#
# $Id: compoundedit.icn,v 1.1 2004-02-12 17:07:55 rparlett Exp $
#
# This file is in the public domain.
#
# Author: Robert Parlett (parlett@dial.pipex.com)
#

package undo

#
# An UndoableEdit which groups several edits together in a list.  The
# undo and redo methods are implemented to undo the edits in the list together.
#
class CompoundEdit:UndoableEdit(l, closed)
   method redo()
      every (!l).redo()
   end

   method undo()
      local i
      every i := *l to 1 by -1 do
         l[i].undo()
   end

   method add_edit(other)
      if \closed then
         fail
      l[-1].add_edit(other) | ::put(l, other)
      return
   end

   #
   # A closed CompoundEdit is one which cannot have any more
   # edits added to it by add_edit.
   #
   method close()
      self.closed := 1
   end

   #
   # Clear the list of edits.
   #
   method clear()
      self.l := []
   end

   initially()
      l := []
end
