示例#1
0
        public void ActionScope()
        {
            var target = new UndoRedoList <int, List <int> > {
                100, 200
            };

            using (var scope = new UndoRedoList <int, List <int> > .ActionScope(target)) {
                target.Add(300);
                target.RemoveAt(0);
                target.RemoveAt(1);
                target.Add(400);
                target.Add(500);
            }
            Assert.AreEqual(3, target.Count);
            Assert.AreEqual(200, target[0]);
            Assert.AreEqual(400, target[1]);
            Assert.AreEqual(500, target[2]);
            Assert.IsTrue(target.CanUndo);
            Assert.IsFalse(target.CanRedo);

            Assert.IsTrue(target.Undo());
            Assert.IsTrue(target.CanUndo);
            Assert.IsTrue(target.CanRedo);
            Assert.AreEqual(2, target.Count);
            Assert.AreEqual(100, target[0]);
            Assert.AreEqual(200, target[1]);

            Assert.IsTrue(target.Redo());
            Assert.IsTrue(target.CanUndo);
            Assert.IsFalse(target.CanRedo);
            Assert.AreEqual(3, target.Count);
            Assert.AreEqual(200, target[0]);
            Assert.AreEqual(400, target[1]);
            Assert.AreEqual(500, target[2]);
        }
        public void TestRedoable()
        {
            UndoRedoList sut = new UndoRedoList();

            sut.Add(NoAction, NoAction);
            Assert.That(sut.IsRedoActive, Is.False);
        }
示例#3
0
        public void MaximumUndoTimes()
        {
            // List which support undo/redo.
            // maximumUndoTimes is 2.
            var target = new UndoRedoList <int>(maximumUndoTimes: 2);

            // Add an element 3 times.
            target.Add(100);
            target.Add(200);
            target.Add(300);

            // You can undo 2 times.
            Assert.IsTrue(target.CanUndo);
            Assert.IsFalse(target.CanRedo);
            Assert.IsTrue(target.Undo());

            Assert.IsTrue(target.CanUndo);
            Assert.IsTrue(target.CanRedo);
            Assert.IsTrue(target.Undo());

            // You can redo 2 times also.
            Assert.IsFalse(target.CanUndo);
            Assert.IsTrue(target.CanRedo);
            Assert.IsTrue(target.Redo());

            //Assert.IsTrue (target.CanUndo);
            //Assert.IsTrue (target.CanRedo);
            //Assert.IsTrue (target.Redo());

            //Assert.IsTrue (target.CanUndo);
            //Assert.IsFalse(target.CanRedo);
        }
示例#4
0
        public void UndoRedoTest()
        {
            // list which support undo/redo.
            var target = new UndoRedoList <int, List <int> >();

            Assert.IsFalse(target.CanUndo);
            Assert.IsFalse(target.CanRedo);

            // Modify target
            target.Add(100);
            Assert.AreEqual(1, target.Count);
            Assert.AreEqual(100, target[0]);
            Assert.IsTrue(target.CanUndo);
            Assert.IsFalse(target.CanRedo);

            // Undo
            Assert.IsTrue(target.Undo());

            Assert.AreEqual(0, target.Count);
            Assert.IsFalse(target.CanUndo);
            Assert.IsTrue(target.CanRedo);

            // Redo
            Assert.IsTrue(target.Redo());

            Assert.AreEqual(1, target.Count);
            Assert.AreEqual(100, target[0]);
            Assert.IsTrue(target.CanUndo);
            Assert.IsFalse(target.CanRedo);
        }
        public void TestBasicListAction()
        {
            UndoRedoList sut = new UndoRedoList();

            sut.Add(null, null);
            Assert.That(sut.UndoCount, Is.EqualTo(1));
        }
        public void TestUndoable()
        {
            UndoRedoList sut = new UndoRedoList();

            sut.Add(NoAction, null);
            Assert.That(sut.IsUndoActive);
        }
        public void TestBasicCannotRedoOrUndo()
        {
            UndoRedoList sut = new UndoRedoList();

            Assert.That(sut.IsRedoActive, Is.False);
            Assert.That(sut.IsUndoActive, Is.False);
        }
