/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Netscape Public License * Version 1.0 (the "NPL"); you may not use this file except in * compliance with the NPL. You may obtain a copy of the NPL at * http://www.mozilla.org/NPL/ * * Software distributed under the NPL is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL * for the specific language governing rights and limitations under the * NPL. * * The Initial Developer of this code under the NPL is Netscape * Communications Corporation. Portions created by Netscape are * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ /* Script for the bookmarks properties window */ function BookmarkProperties() { var tree = document.getElementById('bookmarksTree'); var select_list = tree.getElementsByAttribute("selected", "true"); if (select_list.length >= 1) { // don't bother showing properties on bookmark separators var type = select_list[0].getAttribute('type'); if (type != "http://home.netscape.com/NC-rdf#BookmarkSeparator") { var props = window.open("chrome://bookmarks/content/bm-props.xul", "BookmarkProperties", "chrome,menubar,resizable"); props.BookmarkURL = select_list[0].getAttribute("id"); } } else { dump("nothing selected!\n"); } } function OpenURL(event, node) { // clear any single-click/edit timeouts if (timerID != null) { gEditNode = null; clearTimeout(timerID); timerID = null; } if (node.getAttribute('container') == "true") { return(false); } var url = node.getAttribute('id'); // Ignore "NC:" urls. if (url.substring(0, 3) == "NC:") { return(false); } try { // add support for IE favorites under Win32, and NetPositive URLs under BeOS if (url.indexOf("file://") == 0) { var rdf = Components.classes["component://netscape/rdf/rdf-service"].getService(); if (rdf) rdf = rdf.QueryInterface(Components.interfaces.nsIRDFService); if (rdf) { var fileSys = rdf.GetDataSource("rdf:files"); if (fileSys) { var src = rdf.GetResource(url, true); var prop = rdf.GetResource("http://home.netscape.com/NC-rdf#URL", true); var target = fileSys.GetTarget(src, prop, true); if (target) target = target.QueryInterface(Components.interfaces.nsIRDFLiteral); if (target) target = target.Value; if (target) url = target; } } } } catch(ex) { } window.open(url,'bookmarks'); dump("OpenURL(" + url + ")\n"); return(true); } var htmlInput = null; var saveNode = null; var newValue = ""; var timerID = null; var gEditNode = null; function DoSingleClick(event, node) { var type = node.parentNode.parentNode.getAttribute('type'); var selected = node.parentNode.parentNode.getAttribute('selected'); if (gEditNode == node) { // Only start an inline edit if it is the second consecutive click // on the same node that is not already editing or a separator. if (!htmlInput && type != "http://home.netscape.com/NC-rdf#BookmarkSeparator") { // Edit node if we don't get a double-click in less than 1/2 second timerID = setTimeout("OpenEditNode()", 500); } } else { if (htmlInput) { // Clicked during an edit // Save the changes and move on CloseEditNode(true); } gEditNode = node; } return false; } function OpenEditNode() { dump("OpenEditNode entered.\n"); // clear any single-click/edit timeouts if (timerID != null) { clearTimeout(timerID); timerID = null; } // XXX uncomment the following line to replace the whole input row we do this // (and, therefore, only allow editing on the name column) until we can // arbitrarily change the content model (bugs prevent this at the moment) gEditNode = gEditNode.parentNode; var name = gEditNode.parentNode.getAttribute("Name"); dump("Single click on '" + name + "'\n"); var theParent = gEditNode.parentNode; dump("Parent node is a " + theParent.nodeName + "\n\n"); saveNode = gEditNode; // unselect all nodes! var select_list = document.getElementsByAttribute("selected", "true"); dump("# of Nodes selected: " + select_list.length + "\n\n"); for (var nodeIndex=0; nodeIndex 0) { // perform command intersection calculation for (var cmdIndex = 0; cmdIndex < cmdArray.length; cmdIndex++) { var cmdFound = false; for (var nextCmdIndex = 0; nextCmdIndex < nextCmdArray.length; nextCmdIndex++) { if (nextCmdArray[nextCmdIndex] == cmdArray[cmdIndex]) { cmdFound = true; break; } } if (cmdFound == false) { cmdArray[cmdIndex] = null; } } } } // need a resource to ask RDF for each command's name var rdfNameResource = rdf.GetResource("http://home.netscape.com/NC-rdf#Name"); if (!rdfNameResource) return(false); // build up menu items if (cmdArray.length < 1) return(false); for (var cmdIndex = 0; cmdIndex < cmdArray.length; cmdIndex++) { var cmd = cmdArray[cmdIndex]; if (!cmd) continue; var cmdResource = cmd.QueryInterface(Components.interfaces.nsIRDFResource); if (!cmdResource) break; var cmdNameNode = compositeDB.GetTarget(cmdResource, rdfNameResource, true); if (!cmdNameNode) break; cmdNameLiteral = cmdNameNode.QueryInterface(Components.interfaces.nsIRDFLiteral); if (!cmdNameLiteral) break; cmdName = cmdNameLiteral.Value; if (!cmdName) break; dump("Command #" + cmdIndex + ": id='" + cmdResource.Value + "' name='" + cmdName + "'\n\n"); var menuItem = document.createElement("menuitem"); menuItem.setAttribute("name", cmdName); menuItem.setAttribute("onclick", "return doContextCmd('" + cmdResource.Value + "');"); menuNode.appendChild(menuItem); } return(true); } function doContextCmd(cmdName) { dump("doContextCmd start: cmd='" + cmdName + "'\n"); var treeNode = document.getElementById("bookmarksTree"); if (!treeNode) return(false); var db = treeNode.database; if (!db) return(false); var compositeDB = db.QueryInterface(Components.interfaces.nsIRDFDataSource); if (!compositeDB) return(false); var isupports = Components.classes["component://netscape/rdf/rdf-service"].getService(); if (!isupports) return(false); var rdf = isupports.QueryInterface(Components.interfaces.nsIRDFService); if (!rdf) return(false); // need a resource for the command var cmdResource = rdf.GetResource(cmdName); if (!cmdResource) return(false); cmdResource = cmdResource.QueryInterface(Components.interfaces.nsIRDFResource); if (!cmdResource) return(false); var select_list = treeNode.getElementsByAttribute("selected", "true"); if (select_list.length < 1) return(false); dump("# of Nodes selected: " + select_list.length + "\n\n"); // set up selection nsISupportsArray var selectionInstance = Components.classes["component://netscape/supports-array"].createInstance(); var selectionArray = selectionInstance.QueryInterface(Components.interfaces.nsISupportsArray); // set up arguments nsISupportsArray var argumentsInstance = Components.classes["component://netscape/supports-array"].createInstance(); var argumentsArray = argumentsInstance.QueryInterface(Components.interfaces.nsISupportsArray); // get argument (parent) var parentArc = rdf.GetResource("http://home.netscape.com/NC-rdf#parent"); if (!parentArc) return(false); for (var nodeIndex=0; nodeIndex