コード例 #1
0
ファイル: UndoManager.cs プロジェクト: gitter-badger/Gum
        /// <summary>
        /// Records an undo if any values have changed. This should be called whenever some editing activity has finished.
        /// For example, whenever a value changes in a text box or whenever a drag has finished.
        /// </summary>
        public void RecordUndo()
        {
            if (mRecordedElementSave != null && SelectedState.Self.SelectedElement != null)
            {
                StateSave   currentStateSave = SelectedState.Self.SelectedStateSave;
                ElementSave selectedElement  = SelectedState.Self.SelectedElement;


                bool doStatesDiffer          = FileManager.AreSaveObjectsEqual(mRecordedElementSave.DefaultState, currentStateSave) == false;
                bool doStateCategoriesDiffer =
                    FileManager.AreSaveObjectsEqual(mRecordedElementSave.Categories, selectedElement.Categories) == false;
                bool doInstanceListsDiffer = FileManager.AreSaveObjectsEqual(mRecordedElementSave.Instances, selectedElement.Instances) == false;
                bool doTypesDiffer         = mRecordedElementSave.BaseType != selectedElement.BaseType;
                bool doNamesDiffer         = mRecordedElementSave.Name != selectedElement.Name;

                bool didAnythingChange = doStatesDiffer || doStateCategoriesDiffer || doInstanceListsDiffer || doTypesDiffer || doNamesDiffer;
                if (didAnythingChange)
                {
                    if (mUndos.ContainsKey(SelectedState.Self.SelectedElement) == false)
                    {
                        mUndos.Add(SelectedState.Self.SelectedElement, new Stack <ElementSave>());
                    }

                    if (!doInstanceListsDiffer)
                    {
                        mRecordedElementSave.Instances = null;
                    }
                    if (!doStatesDiffer)
                    {
                        mRecordedElementSave.States = null;
                    }
                    if (!doStateCategoriesDiffer)
                    {
                        mRecordedElementSave.Categories = null;
                    }
                    if (!doNamesDiffer)
                    {
                        mRecordedElementSave.Name = null;
                    }
                    if (!doTypesDiffer)
                    {
                        mRecordedElementSave.BaseType = null;
                    }

                    Stack <ElementSave> stack = mUndos[SelectedState.Self.SelectedElement];

                    stack.Push(mRecordedElementSave);
                    RecordState();

                    UndosChanged?.Invoke(this, null);
                }


                //PrintStatus("RecordUndo");
            }
        }
