Пример #1
0
        public bool DeleteBookmark(HistoryEvent historyEvent)
        {
            HistoryNode historyNode = historyEvent.Node;

            if (!_nodes.Contains(historyNode))
            {
                throw new Exception("Attempted to delete a bookmark history event that doesn't belong to this history!");
            }

            if (historyNode == _rootNode)
            {
                throw new Exception("Can't delete root node!");
            }

            if (historyNode == _currentNode)
            {
                return(false);
            }

            foreach (HistoryNode child in historyNode.Children)
            {
                child.Parent = historyNode.Parent;
                historyNode.Parent.Children.Add(child);
            }

            historyNode.Children.Clear();
            historyNode.Parent.Children.Remove(historyNode);
            historyNode.Parent = null;

            Notify(historyEvent, HistoryChangedAction.DeleteBookmark);

            return(true);
        }
Пример #2
0
 protected HistoryNode(int id, UInt64 ticks, CoreAction action, Bookmark bookmark, HistoryNode parent, DateTime createDate)
 {
     Id         = id;
     Ticks      = ticks;
     Parent     = parent;
     CreateDate = createDate;
     Children   = new List <HistoryNode>();
 }
Пример #3
0
        public History()
        {
            _nodes  = new HashSet <HistoryNode>();
            _nextId = 0;

            _rootNode = new RootHistoryNode();

            _nodes.Add(_rootNode);

            _currentNode = _rootNode;
        }
Пример #4
0
        private void AddChildNode(HistoryNode historyNode, bool notify)
        {
            _currentNode.Children.Add(historyNode);
            _nodes.Add(historyNode);
            _currentNode = historyNode;

            if (notify)
            {
                Notify(historyNode.HistoryEvent, HistoryChangedAction.Add);
            }
        }
Пример #5
0
        public bool IsEqualToOrAncestorOf(HistoryNode ancestor)
        {
            while (ancestor != null)
            {
                if (ancestor == this)
                {
                    return(true);
                }

                ancestor = ancestor.Parent;
            }

            return(false);
        }
Пример #6
0
        public bool DeleteBranch(HistoryEvent historyEvent)
        {
            HistoryNode historyNode = historyEvent.Node;

            if (!_nodes.Contains(historyNode))
            {
                throw new Exception("Attempted to delete a branch that doesn't belong to this history!");
            }

            if (historyNode == _rootNode)
            {
                throw new Exception("Can't delete root node!");
            }

            if (historyNode.IsEqualToOrAncestorOf(_currentNode))
            {
                return(false);
            }

            HistoryNode parent = historyNode.Parent;

            parent.Children.Remove(historyNode);
            historyNode.Parent = null;

            // Remove this node, and all its children
            List <HistoryNode> nodesToRemove = new List <HistoryNode>();

            nodesToRemove.Add(historyNode);
            while (nodesToRemove.Count > 0)
            {
                HistoryNode childHistoryNode = nodesToRemove[0];

                _nodes.Remove(childHistoryNode);

                nodesToRemove.AddRange(childHistoryNode.Children);
                nodesToRemove.RemoveAt(0);
            }

            Notify(historyEvent, HistoryChangedAction.DeleteBranch);

            return(true);
        }
Пример #7
0
 internal RootHistoryEvent(HistoryNode historyNode)
 {
     _node = historyNode as RootHistoryNode;
 }
Пример #8
0
        internal CoreActionHistoryNode(int id, UInt64 ticks, CoreAction action, HistoryNode parent, DateTime createDate) : base(id, ticks, action, null, parent, createDate)
        {
            CoreAction = action;

            HistoryEvent = new CoreActionHistoryEvent(this);
        }
Пример #9
0
        internal BookmarkHistoryNode(int id, UInt64 ticks, Bookmark bookmark, HistoryNode parent, DateTime createDate) : base(id, ticks, null, bookmark, parent, createDate)
        {
            Bookmark = bookmark;

            HistoryEvent = new BookmarkHistoryEvent(this);
        }