Ejemplo n.º 1
0
        protected void CreateShape()
        {
            BaseController canvasController = serviceManager.Get <IFlowSharpCanvasService>().ActiveController;

            int where = xDisplacement;

            // For undo, we need to preserve currently selected shapes.
            List <GraphicElement> currentSelectedShapes = canvasController.SelectedElements.ToList();
            GraphicElement        selectedElement       = selectedElements[0];
            GraphicElement        el = selectedElement.CloneDefault(canvasController.Canvas, new Point(where, 0));

            canvasController.UndoStack.UndoRedo("Create " + el.ToString(),
                                                () =>
            {
                // ElementCache.Instance.Remove(el);
                el.UpdatePath();
                canvasController.Insert(el);
                canvasController.DeselectCurrentSelectedElements();
                canvasController.SelectElement(el);
                serviceManager.Get <IFlowSharpDebugWindowService>().UpdateDebugWindow();

                if (dragging)
                {
                    Cursor.Position = canvas.PointToScreen(el.DisplayRectangle.Center().Move(canvas.Width, 0));

                    if (el.IsConnector)
                    {
                        el.ShowAnchors = true;
                    }
                }
            },
                                                () =>
            {
                // ElementCache.Instance.Add(el);
                canvasController.DeselectCurrentSelectedElements();
                canvasController.DeleteElement(el, false);
                canvasController.SelectElements(currentSelectedShapes);
                serviceManager.Get <IFlowSharpDebugWindowService>().UpdateDebugWindow();
            });
        }