示例#8
0
        public SampleForm()
        {
            // Create data object.
            data = new Data();

            InitializeComponent();

            // Attach (name, value) mapping to comboBox list.
            comboBox.DataSource = SharedResources.ItemTypeItems;

            // Create UndoRedoManager and register "Changed" event.
            undoRedoManager          = new UndoRedoManager();
            undoRedoManager.Changed += OnUndoRedoManagerChanged;

            // Create undo and redo wrapper around the data object.
            UndoRedoTypeDescriptor undoRedoObject =
                new UndoRedoTypeDescriptor(data, Resources.Data_Name, undoRedoManager);

            // Create undo and redo wrapper of the data.Items collection.
            UndoRedoList <GridItem> undoRedoList =
                new UndoRedoList <GridItem>(data.Items, Resources.Data_Name, undoRedoManager);

            // Bind controls.
            propertyGrid.SelectedObject      = undoRedoObject;
            dataBindingSource.DataSource     = undoRedoObject;
            gridItemBindingSource.DataSource = undoRedoList;
        }
示例#9
0
        public void ActionScopeTest()
        {
            // list which support undo/redo.
            var target = new UndoRedoList <int, List <int> >();

            Assert.IsFalse(target.CanUndo);
            Assert.IsFalse(target.CanRedo);

            // ActionScope
            using (var scope = new UndoRedoList <int, List <int> > .ActionScope(target)) {
                // Modify target in ActionScope
                target.Add(100);
                target.Add(200);
                target.Add(300);
            }

            Assert.AreEqual(3, target.Count);
            Assert.AreEqual(100, target[0]);
            Assert.AreEqual(200, target[1]);
            Assert.AreEqual(300, target[2]);
            Assert.IsTrue(target.CanUndo);

            // Undo
            Assert.IsTrue(target.Undo());
            // The 3 actions in ActionScope can undo in one time.
            Assert.AreEqual(0, target.Count);
            Assert.IsFalse(target.CanUndo);
        }
示例#10
0
        public void Undo()
        {
            var target = new UndoRedoList <int, List <int> >();

            Assert.IsFalse(target.Undo());

            target.Add(100);
            Assert.IsTrue(target.CanUndo);
            Assert.AreEqual(1, target.Count);
            Assert.AreEqual(100, target[0]);

            target.Add(200);
            Assert.IsTrue(target.CanUndo);
            Assert.IsFalse(target.CanRedo);
            Assert.AreEqual(2, target.Count);
            Assert.AreEqual(100, target[0]);
            Assert.AreEqual(200, target[1]);

            Assert.IsTrue(target.Undo());
            Assert.IsTrue(target.CanUndo);
            Assert.AreEqual(1, target.Count);
            Assert.AreEqual(100, target[0]);

            Assert.IsTrue(target.Undo());
            Assert.IsFalse(target.CanUndo);
            Assert.AreEqual(0, target.Count);

            target.Add(300);
            Assert.IsTrue(target.CanUndo);
            target.Add(400);
            target.RemoveAt(0);
            Assert.IsTrue(target.CanUndo);
            Assert.AreEqual(1, target.Count);
            Assert.AreEqual(400, target[0]);

            Assert.IsTrue(target.Undo());
            Assert.IsTrue(target.CanUndo);
            Assert.AreEqual(2, target.Count);
            Assert.AreEqual(300, target[0]);
            Assert.AreEqual(400, target[1]);

            target.Add(500);
            target[target.Count - 1] = 600;
            Assert.AreEqual(3, target.Count);
            Assert.AreEqual(600, target[target.Count - 1]);
            Assert.IsTrue(target.CanUndo);
            Assert.IsTrue(target.Undo());
            Assert.AreEqual(3, target.Count);
            Assert.AreEqual(500, target[target.Count - 1]);

            target.Clear();
            Assert.AreEqual(0, target.Count);
            Assert.IsTrue(target.CanUndo);
            Assert.IsTrue(target.Undo());
            Assert.AreEqual(3, target.Count);
            Assert.AreEqual(300, target[0]);
            Assert.AreEqual(400, target[1]);
            Assert.AreEqual(500, target[2]);
        }
        public SudokuSquare()
        {
            _userDismissedValues = new UndoRedoList <bool>(new bool[9]);
            _dismissedValues     = new bool[9];

            _userValue.Changed           += new EventHandler <MemberChangedEventArgs>(_userValue_Changed);
            _userDismissedValues.Changed += new EventHandler <MemberChangedEventArgs>(_userDismissedValues_Changed);
        }
        public void TestRedoableWhenUndo()
        {
            UndoRedoList sut = new UndoRedoList();

            sut.Add(NoAction, NoAction);
            sut.Undo();
            Assert.That(sut.IsRedoActive, Is.True);
        }
        public void TestNameList()
        {
            UndoRedoList sut = new UndoRedoList();

            sut.Add("ActionName", NoAction, NoAction);
            Assert.That(sut.ActionList.Count(), Is.EqualTo(1));
            Assert.That(sut.ActionList.First(), Is.EqualTo("ActionName"));
        }