コード例 #2
0
        public void PerformUndo()
        {
            Stack <UndoSnapshot> stack = null;

            if (SelectedState.Self.SelectedElement != null && mUndos.ContainsKey(SelectedState.Self.SelectedElement))
            {
                stack = mUndos[SelectedState.Self.SelectedElement];
            }

            if (stack != null && stack.Count != 0)
            {
                ElementSave lastSelectedElementSave = SelectedState.Self.SelectedElement;

                var undoSnapshot  = stack.Pop();
                var elementToUndo = undoSnapshot.Element;

                ElementSave toApplyTo = SelectedState.Self.SelectedElement;

                bool shouldRefreshWireframe = false;

                if (elementToUndo.States != null)
                {
                    foreach (var state in elementToUndo.States)
                    {
                        var matchingState = toApplyTo.States.Find(item => item.Name == state.Name);
                        if (matchingState != null)
                        {
                            Apply(state, matchingState, toApplyTo);
                        }
                    }
                }

                if (elementToUndo.Categories != null)
                {
                    foreach (var category in elementToUndo.Categories)
                    {
                        foreach (var state in category.States)
                        {
                            var matchingCategory = toApplyTo.Categories.Find(item => item.Name == category.Name);
                            var matchingState    = matchingCategory?.States.Find(item => item.Name == state.Name);
                            if (matchingState != null)
                            {
                                Apply(state, matchingState, toApplyTo);
                            }
                        }
                    }
                }
                if (elementToUndo.Instances != null)
                {
                    Apply(elementToUndo.Instances, toApplyTo.Instances, toApplyTo);
                    shouldRefreshWireframe = true;
                }
                if (elementToUndo.Name != null)
                {
                    string oldName = toApplyTo.Name;
                    toApplyTo.Name = elementToUndo.Name;
                    RenameLogic.HandleRename(toApplyTo, (InstanceSave)null, oldName, NameChangeAction.Rename, askAboutRename: false);
                }

                if (undoSnapshot.CategoryName != SelectedState.Self.SelectedStateCategorySave?.Name ||
                    undoSnapshot.StateName != SelectedState.Self.SelectedStateSave?.Name)
                {
                    var listOfStates = lastSelectedElementSave.States;
                    if (!string.IsNullOrEmpty(undoSnapshot.CategoryName))
                    {
                        listOfStates = lastSelectedElementSave.Categories
                                       .FirstOrDefault(item => item.Name == undoSnapshot.CategoryName)?.States;
                    }

                    var state = listOfStates?.FirstOrDefault(item => item.Name == undoSnapshot.StateName);

                    isRecordingUndos = false;
                    SelectedState.Self.SelectedStateSave = state;

                    isRecordingUndos = true;
                }

                //if (undoObject.BaseType != null)
                //{
                //    string oldBaseType = toApplyTo.BaseType;
                //    toApplyTo.BaseType = undoObject.BaseType;

                //    toApplyTo.ReactToChangedBaseType(null, oldBaseType);
                //}

                RecordState();


                UndosChanged?.Invoke(this, null);

                GumCommands.Self.GuiCommands.RefreshElementTreeView();
                SelectedState.Self.UpdateToSelectedStateSave();

                // The instances may have changed.  We will want
                // to refresh the wireframe since the IPSOs in the
                // wireframe have tags.
                if (shouldRefreshWireframe)
                {
                    WireframeObjectManager.Self.RefreshAll(true);
                }

                //PrintStatus("PerformUndo");

                // If an instance is removed
                // through an undo and if that
                // instance is the selected instance
                // then we want to refresh that.
                if (lastSelectedElementSave != null && SelectedState.Self.SelectedElement == null)
                {
                    SelectedState.Self.SelectedElement = lastSelectedElementSave;
                }

                GumCommands.Self.FileCommands.TryAutoSaveProject();
                GumCommands.Self.FileCommands.TryAutoSaveCurrentElement();

                ElementTreeViewManager.Self.VerifyComponentsAreInTreeView(ProjectManager.Self.GumProjectSave);
            }
        }
コード例 #3
0
        /// <summary>
        /// Records an undo if any values have changed. This should be called whenever some editing activity has finished.
        /// For example, whenever a value changes in a text box or whenever a drag has finished.
        /// </summary>
        public void RecordUndo()
        {
            if (recordedSnapshot != null && SelectedState.Self.SelectedElement != null && isRecordingUndos &&
                SelectedState.Self.SelectedStateSave != null)
            {
                StateSave   currentStateSave = SelectedState.Self.SelectedStateSave;
                var         currentCategory  = SelectedState.Self.SelectedStateCategorySave;
                ElementSave selectedElement  = SelectedState.Self.SelectedElement;

                StateSave stateToCompareAgainst = null;

                if (currentCategory != null)
                {
                    var category = recordedSnapshot.Element.Categories.Find(item => item.Name == currentCategory.Name);
                    stateToCompareAgainst = category?.States.Find(item => item.Name == currentStateSave.Name);
                }
                else
                {
                    var stateName = currentStateSave.Name;
                    stateToCompareAgainst = recordedSnapshot.Element.States.Find(item => item.Name == stateName);
                }



                bool doStatesDiffer          = FileManager.AreSaveObjectsEqual(stateToCompareAgainst, currentStateSave) == false;
                bool doStateCategoriesDiffer =
                    FileManager.AreSaveObjectsEqual(recordedSnapshot.Element.Categories, selectedElement.Categories) == false;
                bool doInstanceListsDiffer = FileManager.AreSaveObjectsEqual(recordedSnapshot.Element.Instances, selectedElement.Instances) == false;
                bool doTypesDiffer         = recordedSnapshot.Element.BaseType != selectedElement.BaseType;
                bool doNamesDiffer         = recordedSnapshot.Element.Name != selectedElement.Name;

                bool doesSelectedStateDiffer = recordedSnapshot.CategoryName != currentCategory?.Name ||
                                               recordedSnapshot.StateName != currentStateSave?.Name;

                // todo : need to add behavior differences


                bool didAnythingChange = doStatesDiffer || doStateCategoriesDiffer || doInstanceListsDiffer || doTypesDiffer || doNamesDiffer || doesSelectedStateDiffer;
                if (didAnythingChange)
                {
                    if (mUndos.ContainsKey(SelectedState.Self.SelectedElement) == false)
                    {
                        mUndos.Add(SelectedState.Self.SelectedElement, new Stack <UndoSnapshot>());
                    }

                    if (!doInstanceListsDiffer)
                    {
                        recordedSnapshot.Element.Instances = null;
                    }
                    if (!doStatesDiffer)
                    {
                        recordedSnapshot.Element.States = null;
                    }
                    if (!doStateCategoriesDiffer)
                    {
                        recordedSnapshot.Element.Categories = null;
                    }
                    if (!doNamesDiffer)
                    {
                        recordedSnapshot.Element.Name = null;
                    }
                    if (!doTypesDiffer)
                    {
                        recordedSnapshot.Element.BaseType = null;
                    }

                    Stack <UndoSnapshot> stack = mUndos[SelectedState.Self.SelectedElement];

                    stack.Push(recordedSnapshot);
                    RecordState();

                    UndosChanged?.Invoke(this, null);
                }


                //PrintStatus("RecordUndo");
            }
        }
