Пример #1
0
        public bool RemoveLink(SOLink link)
        {
            bool bFound = Links.Remove(link);

            if (bFound)
            {
                if (link.Name != null && NamedLinks.ContainsKey(link.Name))
                {
                    NamedLinks.Remove(link.Name);
                }

                // We might be running this *in* a ChangeOp, in which case we
                // do not want to push another one. ugly problem =\
                if (Scene.History.InPastState)
                {
                    link.Unlink();
                }
                else
                {
                    IChangeOp change = link.GetRemoveChange();
                    if (change == null)
                    {
                        // we cannot undo this link removal
                        link.Unlink();
                    }
                    else
                    {
                        Scene.History.PushChange(change, false);
                    }
                }
            }
            return(bFound);
        }
Пример #2
0
        public OpStatus PushChange(IChangeOp op, bool bIsApplied = false)
        {
            DebugUtil.Log(2, "ChangeHistory.PushChange: pushed {0}", op.Identifier());

            if (vHistory.Count > 0 && iCurrent < vHistory.Count)
            {
                TrimFuture();
            }

            if (bIsApplied == false)
            {
                OpStatus result = op.Apply();
                if (result.code != OpStatus.no_error)
                {
                    DebugUtil.Error("[ChangeHistory::PushChange] Apply() of ChangeOp {0} failed - code {1} message {2}",
                                    op.Identifier(), result.code, result.message);
                    return(result);
                }
            }

            vHistory.Add(op);
            iCurrent++;

            return(OpStatus.Success);
        }
Пример #3
0
        /// <summary>
        /// play history forward until current node has the given tag
        /// </summary>
        public OpStatus StepForwardToAfterNextTag(string tag)
        {
            bool bContinue = true;
            bool bFound    = false;

            while (bContinue)
            {
                OpStatus result = StepForward();
                if (result.code != OpStatus.no_error)
                {
                    return(result);
                }
                if (iCurrent == vHistory.Count)
                {
                    bContinue = false;
                }
                else
                {
                    IChangeOp op = vHistory[iCurrent];
                    if (op.HasTags && op.Tags.Contains(tag))
                    {
                        bContinue = false;
                        bFound    = true;
                    }
                }
            }
            // step to *after* this node, otherwise if we push a new node we will replace this one!
            // [TODO] this is maybe a bit weird...?
            if (bFound)
            {
                StepForward();
            }
            return(OpStatus.Success);
        }
Пример #4
0
        /// <summary>
        /// Rewind history until current node has the given tag
        /// </summary>
        public OpStatus StepBackwardToAfterPreviousTag(string tag)
        {
            bool bContinue = true;

            while (bContinue)
            {
                OpStatus result = StepBack();
                if (result.code != OpStatus.no_error)
                {
                    return(result);
                }
                if (iCurrent == 0)
                {
                    bContinue = false;
                }
                else
                {
                    IChangeOp op = vHistory[iCurrent - 1];
                    if (op.HasTags && op.Tags.Contains(tag))
                    {
                        bContinue = false;
                    }
                }
            }
            return(OpStatus.Success);
        }
Пример #5
0
        public static void SafeSendEvent(OnChangeOpHandler handler, object source, IChangeOp change)
        {
            var tmp = handler;

            if (tmp != null)
            {
                tmp(source, change);
            }
        }
Пример #6
0
        public OpStatus StepBack()
        {
            if (iCurrent == 0)
            {
                return(OpStatus.Success);        // weird but ok
            }
            IChangeOp op = vHistory[iCurrent - 1];

            DebugUtil.Log(2, "ChangeHistory.StepBack: reverting {0}", op.Identifier());
            OpStatus result = op.Revert();

            if (result.code != OpStatus.no_error)
            {
                DebugUtil.Error("[ChangeHistory::StepBack] Revert() of ChangeOp {0} failed - result was code {1} message {2}",
                                op.Identifier(), result.code, result.message);
                return(result);
            }

            iCurrent--;
            return(OpStatus.Success);
        }
Пример #7
0
        public OpStatus StepForward()
        {
            if (iCurrent == vHistory.Count)
            {
                return(OpStatus.Success);
            }

            IChangeOp op = vHistory[iCurrent];

            DebugUtil.Log(2, "ChangeHistory.StepForward: applying {0}", op.Identifier());
            OpStatus result = op.Apply();

            if (result.code != OpStatus.no_error)
            {
                DebugUtil.Error("[ChangeHistory::StepForward] Apply() of ChangeOp {0} failed - result was code {1} message {2}",
                                op.Identifier(), result.code, result.message);
                return(result);
            }

            iCurrent++;
            return(OpStatus.Success);
        }