public void InsertObjectforUndoRedo(ChangeRepresentationObject dataobject) { _UndoActionsCollection.Push(dataobject); _RedoActionsCollection.Clear(); if (EnableDisableUndoRedoFeature != null) { EnableDisableUndoRedoFeature(null, null); } }
public void AddAction(ActionType action, TreeNode node, Object object_old, Object object_new) { if (locked) { return; } ChangeRepresentationObject obj = new ChangeRepresentationObject(); obj.Action = action; obj.id = (new Random()).Next(); obj.expanded = node.IsExpanded; Console.WriteLine("[ADD] {0} {1} {2}", obj.id, obj.Action, node.Text); while (node != null) { if (node.Level == 0) { obj.file_idx = node.Index; } else if (node.Level == 1) { obj.block_idx = node.Index; } else if (node.Level == 2) { obj.trigger_idx = node.Index; } else if (node.Level == 4) { if (object_old is Condition && object_new is Condition) { obj.condition_idx = node.Index; } else if (object_old is Reward && object_new is Reward) { obj.reward_idx = node.Index; } else { throw new FooException("Invalid object type at level 4"); } } node = node.Parent; } obj.obj_new = object_new; obj.obj_old = object_old; _UndoActionsCollection.Push(obj); form.undoToolStripMenuItem.Enabled = true; }
public void Redo(int level) { for (int i = 1; i <= level; i++) { if (_RedoActionsCollection.Count == 0) { return; } ChangeRepresentationObject Redostruct = _RedoActionsCollection.Pop(); Console.WriteLine("Redo {0} {1}", Redostruct.id, Redostruct.Action); if (Redostruct.Action == ActionType.Add_Block) { AddBlock(Redostruct.file_idx, Redostruct.block_idx, (QuestBlock)Redostruct.obj_new, Redostruct.expanded); } else if (Redostruct.Action == ActionType.Del_Block) { DelBlock(Redostruct.file_idx, Redostruct.block_idx); } else if (Redostruct.Action == ActionType.Add_Trigger) { AddTrigger(Redostruct.file_idx, Redostruct.block_idx, Redostruct.trigger_idx, (QuestTrigger)Redostruct.obj_new, Redostruct.expanded); } else if (Redostruct.Action == ActionType.Del_Trigger) { DelTrigger(Redostruct.file_idx, Redostruct.block_idx, Redostruct.trigger_idx); } else if (Redostruct.Action == ActionType.Add_Condition) { AddCondition(Redostruct.file_idx, Redostruct.block_idx, Redostruct.trigger_idx, Redostruct.condition_idx, (Condition)Redostruct.obj_new, Redostruct.expanded); } else if (Redostruct.Action == ActionType.Del_Condition) { DelCondition(Redostruct.file_idx, Redostruct.block_idx, Redostruct.trigger_idx, Redostruct.condition_idx); } else if (Redostruct.Action == ActionType.Add_Reward) { AddReward(Redostruct.file_idx, Redostruct.block_idx, Redostruct.trigger_idx, Redostruct.reward_idx, (Reward)Redostruct.obj_new, Redostruct.expanded); } else if (Redostruct.Action == ActionType.Del_Reward) { DelReward(Redostruct.file_idx, Redostruct.block_idx, Redostruct.trigger_idx, Redostruct.reward_idx); } else if (Redostruct.Action == ActionType.Rename_File) { RenameFile(Redostruct.file_idx, (string)Redostruct.obj_new); } else if (Redostruct.Action == ActionType.Rename_Block) { RenameBlock(Redostruct.file_idx, Redostruct.block_idx, (string)Redostruct.obj_new); } else if (Redostruct.Action == ActionType.Rename_Trigger) { RenameTrigger(Redostruct.file_idx, Redostruct.block_idx, Redostruct.trigger_idx, (string)Redostruct.obj_new); } else if (Redostruct.Action == ActionType.Edit_Condition) { EditCondition(Redostruct.file_idx, Redostruct.block_idx, Redostruct.trigger_idx, Redostruct.condition_idx, (Condition)Redostruct.obj_new); } else if (Redostruct.Action == ActionType.Edit_Reward) { EditReward(Redostruct.file_idx, Redostruct.block_idx, Redostruct.trigger_idx, Redostruct.reward_idx, (Reward)Redostruct.obj_new); } else if (Redostruct.Action == ActionType.Paste) { EditTrigger(Redostruct.file_idx, Redostruct.block_idx, Redostruct.trigger_idx, (QuestTrigger)Redostruct.obj_new, Redostruct.expanded); } else if (Redostruct.Action == ActionType.Move_Up) { MoveNodeUp(Redostruct.file_idx, Redostruct.block_idx, Redostruct.trigger_idx, Redostruct.obj_old); Redostruct.trigger_idx--; } else if (Redostruct.Action == ActionType.Move_Down) { MoveNodeDown(Redostruct.file_idx, Redostruct.block_idx, Redostruct.trigger_idx, Redostruct.obj_old); Redostruct.trigger_idx++; } _UndoActionsCollection.Push(Redostruct); } }