【问题标题】:Drag and drop to desktop in LiveCode在 LiveCode 中拖放到桌面
【发布时间】:2020-07-10 23:55:25
【问题描述】:

我正在开发一个 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

【问题讨论】:

    标签: drag-and-drop livecode


    【解决方案1】:

    我认为您不是在进行真正的拖放操作,因为您实际上并没有将对象从应用程序拖到另一个应用程序(例如,从您的应用程序到 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
    

    【讨论】:

    • 我刚刚注意到保罗的回答。 ScreenMouseLoc 和 globalloc(the moueLoc) 给出相同的结果。
    【解决方案2】:

    您可以使用the screenMouseLoc 代替the mouseLoc

       set the loc of tTheNewStack to the screenMouseLoc
    

    数据库堆栈可能会跳转到新位置,因此以不可见的方式创建堆栈然后在脚本末尾将可见设置为 true 可以避免这种情况。

    【讨论】:

      【解决方案3】:

      我希望这段代码可以帮助您完成扩展。 我正在做的是创建一个堆栈,我将拖动的图像作为背景。类似于 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
      

      【讨论】:

        猜你喜欢
        • 2011-08-16
        • 1970-01-01
        • 2011-03-03
        • 1970-01-01
        • 2023-03-23
        • 1970-01-01
        • 1970-01-01
        • 2016-05-22
        • 2019-12-01
        相关资源
        最近更新 更多