Fix bug # 46710: get d&d working for file/ftp listings. r=pinkerton

This commit is contained in:
rjc%netscape.com 2000-07-28 00:22:07 +00:00
Родитель 2849d98e2b
Коммит 889d7bacb8
3 изменённых файлов: 160 добавлений и 29 удалений

Просмотреть файл

@ -275,6 +275,7 @@ function DropOnTree ( event )
Components.classes["component://netscape/widget/transferable"].createInstance(Components.interfaces.nsITransferable);
if ( !trans ) return(false);
trans.addDataFlavor("moz/rdfitem");
trans.addDataFlavor("text/x-moz-url");
trans.addDataFlavor("text/unicode");
var typeRes = RDF.GetResource(RDF_NS + "type");
@ -297,32 +298,63 @@ function DropOnTree ( event )
var sourceID = null;
var parentID = null;
var checkNameHack = false;
var name=null;
if (bestFlavor.value == "moz/rdfitem")
{
// pull the URL out of the data object
var data = dataObj.data.substring(0, len.value / 2);;
var data = dataObj.data.substring(0, len.value / 2);
// moz/rdfitem allows parent ID specified on next line; check for it
var cr = data.indexOf("\n");
if (cr >= 0)
{
sourceID = data.substr(0, cr);
parentID = data.substr(cr+1);
}
else
{
sourceID = data;
}
}
else
else if (bestFlavor.value == "text/x-moz-url")
{
// pull the URL out of the data object
var data = dataObj.data.substring(0, len.value / 2);
sourceID = data;
// we may need to synthesize a name (just use the URL)
checkNameHack = true;
}
else if (bestFlavor.value == "text/unicode")
{
sourceID = dataObj.data;
// XXX for the moment, if its a text/unicode drop
// we may need to synthesize a name (just use the URL)
checkNameHack = true;
// we may need to synthesize a name (just use the URL)
checkNameHack = true;
}
else
{
// unknown flavor, skip
continue;
}
// pull the (optional) name out of the URL
var space = sourceID.indexOf(" ");
if (space >= 0)
{
name = sourceID.substr(space+1);
sourceID = sourceID.substr(0, space);
}
dump(" Node #" + i + ": drop '" + sourceID + "'\n");
dump(" from container '" + parentID + "'\n");
dump(" action = '" + dropAction + "'\n");
dump(" target = '" + targetID + "'\n");
if (name)
{
dump(" name = '" + name + "'\n");
}
var sourceNode = RDF.GetResource(sourceID, true);
if (!sourceNode) continue;
@ -392,37 +424,42 @@ function DropOnTree ( event )
dirty = true;
}
if (checkNameHack == true)
if ((checkNameHack == true) || (name != null))
{
// XXX for the moment, if its a text/unicode drop
// we may need to synthesize a name (just use the URL)
var srcArc = RDF.GetResource(sourceID, true);
var propArc = RDF.GetResource(NC_NS + "Name", true);
if (srcArc && propArc && Bookmarks)
{
var targetArc = Bookmarks.GetTarget(srcArc, propArc, true);
if (!targetArc)
{
var defaultNameArc = RDF.GetLiteral(sourceID);
if (defaultNameArc)
{
Bookmarks.Assert(srcArc, propArc, defaultNameArc, true);
}
}
}
var srcArc = RDF.GetResource(sourceID, true);
var propArc = RDF.GetResource(NC_NS + "Name", true);
if (srcArc && propArc && Bookmarks)
{
var targetArc = Bookmarks.GetTarget(srcArc, propArc, true);
if (!targetArc)
{
// if no name, fallback to using the URL as the name
var defaultNameArc = RDF.GetLiteral((name != null && name != "") ? name : sourceID);
if (defaultNameArc)
{
Bookmarks.Assert(srcArc, propArc, defaultNameArc, true);
}
}
}
}
}
// should we move the node? (i.e. take it out of the source container?)
if ((parentNode != null) && (containerNode != parentNode))
{
RDFC.Init(Bookmarks, parentNode);
var nodeIndex = RDFC.IndexOf(sourceNode);
try
{
RDFC.Init(Bookmarks, parentNode);
var nodeIndex = RDFC.IndexOf(sourceNode);
if (nodeIndex >= 1)
{
RDFC.RemoveElementAt(nodeIndex, true, sourceNode);
}
if (nodeIndex >= 1)
{
RDFC.RemoveElementAt(nodeIndex, true, sourceNode);
}
}
catch(ex)
{
}
}
if (dirty == true)

