I need help from the gurus to get past first base with the new dialog listbox. The following simple test code and associated resources are as far as I have got. When I run the code, the dialog pops up thus:
When I click item two:
The trace output is:
msg.event = selchange
ctl = lb1
label = undefined
How do I access the value/label of the item I clicked?
Once I get to grips with this, my next question will be how to pre-populate the list box before showing it for the first time. My test code has hard coded values of one, two, three, four in the resources. What I'd like to do is populate dynamically at run time.
Regards, AB
function OnClick(clickData)
{
DOpus.ClearOutput();
var dlg, ctl, i, max, str;
dlg = DOpus.dlg;
dlg.window = clickData.func.sourcetab;
dlg.template = "dlg1";
dlg.detach = true;
dlg.show;
i = 0; max = 3;
do
{
msg = dlg.getmsg();
ctl = msg.control;
DOpus.output("msg.event = " + msg.event);
DOpus.output("ctl = " + ctl);
if (msg.event=="selchange") DOpus.output("label = " + ctl.label);
i++;
}
while (i<max); // For safety while testing!
}
The current selection could be in Dlg.Control(ctl.name).value since beta5, or it is in .index or selectedIndex, don't know what Jon decided on. How to create listitems could be described in the updated release notes. Dlg.Control("lb1").AddItem(label, value) should work, as should something like Dlg.Control("lb1").AddItem( ..CreateNewListItem(label, value) ), but I'd need to seek through the release notes pdf here as well to tell for sure.
PrePostEdit:
New API does not seem to be described in the release notes pdf yet, so maybe wait for the devs to tell you. o)
Thanks @tbone and @jon for your assistance. I have updated the test code as follows and now need to understand how to get the value (e.g. three) of the selected item via the listbox control object. When I execute the code and click on item 3, the output is as per the screen grab. Every method seems to return the item's index.
Regards, AB
function OnClick(clickData)
{
DOpus.ClearOutput();
var dlg, ctl_name, ctl_obj, msg_obj, i, n, max, str;
dlg = DOpus.dlg;
dlg.window = clickData.func.sourcetab;
dlg.template = "dlg1";
dlg.detach = true;
dlg.show;
i = 0; max = 3;
do
{
msg_obj = dlg.getmsg(); DOpus.output("msg_obj.event = " + msg_obj.event);
ctl_name = msg_obj.control; // The name of the control that was selected or clicked
ctl_obj = dlg.control(ctl_name); // This control object
if (msg_obj.event=="selchange")
{
DOpus.output("msg_obj.index = " + msg_obj.index);
DOpus.output("msg_obj.value = " + msg_obj.value);
n = ctl_obj.value; // For a list this is the item number
DOpus.output("ctl_obj.value = " + n);
str = ctl_obj.GetItemAt(n);
DOpus.output("ctl_obj.GetItemAt(n) = " + str);
str = ctl_obj.SelectItem(n);
DOpus.output("ctl_obj.SelectItem(n) = " + str);
}
i++;
}
while (i<max); // For safety while testing!
}
I have printed the relevant Detached Dialogs page from Opus 12 Changes.pdf and the script control's object interface description from the 12.0.5 (Beta) Release History. is there anywhere else I should be looking for more detailed documentation? (I understand a lot of this is WIP and am happy to wait if that's the most sensible course of action).
We haven't updated the PDF with the tbone-inspired changes yet but the help file is up-to-date, the examples have all been updated and the DialogListItem interface is described as well.
OK. Got it. I was looking under Scripting Reference --> Scripting Objects in the manual instead of the Script Objects section in the Directory Opus 12 specific reference. Smart boy wanted!