示例#1
0
        /// <summary>
        /// Создает описание обратного действия
        /// </summary>
        /// <param name="unit"></param>
        /// <returns></returns>
        private UndoUnit CreateReverseUndoAction(UndoUnit unit)
        {
            UndoUnit result = new UndoUnit();

            if (unit.Kind == ActionKind.Add)
            {
                result.Kind             = ActionKind.Remove;
                result.OriginalPointRef = unit.OriginalPointRef;
                result.OriginalParent   = unit.OriginalParent;
                result.OriginalPosition = unit.OriginalParent.Items.IndexOf(unit.OriginalPointRef);
            }
            else if (unit.Kind == ActionKind.Remove)
            {
                result.Kind             = ActionKind.Add;
                result.OriginalPointRef = unit.OriginalPointRef;
                result.OriginalParent   = unit.OriginalParent;
                result.OriginalPosition = unit.OriginalPosition;
            }
            else if (unit.Kind == ActionKind.Move)
            {
                result.Kind                 = ActionKind.Move;
                result.OriginalPointRef     = unit.OriginalPointRef;
                result.OriginalParent       = unit.OriginalPointContent;
                result.OriginalPointContent = unit.OriginalParent;
                result.OriginalPosition     = unit.OriginalPointContent.Items.IndexOf(unit.OriginalPointRef);
            }
            else //if (result.Kind == ActionKind.Edit)
            {
                result.Kind                 = ActionKind.Edit;
                result.OriginalPointRef     = unit.OriginalPointRef;
                result.OriginalPointContent = unit.OriginalPointRef.ClonePointAssignItems();
            }
            return(result);
        }
示例#2
0
 /// <summary>
 /// Создает описание обратного действия
 /// </summary>
 /// <param name="unit"></param>
 /// <returns></returns>
 private UndoUnit CreateReverseUndoAction(UndoUnit unit)
 {
     UndoUnit result = new UndoUnit();
     if (unit.Kind == ActionKind.Add)
     {
         result.Kind = ActionKind.Remove;
         result.OriginalPointRef = unit.OriginalPointRef;
         result.OriginalParent = unit.OriginalParent;
         result.OriginalPosition = unit.OriginalParent.Items.IndexOf(unit.OriginalPointRef);
     }
     else if (unit.Kind == ActionKind.Remove)
     {
         result.Kind = ActionKind.Add;
         result.OriginalPointRef = unit.OriginalPointRef;
         result.OriginalParent = unit.OriginalParent;
         result.OriginalPosition = unit.OriginalPosition;
     }
     else if (unit.Kind == ActionKind.Move)
     {
         result.Kind = ActionKind.Move;
         result.OriginalPointRef = unit.OriginalPointRef;
         result.OriginalParent = unit.OriginalPointContent;
         result.OriginalPointContent = unit.OriginalParent;
         result.OriginalPosition = unit.OriginalPointContent.Items.IndexOf(unit.OriginalPointRef);
     }
     else //if (result.Kind == ActionKind.Edit)
     {
         result.Kind = ActionKind.Edit;
         result.OriginalPointRef = unit.OriginalPointRef;
         result.OriginalPointContent = unit.OriginalPointRef.ClonePointAssignItems();
     }
     return result;
 }
        public void Redo()
        {
            UndoUnit redo = undoEngine.Redo();

            if (redo == null)
            {
                return;
            }

            ApplyUndoUnit(redo);
        }
        public void Undo()
        {
            UndoUnit undo = undoEngine.Undo();

            if (undo == null)
            {
                return;
            }

            ApplyUndoUnit(undo);
        }
示例#5
0
        /// <summary>
        /// Возвращает описание повторяемого действия, попутно сохраняя состояние точки для возможной отмены действия
        /// </summary>
        /// <returns></returns>
        public UndoUnit Redo()
        {
            if (RedoStack.Count == 0)
            {
                return(null);
            }
            UndoUnit result = RedoStack.Pop();

            UndoStack.Push(CreateReverseUndoAction(result));
            return(result);
        }
