private T _getCommand <T>(IActCommand command) where T : class, IActCommand
        {
            var cmd = command as ActGroupCommand;

            if (cmd != null)
            {
                return(cmd.Commands.FirstOrDefault(p => p.GetType() == typeof(T)) as T);
            }

            if (command is T)
            {
                return(command as T);
            }

            return(null);
        }
        private void _commands_CommandUndo(object sender, IActCommand command)
        {
            this.Dispatch(delegate {
                try {
                    var actionCmd = _getCommand <ActionCommand>(command);

                    if (actionCmd != null)
                    {
                        if (actionCmd.Executed &&
                            (actionCmd.Edit == ActionCommand.ActionEdit.CopyAt ||
                             actionCmd.Edit == ActionCommand.ActionEdit.InsertAt ||
                             actionCmd.Edit == ActionCommand.ActionEdit.ReplaceTo ||
                             actionCmd.Edit == ActionCommand.ActionEdit.InsertAt))
                        {
                            SelectedAction = actionCmd.ActionIndexTo;
                        }

                        if (SelectedAction < 0)
                        {
                            SelectedAction = 0;
                        }

                        if (SelectedAction >= _act.NumberOfActions)
                        {
                            SelectedAction = _act.NumberOfActions - 1;
                        }

                        _updateActionSelection();
                    }

                    var frameCmd = _getCommand <FrameCommand>(command);

                    if (frameCmd != null)
                    {
                        if (frameCmd.Executed)
                        {
                            if ((frameCmd.ActionIndexTo == SelectedAction && frameCmd.Edit == FrameCommand.FrameEdit.ReplaceTo) ||
                                (frameCmd.ActionIndexTo == SelectedAction && frameCmd.Edit == FrameCommand.FrameEdit.Switch) ||
                                (frameCmd.ActionIndexTo == SelectedAction && frameCmd.Edit == FrameCommand.FrameEdit.CopyTo)
                                )
                            {
                                SelectedFrame = frameCmd.FrameIndexTo;
                            }
                            else if (frameCmd.ActionIndex == SelectedAction && frameCmd.Edit == FrameCommand.FrameEdit.InsertTo)
                            {
                                SelectedFrame = frameCmd.FrameIndex;
                            }

                            if (SelectedFrame != (int)_sbFrameIndex.Value)
                            {
                                _sbFrameIndex.Value = SelectedFrame;
                            }
                        }
                    }

                    //_updateInfo();
                }
                catch (Exception err) {
                    ErrorHandler.HandleException(err);
                }
            });
        }