%% undo_call
%   called when user selects undo, calls undomanager and performs action
% inputs:
%   object - GUI object
%   src - source object
%   event - event data
% outputs:
%   none
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function [] = undo_call(object,src,event)

object.undo_man;
recalled_data = object.undo_man.undo;
if isempty(recalled_data);
    return;
else
    switch recalled_data.action
        case 1 % changed cell contents
            try
                set(recalled_data.cell,'String',recalled_data.text);
            catch exception
            end
        case 2 % created new cell in grid
            recalled_data.grid.pb_delete_call(recalled_data.grid.delete_cell_pb,1);
        case 3 % deleted cell in grid (not the last)
            recalled_data.grid.cells = [recalled_data.grid.cells recalled_data.cell];
            recalled_data.grid.num_cells = recalled_data.grid.num_cells + 1;
            % refresh the rGrid so that a new results cell is created
            if(~isempty(recalled_data.grid.rGrid))
                recalled_data.grid.rGrid.refresh;
            end
            object.reset_wh();
            object.draw_allgrids(1);
            object.undo_man.search_replace(1,recalled_data.subgrid,recalled_data.cell.cond);
            set(recalled_data.grid.delete_cell_pb,'Enable','on');
            
        case 4 % new grid
            recalled_data.grid.deep_delete;
            recalled_data.cell.subgrid = [];
            recalled_data.cell.pb_flag = 1;
            object.reset_wh();
            object.draw_allgrids(1);
            
        case 5 % deleting last cell in grid
            recalled_data.cell.subgrid = recalled_data.grid;
            recalled_data.cell.pb_flag = 0;
            if(~isempty(recalled_data.cell.parent_grid.rGrid))
                recalled_data.cell.parent_grid.rGrid.delete_g2s(recalled_data.cell);
            end
            if(~isempty(recalled_data.grid.rGrid))
                recalled_data.grid.rGrid.refresh;
            end
            object.reset_wh();
            object.draw_allgrids(1);
            
            recalled_data.grid.cells = [recalled_data.grid.cells recalled_data.subgrid];
            recalled_data.grid.num_cells = recalled_data.grid.num_cells + 1;
            if(~isempty(recalled_data.grid.rGrid))
                recalled_data.grid.rGrid.refresh;
            end
            object.reset_wh();
            object.draw_allgrids(1);
            set(recalled_data.grid.delete_cell_pb,'Enable','on');
    end
end


object.update_undoredo;
end

