The Plan


When code gets repetitive in this way, with lines that are similar except for the data they contain, it s a good idea to factor out the data. The code is calling for a table of data and a loop, instead of repeated blocks of very similar code. That s the idea we re going to work on here. We ll try to produce a table of data that can be used to define the menu strings and the insert and skip tags, all in one place. Then we ll process the table to produce the menus. We ll put the menus in an array or a list so that we can search them easily for accelerators. And we ll try to eliminate the InsertStrings() and SkipStrings() methods entirely. Here s a sketch of the kind of data I m envisioning, not in any language, just to look at:

 Insert &Pre, { "<pre></pre>" }, { "<pre>" } 
Insert &OL, {"<OL>","<LI></LI>","</OL>"}, { "<OL>", "<LI>" }
...

I m envisioning some kind of structure with the menu string and the tag string arrays in it. We would attach that structure to the NotepadMenuItem instead of the current command object. I figure that if I can do this in a couple of hours, it ll be worth it. Let s see.




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