Просмотреть файл

@ -179,3 +179,95 @@ function doSort(sortColName)
}
return(false);
}
var NC_NS = "http://home.netscape.com/NC-rdf#";
function BeginDragTree ( event )
{
var tree = document.getElementById("tree");
if ( event.target == tree )
return(true); // continue propagating the event
var database = tree.database;
if (!database) return(false);
var RDF =
Components.classes["component://netscape/rdf/rdf-service"].getService(Components.interfaces.nsIRDFService);
if (!RDF) return(false);
var dragStarted = false;
var trans =
Components.classes["component://netscape/widget/transferable"].createInstance(Components.interfaces.nsITransferable);
if ( !trans ) return(false);
var genData =
Components.classes["component://netscape/supports-wstring"].createInstance(Components.interfaces.nsISupportsWString);
if (!genData) return(false);
var genDataURL =
Components.classes["component://netscape/supports-wstring"].createInstance(Components.interfaces.nsISupportsWString);
if (!genDataURL) return(false);
trans.addDataFlavor("text/unicode");
trans.addDataFlavor("moz/rdfitem");
// ref/id (url) is on the <treeitem> which is two levels above the <treecell> which is
// the target of the event.
var id = event.target.parentNode.parentNode.getAttribute("ref");
if (!id || id=="")
{
id = event.target.parentNode.parentNode.getAttribute("id");
}
var parentID = event.target.parentNode.parentNode.parentNode.parentNode.getAttribute("ref");
if (!parentID || parentID == "")
{
parentID = event.target.parentNode.parentNode.parentNode.parentNode.getAttribute("id");
}
// if we can get node's name, append (space) name to url
var src = RDF.GetResource(id, true);
var prop = RDF.GetResource(NC_NS + "Name", true);
var target = database.GetTarget(src, prop, true);
if (target) target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
if (target) target = target.Value;
if (target && (target != ""))
{
id = id + " " + target;
}
var trueID = id;
if (parentID != null)
{
trueID += "\n" + parentID;
}
genData.data = trueID;
genDataURL.data = id;
trans.setTransferData ( "moz/rdfitem", genData, genData.data.length * 2); // double byte data
trans.setTransferData ( "text/unicode", genDataURL, genDataURL.data.length * 2); // double byte data
var transArray =
Components.classes["component://netscape/supports-array"].createInstance(Components.interfaces.nsISupportsArray);
if ( !transArray ) return(false);
// put it into the transferable as an |nsISupports|
var genTrans = trans.QueryInterface(Components.interfaces.nsISupports);
transArray.AppendElement(genTrans);
var dragService =
Components.classes["component://netscape/widget/dragservice"].getService(Components.interfaces.nsIDragService);
if ( !dragService ) return(false);
var nsIDragService = Components.interfaces.nsIDragService;
dragService.invokeDragSession ( event.target, transArray, null, nsIDragService.DRAGDROP_ACTION_COPY +
nsIDragService.DRAGDROP_ACTION_MOVE );
dragStarted = true;
return(!dragStarted);
}

Просмотреть файл

@ -36,7 +36,9 @@
<script src="chrome://communicator/content/directory/directory.js"></script>
<tree id="tree" datasources="rdf:files rdf:httpindex" flex="1" style="height:0px;" container="true" open="true" >
<tree id="tree" datasources="rdf:files rdf:httpindex" flex="1" style="height:0px;"
container="true" open="true"
ondraggesture="return BeginDragTree(event);">
<template>
<treechildren flex="1">
<treeitem uri="..." persist="open"