简体   繁体   English

将树项目作为文件拖放到文件夹中?

[英]Drag'n drop tree items as files to a folder?

Is there a way start dragging items from a XUL tree into a folder and when dropped, create a file with data from these items? 有没有一种方法可以将项目从XUL树拖到文件夹中,并在拖放时使用这些项目中的数据创建文件?

I've successfully implemented drag'n drop file from folder to XUL tree as per MDN example, now I need a reverse process. 根据MDN示例,我已经成功实现了从文件夹到XUL树的拖放文件,现在我需要一个反向过程。

Thank you 谢谢

I found a solution, but it has a little side effect - I can't find a way to get notification when user released the mouse button, therefore a file(s) with data from the tree must be created during initialization of dragstart event in a temp directory, which will be moved to the dropped to folder when user released mouse button. 我找到了一个解决方案,但是有一点副作用-当用户释放鼠标按钮时,我找不到一种通知的方法,因此,在初始化dragstart事件期间必须创建一个包含树中数据的文件。临时目录,当用户释放鼠标按钮时,该目录将移动到放置的文件夹中。 Example: 例:

//event listener must be added to <treechildren> element
document.getElementById("myTreeChildren").addEventListener("dragstart", treeDragStart, true);
function    treeDragStart(e)
{
var nsIFile = FileUtils.getFile("TmpD", ["myfilename.txt"], true),
        fos = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream),
        content = "this is an example text";
// flags: PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE
fos.init(nsIFile, 0x04 | 0x08 | 0x20, 0600, 0);
written = fos.write(content, content.length);
if (fos instanceof Ci.nsISafeOutputStream)
    fos.finish();
else
    fos.close();

e.dataTransfer.effectAllowed = "move";
e.dataTransfer.mozSetDataAt("application/x-moz-file", nsIFile, 0);
}//treeDragStart()

Does somebody know if there is a way get notification when drop occur from outside of the application? 有人知道从应用程序外部发生删除时是否有办法获取通知?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM