#!/usr/bin/ruby # # * BOOH * # # A.k.a `Best web-album Of the world, Or your money back, Humerus'. # # The acronyn sucks, however this is a tribute to Dragon Ball by # Akira Toriyama, where the last enemy beaten by heroes of Dragon # Ball is named "Boo". But there was already a free software project # called Boo, so this one will be it "Booh". Or whatever. # # # Copyright (c) 2004 Guillaume Cottenceau # # This software may be freely redistributed under the terms of the GNU # public license version 2. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. require 'gettext' include GetText bindtextdomain("booh") module UndoHandler @undo_actions = [] @redo_actions = [] module_function def save_undo(name, closure, params) @undo_actions << { :name => name, :closure => closure, :params => params } end def undo(statusbar) todo = @undo_actions.pop redo_closure = todo[:closure].call(*todo[:params]) statusbar.pop(0) statusbar.push(0, utf8(_("Undo %s.") % todo[:name])) @redo_actions << { :name => todo[:name], :redo => redo_closure, :undo => todo } return !@undo_actions.empty? end def redo(statusbar) redo_item = @redo_actions.pop redo_item[:redo].call statusbar.pop(0) statusbar.push(0, utf8(_("Redo %s.") % redo_item[:name])) @undo_actions << redo_item[:undo] return !@redo_actions.empty? end def cleanup @undo_actions.clear @redo_actions.clear end end