This commit is contained in:
chanial%noos.fr 2002-09-13 00:13:03 +00:00
Родитель 567b892be0
Коммит dcbd264f88
3 изменённых файлов: 0 добавлений и 1664 удалений

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

@ -1,508 +0,0 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
This is the old bookmarks code, included here for the sake of the bookmarks sidebar panel,
which will be fixed to use my new code in .9. In the mean time, this file provides a
life line to various functionality.
*/
var NC_NS = "http://home.netscape.com/NC-rdf#";
var RDF_NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
function TopLevelDrag ( event )
{
return(true);
}
function BeginDragTree ( event )
{
//XXX we rely on a capturer to already have determined which item the mouse was over
//XXX and have set an attribute.
// if the click is on the tree proper, ignore it. We only care about clicks on items.
var tree = document.getElementById("bookmarksTree");
if ( event.target == tree || event.target.localName == "treechildren" )
return(true); // continue propagating the event
var childWithDatabase = tree;
if ( ! childWithDatabase )
return(false);
var dragStarted = false;
var trans =
Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
if ( !trans ) return(false);
var genData =
Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
if (!genData) return(false);
var genDataURL =
Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
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");
}
var trueID = id;
if (parentID != null)
{
trueID += "\n" + parentID;
}
genData.data = trueID;
genDataURL.data = id;
var database = childWithDatabase.database;
var rdf =
Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
if ((!rdf) || (!database)) { dump("CAN'T GET DATABASE\n"); return(false); }
// make sure its a bookmark, bookmark separator, or bookmark folder
var src = rdf.GetResource(id, true);
var prop = rdf.GetResource(RDF_NS + "type", true);
var target = database.GetTarget(src, prop, true);
if (target) target = target.QueryInterface(Components.interfaces.nsIRDFResource);
if (target) target = target.Value;
if ((!target) || (target == "")) {dump("BAD\n"); return(false);}
if ((target != NC_NS + "BookmarkSeparator") &&
(target != NC_NS + "Bookmark") &&
(target != NC_NS + "Folder")) return(false);
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["@mozilla.org/supports-array;1"].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["@mozilla.org/widget/dragservice;1"].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);
}
function DragOverTree ( event )
{
var validFlavor = false;
var dragSession = null;
var retVal = true;
var dragService =
Components.classes["@mozilla.org/widget/dragservice;1"].getService(Components.interfaces.nsIDragService);
if ( !dragService ) return(false);
dragSession = dragService.getCurrentSession();
if ( !dragSession ) return(false);
if ( dragSession.isDataFlavorSupported("moz/rdfitem") ) validFlavor = true;
else if ( dragSession.isDataFlavorSupported("text/unicode") ) validFlavor = true;
//XXX other flavors here...
// touch the attribute on the rowgroup to trigger the repaint with the drop feedback.
if ( validFlavor )
{
var treeRoot = document.getElementById("bookmarksTree");
if (!treeRoot) return(false);
var treeDatabase = treeRoot.database;
if (!treeDatabase) return(false);
//XXX this is really slow and likes to refresh N times per second.
var rowGroup = event.target.parentNode.parentNode;
var sortActive = treeRoot.getAttribute("sortActive");
if (sortActive == "true")
rowGroup.setAttribute ( "dd-triggerrepaintsorted", 0 );
else
rowGroup.setAttribute ( "dd-triggerrepaint", 0 );
dragSession.canDrop = true;
// necessary??
retVal = false;
}
return(retVal);
}
function DropOnTree ( event )
{
var treeRoot = document.getElementById("bookmarksTree");
if (!treeRoot) return(false);
var treeDatabase = treeRoot.database;
if (!treeDatabase) return(false);
// for beta1, don't allow D&D if sorting is active
var sortActive = treeRoot.getAttribute("sortActive");
if (sortActive == "true")
{
dump("Sorry, drag&drop is currently disabled when sorting is active.\n");
return(false);
}
var RDF =
Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
if (!RDF) return(false);
var RDFC =
Components.classes["@mozilla.org/rdf/container;1"].getService(Components.interfaces.nsIRDFContainer);
if (!RDFC) return(false);
var Bookmarks = RDF.GetDataSource("rdf:bookmarks");
if (!Bookmarks) return(false);
// target is the <treecell>, and "ref/id" is on the <treeitem> two levels above
var treeItem = event.target.parentNode.parentNode;
if (!treeItem) return(false);
// get drop hint attributes
var dropBefore = treeItem.getAttribute("dd-droplocation");
var dropOn = treeItem.getAttribute("dd-dropon");
// calculate drop action
var dropAction;
if (dropBefore == "true") dropAction = "before";
else if (dropOn == "true") dropAction = "on";
else dropAction = "after";
// calculate parent container node
var containerItem = treeItem;
if (dropAction != "on")
{
containerItem = treeItem.parentNode.parentNode;
}
// magical fix for bug # 33546: handle dropping after open container
if (treeItem.getAttribute("container") == "true")
{
if (treeItem.getAttribute("open") == "true")
{
if (dropAction == "after")
{
dropAction = "before";
containerItem = treeItem;
// find <treechildren>, drop before first child
var treeChildren = treeItem;
treeItem = null;
for (var x = 0; x < treeChildren.childNodes.length; x++)
{
if (treeChildren.childNodes[x].tagName == "treechildren")
{
treeItem = treeChildren.childNodes[x].childNodes[0];
break;
}
}
if (!treeItem)
{
dropAction = "on";
containerItem = treeItem.parentNode.parentNode;
}
}
}
}
var targetID = getAbsoluteID("bookmarksTree", treeItem);
if (!targetID) return(false);
var targetNode = RDF.GetResource(targetID, true);
if (!targetNode) return(false);
var containerID = getAbsoluteID("bookmarksTree", containerItem);
if (!containerID) return(false);
var containerNode = RDF.GetResource(containerID);
if (!containerNode) return(false);
var dragService =
Components.classes["@mozilla.org/widget/dragservice;1"].getService(Components.interfaces.nsIDragService);
if ( !dragService ) return(false);
var dragSession = dragService.getCurrentSession();
if ( !dragSession ) return(false);
var trans =
Components.classes["@mozilla.org/widget/transferable;1"].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");
if (!typeRes) return false;
var bmTypeRes = RDF.GetResource(NC_NS + "Bookmark");
if (!bmTypeRes) return false;
var dirty = false;
for ( var i = 0; i < dragSession.numDropItems; ++i )
{
dragSession.getData ( trans, i );
var dataObj = new Object();
var bestFlavor = new Object();
var len = new Object();
trans.getAnyTransferData ( bestFlavor, dataObj, len );
if ( dataObj ) dataObj = dataObj.value.QueryInterface(Components.interfaces.nsISupportsString);
if ( !dataObj ) continue;
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);
// 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 if (bestFlavor.value == "text/x-moz-url")
{
// pull the URL out of the data object
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;
// 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 separator = sourceID.indexOf("\n");
if (separator >= 0)
{
name = sourceID.substr(separator+1);
sourceID = sourceID.substr(0, separator);
}
var sourceNode = RDF.GetResource(sourceID, true);
if (!sourceNode) continue;
var parentNode = null;
if (parentID != null)
{
parentNode = RDF.GetResource(parentID, true);
}
// Prevent dropping of a node before, after, or on itself
if (sourceNode == targetNode) continue;
// Prevent dropping of a node onto its parent container
if ((dropAction == "on") && (containerID) && (containerID == parentID)) continue;
RDFC.Init(Bookmarks, containerNode);
// make sure appropriate bookmark type is set
var bmTypeNode = Bookmarks.GetTarget( sourceNode, typeRes, true );
if (!bmTypeNode)
{
// set default bookmark type
Bookmarks.Assert(sourceNode, typeRes, bmTypeRes, true);
}
if ((dropAction == "before") || (dropAction == "after"))
{
// drop before or after
var nodeIndex;
nodeIndex = RDFC.IndexOf(sourceNode);
if (nodeIndex >= 1)
{
// moving a node around inside of the container
// so remove, then re-add the node
RDFC.RemoveElementAt(nodeIndex, true, sourceNode);
}
nodeIndex = RDFC.IndexOf(targetNode);
if (nodeIndex < 1) return(false);
if (dropAction == "after") ++nodeIndex;
RDFC.InsertElementAt(sourceNode, nodeIndex, true);
// select the newly added node
if (parentID)
{
selectDroppedItems(treeRoot, containerID, sourceID);
}
dirty = true;
}
else
{
// drop on
RDFC.AppendElement(sourceNode);
// select the newly added node
if (parentID)
{
selectDroppedItems(treeRoot, containerID, sourceID);
}
dirty = true;
}
if ((checkNameHack == true) || (name != null))
{
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))
{
try
{
RDFC.Init(Bookmarks, parentNode);
nodeIndex = RDFC.IndexOf(sourceNode);
if (nodeIndex >= 1)
{
RDFC.RemoveElementAt(nodeIndex, true, sourceNode);
}
}
catch(ex)
{
}
}
if (dirty == true)
{
var remote = Bookmarks.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
if (remote)
{
remote.Flush();
}
}
return(false);
}
function selectDroppedItems(treeRoot, containerID, targetID)
{
var select_list = treeRoot.getElementsByAttribute("id", targetID);
for (var x=0; x<select_list.length; x++)
{
var node = select_list[x];
if (!node) continue;
var parent = node.parentNode.parentNode;
if (!parent) continue;
var id = parent.getAttribute("ref");
if (!id || id=="")
{
id = parent.getAttribute("id");
}
if (!id || id=="") continue;
if (id == containerID)
{
treeRoot.selectItem(node);
break;
}
}
}

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