示例#14
0
        static void Test()
        {
            var list = new UndoRedoList <int, List <int> >();

            AddTest(list);
            RemoveTest(list);
            ExchangeTest(list);
        }
示例#15
0
        public void Construct()
        {
            var target = new UndoRedoList <int, List <int> >();

            Assert.AreEqual(0, target.Count);
            Assert.AreEqual(0, target.List.Count);
            Assert.IsFalse(target.CanUndo);
            Assert.IsFalse(target.CanRedo);
        }
示例#16
0
        public void AddRemove()
        {
            var list = new UndoRedoList<int>();
            // Add
            UndoRedoManager.Start("");
            list.Add(1);
            UndoRedoManager.Commit();

            Assert.AreEqual(1, list[0]);
            Assert.AreEqual(1, list.Count);
            // AddRange
            UndoRedoManager.Start("");
            list.AddRange(new int[] { 2, 3, 4, 5, 6});
            UndoRedoManager.Commit();

            Assert.AreEqual(6, list.Count);
            // RemoveRange
            UndoRedoManager.Start("");
            list.RemoveRange(4, 2);
            UndoRedoManager.Commit();

            // RemoveAt
            UndoRedoManager.Start("");
            list.RemoveAt(0);
            UndoRedoManager.Commit();

            // Remove
            UndoRedoManager.Start("");
            list.Remove(2);
            UndoRedoManager.Commit();

            Assert.AreEqual(3, list[0]);
            Assert.AreEqual(4, list[1]);
            Assert.AreEqual(2, list.Count);

            UndoRedoManager.Undo();
            UndoRedoManager.Undo();
            UndoRedoManager.Undo();
            Assert.AreEqual(6, list.Count);

            UndoRedoManager.Undo(); // undo AddRange
            Assert.AreEqual(1, list.Count);

            UndoRedoManager.Undo(); // undo Add
            Assert.AreEqual(0, list.Count);

            UndoRedoManager.Redo(); // redo Add
            UndoRedoManager.Redo(); // redo AddRange
            Assert.AreEqual(6, list.Count);
            Assert.IsTrue(list[0] == 1 && list[1] == 2 && list[2] == 3 && list[3] == 4 && list[4] == 5 && list[5] == 6);

            UndoRedoManager.Redo(); // redo RemoveRange
            UndoRedoManager.Redo(); // redo RemoveAt
            UndoRedoManager.Redo(); // redo Remove
            Assert.AreEqual(2, list.Count);
        }