示例#6
0
        /// <summary>
        /// Создавет экземпляр UndoAction по нынешнему состоянию точки
        /// При kind == move, параметр newParent обязателен
        /// </summary>
        /// <param name="point">Исходная точка</param>
        /// <param name="parent">Исходный родитель точки</param>
        /// <param name="kind">Тип действия</param>
        private UndoUnit CreateUndoUnit(PointOfInterest point, PointOfInterest parent, ActionKind kind, PointOfInterest newParent = null)
        {
            if (kind == ActionKind.Move && newParent == null)
                throw new ArgumentException();
            UndoUnit undo = new UndoUnit();
            undo.Kind = kind;
            undo.OriginalParent = parent;
            undo.OriginalPosition = parent == null ? 0 : parent.Items.IndexOf(point);
            undo.OriginalPointRef = point;
            if (kind == ActionKind.Edit)
                undo.OriginalPointContent = point.ClonePointAssignItems();
            if (kind == ActionKind.Move)
                undo.OriginalPointContent = newParent;

            return undo;
        }
 private void ApplyUndoUnit(UndoUnit action)
 {
     if (action.Kind == ActionKind.Add)
     {
         //Добавляли, нужно удалить
         TreeNode node = FindNodeByValue(action.OriginalPointRef);
         action.OriginalParent.Items.Remove(action.OriginalPointRef);
         removeNodeFromDictionary(node);
         node.Remove();
     }
     else if (action.Kind == ActionKind.Remove)
     {
         //Удаляли, нужно добавить
         TreeNode parentNode = FindNodeByValue(action.OriginalParent);
         action.OriginalParent.Items.Insert(action.OriginalPosition, action.OriginalPointRef);
         TreeNode newNode = ConvertPointToTree(action.OriginalPointRef);
         if (parentNode == null)
         {
             treeView.Nodes.Insert(action.OriginalPosition, newNode);
         }
         else
         {
             parentNode.Nodes.Insert(action.OriginalPosition, newNode);
         }
     }
     else if (action.Kind == ActionKind.Move)
     {
         //Перемещали
         TreeNode           node      = FindNodeByValue(action.OriginalPointRef);
         TreeNodeCollection oldCol    = node.Parent == null ? treeView.Nodes : node.Parent.Nodes;
         TreeNode           newParent = FindNodeByValue(action.OriginalParent);
         TreeNodeCollection newCol    = newParent == null ? treeView.Nodes : newParent.Nodes;
         oldCol.Remove(node);
         newCol.Insert(action.OriginalPosition, node);
         action.OriginalPointContent.Items.Remove(action.OriginalPointRef);
         action.OriginalParent.Items.Insert(action.OriginalPosition, action.OriginalPointRef);
     }
     else if (action.Kind == ActionKind.Edit)
     {
         //Редактировали
         TreeNode node = FindNodeByValue(action.OriginalPointRef);
         action.OriginalPointRef.ApplyChanges(action.OriginalPointContent);
         node.Text        = action.OriginalPointRef.Title;
         node.ToolTipText = action.OriginalPointRef.Note;
     }
     manager.isFileSaved = false;
 }
示例#8
0
        /// <summary>
        /// Создавет экземпляр UndoAction по нынешнему состоянию точки
        /// При kind == move, параметр newParent обязателен
        /// </summary>
        /// <param name="point">Исходная точка</param>
        /// <param name="parent">Исходный родитель точки</param>
        /// <param name="kind">Тип действия</param>
        private UndoUnit CreateUndoUnit(PointOfInterest point, PointOfInterest parent, ActionKind kind, PointOfInterest newParent = null)
        {
            if (kind == ActionKind.Move && newParent == null)
            {
                throw new ArgumentException();
            }
            UndoUnit undo = new UndoUnit();

            undo.Kind             = kind;
            undo.OriginalParent   = parent;
            undo.OriginalPosition = parent == null ? 0 : parent.Items.IndexOf(point);
            undo.OriginalPointRef = point;
            if (kind == ActionKind.Edit)
            {
                undo.OriginalPointContent = point.ClonePointAssignItems();
            }
            if (kind == ActionKind.Move)
            {
                undo.OriginalPointContent = newParent;
            }

            return(undo);
        }
 private void ApplyUndoUnit(UndoUnit action)
 {
     if (action.Kind == ActionKind.Add)
     {
         //Добавляли, нужно удалить
         TreeNode node = FindNodeByValue(action.OriginalPointRef);
         action.OriginalParent.Items.Remove(action.OriginalPointRef);
         removeNodeFromDictionary(node);
         node.Remove();
     }
     else if (action.Kind == ActionKind.Remove)
     {
         //Удаляли, нужно добавить
         TreeNode parentNode = FindNodeByValue(action.OriginalParent);
         action.OriginalParent.Items.Insert(action.OriginalPosition, action.OriginalPointRef);
         TreeNode newNode = ConvertPointToTree(action.OriginalPointRef);
         if (parentNode == null)
             treeView.Nodes.Insert(action.OriginalPosition, newNode);
         else
             parentNode.Nodes.Insert(action.OriginalPosition, newNode);
     }
     else if (action.Kind == ActionKind.Move)
     {
         //Перемещали
         TreeNode node = FindNodeByValue(action.OriginalPointRef);
         TreeNodeCollection oldCol = node.Parent == null ? treeView.Nodes : node.Parent.Nodes;
         TreeNode newParent = FindNodeByValue(action.OriginalParent);
         TreeNodeCollection newCol = newParent == null ? treeView.Nodes : newParent.Nodes;
         oldCol.Remove(node);
         newCol.Insert(action.OriginalPosition, node);
         action.OriginalPointContent.Items.Remove(action.OriginalPointRef);
         action.OriginalParent.Items.Insert(action.OriginalPosition, action.OriginalPointRef);
     }
     else if (action.Kind == ActionKind.Edit)
     {
         //Редактировали
         TreeNode node = FindNodeByValue(action.OriginalPointRef);
         action.OriginalPointRef.ApplyChanges(action.OriginalPointContent);
         node.Text = action.OriginalPointRef.Title;
         node.ToolTipText = action.OriginalPointRef.Note;
     }
     manager.isFileSaved = false;
 }