@ -1,397 +0,0 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@netscape.com> (Original Author, v2.0)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
var NC_NS = "http://home.netscape.com/NC-rdf#";
var RDF_NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
var gSpringLoadTracker = {
timeout: 0,
element: null,
open: function (aRDFNode)
{
if (this.element)
this.element.setAttribute("open", "true");
clearTimeout(this.timeout);
}
};
var bookmarksDNDObserver = {
_RDF: null,
get RDF ()
{
if (!this._RDF) {
const kRDFContractID = "@mozilla.org/rdf/rdf-service;1";
const kRDFIID = Components.interfaces.nsIRDFService;
this._RDF = Components.classes[kRDFContractID].getService(kRDFIID);
}
return this._RDF;
},
// XXX I belong somewhere shared.
getResource: function(aString)
{
return this.RDF.GetResource(aString, true);
},
getTarget: function(aDS, aSourceID, aPropertyID)
{
var source = this.getResource(aSourceID);
var property = this.getResource(aPropertyID);
return aDS.GetTarget(source, property, true);
},
onDragStart: function (aEvent, aXferData, aDragAction)
{
var bookmarksTree = document.getElementById("bookmarksTree");
if (aEvent.target == bookmarksTree || aEvent.target.localName == "treechildren" ||
aEvent.target.localName == "splitter" || aEvent.target.localName == "menu")
throw Components.results.NS_OK; // not a draggable item.
if (aEvent.target.parentNode && aEvent.target.parentNode.parentNode &&
aEvent.target.parentNode.parentNode.localName == "treehead")
throw Components.results.NS_OK; // don't drag treehead cells.
if (bookmarksTree.getAttribute("sortActive") == "true")
throw Components.results.NS_OK;
var selItems = null;
if (bookmarksTree.selectedItems.length <= 0)
selItems = [aEvent.target.parentNode.parentNode];
else
selItems = bookmarksTree.selectedItems;
aXferData.data = new TransferDataSet();
for (var i = 0; i < selItems.length; ++i) {
var currItem = selItems[i];
var currURI = NODE_ID(currItem);
var parentItem = currItem.parentNode.parentNode;
var parentURI = NODE_ID(parentItem);
var type = this.getTarget(bookmarksTree.database, currURI, RDF_NS + "type");
type = type.QueryInterface(Components.interfaces.nsIRDFResource).Value;
if (!type || (type != (NC_NS + "BookmarkSeparator") &&
type != (NC_NS + "Bookmark") &&
type != (NC_NS + "Folder")))
throw Components.results.NS_OK;
var name = this.getTarget(bookmarksTree.database, currURI, NC_NS + "Name");
var data = new TransferData();
if (name) {
name = name.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
data.addDataForFlavour("text/x-moz-url", currURI + "\n" + name);
}
else {
data.addDataForFlavour("text/x-moz-url", currURI);
}
data.addDataForFlavour("moz/rdfitem", currURI + "\n" + parentURI);
data.addDataForFlavour("text/unicode", currURI);
aXferData.data.push(data);
}
if (aEvent.ctrlKey) {
const kDSIID = Components.interfaces.nsIDragService;
aDragAction.action = kDSIID.DRAGDROP_ACTION_COPY + kDSIID.DRAGDROP_ACTION_LINK;
}
},
onDragOver: function (aEvent, aFlavour, aDragSession)
{
var bookmarksTree = document.getElementById("bookmarksTree");
var rowGroup = aEvent.target.parentNode.parentNode;
if (rowGroup)
rowGroup.setAttribute("dd-triggerrepaint" +
(bookmarksTree.getAttribute("sortActive") == "true" ? "sorted" : ""), 0);
var rdfNode = gBookmarksShell.findRDFNode(aEvent.target, true);
var rdfParent = rdfNode.parentNode.parentNode;
var isContainer = false;
if (rdfParent && rdfParent.getAttribute("container") == "true") {
var rDragOverContainer = this.RDF.GetResource(NODE_ID(rdfParent));
const kBMDS = this.RDF.GetDataSource("rdf:bookmarks");
const kRDFCUtilsContractID = "@mozilla.org/rdf/container-utils;1";
const kRDFCUtilsIID = Components.interfaces.nsIRDFContainerUtils;
const kRDFCUtils = Components.classes[kRDFCUtilsContractID].getService(kRDFCUtilsIID);
isContainer = kRDFCUtils.IsContainer(kBMDS, rDragOverContainer);
}
if (!isContainer || rowGroup.id == "headRow") {
// Not a container, or dropping onto something that isn't designed to take drops
// (e.g. the tree header)
aDragSession.canDrop = false;
return;
}
// Springloaded folders.
/* XXX - not yet.
if (rdfNode && rdfNode.getAttribute("container") == "true" &&
rdfNode.getAttribute("open") != "true") {
if (!gSpringLoadTracker.element || gSpringLoadTracker.element.id != rdfNode.id) {
// XXX - this is not good enough. We need to keep track of nesting and close up
// folders after the user has dragged out of them otherwise we end up with
// everything open and a big mess!
if (gSpringLoadTracker.timeout)
clearTimeout(gSpringLoadTracker.timeout);
gSpringLoadTracker.element = rdfNode;
gSpringLoadTracker.timeout = setTimeout("gSpringLoadTracker.open()", 100);
}
}
*/
},
_flavourSet: null,
getSupportedFlavours: function ()
{
if (!this._flavourSet) {
this._flavourSet = new FlavourSet();
this._flavourSet.appendFlavour("moz/rdfitem");
this._flavourSet.appendFlavour("text/x-moz-url");
this._flavourSet.appendFlavour("text/unicode");
}
return this._flavourSet;
},
canHandleMultipleItems: true,
onDrop: function (aEvent, aXferData, aDragSession)
{
var bookmarksTree = document.getElementById("bookmarksTree");
// XXX lame
if (bookmarksTree.getAttribute("sortActive") == "true") return;
const kRDFCContractID = "@mozilla.org/rdf/container;1";
const kRDFIID = Components.interfaces.nsIRDFContainer;
var RDFC = Components.classes[kRDFCContractID].getService(kRDFIID);
const kBMDS = this.RDF.GetDataSource("rdf:bookmarks");
var dropItem = aEvent.target.parentNode.parentNode;
if (aEvent.target.localName == "treechildren")
dropItem = aEvent.target.parentNode; // handle drop on blank space.
// In the default view, the root node is the NC root, and we don't want to append
// to that. Adjust accordingly...
if (NODE_ID(dropItem) == "NC:NavCenter")
dropItem = document.getElementById("treechildren-bookmarks").firstChild;
// Don't allow drops on the header row & prevent catastrophe
if (dropItem.id == "headRow" || !dropItem) return;
// XXX we could probably compute this ourselves, but let the tree do this
// automagically for now.
var dropBefore = dropItem.getAttribute("dd-droplocation");
var dropOn = dropItem.getAttribute("dd-dropon");
var dropAction = dropBefore == "true" ? "before" : dropOn == "true" ? "on" : "after";
if (aEvent.target.localName == "treechildren")
dropAction = "on"; // handle drop on blank space.
var containerItem = dropAction == "on" ? dropItem : dropItem.parentNode.parentNode;
// XXX magical fix for bug # 33546: handle dropping after open container
if (dropItem.getAttribute("container") && dropItem.getAttribute("open") &&
dropAction == "after") {
dropAction = "before";
containerItem = dropItem;
dropItem = null;
for (var i = 0; i < containerItem.childNodes.length; ++i) {
if (containerItem.childNodes[i].localName == "treechildren") {
dropItem = containerItem.childNodes[i].firstChild;
break;
}
}
if (!dropItem) {
dropAction = "on";
dropItem = containerItem.parentNode.parentNode;
}
}
var rTarget = this.getResource(NODE_ID(dropItem));
var rContainer = this.getResource(NODE_ID(containerItem));
const kRDFCUtilsContractID = "@mozilla.org/rdf/container-utils;1";
const kRDFCUtilsIID = Components.interfaces.nsIRDFContainerUtils;
const kRDFCUtils = Components.classes[kRDFCUtilsContractID].getService(kRDFCUtilsIID);
var isContainer = kRDFCUtils.IsContainer(kBMDS, rContainer);
// XXX
var rType = this.getResource(RDF_NS + "type");
var rBookmark = this.getResource(NC_NS + "Bookmark");
var dirty = false;
var additiveFlag = false;
var numObjects = aXferData.dataList.length;
/*
if (numObjects > 1) {
var bo = bookmarksTree.boxObject.QueryInterface(Components.interfaces.nsITreeBoxObject);
bo.beginBatch();
}
*/
var sourceID = [], parentID = [], nameRequired = [], name = [];
var flavourData;
for (i = 0; i < numObjects; ++i) {
flavourData = aXferData.dataList[i].first;
nameRequired[i] = false;
name[i] = null;
var data = flavourData.data;
switch (flavourData.flavour.contentType) {
case "moz/rdfitem":
var ix = data.indexOf("\n");
sourceID[i] = ix >= 0 ? (parentID[i] = data.substr(ix+1), data.substr(0, ix)) : data;
break;
case "text/x-moz-url":
ix = data.indexOf("\n");
sourceID[i] = ix >= 0 ? (name[i] = data.substr(ix+1), data.substr(0, ix)) : data;
break;
case "text/unicode":
sourceID[i] = data;
nameRequired[i] = true;
break;
default:
continue;
}
var rSource = this.getResource(sourceID[i]);
var rParent = parentID[i] ? this.getResource(parentID[i]) : null;
// Prevent dropping node on itself, before or after itself, on its parent
// container, or a weird situation when an open container is dropped into
// itself (which results in data loss!).
// Also prevent dropping into a folder that isn't actually a container
// (and is thus probably a pseudo-container from an aggregated datasource,
// see bug 68656 fir details).
if (rSource == rTarget || (dropAction == "on" && rContainer == rParent) ||
rContainer == rSource || !isContainer)
return;
// Prevent dropping node into one of its own subfolders
var dropItem2 = dropItem;
do {
var targetAncestor = NODE_ID(dropItem2);
dropItem2 = dropItem2.parentNode;
} while (targetAncestor != "NC:BookmarksRoot" && targetAncestor != sourceID[i]);
if (targetAncestor == sourceID[i]) {
return;
}
}
for (i = 0; i < numObjects; ++i) {
flavourData = aXferData.dataList[i].first;
rSource = this.getResource(sourceID[i]);
rParent = parentID[i] ? this.getResource(parentID[i]) : null;
// XXX if any of the following fails, the nodes are gone for good!
const kDSIID = Components.interfaces.nsIDragService;
const kCopyAction = kDSIID.DRAGDROP_ACTION_COPY + kDSIID.DRAGDROP_ACTION_LINK;
if (rParent) {
if (!(aDragSession.dragAction & kCopyAction)) {
try {
RDFC.Init(kBMDS, rParent);
ix = RDFC.IndexOf(rSource);
if (ix >= 1)
RDFC.RemoveElementAt(ix, true);
}
catch (ex) { }
}
}
RDFC.Init(kBMDS, rContainer);
// If this item already exists in this container, don't paste, as
// this will result in the creation of multiple copies in the datasource
// but will not result in an update of the UI. (In Short: we don't
// handle multiple bookmarks well)
ix = RDFC.IndexOf(rSource);
if (ix != -1)
continue;
var bmType = this.getTarget(bookmarksTree.database, sourceID[i], RDF_NS + "type");
if (!bmType)
kBMDS.Assert(rSource, rType, rBookmark, true);
if (bmType == NC_NS + "Folder") {
// If we're going to copy a folder type, we need to clone the folder
// rather than just asserting the new node as a child of the drop folder.
if (aDragSession.dragAction & kCopyAction)
rSource = BookmarksUtils.cloneFolder(rSource, rContainer, rTarget);
}
if (dropAction == "before" || dropAction == "after") {
var dropIx = RDFC.IndexOf(rTarget);
RDFC.InsertElementAt(rSource, dropAction == "after" ? ++dropIx : dropIx, true);
}
else
RDFC.AppendElement(rSource); // drop on
dirty = true;
if (rParent) {
gBookmarksShell.selectFolderItem(rContainer.Value, sourceID[i], additiveFlag);
if (!additiveFlag) additiveFlag = true;
}
// If a name is supplied, we want to assert this information into the
// graph. E.g. user drags an internet shortcut to the app, we want to
// preserve not only the URL but the name of the shortcut. The other case
// where we need to assert a name is when the node does not already exist
// in the graph, in this case we'll just use the URL as the name.
if (name[i] || nameRequired[i]) {
var currentName = this.getTarget(bookmarksTree.database, sourceID[i], NC_NS + "Name");
if (!currentName) {
var rDefaultName = this.RDF.GetLiteral(name[i] || sourceID[i]);
if (rDefaultName) {
var rName = this.RDF.GetResource(NC_NS + "Name");
kBMDS.Assert(rSource, rName, rDefaultName, true);
}
}
}
}
/*
if (numObjects > 1) {
var bo = bookmarksTree.boxObject.QueryInterface(Components.interfaces.nsITreeBoxObject);
bo.endBatch();
}
*/
if (dirty) {
var remoteDS = kBMDS.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
remoteDS.Flush();
}
}
}

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

