private void EllipseButton_Click(object sender, EventArgs e)
        {
            Command addShape = new AddShapeCommand(shapeList, new BaseShape("ellipse", 50, 50, 50, 50, EllipseStrategy.Instance()));

            history.Add(addShape);
            Invalidate();
        }
Exemple #2
0
        public IEnumerable <TranslatableItem> ReplaceTranslate(ReplaceCriteria criteria)
        {
            FilterCriteria searchCriteria = new FilterCriteria(criteria.Pattern, TranslatableItem.Fields.Translate,
                                                               criteria.IsRegex, criteria.IsIgnoreCase);

            List <TranslatableItem>         result   = GetElements(searchCriteria).ToList();
            ConcurrentBag <EditableElement> elements = new ConcurrentBag <EditableElement>();
            Expression <Func <TranslatableItem, string> > replaceExpression;

            if (criteria.IsRegex)
            {
                Regex regex = CreateRegex(criteria.Pattern, criteria.IsIgnoreCase);
                replaceExpression = item => regex.Replace(item.Translate, criteria.Replacement);
            }
            else
            {
                StringComparison comparisonType = GetComparison(criteria.IsIgnoreCase);
                replaceExpression = item => Replace(item.Translate, criteria.Pattern, criteria.Replacement, comparisonType);
            }
            Func <TranslatableItem, string> replaceFunction = replaceExpression.Compile();

            result.AsParallel().ForAll(item =>
            {
                string newTranslate = replaceFunction(item);
                elements.Add(new EditableElement(item, newTranslate));
                item.UpdateTranslate(newTranslate, false);
            });

            UndoRedoManager.Add(elements.ToList());
            HasChanges = true;
            return(result);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnNodeDragCompleted(NetworkView sender, NodeDragCompletedEventArgs e)
        {
            foreach (PositionNodeUndoCommand.NodeDraggingInfo info in m_CachedNodesDraggingList)
            {
                info.EndX = info.Node.X;
                info.EndY = info.Node.Y;
            }

            UndoRedoManager.Add(new PositionNodeUndoCommand(this, m_CachedNodesDraggingList));
        }
Exemple #4
0
        public void ElementUpdated(TranslatableItem element, string newValue, bool isGtran)
        {
            if (element.Translate == newValue)
            {
                return;
            }

            UndoRedoManager.Add(new EditableElement(element, newValue));
            element.UpdateTranslate(newValue, isGtran);
            HasChanges = true;
        }
        public void UndoRedoManagerCanRedo()
        {
            UndoRedoManager undoRedoManager = new UndoRedoManager();

             BookCollection myBooks = new BookCollection();
             myBooks.Name = "A few of my favorite books";
             myBooks.Library.Add( ClockWorkOrange );
             myBooks.Library.Add( DarwinsGod );
             myBooks.Library.Add( SoftwareEstimates );
             myBooks.FavoriteBook = ClockWorkOrange;

             // Originally, cannot redo, there is nothing to redo.
             Assert.IsFalse( undoRedoManager.CanRedo );

             // Add an item, still nothing to redo
             myBooks.Name = "Some Books";
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, String>( myBooks, "Name", UndoableActions.Modify, "A few of my favorite books", "Some Books" ) );
             Assert.IsFalse( undoRedoManager.CanRedo );

             // Undo this item, we now have something to redo
             undoRedoManager.Undo();
             Assert.IsTrue( undoRedoManager.CanRedo );

             // Redo it, and we no longer have anything to redo
             undoRedoManager.Redo();
             Assert.IsFalse( undoRedoManager.CanRedo );

             // Undo it, make a change, undo that one, have two items to redo
             undoRedoManager.Undo();
             myBooks.FavoriteBook = MereChristianity;
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, Book>( myBooks, "FavoriteBook", UndoableActions.Modify, ClockWorkOrange, MereChristianity ) );
             undoRedoManager.Undo();

             Assert.IsTrue( undoRedoManager.CanRedo );
             undoRedoManager.Redo();
             Assert.IsTrue( undoRedoManager.CanRedo );
             undoRedoManager.Redo();
             Assert.IsFalse( undoRedoManager.CanRedo );
        }
        /// <summary>
        /// Delete the currently selected nodes from the view-model.
        /// </summary>
        public void DeleteSelectedNodes()
        {
            // Take a copy of the selected nodes list so we can delete nodes while iterating.
            var nodesCopy = this.Network.Nodes.ToArray();

            List <NodeViewModel> selectedNodes = new List <NodeViewModel>();

            foreach (var node in nodesCopy)
            {
                if (node.IsSelected)
                {
                    selectedNodes.Add(node);
                }
            }

            UndoRedoManager.Add(new DeleteNodesUndoCommand(this, selectedNodes));

            foreach (var node in selectedNodes)
            {
                DeleteNode(node);
            }
        }
        public void UndoRedoManagerCanUndo()
        {
            UndoRedoManager undoRedoManager = new UndoRedoManager();

             BookCollection myBooks = new BookCollection();
             myBooks.Name = "A few of my favorite books";
             myBooks.Library.Add( ClockWorkOrange );
             myBooks.Library.Add( DarwinsGod );
             myBooks.Library.Add( SoftwareEstimates );
             myBooks.FavoriteBook = ClockWorkOrange;

             // Originally, cannot undo, there is nothing to undo.
             Assert.IsFalse( undoRedoManager.CanUndo );

             // Add an item, can now undo
             myBooks.Name = "Some Books";
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, String>( myBooks, "Name", UndoableActions.Modify, "A few of my favorite books", "Some Books" ) );
             Assert.IsTrue( undoRedoManager.CanUndo );

             // After undoing the one change, there is nothing to undo
             undoRedoManager.Undo();
             Assert.IsFalse( undoRedoManager.CanUndo );

             // After redoing, we should be able to undo it again
             undoRedoManager.Redo();
             Assert.IsTrue( undoRedoManager.CanUndo );

             // Make another change, then undo it, should still be able to undo as the first one is still in there.
             myBooks.FavoriteBook = MereChristianity;
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, Book>( myBooks, "FavoriteBook", UndoableActions.Modify, ClockWorkOrange, MereChristianity ) );
             Assert.IsTrue( undoRedoManager.CanUndo );

             undoRedoManager.Undo();
             Assert.IsTrue( undoRedoManager.CanUndo );

             undoRedoManager.Undo();
             Assert.IsFalse( undoRedoManager.CanUndo );
        }
        public void UndoRedoManagerUndoAndRedo()
        {
            UndoRedoManager undoRedoManager = new UndoRedoManager();

             BookCollection myBooks = new BookCollection();
             myBooks.Name = "A few of my favorite books";
             myBooks.Library.Add( DarwinsGod );
             myBooks.Library.Add( SoftwareEstimates );
             myBooks.FavoriteBook = ClockWorkOrange;

             DarwinsGod.Pages = 700;
             SoftwareEstimates.Pages = 800;

             Assert.AreEqual( "A few of my favorite books", myBooks.Name );
             Assert.AreEqual( 2, myBooks.Library.Count );
             Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) );
             Assert.IsTrue( myBooks.Library.Contains( SoftwareEstimates ) );
             Assert.AreEqual( ClockWorkOrange, myBooks.FavoriteBook );
             Assert.AreEqual( 192, ClockWorkOrange.Pages );
             Assert.AreEqual( 700, DarwinsGod.Pages );
             Assert.AreEqual( 227, MereChristianity.Pages );
             Assert.AreEqual( 800, SoftwareEstimates.Pages );

             // Simulate the following editting that got to the state above:
             //    1 - Name -> "Some Books"
             //    2 - Library -> Add MereChristianity
             //    3 - Name -> "A few of my books"
             //    4 - Favorite -> DarwinsGod
             //    5 - Library -> Add DarwinsGod
             //    6 - DarwinsGod -> change pages to 700
             //    7 - SoftwareEstimates -> change pages to 800
             //    8 - Library -> Remove MereChristianity
             //    9 - Favorite -> ClockWorkOrange
             //   10 - Library -> Add SoftwareEstimates
             //   11 - Name -> "A few of my favorite books"
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, String>( myBooks, "Name", UndoableActions.Modify, null, "Some Books" ) );
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, Book>( myBooks, "Library", UndoableActions.Add, null, MereChristianity ) );
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, String>( myBooks, "Name", UndoableActions.Modify, "Some Books", "A few of my books" ) );
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, Book>( myBooks, "FavoriteBook", UndoableActions.Modify, null, DarwinsGod ) );
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, Book>( myBooks, "Library", UndoableActions.Add, null, DarwinsGod ) );
             undoRedoManager.Add(
            new UndoablePropertyValue<Book, Int16>( DarwinsGod, "Pages", UndoableActions.Modify, 338, 700 ) );
             undoRedoManager.Add(
            new UndoablePropertyValue<Book, Int16>( SoftwareEstimates, "Pages", UndoableActions.Modify, 308, 800 ) );
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, Book>( myBooks, "Library", UndoableActions.Remove, MereChristianity, null ) );
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, Book>( myBooks, "FavoriteBook", UndoableActions.Modify, DarwinsGod, ClockWorkOrange ) );
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, Book>( myBooks, "Library", UndoableActions.Add, null, SoftwareEstimates ) );
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, String>( myBooks, "Name", UndoableActions.Modify, "A few of my books", "A few of my favorite books" ) );

             // Can undo, cannot redo.  Undo five items, verify undo() performed at each step.
             Assert.IsTrue( undoRedoManager.CanUndo );
             Assert.IsFalse( undoRedoManager.CanRedo );
             undoRedoManager.Undo(); // 11
             Assert.AreEqual( "A few of my books", myBooks.Name );
             Assert.AreEqual( 2, myBooks.Library.Count );
             Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) );
             Assert.IsTrue( myBooks.Library.Contains( SoftwareEstimates ) );
             Assert.AreEqual( ClockWorkOrange, myBooks.FavoriteBook );
             Assert.AreEqual( 192, ClockWorkOrange.Pages );
             Assert.AreEqual( 700, DarwinsGod.Pages );
             Assert.AreEqual( 227, MereChristianity.Pages );
             Assert.AreEqual( 800, SoftwareEstimates.Pages );

             undoRedoManager.Undo(); // 10
             Assert.AreEqual( "A few of my books", myBooks.Name );
             Assert.AreEqual( 1, myBooks.Library.Count );
             Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) );
             Assert.AreEqual( ClockWorkOrange, myBooks.FavoriteBook );
             Assert.AreEqual( 192, ClockWorkOrange.Pages );
             Assert.AreEqual( 700, DarwinsGod.Pages );
             Assert.AreEqual( 227, MereChristianity.Pages );
             Assert.AreEqual( 800, SoftwareEstimates.Pages );

             undoRedoManager.Undo(); // 9
             Assert.AreEqual( "A few of my books", myBooks.Name );
             Assert.AreEqual( 1, myBooks.Library.Count );
             Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) );
             Assert.AreEqual( DarwinsGod, myBooks.FavoriteBook );
             Assert.AreEqual( 192, ClockWorkOrange.Pages );
             Assert.AreEqual( 700, DarwinsGod.Pages );
             Assert.AreEqual( 227, MereChristianity.Pages );
             Assert.AreEqual( 800, SoftwareEstimates.Pages );

             undoRedoManager.Undo(); // 8
             Assert.AreEqual( "A few of my books", myBooks.Name );
             Assert.AreEqual( 2, myBooks.Library.Count );
             Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) );
             Assert.IsTrue( myBooks.Library.Contains( MereChristianity ) );
             Assert.AreEqual( DarwinsGod, myBooks.FavoriteBook );
             Assert.AreEqual( 192, ClockWorkOrange.Pages );
             Assert.AreEqual( 700, DarwinsGod.Pages );
             Assert.AreEqual( 227, MereChristianity.Pages );
             Assert.AreEqual( 800, SoftwareEstimates.Pages );

             undoRedoManager.Undo(); // 7
             Assert.AreEqual( "A few of my books", myBooks.Name );
             Assert.AreEqual( 2, myBooks.Library.Count );
             Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) );
             Assert.IsTrue( myBooks.Library.Contains( MereChristianity ) );
             Assert.AreEqual( DarwinsGod, myBooks.FavoriteBook );
             Assert.AreEqual( 192, ClockWorkOrange.Pages );
             Assert.AreEqual( 700, DarwinsGod.Pages );
             Assert.AreEqual( 227, MereChristianity.Pages );
             Assert.AreEqual( 308, SoftwareEstimates.Pages );

             // Redo two items
             undoRedoManager.Redo(); // 7
             Assert.AreEqual( "A few of my books", myBooks.Name );
             Assert.AreEqual( 2, myBooks.Library.Count );
             Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) );
             Assert.IsTrue( myBooks.Library.Contains( MereChristianity ) );
             Assert.AreEqual( DarwinsGod, myBooks.FavoriteBook );
             Assert.AreEqual( 192, ClockWorkOrange.Pages );
             Assert.AreEqual( 700, DarwinsGod.Pages );
             Assert.AreEqual( 227, MereChristianity.Pages );
             Assert.AreEqual( 800, SoftwareEstimates.Pages );

             undoRedoManager.Redo(); // 8
             Assert.AreEqual( "A few of my books", myBooks.Name );
             Assert.AreEqual( 1, myBooks.Library.Count );
             Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) );
             Assert.AreEqual( DarwinsGod, myBooks.FavoriteBook );
             Assert.AreEqual( 192, ClockWorkOrange.Pages );
             Assert.AreEqual( 700, DarwinsGod.Pages );
             Assert.AreEqual( 227, MereChristianity.Pages );
             Assert.AreEqual( 800, SoftwareEstimates.Pages );

             // Undo all items
             undoRedoManager.Undo(); // 8
             undoRedoManager.Undo(); // 7
             undoRedoManager.Undo(); // 6
             undoRedoManager.Undo(); // 5
             undoRedoManager.Undo(); // 4
             undoRedoManager.Undo(); // 3
             undoRedoManager.Undo(); // 2
             undoRedoManager.Undo(); // 1
             Assert.IsFalse( undoRedoManager.CanUndo );
             Assert.IsTrue( String.IsNullOrEmpty( myBooks.Name ) );
             Assert.AreEqual( 0, myBooks.Library.Count );
             Assert.IsNull( myBooks.FavoriteBook );
             Assert.AreEqual( 192, ClockWorkOrange.Pages );
             Assert.AreEqual( 338, DarwinsGod.Pages );
             Assert.AreEqual( 227, MereChristianity.Pages );
             Assert.AreEqual( 308, SoftwareEstimates.Pages );

             // Redo all items
             undoRedoManager.Redo(); //  1
             undoRedoManager.Redo(); //  2
             undoRedoManager.Redo(); //  3
             undoRedoManager.Redo(); //  4
             undoRedoManager.Redo(); //  5
             undoRedoManager.Redo(); //  6
             undoRedoManager.Redo(); //  7
             undoRedoManager.Redo(); //  8
             undoRedoManager.Redo(); //  9
             undoRedoManager.Redo(); // 10
             undoRedoManager.Redo(); // 11
             Assert.IsFalse( undoRedoManager.CanRedo );
             Assert.AreEqual( "A few of my favorite books", myBooks.Name );
             Assert.AreEqual( 2, myBooks.Library.Count );
             Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) );
             Assert.IsTrue( myBooks.Library.Contains( SoftwareEstimates ) );
             Assert.AreEqual( ClockWorkOrange, myBooks.FavoriteBook );
             Assert.AreEqual( 192, ClockWorkOrange.Pages );
             Assert.AreEqual( 700, DarwinsGod.Pages );
             Assert.AreEqual( 227, MereChristianity.Pages );
             Assert.AreEqual( 800, SoftwareEstimates.Pages );

             // Reset pages on potentially changed books
             DarwinsGod.Pages = 338;
             SoftwareEstimates.Pages = 308;
        }
        /// <summary>
        /// Called when the user has finished dragging out the new connection.
        /// </summary>
        public void ConnectionDragCompleted(
            ConnectionViewModel newConnection,
            ConnectorViewModel connectorDraggedOut,
            ConnectorViewModel connectorDraggedOver)
        {
            if (connectorDraggedOver == null)
            {
                //
                // The connection was unsuccessful.
                // Maybe the user dragged it out and dropped it in empty space.
                //
                this.Network.Connections.Remove(newConnection);
//                 m_connectorDraggedOut = connectorDraggedOut;
//                 m_ConnectorDraggedOver = connectorDraggedOver;
//
//                 //Open contextMenu
//                 if (ContextMenuOpened != null)
//                 {
//                     ContextMenuOpened(this, null);
//                 }

                return;
            }

            //
            // Only allow connections from output connector to input connector (ie each
            // connector must have a different type).
            // Also only allocation from one node to another, never one node back to the same node.
            //
            string dummy        = string.Empty;
            bool   connectionOk = IsValidConnection(connectorDraggedOut, connectorDraggedOver, ref dummy);

            if (!connectionOk)
            {
                //
                // Connections between connectors that have the same type,
                // eg input -> input or output -> output, are not allowed,
                // Remove the connection.
                //
                this.Network.Connections.Remove(newConnection);
                return;
            }

            //
            // The user has dragged the connection on top of another valid connector.
            //

            //
            // Remove any existing connection between the same two connectors.
            //
            var existingConnection = FindConnection(connectorDraggedOut, connectorDraggedOver);

            if (existingConnection != null)
            {
                this.Network.Connections.Remove(existingConnection);
            }

            // Finalize the connection by reordering the source & destination
            // if necessary
            if (newConnection.DestConnector == null)
            {
                if (connectorDraggedOver.SourceSlot.ConnectionType == SlotType.VarInOut)
                {
                    if (newConnection.SourceConnector.SourceSlot.ConnectionType == SlotType.VarIn)
                    {
                        ConnectorViewModel dest = newConnection.SourceConnector;
                        newConnection.SourceConnector = connectorDraggedOver;
                        newConnection.DestConnector   = dest;
                    }
                    else
                    {
                        newConnection.DestConnector = connectorDraggedOver;
                    }
                }
                else if (connectorDraggedOver.SourceSlot.ConnectionType == SlotType.NodeIn ||
                         connectorDraggedOver.SourceSlot.ConnectionType == SlotType.VarIn)
                {
                    newConnection.DestConnector = connectorDraggedOver;
                }
                else
                {
                    ConnectorViewModel dest = newConnection.SourceConnector;
                    newConnection.SourceConnector = connectorDraggedOver;
                    newConnection.DestConnector   = dest;
                }
            }
            else // connector source is null
            {
                if (connectorDraggedOver.SourceSlot.ConnectionType == SlotType.VarInOut)
                {
                    if (newConnection.DestConnector.SourceSlot.ConnectionType == SlotType.VarIn)
                    {
                        newConnection.SourceConnector = connectorDraggedOver;
                    }
                    else
                    {
                        ConnectorViewModel dest = newConnection.DestConnector;
                        newConnection.DestConnector   = connectorDraggedOver;
                        newConnection.SourceConnector = dest;
                    }
                }
                else if (connectorDraggedOver.SourceSlot.ConnectionType == SlotType.NodeIn ||
                         connectorDraggedOver.SourceSlot.ConnectionType == SlotType.VarIn)
                {
                    newConnection.SourceConnector = connectorDraggedOver;
                }
                else
                {
                    ConnectorViewModel dest = newConnection.DestConnector;
                    newConnection.SourceConnector = connectorDraggedOver;
                    newConnection.DestConnector   = dest;
                }
            }

            //special case variable from 2 SequenceNode directly connected
            if (newConnection.SourceConnector.SourceSlot is NodeSlotVar &&
                newConnection.DestConnector.SourceSlot is NodeSlotVar)
            {
                ConnectorViewModel src = newConnection.SourceConnector;
                newConnection.SourceConnector = newConnection.DestConnector;
                newConnection.DestConnector   = src;
            }

            m_UndoManager.Add(new CreateConnectionUndoCommand(this, newConnection));
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="nodes_"></param>
 public void OnNodesDeselectedChanged(NetworkView view_, IEnumerable <NodeViewModel> nodes_)
 {
     UndoRedoManager.Add(new DeselectNodesUndoCommand(view_, nodes_));
 }