private void undoToolStripMenuItem_Click(object sender, EventArgs e) { if (undo.Count < 1) { return; } int nodeId = undo.Peek().Id; while (undo.Count > 0 && nodeId == undo.Peek().Id) { // undo Model.HistoryNode undoo = undo.Pop(); // save for redo redo.Push(new Model.HistoryNode(undoo.Id, undoo.MapX, undoo.MapY, map[undoo.MapX, undoo.MapY])); // render undo map[undoo.MapX, undoo.MapY] = undoo.Value; } RenderMap(); redoToolStripMenuItem.Enabled = true; if (undo.Count > 0) { undoToolStripMenuItem.Enabled = true; } else { undoToolStripMenuItem.Enabled = false; } }
private void redoToolStripMenuItem_Click(object sender, EventArgs e) { if (redo.Count < 1) { return; } int nodeId = redo.Peek().Id; while (redo.Count > 0 && nodeId == redo.Peek().Id) { // redo Model.HistoryNode redoo = redo.Pop(); // save current map for undo undo.Push(new Model.HistoryNode(redoo.Id, redoo.MapX, redoo.MapY, map[redoo.MapX, redoo.MapY])); // render redo map[redoo.MapX, redoo.MapY] = redoo.Value; } RenderMap(); undoToolStripMenuItem.Enabled = true; if (redo.Count > 0) { redoToolStripMenuItem.Enabled = true; } else { redoToolStripMenuItem.Enabled = false; } }