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); }
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>(); }
public History() { _nodes = new HashSet <HistoryNode>(); _nextId = 0; _rootNode = new RootHistoryNode(); _nodes.Add(_rootNode); _currentNode = _rootNode; }
private void AddChildNode(HistoryNode historyNode, bool notify) { _currentNode.Children.Add(historyNode); _nodes.Add(historyNode); _currentNode = historyNode; if (notify) { Notify(historyNode.HistoryEvent, HistoryChangedAction.Add); } }
public bool IsEqualToOrAncestorOf(HistoryNode ancestor) { while (ancestor != null) { if (ancestor == this) { return(true); } ancestor = ancestor.Parent; } return(false); }
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); }
internal RootHistoryEvent(HistoryNode historyNode) { _node = historyNode as RootHistoryNode; }
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); }
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); }