diff --git a/suite/common/search/search-panel.js b/suite/common/search/search-panel.js index 59a41478f541..8f4a029f890a 100644 --- a/suite/common/search/search-panel.js +++ b/suite/common/search/search-panel.js @@ -25,15 +25,28 @@ var textArc = null; var RDF_observer = new Object; var pref = null; + + +function debug(msg) +{ + // uncomment for debugging information + // dump(msg+"\n"); +} + + + // get the click count pref -try { - pref = Components.classes["component://netscape/preferences"].getService(); - if( pref ) - pref = pref.QueryInterface( Components.interfaces.nsIPref ); +try +{ + pref = Components.classes["component://netscape/preferences"].getService(); + if( pref ) pref = pref.QueryInterface( Components.interfaces.nsIPref ); } -catch(e) { +catch(e) +{ } + + RDF_observer = { OnAssert : function(src, prop, target) @@ -58,25 +71,33 @@ RDF_observer = } } -function rememberSearchText(targetNode) + + +function rememberSearchText(target) { - if (targetNode) targetNode = targetNode.QueryInterface(Components.interfaces.nsIRDFLiteral); - if (targetNode) targetNode = targetNode.Value; - if (targetNode && (targetNode != "")) + if (target) target = target.QueryInterface(Components.interfaces.nsIRDFLiteral); + if (target) target = target.Value; + if (target && (target != "")) { var textNode = document.getElementById("sidebar-search-text"); if (!textNode) return(false); - textNode.value = unescape(targetNode); + + // convert pluses (+) back to spaces + target = target.replace(/+/i, " "); + + textNode.value = unescape(target); } } + + // Initialize the Search panel: // 1) init the category list // 2) load the search engines associated with this category // 3) initialise the checked state of said engines. function SearchPanelStartup() { - bundle = srGetStrBundle( "chrome://search/locale/search-panel.properties" ); + bundle = srGetStrBundle( "chrome://search/locale/search-panel.properties" ); var tree = document.getElementById("Tree"); if (tree) @@ -107,46 +128,85 @@ function SearchPanelStartup() } } } - - try { - var pref = Components.classes["component://netscape/preferences"].getService(); - if( pref ) - pref = pref.QueryInterface( Components.interfaces.nsIPref ); - var lastCategoryName = pref.CopyCharPref( "browser.search.last_search_category" ); - } - catch( e ) { - var lastCategoryName = ""; - } -// dump("*** lastCategoryName = " + lastCategoryName + "\n"); - var categoryList = document.getElementById( "categoryList" ); - if( categoryList ) { - //set to default value 'the web' - //hack: hardcoded postion in here replace with a function that finds the entry 'the web' - - for( var i = 0; i < categoryList.options.length; i++ ) - { - if( ( lastCategoryName == "" && categoryList.options[i].value == "NC:SearchEngineRoot" ) || - ( categoryList.options[i].getAttribute("id") == lastCategoryName ) ) { - categoryList.selectedIndex = i; - } - } - - if( lastCategoryName == "" ) - lastCategoryName = "NC:SearchEngineRoot"; - else - lastCategoryName = "NC:SearchCategory?category=" + lastCategoryName; - var treeNode = document.getElementById("searchengines"); - treeNode.setAttribute( "ref", lastCategoryName ); - } - loadEngines( lastCategoryName ); + // try and determine last category name used + var lastCategoryName = ""; + try + { + var pref = Components.classes["component://netscape/preferences"].getService(); + if (pref) pref = pref.QueryInterface( Components.interfaces.nsIPref ); + if (pref) lastCategoryName = pref.CopyCharPref( "browser.search.last_search_category" ); + + if (lastCategoryName != "") + { + // strip off the prefix if necessary + var prefix="NC:SearchCategory?category="; + if (lastCategoryName.indexOf(prefix) == 0) + { + lastCategoryName = lastCategoryName.substr(prefix.length); + } + } + + } + catch( e ) + { + debug("Exception in SearchPanelStartup\n"); + lastCategoryName = ""; + } + debug("\nSearchPanelStartup: lastCategoryName = '" + lastCategoryName + "'\n"); + + // select the appropriate category + var categoryList = document.getElementById( "categoryList" ); + var categoryPopup = document.getElementById( "categoryPopup" ); + if( categoryList && categoryPopup ) + { + //set to default value 'Web' + //hack: hardcoded postion in here replace with a function that finds the entry 'the web' + + var found = false; + for( var i = 0; i < categoryPopup.childNodes.length; i++ ) + { + if( ( lastCategoryName == "" && categoryPopup.childNodes[i].getAttribute("data") == "NC:SearchEngineRoot" ) || + ( categoryPopup.childNodes[i].getAttribute("id") == lastCategoryName ) ) + { + categoryList.selectedItem = categoryPopup.childNodes[i]; + found = true; + break; + } + } + if (found == false) + { + categoryList.selectedItem = categoryPopup.childNodes[0]; + } + + if( lastCategoryName == "" ) + { + lastCategoryName = "NC:SearchEngineRoot"; + } + else + { + lastCategoryName = "NC:SearchCategory?category=" + lastCategoryName; + } + + var treeNode = document.getElementById("searchengines"); + treeNode.setAttribute( "ref", lastCategoryName ); + } + + loadEngines( lastCategoryName ); - // if we have search results, show them, otherwise show engines - if (haveSearchResults() == true) - switchTab(0); - else switchTab(1); + // if we have search results, show them, otherwise show engines + if (haveSearchResults() == true) + { + switchTab(0); + } + else + { + switchTab(1); + } } + + function haveSearchResults() { var resultsTree = document.getElementById("Tree"); @@ -167,6 +227,10 @@ function haveSearchResults() { var textNode = document.getElementById("sidebar-search-text"); if (!textNode) return(false); + + // convert pluses (+) back to spaces + target = target.replace(/+/i, " "); + textNode.value = unescape(target); return(true); } @@ -174,60 +238,86 @@ function haveSearchResults() return(false); } + + function getNumEngines() { var treeNode = document.getElementById("searchengines"); - var numChildren = treeNode.childNodes.length; + var numChildren = treeNode.childNodes.length; + var treeChildrenNode = null; + for (var x = 0; x