This might be almost enough for now. Weve shown that we can get rid of the beep, and weve learned a little bit about menus . Our Insert Section Tags story is working fine. There are, however, some things to worry about:
Looking at that MenuInsertSection, we can see that theres some code duplication coming. Every one of the commands we send will have to read the TextBox into the TextModel, execute the model, and then read the model back into the TextBox. Well have to deal with thatbut not until it happens.
We dont have decent testing of the GUI. This all started when we implemented the section logic in the model and tested it but forgot to put any way to access it into the GUI. So we need to be on the alert to improve that testing.
I just noticed that my references to the textbox in the constructor dont start with this., while the ones generated by Windows do. Those need to be consistent. Ill change them all to use this. because although the textbox variable is local to this class, the other things being referenced are in the superclass and without the this., it wouldnt be clear what was going on. This could be wrong; well find out as time goes on.
Now lets review our predictions from above.
The menu code isnt long yet, but we can see that its going to take a lot of words to say very little. Its not very difficult, though, as I had hoped.
We moved the code to the handler and removed the duplication at the same time. A little use of foresight, but not too much, I feel. What would have happened had I not removed it? I suspect it would have inserted the section tags twice. Anyway, we dodged that bullet.
The code did get removed from the keyboard handler.
The code is a tiny bit nicer, I think. The function is a bit more clear, because the menu handler is more explicit and doesnt confuse the AltS and InsertSectionTags notions. Just a small improvement, but I think a real one.
We havent seen duplication across menu items yet, but it seems clear that each one is going to look much like the previous ones. Well keep watching for this, and if it crops up as we expect, well deal with it.
So this time, most of the predictions came true. Overall, my prediction record isnt quite that good; thats why I dont make many predictions.