%% new_state
%    when new action occurs gets add to the top of the queue of actions.
% inputs:
%   object - current UndoManager object
%   data:struct - data structure to specify action taken.
% outputs:
%   none
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification

function [] = new_state( object, data )

% data object should be structure of following form.
% data.action
% data.grid
% data.cell
% data.text
% data.subgrid

% if user has already issued an undo command before performing another
% action then perform an action, we do not allow them to redo anymore.
if (object.undo_level > 0)
    object.current_depth = object.current_depth + 1;
    object.queue(object.current_depth) = data;
    if object.undo_level > 1
        object.queue(object.current_depth+1:object.current_depth+object.undo_level-1) = [];
    end
    object.undo_level = 0;
% if user is not undoing, then we make sure queue size less than max depth,
% otherwise we shift out the oldest action
else
    
    if (size(object.queue,2) < object.max_depth)
        object.queue = [object.queue data];
        object.current_depth = object.current_depth + 1;
    else
        object.shift_queue_left();
        object.queue(object.current_depth) = data;        
    end
end
    
end



