예제 #1
0
        private void HandleRedoOperation()
        {
            BindingsHelper.RemoveAllBindingsOnLoadedEntities();
            int version = int.MaxValue;

            try
            {
                do
                {
                    if (m_RedoableChanges.Count > 0)
                    {
                        //Debug.Log("Redo operation");
                        var changes = m_RedoableChanges.Last();
                        foreach (var change in changes)
                        {
                            var originator = m_Registry.FindById <IRegistryObject>(change.Id) as IOriginator;
                            version = change.Version;
                            if (null == originator)
                            {
                                originator = change.RegistryObject as IOriginator;
                            }

                            // We have no next version, which means that the originator must have been created.
                            // Knowing this, we shall remove it from the registry.
                            if (null == change.NextVersion)
                            {
                                m_Registry.Unregister(originator as IRegistryObject);
                            }
                            // Otherwise, restore the next version.
                            else
                            {
                                originator.Restore(change.NextVersion);
                            }
                        }
                        m_RedoableChanges.RemoveAt(m_RedoableChanges.Count - 1);
                        m_UndoableChanges.Add(changes);
                    }
                    else
                    {
                        break;
                    }
                }while (version < m_Undo.Version);
            }
            finally
            {
                RefreshAll();
                OnRedoPerformed?.Invoke();
                m_Caretaker.OnObjectChanged -= HandleUndoableChange;
                m_Caretaker.Update();
                m_Registry.ClearUnregisteredObjects();
                m_Caretaker.OnObjectChanged += HandleUndoableChange;
                BindingsHelper.RunAllBindingsOnLoadedEntities();
            }
        }