Ejemplo n.º 1
0
 public UndoRedoManager(UndoRedoOptions options = null)
 {
     _options = options ?? new UndoRedoOptions();
     _options.Validate();
     _snapshots = new PushOutCollection <LineViewSnapshot>(_options.MaxCount);
     _iterator  = new CollectionIterator <LineViewSnapshot>(_snapshots);
 }
Ejemplo n.º 2
0
 private static void PopulateCollection(PushOutCollection <int> collection, int count)
 {
     for (int i = 0; i < count; i++)
     {
         collection.Add(i);
     }
 }
Ejemplo n.º 3
0
        public void HaveCapacityOfPassedCollection(int[] elements)
        {
            // Act
            var collection = new PushOutCollection <int>(elements);

            // Assert
            Assert.Equal(elements.Length, collection.MaxCount);
        }
Ejemplo n.º 4
0
        public void ClearElements()
        {
            // Arrange
            var collection = new PushOutCollection <int>(new int[] { 0, 1, 2 });

            // Act
            collection.Clear();

            // Assert
            Assert.Empty(collection);
        }
Ejemplo n.º 5
0
        public void TrimToCount(int capacity, int extraElements, int newCount, int[] expected)
        {
            // Arrange
            var collection = new PushOutCollection <int>(capacity);

            PopulateCollection(collection, capacity + extraElements);

            // Act
            collection.TrimTo(newCount);

            // Assert
            Assert.Equal(expected, collection);
        }
Ejemplo n.º 6
0
        public void SetWithZeroBasedIndexing(int capacity, int extraElements, int[] expected)
        {
            // Arrange
            var collection = new PushOutCollection <int>(capacity);

            PopulateCollection(collection, capacity + extraElements);

            // Act
            collection[0] = -1;

            // Assert
            Assert.Equal(expected, collection);
        }
Ejemplo n.º 7
0
        public void GetWithZeroBasedIndexing(int capacity, int extraElements, int index, int expected)
        {
            // Arrange
            var collection = new PushOutCollection <int>(capacity);

            PopulateCollection(collection, capacity + extraElements);

            // Act
            int actual = collection[index];

            // Assert
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 8
0
        public void PushOutFirstElement(int capacity, int extraElements, int[] expected)
        {
            // Arrange
            var collection = new PushOutCollection <int>(capacity);

            // Act
            for (int i = 0; i < capacity + extraElements; i++)
            {
                collection.Add(i);
            }

            // Assert
            Assert.Equal(expected, collection);
        }
Ejemplo n.º 9
0
        public void IncreaseCount(int capacity, int newElements)
        {
            // Arrange
            var collection = new PushOutCollection <int>(capacity);

            // Act
            for (int i = 0; i < newElements; i++)
            {
                collection.Add(i);
            }

            // Assert
            Assert.Equal(newElements, collection.Count);
        }
Ejemplo n.º 10
0
        public void NotExceedCapacity(int capacity, int newElements)
        {
            // Arrange
            var collection = new PushOutCollection <int>(capacity);

            // Act
            for (int i = 0; i < newElements; i++)
            {
                collection.Add(i);
            }

            // Assert
            Assert.Equal(capacity, collection.Count);
            Assert.Equal(capacity, collection.MaxCount);
        }
Ejemplo n.º 11
0
        public void Clear()
        {
            lock (_commandsWriteLock)
            {
                if (_commands == null)
                {
                    _commands = new PushOutCollection <string>(MaxCount);
                }
                else
                {
                    _commands.Clear();
                }
                _current = 0;
            }

            ScheduleSaveCommands();
        }
Ejemplo n.º 12
0
        private void EnsureCommandsLoaded()
        {
            if (_commands != null)
            {
                return;
            }

            lock (_commandsWriteLock)
            {
                if (_historyStorage == null)
                {
                    _commands = new PushOutCollection <string>(MaxCount);
                }
                else
                {
                    IReadOnlyList <string> loaded = null;
                    lock (_historyStorage)
                    {
                        loaded = _historyStorage.Load();
                    }
                    loaded = loaded.Where(_ => !String.IsNullOrWhiteSpace(_)).ToArray();

                    if (loaded.Count > MaxCount)
                    {
                        _commands = new PushOutCollection <string>(loaded.Skip(loaded.Count - MaxCount));
                    }
                    else
                    {
                        _commands = new PushOutCollection <string>(MaxCount);
                        for (int i = 0; i < loaded.Count; i++)
                        {
                            _commands.Add(loaded[i]);
                        }
                    }
                }

                _current = _commands.Count;
            }
        }