public void IsActiveIsFalse() { var item = new ActivityHistoryItem(); var viewItem = new HistoryViewItem(item, null); Assert.That(viewItem.IsActive, Is.False); }
public void AddSelectedItem(HistoryViewItem addedItem) { if (!_selectedItems.Contains(addedItem)) { _selectedItems.Add(addedItem); } }
public void DateSameAsItemCompletedDate() { DateTime date = DateTime.Now; var item = new ActivityHistoryItem() { CompletedDate = date }; var viewItem = new HistoryViewItem(item, null); Assert.That(viewItem.Date, Is.EqualTo(date)); }
public void NameSameAsItemName() { string name = "Test Activity"; var item = new ActivityHistoryItem() { Name = name }; var viewItem = new HistoryViewItem(item, null); Assert.That(viewItem.Name, Is.EqualTo(name)); }
public void AddSelectedItemTwice() { // Setup HistoryViewItem branchViewItem = _leaf1ViewItem; // Act _viewModel.AddSelectedItem(_leaf1ViewItem); _viewModel.AddSelectedItem(_leaf1ViewItem); // Verify Assert.AreEqual(1, _viewModel.SelectedItems.Count(i => i == _leaf1ViewItem)); }
public void Setup() { MockTextFile mockTextFile = new MockTextFile(); _mockFileSystem = new Mock <IFileSystem>(MockBehavior.Strict); _mockFileSystem.Setup(fileSystem => fileSystem.OpenTextFile(AnyString())).Returns(mockTextFile); _mockFileSystem.Setup(fileSystem => fileSystem.DeleteFile(AnyString())); _mockFileSystem.Setup(fileSystem => fileSystem.ReplaceFile(AnyString(), AnyString())); _mockFileSystem.Setup(ReadBytes()).Returns(new byte[1]); _history = new History(); _bookmark1Event = _history.AddBookmark(100, new Bookmark(false, 0, null, null)); _history.AddCoreAction(CoreAction.RunUntil(100, 400, null)); _leaf1Event = _history.AddCoreAction(CoreAction.KeyPress(400, 42, true)); _history.CurrentEvent = _bookmark1Event; _bookmark2Event = _history.AddBookmark(200, new Bookmark(false, 0, null, null)); _history.AddCoreAction(CoreAction.RunUntil(200, 300, null)); _leaf2Event = _history.AddCoreAction(CoreAction.KeyPress(300, 42, true)); _history.CurrentEvent = _bookmark2Event; _history.AddCoreAction(CoreAction.KeyPress(300, 42, true)); _history.AddCoreAction(CoreAction.KeyPress(400, 42, false)); _bookmark3Event = _history.AddBookmark(500, new Bookmark(false, 0, null, null)); _history.CurrentEvent = _history.RootEvent; _leaf3Event = _history.AddCoreAction(CoreAction.KeyPress(50, 42, true)); _history.CurrentEvent = _bookmark3Event; // Diagram of this history... // // 500: o // 400: | | // 300: | | | // 200: o-/ | // 100: o---/ // 50 | | // 0: o-----/ _viewModel = new BookmarksViewModel(_history); Assert.AreEqual(7, _viewModel.Items.Count); _bookmark3ViewItem = _viewModel.Items[0]; _leaf1ViewItem = _viewModel.Items[1]; _leaf2ViewItem = _viewModel.Items[2]; _bookmark2ViewItem = _viewModel.Items[3]; _bookmark1ViewItem = _viewModel.Items[4]; _leaf3ViewItem = _viewModel.Items[5]; _rootViewItem = _viewModel.Items[6]; }
private void HistoryListView_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { if (e.AddedItems != null) { foreach (HistoryViewItem addedItem in e.AddedItems) { _viewModel.AddSelectedItem(addedItem); } } if (e.RemovedItems != null) { foreach (HistoryViewItem removedItem in e.RemovedItems) { _viewModel.RemoveSelectedItem(removedItem); } } if (_historyListView.SelectedItems.Count == 1) { // Set bitmap to currently focussed list item, if it happens to be a bookmark: HistoryViewItem selectedItem = _historyListView.SelectedItems[0] as HistoryViewItem; { WriteableBitmap bitmap = null; HistoryEvent historyEvent = selectedItem.HistoryEvent; // Even though the current event doesn't necessarily have a bookmark, we can still populate the display. if (historyEvent == _machine.History.CurrentEvent) { bitmap = _machine.Display.Bitmap; } else if (historyEvent is BookmarkHistoryEvent bookmarkHistoryEvent) { _display.GetFromBookmark(bookmarkHistoryEvent.Bookmark); bitmap = _display.Bitmap; } _fullScreenImage.Source = bitmap; } _fullScreenImage.Visibility = Visibility.Visible; } else { _fullScreenImage.Visibility = Visibility.Hidden; } }
public void RemoveSelectedItem(HistoryViewItem removedItem) { _selectedItems.Remove(removedItem); }
/// <summary> /// Generates a list of HistoryViewItem objects that are used to populate the history view. /// </summary> public void RefreshHistoryViewItems() { // Avoid calling this function recursively since the depth of the history could be large... List <Tuple <int, HistoryEvent> > eventStack = new List <Tuple <int, HistoryEvent> > { new Tuple <int, HistoryEvent>(0, _history.RootEvent) }; // Note that items is sorted in ascending order of ticks (i.e. oldest to most recent). List <HistoryViewItem> items = new List <HistoryViewItem>(); while (eventStack.Count > 0) { int left = eventStack[0].Item1; HistoryEvent historyEvent = eventStack[0].Item2; eventStack.RemoveAt(0); if (ShouldShow(historyEvent)) { HistoryViewItem item = new HistoryViewItem(historyEvent); // Figure out where this new item should be placed. int itemIndex = items.FindIndex(x => x.HistoryEvent.Ticks > historyEvent.Ticks); if (itemIndex == -1) { // Not found? Add the item to the end. itemIndex = items.Count; } // Add passthrough events to all items inbetween the item and its parent. HistoryEvent parent = MostRecentShownAncestor(historyEvent); if (parent != null) { // As the parent should have been added by now, we don't need to check for FindIndex returning -1. int parentIndex = items.FindIndex(x => x.HistoryEvent == parent); for (int i = parentIndex + 1; i < itemIndex; i++) { left = items[i].AddEvent(left, historyEvent); } } // Copy the Events from the next item so passthroughs are correctly rendered. if (itemIndex < items.Count) { item.Events = new List <HistoryEvent>(items[itemIndex].Events); } // Now add the actual event itself. left = item.AddEvent(left, historyEvent); items.Insert(itemIndex, item); } List <HistoryEvent> sortedChildren = new List <HistoryEvent>(historyEvent.Children); sortedChildren.Sort((x, y) => y.GetMaxDescendentTicks().CompareTo(x.GetMaxDescendentTicks())); for (int c = 0; c < sortedChildren.Count; c++) { // Place the children at the top of the stack; effectively means we're doing a depth-first walk of the tree. eventStack.Insert(c, new Tuple <int, HistoryEvent>(left, sortedChildren[c])); } } // Draw items to their respective canvasses. HistoryViewItem next = null; for (int i = items.Count - 1; i >= 0; i--) { HistoryViewItem item = items[i]; item.Draw(next, _history.CurrentEvent); next = item; } // Show the items in descending order of Ticks (i.e. most to least recent). items.Reverse(); Items.Clear(); foreach (HistoryViewItem item in items) { Items.Add(item); } }