Hi,

First of all, my question:
I have an "RDF content tree" (ie generated from an RDF datasource, but
without the 'dont-build-content' flag. Is it possible to support UI
feedback when dragging things over the tree? (ie. horizontal insertion
bars between tree elements)

To show what I mean, I've implemented the DnD using the nsdraganddrop
wrapper as follows:
---
var treeObserver = { 
    getSupportedFlavours : function () { 
        var flavours = new FlavourSet(); 
        flavours.appendFlavour("text/x-moz-url"); 
        return flavours; 
    }, 
    
    onDragOver: function (evt,flavour,session) {
        session.canDrop=true;
    }, 

    onDrop: function (evt,dropdata,session) { 
        var tree = document.getElementById("UpdateTree");
        var col={};
        var row={};
        var child={};

        tree.treeBoxObject.getCellAt(evt.pageX, evt.pageY, row, col, child);

        split = dropdata.data.indexOf("\n");
        url = dropdata.data.substring(0, split);
        title = dropdata.data.substring(split);

        openNewDialogNoRefresh(title, url, row.value);
    } 
};
---

This works fine, but doesn't provide any feedback when an item is
dragged over the tree. 

So I tried a different approach, adding the dont-build-content flag, and
assigning the builder manually. I then added the following observer to
the builder:
---
var dragService =
Components.classes["@mozilla.org/widget/dragservice;1"].getService().QueryInterface(Components.interfaces.nsIDragService);

var treeBuilderObserver = {
  canDrop : function(idx, orient) { 
      if (orient == Components.interfaces.nsITreeView.DROP_ON)
          return false;
      else
          return true;
  },

  onDrop : function(index, orient) {
      data = getDragData("text/x-moz-url").data.split("\n");
      url = data[0];
      title = data[1];
      openNewDialogNoRefresh(title, url, index);
  },
};

function getDragData(flavour)
{
    var dragSession = dragService.getCurrentSession();
    if (!dragSession)
      return false;

    var trans =
    Components.classes["@mozilla.org/widget/transferable;1"].
                createInstance(Components.interfaces.nsITransferable);
    trans.addDataFlavor(flavour);
 
    var dataObj = new Object();
    var flavor = new Object();
    var len = new Object();
    for (var i = 0; i < dragSession.numDropItems; i++)
    {
        dragSession.getData(trans, i);
        trans.getAnyTransferData(flavor, dataObj, len);
        if (!dataObj)
            continue;

        return dataObj.value.QueryInterface(
               Components.interfaces.nsISupportsString);
    }
    return null;
}
---
This provided the UI feedback I was after (an insertion bar appears when
dragging something over the tree), but introduced other problems:

* The openNewDialogNoRefresh function brings up a dialog window, to
allow the user to edit the new item. This doesn't work when called from
the new observer callback function - the dialog isn't drawn correctly,
and doesn't respond to user input. I'm guessing I need to return
immediately from the builder callback.

* Other parts of my code rely on the content builder for getting the
currently selected item, etc. I should be able to work around this, but
results in many changes to my code

* I saw some strange behaviour, with elements of the tree changing
position randomly. Again, I can probably work around this, but it is
pretty weird!

So for these reasons (the first one in particular), I would like to use
the content builder and nsdraganddrop wrapper. Which takes me back to my
original question:

Is it possible to support UI feedback with a content builder? (I'm still
learning about how trees work in XUL, so any hints are appreciated!)

Thanks,
Pete

-- 
http://www.fastmail.fm - I mean, what is it about a decent email service?

_______________________________________________
Project_owners mailing list
[email protected]
http://mozdev.org/mailman/listinfo/project_owners

Reply via email to