I'm sorry, but I think I'm missing something here
First : instead of numbers to identify your types, you could go with explicit type names, it would be more readable.
Then, resetting data in a dialog, IMHO, is very specific to each dialog.
If we take a checkbox : sometimes you'll want it checked by default, sometimes unchecked.
If we take a combo box : sometimes, you'll want it empty, sometimes you'll want to have it populated with relevant values according to what your script does. And if there are multiple combos, each one will have to be populated with different things (and clearing it empty before populating is one easy step in that process).
edits : sometimes empty, sometimes with a default value.
I'll stop here, I think you get the point.
Whenever I have some dialog in a script, I do have some kind of InitDialog
(or ResetDialog
) that makes it in the proper state according to what has to be done, and I find it much easier to do based on the control names which are speaking to me when I do it, rather than based on the control type (I've made quite a few dialogs now, and never had to rely on the control type : acting with knowledge on every control by using its name is really all is needed).
That Init or Reset function might even take a parameter so that the global state can be altered afterwards upon some user interaction (and then either clear or populate differently some controls).
Anyway, if you really want something "generic", one thing you could do, but I do not advise it, is to make a function that goes and read the .js
file to parse the xml dialogs description at the end, and that makes :
- A map
DialogControls
: for each dialog name it associates another map
- For each dialog control, that map will associate "control name" and "control type" which are both attributes of the xml.
Then you could call your generic Reset function with the first map as a parameter.
Yet, honestly, I think in practical use afterwards, you'll execute your reset function only to then go and initialize properly with meaningful values your different controls, leading to extra code, not helping the readability of the code, and getting extra unneeded execution steps.
Last idea : use proper and consistent naming of your controls : every combo box has a name like "combo_xxx" (or "cb_xxx"), every edit is "edit_xxx" (or (e_xxx). I try and do that oftentimes to help knowing the type of the controls I manipulate in the code. If you apply that with rigor (as every developer should ), then getting the type of the control is just as simple as parsing the beginning of the name of the control (which I would prefer to the xml parsing aforementioned).