From d7d325434a3df426131f7c34b472fd59eb25b9a7 Mon Sep 17 00:00:00 2001 From: "rjc%netscape.com" Date: Sat, 26 Jun 1999 04:38:48 +0000 Subject: [PATCH] Add support for context menus. --- suite/common/bookmarks/bookmarks.js | 125 ++++++++++++++++++ .../bookmarks/resources/bookmarks.js | 125 ++++++++++++++++++ .../bookmarks/resources/bookmarks.xul | 6 +- 3 files changed, 255 insertions(+), 1 deletion(-) diff --git a/suite/common/bookmarks/bookmarks.js b/suite/common/bookmarks/bookmarks.js index 9c76f81f37ca..0817abe0405e 100644 --- a/suite/common/bookmarks/bookmarks.js +++ b/suite/common/bookmarks/bookmarks.js @@ -129,3 +129,128 @@ function doSort(sortColName) rdfCore.doSort(node, sortResource, sortDirection); return(false); } + + +function fillContextMenu(name) +{ + if (!name) return(false); + var popupNode = document.getElementById(name); + if (!popupNode) return(false); + + // remove the menu node (which tosses all of its kids); + // do this in case any old command nodes are hanging around + var menuNode = popupNode.childNodes[0]; + popupNode.removeChild(menuNode); + + // create a new menu node + menuNode = document.createElement("menu"); + popupNode.appendChild(menuNode); + + 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); + + var select_list = treeNode.getElementsByAttribute("selected", "true"); + if (select_list.length < 1) return(false); + + dump("# of Nodes selected: " + select_list.length + "\n\n"); + + // perform intersection of commands over selected nodes + var cmdArray = new Array(); + + for (var nodeIndex=0; nodeIndex 0) + { + // perform command intersection calculation + for (var cmdIndex = 0; cmdIndex < cmdArray.lenght; cmdIndex++) + { + var cmdFound = false; + for (var nextCmdIndex = 0; nextCmdIndex < nextCmdArray.lenght; 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: cmd='" + cmdName + "'\n"); + + return(true); +} diff --git a/xpfe/components/bookmarks/resources/bookmarks.js b/xpfe/components/bookmarks/resources/bookmarks.js index 9c76f81f37ca..0817abe0405e 100644 --- a/xpfe/components/bookmarks/resources/bookmarks.js +++ b/xpfe/components/bookmarks/resources/bookmarks.js @@ -129,3 +129,128 @@ function doSort(sortColName) rdfCore.doSort(node, sortResource, sortDirection); return(false); } + + +function fillContextMenu(name) +{ + if (!name) return(false); + var popupNode = document.getElementById(name); + if (!popupNode) return(false); + + // remove the menu node (which tosses all of its kids); + // do this in case any old command nodes are hanging around + var menuNode = popupNode.childNodes[0]; + popupNode.removeChild(menuNode); + + // create a new menu node + menuNode = document.createElement("menu"); + popupNode.appendChild(menuNode); + + 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); + + var select_list = treeNode.getElementsByAttribute("selected", "true"); + if (select_list.length < 1) return(false); + + dump("# of Nodes selected: " + select_list.length + "\n\n"); + + // perform intersection of commands over selected nodes + var cmdArray = new Array(); + + for (var nodeIndex=0; nodeIndex 0) + { + // perform command intersection calculation + for (var cmdIndex = 0; cmdIndex < cmdArray.lenght; cmdIndex++) + { + var cmdFound = false; + for (var nextCmdIndex = 0; nextCmdIndex < nextCmdArray.lenght; 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: cmd='" + cmdName + "'\n"); + + return(true); +} diff --git a/xpfe/components/bookmarks/resources/bookmarks.xul b/xpfe/components/bookmarks/resources/bookmarks.xul index 2b9e7ffe7c93..a18216cc150d 100644 --- a/xpfe/components/bookmarks/resources/bookmarks.xul +++ b/xpfe/components/bookmarks/resources/bookmarks.xul @@ -82,7 +82,11 @@ - + + + +