/*
 * Copyright (c) OutWit Technologies 2007-2017.
 * All rights reserved.
 */

/**
 * @fileOverview D&D stuff for the slideshow
 * @author 21
 * @version 0.8
 * @internal
 */

var dragObserver = {
  getSession : function() {
    var ds = Components.classes["@mozilla.org/widget/dragservice;1"]
        .getService(Components.interfaces.nsIDragService);
    return ds.getCurrentSession();
  },

  setData : function(someData) {
    var transferable = Components.classes["@mozilla.org/widget/transferable;1"]
        .createInstance(Components.interfaces.nsITransferable);
    transferable.addDataFlavor("text/unicode");

    var textWrapper = Components.classes["@mozilla.org/supports-string;1"]
        .createInstance(Components.interfaces.nsISupportsString);
    textWrapper.data = someData;

    transferable.setTransferData("text/unicode", textWrapper,
        textWrapper.data.length); // double byte data

    // create an array for our drag items, though we only have one this time
    var transferableArray = Components.classes["@mozilla.org/supports-array;1"]
        .createInstance(Components.interfaces.nsISupportsArray);
    transferable.QueryInterface(Components.interfaces.nsISupports);
    transferableArray.AppendElement(transferable);
    return transferableArray;
  },

  getSupportedFlavours : function() {
    var flavours = new FlavourSet();
    flavours.appendFlavour("text/unicode");
    return flavours;
  },

  onDragStart : function(aEvent, aDragData, aDragAction) {},
  onDragOver : function(aEvent, aFlavour, aDragSession) {},
  onDragEnter : function(aEvent, aFlavour, aDragSession) {},
  onDragExit : function(aEvent, aFlavour, aDragSession) {},

  onDrop : function(aEvent, aDragData, aDragSession) {
    try {
      if(aDragSession.sourceDocument.location.href.substr(0, 42) != "chrome://outwit-kernel/content/widgets/directory/") return;
      if( searchTreeCtrl.isCurrent('catch') ) return;
      var selection = gContainer.selection;

      var selected = [];
      for( item in selection){
        var node = selection[item];
        try {
          for (var i = 0; i < searchTreeCtrl.current.length; ++i)
            CategoryManager.getCategory( searchTreeCtrl.current[i] ).mark( node.mediaUrl );
        }
        catch(e){
          alert(e);
        }

        var theBean = {
          sourceUrl : node.sourceUrl,
          mediaUrl  : node.mediaUrl,
          docSize   : node.docSize,
          filename  : node.filename,
          lastModified  : node.lastModified,
        }
        coreKit.coreMessager.observe('CATCH', 1, 1, '', theBean);
      }
    } catch (e) {
      dump(e);
    }
  }
};