示例#17
0
        public void ClearUndo()
        {
            var target = new UndoRedoList <int, List <int> > {
                100, 200, 300
            };

            Assert.IsTrue(target.CanUndo);
            target.ClearUndo();
            Assert.IsFalse(target.CanUndo);
        }
        public void TestBasicUndo()
        {
            Action act = mockRepo.CreateMock <Action>();

            act();
            mockRepo.ReplayAll();
            UndoRedoList sut = new UndoRedoList();

            sut.Add(act, null);
            sut.Undo();
        }
        public void TestRedoListCount()
        {
            UndoRedoList sut = new UndoRedoList();

            sut.Add(NoAction, NoAction);
            sut.Add(NoAction, NoAction);
            sut.Add(NoAction, NoAction);
            sut.Undo();
            sut.Undo();
            Assert.That(sut.RedoCount, Is.EqualTo(2));
        }
示例#20
0
        public void UndoRedoListTest()
        {
            // List which support undo/redo.
            var target = new UndoRedoList <int>();

            target.Add(100);

            // You can undo/redo also.
            Assert.IsTrue(target.CanUndo);
            Assert.IsFalse(target.CanRedo);

            Assert.IsTrue(target.Undo());
            Assert.IsTrue(target.Redo());
        }
示例#21
0
        public void AnotherUndoRedoList()
        {
            // List which support undo/redo.
            var target = new UndoRedoList <int>(maximumUndoTimes: 2);

            target.Add(100);
            target.RemoveAt(0);
            Assert.IsTrue(target.Undo());
            Assert.IsTrue(target.Undo());
            Assert.IsFalse(target.Undo());
            Assert.IsTrue(target.Redo());
            Assert.IsTrue(target.Redo());
            Assert.IsFalse(target.Redo());
        }
        public void TestUndoRedoTwoTimes()
        {
            Action undo = mockRepo.CreateMock <Action>();
            Action redo = mockRepo.CreateMock <Action>();

            Expect.Call(() => undo()).Repeat.Twice();
            Expect.Call(() => redo()).Repeat.Twice();
            mockRepo.ReplayAll();
            UndoRedoList sut = new UndoRedoList();

            sut.Add(undo, redo);
            sut.Undo();
            sut.Redo();
            sut.Undo();
            sut.Redo();
        }
示例#23
0
        static void AddTest(UndoRedoList <int, List <int> > list)
        {
            for (var count = 1; count <= times; count++)
            {
                list.Add(count);
            }

            for (var count = 1; count <= times; count++)
            {
                list.Undo();
            }

            for (var count = 1; count <= times; count++)
            {
                list.Redo();
            }
        }
示例#24
0
        static void RemoveTest(UndoRedoList <int, List <int> > list)
        {
            for (var count = 1; count <= times; count++)
            {
                list.RemoveAt(times - count);
            }

            for (var count = 1; count <= times; count++)
            {
                list.Undo();
            }

            for (var count = 1; count <= times; count++)
            {
                list.Redo();
            }
        }
示例#25
0
        public void DisabledUndoScope()
        {
            var target = new UndoRedoList <int, List <int> > {
                100
            };

            Assert.IsTrue(target.CanUndo);

            using (var scope = new UndoRedoList <int, List <int> > .DisabledUndoScope(target))
                target.Add(200);

            Assert.IsTrue(target.CanUndo);
            Assert.IsTrue(target.Undo());
            Assert.IsFalse(target.CanUndo);
            target.Add(300);
            Assert.IsTrue(target.CanUndo);
        }
        public void TestUndoRedoTwoTimesIsUndoableRedoable()
        {
            UndoRedoList sut = new UndoRedoList();

            sut.Add(NoAction, NoAction);
            Assert.That(sut.IsUndoActive);
            Assert.That(sut.UndoCount, Is.EqualTo(1));
            sut.Undo();
            Assert.That(sut.IsUndoActive, Is.False);
            Assert.That(sut.UndoCount, Is.EqualTo(0));
            Assert.That(sut.IsRedoActive);
            Assert.That(sut.RedoCount, Is.EqualTo(1));
            sut.Redo();
            Assert.That(sut.IsUndoActive);
            Assert.That(sut.UndoCount, Is.EqualTo(1));
            Assert.That(sut.IsRedoActive, Is.False);
            Assert.That(sut.RedoCount, Is.EqualTo(0));
        }
