From 5ae3e2fbc87a98e38ad1c071f16ed2742749aa1a Mon Sep 17 00:00:00 2001 From: "rjc%netscape.com" Date: Thu, 27 Jul 2006 14:49:11 +0000 Subject: [PATCH] Add RDF command separator support. --- suite/common/search/shared.js | 42 +++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/suite/common/search/shared.js b/suite/common/search/shared.js index 25ba0693ac06..2cf5d496b5fe 100644 --- a/suite/common/search/shared.js +++ b/suite/common/search/shared.js @@ -36,6 +36,9 @@ function fillContextMenu(name, treeName) var select_list = treeNode.selectedItems; + var separatorResource = rdf.GetResource("http://home.netscape.com/NC-rdf#BookmarkSeparator"); + if (!separatorResource) return(false); + // perform intersection of commands over selected nodes var cmdArray = new Array(); var selectLength = select_list.length; @@ -91,9 +94,13 @@ function fillContextMenu(name, treeName) break; } } - if (cmdFound == false) + if ((cmdFound == false) && (cmdArray[cmdIndex])) { - cmdArray[cmdIndex] = null; + var cmdResource = cmdArray[cmdIndex].QueryInterface(Components.interfaces.nsIRDFResource); + if ((cmdResource) && (cmdResource != separatorResource)) + { + cmdArray[cmdIndex] = null; + } } } } @@ -106,12 +113,29 @@ function fillContextMenu(name, treeName) // build up menu items if (cmdArray.length < 1) return(false); + var lastWasSep = 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; + + // handle separators + if (cmdResource == separatorResource) + { + if (lastWasSep != true) + { + lastWasSep = true; + var menuItem = document.createElement("menuseparator"); + popupNode.appendChild(menuItem); + } + continue; + } + + lastWasSep = false; + var cmdNameNode = compositeDB.GetTarget(cmdResource, rdfNameResource, true); if (!cmdNameNode) break; cmdNameLiteral = cmdNameNode.QueryInterface(Components.interfaces.nsIRDFLiteral); @@ -126,6 +150,20 @@ function fillContextMenu(name, treeName) menuItem.setAttribute("oncommand", "return doContextCmd('" + cmdResource.Value + "', '" + treeName + "');"); } + // strip off leading/trailing menuseparators + while (popupNode.childNodes.length > 0) + { + if (popupNode.childNodes[0].tagName != "menuseparator") + break; + popupNode.removeChild(popupNode.childNodes[0]); + } + while (popupNode.childNodes.length > 0) + { + if (popupNode.childNodes[popupNode.childNodes.length - 1].tagName != "menuseparator") + break; + popupNode.removeChild(popupNode.childNodes[popupNode.childNodes.length - 1]); + } + return(true); }