private void AddToUndo(string SourceFilename, string DestFilename, UndoMode mode, int picIndex) { UndoData u = new UndoData(); u.source = SourceFilename; u.dest = DestFilename; u.mode = mode; u.picIndex = picIndex; undo.Push(u); mainForm.FileManagementCallback(new UndoCallbackData(UndoCallbackEvent.UndoUpdated, u)); }
public void UndoLastFileOperation() { bool bContinue = true; string errors = ""; string lastItemGroup = "unset"; if (undo.Count == 0) { MessageBox.Show(_("Nothing to undo..."), _("Oops"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } bool stopGoto = false; int num = 0; string oldCurPath = mainForm.GetCurPicPath(); // CurPath must be no duplicates while (bContinue) { if (undo.Count == 0 || lastItemGroup != "unset" && lastItemGroup != undo.Peek().actionGroup) // Assume that batch data is continuous { if (stopGoto && num > 0) // Refresh when undoing a batch of deletions, keep in current picture. { mainForm.PicGotoCallback(-1, oldCurPath); } break; // emptied or this is new undo group } UndoData u = undo.Pop(); lastItemGroup = u.actionGroup; if (u.mode == UndoMode.Copy) { DeleteFile(u.dest, false); // delete copy of original file } else if (u.mode == UndoMode.Move) { AppSettings s = new AppSettings(); s.FileMode = FileOperations.Move; s.ExistingFiles = ExistingFileOptions.Overwrite; errors += CopyMoveFile(u.dest, u.source, s, -1, false) + "\n"; // move back file } else if (u.mode == UndoMode.Rename) { RenameFile(u.dest, u.source, -1, false); // rename back to original filename } else if (u.mode == UndoMode.Delete) { Undelete(u.source); stopGoto = true; // better performance for a batch } num++; mainForm.FileManagementCallback(new UndoCallbackData(UndoCallbackEvent.UndoPerformed, u), stopGoto); } if (!string.IsNullOrWhiteSpace(errors)) { MessageBox.Show("Error copying/moving file: \n\n" + errors, "File Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }