0

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?

I've successfully implemented drag'n drop file from folder to XUL tree as per MDN example, now I need a reverse process.

Thank you

vanowm
  • 9,466
  • 2
  • 21
  • 37

1 Answers1

0

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. 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?

vanowm
  • 9,466
  • 2
  • 21
  • 37