コード例 #4
0
ファイル: UndoManager.cs プロジェクト: gitter-badger/Gum
        public void PerformUndo()
        {
            Stack <ElementSave> stack = null;

            if (SelectedState.Self.SelectedElement != null && mUndos.ContainsKey(SelectedState.Self.SelectedElement))
            {
                stack = mUndos[SelectedState.Self.SelectedElement];
            }

            if (stack != null && stack.Count != 0)
            {
                ElementSave lastSelectedElementSave = SelectedState.Self.SelectedElement;

                ElementSave undoObject = stack.Pop();

                ElementSave toApplyTo = SelectedState.Self.SelectedElement;

                bool shouldRefreshWireframe = false;

                if (undoObject.DefaultState != null)
                {
                    Apply(undoObject.DefaultState, toApplyTo.DefaultState, toApplyTo);
                }
                if (undoObject.Instances != null)
                {
                    Apply(undoObject.Instances, toApplyTo.Instances, toApplyTo);
                    shouldRefreshWireframe = true;
                }
                if (undoObject.Name != null)
                {
                    string oldName = toApplyTo.Name;
                    toApplyTo.Name = undoObject.Name;
                    RenameManager.Self.HandleRename(toApplyTo, (InstanceSave)null, oldName, NameChangeAction.Rename, askAboutRename: false);
                }
                //if (undoObject.BaseType != null)
                //{
                //    string oldBaseType = toApplyTo.BaseType;
                //    toApplyTo.BaseType = undoObject.BaseType;

                //    toApplyTo.ReactToChangedBaseType(null, oldBaseType);
                //}

                RecordState();


                UndosChanged?.Invoke(this, null);

                GumCommands.Self.GuiCommands.RefreshElementTreeView();
                SelectedState.Self.UpdateToSelectedStateSave();

                // The instances may have changed.  We will want
                // to refresh the wireframe since the IPSOs in the
                // wireframe have tags.
                if (shouldRefreshWireframe)
                {
                    WireframeObjectManager.Self.RefreshAll(true);
                }

                //PrintStatus("PerformUndo");

                // If an instance is removed
                // through an undo and if that
                // instance is the selected instance
                // then we want to refresh that.
                if (lastSelectedElementSave != null && SelectedState.Self.SelectedElement == null)
                {
                    SelectedState.Self.SelectedElement = lastSelectedElementSave;
                }

                GumCommands.Self.FileCommands.TryAutoSaveProject();
                GumCommands.Self.FileCommands.TryAutoSaveCurrentElement();

                ElementTreeViewManager.Self.VerifyComponentsAreInTreeView(ProjectManager.Self.GumProjectSave);
            }
        }