示例#27
0
        public void DisabledUndoScopeTest()
        {
            // list which support undo/redo.
            var target = new UndoRedoList <int, List <int> >();

            Assert.IsFalse(target.CanUndo);
            Assert.IsFalse(target.CanRedo);

            // DisabledUndoScope
            using (var scope = new UndoRedoList <int, List <int> > .DisabledUndoScope(target)) {
                // Modify target in DisabledUndoScope
                target.Add(100);
            }

            // You can't undo actions in DisabledUndoScope.
            Assert.IsFalse(target.CanUndo);
            Assert.IsFalse(target.CanRedo);
        }
示例#28
0
        static void ExchangeTest(UndoRedoList <int, List <int> > list)
        {
            for (var count = 1; count <= times; count++)
            {
                list.Add(count);
            }

            for (var count = 1; count <= times; count++)
            {
                list[random.Next(times)] = count;
            }

            for (var count = 1; count <= times; count++)
            {
                list.Undo();
            }

            for (var count = 1; count <= times; count++)
            {
                list.Redo();
            }
        }
        public CellTriggersTool(MapPanel mapPanel, MapLayerFlag layers, ToolStripStatusLabel statusLbl, ComboBox triggerCombo, IGamePlugin plugin, UndoRedoList <UndoRedoEventArgs> url)
            : base(mapPanel, layers, statusLbl, plugin, url)
        {
            this.mapPanel.MouseDown            += MapPanel_MouseDown;
            this.mapPanel.MouseUp              += MapPanel_MouseUp;
            this.mapPanel.MouseMove            += MapPanel_MouseMove;
            (this.mapPanel as Control).KeyDown += WaypointsTool_KeyDown;
            (this.mapPanel as Control).KeyUp   += WaypointsTool_KeyUp;

            this.triggerCombo = triggerCombo;

            navigationWidget.MouseCellChanged += MouseoverWidget_MouseCellChanged;

            UpdateStatus();
        }
        public void RevertToConcrete()
        {
            _building = true;
            _dontCache = true;

            Layers = new UndoRedoList<EditorTileLayer>();

            Width = ConcreteWidth;
            Height = ConcreteHeight;

            foreach (var layer in ConcreteLayers)
            {
                var newLayer = new EditorTileLayer(layer.Name, layer.Opacity, layer.Visible)
                {
                    Tiles = new EditorTile[Width,Height],
                    Sprites = new Sprite[Width,Height],
                    TerrainCache = new TerrainCache[Width,Height]
                };

                for (var x = 0; x < Width; x++)
                {
                    for (var y = 0; y < Height; y++)
                    {
                        newLayer.Tiles[x, y] = new EditorTile(x, y, 0, 0, 0, 0, newLayer);
                        newLayer.Tiles[x, y].PropertyChanged += Tile_PropertyChanged;
                    }
                }

                foreach (var tile in layer.Tiles)
                {
                    var newTile = newLayer.Tiles[tile.X, tile.Y];
                    newTile.X = tile.X;
                    newTile.Y = tile.Y;
                    newTile.Tileset = tile.Tileset;
                    newTile.SrcX = tile.SrcX;
                    newTile.SrcY = tile.SrcY;
                    newTile.Terrain = tile.Terrain;
                }

                Layers.Add(newLayer);
            }

            _building = false;
            _dontCache = false;

            CacheAllTiles();
        }
 public override void Initialize(MapPanel mapPanel, MapLayerFlag activeLayers, ToolStripStatusLabel toolStatusLabel, ToolTip mouseToolTip, IGamePlugin plugin, UndoRedoList <UndoRedoEventArgs> undoRedoList)
 {
     GenericTypeListBox.Types = plugin.Map.OverlayTypes.Where(t => t.IsWall).OrderBy(t => t.Name);
     Tool = new WallsTool(mapPanel, activeLayers, toolStatusLabel,
                          GenericTypeListBox, GenericTypeMapPanel, plugin, undoRedoList);
 }
