Are We There Yet?


Not quite. We know there is a problem with an Undo that tries to Undo too much. We know how to fix it: we ll just check whether the stack is empty, and if it isn t, we ll do nothing. But we need a test ”let s add one more *undo to the undo.test file:

 *enter 
*type abc
*output
<P>abc</P>
*end
*undo
*output
<P>ab</P>
*end
*undo
*output
<P>a</P>
*end
*undo
*output
<P></P>
*end
*undo
*output

*end *undo *output *end

This fails, predictably, with the message Stack Empty . Now we can add the feature:

 public void Restore() { 
if (SavedModels.Count == 0) return;
TextModel savedModel = (TextModel) SavedModels.Pop();
lines = savedModel.Lines;
selectionStart = savedModel.SelectionStart;
}

The tests all run. I believe that functionality is now complete. Let s reflect. In the next chapter ”Chapter 29, The Final Optimized Undo ”we ll turn our attention to efficiency.




Extreme Programming Adventures in C#
Javaв„ў EE 5 Tutorial, The (3rd Edition)
ISBN: 735619492
EAN: 2147483647
Year: 2006
Pages: 291

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net