using System;
using System.Windows;
using System.Windows.Controls;
using C1.Silverlight.FlexGrid;

namespace C1.Silverlight.FlexGridExcel
{
    /// <summary>
    /// Undoable column layout action (resize, move, hide/show).
    /// </summary>
    public class ColumnAction : IUndoableAction
    {
        //-------------------------------------------------------------------------
        #region ** fields

        C1FlexGrid _flex;
        string _oldLayout, _newLayout;

        #endregion

        //-------------------------------------------------------------------------
        #region ** ctor

        /// <summary>
        /// Initializes a new instance of a <see cref="ColumnAction"/>.
        /// </summary>
        /// <param name="sender"><see cref="C1FlexGrid"/> that owns the action.</param>
        /// <param name="oldLayout"><see cref="string"/> that represents the column layout before the action.</param>
        public ColumnAction(object sender, string oldLayout)
        {
            _flex = sender as C1FlexGrid;
            _oldLayout = oldLayout;
            _newLayout = _flex.ColumnLayout;
        }

        #endregion

        //-------------------------------------------------------------------------
        #region ** IUndoableAction

        /// <summary>
        /// Reverts the effect of the last action.
        /// </summary>
        public void Undo()
        {
            _flex.ColumnLayout = _oldLayout;
        }
        /// <summary>
        /// Restores the effect of the last undone action.
        /// </summary>
        public void Redo()
        {
            _flex.ColumnLayout = _newLayout;
        }

        #endregion
    }
}
