PDA

View Full Version : Double onDrop event in nested windowlist



psicodelix
July 27th, 2011, 10:21
Hi,

I have a windowlist wich item class has another windowlist (nested). Each windowlist accepts different drop classes, and the only handler for onDrop events is on the main windowlist. When I drop a main object into the list the handler works fine and the list creates a main item. However when I drop a secondary object the onDrop event fires twice, and 2 secondary items are created. That's the source code of the event:



function onDrop(x, y, draginfo)

if draginfo.isType("shortcut") then

-- POWER
if draginfo.getShortcutData() == "referencepower" then
local sourcenode = draginfo.getDatabaseNode();

local newwin = NodeManager.createSafeWindow(self);
if newwin then
local newname = sourcenode.getChild("name").getValue();
local newvalue = sourcenode.getChild("action").getValue() .. ', ' .. sourcenode.getChild("descriptor").getValue();
newwin.name.setValue(newname);
newwin.value.setValue(newvalue);
newwin.shortcut.setValue(draginfo.getShortcutData( ));
end

return true;
end

-- FEAT
if draginfo.getShortcutData() == "referencefeat" then


local droptarget = getWindowAt(x, y);
if droptarget then
local sourcenode = draginfo.getDatabaseNode();

-- Create new entry based on entry in another level
local newwin = NodeManager.createSafeWindow(droptarget.powerfeats list);
if newwin then
newwin.name.setValue(sourcenode.getChild("name").getValue());
newwin.value.setValue(sourcenode.getChild("summary").getValue());
newwin.shortcut.setValue(draginfo.getShortcutData( ));
end
end

end
end
end


Any idea?

thank you very much.

Sorcerer
July 27th, 2011, 10:29
Do you also have an <acceptdrop> in the windowlist?

you have not returned true for the second list, so FG will assume a return of nil, which would normally tell it to fire up the acceptdrop event if it is present. which would result in a second window (of whatever class is in the acceptdrop) being created.

psicodelix
July 27th, 2011, 10:57
Ok, I forget the return true in the second block.

Thank you very much Sorcerer.