Dynamic menu construction

Topics: CAB & Smart Client Software Factory
Feb 25, 2006 at 2:19 PM
originally posted by: aras03k

Hi everybody,

I have a small issue which I thought I might share with this great group of people :)

First a quick briefing on my app:
In my CAB application, which consists of the shell, a smartpart asembly with all my smartparts and a series of modules which I plan on making completely independant on each other (and the shell of course). The modules will each implement a series of workitems and any work items that are reused across modules are put into a common class library assembly. When the ModuleLoaderService loads my modules i will add its work items to the rootworkitem through the moduleinit extended class. Once loaded, any workitems wired up to the menu never gets terminated. Workitems not wired up or work items that act as "child workitems" will be terminated upon end of use. The number of work items will be rather large. This is an enterprise level app.

My idea is that the work items themselves will be injected with a menu constructing service from the shell. This menu service will hold a tree like collection of menu objects and each time a work item is loaded it calls the menu service telling it which menu item to add, the Command ID and from what module it came. (there may be other info like if the menu item is checked or not or has an image icon). The menu service will read an XML configuration file where the structure of the menu is described. By structure i mean in what order should the menu items be displayed. The menu service will not draw the menu before the collection is complete and all work items are loaded.

My problem is how do I tie the information in the XML to the to actual menu requests from my work items? I guess one way would be to hardcode the Command ID's into the XML file and then catch them as my work items calls the service and put them in the correct order in my menu collection. (and eventually registering the command with the menu items)

Would there be better ways going about this? Is loading all my workitems into the root workitem on startup a bad practice? I will be performing cleanups on my smartparts during runtime so it will mostly only be the active workitem that will hold smartparts in memory.

Any insight will be appreciated,
Feb 28, 2006 at 5:16 AM
originally posted by: DLorenz

The way I did this was to just have one workitem at the base. After all the modules are loaded, I raise an event on the "MainMenuWorkItem" that all the ModuleInits can hear. This causes each init that is available to register any starting points into the MainMenu. It sends a class with enough information to dynamically create a menuitem and also manually fire an eventpublication that the init will hear on the click event of the menuitem. Then you can run the entry point off of the sender, which will be the MainMenuWorkItem. I use this in place of Commands.