From 87c70dead605161e52506c498eb0dab9780845a0 Mon Sep 17 00:00:00 2001 From: "dietrich%mozilla.com" Date: Mon, 7 Apr 2008 15:59:30 +0000 Subject: [PATCH] Bug 405887 - library search should default to Selected Folder (for mak77@supereva.it, r=mano) --- browser/components/places/content/places.js | 70 ++++++++++++++++--- browser/components/places/content/places.xul | 6 -- .../pinstripe/browser/places/organizer.css | 2 +- .../winstripe/browser/places/organizer.css | 31 ++++++++ toolkit/components/places/src/utils.js | 17 +++++ 5 files changed, 109 insertions(+), 17 deletions(-) diff --git a/browser/components/places/content/places.js b/browser/components/places/content/places.js index ae2ba4ce8f3..543eca8d0f5 100755 --- a/browser/components/places/content/places.js +++ b/browser/components/places/content/places.js @@ -223,14 +223,61 @@ var PlacesOrganizer = { searchFilter.reset(); } - // Update the "Find in " command and the gray text in - // the search box in the toolbar if the active collection is the current - // collection. + this._setSearchScopeForNode(node); + }, + + /** + * Sets the search scope based on node's properties + * @param aNode + * the node to set up scope from + */ + _setSearchScopeForNode: function PO__setScopeForNode(aNode) { + var scopeBarFolder = document.getElementById("scopeBarFolder"); + var itemId = aNode.itemId; + if (PlacesUtils.nodeIsHistoryContainer(aNode) || + itemId == PlacesUIUtils.leftPaneQueries["History"]) { + scopeBarFolder.disabled = true; + var folders = []; + var filterCollection = "history"; + var scopeButton = "scopeBarHistory"; + } + else if (PlacesUtils.nodeIsFolder(aNode) && + itemId != PlacesUIUtils.leftPaneQueries["AllBookmarks"] && + itemId != PlacesUIUtils.leftPaneQueries["Tags"] && + aNode.parent.itemId != PlacesUIUtils.leftPaneQueries["Tags"]) { + // enable folder scope + scopeBarFolder.disabled = false; + var folders = [PlacesUtils.getConcreteItemId(aNode)]; + var filterCollection = "collection"; + var scopeButton = "scopeBarFolder"; + } + else { + // default to All Bookmarks + scopeBarFolder.disabled = true; + var folders = []; + var filterCollection = "bookmarks"; + var scopeButton = "scopeBarAll"; + } + + // set search scope + PlacesSearchBox.folders = folders; + PlacesSearchBox.filterCollection = filterCollection; + + // update scope bar active child + var scopeBar = document.getElementById("organizerScopeBar"); + var child = scopeBar.firstChild; + while (child) { + if (child.getAttribute("id") != scopeButton) + child.removeAttribute("checked"); + else + child.setAttribute("checked", "true"); + child = child.nextSibling; + } + + // Update the "Find in " command var findCommand = document.getElementById("OrganizerCommand_find:current"); - var findLabel = PlacesUIUtils.getFormattedString("findInPrefix", [node.title]); + var findLabel = PlacesUIUtils.getFormattedString("findInPrefix", [aNode.title]); findCommand.setAttribute("label", findLabel); - if (PlacesSearchBox.filterCollection == "collection") - PlacesSearchBox.updateCollectionTitle(node.title); }, /** @@ -817,10 +864,13 @@ var PlacesSearchBox = { * The title of the current collection. */ updateCollectionTitle: function PSB_updateCollectionTitle(title) { - this.searchFilter.emptyText = - title ? - PlacesUIUtils.getFormattedString("searchCurrentDefault", [title]) : - PlacesUIUtils.getString("searchBookmarks"); + if (title) + this.searchFilter.emptyText = + PlacesUIUtils.getFormattedString("searchCurrentDefault", [title]); + else + this.searchFilter.emptyText = this.filterCollection == "history" ? + PlacesUIUtils.getString("searchHistory") : + PlacesUIUtils.getString("searchBookmarks"); }, /** diff --git a/browser/components/places/content/places.xul b/browser/components/places/content/places.xul index 9ae77a7b191..2fda38a827b 100755 --- a/browser/components/places/content/places.xul +++ b/browser/components/places/content/places.xul @@ -422,12 +422,6 @@ oncommand="PlacesQueryBuilder.onScopeSelected(this);" label="&search.scopeAll.label;" checked="true"/> - -