I'm creating a test program in C#. (The final program will be in C++, but I'm more familiar with C#) Right now I'm just composing a general idea of how this program will be structured. This will be a menu
has a list of menuItems
has some menu Text
to display to the user, and an Action
which is what the program does if the user executes that menuItem
also keeps track of the currently selected menu item currentMenuItem
has list of MenuItems
maintains currentMenuItem (the menu item currently selected)
set currentMenuItem to the previous one
set currentMenuItem to the next one
run the method which is what this menu item does
property menu text
property menu action //run this if user executes this menu item
MenuItem(string menuText, thing to do) //CONSTRUCTOR
text = menuText;
action = thing to do
a Stack of Menus
Method PushMenu(Menu menu)
push this menu onto the stack
Method PopMenu(Menu menu)
pop top menu off the stack and return it
My question is how do I deal with storing the MenuItem Action? I'm thinking Delegates but don't quite have the syntax right.
Will I end up with a separate Delegate for each possible Action?
Perhaps a Lambda expression will work OK.
The Menu Item Action may be "go to submenu Xyzzy". So MenuItem will be referring to sub menu Xyzzy, and I start having tightly coupled code. How do I avoid tightly coupled code?
How will this work when I translate this to unmanaged C++ (which I'm not as familiar with the syntax)? Does unmanaged C++ just have pointers to functions, and you hope the pointer points correctly to the beginning of a function, because you're going to tell the computer to jump there and start executing what you hope is code?
Also I'd like to i18n
the menu Text so I'm not hard coding English into my code. Would like to make it flexible so the menu can be displayed in other languages.
The two methods I've seen use Dictionary lookups, either create an enum variable for each message string and look that up in the appropriate language dictionary (e.g. DoThis, DoThat, DoSomethingElse, becomes "Do This", "Do that", "Do something else"). The problem with this is you end up with numerous enum variables that are either cryptic or very long.
Or, I've also seen using English text as the key instead of enum variables (e.g. "Do this", "Do that", "Do something else" for English becomes "Do this", "Do that", "Do something else", and for French becomes a different set of strings.) Problem with this is if you want to change the English, you might change the code but forget to change the dictionary.
Not sure what a good way to go is for this i18n thing.