Beispiel #1
0
        private void ChangeProperty(object prop, Entity selection, object obj, object newval,
                                    ref bool committed, bool shouldUpdateVisual, bool destroyRenderModel, int arrayindex = -1)
        {
            if (prop == _changingPropery && _lastUncommittedAction != null && ContextActionManager.PeekUndoAction() == _lastUncommittedAction)
            {
                ContextActionManager.UndoAction();
            }
            else
            {
                _lastUncommittedAction = null;
            }

            if (_changingObject != null && selection != null && selection.WrappedObject != _changingObject)
            {
                committed = true;
            }
            else
            {
                PropertiesChangedAction action;
                if (arrayindex != -1)
                {
                    action = new PropertiesChangedAction((PropertyInfo)prop, arrayindex, obj, newval);
                }
                else
                {
                    action = new PropertiesChangedAction((PropertyInfo)prop, obj, newval);
                }
                if (shouldUpdateVisual && selection != null)
                {
                    action.SetPostExecutionAction((undo) =>
                    {
                        if (destroyRenderModel)
                        {
                            if (selection.RenderSceneMesh != null)
                            {
                                selection.RenderSceneMesh.Dispose();
                                selection.RenderSceneMesh = null;
                            }
                        }
                        selection.UpdateRenderModel();
                    });
                }
                ContextActionManager.ExecuteAction(action);

                _lastUncommittedAction = action;
                _changingPropery       = prop;
                // ChangingObject = selection.MsbObject;
                _changingObject = selection != null ? selection.WrappedObject : obj;
            }
        }
Beispiel #2
0
        private void ChangeProperty(object prop, Entity selection, object obj, object newval,
                                    bool changed, bool committed, bool shouldUpdateVisual, int arrayindex = -1)
        {
            if (changed)
            {
                if (prop == ChangingPropery && LastUncommittedAction != null)
                {
                    if (ContextActionManager.PeekUndoAction() == LastUncommittedAction)
                    {
                        ContextActionManager.UndoAction();
                    }
                    else
                    {
                        LastUncommittedAction = null;
                    }
                }
                else
                {
                    LastUncommittedAction = null;
                }

                if (ChangingObject != null && selection != null && selection.WrappedObject != ChangingObject)
                {
                    committed = true;
                }
                else
                {
                    PropertiesChangedAction action;
                    if (arrayindex != -1)
                    {
                        action = new PropertiesChangedAction((PropertyInfo)prop, arrayindex, obj, newval);
                    }
                    else
                    {
                        action = new PropertiesChangedAction((PropertyInfo)prop, obj, newval);
                    }
                    if (shouldUpdateVisual && selection != null)
                    {
                        action.SetPostExecutionAction((undo) =>
                        {
                            selection.UpdateRenderModel();
                        });
                    }
                    ContextActionManager.ExecuteAction(action);

                    LastUncommittedAction = action;
                    ChangingPropery       = prop;
                    //ChangingObject = selection.MsbObject;
                    ChangingObject = selection != null ? selection.WrappedObject : obj;
                }
            }
            if (committed)
            {
                // Invalidate name cache
                if (selection != null)
                {
                    selection.Name = null;
                }

                // Undo and redo the last action with a rendering update
                if (LastUncommittedAction != null && ContextActionManager.PeekUndoAction() == LastUncommittedAction)
                {
                    if (LastUncommittedAction is PropertiesChangedAction a)
                    {
                        // Kinda a hack to prevent a jumping glitch
                        a.SetPostExecutionAction(null);
                        ContextActionManager.UndoAction();
                        if (selection != null)
                        {
                            a.SetPostExecutionAction((undo) =>
                            {
                                selection.UpdateRenderModel();
                            });
                        }
                        ContextActionManager.ExecuteAction(a);
                    }
                }

                LastUncommittedAction = null;
                ChangingPropery       = null;
                ChangingObject        = null;
            }
        }