在LiveCode中拖放到桌面

时间:2015-03-13 21:38:18

标签: drag-and-drop livecode

我正在开发IDE扩展程序。我需要做的第一件事就是从我的新工具面板拖出一个图标 开放空间并在释放时创建一个堆栈。

这是我到目前为止的代码。问题是,当我释放拖动时,它会将鼠标弹回到开始位置 阻力并在那里创造,而不是在最终位置。我怀疑那是因为我没有拖到目标对象上 因为我正在尝试制作一个新的堆栈。如何在不超过LiveCode对象的情况下获取发布点?

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

3 个答案:

答案 0 :(得分:0)

您可以使用the screenMouseLoc代替the mouseLoc

   set the loc of tTheNewStack to the screenMouseLoc

数据库堆栈可能会跳转到新位置,因此无形地创建堆栈,然后在脚本结束时将visible设置为true将避免这种情况。

答案 1 :(得分:0)

我不认为您正在进行真正的拖放操作,因为您实际上并未将对象从应用程序拖动到另一个应用程序(例如,从您的应用程序拖动到Finder或Windows资源管理器) 。因此,您可以使用不同的方法,而无需拖放。

以下方法创建占位符堆栈。您可以将脚本更改为不删除占位符堆栈并调整其属性。我决定删除占位符堆栈然后运行你的脚本。

on mouseDown
     set the rect of the templateStack to 0,0,100,100
     set the decorations of the templateStack to "maximize,minimize,close"
     set the backgroundColor of the templateStack to gray
     set the blendLevel of the templateStack to 50
     set the vis of the templateStack to true
     set the name of the templateStack to "extPlace Holder"
     set the loc of the templateStack to globalloc(the mouseLoc)
     create stack
     reset the templateStack
     send "followMouse it" to me in 0 millisecs
end mouseDown

on followMouse theStack
     put the mouseLoc into myLoc
     if the mouse is down then
          set the loc of theStack to globalLoc(myLoc)
          send "followMouse theStack" to me in 20 millisecs
     end if
end followMouse

on mouseRelease
     put the mouseLoc into myLoc
     if there is a stack "extPlace Holder" then delete stack "extPlace Holder"
     createNewStack "New Database Stack","Default.sdb"
     /*
     if there is a stack "New Database Stack" then
          set the loc of stack "New Database Stack" to myLoc
     end if
     */
end mouseRelease

on mouseUp
     put the mouseLoc into myLoc
     if there is a stack "extPlace Holder" then delete stack "extPlace Holder"
end mouseUp

command createNewStack pNewStackName,pDBname
     put globalLoc(the mouseloc) into myLoc
     #create stack
     set the vis of the templateStack to false
     create stack pNewStackName
     put it into tTheNewStack
     set the loc of tTheNewStack to myLoc
     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
     show tTheNewStack
     reset the templateStack
end createNewStack

答案 2 :(得分:0)

我希望这段代码可以帮助您完成扩展。 我正在做的是创建一个堆栈,然后将拖动的图像作为背景。与LiveCode IDE的功能类似。

_deleteDragStack命令中的

重要查找调用CreateNewDBStack的位置并将参数pNewStackName pDBname传递给它。

local sDragStack
local sStackLoc

on mouseMove
   if the mouse is up then
      _deleteDragStack
      
   else if the mouse is down and there is not a sDragStack then
      local tTarget
      
      put the target into tTarget
      if word 1 of tTarget is "image" then
         set the destroyStack of templateStack to true
         set the windowShape of templateStack to (the id of tTarget)
         set the backgroundPattern of templateStack to (the id  of tTarget)
         set the blendLevel of templateStack to 100
         set the loc of templateStack to globalLoc(the mouseLoc)
         create stack
         put it into sDragStack
         reset templateStack
      end if
   else if there is sDragStack then
      
      put globalLoc( the mouseLoc) into sStackLoc
      set the loc of sDragStack to sStackLoc
      set the blendLevel of sDragStack to 25
   end if
   pass mouseMove
end mouseMove

on mouseUp
   if there is sDragStack then _deleteDragStack
end mouseUp

on mouseRelease
   if there is sDragStack then _deleteDragStack
end mouseRelease

private command _deleteDragStack
   if there is sDragStack then
      lock messages
      close sDragStack
      
      CreateNewDBStack "Untitled"&&(random(1000))---> pNewStackName, pDBname
      
      delete local sDragStack
      unlock messages
   end if
end _deleteDragStack

command CreateNewDBStack  pNewStackName, pDBname
   local tTheNewStack
   #create stack
   create stack pNewStackName
   put it into tTheNewStack
   set the loc of tTheNewStack to sStackLoc
   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