コード例 #1
0
ファイル: UndoStack.cs プロジェクト: git-thinh/appie
 /// <summary>Executes an action and adds it to the undo stack.</summary>
 /// <param name="action">Action to take. Initially called with an argument of true.</param>
 /// <param name="finishGroup">If you want to group multiple actions together
 /// so that one undo command undoes all of them, this parameter should be
 /// true only on the last action.</param>
 /// <remarks>If there are any actions on the tentative stack, they are accepted
 /// and grouped with this new action.</remarks>
 public virtual void Do(DoOrUndo action, bool finishGroup = true)
 {
     if (action != null)
     {
         AcceptTentativeAction(false);
         _undoStack.Push(new Command(action, finishGroup).Do());
         _redoStack.Clear();
         AfterAction(true);
     }
 }
コード例 #2
0
        /// <summary>Executes an action and adds it to the undo stack.</summary>
        /// <param name="action">Action to take. Initially called with an argument of true.</param>
        /// <param name="finishGroup">If you want to group multiple actions together
        /// so that one undo command undoes all of them, this parameter should be
        /// true only on the last action.</param>
        /// <remarks>If there are any actions on the tentative stack, they are accepted
        /// and grouped with this new action.</remarks>
        public virtual void Do(string name, DoOrUndo action, bool finishGroup = true)
        {
            Performing = ActionState.Do;

            if (action != null)
            {
                AcceptTentativeAction(false);
                _undoStack.Push(new Command(name, action, finishGroup).Do());
                _redoStack.Clear();
                //   AfterAction.Fire(this, EventArgs.Empty);
                // AfterAction(true);
            }
        }
コード例 #3
0
        private void HandleMouseUp(DragState state, Shape newShape, IEnumerable <Shape> eraseSet)
        {
            if (!state.IsDrag)
            {
                if (state.Clicks >= 2)
                {
                    if (Control.SelectedShapes.Count != 0)
                    {
                        var htr = state.ClickedShape;
                        foreach (var shape in Control.SelectedShapes)
                        {
                            DoOrUndo action = shape.DoubleClickAction(htr.Shape == shape ? htr : null);
                            if (action != null)
                            {
                                _doc.UndoStack.Do(action, false);
                            }
                        }
                        _doc.UndoStack.FinishGroup();
                    }
                    else
                    {
                        // Create marker shape
                        newShape = new Marker(Control.BoxStyle, state.FirstPoint, Control.MarkerRadius, Control.MarkerType);
                    }
                }
                else
                {
                    Control.ClickSelect(state.ClickedShape != null ? state.ClickedShape.Shape as Shape : null);
                    Control._lastClickLocation = state.FirstPoint;
                }
            }

            _doc.UndoStack.AcceptTentativeAction();             // if any
            Control._partialSelShape = null;
            if (newShape != null)
            {
                if (newShape.Style == SelectorBoxStyle)
                {
                    SelectByBox(newShape.BBox);
                }
                else
                {
                    Control.AddShape(newShape);
                }
            }
            if (eraseSet != null)
            {
                Control.DeleteShapes(new Set <Shape>(eraseSet));
            }
            _doc.MarkPanels();
        }
コード例 #4
0
        private void HandleShapeDrag(DragState state)
        {
            _doc.UndoStack.UndoTentativeAction();

            var movingShapes = Control.SelectedShapes;
            var panels       = Control.SelectedShapes.Where(s => s.IsPanel);

            if (panels.Any() && (Control.SelectedShapes.Count > 1 ||
                                 state.ClickedShape.MouseCursor == Cursors.SizeAll))
            {
                // Also move shapes that are inside the panel
                movingShapes = Control.SelectedShapes.Clone();
                foreach (var panel in panels)
                {
                    movingShapes.AddRange(ShapesInsidePanel(panel));
                }
            }

            if (movingShapes.Count <= 1)
            {
                var shape = state.ClickedShape.Shape;
                if (shape is Shape)
                {
                    DoOrUndo action = ((Shape)shape).DragMoveAction(state.ClickedShape, state.TotalDelta);
                    if (action != null)
                    {
                        _doc.UndoStack.DoTentatively(action);
                        AutoHandleAnchorsChanged();
                    }
                }
            }
            else
            {
                foreach (Shape shape in movingShapes)
                {
                    DoOrUndo action = shape.DragMoveAction(state.ClickedShape, state.TotalDelta);
                    if (action != null)
                    {
                        _doc.UndoStack.DoTentatively(action);
                    }
                }
                AutoHandleAnchorsChanged();
            }
        }
コード例 #5
0
        public bool Paste(bool run = true)
        {
            if (Clipboard.ContainsData("DiagramDocument"))
            {
                if (run)
                {
                    var buf = Clipboard.GetData("DiagramDocument") as byte[];
                    if (buf != null)
                    {
                        PasteAndSelect(new MemoryStream(buf), VectorT.Zero);
                    }
                }
                return(true);
            }
            else if (Clipboard.ContainsText())
            {
                if (run)
                {
                    var text = Clipboard.GetText();

                    DoOrUndo act = null;
                    if (_focusShape != null && (act = _focusShape.AppendTextAction(text)) != null)
                    {
                        _doc.UndoStack.Do(act, true);
                    }
                    else
                    {
                        var textBox = new TextBox(new BoundingBox <Coord>(0, 0, 300, 200))
                        {
                            Text        = text,
                            TextJustify = LLTextShape.JustifyMiddleCenter,
                            BoxType     = BoxType.Borderless,
                            Style       = BoxStyle
                        };
                        _doc.AddShape(textBox);
                    }
                }
                return(true);
            }
            return(false);
        }
コード例 #6
0
 public Command(DoOrUndo action, bool finishGroup)
 {
     _action = action; _done = false; _finishGroup = finishGroup;
 }
コード例 #7
0
ファイル: UndoStack.cs プロジェクト: git-thinh/appie
 /// <summary>Performs an action without clearing the redo stack.</summary>
 /// <remarks>All tentative actions pending at the same time are placed
 /// in the same undo group. Call <see cref="AcceptTentativeAction"/> or
 /// <see cref="Do"/> to finalize, or <see cref="UndoTetativeAction"/> to
 /// undo.
 public virtual void DoTentatively(DoOrUndo action)
 {
     _tempStack.Push(new Command(action, false).Do());
     AfterAction(true);
 }
コード例 #8
0
 public Command(string name, DoOrUndo action, bool finishGroup)
 {
     _name = name; _action = action; _done = false; _finishGroup = finishGroup;
 }