@ -1,759 +0,0 @@
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@netscape.com> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
var gBookmarksShell = null;
///////////////////////////////////////////////////////////////////////////////
// Tracks the selected item, the cell last clicked on, and the number of clicks
// given to it. Used to activate inline edit mode.
var gSelectionTracker = { currentItem: null, currentCell: null, clickCount: 0 };
///////////////////////////////////////////////////////////////////////////////
// Class which defines methods for a bookmarks UI implementation based around
// a treeview. Subclasses BookmarksBase in bookmarksOverlay.js. Some methods
// are required by the base class, others are for event handling. Window specific
// glue code should go into the BookmarksWindow class in bookmarks.js
function BookmarksTree (aID)
{
this.id = aID;
}
BookmarksTree.prototype = {
__proto__: BookmarksUIElement.prototype,
// XXX - change this to .element and move into base.
get tree ()
{
return document.getElementById(this.id);
},
/////////////////////////////////////////////////////////////////////////////
// This method constructs a menuitem for a context menu for the given command.
// This is implemented by the client so that it can intercept menuitem naming
// as appropriate.
createMenuItem: function (aDisplayName, aCommandName, aItemNode)
{
const kXULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var xulElement = document.createElementNS(kXULNS, "menuitem");
xulElement.setAttribute("cmd", aCommandName);
xulElement.setAttribute("command", "cmd_" + aCommandName.substring(NC_NS_CMD.length));
switch (aCommandName) {
case NC_NS_CMD + "open":
xulElement.setAttribute("label", aDisplayName);
xulElement.setAttribute("default", "true");
break;
case NC_NS_CMD + "openfolder":
aDisplayName = aItemNode.getAttribute("open") == "true" ? this.getLocaleString("cmd_openfolder2") : aDisplayName;
xulElement.setAttribute("label", aDisplayName);
xulElement.setAttribute("default", "true");
break;
case NC_NS_CMD + "renamebookmark":
if (!document.popupNode.hasAttribute("type")) {
xulElement.setAttribute("label", this.getLocaleString("cmd_renamebookmark2"));
xulElement.setAttribute("cmd", (NC_NS_CMD + "editurl"));
}
else
xulElement.setAttribute("label", aDisplayName);
break;
default:
xulElement.setAttribute("label", aDisplayName);
break;
}
return xulElement;
},
// XXX - ideally this would be in the base. this.tree needs to change to
// this.element and then we can do just that.
setRoot: function (aRoot)
{
this.tree.setAttribute("ref", aRoot);
},
// Command implementation
commands: {
openFolder: function (aSelectedItem)
{
if (aSelectedItem.getAttribute("open") == "true")
aSelectedItem.removeAttribute("open");
else
aSelectedItem.setAttribute("open", "true");
},
// Things Needed to Satisfy Mac Weenies:
// 1) need to implement timed single click edit. This could be Hard.
// 2) need to implement some other method of key access apart from F2.
// mpt claims that 'Cmd+U' is the excel equivalent.
editCell: function (aSelectedItem, aCell)
{
// XXX throw up properties dialog with name selected so user can rename
// that way, until tree conversion allows us to use IL again.
goDoCommand("cmd_properties");
return; // Disable inline edit for now.
var editCell = aSelectedItem.firstChild.childNodes[aCell];
if (editCell.getAttribute("editable") != "true")
return;
// Cause the inline edit cell binding to be used.
editCell.setAttribute("class", "treecell-indent treecell-editable");
var editColGroup = document.getElementById("theColumns");
var count = 0;
var property = "";
for (var i = 0; i < editColGroup.childNodes.length; ++i) {
var currCol = editColGroup.childNodes[i];
if (currCol.getAttribute("hidden") == "true")
return;
if (count == aCell) {
property = currCol.getAttribute("resource");
break;
}
++count;
// Deal with interleaved column resizer splitters
if (currCol.nextSibling.localName == "splitter") ++i;
}
if (property) {
editCell.setMode("edit");
editCell.addObserver(this.postModifyCallback, "accept",
[editCell, aSelectedItem, property]);
}
},
///////////////////////////////////////////////////////////////////////////
// Called after an inline-edit cell has left inline-edit mode, and data
// needs to be modified in the datasource.
postModifyCallback: function (aParams)
{
var selItemURI = NODE_ID(aParams[1]);
gBookmarksShell.propertySet(selItemURI, aParams[2], aParams[3]);
gBookmarksShell.selectFolderItem(NODE_ID(gBookmarksShell.findRDFNode(aParams[1], false)),
selItemURI, false);
gBookmarksShell.tree.focus();
gSelectionTracker.clickCount = 0;
// Set the cell back to use the standard treecell binding.
var editCell = aParams[0];
editCell.setAttribute("class", "treecell-indent");
},
///////////////////////////////////////////////////////////////////////////
// New Folder Creation
// Strategy: create a dummy row with edit fields to harvest information
// from the user, then destroy these rows and create an item
// in its place.
///////////////////////////////////////////////////////////////////////////
// Edit folder name & update the datasource if name is valid
onEditFolderName: function (aParams, aTopic)
{
var name = aParams[3];
var shell = gBookmarksShell.commands; // suck
var dummyItem = aParams[2];
var relativeNode = aParams[1];
var parentNode = relativeNode ? gBookmarksShell.findRDFNode(relativeNode, false) : gBookmarksShell.tree;
dummyItem.parentNode.removeChild(dummyItem);
if (!shell.validateNameAndTopic(name, aTopic, relativeNode, dummyItem)) {
gBookmarksShell.tree.selectItem(relativeNode);
gBookmarksShell.tree.focus();
return;
}
if (relativeNode) {
// If we're attempting to create a folder as a subfolder of an open folder,
// we need to set the parentFolder to be relativeNode, which will be the
// parent of the new folder, rather than the parent of the relativeNode,
// which will result in the folder being created in an incorrect position
// (adjacent to the relativeNode).
var selKids = ContentUtils.childByLocalName(relativeNode, "treechildren");
if (selKids && selKids.hasChildNodes() && selKids.lastChild == dummyItem)
parentNode = relativeNode;
}
var args = [{ property: NC_NS + "parent",
resource: NODE_ID(parentNode) },
{ property: NC_NS + "Name",
literal: name }];
const kBMDS = gBookmarksShell.RDF.GetDataSource("rdf:bookmarks");
kBMDS.AddObserver(newFolderRDFObserver);
var relId = relativeNode ? NODE_ID(relativeNode) : "NC:BookmarksRoot";
BookmarksUtils.doBookmarksCommand(relId, NC_NS_CMD + "newfolder", args);
kBMDS.RemoveObserver(newFolderRDFObserver);
var newFolderItem = document.getElementById(newFolderRDFObserver._newFolderURI);
gBookmarksShell.tree.focus();
gBookmarksShell.tree.selectItem(newFolderItem);
// Can't use newFolderItem because it may not have been created yet. Hack, huh?
var index = gBookmarksShell.tree.getIndexOfItem(relativeNode);
gBookmarksShell.tree.ensureIndexIsVisible(index+1);
gSelectionTracker.clickCount = 0;
},
///////////////////////////////////////////////////////////////////////////
// Performs simple validation on what the user has entered:
// 1) prevents entering an empty string
// 2) in the case of a canceled operation, remove the dummy item and
// restore selection.
validateNameAndTopic: function (aName, aTopic, aOldSelectedItem, aDummyItem)
{
// Don't allow user to enter an empty string "";
if (!aName) return false;
// If the user hit escape, go no further.
if (aTopic == "reject") {
if (aOldSelectedItem)
gBookmarksShell.tree.selectItem(aOldSelectedItem);
return false;
}
return true;
},
///////////////////////////////////////////////////////////////////////////
// Creates a dummy item that can be placed in edit mode to retrieve data
// to create new bookmarks/folders.
createBookmarkItem: function (aMode, aSelectedItem)
{
/////////////////////////////////////////////////////////////////////////
// HACK HACK HACK HACK HACK
// Disable Inline-Edit for now and just use a dialog.
// XXX - most of this is just copy-pasted from the other two folder
// creation functions. Yes it's ugly, but it'll do the trick for
// now as this is in no way intended to be a long-term solution.
const kPromptSvcContractID = "@mozilla.org/embedcomp/prompt-service;1";
const kPromptSvcIID = Components.interfaces.nsIPromptService;
const kPromptSvc = Components.classes[kPromptSvcContractID].getService(kPromptSvcIID);
var defaultValue = gBookmarksShell.getLocaleString("ile_newfolder");
var dialogTitle = gBookmarksShell.getLocaleString("newfolder_dialog_title");
var dialogMsg = gBookmarksShell.getLocaleString("newfolder_dialog_msg");
var stringValue = { value: defaultValue };
if (kPromptSvc.prompt(window, dialogTitle, dialogMsg, stringValue, null, { value: 0 })) {
var relativeNode = gBookmarksShell.tree;
var parentNode;
if (aSelectedItem && aSelectedItem.localName != "tree") {
// By default, create adjacent to the selected item
relativeNode = aSelectedItem;
if (relativeNode.getAttribute("container") == "true" &&
relativeNode.getAttribute("open") == "true") {
// But if it's an open container, the relative node should be the last child.
var treechildren = ContentUtils.childByLocalName(relativeNode, "treechildren");
if (treechildren && treechildren.hasChildNodes())
relativeNode = treechildren.lastChild; // folder non-empty, set relativeNode
parentNode = aSelectedItem; // no matter what, folder is open, so make it parent
} else {
parentNode = relativeNode ? gBookmarksShell.findRDFNode(relativeNode, false) : gBookmarksShell.tree;
}
}
var args = [{ property: NC_NS + "parent",
resource: NODE_ID(parentNode) },
{ property: NC_NS + "Name",
literal: stringValue.value }];
const kBMDS = gBookmarksShell.RDF.GetDataSource("rdf:bookmarks");
kBMDS.AddObserver(newFolderRDFObserver);
var relId = relativeNode ? NODE_ID(relativeNode) : "NC:BookmarksRoot";
BookmarksUtils.doBookmarksCommand(relId, NC_NS_CMD + "newfolder", args);
kBMDS.RemoveObserver(newFolderRDFObserver);
var newFolderItem = document.getElementById(newFolderRDFObserver._newFolderURI);
gBookmarksShell.tree.focus();
gBookmarksShell.tree.selectItem(newFolderItem);
// Can't use newFolderItem because it may not have been created yet. Hack, huh?
var index = gBookmarksShell.tree.getIndexOfItem(relativeNode);
gBookmarksShell.tree.ensureIndexIsVisible(index+1);
}
return;
// HACK HACK HACK HACK HACK
/////////////////////////////////////////////////////////////////////////
/* Disable inline edit for now
const kXULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var dummyItem = document.createElementNS(kXULNS, "treeitem");
dummyItem = gBookmarksShell.createBookmarkFolderDecorations(dummyItem);
dummyItem.setAttribute("class", "bookmark-item");
var dummyRow = document.createElementNS(kXULNS, "treerow");
var dummyCell = document.createElementNS(kXULNS, "treecell");
var dummyCell2 = document.createElementNS(kXULNS, "treecell");
dummyCell.setAttribute("label", gBookmarksShell.getLocaleString("ile_newfolder") + " ");
dummyCell.setAttribute("type", NC_NS + "Folder");
dummyCell.setAttribute("editable", "true");
dummyCell.setAttribute("class", "treecell-indent treecell-editable");
dummyRow.appendChild(dummyCell);
dummyItem.appendChild(dummyRow);
var relativeNode = null;
// If there are selected items, try to create the dummy item relative to the
// best item, and position the bookmark there when created. Otherwise just
// append to the root.
if (aSelectedItem && aSelectedItem.localName != "tree") {
// By default, create adjacent to the selected item
relativeNode = aSelectedItem;
if (relativeNode.getAttribute("container") == "true" &&
relativeNode.getAttribute("open") == "true") {
// But if it's an open container, the relative node should be the last child.
var treechildren = ContentUtils.childByLocalName(relativeNode, "treechildren");
if (treechildren && treechildren.hasChildNodes())
relativeNode = treechildren.lastChild;
}
if (aSelectedItem.getAttribute("container") == "true") {
if (aSelectedItem.getAttribute("open") == "true") {
var treechildren = ContentUtils.childByLocalName(aSelectedItem, "treechildren");
if (!treechildren) {
treechildren = document.createElementNS(kXULNS, "treechildren");
aSelectedItem.appendChild(treechildren);
}
// Insert new item after last item.
treechildren.appendChild(dummyItem);
}
else {
if (aSelectedItem.nextSibling)
aSelectedItem.parentNode.insertBefore(dummyItem, aSelectedItem.nextSibling);
else
aSelectedItem.parentNode.appendChild(dummyItem);
}
var index = gBookmarksShell.tree.getIndexOfItem(dummyItem);
gBookmarksShell.tree.ensureIndexIsVisible(index);
}
else {
if (aSelectedItem.nextSibling)
aSelectedItem.parentNode.insertBefore(dummyItem, aSelectedItem.nextSibling);
else
aSelectedItem.parentNode.appendChild(dummyItem);
}
}
else {
// No items in the tree. Append to the root.
var rootKids = document.getElementById("treechildren-bookmarks");
rootKids.appendChild(dummyItem);
}
dummyCell.setMode("edit");
dummyCell.addObserver(this.onEditFolderName, "accept", [dummyCell, relativeNode, dummyItem]);
dummyCell.addObserver(this.onEditFolderName, "reject", [dummyCell, relativeNode, dummyItem]);
*/
}
},
/////////////////////////////////////////////////////////////////////////////
// Evaluates an event to determine whether or not it affords opening a tree
// item. Typically, this is when the left mouse button is used, and provided
// the click-rate matches that specified by our owning tree class. For example,
// some trees open an item when double clicked (bookmarks/history windows) and
// others on a single click (sidebar panels).
isValidOpenEvent: function (aEvent)
{
return !(aEvent.type == "click" &&
(aEvent.button != 0 || aEvent.detail != this.openClickCount))
},
/////////////////////////////////////////////////////////////////////////////
// For the given selection, selects the best adjacent element. This method is
// useful when an action such as a cut or a deletion is performed on a
// selection, and focus/selection needs to be restored after the operation
// is performed.
getNextElement: function (aElement)
{
if (aElement.nextSibling)
return aElement.nextSibling;
else if (aElement.previousSibling)
return aElement.previousSibling;
else
return aElement.parentNode.parentNode;
},
selectElement: function (aElement)
{
this.tree.selectItem(aElement);
},
//////////////////////////////////////////////////////////////////////////////
// Add the treeitem element specified by aURI to the tree's current selection.
addItemToSelection: function (aURI)
{
var item = document.getElementById(aURI) // XXX flawed for multiple ids
this.tree.addItemToSelection(item);
},
/////////////////////////////////////////////////////////////////////////////
// Return a set of DOM nodes that represent the selection in the tree widget.
// This method is takes a node parameter which is the popupNode for the
// document. If the popupNode is not contained by the selection, the
// popupNode is selected and the new selection returned.
getSelection: function ()
{
// Note that we don't just the selectedItems NodeList here because that
// is a reference to a LIVE DOM NODE LIST. We want to maintain control
// over what is in the selection array ourselves.
return [].concat(this.tree.selectedItems);
},
getBestItem: function ()
{
var seln = this.getSelection ();
if (seln.length < 1) {
var kids = ContentUtils.childByLocalName(this.tree, "treechildren");
return kids.lastChild || this.tree;
}
else
return seln[0];
return this.tree;
},
/////////////////////////////////////////////////////////////////////////////
// Return a set of DOM nodes that represent the selection in the tree widget.
// This method is takes a node parameter which is the popupNode for the
// document. If the popupNode is not contained by the selection, the
// popupNode is selected and the new selection returned.
getContextSelection: function (aItemNode)
{
// How a context-click works:
// if the popup node is contained by the selection, the context menu is
// built for that selection. However, if the popup node is invoked on a
// non-selected node, unless modifiers are pressed**, the previous
// selection is discarded and that node selected.
var selectedItems = this.tree.selectedItems;
for (var i = 0; i < selectedItems.length; ++i) {
if (selectedItems[i] == aItemNode)
return selectedItems;
}
if (aItemNode.localName == "treeitem")
this.tree.selectItem(aItemNode);
return this.tree.selectedItems.length ? this.tree.selectedItems : [this.tree];
},
getSelectedFolder: function ()
{
var selectedItem = this.getBestItem();
if (!selectedItem) return "NC:BookmarksRoot";
while (selectedItem && selectedItem.nodeType == Node.ELEMENT_NODE) {
if (selectedItem.getAttribute("container") == "true" &&
selectedItem.getAttribute("open") == "true")
return NODE_ID(selectedItem);
selectedItem = selectedItem.parentNode.parentNode;
}
return "NC:BookmarksRoot";
},
/////////////////////////////////////////////////////////////////////////////
// For a given start DOM element, find the enclosing DOM element that contains
// the template builder RDF resource decorations (id, ref, etc).
findRDFNode: function (aStartNode, aIncludeStartNodeFlag)
{
var temp = aIncludeStartNodeFlag ? aStartNode : aStartNode.parentNode;
while (temp && temp.localName != "treeitem")
temp = temp.parentNode;
return temp || this.tree;
},
/////////////////////////////////////////////////////////////////////////////
// Tree click events. This handles when to go into inline-edit mode for
// editable cells.
treeClicked: function (aEvent)
{
// We are disabling Inline Edit for now. It's too buggy in the old XUL tree widget.
// A more solid implementation will follow the conversion to tree
/*
if (this.tree.selectedItems.length > 1 || aEvent.detail > 1 || aEvent.button != 0) {
gSelectionTracker.clickCount = 0;
return;
}
if (gSelectionTracker.currentItem == this.tree.currentItem &&
gSelectionTracker.currentCell == aEvent.target)
++gSelectionTracker.clickCount;
else
gSelectionTracker.clickCount = 0;
if (!this.tree.currentItem)
return;
gSelectionTracker.currentItem = this.tree.currentItem;
gSelectionTracker.currentCell = aEvent.target;
if (gSelectionTracker.currentItem.getAttribute("type") != NC_NS + "Bookmark" &&
gSelectionTracker.currentItem.getAttribute("type") != NC_NS + "Folder")
return;
var row = gSelectionTracker.currentItem.firstChild;
if (row) {
for (var i = 0; i < row.childNodes.length; ++i) {
if (row.childNodes[i] == gSelectionTracker.currentCell) {
// Don't allow inline-edit of cells other than name for folders.
// XXX - so so skeezy. Change this to look for NC:Name or some such.
if (gSelectionTracker.currentItem.getAttribute("type") != NC_NS + "Bookmark" && i)
return;
// Don't allow editing of the root folder name
if (gSelectionTracker.currentItem.id == "NC:BookmarksRoot")
return;
if (gSelectionTracker.clickCount == 1 && this.openClickCount > 1)
gBookmarksShell.commands.editCell(this.tree.currentItem, i);
break;
}
}
}
*/
},
treeOpen: function (aEvent)
{
if (this.isValidOpenEvent(aEvent)) {
var rdfNode = this.findRDFNode(aEvent.target, true);
if (rdfNode.getAttribute("container") != "true")
this.open(aEvent, rdfNode);
}
},
/////////////////////////////////////////////////////////////////////////////
// Tree key events. This handles when to go into inline-edit mode for editable
// cells, when to load a URL, etc.
treeKeyPress: function (aEvent)
{
if (this.tree.selectedItems.length > 1) return;
/* Disabling Inline Edit
if (aEvent.keyCode == 113 && aEvent.shiftKey) {
const kNodeId = NODE_ID(this.tree.currentItem);
if (this.resolveType(kNodeId) == NC_NS + "Bookmark")
gBookmarksShell.commands.editCell (this.tree.currentItem, 1);
}
else */
if (aEvent.keyCode == 113)
goDoCommand("cmd_rename");
else if (aEvent.keyCode == 13) // && this.tree.currentItem.firstChild.getAttribute("inline-edit") != "true")
goDoCommand(aEvent.altKey ? "cmd_properties" : "cmd_open");
},
selectFolderItem: function (aFolderURI, aItemURI, aAdditiveFlag)
{
var folder = document.getElementById(aFolderURI);
var kids = ContentUtils.childByLocalName(folder, "treechildren");
if (!kids) return;
var item = kids.firstChild;
while (item) {
if (item.id == aItemURI) break;
item = item.nextSibling;
}
if (!item) return;
this.tree[aAdditiveFlag ? "addItemToSelection" : "selectItem"](item);
},
/////////////////////////////////////////////////////////////////////////////
// Command handling & Updating.
controller: {
supportsCommand: function (aCommand)
{
switch(aCommand) {
case "cmd_undo":
case "cmd_redo":
return false;
case "cmd_bm_cut":
case "cmd_bm_copy":
case "cmd_bm_paste":
case "cmd_bm_delete":
case "cmd_bm_selectAll":
return true;
case "cmd_open":
case "cmd_openfolder":
case "cmd_openfolderinnewwindow":
case "cmd_newbookmark":
case "cmd_newfolder":
case "cmd_newseparator":
case "cmd_find":
case "cmd_properties":
case "cmd_rename":
case "cmd_setnewbookmarkfolder":
case "cmd_setpersonaltoolbarfolder":
case "cmd_setnewsearchfolder":
case "cmd_import":
case "cmd_export":
case "cmd_bm_fileBookmark":
return true;
default:
return false;
}
},
isCommandEnabled: function (aCommand)
{
var numSelectedItems = gBookmarksShell.tree.selectedItems.length;
var seln, firstSelected, folderType, bItemCountCorrect;
switch(aCommand) {
case "cmd_undo":
case "cmd_redo":
return false;
case "cmd_bm_paste":
return gBookmarksShell.canPaste();
case "cmd_bm_cut":
case "cmd_bm_copy":
case "cmd_bm_delete":
return numSelectedItems >= 1;
case "cmd_bm_selectAll":
return true;
case "cmd_open":
seln = gBookmarksShell.tree.selectedItems;
return numSelectedItems == 1 && seln[0].getAttribute("type") == NC_NS + "Bookmark";
case "cmd_openfolder":
case "cmd_openfolderinnewwindow":
seln = gBookmarksShell.tree.selectedItems;
return numSelectedItems == 1 && seln[0].getAttribute("type") == NC_NS + "Folder";
case "cmd_find":
case "cmd_newbookmark":
case "cmd_newfolder":
case "cmd_newseparator":
case "cmd_import":
case "cmd_export":
return true;
case "cmd_properties":
case "cmd_rename":
seln = gBookmarksShell.tree.selectedItems;
return numSelectedItems == 1 && seln[0].getAttribute("type") != NC_NS + "BookmarkSeparator";
case "cmd_setnewbookmarkfolder":
seln = gBookmarksShell.tree.selectedItems;
firstSelected = seln.length ? seln[0] : gBookmarksShell.tree;
folderType = firstSelected.getAttribute("type") == (NC_NS + "Folder");
bItemCountCorrect = seln.length ? numSelectedItems == 1 : true;
return bItemCountCorrect && !(NODE_ID(firstSelected) == "NC:NewBookmarkFolder") && folderType;
case "cmd_setpersonaltoolbarfolder":
seln = gBookmarksShell.tree.selectedItems;
firstSelected = seln.length ? seln[0] : gBookmarksShell.tree;
folderType = firstSelected.getAttribute("type") == (NC_NS + "Folder");
bItemCountCorrect = seln.length ? numSelectedItems == 1 : true;
return bItemCountCorrect && !(NODE_ID(firstSelected) == "NC:PersonalToolbarFolder") && folderType;
case "cmd_setnewsearchfolder":
seln = gBookmarksShell.tree.selectedItems;
firstSelected = seln.length ? seln[0] : gBookmarksShell.tree;
folderType = firstSelected.getAttribute("type") == (NC_NS + "Folder");
bItemCountCorrect = seln.length ? numSelectedItems == 1 : true;
return bItemCountCorrect == 1 && !(NODE_ID(firstSelected) == "NC:NewSearchFolder") && folderType;
case "cmd_bm_fileBookmark":
seln = gBookmarksShell.tree.selectedItems;
return seln.length > 0;
default:
return false;
}
},
doCommand: function (aCommand)
{
switch(aCommand) {
case "cmd_undo":
case "cmd_redo":
break;
case "cmd_bm_paste":
case "cmd_bm_copy":
case "cmd_bm_cut":
case "cmd_bm_delete":
case "cmd_newbookmark":
case "cmd_newfolder":
case "cmd_newseparator":
case "cmd_properties":
case "cmd_rename":
case "cmd_open":
case "cmd_openfolder":
case "cmd_openfolderinnewwindow":
case "cmd_setnewbookmarkfolder":
case "cmd_setpersonaltoolbarfolder":
case "cmd_setnewsearchfolder":
case "cmd_find":
case "cmd_import":
case "cmd_export":
case "cmd_bm_fileBookmark":
gBookmarksShell.execCommand(aCommand.substring("cmd_".length));
break;
case "cmd_bm_selectAll":
gBookmarksShell.tree.selectAll();
break;
}
},
onEvent: function (aEvent)
{
switch (aEvent) {
case "tree-select":
this.onCommandUpdate();
break;
}
},
onCommandUpdate: function ()
{
var commands = ["cmd_properties", "cmd_rename", "cmd_bm_copy",
"cmd_bm_paste", "cmd_bm_cut", "cmd_bm_delete",
"cmd_setpersonaltoolbarfolder",
"cmd_setnewbookmarkfolder",
"cmd_setnewsearchfolder", "cmd_bm_fileBookmark",
"cmd_openfolderinnewwindow", "cmd_openfolder"];
for (var i = 0; i < commands.length; ++i)
goUpdateCommand(commands[i]);
}
}
};
var newFolderRDFObserver = {
_newFolderURI: null,
onAssert: function (aDS, aSource, aProperty, aValue)
{
try {
var value = aValue.QueryInterface(Components.interfaces.nsIRDFResource);
if (aDS.URI == "rdf:bookmarks" && aProperty.Value == RDF_NS + "type" &&
value.Value == NC_NS + "Folder")
this._newFolderURI = aSource.Value;
}
catch (e) {
// Failures are OK, the value could be a literal instead of a resource.
}
},
onUnassert: function (aDS, aSource, aProperty, aTarget) { },
onChange: function (aDS, aSource, aProperty, aOldTarget, aNewTarget) { },
onMove: function (aDS, aOldSource, aNewSource, aProperty, aTarget) { },
beginUpdateBatch: function (aDS) { },
endUpdateBatch: function (aDS) { }
};