I have an application where I use a lot of hierarchical menuitems, each one has a text template associated with it. Everything is made at design time, so menuitems and text templates are constant. On the application, when choosing a menuitem, the relevant text template is inserted into a synedit control.
What would be a good approach to design this? My thinking is that inserting each menuitem through the IDE is cumbersome and not very friendly if I want to change/add/remove items, also, there are a lot of them..
For completeness, here is what I ended up doing (as a full answer):
- Created a text file with the templates of the text items to be inserted, in no particular order. I can add to this file without too much thinking about order and logic in presenting the menus later on.
- Wrote a python script that takes this raw file and creates a resource file, which is ordered with submenues and menuitems, on the lines of @Craig comment above. Optionally, it can create a D/LFM file to be loaded on compilation.
- Include the .res file and write a small function on startup to dynamically create the menus (or optionally just include the D/LFM file).
Edit
Recently I tried to compile this on linux, it didn’t work… and it seems too ‘windowy’ anyways. So here is the updated version:
- Same as 1 above.
- Wrote a python script which takes this file and builds a unit with a collection and many collectionitems corresponding to the text items. The unit also has a function to populate the collection at runtime and a function to build runtime menus using the collectionitems.
- When the program starts, first the collection is populated with all the collectionitems.
- Every time a new editor window is opened, the “Insert text” menu is built dynamically from the collection.
This algorithm works great on windows and linux, is clean and easy to implement, plus no messing with D/LFM files, it is pure code.