示例#32
0
        public void ManualCancel()
        {
            var i = new UndoRedo<int>(0);
            var list = new UndoRedoList<int>(new int[] {1, 2, 3});
            var dict = new UndoRedoDictionary<int, string>();

            UndoRedoManager.Start("");
            i.Value = 1;
            list.Add(4);
            dict[1] = "One";
            UndoRedoManager.Cancel();

            Assert.AreEqual(0, i.Value);
            Assert.AreEqual(3, list.Count);
            Assert.IsFalse(dict.ContainsKey(1));

            // run next command to make sure that framework works well after cancel
            UndoRedoManager.Start("");
            i.Value = 1;
            UndoRedoManager.Commit();

            Assert.AreEqual(1, i.Value);
        }
示例#33
0
        public void Clear()
        {
            var list = new UndoRedoList<int>(new int[] {1, 2, 3});
            Assert.AreEqual(3, list.Count);
            // clear
            UndoRedoManager.Start("");
            list.Clear();
            UndoRedoManager.Commit();
            Assert.AreEqual(0, list.Count);
            // add
            UndoRedoManager.Start("");
            list.Add(1);
            UndoRedoManager.Commit();
            Assert.AreEqual(1, list.Count);

            UndoRedoManager.Undo(); // undo add
            Assert.AreEqual(0, list.Count);
            UndoRedoManager.Undo(); // undo clear
            Assert.AreEqual(3, list.Count);

            UndoRedoManager.Redo(); // redo clear
            Assert.AreEqual(0, list.Count);
            UndoRedoManager.Redo(); // redo add
            Assert.AreEqual(1, list.Count);

            UndoRedoManager.Start("");
            list.Add(1);
            list.Add(2);
            Assert.AreEqual(3, list.Count);
            list.Clear();
            Assert.AreEqual(0, list.Count);
            UndoRedoManager.Commit();

            Assert.AreEqual(0, list.Count);
            UndoRedoManager.Undo(); // undo
            Assert.AreEqual(1, list.Count);
        }
示例#34
0
 static void ApplyChildren(XmlReader re, IChildFigureable c)
 {
     UndoRedoList<Figure> figs = new UndoRedoList<Figure>();
     while (re.Read())
     {
         if (re.NodeType == XmlNodeType.Element && re.LocalName == FIGURE_ELE)
         {
             Figure f = FromXml(re.ReadSubtree());
             if (f != null)
                 figs.Add(f);
         }
     }
     c.ChildFigures = figs;
 }
示例#35
0
 public override void Initialize(MapPanel mapPanel, MapLayerFlag activeLayers, ToolStripStatusLabel toolStatusLabel, ToolTip mouseToolTip, IGamePlugin plugin, UndoRedoList <UndoRedoEventArgs> undoRedoList)
 {
     WaypointCombo.DataSource = plugin.Map.Waypoints.Select(w => w.Name).ToArray();
     Tool = new WaypointsTool(mapPanel, activeLayers, toolStatusLabel, WaypointCombo, plugin, undoRedoList);
 }
示例#36
0
文件: Figure.cs 项目: djpnewton/ddraw
 public GroupFigure(IList<Figure> figs)
 {
     System.Diagnostics.Debug.Assert(figs != null, "figs is not assigned");
     // make new figure list
     childFigs = new UndoRedoList<Figure>();
     foreach (Figure f in figs)
         childFigs.Add(f);
     // store starting dimensions for scaling later on
     CreateOriginalRects();
     // use individual alpha for each child
     UseRealAlpha = false;
 }