public void ModelUndo() { var compound = new NbtCompound(); //compound.Add(new NbtByte("test")); //Assert.AreEqual(compound.Count, 1); //model.UndoHistory.Undo(); //Assert.AreEqual(compound.Count, 0); var sub = new NbtCompound("test"); var b1 = new NbtByte("b1"); var b2 = new NbtByte("b2"); compound.Add(sub); sub.Add(b1); sub.Add(b2); var model = new NbtTreeModel(); var node = new NbtTagNode(model, null, compound); model.Import(node); model.UndoHistory.StartBatchOperation(); node.ReceiveDrop(new[] { node.Children.First() }, 0); model.UndoHistory.FinishBatchOperation(new DescriptionHolder(""), true); model.UndoHistory.StartBatchOperation(); node.Children.First().ReceiveDrop(new[] { node.Children.First().Children.First() }, 0); model.UndoHistory.FinishBatchOperation(new DescriptionHolder(""), true); model.UndoHistory.Undo(); }
public void CheckSynchronized() { var root = new NbtCompound("test"); var view = new NbtTreeView(); var model = new NbtTreeModel((object)root); view.Model = model; Assert.AreEqual(model.Root.Children.Count(), 1); Assert.AreEqual(view.Root.Children.Count, 1); AssertSynchronized(view, model); root.Add(new NbtByte("test1")); AssertSynchronized(view, model); root.Add(new NbtByte("test2")); AssertSynchronized(view, model); root.Add(new NbtCompound("test3")); AssertSynchronized(view, model); root.Get <NbtCompound>("test3").Add(new NbtShort("test4")); Assert.AreEqual(view.Root.DescendantsCount, 5); Assert.AreEqual(model.Root.DescendantsCount, 5); AssertSynchronized(view, model); root.Remove("test2"); AssertSynchronized(view, model); root.Get <NbtCompound>("test3").Clear(); Assert.AreEqual(view.Root.DescendantsCount, 3); Assert.AreEqual(model.Root.DescendantsCount, 3); AssertSynchronized(view, model); root.Clear(); AssertSynchronized(view, model); }
private void AssertSynchronized(NbtTreeView view, NbtTreeModel model) { var view_queue = new Queue <TreeNodeAdv>(); var model_queue = new Queue <INode>(); foreach (var root in view.Root.Children) { view_queue.Enqueue(root); } foreach (var root in model.Root.Children) { model_queue.Enqueue(root); } while (view_queue.Any() || model_queue.Any()) { Assert.AreEqual(view_queue.Count, model_queue.Count); var view_item = view_queue.Dequeue(); var model_item = model_queue.Dequeue(); Assert.AreEqual(view_item.DescendantsCount, model_item.DescendantsCount); foreach (var child in view_item.Children) { view_queue.Enqueue(child); } foreach (var child in model_item.Children) { model_queue.Enqueue(child); } Assert.AreEqual(view_item.Tag, model_item); } }
public FindWindow(IconSource source, NbtTreeModel model, NbtTreeView view) { InitializeComponent(); SearchingModel = model; SearchingView = view; this.Icon = source.GetImage(IconType.Search).Icon; UpdateButtons(); }