Ejemplo n.º 1
0
        public void UndoTest()
        {
            UndoManager undoManager = new UndoManager();
            MockUndo    undo1       = new MockUndo();
            MockUndo    undo2       = new MockUndo();

            undoManager.Add(undo1);
            undoManager.Add(undo2);

            undoManager.Undo();
            Assert.IsTrue(undo2.undoCalled);
            Assert.IsFalse(undo1.undoCalled);
            Assert.IsTrue(undoManager.CanUndo);
        }
        //------------------------------------------------------
        //
        //  Privte Methods
        //
        //------------------------------------------------------

        #region Private Methods

        // Private helper that adds a new UIElementPropertyUndoUnit to the undo stack.
        private static void AddPrivate(ITextContainer textContainer, UIElement uiElement, DependencyProperty property, object newValue)
        {
            UndoManager undoManager = TextTreeUndo.GetOrClearUndoManager(textContainer);

            if (undoManager == null)
            {
                return;
            }

            object currentValue = uiElement.ReadLocalValue(property);

            if (currentValue is Expression)
            {
                // Can't undo when old value is an expression, so clear the stack.
                if (undoManager.IsEnabled)
                {
                    undoManager.Clear();
                }
                return;
            }

            if (currentValue.Equals(newValue))
            {
                // No property change.
                return;
            }

            undoManager.Add(new UIElementPropertyUndoUnit(uiElement, property, currentValue));
        }
Ejemplo n.º 3
0
        public void CanRedoTest()
        {
            UndoManager undoManager = new UndoManager();

            Assert.IsFalse(undoManager.CanUndo);

            undoManager.Add(new MockUndo(false));
            Assert.IsTrue(undoManager.CanUndo);
            undoManager.Undo();
            Assert.IsFalse(undoManager.CanRedo);
            undoManager.Add(new MockUndo(true));
            Assert.IsTrue(undoManager.CanUndo);
            undoManager.Undo();
            Assert.IsFalse(undoManager.CanUndo);
            Assert.IsTrue(undoManager.CanRedo);
            undoManager.Redo();
            Assert.IsTrue(undoManager.CanUndo);
            Assert.IsFalse(undoManager.CanRedo);
        }
        // Token: 0x06003E29 RID: 15913 RVA: 0x0011D570 File Offset: 0x0011B770
        internal static void CreateInsertUndoUnit(TextContainer tree, int symbolOffset, int symbolCount)
        {
            UndoManager orClearUndoManager = TextTreeUndo.GetOrClearUndoManager(tree);

            if (orClearUndoManager == null)
            {
                return;
            }
            orClearUndoManager.Add(new TextTreeInsertUndoUnit(tree, symbolOffset, symbolCount));
        }
Ejemplo n.º 5
0
 public void AddUndo(IUndo undo)
 {
     if (undo.GetType() == typeof(UndoMap))
     {
         this.mapOriginal      = (undo as UndoMap).MapOriginal;
         this.undoEventHandler = (undo as UndoMap).UndoEventHandler;
     }
     undoManagerEditing = true;
     manager.Add(undo, listView1.Items);
     undoManagerEditing = false;
 }
        // Token: 0x06003E2D RID: 15917 RVA: 0x0011D670 File Offset: 0x0011B870
        internal static TextTreeExtractElementUndoUnit CreateExtractElementUndoUnit(TextContainer tree, TextTreeTextElementNode elementNode)
        {
            UndoManager orClearUndoManager = TextTreeUndo.GetOrClearUndoManager(tree);

            if (orClearUndoManager == null)
            {
                return(null);
            }
            TextTreeExtractElementUndoUnit textTreeExtractElementUndoUnit = new TextTreeExtractElementUndoUnit(tree, elementNode);

            orClearUndoManager.Add(textTreeExtractElementUndoUnit);
            return(textTreeExtractElementUndoUnit);
        }
Ejemplo n.º 7
0
        public void RedoTest()
        {
            UndoManager undoManager = new UndoManager();
            MockUndo    undo1       = new MockUndo(true);

            undoManager.Add(undo1);
            undoManager.Undo();
            Assert.IsTrue(undo1.undoCalled);
            Assert.IsFalse(undo1.redoCalled);
            Assert.IsTrue(undoManager.CanRedo);
            undoManager.Redo();
            Assert.IsTrue(undo1.redoCalled);
            Assert.IsFalse(undoManager.CanRedo);
        }
        // Token: 0x06003E2B RID: 15915 RVA: 0x0011D5C0 File Offset: 0x0011B7C0
        internal static void CreatePropertyUndoUnit(TextElement element, DependencyPropertyChangedEventArgs e)
        {
            TextContainer textContainer      = element.TextContainer;
            UndoManager   orClearUndoManager = TextTreeUndo.GetOrClearUndoManager(textContainer);

            if (orClearUndoManager == null)
            {
                return;
            }
            PropertyRecord propertyRecord = default(PropertyRecord);

            propertyRecord.Property = e.Property;
            propertyRecord.Value    = ((e.OldValueSource == BaseValueSourceInternal.Local) ? e.OldValue : DependencyProperty.UnsetValue);
            orClearUndoManager.Add(new TextTreePropertyUndoUnit(textContainer, element.TextElementNode.GetSymbolOffset(textContainer.Generation) + 1, propertyRecord));
        }
