2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Places Organizer.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Google Inc.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2005-2006
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Ben Goodger <beng@google.com>
|
|
|
|
* Annie Sullivan <annie.sullivan@gmail.com>
|
|
|
|
* Asaf Romano <mano@mozilla.com>
|
2008-02-13 02:59:23 -08:00
|
|
|
* Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
2009-01-30 04:34:38 -08:00
|
|
|
* Drew Willcoxon <adw@mozilla.com>
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
var PlacesOrganizer = {
|
|
|
|
_places: null,
|
|
|
|
_content: null,
|
|
|
|
|
2007-11-19 18:01:53 -08:00
|
|
|
_initFolderTree: function() {
|
2008-03-13 12:25:49 -07:00
|
|
|
var leftPaneRoot = PlacesUIUtils.leftPaneFolderId;
|
2007-11-19 18:01:53 -08:00
|
|
|
this._places.place = "place:excludeItems=1&expandQueries=0&folder=" + leftPaneRoot;
|
2007-11-26 11:04:23 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
selectLeftPaneQuery: function PO_selectLeftPaneQuery(aQueryName) {
|
2008-03-13 12:25:49 -07:00
|
|
|
var itemId = PlacesUIUtils.leftPaneQueries[aQueryName];
|
2007-11-26 11:04:23 -08:00
|
|
|
this._places.selectItems([itemId]);
|
|
|
|
// Forcefully expand all-bookmarks
|
|
|
|
if (aQueryName == "AllBookmarks")
|
|
|
|
asContainer(this._places.selectedNode).containerOpen = true;
|
2007-11-19 18:01:53 -08:00
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
init: function PO_init() {
|
|
|
|
this._places = document.getElementById("placesList");
|
|
|
|
this._content = document.getElementById("placeContent");
|
2007-11-19 18:01:53 -08:00
|
|
|
this._initFolderTree();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-26 11:04:23 -08:00
|
|
|
var leftPaneSelection = "AllBookmarks"; // default to all-bookmarks
|
|
|
|
if ("arguments" in window && window.arguments.length > 0)
|
|
|
|
leftPaneSelection = window.arguments[0];
|
|
|
|
|
|
|
|
this.selectLeftPaneQuery(leftPaneSelection);
|
2007-12-13 06:29:11 -08:00
|
|
|
// clear the back-stack
|
|
|
|
this._backHistory.splice(0);
|
|
|
|
document.getElementById("OrganizerCommand:Back").setAttribute("disabled", true);
|
2007-11-26 11:04:23 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var view = this._content.treeBoxObject.view;
|
|
|
|
if (view.rowCount > 0)
|
|
|
|
view.selection.select(0);
|
|
|
|
|
|
|
|
this._content.focus();
|
|
|
|
|
|
|
|
// Set up the search UI.
|
|
|
|
PlacesSearchBox.init();
|
|
|
|
|
2008-03-29 11:16:27 -07:00
|
|
|
#ifdef PLACES_QUERY_BUILDER
|
2007-03-22 10:30:00 -07:00
|
|
|
// Set up the advanced query builder UI
|
|
|
|
PlacesQueryBuilder.init();
|
2008-03-29 11:16:27 -07:00
|
|
|
#endif
|
2007-09-22 16:01:08 -07:00
|
|
|
|
2007-12-15 18:24:59 -08:00
|
|
|
window.addEventListener("AppCommand", this, true);
|
2007-09-22 16:01:08 -07:00
|
|
|
#ifdef XP_MACOSX
|
2009-02-28 03:56:12 -08:00
|
|
|
// 1. Map Edit->Find command to OrganizerCommand_find:all. Need to map
|
|
|
|
// both the menuitem and the Find key.
|
2007-12-13 06:26:51 -08:00
|
|
|
var findMenuItem = document.getElementById("menu_find");
|
2009-02-28 03:56:12 -08:00
|
|
|
findMenuItem.setAttribute("command", "OrganizerCommand_find:all");
|
2007-12-13 06:26:51 -08:00
|
|
|
var findKey = document.getElementById("key_find");
|
2009-02-28 03:56:12 -08:00
|
|
|
findKey.setAttribute("command", "OrganizerCommand_find:all");
|
2007-09-22 16:01:08 -07:00
|
|
|
|
|
|
|
// 2. Disable some keybindings from browser.xul
|
|
|
|
var elements = ["cmd_handleBackspace", "cmd_handleShiftBackspace"];
|
|
|
|
for (var i=0; i < elements.length; i++) {
|
|
|
|
document.getElementById(elements[i]).setAttribute("disabled", "true");
|
|
|
|
}
|
2008-03-07 15:55:06 -08:00
|
|
|
|
|
|
|
// 3. Disable the keyboard shortcut for the History menu back/forward
|
|
|
|
// in order to support those in the Library
|
|
|
|
var historyMenuBack = document.getElementById("historyMenuBack");
|
|
|
|
historyMenuBack.removeAttribute("key");
|
|
|
|
var historyMenuForward = document.getElementById("historyMenuForward");
|
|
|
|
historyMenuForward.removeAttribute("key");
|
2007-09-22 16:01:08 -07:00
|
|
|
#endif
|
2008-04-20 19:32:43 -07:00
|
|
|
|
|
|
|
// remove the "Properties" context-menu item, we've our own details pane
|
|
|
|
document.getElementById("placesContext")
|
|
|
|
.removeChild(document.getElementById("placesContext_show:info"));
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2007-12-15 18:24:59 -08:00
|
|
|
QueryInterface: function PO_QueryInterface(aIID) {
|
|
|
|
if (aIID.equals(Components.interfaces.nsIDOMEventListener) ||
|
|
|
|
aIID.equals(Components.interfaces.nsISupports))
|
|
|
|
return this;
|
|
|
|
|
|
|
|
throw Components.results.NS_NOINTERFACE;
|
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function PO_handleEvent(aEvent) {
|
|
|
|
if (aEvent.type != "AppCommand")
|
|
|
|
return;
|
|
|
|
|
|
|
|
aEvent.stopPropagation();
|
|
|
|
switch (aEvent.command) {
|
|
|
|
case "Back":
|
|
|
|
if (this._backHistory.length > 0)
|
|
|
|
this.back();
|
|
|
|
break;
|
|
|
|
case "Forward":
|
|
|
|
if (this._forwardHistory.length > 0)
|
|
|
|
this.forward();
|
|
|
|
break;
|
|
|
|
case "Search":
|
|
|
|
PlacesSearchBox.findAll();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
destroy: function PO_destroy() {
|
|
|
|
},
|
|
|
|
|
2007-09-18 14:26:46 -07:00
|
|
|
_location: null,
|
|
|
|
get location() {
|
|
|
|
return this._location;
|
|
|
|
},
|
|
|
|
|
|
|
|
set location(aLocation) {
|
2007-12-13 06:29:11 -08:00
|
|
|
if (!aLocation || this._location == aLocation)
|
2007-09-18 14:26:46 -07:00
|
|
|
return aLocation;
|
|
|
|
|
2007-12-13 06:29:11 -08:00
|
|
|
if (this.location) {
|
2007-09-18 14:26:46 -07:00
|
|
|
this._backHistory.unshift(this.location);
|
2007-12-13 06:29:11 -08:00
|
|
|
this._forwardHistory.splice(0);
|
|
|
|
}
|
2007-09-18 14:26:46 -07:00
|
|
|
|
2007-12-13 06:29:11 -08:00
|
|
|
this._location = aLocation;
|
|
|
|
this._places.selectPlaceURI(aLocation);
|
|
|
|
|
|
|
|
if (!this._places.hasSelection) {
|
|
|
|
// If no node was found for the given place: uri, just load it directly
|
|
|
|
this._content.place = aLocation;
|
|
|
|
}
|
2007-09-21 15:57:18 -07:00
|
|
|
this.onContentTreeSelect();
|
2007-09-18 14:26:46 -07:00
|
|
|
|
|
|
|
// update navigation commands
|
|
|
|
if (this._backHistory.length == 0)
|
|
|
|
document.getElementById("OrganizerCommand:Back").setAttribute("disabled", true);
|
|
|
|
else
|
|
|
|
document.getElementById("OrganizerCommand:Back").removeAttribute("disabled");
|
|
|
|
if (this._forwardHistory.length == 0)
|
|
|
|
document.getElementById("OrganizerCommand:Forward").setAttribute("disabled", true);
|
|
|
|
else
|
|
|
|
document.getElementById("OrganizerCommand:Forward").removeAttribute("disabled");
|
|
|
|
|
|
|
|
return aLocation;
|
|
|
|
},
|
|
|
|
|
|
|
|
_backHistory: [],
|
|
|
|
_forwardHistory: [],
|
2007-12-13 06:29:11 -08:00
|
|
|
|
2007-09-18 14:26:46 -07:00
|
|
|
back: function PO_back() {
|
|
|
|
this._forwardHistory.unshift(this.location);
|
|
|
|
var historyEntry = this._backHistory.shift();
|
|
|
|
this._location = null;
|
|
|
|
this.location = historyEntry;
|
|
|
|
},
|
|
|
|
forward: function PO_forward() {
|
2007-12-13 06:29:11 -08:00
|
|
|
this._backHistory.unshift(this.location);
|
2007-09-18 14:26:46 -07:00
|
|
|
var historyEntry = this._forwardHistory.shift();
|
2007-12-13 06:29:11 -08:00
|
|
|
this._location = null;
|
2007-09-18 14:26:46 -07:00
|
|
|
this.location = historyEntry;
|
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Called when a place folder is selected in the left pane.
|
|
|
|
* @param resetSearchBox
|
2009-02-28 03:56:12 -08:00
|
|
|
* true if the search box should also be reset, false otherwise.
|
|
|
|
* The search box should be reset when a new folder in the left
|
|
|
|
* pane is selected; the search scope and text need to be cleared in
|
|
|
|
* preparation for the new folder. Note that if the user manually
|
|
|
|
* resets the search box, either by clicking its reset button or by
|
|
|
|
* deleting its text, this will be false.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2009-02-28 03:56:12 -08:00
|
|
|
_cachedLeftPaneSelectedURI: null,
|
2007-03-22 10:30:00 -07:00
|
|
|
onPlaceSelected: function PO_onPlaceSelected(resetSearchBox) {
|
2009-02-28 03:56:12 -08:00
|
|
|
// Don't change the right-hand pane contents when there's no selection.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!this._places.hasSelection)
|
|
|
|
return;
|
2007-09-18 14:26:46 -07:00
|
|
|
|
2007-12-13 06:29:11 -08:00
|
|
|
var node = this._places.selectedNode;
|
|
|
|
var queries = asQuery(node).getQueries({});
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-02-28 03:56:12 -08:00
|
|
|
// Items are only excluded on the left pane.
|
2007-03-22 10:30:00 -07:00
|
|
|
var options = node.queryOptions.clone();
|
|
|
|
options.excludeItems = false;
|
2009-02-28 03:56:12 -08:00
|
|
|
var placeURI = PlacesUtils.history.queriesToQueryString(queries,
|
|
|
|
queries.length,
|
|
|
|
options);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-02-28 03:56:12 -08:00
|
|
|
// If either the place of the content tree in the right pane has changed or
|
|
|
|
// the user cleared the search box, update the place, hide the search UI,
|
|
|
|
// and update the back/forward buttons by setting location.
|
2008-04-29 10:59:18 -07:00
|
|
|
if (this._content.place != placeURI || !resetSearchBox) {
|
2008-02-16 22:17:34 -08:00
|
|
|
this._content.place = placeURI;
|
2009-02-28 03:56:12 -08:00
|
|
|
PlacesSearchBox.hideSearchUI();
|
2008-04-29 10:59:18 -07:00
|
|
|
this.location = node.uri;
|
|
|
|
}
|
2007-09-21 15:57:18 -07:00
|
|
|
|
2009-03-17 14:00:44 -07:00
|
|
|
// Update the selected folder title where it appears in the UI: the folder
|
|
|
|
// scope button, "Find in <current collection>" command, and the search box
|
|
|
|
// emptytext. They must be updated even if the selection hasn't changed --
|
|
|
|
// specifically when node's title changes. In that case a selection event
|
|
|
|
// is generated, this method is called, but the selection does not change.
|
|
|
|
var folderButton = document.getElementById("scopeBarFolder");
|
|
|
|
var folderTitle = node.title || folderButton.getAttribute("emptytitle");
|
|
|
|
folderButton.setAttribute("label", folderTitle);
|
|
|
|
var cmd = document.getElementById("OrganizerCommand_find:current");
|
|
|
|
var label = PlacesUIUtils.getFormattedString("findInPrefix", [folderTitle]);
|
|
|
|
cmd.setAttribute("label", label);
|
|
|
|
if (PlacesSearchBox.filterCollection == "collection")
|
|
|
|
PlacesSearchBox.updateCollectionTitle(folderTitle);
|
|
|
|
|
2009-02-27 13:39:02 -08:00
|
|
|
// When we invalidate a container we use suppressSelectionEvent, when it is
|
|
|
|
// unset a select event is fired, in many cases the selection did not really
|
|
|
|
// change, so we should check for it, and return early in such a case. Note
|
|
|
|
// that we cannot return any earlier than this point, because when
|
|
|
|
// !resetSearchBox, we need to update location and hide the UI as above,
|
|
|
|
// even though the selection has not changed.
|
2009-02-28 03:56:12 -08:00
|
|
|
if (node.uri == this._cachedLeftPaneSelectedURI)
|
2009-02-27 13:39:02 -08:00
|
|
|
return;
|
2009-02-28 03:56:12 -08:00
|
|
|
this._cachedLeftPaneSelectedURI = node.uri;
|
2009-02-27 13:39:02 -08:00
|
|
|
|
2009-02-28 03:56:12 -08:00
|
|
|
// At this point, resetSearchBox is true, because the left pane selection
|
|
|
|
// has changed; otherwise we would have returned earlier.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-02-28 03:56:12 -08:00
|
|
|
PlacesSearchBox.searchFilter.reset();
|
2008-04-07 08:59:30 -07:00
|
|
|
this._setSearchScopeForNode(node);
|
2008-05-01 08:41:37 -07:00
|
|
|
if (this._places.treeBoxObject.focused)
|
2008-09-29 23:10:47 -07:00
|
|
|
this._fillDetailsPane([node]);
|
2008-04-07 08:59:30 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2009-02-28 03:56:12 -08:00
|
|
|
* Sets the search scope based on aNode's properties.
|
2008-04-07 08:59:30 -07:00
|
|
|
* @param aNode
|
|
|
|
* the node to set up scope from
|
|
|
|
*/
|
|
|
|
_setSearchScopeForNode: function PO__setScopeForNode(aNode) {
|
|
|
|
var itemId = aNode.itemId;
|
|
|
|
if (PlacesUtils.nodeIsHistoryContainer(aNode) ||
|
|
|
|
itemId == PlacesUIUtils.leftPaneQueries["History"]) {
|
2009-02-28 03:56:12 -08:00
|
|
|
PlacesQueryBuilder.setScope("history");
|
2008-04-07 08:59:30 -07:00
|
|
|
}
|
2009-02-28 03:56:12 -08:00
|
|
|
// Default to All Bookmarks for all other nodes, per bug 469437.
|
|
|
|
else
|
|
|
|
PlacesQueryBuilder.setScope("bookmarks");
|
|
|
|
|
|
|
|
// Enable or disable the folder scope button.
|
|
|
|
var folderButton = document.getElementById("scopeBarFolder");
|
2009-03-17 14:00:44 -07:00
|
|
|
folderButton.hidden = !PlacesUtils.nodeIsFolder(aNode) ||
|
|
|
|
itemId == PlacesUIUtils.allBookmarksFolderId;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2009-05-14 05:11:46 -07:00
|
|
|
* Handle clicks on the tree.
|
|
|
|
* Single Left click, right click or modified click do not result in any
|
|
|
|
* special action, since they're related to selection.
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param aEvent
|
|
|
|
* The mouse event.
|
|
|
|
*/
|
2007-09-24 19:21:58 -07:00
|
|
|
onTreeClick: function PO_onTreeClick(aEvent) {
|
2009-05-14 05:11:46 -07:00
|
|
|
// Only handle clicks on tree children.
|
2007-11-20 17:35:14 -08:00
|
|
|
if (aEvent.target.localName != "treechildren")
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
2007-11-20 17:35:14 -08:00
|
|
|
|
2008-02-26 02:37:59 -08:00
|
|
|
var currentView = aEvent.currentTarget;
|
2008-02-25 13:45:22 -08:00
|
|
|
var selectedNode = currentView.selectedNode;
|
2009-05-14 05:11:46 -07:00
|
|
|
if (selectedNode) {
|
|
|
|
var doubleClickOnFlatList = (aEvent.button == 0 && aEvent.detail == 2 &&
|
|
|
|
aEvent.target.parentNode.flatList);
|
2009-06-11 21:07:06 -07:00
|
|
|
var middleClick = (aEvent.button == 1 && aEvent.detail == 1);
|
2009-05-14 05:11:46 -07:00
|
|
|
|
|
|
|
if (PlacesUtils.nodeIsURI(selectedNode) &&
|
|
|
|
(doubleClickOnFlatList || middleClick)) {
|
|
|
|
// Open associated uri in the browser.
|
|
|
|
PlacesOrganizer.openSelectedNode(aEvent);
|
|
|
|
}
|
|
|
|
else if (middleClick &&
|
|
|
|
PlacesUtils.nodeIsContainer(selectedNode)) {
|
|
|
|
// The command execution function will take care of seeing if the
|
|
|
|
// selection is a folder or a different container type, and will
|
|
|
|
// load its contents in tabs.
|
2008-09-08 14:34:04 -07:00
|
|
|
PlacesUIUtils.openContainerNodeInTabs(selectedNode, aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-04-25 09:47:35 -07:00
|
|
|
/**
|
|
|
|
* Handle focus changes on the trees.
|
|
|
|
* When moving focus between panes we should update the details pane contents.
|
|
|
|
* @param aEvent
|
|
|
|
* The mouse event.
|
|
|
|
*/
|
|
|
|
onTreeFocus: function PO_onTreeFocus(aEvent) {
|
|
|
|
var currentView = aEvent.currentTarget;
|
2008-09-29 23:10:47 -07:00
|
|
|
var selectedNodes = currentView.selectedNode ? [currentView.selectedNode] :
|
|
|
|
this._content.getSelectionNodes();
|
|
|
|
this._fillDetailsPane(selectedNodes);
|
2008-04-25 09:47:35 -07:00
|
|
|
},
|
|
|
|
|
2008-02-16 22:17:34 -08:00
|
|
|
openFlatContainer: function PO_openFlatContainerFlatContainer(aContainer) {
|
|
|
|
if (aContainer.itemId != -1)
|
|
|
|
this._places.selectItems([aContainer.itemId]);
|
|
|
|
else if (PlacesUtils.nodeIsQuery(aContainer))
|
|
|
|
this._places.selectPlaceURI(aContainer.uri);
|
2007-11-19 18:01:53 -08:00
|
|
|
},
|
|
|
|
|
2009-02-04 09:49:44 -08:00
|
|
|
openSelectedNode: function PO_openSelectedNode(aEvent) {
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUIUtils.openNodeWithEvent(this._content.selectedNode, aEvent);
|
2007-09-24 19:21:58 -07:00
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Returns the options associated with the query currently loaded in the
|
|
|
|
* main places pane.
|
|
|
|
*/
|
|
|
|
getCurrentOptions: function PO_getCurrentOptions() {
|
|
|
|
return asQuery(this._content.getResult().root).queryOptions;
|
|
|
|
},
|
2007-09-21 15:57:18 -07:00
|
|
|
|
2008-02-04 10:10:28 -08:00
|
|
|
/**
|
|
|
|
* Returns the queries associated with the query currently loaded in the
|
|
|
|
* main places pane.
|
|
|
|
*/
|
|
|
|
getCurrentQueries: function PO_getCurrentQueries() {
|
|
|
|
return asQuery(this._content.getResult().root).getQueries({});
|
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Show the migration wizard for importing from a file.
|
|
|
|
*/
|
|
|
|
importBookmarks: function PO_import() {
|
|
|
|
// XXX: ifdef it to be non-modal (non-"sheet") on mac (see bug 259039)
|
|
|
|
var features = "modal,centerscreen,chrome,resizable=no";
|
|
|
|
|
|
|
|
// The migrator window will set this to true when it closes, if the user
|
|
|
|
// chose to migrate from a specific file.
|
|
|
|
window.fromFile = false;
|
|
|
|
openDialog("chrome://browser/content/migration/migration.xul",
|
|
|
|
"migration", features, "bookmarks");
|
|
|
|
if (window.fromFile)
|
2008-04-03 13:51:54 -07:00
|
|
|
this.importFromFile();
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-09-09 18:02:41 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Open a file-picker and import the selected file into the bookmarks store
|
|
|
|
*/
|
|
|
|
importFromFile: function PO_importFromFile() {
|
|
|
|
var fp = Cc["@mozilla.org/filepicker;1"].
|
|
|
|
createInstance(Ci.nsIFilePicker);
|
2008-03-13 12:25:49 -07:00
|
|
|
fp.init(window, PlacesUIUtils.getString("SelectImport"),
|
2007-03-22 10:30:00 -07:00
|
|
|
Ci.nsIFilePicker.modeOpen);
|
2008-04-03 13:51:54 -07:00
|
|
|
fp.appendFilters(Ci.nsIFilePicker.filterHTML);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (fp.show() != Ci.nsIFilePicker.returnCancel) {
|
2007-05-03 01:56:41 -07:00
|
|
|
if (fp.file) {
|
|
|
|
var importer = Cc["@mozilla.org/browser/places/import-export-service;1"].
|
|
|
|
getService(Ci.nsIPlacesImportExportService);
|
2007-05-07 11:27:38 -07:00
|
|
|
var file = fp.file.QueryInterface(Ci.nsILocalFile);
|
2007-05-16 23:06:48 -07:00
|
|
|
importer.importHTMLFromFile(file, false);
|
2007-05-03 01:56:41 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows simple exporting of bookmarks.
|
|
|
|
*/
|
|
|
|
exportBookmarks: function PO_exportBookmarks() {
|
|
|
|
var fp = Cc["@mozilla.org/filepicker;1"].
|
|
|
|
createInstance(Ci.nsIFilePicker);
|
2008-03-13 12:25:49 -07:00
|
|
|
fp.init(window, PlacesUIUtils.getString("EnterExport"),
|
2007-03-22 10:30:00 -07:00
|
|
|
Ci.nsIFilePicker.modeSave);
|
|
|
|
fp.appendFilters(Ci.nsIFilePicker.filterHTML);
|
|
|
|
fp.defaultString = "bookmarks.html";
|
2007-05-03 01:56:41 -07:00
|
|
|
if (fp.show() != Ci.nsIFilePicker.returnCancel) {
|
|
|
|
var exporter = Cc["@mozilla.org/browser/places/import-export-service;1"].
|
|
|
|
getService(Ci.nsIPlacesImportExportService);
|
|
|
|
exporter.exportHTMLToFile(fp.file);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2007-09-09 18:02:41 -07:00
|
|
|
/**
|
|
|
|
* Populates the restore menu with the dates of the backups available.
|
|
|
|
*/
|
|
|
|
populateRestoreMenu: function PO_populateRestoreMenu() {
|
|
|
|
var restorePopup = document.getElementById("fileRestorePopup");
|
|
|
|
|
2009-02-17 06:15:01 -08:00
|
|
|
var dateSvc = Cc["@mozilla.org/intl/scriptabledateformat;1"].
|
|
|
|
getService(Ci.nsIScriptableDateFormat);
|
|
|
|
|
2007-09-09 18:02:41 -07:00
|
|
|
// remove existing menu items
|
|
|
|
// last item is the restoreFromFile item
|
|
|
|
while (restorePopup.childNodes.length > 1)
|
|
|
|
restorePopup.removeChild(restorePopup.firstChild);
|
|
|
|
|
|
|
|
// get list of files
|
2008-11-13 08:54:25 -08:00
|
|
|
var localizedFilename = PlacesUtils.getString("bookmarksArchiveFilename");
|
|
|
|
var localizedFilenamePrefix = localizedFilename.substr(0, localizedFilename.indexOf("-"));
|
2007-09-09 18:02:41 -07:00
|
|
|
var fileList = [];
|
2008-04-02 09:19:00 -07:00
|
|
|
var files = this.bookmarksBackupDir.directoryEntries;
|
2007-09-09 18:02:41 -07:00
|
|
|
while (files.hasMoreElements()) {
|
|
|
|
var f = files.getNext().QueryInterface(Ci.nsIFile);
|
2009-02-17 06:15:01 -08:00
|
|
|
var rx = new RegExp("^(bookmarks|" + localizedFilenamePrefix +
|
|
|
|
")-([0-9]{4}-[0-9]{2}-[0-9]{2})\.json$");
|
|
|
|
if (!f.isHidden() && f.leafName.match(rx)) {
|
|
|
|
var date = f.leafName.match(rx)[2].replace(/-/g, "/");
|
|
|
|
var dateObj = new Date(date);
|
|
|
|
fileList.push({date: dateObj, filename: f.leafName});
|
|
|
|
}
|
2007-09-09 18:02:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fileList.sort(function PO_fileList_compare(a, b) {
|
2009-02-17 06:15:01 -08:00
|
|
|
return b.date - a.date;
|
2008-03-13 12:25:49 -07:00
|
|
|
});
|
2007-09-09 18:02:41 -07:00
|
|
|
|
|
|
|
if (fileList.length == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// populate menu
|
|
|
|
for (var i = 0; i < fileList.length; i++) {
|
|
|
|
var m = restorePopup.insertBefore
|
|
|
|
(document.createElement("menuitem"),
|
|
|
|
document.getElementById("restoreFromFile"));
|
2009-02-17 06:15:01 -08:00
|
|
|
m.setAttribute("label",
|
|
|
|
dateSvc.FormatDate("",
|
|
|
|
Ci.nsIScriptableDateFormat.dateFormatLong,
|
|
|
|
fileList[i].date.getFullYear(),
|
|
|
|
fileList[i].date.getMonth() + 1,
|
|
|
|
fileList[i].date.getDate()));
|
|
|
|
m.setAttribute("value", fileList[i].filename);
|
2007-09-09 18:02:41 -07:00
|
|
|
m.setAttribute("oncommand",
|
|
|
|
"PlacesOrganizer.onRestoreMenuItemClick(this);");
|
|
|
|
}
|
|
|
|
restorePopup.insertBefore(document.createElement("menuseparator"),
|
|
|
|
document.getElementById("restoreFromFile"));
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when a menuitem is selected from the restore menu.
|
|
|
|
*/
|
|
|
|
onRestoreMenuItemClick: function PO_onRestoreMenuItemClick(aMenuItem) {
|
|
|
|
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
|
2007-09-21 15:57:18 -07:00
|
|
|
getService(Ci.nsIProperties);
|
2007-09-09 18:02:41 -07:00
|
|
|
var bookmarksFile = dirSvc.get("ProfD", Ci.nsIFile);
|
2007-09-21 15:57:18 -07:00
|
|
|
bookmarksFile.append("bookmarkbackups");
|
2007-09-09 18:02:41 -07:00
|
|
|
bookmarksFile.append(aMenuItem.getAttribute("value"));
|
|
|
|
if (!bookmarksFile.exists())
|
|
|
|
return;
|
2008-03-13 12:25:49 -07:00
|
|
|
this.restoreBookmarksFromFile(bookmarksFile);
|
2007-09-09 18:02:41 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2008-03-13 12:25:49 -07:00
|
|
|
* Called when 'Choose File...' is selected from the restore menu.
|
|
|
|
* Prompts for a file and restores bookmarks to those in the file.
|
2007-09-09 18:02:41 -07:00
|
|
|
*/
|
2008-03-13 12:25:49 -07:00
|
|
|
onRestoreBookmarksFromFile: function PO_onRestoreBookmarksFromFile() {
|
2007-09-09 18:02:41 -07:00
|
|
|
var fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
|
2008-03-13 12:25:49 -07:00
|
|
|
fp.init(window, PlacesUIUtils.getString("bookmarksRestoreTitle"),
|
|
|
|
Ci.nsIFilePicker.modeOpen);
|
2008-04-03 13:51:54 -07:00
|
|
|
fp.appendFilter(PlacesUIUtils.getString("bookmarksRestoreFilterName"),
|
|
|
|
PlacesUIUtils.getString("bookmarksRestoreFilterExtension"));
|
2009-04-24 02:22:41 -07:00
|
|
|
fp.appendFilters(Ci.nsIFilePicker.filterAll);
|
2007-09-21 15:57:18 -07:00
|
|
|
|
2007-09-09 18:02:41 -07:00
|
|
|
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
|
2007-09-21 15:57:18 -07:00
|
|
|
getService(Ci.nsIProperties);
|
2007-09-09 18:02:41 -07:00
|
|
|
var backupsDir = dirSvc.get("Desk", Ci.nsILocalFile);
|
|
|
|
fp.displayDirectory = backupsDir;
|
|
|
|
|
2008-03-13 12:25:49 -07:00
|
|
|
if (fp.show() != Ci.nsIFilePicker.returnCancel)
|
2008-04-03 13:51:54 -07:00
|
|
|
this.restoreBookmarksFromFile(fp.file);
|
2007-09-09 18:02:41 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2008-04-03 13:51:54 -07:00
|
|
|
* Restores bookmarks from a JSON file.
|
2007-09-09 18:02:41 -07:00
|
|
|
*/
|
2008-03-13 12:25:49 -07:00
|
|
|
restoreBookmarksFromFile: function PO_restoreBookmarksFromFile(aFile) {
|
2008-04-03 13:51:54 -07:00
|
|
|
// check file extension
|
|
|
|
if (!aFile.leafName.match(/\.json$/)) {
|
|
|
|
this._showErrorAlert(PlacesUIUtils.getString("bookmarksRestoreFormatError"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// confirm ok to delete existing bookmarks
|
2007-09-09 18:02:41 -07:00
|
|
|
var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"].
|
2007-09-21 15:57:18 -07:00
|
|
|
getService(Ci.nsIPromptService);
|
2008-03-13 12:25:49 -07:00
|
|
|
if (!prompts.confirm(null,
|
|
|
|
PlacesUIUtils.getString("bookmarksRestoreAlertTitle"),
|
|
|
|
PlacesUIUtils.getString("bookmarksRestoreAlert")))
|
2007-09-09 18:02:41 -07:00
|
|
|
return;
|
2007-09-21 15:57:18 -07:00
|
|
|
|
2008-04-03 13:51:54 -07:00
|
|
|
try {
|
2009-01-21 03:39:07 -08:00
|
|
|
PlacesUtils.restoreBookmarksFromJSONFile(aFile);
|
2008-03-13 12:25:49 -07:00
|
|
|
}
|
2008-04-03 13:51:54 -07:00
|
|
|
catch(ex) {
|
|
|
|
this._showErrorAlert(PlacesUIUtils.getString("bookmarksRestoreParseError"));
|
2008-03-13 12:25:49 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-04-03 13:51:54 -07:00
|
|
|
_showErrorAlert: function PO__showErrorAlert(aMsg) {
|
|
|
|
var brandShortName = document.getElementById("brandStrings").
|
|
|
|
getString("brandShortName");
|
|
|
|
|
|
|
|
Cc["@mozilla.org/embedcomp/prompt-service;1"].
|
|
|
|
getService(Ci.nsIPromptService).
|
|
|
|
alert(window, brandShortName, aMsg);
|
|
|
|
},
|
|
|
|
|
2008-03-13 12:25:49 -07:00
|
|
|
/**
|
|
|
|
* Backup bookmarks to desktop, auto-generate a filename with a date.
|
|
|
|
* The file is a JSON serialization of bookmarks, tags and any annotations
|
|
|
|
* of those items.
|
|
|
|
*/
|
|
|
|
backupBookmarks: function PO_backupBookmarks() {
|
2007-09-09 18:02:41 -07:00
|
|
|
var fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
|
2008-03-13 12:25:49 -07:00
|
|
|
fp.init(window, PlacesUIUtils.getString("bookmarksBackupTitle"),
|
|
|
|
Ci.nsIFilePicker.modeSave);
|
2008-04-03 13:51:54 -07:00
|
|
|
fp.appendFilter(PlacesUIUtils.getString("bookmarksRestoreFilterName"),
|
|
|
|
PlacesUIUtils.getString("bookmarksRestoreFilterExtension"));
|
2007-09-21 15:57:18 -07:00
|
|
|
|
2007-09-09 18:02:41 -07:00
|
|
|
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
|
2007-09-21 15:57:18 -07:00
|
|
|
getService(Ci.nsIProperties);
|
2007-09-09 18:02:41 -07:00
|
|
|
var backupsDir = dirSvc.get("Desk", Ci.nsILocalFile);
|
|
|
|
fp.displayDirectory = backupsDir;
|
2007-09-21 15:57:18 -07:00
|
|
|
|
2009-08-06 07:34:16 -07:00
|
|
|
fp.defaultString = PlacesUtils.getBackupFilename();
|
2008-03-13 12:25:49 -07:00
|
|
|
|
2008-04-02 09:19:00 -07:00
|
|
|
if (fp.show() != Ci.nsIFilePicker.returnCancel) {
|
2009-01-21 03:39:07 -08:00
|
|
|
PlacesUtils.backupBookmarksToFile(fp.file);
|
2008-04-02 09:19:00 -07:00
|
|
|
|
|
|
|
// copy new backup to /backups dir (bug 424389)
|
|
|
|
var latestBackup = PlacesUtils.getMostRecentBackup();
|
2008-05-06 13:58:45 -07:00
|
|
|
if (!latestBackup || latestBackup != fp.file) {
|
2008-04-03 13:51:54 -07:00
|
|
|
latestBackup.remove(false);
|
2009-08-06 07:34:16 -07:00
|
|
|
var name = PlacesUtils.getBackupFilename();
|
2008-04-02 09:19:00 -07:00
|
|
|
fp.file.copyTo(this.bookmarksBackupDir, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
get bookmarksBackupDir() {
|
|
|
|
delete this.bookmarksBackupDir;
|
|
|
|
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
|
|
|
|
getService(Ci.nsIProperties);
|
|
|
|
var bookmarksBackupDir = dirSvc.get("ProfD", Ci.nsIFile);
|
|
|
|
bookmarksBackupDir.append("bookmarkbackups");
|
|
|
|
if (!bookmarksBackupDir.exists())
|
2008-04-03 13:51:54 -07:00
|
|
|
bookmarksBackupDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0700);
|
2008-04-02 09:19:00 -07:00
|
|
|
return this.bookmarksBackupDir = bookmarksBackupDir;
|
2007-09-09 18:02:41 -07:00
|
|
|
},
|
|
|
|
|
2007-09-21 15:57:18 -07:00
|
|
|
_paneDisabled: false,
|
|
|
|
_setDetailsFieldsDisabledState:
|
|
|
|
function PO__setDetailsFieldsDisabledState(aDisabled) {
|
|
|
|
if (aDisabled) {
|
|
|
|
document.getElementById("paneElementsBroadcaster")
|
|
|
|
.setAttribute("disabled", "true");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
document.getElementById("paneElementsBroadcaster")
|
|
|
|
.removeAttribute("disabled");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_detectAndSetDetailsPaneMinimalState:
|
|
|
|
function PO__detectAndSetDetailsPaneMinimalState(aNode) {
|
|
|
|
/**
|
|
|
|
* The details of simple folder-items (as opposed to livemarks) or the
|
2008-04-13 18:07:47 -07:00
|
|
|
* of livemark-children are not likely to fill the infoBox anyway,
|
2007-09-21 15:57:18 -07:00
|
|
|
* thus we remove the "More/Less" button and show all details.
|
|
|
|
*
|
|
|
|
* the wasminimal attribute here is used to persist the "more/less"
|
|
|
|
* state in a bookmark->folder->bookmark scenario.
|
|
|
|
*/
|
2008-04-08 22:49:49 -07:00
|
|
|
var infoBox = document.getElementById("infoBox");
|
|
|
|
var infoBoxExpander = document.getElementById("infoBoxExpander");
|
2009-01-23 03:52:14 -08:00
|
|
|
var infoBoxExpanderWrapper = document.getElementById("infoBoxExpanderWrapper");
|
|
|
|
|
2008-09-29 23:10:47 -07:00
|
|
|
if (!aNode) {
|
2009-01-23 03:52:14 -08:00
|
|
|
infoBoxExpanderWrapper.hidden = true;
|
2008-09-29 23:10:47 -07:00
|
|
|
return;
|
|
|
|
}
|
2008-04-20 17:33:02 -07:00
|
|
|
if (aNode.itemId != -1 &&
|
|
|
|
((PlacesUtils.nodeIsFolder(aNode) &&
|
|
|
|
!PlacesUtils.nodeIsLivemarkContainer(aNode)) ||
|
|
|
|
PlacesUtils.nodeIsLivemarkItem(aNode))) {
|
2008-04-08 22:49:49 -07:00
|
|
|
if (infoBox.getAttribute("minimal") == "true")
|
|
|
|
infoBox.setAttribute("wasminimal", "true");
|
|
|
|
infoBox.removeAttribute("minimal");
|
2009-01-23 03:52:14 -08:00
|
|
|
infoBoxExpanderWrapper.hidden = true;
|
2007-09-21 15:57:18 -07:00
|
|
|
}
|
|
|
|
else {
|
2008-04-08 22:49:49 -07:00
|
|
|
if (infoBox.getAttribute("wasminimal") == "true")
|
|
|
|
infoBox.setAttribute("minimal", "true");
|
|
|
|
infoBox.removeAttribute("wasminimal");
|
2009-01-23 03:52:14 -08:00
|
|
|
infoBoxExpanderWrapper.hidden = false;
|
2007-09-21 15:57:18 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2007-11-19 18:01:53 -08:00
|
|
|
// NOT YET USED
|
2007-09-21 15:57:18 -07:00
|
|
|
updateThumbnailProportions: function PO_updateThumbnailProportions() {
|
|
|
|
var previewBox = document.getElementById("previewBox");
|
|
|
|
var canvas = document.getElementById("itemThumbnail");
|
|
|
|
var height = previewBox.boxObject.height;
|
|
|
|
var width = height * (screen.width / screen.height);
|
|
|
|
canvas.width = width;
|
|
|
|
canvas.height = height;
|
|
|
|
},
|
|
|
|
|
2007-08-22 07:42:37 -07:00
|
|
|
onContentTreeSelect: function PO_onContentTreeSelect() {
|
2008-05-01 08:41:37 -07:00
|
|
|
if (this._content.treeBoxObject.focused)
|
2008-09-29 23:10:47 -07:00
|
|
|
this._fillDetailsPane(this._content.getSelectionNodes());
|
2008-04-25 09:47:35 -07:00
|
|
|
},
|
|
|
|
|
2008-09-29 23:10:47 -07:00
|
|
|
_fillDetailsPane: function PO__fillDetailsPane(aNodeList) {
|
2008-04-25 09:47:35 -07:00
|
|
|
var infoBox = document.getElementById("infoBox");
|
|
|
|
var detailsDeck = document.getElementById("detailsDeck");
|
2008-12-07 06:42:10 -08:00
|
|
|
|
|
|
|
// Make sure the infoBox UI is visible if we need to use it, we hide it
|
|
|
|
// below when we don't.
|
|
|
|
infoBox.hidden = false;
|
2008-09-29 23:10:47 -07:00
|
|
|
var aSelectedNode = aNodeList.length == 1 ? aNodeList[0] : null;
|
2007-09-21 15:57:18 -07:00
|
|
|
// If a textbox within a panel is focused, force-blur it so its contents
|
|
|
|
// are saved
|
|
|
|
if (gEditItemOverlay.itemId != -1) {
|
|
|
|
var focusedElement = document.commandDispatcher.focusedElement;
|
2007-10-24 02:33:09 -07:00
|
|
|
if ((focusedElement instanceof HTMLInputElement ||
|
|
|
|
focusedElement instanceof HTMLTextAreaElement) &&
|
2007-09-21 15:57:18 -07:00
|
|
|
/^editBMPanel.*/.test(focusedElement.parentNode.parentNode.id))
|
|
|
|
focusedElement.blur();
|
|
|
|
|
2008-09-29 23:10:47 -07:00
|
|
|
// don't update the panel if we are already editing this node unless we're
|
|
|
|
// in multi-edit mode
|
2009-05-18 16:07:01 -07:00
|
|
|
if (aSelectedNode) {
|
|
|
|
var concreteId = PlacesUtils.getConcreteItemId(aSelectedNode);
|
|
|
|
var nodeIsSame = gEditItemOverlay.itemId == aSelectedNode.itemId ||
|
|
|
|
gEditItemOverlay.itemId == concreteId ||
|
|
|
|
(aSelectedNode.itemId == -1 && gEditItemOverlay.uri &&
|
|
|
|
gEditItemOverlay.uri == aSelectedNode.uri);
|
|
|
|
if (nodeIsSame && detailsDeck.selectedIndex == 1 &&
|
|
|
|
!gEditItemOverlay.multiEdit)
|
|
|
|
return;
|
|
|
|
}
|
2008-04-25 09:47:35 -07:00
|
|
|
}
|
2009-01-13 02:48:28 -08:00
|
|
|
|
|
|
|
// Clean up the panel before initing it again.
|
|
|
|
gEditItemOverlay.uninitPanel(false);
|
|
|
|
|
2008-04-25 09:47:35 -07:00
|
|
|
if (aSelectedNode && !PlacesUtils.nodeIsSeparator(aSelectedNode)) {
|
2008-04-20 17:33:02 -07:00
|
|
|
detailsDeck.selectedIndex = 1;
|
2009-03-18 07:23:56 -07:00
|
|
|
// Using the concrete itemId is arguably wrong. The bookmarks API
|
2008-04-20 17:33:02 -07:00
|
|
|
// does allow setting properties for folder shortcuts as well, but since
|
|
|
|
// the UI does not distinct between the couple, we better just show
|
2009-03-18 07:23:56 -07:00
|
|
|
// the concrete item properties for shortcuts to root nodes.
|
|
|
|
var concreteId = PlacesUtils.getConcreteItemId(aSelectedNode);
|
|
|
|
var isRootItem = concreteId != -1 && PlacesUtils.isRootItem(concreteId);
|
|
|
|
var readOnly = isRootItem ||
|
|
|
|
aSelectedNode.parent.itemId == PlacesUIUtils.leftPaneFolderId;
|
|
|
|
var useConcreteId = isRootItem ||
|
|
|
|
PlacesUtils.nodeIsTagQuery(aSelectedNode);
|
|
|
|
var itemId = -1;
|
|
|
|
if (concreteId != -1 && useConcreteId)
|
|
|
|
itemId = concreteId;
|
|
|
|
else if (aSelectedNode.itemId != -1)
|
|
|
|
itemId = aSelectedNode.itemId;
|
|
|
|
else
|
|
|
|
itemId = PlacesUtils._uri(aSelectedNode.uri);
|
|
|
|
|
|
|
|
gEditItemOverlay.initPanel(itemId, { hiddenRows: ["folderPicker"],
|
|
|
|
forceReadOnly: readOnly });
|
2008-09-29 23:10:47 -07:00
|
|
|
|
2009-04-02 16:41:20 -07:00
|
|
|
// Dynamically generated queries, like history date containers, have
|
|
|
|
// itemId !=0 and do not exist in history. For them the panel is
|
|
|
|
// read-only, but empty, since it can't get a valid title for the object.
|
|
|
|
// In such a case we force the title using the selectedNode one, for UI
|
|
|
|
// polishness.
|
|
|
|
if (aSelectedNode.itemId == -1 &&
|
|
|
|
(PlacesUtils.nodeIsDay(aSelectedNode) ||
|
|
|
|
PlacesUtils.nodeIsHost(aSelectedNode)))
|
|
|
|
gEditItemOverlay._element("namePicker").value = aSelectedNode.title;
|
|
|
|
|
2008-04-25 09:47:35 -07:00
|
|
|
this._detectAndSetDetailsPaneMinimalState(aSelectedNode);
|
2007-08-22 07:42:37 -07:00
|
|
|
}
|
2008-09-29 23:10:47 -07:00
|
|
|
else if (!aSelectedNode && aNodeList[0]) {
|
|
|
|
var itemIds = [];
|
|
|
|
for (var i = 0; i < aNodeList.length; i++) {
|
2008-11-01 19:57:07 -07:00
|
|
|
if (!PlacesUtils.nodeIsBookmark(aNodeList[i]) &&
|
|
|
|
!PlacesUtils.nodeIsURI(aNodeList[i])) {
|
2008-09-29 23:10:47 -07:00
|
|
|
detailsDeck.selectedIndex = 0;
|
|
|
|
var selectItemDesc = document.getElementById("selectItemDescription");
|
|
|
|
var itemsCountLabel = document.getElementById("itemsCountText");
|
|
|
|
selectItemDesc.hidden = false;
|
|
|
|
itemsCountLabel.value =
|
|
|
|
PlacesUIUtils.getFormattedString("detailsPane.multipleItems",
|
|
|
|
[aNodeList.length]);
|
2008-12-07 06:42:10 -08:00
|
|
|
infoBox.hidden = true;
|
2008-09-29 23:10:47 -07:00
|
|
|
return;
|
|
|
|
}
|
2008-11-01 19:57:07 -07:00
|
|
|
itemIds[i] = aNodeList[i].itemId != -1 ? aNodeList[i].itemId :
|
|
|
|
PlacesUtils._uri(aNodeList[i].uri);
|
2008-09-29 23:10:47 -07:00
|
|
|
}
|
|
|
|
detailsDeck.selectedIndex = 1;
|
|
|
|
gEditItemOverlay.initPanel(itemIds,
|
|
|
|
{ hiddenRows: ["folderPicker",
|
|
|
|
"loadInSidebar",
|
|
|
|
"location",
|
|
|
|
"keyword",
|
|
|
|
"description",
|
|
|
|
"name"]});
|
|
|
|
this._detectAndSetDetailsPaneMinimalState(aSelectedNode);
|
|
|
|
}
|
2007-09-21 15:57:18 -07:00
|
|
|
else {
|
|
|
|
detailsDeck.selectedIndex = 0;
|
2008-12-07 06:42:10 -08:00
|
|
|
infoBox.hidden = true;
|
2007-09-21 15:57:18 -07:00
|
|
|
var selectItemDesc = document.getElementById("selectItemDescription");
|
|
|
|
var itemsCountLabel = document.getElementById("itemsCountText");
|
|
|
|
var rowCount = this._content.treeBoxObject.view.rowCount;
|
|
|
|
if (rowCount == 0) {
|
|
|
|
selectItemDesc.hidden = true;
|
2008-03-13 12:25:49 -07:00
|
|
|
itemsCountLabel.value = PlacesUIUtils.getString("detailsPane.noItems");
|
2007-09-21 15:57:18 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
selectItemDesc.hidden = false;
|
|
|
|
if (rowCount == 1)
|
2008-03-13 12:25:49 -07:00
|
|
|
itemsCountLabel.value = PlacesUIUtils.getString("detailsPane.oneItem");
|
2007-09-21 15:57:18 -07:00
|
|
|
else {
|
|
|
|
itemsCountLabel.value =
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUIUtils.getFormattedString("detailsPane.multipleItems",
|
|
|
|
[rowCount]);
|
2007-09-21 15:57:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2007-11-19 18:01:53 -08:00
|
|
|
// NOT YET USED
|
2007-09-21 15:57:18 -07:00
|
|
|
_updateThumbnail: function PO__updateThumbnail() {
|
|
|
|
var bo = document.getElementById("previewBox").boxObject;
|
|
|
|
var width = bo.width;
|
|
|
|
var height = bo.height;
|
|
|
|
|
|
|
|
var canvas = document.getElementById("itemThumbnail");
|
|
|
|
var ctx = canvas.getContext('2d');
|
|
|
|
var notAvailableText = canvas.getAttribute("notavailabletext");
|
|
|
|
ctx.save();
|
|
|
|
ctx.fillStyle = "-moz-Dialog";
|
|
|
|
ctx.fillRect(0, 0, width, height);
|
|
|
|
ctx.translate(width/2, height/2);
|
|
|
|
|
|
|
|
ctx.fillStyle = "GrayText";
|
|
|
|
ctx.mozTextStyle = "12pt sans serif";
|
|
|
|
var len = ctx.mozMeasureText(notAvailableText);
|
|
|
|
ctx.translate(-len/2,0);
|
|
|
|
ctx.mozDrawText(notAvailableText);
|
|
|
|
ctx.restore();
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleAdditionalInfoFields: function PO_toggleAdditionalInfoFields() {
|
2008-04-08 22:49:49 -07:00
|
|
|
var infoBox = document.getElementById("infoBox");
|
|
|
|
var infoBoxExpander = document.getElementById("infoBoxExpander");
|
2008-07-11 14:42:39 -07:00
|
|
|
var infoBoxExpanderLabel = document.getElementById("infoBoxExpanderLabel");
|
2009-01-23 03:52:14 -08:00
|
|
|
|
2008-04-08 22:49:49 -07:00
|
|
|
if (infoBox.getAttribute("minimal") == "true") {
|
|
|
|
infoBox.removeAttribute("minimal");
|
2008-07-11 14:42:39 -07:00
|
|
|
infoBoxExpanderLabel.value = infoBoxExpanderLabel.getAttribute("lesslabel");
|
2009-03-19 10:42:28 -07:00
|
|
|
infoBoxExpanderLabel.accessKey = infoBoxExpanderLabel.getAttribute("lessaccesskey");
|
2008-07-11 14:42:39 -07:00
|
|
|
infoBoxExpander.className = "expander-up";
|
2007-09-21 15:57:18 -07:00
|
|
|
}
|
|
|
|
else {
|
2008-04-08 22:49:49 -07:00
|
|
|
infoBox.setAttribute("minimal", "true");
|
2008-07-11 14:42:39 -07:00
|
|
|
infoBoxExpanderLabel.value = infoBoxExpanderLabel.getAttribute("morelabel");
|
2009-03-19 10:42:28 -07:00
|
|
|
infoBoxExpanderLabel.accessKey = infoBoxExpanderLabel.getAttribute("moreaccesskey");
|
2008-07-11 14:42:39 -07:00
|
|
|
infoBoxExpander.className = "expander-down";
|
2007-09-21 15:57:18 -07:00
|
|
|
}
|
2007-09-01 14:23:36 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save the current search (or advanced query) to the bookmarks root.
|
|
|
|
*/
|
2007-09-21 15:57:18 -07:00
|
|
|
saveSearch: function PO_saveSearch() {
|
2007-09-01 14:23:36 -07:00
|
|
|
// Get the place: uri for the query.
|
|
|
|
// If the advanced query builder is showing, use that.
|
|
|
|
var options = this.getCurrentOptions();
|
2008-03-29 11:16:27 -07:00
|
|
|
|
2008-04-23 16:04:58 -07:00
|
|
|
#ifdef PLACES_QUERY_BUILDER
|
|
|
|
var queries = PlacesQueryBuilder.queries;
|
|
|
|
#else
|
|
|
|
var queries = this.getCurrentQueries();
|
2008-03-29 11:16:27 -07:00
|
|
|
#endif
|
|
|
|
|
2007-09-01 14:23:36 -07:00
|
|
|
var placeSpec = PlacesUtils.history.queriesToQueryString(queries,
|
|
|
|
queries.length,
|
|
|
|
options);
|
2008-02-01 16:39:05 -08:00
|
|
|
var placeURI = Cc["@mozilla.org/network/io-service;1"].
|
|
|
|
getService(Ci.nsIIOService).
|
|
|
|
newURI(placeSpec, null, null);
|
2007-09-01 14:23:36 -07:00
|
|
|
|
|
|
|
// Prompt the user for a name for the query.
|
|
|
|
// XXX - using prompt service for now; will need to make
|
|
|
|
// a real dialog and localize when we're sure this is the UI we want.
|
2008-03-13 12:25:49 -07:00
|
|
|
var title = PlacesUIUtils.getString("saveSearch.title");
|
|
|
|
var inputLabel = PlacesUIUtils.getString("saveSearch.inputLabel");
|
2008-07-03 12:04:38 -07:00
|
|
|
var defaultText = PlacesUIUtils.getString("saveSearch.inputDefaultText");
|
2007-09-01 14:23:36 -07:00
|
|
|
|
|
|
|
var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"].
|
2007-09-21 15:57:18 -07:00
|
|
|
getService(Ci.nsIPromptService);
|
2007-09-01 14:23:36 -07:00
|
|
|
var check = {value: false};
|
|
|
|
var input = {value: defaultText};
|
|
|
|
var save = prompts.prompt(null, title, inputLabel, input, null, check);
|
|
|
|
|
|
|
|
// Don't add the query if the user cancels or clears the seach name.
|
|
|
|
if (!save || input.value == "")
|
|
|
|
return;
|
|
|
|
|
2007-09-21 15:57:18 -07:00
|
|
|
// Add the place: uri as a bookmark under the bookmarks root.
|
2008-03-13 12:25:49 -07:00
|
|
|
var txn = PlacesUIUtils.ptm.createItem(placeURI,
|
|
|
|
PlacesUtils.bookmarksMenuFolderId,
|
|
|
|
PlacesUtils.bookmarks.DEFAULT_INDEX,
|
|
|
|
input.value);
|
|
|
|
PlacesUIUtils.ptm.doTransaction(txn);
|
2008-01-31 16:19:43 -08:00
|
|
|
|
|
|
|
// select and load the new query
|
|
|
|
this._places.selectPlaceURI(placeSpec);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2007-09-21 15:57:18 -07:00
|
|
|
* A set of utilities relating to search within Bookmarks and History.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
var PlacesSearchBox = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Search text field
|
|
|
|
*/
|
|
|
|
get searchFilter() {
|
|
|
|
return document.getElementById("searchFilter");
|
|
|
|
},
|
|
|
|
|
2007-10-01 22:26:47 -07:00
|
|
|
/**
|
|
|
|
* Folders to include when searching.
|
|
|
|
*/
|
|
|
|
_folders: [],
|
|
|
|
get folders() {
|
|
|
|
if (this._folders.length == 0)
|
2007-11-19 18:01:53 -08:00
|
|
|
this._folders.push(PlacesUtils.bookmarksMenuFolderId,
|
|
|
|
PlacesUtils.unfiledBookmarksFolderId,
|
|
|
|
PlacesUtils.toolbarFolderId);
|
2007-10-01 22:26:47 -07:00
|
|
|
return this._folders;
|
|
|
|
},
|
|
|
|
set folders(aFolders) {
|
|
|
|
this._folders = aFolders;
|
|
|
|
return aFolders;
|
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Run a search for the specified text, over the collection specified by
|
|
|
|
* the dropdown arrow. The default is all bookmarks, but can be
|
2007-09-21 15:57:18 -07:00
|
|
|
* localized to the active collection.
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param filterString
|
2007-09-21 15:57:18 -07:00
|
|
|
* The text to search for.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
search: function PSB_search(filterString) {
|
2007-10-01 22:26:47 -07:00
|
|
|
var PO = PlacesOrganizer;
|
|
|
|
// If the user empties the search box manually, reset it and load all
|
|
|
|
// contents of the current scope.
|
|
|
|
// XXX this might be to jumpy, maybe should search for "", so results
|
|
|
|
// are ungrouped, and search box not reset
|
2008-08-16 01:45:12 -07:00
|
|
|
if (filterString == "") {
|
2007-10-01 22:26:47 -07:00
|
|
|
PO.onPlaceSelected(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
2007-10-01 22:26:47 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-10-01 22:26:47 -07:00
|
|
|
var currentOptions = PO.getCurrentOptions();
|
|
|
|
var content = PO._content;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-02-28 03:56:12 -08:00
|
|
|
// Search according to the current scope and folders, which were set by
|
|
|
|
// PQB_setScope()
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (PlacesSearchBox.filterCollection) {
|
|
|
|
case "collection":
|
2007-11-20 17:35:14 -08:00
|
|
|
content.applyFilter(filterString, this.folders);
|
2007-10-01 22:26:47 -07:00
|
|
|
// XXX changing the button text is badness
|
|
|
|
//var scopeBtn = document.getElementById("scopeBarFolder");
|
|
|
|
//scopeBtn.label = PlacesOrganizer._places.selectedNode.title;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case "bookmarks":
|
2009-02-28 03:56:12 -08:00
|
|
|
content.applyFilter(filterString, this.folders);
|
2007-10-01 22:26:47 -07:00
|
|
|
break;
|
|
|
|
case "history":
|
|
|
|
if (currentOptions.queryType != Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY) {
|
|
|
|
var query = PlacesUtils.history.getNewQuery();
|
|
|
|
query.searchTerms = filterString;
|
|
|
|
var options = currentOptions.clone();
|
2009-04-08 05:26:57 -07:00
|
|
|
// Make sure we're getting uri results.
|
|
|
|
options.resultType = currentOptions.RESULT_TYPE_URI;
|
2007-10-01 22:26:47 -07:00
|
|
|
options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY;
|
2007-11-20 17:35:14 -08:00
|
|
|
content.load([query], options);
|
2007-09-01 14:23:36 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
else
|
2007-11-20 17:35:14 -08:00
|
|
|
content.applyFilter(filterString);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2009-02-28 03:56:12 -08:00
|
|
|
default:
|
|
|
|
throw "Invalid filterCollection on search";
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
2007-09-21 15:57:18 -07:00
|
|
|
|
2007-10-01 22:26:47 -07:00
|
|
|
PlacesSearchBox.showSearchUI();
|
2008-04-02 12:18:11 -07:00
|
|
|
|
|
|
|
// Update the details panel
|
|
|
|
PlacesOrganizer.onContentTreeSelect();
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds across all bookmarks
|
|
|
|
*/
|
|
|
|
findAll: function PSB_findAll() {
|
2009-02-28 03:56:12 -08:00
|
|
|
PlacesQueryBuilder.setScope("bookmarks");
|
2007-03-22 10:30:00 -07:00
|
|
|
this.focus();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds in the currently selected Place.
|
|
|
|
*/
|
|
|
|
findCurrent: function PSB_findCurrent() {
|
2009-02-28 03:56:12 -08:00
|
|
|
PlacesQueryBuilder.setScope("collection");
|
2007-03-22 10:30:00 -07:00
|
|
|
this.focus();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the display with the title of the current collection.
|
|
|
|
* @param title
|
|
|
|
* The title of the current collection.
|
|
|
|
*/
|
|
|
|
updateCollectionTitle: function PSB_updateCollectionTitle(title) {
|
2008-04-07 08:59:30 -07:00
|
|
|
if (title)
|
|
|
|
this.searchFilter.emptyText =
|
|
|
|
PlacesUIUtils.getFormattedString("searchCurrentDefault", [title]);
|
|
|
|
else
|
|
|
|
this.searchFilter.emptyText = this.filterCollection == "history" ?
|
|
|
|
PlacesUIUtils.getString("searchHistory") :
|
|
|
|
PlacesUIUtils.getString("searchBookmarks");
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets/sets the active collection from the dropdown menu.
|
|
|
|
*/
|
|
|
|
get filterCollection() {
|
|
|
|
return this.searchFilter.getAttribute("collection");
|
|
|
|
},
|
|
|
|
set filterCollection(collectionName) {
|
2009-01-30 02:26:20 -08:00
|
|
|
if (collectionName == this.filterCollection)
|
|
|
|
return collectionName;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
this.searchFilter.setAttribute("collection", collectionName);
|
2009-01-30 02:26:20 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var newGrayText = null;
|
2009-03-17 14:00:44 -07:00
|
|
|
if (collectionName == "collection") {
|
|
|
|
newGrayText = PlacesOrganizer._places.selectedNode.title ||
|
|
|
|
document.getElementById("scopeBarFolder").
|
|
|
|
getAttribute("emptytitle");
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
this.updateCollectionTitle(newGrayText);
|
|
|
|
return collectionName;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Focus the search box
|
|
|
|
*/
|
|
|
|
focus: function PSB_focus() {
|
|
|
|
this.searchFilter.focus();
|
|
|
|
},
|
|
|
|
|
2007-09-21 15:57:18 -07:00
|
|
|
/**
|
|
|
|
* Set up the gray text in the search bar as the Places View loads.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
init: function PSB_init() {
|
2008-02-06 21:31:21 -08:00
|
|
|
this.updateCollectionTitle();
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-09-21 15:57:18 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2007-09-21 15:57:18 -07:00
|
|
|
* Gets or sets the text shown in the Places Search Box
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
get value() {
|
|
|
|
return this.searchFilter.value;
|
|
|
|
},
|
|
|
|
set value(value) {
|
|
|
|
return this.searchFilter.value = value;
|
2007-10-01 22:26:47 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
showSearchUI: function PSB_showSearchUI() {
|
|
|
|
// Hide the advanced search controls when the user hasn't searched
|
|
|
|
var searchModifiers = document.getElementById("searchModifiers");
|
|
|
|
searchModifiers.hidden = false;
|
|
|
|
|
2008-03-29 11:16:27 -07:00
|
|
|
#ifdef PLACES_QUERY_BUILDER
|
2007-10-01 22:26:47 -07:00
|
|
|
// if new search, open builder with pre-populated text row
|
|
|
|
if (PlacesQueryBuilder.numRows == 0)
|
|
|
|
document.getElementById("OrganizerCommand_search:moreCriteria").doCommand();
|
2008-03-29 11:16:27 -07:00
|
|
|
#endif
|
2007-10-01 22:26:47 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
hideSearchUI: function PSB_hideSearchUI() {
|
|
|
|
var searchModifiers = document.getElementById("searchModifiers");
|
|
|
|
searchModifiers.hidden = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Functions and data for advanced query builder
|
|
|
|
*/
|
|
|
|
var PlacesQueryBuilder = {
|
|
|
|
|
2007-09-01 14:23:36 -07:00
|
|
|
queries: [],
|
|
|
|
queryOptions: null,
|
|
|
|
|
2008-03-29 11:16:27 -07:00
|
|
|
#ifdef PLACES_QUERY_BUILDER
|
2007-10-01 22:26:47 -07:00
|
|
|
numRows: 0,
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
2007-09-21 15:57:18 -07:00
|
|
|
* The maximum number of terms that can be added.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2007-10-01 22:26:47 -07:00
|
|
|
_maxRows: null,
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
_keywordSearch: {
|
|
|
|
advancedSearch_N_Subject: "advancedSearch_N_SubjectKeyword",
|
|
|
|
advancedSearch_N_LocationMenulist: false,
|
|
|
|
advancedSearch_N_TimeMenulist: false,
|
|
|
|
advancedSearch_N_Textbox: "",
|
|
|
|
advancedSearch_N_TimePicker: false,
|
|
|
|
advancedSearch_N_TimeMenulist2: false
|
|
|
|
},
|
|
|
|
_locationSearch: {
|
|
|
|
advancedSearch_N_Subject: "advancedSearch_N_SubjectLocation",
|
|
|
|
advancedSearch_N_LocationMenulist: "advancedSearch_N_LocationMenuSelected",
|
|
|
|
advancedSearch_N_TimeMenulist: false,
|
|
|
|
advancedSearch_N_Textbox: "",
|
|
|
|
advancedSearch_N_TimePicker: false,
|
|
|
|
advancedSearch_N_TimeMenulist2: false
|
|
|
|
},
|
|
|
|
_timeSearch: {
|
|
|
|
advancedSearch_N_Subject: "advancedSearch_N_SubjectVisited",
|
|
|
|
advancedSearch_N_LocationMenulist: false,
|
|
|
|
advancedSearch_N_TimeMenulist: true,
|
|
|
|
advancedSearch_N_Textbox: false,
|
|
|
|
advancedSearch_N_TimePicker: "date",
|
|
|
|
advancedSearch_N_TimeMenulist2: false
|
|
|
|
},
|
|
|
|
_timeInLastSearch: {
|
|
|
|
advancedSearch_N_Subject: "advancedSearch_N_SubjectVisited",
|
|
|
|
advancedSearch_N_LocationMenulist: false,
|
|
|
|
advancedSearch_N_TimeMenulist: true,
|
|
|
|
advancedSearch_N_Textbox: "7",
|
|
|
|
advancedSearch_N_TimePicker: false,
|
|
|
|
advancedSearch_N_TimeMenulist2: true
|
|
|
|
},
|
|
|
|
_nextSearch: null,
|
|
|
|
_queryBuilders: null,
|
|
|
|
|
2008-03-29 11:16:27 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
init: function PQB_init() {
|
|
|
|
// Initialize advanced search
|
|
|
|
this._nextSearch = {
|
|
|
|
"keyword": this._timeSearch,
|
|
|
|
"visited": this._locationSearch,
|
|
|
|
"location": null
|
|
|
|
};
|
2007-09-21 15:57:18 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
this._queryBuilders = {
|
|
|
|
"keyword": this.setKeywordQuery,
|
|
|
|
"visited": this.setVisitedQuery,
|
|
|
|
"location": this.setLocationQuery
|
|
|
|
};
|
|
|
|
|
2007-10-01 22:26:47 -07:00
|
|
|
this._maxRows = this._queryBuilders.length;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
this._dateService = Cc["@mozilla.org/intl/scriptabledateformat;1"].
|
|
|
|
getService(Ci.nsIScriptableDateFormat);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the query builder, and the match rule UI if visible.
|
|
|
|
*/
|
|
|
|
hide: function PQB_hide() {
|
|
|
|
var advancedSearch = document.getElementById("advancedSearch");
|
|
|
|
// Need to collapse the advanced search box.
|
|
|
|
advancedSearch.collapsed = true;
|
|
|
|
},
|
2007-09-21 15:57:18 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Shows the query builder
|
|
|
|
*/
|
|
|
|
show: function PQB_show() {
|
|
|
|
var advancedSearch = document.getElementById("advancedSearch");
|
|
|
|
advancedSearch.collapsed = false;
|
|
|
|
},
|
|
|
|
|
2007-10-01 22:26:47 -07:00
|
|
|
toggleVisibility: function ABP_toggleVisibility() {
|
|
|
|
var expander = document.getElementById("organizerScopeBarExpander");
|
|
|
|
var advancedSearch = document.getElementById("advancedSearch");
|
|
|
|
if (advancedSearch.collapsed) {
|
|
|
|
advancedSearch.collapsed = false;
|
|
|
|
expander.className = "expander-down";
|
|
|
|
expander.setAttribute("tooltiptext",
|
|
|
|
expander.getAttribute("tooltiptextdown"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
advancedSearch.collapsed = true;
|
|
|
|
expander.className = "expander-up"
|
|
|
|
expander.setAttribute("tooltiptext",
|
|
|
|
expander.getAttribute("tooltiptextup"));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2007-09-21 15:57:18 -07:00
|
|
|
* Includes the rowId in the id attribute of an element in a row newly
|
2007-03-22 10:30:00 -07:00
|
|
|
* created from the template row.
|
|
|
|
* @param element
|
|
|
|
* The element whose id attribute needs to be updated.
|
|
|
|
* @param rowId
|
|
|
|
* The index of the new row.
|
|
|
|
*/
|
|
|
|
_setRowId: function PQB__setRowId(element, rowId) {
|
|
|
|
if (element.id)
|
|
|
|
element.id = element.id.replace("advancedSearch0", "advancedSearch" + rowId);
|
|
|
|
if (element.hasAttribute("rowid"))
|
|
|
|
element.setAttribute("rowid", rowId);
|
|
|
|
for (var i = 0; i < element.childNodes.length; ++i) {
|
|
|
|
this._setRowId(element.childNodes[i], rowId);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateUIForRowChange: function PQB__updateUIForRowChange() {
|
|
|
|
// Update the "can add more criteria" command to make sure various +
|
|
|
|
// buttons are disabled.
|
2007-10-01 22:26:47 -07:00
|
|
|
var command = document.getElementById("OrganizerCommand_search:moreCriteria");
|
|
|
|
if (this.numRows >= this._maxRows)
|
2007-03-22 10:30:00 -07:00
|
|
|
command.setAttribute("disabled", "true");
|
|
|
|
else
|
|
|
|
command.removeAttribute("disabled");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2007-09-21 15:57:18 -07:00
|
|
|
* Adds a row to the view, prefilled with the next query subject. If the
|
2007-03-22 10:30:00 -07:00
|
|
|
* query builder is not visible, it will be shown.
|
|
|
|
*/
|
|
|
|
addRow: function PQB_addRow() {
|
|
|
|
// Limits the number of rows that can be added based on the maximum number
|
|
|
|
// of search query subjects.
|
2007-10-01 22:26:47 -07:00
|
|
|
if (this.numRows >= this._maxRows)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Clone the template row and unset the hidden attribute.
|
|
|
|
var gridRows = document.getElementById("advancedSearchRows");
|
|
|
|
var newRow = gridRows.firstChild.cloneNode(true);
|
|
|
|
newRow.hidden = false;
|
|
|
|
|
|
|
|
// Determine what the search type is based on the last visible row. If this
|
|
|
|
// is the first row, the type is "keyword search". Otherwise, it's the next
|
2007-09-21 15:57:18 -07:00
|
|
|
// in the sequence after the one defined by the previous visible row's
|
2007-03-22 10:30:00 -07:00
|
|
|
// Subject selector, as defined in _nextSearch.
|
|
|
|
var searchType = this._keywordSearch;
|
|
|
|
var lastMenu = document.getElementById("advancedSearch" +
|
2007-10-01 22:26:47 -07:00
|
|
|
this.numRows +
|
2007-03-22 10:30:00 -07:00
|
|
|
"Subject");
|
2007-10-01 22:26:47 -07:00
|
|
|
if (this.numRows > 0 && lastMenu && lastMenu.selectedItem)
|
2007-03-22 10:30:00 -07:00
|
|
|
searchType = this._nextSearch[lastMenu.selectedItem.value];
|
2007-10-01 22:26:47 -07:00
|
|
|
|
2007-09-21 15:57:18 -07:00
|
|
|
// There is no "next" search type. We are here in error.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!searchType)
|
|
|
|
return;
|
2007-09-21 15:57:18 -07:00
|
|
|
// We don't insert into the document until _after_ the searchType is
|
2007-03-22 10:30:00 -07:00
|
|
|
// determined, since this will interfere with the computation.
|
|
|
|
gridRows.appendChild(newRow);
|
2007-10-01 22:26:47 -07:00
|
|
|
this._setRowId(newRow, ++this.numRows);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-21 15:57:18 -07:00
|
|
|
// Ensure the Advanced Search container is visible, if this is the first
|
2007-03-22 10:30:00 -07:00
|
|
|
// row being added.
|
2007-10-01 22:26:47 -07:00
|
|
|
if (this.numRows == 1) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this.show();
|
|
|
|
|
2007-09-21 15:57:18 -07:00
|
|
|
// Pre-fill the search terms field with the value from the one on the
|
2007-03-22 10:30:00 -07:00
|
|
|
// toolbar.
|
2007-09-21 15:57:18 -07:00
|
|
|
// For some reason, setting.value here synchronously does not appear to
|
2007-03-22 10:30:00 -07:00
|
|
|
// work.
|
|
|
|
var searchTermsField = document.getElementById("advancedSearch1Textbox");
|
|
|
|
if (searchTermsField)
|
|
|
|
setTimeout(function() { searchTermsField.value = PlacesSearchBox.value; }, 10);
|
2008-02-04 10:10:28 -08:00
|
|
|
this.queries = PlacesOrganizer.getCurrentQueries();
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
2007-09-21 15:57:18 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-10-01 22:26:47 -07:00
|
|
|
this.showSearch(this.numRows, searchType);
|
2007-03-22 10:30:00 -07:00
|
|
|
this._updateUIForRowChange();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a row from the set of terms
|
|
|
|
* @param row
|
|
|
|
* The row to remove. If this is null, the last row will be removed.
|
|
|
|
* If there are no more rows, the query builder will be hidden.
|
|
|
|
*/
|
|
|
|
removeRow: function PQB_removeRow(row) {
|
|
|
|
if (!row)
|
2007-10-01 22:26:47 -07:00
|
|
|
row = document.getElementById("advancedSearch" + this.numRows + "Row");
|
2007-03-22 10:30:00 -07:00
|
|
|
row.parentNode.removeChild(row);
|
2007-10-01 22:26:47 -07:00
|
|
|
--this.numRows;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-10-01 22:26:47 -07:00
|
|
|
if (this.numRows < 1) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this.hide();
|
|
|
|
|
|
|
|
// Re-do the original toolbar-search-box search that the user used to
|
|
|
|
// spawn the advanced UI... this effectively "reverts" the UI to the
|
|
|
|
// point it was in before they began monkeying with advanced search.
|
|
|
|
PlacesSearchBox.search(PlacesSearchBox.value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.doSearch();
|
|
|
|
this._updateUIForRowChange();
|
|
|
|
},
|
|
|
|
|
|
|
|
onDateTyped: function PQB_onDateTyped(event, row) {
|
|
|
|
var textbox = document.getElementById("advancedSearch" + row + "TimePicker");
|
|
|
|
var dateString = textbox.value;
|
|
|
|
var dateArr = dateString.split("-");
|
|
|
|
// The date can be split into a range by the '-' character, i.e.
|
|
|
|
// 9/5/05 - 10/2/05. Unfortunately, dates can also be written like
|
|
|
|
// 9-5-05 - 10-2-05. Try to parse the date based on how many hyphens
|
|
|
|
// there are.
|
|
|
|
var d0 = null;
|
|
|
|
var d1 = null;
|
2007-09-21 15:57:18 -07:00
|
|
|
// If there are an even number of elements in the date array, try to
|
2007-03-22 10:30:00 -07:00
|
|
|
// parse it as a range of two dates.
|
|
|
|
if ((dateArr.length & 1) == 0) {
|
|
|
|
var mid = dateArr.length / 2;
|
|
|
|
var dateStr0 = dateArr[0];
|
|
|
|
var dateStr1 = dateArr[mid];
|
|
|
|
for (var i = 1; i < mid; ++i) {
|
|
|
|
dateStr0 += "-" + dateArr[i];
|
|
|
|
dateStr1 += "-" + dateArr[i + mid];
|
|
|
|
}
|
|
|
|
d0 = new Date(dateStr0);
|
|
|
|
d1 = new Date(dateStr1);
|
|
|
|
}
|
|
|
|
// If that didn't work, try to parse it as a single date.
|
|
|
|
if (d0 == null || d0 == "Invalid Date") {
|
|
|
|
d0 = new Date(dateString);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d0 != null && d0 != "Invalid Date") {
|
|
|
|
// Parsing succeeded -- update the calendar.
|
|
|
|
var calendar = document.getElementById("advancedSearch" + row + "Calendar");
|
|
|
|
if (d0.getFullYear() < 2000)
|
|
|
|
d0.setFullYear(2000 + (d0.getFullYear() % 100));
|
|
|
|
if (d1 != null && d1 != "Invalid Date") {
|
|
|
|
if (d1.getFullYear() < 2000)
|
|
|
|
d1.setFullYear(2000 + (d1.getFullYear() % 100));
|
|
|
|
calendar.updateSelection(d0, d1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
calendar.updateSelection(d0, d0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// And update the search.
|
|
|
|
this.doSearch();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onCalendarChanged: function PQB_onCalendarChanged(event, row) {
|
|
|
|
var calendar = document.getElementById("advancedSearch" + row + "Calendar");
|
|
|
|
var begin = calendar.beginrange;
|
|
|
|
var end = calendar.endrange;
|
2007-09-21 15:57:18 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// If the calendar doesn't have a begin/end, don't change the textbox.
|
|
|
|
if (begin == null || end == null)
|
|
|
|
return true;
|
2007-09-21 15:57:18 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// If the begin and end are the same day, only fill that into the textbox.
|
|
|
|
var textbox = document.getElementById("advancedSearch" + row + "TimePicker");
|
|
|
|
var beginDate = begin.getDate();
|
|
|
|
var beginMonth = begin.getMonth() + 1;
|
|
|
|
var beginYear = begin.getFullYear();
|
|
|
|
var endDate = end.getDate();
|
|
|
|
var endMonth = end.getMonth() + 1;
|
|
|
|
var endYear = end.getFullYear();
|
|
|
|
if (beginDate == endDate && beginMonth == endMonth && beginYear == endYear) {
|
|
|
|
// Just one date.
|
|
|
|
textbox.value = this._dateService.FormatDate("",
|
|
|
|
this._dateService.dateFormatShort,
|
|
|
|
beginYear,
|
|
|
|
beginMonth,
|
|
|
|
beginDate);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Two dates.
|
|
|
|
var beginStr = this._dateService.FormatDate("",
|
|
|
|
this._dateService.dateFormatShort,
|
|
|
|
beginYear,
|
|
|
|
beginMonth,
|
|
|
|
beginDate);
|
|
|
|
var endStr = this._dateService.FormatDate("",
|
|
|
|
this._dateService.dateFormatShort,
|
|
|
|
endYear,
|
|
|
|
endMonth,
|
|
|
|
endDate);
|
|
|
|
textbox.value = beginStr + " - " + endStr;
|
|
|
|
}
|
2007-09-21 15:57:18 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Update the search.
|
|
|
|
this.doSearch();
|
2007-09-21 15:57:18 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
handleTimePickerClick: function PQB_handleTimePickerClick(event, row) {
|
|
|
|
var popup = document.getElementById("advancedSearch" + row + "DatePopup");
|
|
|
|
if (popup.showing)
|
|
|
|
popup.hidePopup();
|
|
|
|
else {
|
|
|
|
var textbox = document.getElementById("advancedSearch" + row + "TimePicker");
|
|
|
|
popup.showPopup(textbox, -1, -1, "popup", "bottomleft", "topleft");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
showSearch: function PQB_showSearch(row, values) {
|
|
|
|
for (val in values) {
|
|
|
|
var id = val.replace("_N_", row);
|
|
|
|
var element = document.getElementById(id);
|
|
|
|
if (values[val] || typeof(values[val]) == "string") {
|
|
|
|
if (typeof(values[val]) == "string") {
|
|
|
|
if (values[val] == "date") {
|
|
|
|
// "date" means that the current date should be filled into the
|
|
|
|
// textbox, and the calendar for the row updated.
|
|
|
|
var d = new Date();
|
|
|
|
element.value = this._dateService.FormatDate("",
|
|
|
|
this._dateService.dateFormatShort,
|
|
|
|
d.getFullYear(),
|
|
|
|
d.getMonth() + 1,
|
|
|
|
d.getDate());
|
|
|
|
var calendar = document.getElementById("advancedSearch" + row + "Calendar");
|
|
|
|
calendar.updateSelection(d, d);
|
|
|
|
}
|
|
|
|
else if (element.nodeName == "textbox") {
|
|
|
|
// values[val] is the initial value of the textbox.
|
|
|
|
element.value = values[val];
|
|
|
|
} else {
|
|
|
|
// values[val] is the menuitem which should be selected.
|
|
|
|
var itemId = values[val].replace("_N_", row);
|
|
|
|
var item = document.getElementById(itemId);
|
|
|
|
element.selectedItem = item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
element.hidden = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
element.hidden = true;
|
|
|
|
}
|
|
|
|
}
|
2007-09-21 15:57:18 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
this.doSearch();
|
|
|
|
},
|
|
|
|
|
|
|
|
setKeywordQuery: function PQB_setKeywordQuery(query, prefix) {
|
|
|
|
query.searchTerms += document.getElementById(prefix + "Textbox").value + " ";
|
|
|
|
},
|
|
|
|
|
|
|
|
setLocationQuery: function PQB_setLocationQuery(query, prefix) {
|
|
|
|
var type = document.getElementById(prefix + "LocationMenulist").selectedItem.value;
|
|
|
|
if (type == "onsite") {
|
|
|
|
query.domain = document.getElementById(prefix + "Textbox").value;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
query.uriIsPrefix = (type == "startswith");
|
|
|
|
var spec = document.getElementById(prefix + "Textbox").value;
|
2008-02-01 16:39:05 -08:00
|
|
|
var ios = Cc["@mozilla.org/network/io-service;1"].
|
|
|
|
getService(Ci.nsIIOService);
|
2007-03-22 10:30:00 -07:00
|
|
|
try {
|
2008-02-01 16:39:05 -08:00
|
|
|
query.uri = ios.newURI(spec, null, null);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2007-09-21 15:57:18 -07:00
|
|
|
// Invalid input can cause newURI to barf, that's OK, tack "http://"
|
2007-03-22 10:30:00 -07:00
|
|
|
// onto the front and try again to see if the user omitted it
|
|
|
|
try {
|
2008-02-01 16:39:05 -08:00
|
|
|
query.uri = ios.newURI("http://" + spec, null, null);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
// OK, they have entered something which can never match. This should
|
|
|
|
// not happen.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setVisitedQuery: function PQB_setVisitedQuery(query, prefix) {
|
|
|
|
var searchType = document.getElementById(prefix + "TimeMenulist").selectedItem.value;
|
|
|
|
const DAY_MSEC = 86400000;
|
|
|
|
switch (searchType) {
|
|
|
|
case "on":
|
|
|
|
var calendar = document.getElementById(prefix + "Calendar");
|
|
|
|
var begin = calendar.beginrange.getTime();
|
|
|
|
var end = calendar.endrange.getTime();
|
|
|
|
if (begin == end) {
|
|
|
|
end = begin + DAY_MSEC;
|
|
|
|
}
|
|
|
|
query.beginTime = begin * 1000;
|
|
|
|
query.endTime = end * 1000;
|
|
|
|
break;
|
|
|
|
case "before":
|
|
|
|
var calendar = document.getElementById(prefix + "Calendar");
|
|
|
|
var time = calendar.beginrange.getTime();
|
|
|
|
query.endTime = time * 1000;
|
|
|
|
break;
|
|
|
|
case "after":
|
|
|
|
var calendar = document.getElementById(prefix + "Calendar");
|
|
|
|
var time = calendar.endrange.getTime();
|
|
|
|
query.beginTime = time * 1000;
|
|
|
|
break;
|
|
|
|
case "inLast":
|
|
|
|
var textbox = document.getElementById(prefix + "Textbox");
|
|
|
|
var amount = parseInt(textbox.value);
|
|
|
|
amount = amount * DAY_MSEC;
|
|
|
|
var menulist = document.getElementById(prefix + "TimeMenulist2");
|
|
|
|
if (menulist.selectedItem.value == "weeks")
|
|
|
|
amount = amount * 7;
|
|
|
|
else if (menulist.selectedItem.value == "months")
|
|
|
|
amount = amount * 30;
|
|
|
|
var now = new Date();
|
|
|
|
now = now - amount;
|
|
|
|
query.beginTime = now * 1000;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
doSearch: function PQB_doSearch() {
|
|
|
|
// Create the individual queries.
|
|
|
|
var queryType = document.getElementById("advancedSearchType").selectedItem.value;
|
2007-09-01 14:23:36 -07:00
|
|
|
this.queries = [];
|
2007-03-22 10:30:00 -07:00
|
|
|
if (queryType == "and")
|
2007-10-01 22:26:47 -07:00
|
|
|
this.queries.push(PlacesUtils.history.getNewQuery());
|
2007-03-22 10:30:00 -07:00
|
|
|
var updated = 0;
|
2007-10-01 22:26:47 -07:00
|
|
|
for (var i = 1; updated < this.numRows; ++i) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var prefix = "advancedSearch" + i;
|
|
|
|
|
2007-09-21 15:57:18 -07:00
|
|
|
// The user can remove rows from the middle and start of the list, not
|
2007-03-22 10:30:00 -07:00
|
|
|
// just from the end, so we need to make sure that this row actually
|
|
|
|
// exists before attempting to construct a query for it.
|
|
|
|
var querySubjectElement = document.getElementById(prefix + "Subject");
|
|
|
|
if (querySubjectElement) {
|
|
|
|
// If the queries are being AND-ed, put all the rows in one query.
|
|
|
|
// If they're being OR-ed, add a separate query for each row.
|
|
|
|
var query;
|
|
|
|
if (queryType == "and")
|
2007-09-01 14:23:36 -07:00
|
|
|
query = this.queries[0];
|
2007-03-22 10:30:00 -07:00
|
|
|
else
|
|
|
|
query = PlacesUtils.history.getNewQuery();
|
2007-09-21 15:57:18 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var querySubject = querySubjectElement.value;
|
|
|
|
this._queryBuilders[querySubject](query, prefix);
|
2007-09-21 15:57:18 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (queryType == "or")
|
2007-09-01 14:23:36 -07:00
|
|
|
this.queries.push(query);
|
2007-09-21 15:57:18 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
++updated;
|
|
|
|
}
|
|
|
|
}
|
2007-09-21 15:57:18 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Make sure we're getting uri results, not visits
|
2007-09-01 14:23:36 -07:00
|
|
|
this.options = PlacesOrganizer.getCurrentOptions();
|
2007-10-01 22:26:47 -07:00
|
|
|
this.options.resultType = this.options.RESULT_TYPE_URI;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// XXXben - find some public way of doing this!
|
2007-11-20 17:35:14 -08:00
|
|
|
PlacesOrganizer._content.load(this.queries, this.options);
|
2008-04-02 12:18:11 -07:00
|
|
|
|
|
|
|
// Update the details panel
|
|
|
|
PlacesOrganizer.onContentTreeSelect();
|
2007-10-01 22:26:47 -07:00
|
|
|
},
|
2008-03-29 11:16:27 -07:00
|
|
|
#endif
|
2007-10-01 22:26:47 -07:00
|
|
|
|
2009-02-28 03:56:12 -08:00
|
|
|
/**
|
|
|
|
* Called when a scope button in the scope bar is clicked.
|
|
|
|
* @param aButton
|
|
|
|
* the scope button that was selected
|
|
|
|
*/
|
2007-10-01 22:26:47 -07:00
|
|
|
onScopeSelected: function PQB_onScopeSelected(aButton) {
|
2009-02-28 03:56:12 -08:00
|
|
|
switch (aButton.id) {
|
|
|
|
case "scopeBarHistory":
|
|
|
|
this.setScope("history");
|
|
|
|
break;
|
|
|
|
case "scopeBarFolder":
|
|
|
|
this.setScope("collection");
|
|
|
|
break;
|
|
|
|
case "scopeBarAll":
|
|
|
|
this.setScope("bookmarks");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw "Invalid search scope button ID";
|
|
|
|
break;
|
2007-10-01 22:26:47 -07:00
|
|
|
}
|
2009-02-28 03:56:12 -08:00
|
|
|
},
|
2007-10-01 22:26:47 -07:00
|
|
|
|
2009-02-28 03:56:12 -08:00
|
|
|
/**
|
|
|
|
* Sets the search scope. This can be called when no search is active, and
|
|
|
|
* in that case, when the user does begin a search aScope will be used (see
|
|
|
|
* PSB_search()). If there is an active search, it's performed again to
|
|
|
|
* update the content tree.
|
|
|
|
* @param aScope
|
|
|
|
* the search scope, "bookmarks", "collection", or "history"
|
|
|
|
*/
|
|
|
|
setScope: function PQB_setScope(aScope) {
|
|
|
|
// Determine filterCollection, folders, and scopeButtonId based on aScope.
|
|
|
|
var filterCollection;
|
2007-10-01 22:26:47 -07:00
|
|
|
var folders = [];
|
2009-02-28 03:56:12 -08:00
|
|
|
var scopeButtonId;
|
|
|
|
switch (aScope) {
|
|
|
|
case "history":
|
|
|
|
filterCollection = "history";
|
|
|
|
scopeButtonId = "scopeBarHistory";
|
|
|
|
break;
|
|
|
|
case "collection":
|
2009-03-17 14:00:44 -07:00
|
|
|
// The folder scope button can only become hidden upon selecting a new
|
2009-02-28 03:56:12 -08:00
|
|
|
// folder in the left pane, and the disabled state will remain unchanged
|
|
|
|
// until a new folder is selected. See PO__setScopeForNode().
|
2009-03-17 14:00:44 -07:00
|
|
|
if (!document.getElementById("scopeBarFolder").hidden) {
|
2009-02-28 03:56:12 -08:00
|
|
|
filterCollection = "collection";
|
|
|
|
scopeButtonId = "scopeBarFolder";
|
|
|
|
folders.push(PlacesUtils.getConcreteItemId(
|
|
|
|
PlacesOrganizer._places.selectedNode));
|
2007-10-01 22:26:47 -07:00
|
|
|
break;
|
2009-02-28 03:56:12 -08:00
|
|
|
}
|
|
|
|
// Fall through. If collection scope doesn't make sense for the
|
|
|
|
// selected node, choose bookmarks scope.
|
|
|
|
case "bookmarks":
|
|
|
|
filterCollection = "bookmarks";
|
|
|
|
scopeButtonId = "scopeBarAll";
|
|
|
|
folders.push(PlacesUtils.bookmarksMenuFolderId,
|
|
|
|
PlacesUtils.toolbarFolderId,
|
|
|
|
PlacesUtils.unfiledBookmarksFolderId);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw "Invalid search scope";
|
|
|
|
break;
|
2007-10-01 22:26:47 -07:00
|
|
|
}
|
|
|
|
|
2009-02-28 03:56:12 -08:00
|
|
|
// Check the appropriate scope button in the scope bar.
|
|
|
|
document.getElementById(scopeButtonId).checked = true;
|
|
|
|
|
|
|
|
// Update the search box. Re-search if there's an active search.
|
|
|
|
PlacesSearchBox.filterCollection = filterCollection;
|
2007-10-01 22:26:47 -07:00
|
|
|
PlacesSearchBox.folders = folders;
|
2009-02-28 03:56:12 -08:00
|
|
|
var searchStr = PlacesSearchBox.searchFilter.value;
|
|
|
|
if (searchStr)
|
|
|
|
PlacesSearchBox.search(searchStr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2007-09-21 15:57:18 -07:00
|
|
|
* Population and commands for the View Menu.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
var ViewMenu = {
|
|
|
|
/**
|
|
|
|
* Removes content generated previously from a menupopup.
|
|
|
|
* @param popup
|
|
|
|
* The popup that contains the previously generated content.
|
|
|
|
* @param startID
|
2007-09-21 15:57:18 -07:00
|
|
|
* The id attribute of an element that is the start of the
|
2007-03-22 10:30:00 -07:00
|
|
|
* dynamically generated region - remove elements after this
|
2007-09-21 15:57:18 -07:00
|
|
|
* item only.
|
2007-03-22 10:30:00 -07:00
|
|
|
* Must be contained by popup. Can be null (in which case the
|
2007-09-21 15:57:18 -07:00
|
|
|
* contents of popup are removed).
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param endID
|
|
|
|
* The id attribute of an element that is the end of the
|
|
|
|
* dynamically generated region - remove elements up to this
|
|
|
|
* item only.
|
|
|
|
* Must be contained by popup. Can be null (in which case all
|
|
|
|
* items until the end of the popup will be removed). Ignored
|
2007-09-21 15:57:18 -07:00
|
|
|
* if startID is null.
|
|
|
|
* @returns The element for the caller to insert new items before,
|
2007-03-22 10:30:00 -07:00
|
|
|
* null if the caller should just append to the popup.
|
|
|
|
*/
|
|
|
|
_clean: function VM__clean(popup, startID, endID) {
|
2007-09-21 15:57:18 -07:00
|
|
|
if (endID)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERT(startID, "meaningless to have valid endID and null startID");
|
|
|
|
if (startID) {
|
|
|
|
var startElement = document.getElementById(startID);
|
2007-09-21 15:57:18 -07:00
|
|
|
NS_ASSERT(startElement.parentNode ==
|
2007-03-22 10:30:00 -07:00
|
|
|
popup, "startElement is not in popup");
|
2007-09-21 15:57:18 -07:00
|
|
|
NS_ASSERT(startElement,
|
2007-03-22 10:30:00 -07:00
|
|
|
"startID does not correspond to an existing element");
|
|
|
|
var endElement = null;
|
|
|
|
if (endID) {
|
|
|
|
endElement = document.getElementById(endID);
|
2007-09-21 15:57:18 -07:00
|
|
|
NS_ASSERT(endElement.parentNode == popup,
|
2007-03-22 10:30:00 -07:00
|
|
|
"endElement is not in popup");
|
2007-09-21 15:57:18 -07:00
|
|
|
NS_ASSERT(endElement,
|
2007-03-22 10:30:00 -07:00
|
|
|
"endID does not correspond to an existing element");
|
|
|
|
}
|
|
|
|
while (startElement.nextSibling != endElement)
|
|
|
|
popup.removeChild(startElement.nextSibling);
|
|
|
|
return endElement;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
while(popup.hasChildNodes())
|
2007-09-21 15:57:18 -07:00
|
|
|
popup.removeChild(popup.firstChild);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fills a menupopup with a list of columns
|
|
|
|
* @param event
|
|
|
|
* The popupshowing event that invoked this function.
|
|
|
|
* @param startID
|
|
|
|
* see _clean
|
|
|
|
* @param endID
|
|
|
|
* see _clean
|
|
|
|
* @param type
|
2007-09-21 15:57:18 -07:00
|
|
|
* the type of the menuitem, e.g. "radio" or "checkbox".
|
|
|
|
* Can be null (no-type).
|
2007-03-22 10:30:00 -07:00
|
|
|
* Checkboxes are checked if the column is visible.
|
|
|
|
* @param propertyPrefix
|
|
|
|
* If propertyPrefix is non-null:
|
|
|
|
* propertyPrefix + column ID + ".label" will be used to get the
|
|
|
|
* localized label string.
|
|
|
|
* propertyPrefix + column ID + ".accesskey" will be used to get the
|
|
|
|
* localized accesskey.
|
|
|
|
* If propertyPrefix is null, the column label is used as label and
|
|
|
|
* no accesskey is assigned.
|
|
|
|
*/
|
|
|
|
fillWithColumns: function VM_fillWithColumns(event, startID, endID, type, propertyPrefix) {
|
2007-09-21 15:57:18 -07:00
|
|
|
var popup = event.target;
|
2007-03-22 10:30:00 -07:00
|
|
|
var pivot = this._clean(popup, startID, endID);
|
|
|
|
|
2007-09-21 15:57:18 -07:00
|
|
|
// If no column is "sort-active", the "Unsorted" item needs to be checked,
|
|
|
|
// so track whether or not we find a column that is sort-active.
|
2007-03-22 10:30:00 -07:00
|
|
|
var isSorted = false;
|
|
|
|
var content = document.getElementById("placeContent");
|
|
|
|
var columns = content.columns;
|
|
|
|
for (var i = 0; i < columns.count; ++i) {
|
|
|
|
var column = columns.getColumnAt(i).element;
|
2007-11-19 18:01:53 -08:00
|
|
|
var menuitem = document.createElement("menuitem");
|
2007-03-22 10:30:00 -07:00
|
|
|
menuitem.id = "menucol_" + column.id;
|
2007-11-20 19:28:46 -08:00
|
|
|
menuitem.column = column;
|
2007-03-22 10:30:00 -07:00
|
|
|
var label = column.getAttribute("label");
|
|
|
|
if (propertyPrefix) {
|
2007-08-27 17:40:47 -07:00
|
|
|
var menuitemPrefix = propertyPrefix;
|
|
|
|
// for string properties, use "name" as the id, instead of "title"
|
|
|
|
// see bug #386287 for details
|
2007-11-20 19:28:46 -08:00
|
|
|
var columnId = column.getAttribute("anonid");
|
|
|
|
menuitemPrefix += columnId == "title" ? "name" : columnId;
|
2008-03-13 12:25:49 -07:00
|
|
|
label = PlacesUIUtils.getString(menuitemPrefix + ".label");
|
|
|
|
var accesskey = PlacesUIUtils.getString(menuitemPrefix + ".accesskey");
|
2007-03-22 10:30:00 -07:00
|
|
|
menuitem.setAttribute("accesskey", accesskey);
|
|
|
|
}
|
|
|
|
menuitem.setAttribute("label", label);
|
|
|
|
if (type == "radio") {
|
|
|
|
menuitem.setAttribute("type", "radio");
|
|
|
|
menuitem.setAttribute("name", "columns");
|
2007-09-21 15:57:18 -07:00
|
|
|
// This column is the sort key. Its item is checked.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (column.getAttribute("sortDirection") != "") {
|
|
|
|
menuitem.setAttribute("checked", "true");
|
|
|
|
isSorted = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == "checkbox") {
|
|
|
|
menuitem.setAttribute("type", "checkbox");
|
2007-08-27 15:44:18 -07:00
|
|
|
// Cannot uncheck the primary column.
|
|
|
|
if (column.getAttribute("primary") == "true")
|
2007-03-22 10:30:00 -07:00
|
|
|
menuitem.setAttribute("disabled", "true");
|
2007-09-21 15:57:18 -07:00
|
|
|
// Items for visible columns are checked.
|
2007-05-19 17:44:57 -07:00
|
|
|
if (!column.hidden)
|
2007-03-22 10:30:00 -07:00
|
|
|
menuitem.setAttribute("checked", "true");
|
|
|
|
}
|
|
|
|
if (pivot)
|
|
|
|
popup.insertBefore(menuitem, pivot);
|
|
|
|
else
|
2007-09-21 15:57:18 -07:00
|
|
|
popup.appendChild(menuitem);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
event.stopPropagation();
|
|
|
|
},
|
2007-09-21 15:57:18 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Set up the content of the view menu.
|
|
|
|
*/
|
2007-09-18 14:26:46 -07:00
|
|
|
populateSortMenu: function VM_populateSortMenu(event) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this.fillWithColumns(event, "viewUnsorted", "directionSeparator", "radio", "view.sortBy.");
|
|
|
|
|
|
|
|
var sortColumn = this._getSortColumn();
|
|
|
|
var viewSortAscending = document.getElementById("viewSortAscending");
|
|
|
|
var viewSortDescending = document.getElementById("viewSortDescending");
|
2007-09-21 15:57:18 -07:00
|
|
|
// We need to remove an existing checked attribute because the unsorted
|
2007-03-22 10:30:00 -07:00
|
|
|
// menu item is not rebuilt every time we open the menu like the others.
|
|
|
|
var viewUnsorted = document.getElementById("viewUnsorted");
|
|
|
|
if (!sortColumn) {
|
|
|
|
viewSortAscending.removeAttribute("checked");
|
|
|
|
viewSortDescending.removeAttribute("checked");
|
|
|
|
viewUnsorted.setAttribute("checked", "true");
|
|
|
|
}
|
|
|
|
else if (sortColumn.getAttribute("sortDirection") == "ascending") {
|
|
|
|
viewSortAscending.setAttribute("checked", "true");
|
|
|
|
viewSortDescending.removeAttribute("checked");
|
|
|
|
viewUnsorted.removeAttribute("checked");
|
|
|
|
}
|
|
|
|
else if (sortColumn.getAttribute("sortDirection") == "descending") {
|
|
|
|
viewSortDescending.setAttribute("checked", "true");
|
|
|
|
viewSortAscending.removeAttribute("checked");
|
|
|
|
viewUnsorted.removeAttribute("checked");
|
|
|
|
}
|
|
|
|
},
|
2007-09-21 15:57:18 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Shows/Hides a tree column.
|
|
|
|
* @param element
|
|
|
|
* The menuitem element for the column
|
|
|
|
*/
|
|
|
|
showHideColumn: function VM_showHideColumn(element) {
|
2007-11-20 19:28:46 -08:00
|
|
|
var column = element.column;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
var splitter = column.nextSibling;
|
|
|
|
if (splitter && splitter.localName != "splitter")
|
|
|
|
splitter = null;
|
2007-09-21 15:57:18 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (element.getAttribute("checked") == "true") {
|
2008-05-07 21:20:00 -07:00
|
|
|
column.setAttribute("hidden", "false");
|
2007-05-19 17:44:57 -07:00
|
|
|
if (splitter)
|
|
|
|
splitter.removeAttribute("hidden");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
column.setAttribute("hidden", "true");
|
2007-05-19 17:44:57 -07:00
|
|
|
if (splitter)
|
|
|
|
splitter.setAttribute("hidden", "true");
|
2007-09-21 15:57:18 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2007-09-21 15:57:18 -07:00
|
|
|
* Gets the last column that was sorted.
|
|
|
|
* @returns the currently sorted column, null if there is no sorted column.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
_getSortColumn: function VM__getSortColumn() {
|
|
|
|
var content = document.getElementById("placeContent");
|
|
|
|
var cols = content.columns;
|
|
|
|
for (var i = 0; i < cols.count; ++i) {
|
|
|
|
var column = cols.getColumnAt(i).element;
|
|
|
|
var sortDirection = column.getAttribute("sortDirection");
|
|
|
|
if (sortDirection == "ascending" || sortDirection == "descending")
|
|
|
|
return column;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2007-11-20 19:28:46 -08:00
|
|
|
* Sorts the view by the specified column.
|
|
|
|
* @param aColumn
|
|
|
|
* The colum that is the sort key. Can be null - the
|
|
|
|
* current sort column or the title column will be used.
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param aDirection
|
2007-09-21 15:57:18 -07:00
|
|
|
* The direction to sort - "ascending" or "descending".
|
2007-03-22 10:30:00 -07:00
|
|
|
* Can be null - the last direction or descending will be used.
|
|
|
|
*
|
|
|
|
* If both aColumnID and aDirection are null, the view will be unsorted.
|
|
|
|
*/
|
2007-11-20 19:28:46 -08:00
|
|
|
setSortColumn: function VM_setSortColumn(aColumn, aDirection) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var result = document.getElementById("placeContent").getResult();
|
2007-11-20 19:28:46 -08:00
|
|
|
if (!aColumn && !aDirection) {
|
2007-03-22 10:30:00 -07:00
|
|
|
result.sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_NONE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-11-20 19:28:46 -08:00
|
|
|
var columnId;
|
|
|
|
if (aColumn) {
|
2009-01-30 04:34:38 -08:00
|
|
|
columnId = aColumn.getAttribute("anonid");
|
2007-11-20 19:28:46 -08:00
|
|
|
if (!aDirection) {
|
|
|
|
var sortColumn = this._getSortColumn();
|
2009-01-30 04:34:38 -08:00
|
|
|
if (sortColumn)
|
|
|
|
aDirection = sortColumn.getAttribute("sortDirection");
|
2007-11-20 19:28:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var sortColumn = this._getSortColumn();
|
|
|
|
columnId = sortColumn ? sortColumn.getAttribute("anonid") : "title";
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-01-30 04:34:38 -08:00
|
|
|
// This maps the possible values of columnId (i.e., anonid's of treecols in
|
|
|
|
// placeContent) to the default sortingMode and sortingAnnotation values for
|
|
|
|
// each column.
|
|
|
|
// key: Sort key in the name of one of the
|
|
|
|
// nsINavHistoryQueryOptions.SORT_BY_* constants
|
|
|
|
// dir: Default sort direction to use if none has been specified
|
|
|
|
// anno: The annotation to sort by, if key is "ANNOTATION"
|
|
|
|
var colLookupTable = {
|
|
|
|
title: { key: "TITLE", dir: "ascending" },
|
|
|
|
tags: { key: "TAGS", dir: "ascending" },
|
|
|
|
url: { key: "URI", dir: "ascending" },
|
|
|
|
date: { key: "DATE", dir: "descending" },
|
|
|
|
visitCount: { key: "VISITCOUNT", dir: "descending" },
|
|
|
|
keyword: { key: "KEYWORD", dir: "ascending" },
|
|
|
|
dateAdded: { key: "DATEADDED", dir: "descending" },
|
|
|
|
lastModified: { key: "LASTMODIFIED", dir: "descending" },
|
|
|
|
description: { key: "ANNOTATION",
|
|
|
|
dir: "ascending",
|
|
|
|
anno: DESCRIPTION_ANNO }
|
|
|
|
};
|
|
|
|
|
|
|
|
// Make sure we have a valid column.
|
|
|
|
if (!colLookupTable.hasOwnProperty(columnId))
|
|
|
|
throw("Invalid column");
|
|
|
|
|
|
|
|
// Use a default sort direction if none has been specified. If aDirection
|
|
|
|
// is invalid, result.sortingMode will be undefined, which has the effect
|
|
|
|
// of unsorting the tree.
|
|
|
|
aDirection = (aDirection || colLookupTable[columnId].dir).toUpperCase();
|
|
|
|
|
|
|
|
var sortConst = "SORT_BY_" + colLookupTable[columnId].key + "_" + aDirection;
|
|
|
|
result.sortingAnnotation = colLookupTable[columnId].anno || "";
|
|
|
|
result.sortingMode = Ci.nsINavHistoryQueryOptions[sortConst];
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
};
|