private void UndoRedo(Stack source, Stack dest) { if (source != null && source.Count != 0) { listSSA.BeginUpdate(); object undo = source.Pop(); LineUndo lu; if (undo is List<Line>) { // New list dest.Push(lineColl); lineColl = (List<Line>)undo; } else if (undo is List<int>) { // Added multiple lines List<LineUndo> redolu = new List<LineUndo>(); List<int> undointlist = (List<int>)undo; int rindex; for (int index = 0; index != undointlist.Count; index+=1) { lu = new LineUndo(); rindex = undointlist[index]; lu.index = rindex; lu.line = lineColl[rindex]; redolu.Add(lu); lineColl.RemoveAt(rindex); } dest.Push(redolu); } else if (undo is List<LineUndo>) { // Deleted multiple lines List<int> redoint = new List<int>(); List<LineUndo> undolulist = (List<LineUndo>)undo; for (int index = 0; index != undolulist.Count; index+=1) { lu = (LineUndo)undolulist[index]; redoint.Add(lu.index); lineColl.Insert(lu.index, lu.line); } dest.Push(redoint); } else if (undo is int) { // added one line lu.index = (int)undo; lu.line = lineColl[lu.index]; lineColl.RemoveAt(lu.index); dest.Push(lu); } else if (undo is LineUndo) { // deleted one line lu = (LineUndo)undo; dest.Push(lu.index); lineColl.Insert(lu.index, lu.line); } else if (undo is LineCUndo) { // Changed a line LineCUndo luold = (LineCUndo)undo; Line lold = lineColl[luold.index]; lineColl[luold.index] = luold.line; luold.line = lold; dest.Push(luold); } listSSA.VirtualListSize = lineColl.Count; listSSA.EndUpdate(); menuUndo.Enabled = undoStack.Count != 0; menuRedo.Enabled = redoStack.Count != 0; } ExtractStyles(); }
private void menuRemoveLine_Click(object sender, System.EventArgs e) { if (lineColl != null && undoStack != null) { listSSA.BeginUpdate(); List<LineUndo> lul = new List<LineUndo>(); LineUndo lu; for (int index = lineColl.Count - 1; index != -1; index--) { if (lineColl[index].selected) { listSSA.VirtualListSize--; lu = new LineUndo(); lu.index = index; lu.line = lineColl[index]; lul.Add(lu); lineColl.RemoveAt(index); } } undoStack.Push(lul); menuUndo.Enabled = true; listSSA.EndUpdate(); } }