Ejemplo n.º 9
0
        private bool CreateUndo(Map map, int position)
        {
            Map        mapBeforeEdit = map.CopyRegion();
            IMapObject obj;

            fillMapRects[position] = new Rectangle();
            switch (random.Next(3))
            {
            case 0:
                fillMapRects[position] = FillMapRandom(map);
                totalBackgroundCount++;
                // Sicherstellen, dass Änderungen gemacht wurden.
                if (fillMapRects[position].IsEmpty)
                {
                    return(false);
                }
                break;

            case 1:
                obj = FillMapObject(map);
                totalObjectCount++;
                break;

            case 2:
                FillMapCollisions(map);
                totalCollsionCount++;
                break;

            default:
                break;
            }


            UndoMap   undoMap            = new UndoMap(mapBeforeEdit, map, new UndoEventHandler(UndoEvent));
            int       listViewItemsCount = listView.Items.Count;
            Rectangle rectBeforeUndo     = TileDiffs(mapBeforeEdit, map);

            undoManager.Add(undoMap, listView.Items);

            // Sicherstellen, dass ein Eintrag im ListView gemacht wurde.
            if (listViewItemsCount + 1 != listView.Items.Count)
            {
                return(false);
            }

            // Rückgabewert ist true, falls das Skript bis hierhin gelaufen ist.
            return(true);
        }
        // Token: 0x06003E2C RID: 15916 RVA: 0x0011D638 File Offset: 0x0011B838
        internal static TextTreeDeleteContentUndoUnit CreateDeleteContentUndoUnit(TextContainer tree, TextPointer start, TextPointer end)
        {
            if (start.CompareTo(end) == 0)
            {
                return(null);
            }
            UndoManager orClearUndoManager = TextTreeUndo.GetOrClearUndoManager(tree);

            if (orClearUndoManager == null)
            {
                return(null);
            }
            TextTreeDeleteContentUndoUnit textTreeDeleteContentUndoUnit = new TextTreeDeleteContentUndoUnit(tree, start, end);

            orClearUndoManager.Add(textTreeDeleteContentUndoUnit);
            return(textTreeDeleteContentUndoUnit);
        }
Ejemplo n.º 11
0
        public void MaxSupportedOperationsTest()
        {
            UndoManager target = new UndoManager {
                MaxSupportedOperations = 5
            };
            List <MockUndo> listUndoOps = new List <MockUndo>();

            for (int i = 0; i < 10; i++)
            {
                MockUndo undoObj = new MockUndo()
                {
                    Value = i
                };
                target.Add(undoObj);
                listUndoOps.Add(undoObj);
            }

            int count = 0;

            while (target.CanUndo)
            {
                target.Undo();
                count++;
            }

            // Should have called final 5.. skipped first 5.
            for (int i = 0; i < 5; i++)
            {
                Assert.IsFalse(listUndoOps[i].undoCalled);
            }
            for (int i = 5; i < 10; i++)
            {
                Assert.IsTrue(listUndoOps[i].undoCalled);
            }

            Assert.AreEqual(count, target.MaxSupportedOperations);
        }
Ejemplo n.º 12
0
        // Token: 0x06002F10 RID: 12048 RVA: 0x000D4A50 File Offset: 0x000D2C50
        private static void AddPrivate(ITextContainer textContainer, UIElement uiElement, DependencyProperty property, object newValue)
        {
            UndoManager orClearUndoManager = TextTreeUndo.GetOrClearUndoManager(textContainer);

            if (orClearUndoManager == null)
            {
                return;
            }
            object obj = uiElement.ReadLocalValue(property);

            if (obj is Expression)
            {
                if (orClearUndoManager.IsEnabled)
                {
                    orClearUndoManager.Clear();
                }
                return;
            }
            if (obj.Equals(newValue))
            {
                return;
            }
            orClearUndoManager.Add(new UIElementPropertyUndoUnit(uiElement, property, obj));
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Adds an undo unit to current document's undo stack
 /// </summary>
 public virtual void AddUndoUnit(IOleUndoUnit undoUnit)
 {
     UndoManager.Add(undoUnit);
 }