2015-03-13 2 views
0

Я работаю над расширением IDE. Одна из первых вещей, которые мне нужно сделать, это перетащить значок из моей новой панели инструментов на в открытое пространство и создать стек при выпуске.Перетаскивание на рабочий стол в LiveCode

Это код, который у меня есть до сих пор. Проблема в том, что когда я отбрасываю перетаскивание, он выталкивает мышь обратно в исходную позицию и создает там, а не в конечной позиции. Я подозреваю, что это потому, что я не перетаскиваю объект назначения , так как я пытаюсь создать новый стек. Как я могу получить точку высвобождения, когда она не находится над объектом 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 

ответ

0

Вы можете использовать the screenMouseLoc вместо the mouseLoc.

set the loc of tTheNewStack to the screenMouseLoc 

стек DB может перейти на новое место, создавая таким образом стек незримо затем установить видимую истину в конце сценария будет избежать этого.

0

Я не думаю, что вы делаете настоящий перетаскивание, так как вы не перетаскиваете объект из приложения в другое приложение (например, из вашего приложения в Finder или Windows Explorer). Поэтому вы можете использовать другой подход без перетаскивания.

Следующий способ создает стопку держателя места. Вы можете изменить сценарий, чтобы не удалять стек держателя места и не изменять его свойства. Я решил удалить стек держателя места, а затем запустить скрипт.

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 
+0

Я только что заметил ответ Павла. ScreenMouseLoc и globalloc (moueLoc) дают тот же результат. – Mark

Смежные вопросы