internal void saveCommand(Command cmd, FlowChart flowChart) { if (maxDepth == 0 || !flowChart.confirmRecordAction(cmd)) { cmd.freeUndoResources(); return; } if (currCmd < commands.Count - 1) { for (int i = currCmd + 1; i < commands.Count; ++i) commands[i].freeRedoResources(); commands.RemoveRange(currCmd + 1, commands.Count - currCmd - 1); } commands.Add(cmd); currCmd++; if (commands.Count > maxDepth) { commands[0].freeUndoResources(); commands.RemoveAt(0); currCmd--; } flowChart.fireActionRecorded(cmd); }
internal void executeCommand(Command cmd) { if (cmd == null) return; // just execute the action if no later undo is needed if (!undoEnabled) { cmd.setContext(defaultCmdContext); cmd.Execute(false); cmd.freeUndoResources(); return; } // if executing the ChangeItem comand on table, clear last reference if (cmd == currChangeTableCmd) currChangeTableCmd = null; // if redimensioning a table, handle arrow removals RemoveItemCmd removeItemCmd = cmd as RemoveItemCmd; if (currRedimCmd != null && cmd != currRedimCmd && removeItemCmd != null) { if (removeItemCmd.getItem() is Arrow) { Arrow arr = (Arrow)removeItemCmd.getItem(); if (arr.Origin == currRedimCmd.getItem() || arr.Destination == currRedimCmd.getItem()) { cmd.setContext(defaultCmdContext); cmd.Execute(true); currRedimCmd.AddSubCmd(cmd); return; } } } // handle current composite command if (currCompositeCmd != null) { if (cmd == currCompositeCmd) { history.saveCommand(currCompositeCmd, document); currCompositeCmd = null; return; } else { cmd.setContext(defaultCmdContext); cmd.Execute(true); currCompositeCmd.AddSubCmd(cmd); return; } } // create a single composite command for modify or remove commands // that lead to modification or removal of more items if (currCommand == null) { currCommand = cmd; cmd.setContext(defaultCmdContext); cmd.Execute(true); history.saveCommand(cmd, document); currCommand = null; } else { cmd.setContext(defaultCmdContext); cmd.Execute(true); currCommand.AddSubCmd(cmd); } }