LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
Hi, I'm working on an IDE extension. One of the first things I need to be able to do is drag an icon from my new tool panel out to
the open space and create a stack when released.
This is the code I have so far. The problem is that, when I release the drag, it pops the mouse back to the start position of
the drag and creates there rather then at the end position. I suspect that is because I am not dragging onto a destination object
since I am trying to make a new stack. How can I get the release point when its not over a LiveCode object?
on mouseDown
set the dragData["text"] to empty
end mouseDown
on dragStart
set the dragImage to the id of the target
end dragStart
on dragEnd
CreateNewDBStack("New Databse Stack", "Default.sdb")
end dragEnd
command CreateNewDBStack pNewStackName, pDBname
#create stack
create stack pNewStackName
put it into tTheNewStack
set the loc of tTheNewStack to the mouseloc
set the DBPath of tTheNewStack to pDBName
#create DBscript on stack
local tScript
put "global gDBConnectionID"&cr into tScript
put "command onPreOpenStack"&cr after tScript
put " library stack ""e&"DatabaseLibrary.livecode""e&cr after tScript
put " put the DBPath of me into tDBPath"&cr after tScript
put " put databaseConnect(tDBPath) into gDBConnectionID" &cr after tScript
put "end onPreOpenStack" after tScript
set the script of tTheNewStack to tScript
end CreateNewDBStack
are you adventurous and don't mind using a quite complex and strange workaround?
I remember having solved a similar problem in a project a couple of years ago.
It was about dragging and dropping files from LC, but will surely work with a stack, too!
Sorry, I am about to leave for a gig with my rock band, so I will not have the time to search
for that stack on my hd and explain this before tomorrow. So stay tuned!
As Klaus noted, LC does not currently return the path of items dropped in the file manager of the host OS - I've submitted a request for that: http://quality.runrev.com/show_bug.cgi?id=8634
However, some experimentation allowed me to discover that if you write a file to tmp and then set the dragData["file"] to that path with a dragAction of "move", on OS X at least this will work:
on dragStart
set the dragaction to "move"
--
-- Create stack in temp:
put specialfolderpath("temporary") & "/sample.livecode" into tFile
put "DragThang"& the long seconds into tStackName
put the properties of the templateStack into tSaveTMPL
set the name of the templateStack to tStackName
lock messages
create invisible stack tStackName
reset the templateStack
--
-- Add payload object (put anything you want here):
copy me to stack tStackName
--
-- Save stack to temp:
set the filename of stack tStackName to tFile
close stack tStackName
set the visible of stack tStackName to true
set the destroyStack of stack tStackName to true
save stack tStackName
--
-- Let other programs know your drag action involves a file:
set the dragdata["files"] to tFile
end dragStart
I don't know if that will work on Windows, and unfortunately it doesn't work on Linux at this time because while the LiveCode Linux engine will read dragData["files"] for dropping into LiveCode objects a bug currently prevents us from setting it for external drops: http://quality.runrev.com/show_bug.cgi?id=10334
Richard Gaskin LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Why do you need to drag something to the desktop to create a new stack? Why cannot you simply create a new stack? Surely the location on screen of that stack ought not to matter.
FourthWorld wrote:However, some experimentation allowed me to discover that if you write a file to tmp and then set the dragData["file"] to that path with a dragAction of "move", on OS X at least this will work:...
That's exactly what I was going to write, and it also works on Windows!