PDA

View Full Version : dragData in onDragStart() returning true/false/nil



celestian
February 14th, 2020, 05:01
Discussion came up on the discord channel and it was mentioned that one could "edit" the drag data instead of having to fill in the rest (and keep what would normally be there). I tested myself and was unable to get this to work and Moon requested I post it here for later discussions.




<template name="link_audiostop">
<linkcontrol name="audioshortcut">
<script>
function onDragStart(button, x, y, draginfo)
local node = window.getDatabaseNode();
draginfo.setDescription(DB.getValue(node,"name","") .. " [stop]");
return nil;
end
</script>
<class>urlaudiostop</class>
<icon normal="link_audio" pressed="link_audio_down" empty="button_link_empty" />
</linkcontrol>
</template>


I couldn't get the "nil" return value to change the description using the above method. This is what I have that is working for now. This fills in ALL the data since the datainfo value is empty on start.




<template name="link_audiostop">
<linkcontrol name="audioshortcut">
<script>
function onDragStart(button, x, y, draginfo)
local node = window.getDatabaseNode();
draginfo.setDescription(DB.getValue(node,"name","") .. " [stop]");
draginfo.setShortcutData("urlaudiostop",node.getPath())
draginfo.setIcon("link_audio");
draginfo.setType("shortcut");
return true;
end
</script>
<class>urlaudiostop</class>
<icon normal="link_audio" pressed="link_audio_down" empty="button_link_empty" />
</linkcontrol>
</template>

Moon Wizard
February 14th, 2020, 17:50
Just looked at the code. The drag object for default behavior is not created until after scripts are completed. The one passed to onDragStart/onDrag scripts is a "temp" drag object that is only used if you return true/false. So, you'll have to use the full override.

Regards,
JPG