Drag and drop to desktop

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!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Cyberqat
Posts: 24
Joined: Thu Jun 10, 2010 5:38 pm

Drag and drop to desktop

Post by Cyberqat » Fri Mar 13, 2015 10:04 pm

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?

Code: Select all

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 "&quote&"DatabaseLibrary.livecode"&quote&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

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Drag and drop to desktop

Post by Klaus » Sat Mar 14, 2015 1:29 am

Hi Cyberquat,

unfortunately we have no control nor do we know where the user may drop anything OUTSIDE of Livecode! :(

Hint: This
...
put "command onPreOpenStack"&cr after tScript
...
should read:
...
put "on PreOpenStack"& cr after tScript
...

Best

Klaus

Cyberqat
Posts: 24
Joined: Thu Jun 10, 2010 5:38 pm

Re: Drag and drop to desktop

Post by Cyberqat » Sat Mar 14, 2015 3:25 am

Thanks Klaus.

I guess the idea creates new stacks from the menu. So I need to do something similar.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Drag and drop to desktop

Post by Klaus » Sat Mar 14, 2015 1:01 pm

Hi Cyberqat,

are you adventurous and don't mind using a quite complex and strange workaround? :D

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! :D


Best

Klaus

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Drag and drop to desktop

Post by FourthWorld » Sat Mar 14, 2015 3:30 pm

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:

Code: Select all

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Drag and drop to desktop

Post by dunbarx » Sat Mar 14, 2015 4:33 pm

Hi.

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.

Craig Newman

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Drag and drop to desktop

Post by Klaus » Sun Mar 15, 2015 2:29 pm

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! :D

Cyberqat
Posts: 24
Joined: Thu Jun 10, 2010 5:38 pm

Re: Drag and drop to desktop

Post by Cyberqat » Sun Mar 22, 2015 10:40 pm

Clever solution. Thanks guys!

Post Reply