Dialogs in includes?

I suppose it is not possible to include a dialog definition in an include file? (I did a lilttle experiment by including a ==SCRIPT RESOURCES section at the end but it didn't seem to work - and frankly I didn't expect it to work).

The logic behind my question is that I have a tendency to use includes not only for specific tasks, but also include in it the logic to get data via a specific dialog, as all these things are specifically related to the same functionality. For instance for a download I need download functions but also a choice of download parameters, this requires a specific dialog. As it is today, I have to re-create or copy the dialog from other source code that uses it, because the dialog does not come with the include. Those functions in the include do of course receive the dialog object, which always has to be the same, or at least have the same name and identical named controls. The multiple copies of the dialog are technically and practically "overhead".

I also suppose this would not be a simple thing to do -- it would obviously require a "Dialog" section as a sub-branch of the include file, in the script editor, and some serious code changes to make it work.

Oh, wait: it works - at least partially. I think the first time I added accidentally some spaces where they don't belong.

The dialog is NOT visible in the editor, but I can see it in the include file (I already knew that) and it does not procuce errors. And now suddenly the dialog appears when I call up the dialog. But this is a dialog with a few tabs and the tabs do not yet appear. I need to investigate this further.

Was this even SUPPOSED to work?

One thing that should work (even though I never tested it), is to have the XML code in a variable and then use Script.LoadResources on that variable.

You loose the ability to edit your dialog in the UI Editor ... but if you've set up your dialog in some kind of sandbox script, then you can make it available like that in an include script: put the xml content in a variable of your include script, and call Script.LoadResources either from your main script, or from a function inside the include script (the later should work since everything you do in your include script is actually as if the code was pasted in the main script (never tested for the ==SCRIPT RESSOURCES part though)

Great. Thanks for the hint - but indeed ==SCRIPT RESOURCES seems to work, at first sight. And yes, indeed, some kind of sandbox project just for maintaining design changes in the dialog, which then have to be copied again to the include (or into your variable). You can even load all the includes in that "design project" and copy them directly there, I suppose (I'll test this - it may cause a conflict as the project then has essentially double dialogs that bear the same resource name).

Fortunately you can, in the editor, just do a CTRL-C on the dialog resource and then paste in any include file. Pretty neat. I suppose it was designed for this otherwise Opus wouldn't even look in the includes for any dialog declarations.

In fact, as I noticed while experimenting: you can just select the dialog resources code (the raw xml under ==SCRIPT RESOURCES) and paste it inside the Dialogs section of the project you're in. There you can adapt the design just as you do any dialog. Then just copy it again from there to the include file, replacing the old code (and delete the design version to avoid a resource name clash. It's kind of easy-peasy.