home *** CD-ROM | disk | FTP | other *** search
- /* -*- 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>
- * Ehsan Akhgari <ehsan.akhgari@gmail.com>
- *
- * 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,
-
- _initFolderTree: function() {
- var leftPaneRoot = PlacesUIUtils.leftPaneFolderId;
- this._places.place = "place:excludeItems=1&expandQueries=0&folder=" + leftPaneRoot;
- },
-
- selectLeftPaneQuery: function PO_selectLeftPaneQuery(aQueryName) {
- var itemId = PlacesUIUtils.leftPaneQueries[aQueryName];
- this._places.selectItems([itemId]);
- // Forcefully expand all-bookmarks
- if (aQueryName == "AllBookmarks")
- asContainer(this._places.selectedNode).containerOpen = true;
- },
-
- init: function PO_init() {
- this._places = document.getElementById("placesList");
- this._content = document.getElementById("placeContent");
- this._initFolderTree();
-
- var leftPaneSelection = "AllBookmarks"; // default to all-bookmarks
- if ("arguments" in window && window.arguments.length > 0)
- leftPaneSelection = window.arguments[0];
-
- this.selectLeftPaneQuery(leftPaneSelection);
- // clear the back-stack
- this._backHistory.splice(0);
- document.getElementById("OrganizerCommand:Back").setAttribute("disabled", true);
-
- var view = this._content.treeBoxObject.view;
- if (view.rowCount > 0)
- view.selection.select(0);
-
- this._content.focus();
-
- // Set up the search UI.
- PlacesSearchBox.init();
-
- //@line 85 "/build/buildd/firefox-3.0-3.0.14+build2+nobinonly/build-tree/mozilla/browser/components/places/content/places.js"
-
- window.addEventListener("AppCommand", this, true);
- //@line 107 "/build/buildd/firefox-3.0-3.0.14+build2+nobinonly/build-tree/mozilla/browser/components/places/content/places.js"
-
- // remove the "Properties" context-menu item, we've our own details pane
- document.getElementById("placesContext")
- .removeChild(document.getElementById("placesContext_show:info"));
- },
-
- 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;
- }
- },
-
- destroy: function PO_destroy() {
- },
-
- _location: null,
- get location() {
- return this._location;
- },
-
- set location(aLocation) {
- if (!aLocation || this._location == aLocation)
- return aLocation;
-
- if (this.location) {
- this._backHistory.unshift(this.location);
- this._forwardHistory.splice(0);
- }
-
- 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;
- }
- this.onContentTreeSelect();
-
- // 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: [],
-
- back: function PO_back() {
- this._forwardHistory.unshift(this.location);
- var historyEntry = this._backHistory.shift();
- this._location = null;
- this.location = historyEntry;
- },
- forward: function PO_forward() {
- this._backHistory.unshift(this.location);
- var historyEntry = this._forwardHistory.shift();
- this._location = null;
- this.location = historyEntry;
- },
-
- /**
- * Called when a place folder is selected in the left pane.
- * @param resetSearchBox
- * true if the search box should also be reset, false if it should
- * be left alone.
- */
- onPlaceSelected: function PO_onPlaceSelected(resetSearchBox) {
- // Don't change the right-hand pane contents when there's no selection
- if (!this._places.hasSelection)
- return;
-
- var node = this._places.selectedNode;
- var queries = asQuery(node).getQueries({});
-
- // Items are only excluded on the left pane
- var options = node.queryOptions.clone();
- options.excludeItems = false;
- var placeURI = PlacesUtils.history.queriesToQueryString(queries, queries.length, options);
-
- // Update the right-pane contents.
- // We must update also if the user clears the search box, in that case
- // we are called with resetSearchBox == false.
- if (this._content.place != placeURI || !resetSearchBox) {
- this._content.place = placeURI;
-
- // Update the back/forward buttons.
- this.location = node.uri;
- }
-
- // Make sure the search UI is hidden.
- PlacesSearchBox.hideSearchUI();
- if (resetSearchBox) {
- var searchFilter = document.getElementById("searchFilter");
- searchFilter.reset();
- }
-
- this._setSearchScopeForNode(node);
- if (this._places.treeBoxObject.focused)
- this._fillDetailsPane(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 <current collection>" command
- var findCommand = document.getElementById("OrganizerCommand_find:current");
- var findLabel = PlacesUIUtils.getFormattedString("findInPrefix", [aNode.title]);
- findCommand.setAttribute("label", findLabel);
- },
-
- /**
- * Handle clicks on the tree. If the user middle clicks on a URL, load that
- * URL according to rules. Single clicks or modified clicks do not result in
- * any special action, since they're related to selection.
- * @param aEvent
- * The mouse event.
- */
- onTreeClick: function PO_onTreeClick(aEvent) {
- if (aEvent.target.localName != "treechildren")
- return;
-
- var currentView = aEvent.currentTarget;
- var selectedNode = currentView.selectedNode;
- if (selectedNode && aEvent.button == 1) {
- if (PlacesUtils.nodeIsURI(selectedNode))
- PlacesUIUtils.openNodeWithEvent(selectedNode, aEvent);
- else if (PlacesUtils.nodeIsContainer(selectedNode)) {
- // The command execution function will take care of seeing the
- // selection is a folder/container and loading its contents in
- // tabs for us.
- PlacesUIUtils.openContainerNodeInTabs(selectedNode);
- }
- }
- },
-
- /**
- * 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;
- var selectedNode = currentView.selectedNode;
- this._fillDetailsPane(selectedNode);
- },
-
- openFlatContainer: function PO_openFlatContainerFlatContainer(aContainer) {
- if (aContainer.itemId != -1)
- this._places.selectItems([aContainer.itemId]);
- else if (PlacesUtils.nodeIsQuery(aContainer))
- this._places.selectPlaceURI(aContainer.uri);
- },
-
- openSelectedNode: function PU_openSelectedNode(aEvent) {
- PlacesUIUtils.openNodeWithEvent(this._content.selectedNode, aEvent);
- },
-
- /**
- * 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;
- },
-
- /**
- * 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({});
- },
-
- /**
- * 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)
- this.importFromFile();
- },
-
- /**
- * 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);
- fp.init(window, PlacesUIUtils.getString("SelectImport"),
- Ci.nsIFilePicker.modeOpen);
- fp.appendFilters(Ci.nsIFilePicker.filterHTML);
- if (fp.show() != Ci.nsIFilePicker.returnCancel) {
- if (fp.file) {
- var importer = Cc["@mozilla.org/browser/places/import-export-service;1"].
- getService(Ci.nsIPlacesImportExportService);
- var file = fp.file.QueryInterface(Ci.nsILocalFile);
- importer.importHTMLFromFile(file, false);
- }
- }
- },
-
- /**
- * Allows simple exporting of bookmarks.
- */
- exportBookmarks: function PO_exportBookmarks() {
- var fp = Cc["@mozilla.org/filepicker;1"].
- createInstance(Ci.nsIFilePicker);
- fp.init(window, PlacesUIUtils.getString("EnterExport"),
- Ci.nsIFilePicker.modeSave);
- fp.appendFilters(Ci.nsIFilePicker.filterHTML);
- fp.defaultString = "bookmarks.html";
- if (fp.show() != Ci.nsIFilePicker.returnCancel) {
- var exporter = Cc["@mozilla.org/browser/places/import-export-service;1"].
- getService(Ci.nsIPlacesImportExportService);
- exporter.exportHTMLToFile(fp.file);
- }
- },
-
- /**
- * Populates the restore menu with the dates of the backups available.
- */
- populateRestoreMenu: function PO_populateRestoreMenu() {
- var restorePopup = document.getElementById("fileRestorePopup");
-
- // remove existing menu items
- // last item is the restoreFromFile item
- while (restorePopup.childNodes.length > 1)
- restorePopup.removeChild(restorePopup.firstChild);
-
- // get list of files
- var localizedFilename = PlacesUtils.getString("bookmarksArchiveFilename");
- var localizedFilenamePrefix = localizedFilename.substr(0, localizedFilename.indexOf("-"));
- var fileList = [];
- var files = this.bookmarksBackupDir.directoryEntries;
- while (files.hasMoreElements()) {
- var f = files.getNext().QueryInterface(Ci.nsIFile);
- var rx = new RegExp("^(bookmarks|" + localizedFilenamePrefix + ")-.+\.json");
- if (!f.isHidden() && f.leafName.match(rx))
- fileList.push(f);
- }
-
- fileList.sort(function PO_fileList_compare(a, b) {
- return b.lastModifiedTime - a.lastModifiedTime;
- });
-
- 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"));
- var rx = new RegExp("^(bookmarks|" + localizedFilenamePrefix + ")-");
- var dateStr = fileList[i].leafName.replace(rx, "").replace(/\.json$/, "");
- if (!dateStr.length)
- dateStr = fileList[i].leafName;
- m.setAttribute("label", dateStr);
- m.setAttribute("value", fileList[i].leafName);
- 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"].
- getService(Ci.nsIProperties);
- var bookmarksFile = dirSvc.get("ProfD", Ci.nsIFile);
- bookmarksFile.append("bookmarkbackups");
- bookmarksFile.append(aMenuItem.getAttribute("value"));
- if (!bookmarksFile.exists())
- return;
- this.restoreBookmarksFromFile(bookmarksFile);
- },
-
- /**
- * Called when 'Choose File...' is selected from the restore menu.
- * Prompts for a file and restores bookmarks to those in the file.
- */
- onRestoreBookmarksFromFile: function PO_onRestoreBookmarksFromFile() {
- var fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
- fp.init(window, PlacesUIUtils.getString("bookmarksRestoreTitle"),
- Ci.nsIFilePicker.modeOpen);
- fp.appendFilter(PlacesUIUtils.getString("bookmarksRestoreFilterName"),
- PlacesUIUtils.getString("bookmarksRestoreFilterExtension"));
-
- var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties);
- var backupsDir = dirSvc.get("Desk", Ci.nsILocalFile);
- fp.displayDirectory = backupsDir;
-
- if (fp.show() != Ci.nsIFilePicker.returnCancel)
- this.restoreBookmarksFromFile(fp.file);
- },
-
- /**
- * Restores bookmarks from a JSON file.
- */
- restoreBookmarksFromFile: function PO_restoreBookmarksFromFile(aFile) {
- // check file extension
- if (!aFile.leafName.match(/\.json$/)) {
- this._showErrorAlert(PlacesUIUtils.getString("bookmarksRestoreFormatError"));
- return;
- }
-
- // confirm ok to delete existing bookmarks
- var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"].
- getService(Ci.nsIPromptService);
- if (!prompts.confirm(null,
- PlacesUIUtils.getString("bookmarksRestoreAlertTitle"),
- PlacesUIUtils.getString("bookmarksRestoreAlert")))
- return;
-
- try {
- PlacesUtils.restoreBookmarksFromJSONFile(aFile, [PlacesUIUtils.leftPaneFolderId]);
- }
- catch(ex) {
- this._showErrorAlert(PlacesUIUtils.getString("bookmarksRestoreParseError"));
- }
- },
-
- _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);
- },
-
- /**
- * 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() {
- var fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
- fp.init(window, PlacesUIUtils.getString("bookmarksBackupTitle"),
- Ci.nsIFilePicker.modeSave);
- fp.appendFilter(PlacesUIUtils.getString("bookmarksRestoreFilterName"),
- PlacesUIUtils.getString("bookmarksRestoreFilterExtension"));
-
- var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties);
- var backupsDir = dirSvc.get("Desk", Ci.nsILocalFile);
- fp.displayDirectory = backupsDir;
-
- // Use YYYY-MM-DD (ISO 8601) as it doesn't contain illegal characters
- // and makes the alphabetical order of multiple backup files more useful.
- var date = (new Date).toLocaleFormat("%Y-%m-%d");
- fp.defaultString = PlacesUIUtils.getFormattedString("bookmarksBackupFilenameJSON",
- [date]);
-
- if (fp.show() != Ci.nsIFilePicker.returnCancel) {
- PlacesUtils.backupBookmarksToFile(fp.file, [PlacesUIUtils.leftPaneFolderId]);
-
- // copy new backup to /backups dir (bug 424389)
- var latestBackup = PlacesUtils.getMostRecentBackup();
- if (!latestBackup || latestBackup != fp.file) {
- latestBackup.remove(false);
- var date = new Date().toLocaleFormat("%Y-%m-%d");
- var name = PlacesUtils.getFormattedString("bookmarksArchiveFilename",
- [date]);
- 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())
- bookmarksBackupDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0700);
- return this.bookmarksBackupDir = bookmarksBackupDir;
- },
-
- _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
- * of livemark-children are not likely to fill the infoBox anyway,
- * 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.
- */
- var infoBox = document.getElementById("infoBox");
- var infoBoxExpander = document.getElementById("infoBoxExpander");
- if (aNode.itemId != -1 &&
- ((PlacesUtils.nodeIsFolder(aNode) &&
- !PlacesUtils.nodeIsLivemarkContainer(aNode)) ||
- PlacesUtils.nodeIsLivemarkItem(aNode))) {
- if (infoBox.getAttribute("minimal") == "true")
- infoBox.setAttribute("wasminimal", "true");
- infoBox.removeAttribute("minimal");
- infoBoxExpander.hidden = true;
- }
- else {
- if (infoBox.getAttribute("wasminimal") == "true")
- infoBox.setAttribute("minimal", "true");
- infoBox.removeAttribute("wasminimal");
- infoBoxExpander.hidden = false;
- }
- },
-
- // NOT YET USED
- 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;
- },
-
- onContentTreeSelect: function PO_onContentTreeSelect() {
- if (this._content.treeBoxObject.focused)
- this._fillDetailsPane(this._content.selectedNode);
- },
-
- _fillDetailsPane: function PO__fillDetailsPane(aSelectedNode) {
- var infoBox = document.getElementById("infoBox");
- var detailsDeck = document.getElementById("detailsDeck");
-
- // 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;
- if ((focusedElement instanceof HTMLInputElement ||
- focusedElement instanceof HTMLTextAreaElement) &&
- /^editBMPanel.*/.test(focusedElement.parentNode.parentNode.id))
- focusedElement.blur();
-
- // don't update the panel if we are already editing this node
- if (aSelectedNode && gEditItemOverlay.itemId == aSelectedNode.itemId &&
- detailsDeck.selectedIndex == 1)
- return;
- }
-
- if (aSelectedNode && !PlacesUtils.nodeIsSeparator(aSelectedNode)) {
- detailsDeck.selectedIndex = 1;
- // Using the concrete itemId is arguably wrong. The bookmarks API
- // does allow setting properties for folder shortcuts as well, but since
- // the UI does not distinct between the couple, we better just show
- // the concrete item properties.
- if (aSelectedNode.type ==
- Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER_SHORTCUT) {
- gEditItemOverlay.initPanel(asQuery(aSelectedNode).folderItemId,
- { hiddenRows: ["folderPicker"],
- forceReadOnly: true });
- }
- else {
- var itemId = PlacesUtils.getConcreteItemId(aSelectedNode);
- gEditItemOverlay.initPanel(itemId != -1 ? itemId :
- PlacesUtils._uri(aSelectedNode.uri),
- { hiddenRows: ["folderPicker"] });
- }
- this._detectAndSetDetailsPaneMinimalState(aSelectedNode);
- }
- else {
- detailsDeck.selectedIndex = 0;
- var selectItemDesc = document.getElementById("selectItemDescription");
- var itemsCountLabel = document.getElementById("itemsCountText");
- var rowCount = this._content.treeBoxObject.view.rowCount;
- if (rowCount == 0) {
- selectItemDesc.hidden = true;
- itemsCountLabel.value = PlacesUIUtils.getString("detailsPane.noItems");
- }
- else {
- selectItemDesc.hidden = false;
- if (rowCount == 1)
- itemsCountLabel.value = PlacesUIUtils.getString("detailsPane.oneItem");
- else {
- itemsCountLabel.value =
- PlacesUIUtils.getFormattedString("detailsPane.multipleItems",
- [rowCount]);
- }
- }
- }
- },
-
- // NOT YET USED
- _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() {
- var infoBox = document.getElementById("infoBox");
- var infoBoxExpander = document.getElementById("infoBoxExpander");
- if (infoBox.getAttribute("minimal") == "true") {
- infoBox.removeAttribute("minimal");
- infoBoxExpander.label = infoBoxExpander.getAttribute("lesslabel");
- infoBoxExpander.accessKey = infoBoxExpander.getAttribute("lessaccesskey");
- }
- else {
- infoBox.setAttribute("minimal", "true");
- infoBoxExpander.label = infoBoxExpander.getAttribute("morelabel");
- infoBoxExpander.accessKey = infoBoxExpander.getAttribute("moreaccesskey");
- }
- },
-
- /**
- * Save the current search (or advanced query) to the bookmarks root.
- */
- saveSearch: function PO_saveSearch() {
- // Get the place: uri for the query.
- // If the advanced query builder is showing, use that.
- var options = this.getCurrentOptions();
-
- //@line 739 "/build/buildd/firefox-3.0-3.0.14+build2+nobinonly/build-tree/mozilla/browser/components/places/content/places.js"
- var queries = this.getCurrentQueries();
- //@line 741 "/build/buildd/firefox-3.0-3.0.14+build2+nobinonly/build-tree/mozilla/browser/components/places/content/places.js"
-
- var placeSpec = PlacesUtils.history.queriesToQueryString(queries,
- queries.length,
- options);
- var placeURI = Cc["@mozilla.org/network/io-service;1"].
- getService(Ci.nsIIOService).
- newURI(placeSpec, null, null);
-
- // 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.
- var title = PlacesUIUtils.getString("saveSearch.title");
- var inputLabel = PlacesUIUtils.getString("saveSearch.inputLabel");
- var defaultText = PlacesUIUtils.getString("saveSearch.defaultText");
-
- var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"].
- getService(Ci.nsIPromptService);
- 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;
-
- // Add the place: uri as a bookmark under the bookmarks root.
- var txn = PlacesUIUtils.ptm.createItem(placeURI,
- PlacesUtils.bookmarksMenuFolderId,
- PlacesUtils.bookmarks.DEFAULT_INDEX,
- input.value);
- PlacesUIUtils.ptm.doTransaction(txn);
-
- // select and load the new query
- this._places.selectPlaceURI(placeSpec);
- }
- };
-
- /**
- * A set of utilities relating to search within Bookmarks and History.
- */
- var PlacesSearchBox = {
-
- /**
- * The Search text field
- */
- get searchFilter() {
- return document.getElementById("searchFilter");
- },
-
- /**
- * Folders to include when searching.
- */
- _folders: [],
- get folders() {
- if (this._folders.length == 0)
- this._folders.push(PlacesUtils.bookmarksMenuFolderId,
- PlacesUtils.unfiledBookmarksFolderId,
- PlacesUtils.toolbarFolderId);
- return this._folders;
- },
- set folders(aFolders) {
- this._folders = aFolders;
- return aFolders;
- },
-
- /**
- * Run a search for the specified text, over the collection specified by
- * the dropdown arrow. The default is all bookmarks, but can be
- * localized to the active collection.
- * @param filterString
- * The text to search for.
- */
- search: function PSB_search(filterString) {
- 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
- if ((filterString == "" || this.searchFilter.hasAttribute("empty"))) {
- PO.onPlaceSelected(false);
- return;
- }
-
- var currentOptions = PO.getCurrentOptions();
- var content = PO._content;
-
- switch (PlacesSearchBox.filterCollection) {
- case "collection":
- content.applyFilter(filterString, this.folders);
- // XXX changing the button text is badness
- //var scopeBtn = document.getElementById("scopeBarFolder");
- //scopeBtn.label = PlacesOrganizer._places.selectedNode.title;
- break;
- case "bookmarks":
- content.applyFilter(filterString,
- [PlacesUtils.bookmarksMenuFolderId,
- PlacesUtils.toolbarFolderId,
- PlacesUtils.unfiledBookmarksFolderId]);
- break;
- case "history":
- if (currentOptions.queryType != Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY) {
- var query = PlacesUtils.history.getNewQuery();
- query.searchTerms = filterString;
- var options = currentOptions.clone();
- options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY;
- content.load([query], options);
- }
- else
- content.applyFilter(filterString);
- break;
- case "all":
- content.applyFilter(filterString);
- break;
- }
-
- PlacesSearchBox.showSearchUI();
- this.searchFilter.setAttribute("filtered", "true");
-
- // Update the details panel
- PlacesOrganizer.onContentTreeSelect();
- },
-
- /**
- * Finds across all bookmarks
- */
- findAll: function PSB_findAll() {
- this.filterCollection = "all";
- this.focus();
- },
-
- /**
- * Finds in the currently selected Place.
- */
- findCurrent: function PSB_findCurrent() {
- this.filterCollection = "collection";
- 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) {
- if (title)
- this.searchFilter.emptyText =
- PlacesUIUtils.getFormattedString("searchCurrentDefault", [title]);
- else
- this.searchFilter.emptyText = this.filterCollection == "history" ?
- PlacesUIUtils.getString("searchHistory") :
- PlacesUIUtils.getString("searchBookmarks");
- },
-
- /**
- * Gets/sets the active collection from the dropdown menu.
- */
- get filterCollection() {
- return this.searchFilter.getAttribute("collection");
- },
- set filterCollection(collectionName) {
- this.searchFilter.setAttribute("collection", collectionName);
- if (this.searchFilter.value)
- return; // don't overwrite pre-existing search terms
- var newGrayText = null;
- if (collectionName == "collection")
- newGrayText = PlacesOrganizer._places.selectedNode.title;
- this.updateCollectionTitle(newGrayText);
- return collectionName;
- },
-
- /**
- * Focus the search box
- */
- focus: function PSB_focus() {
- this.searchFilter.focus();
- },
-
- /**
- * Set up the gray text in the search bar as the Places View loads.
- */
- init: function PSB_init() {
- this.updateCollectionTitle();
- },
-
- /**
- * Gets or sets the text shown in the Places Search Box
- */
- get value() {
- return this.searchFilter.value;
- },
- set value(value) {
- return this.searchFilter.value = value;
- },
-
- showSearchUI: function PSB_showSearchUI() {
- // Hide the advanced search controls when the user hasn't searched
- var searchModifiers = document.getElementById("searchModifiers");
- searchModifiers.hidden = false;
-
- //@line 945 "/build/buildd/firefox-3.0-3.0.14+build2+nobinonly/build-tree/mozilla/browser/components/places/content/places.js"
- },
-
- hideSearchUI: function PSB_hideSearchUI() {
- var searchModifiers = document.getElementById("searchModifiers");
- searchModifiers.hidden = true;
- }
- };
-
- /**
- * Functions and data for advanced query builder
- */
- var PlacesQueryBuilder = {
-
- queries: [],
- queryOptions: null,
-
- //@line 1424 "/build/buildd/firefox-3.0-3.0.14+build2+nobinonly/build-tree/mozilla/browser/components/places/content/places.js"
-
- onScopeSelected: function PQB_onScopeSelected(aButton) {
- var id = aButton.getAttribute("id");
- // get scope bar
- var bar = document.getElementById("organizerScopeBar");
- var child = bar.firstChild;
- while (child) {
- if (child.getAttribute("id") != id)
- child.removeAttribute("checked");
- else
- child.setAttribute("checked", "true");
- child = child.nextSibling;
- }
-
- // update collection type and get folders
- var folders = [];
- switch (id) {
- case "scopeBarHistory":
- PlacesSearchBox.filterCollection = "history";
- folders = [];
- break;
- case "scopeBarFolder":
- var selectedFolder = PlacesOrganizer._places.selectedNode.itemId;
- // note "all bookmarks" isn't the concrete parent of the top-level
- // bookmark folders
- if (selectedFolder != PlacesUIUtils.allBookmarksFolderId) {
- PlacesSearchBox.filterCollection = "collection";
- folders.push(PlacesOrganizer._places.selectedNode.itemId);
- break;
- }
- default: // all bookmarks
- PlacesSearchBox.filterCollection = "bookmarks";
- folders.push(PlacesUtils.bookmarksMenuFolderId,
- PlacesUtils.toolbarFolderId,
- PlacesUtils.unfiledBookmarksFolderId);
- }
-
- // set scope, and re-search
- PlacesSearchBox.folders = folders;
- PlacesSearchBox.search(PlacesSearchBox.searchFilter.value);
- }
- };
-
- /**
- * Population and commands for the View Menu.
- */
- var ViewMenu = {
- /**
- * Removes content generated previously from a menupopup.
- * @param popup
- * The popup that contains the previously generated content.
- * @param startID
- * The id attribute of an element that is the start of the
- * dynamically generated region - remove elements after this
- * item only.
- * Must be contained by popup. Can be null (in which case the
- * contents of popup are removed).
- * @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
- * if startID is null.
- * @returns The element for the caller to insert new items before,
- * null if the caller should just append to the popup.
- */
- _clean: function VM__clean(popup, startID, endID) {
- if (endID)
- NS_ASSERT(startID, "meaningless to have valid endID and null startID");
- if (startID) {
- var startElement = document.getElementById(startID);
- NS_ASSERT(startElement.parentNode ==
- popup, "startElement is not in popup");
- NS_ASSERT(startElement,
- "startID does not correspond to an existing element");
- var endElement = null;
- if (endID) {
- endElement = document.getElementById(endID);
- NS_ASSERT(endElement.parentNode == popup,
- "endElement is not in popup");
- NS_ASSERT(endElement,
- "endID does not correspond to an existing element");
- }
- while (startElement.nextSibling != endElement)
- popup.removeChild(startElement.nextSibling);
- return endElement;
- }
- else {
- while(popup.hasChildNodes())
- popup.removeChild(popup.firstChild);
- }
- 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
- * the type of the menuitem, e.g. "radio" or "checkbox".
- * Can be null (no-type).
- * 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) {
- var popup = event.target;
- var pivot = this._clean(popup, startID, endID);
-
- // 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.
- 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;
- var menuitem = document.createElement("menuitem");
- menuitem.id = "menucol_" + column.id;
- menuitem.column = column;
- var label = column.getAttribute("label");
- if (propertyPrefix) {
- var menuitemPrefix = propertyPrefix;
- // for string properties, use "name" as the id, instead of "title"
- // see bug #386287 for details
- var columnId = column.getAttribute("anonid");
- menuitemPrefix += columnId == "title" ? "name" : columnId;
- label = PlacesUIUtils.getString(menuitemPrefix + ".label");
- var accesskey = PlacesUIUtils.getString(menuitemPrefix + ".accesskey");
- menuitem.setAttribute("accesskey", accesskey);
- }
- menuitem.setAttribute("label", label);
- if (type == "radio") {
- menuitem.setAttribute("type", "radio");
- menuitem.setAttribute("name", "columns");
- // This column is the sort key. Its item is checked.
- if (column.getAttribute("sortDirection") != "") {
- menuitem.setAttribute("checked", "true");
- isSorted = true;
- }
- }
- else if (type == "checkbox") {
- menuitem.setAttribute("type", "checkbox");
- // Cannot uncheck the primary column.
- if (column.getAttribute("primary") == "true")
- menuitem.setAttribute("disabled", "true");
- // Items for visible columns are checked.
- if (!column.hidden)
- menuitem.setAttribute("checked", "true");
- }
- if (pivot)
- popup.insertBefore(menuitem, pivot);
- else
- popup.appendChild(menuitem);
- }
- event.stopPropagation();
- },
-
- /**
- * Set up the content of the view menu.
- */
- populateSortMenu: function VM_populateSortMenu(event) {
- this.fillWithColumns(event, "viewUnsorted", "directionSeparator", "radio", "view.sortBy.");
-
- var sortColumn = this._getSortColumn();
- var viewSortAscending = document.getElementById("viewSortAscending");
- var viewSortDescending = document.getElementById("viewSortDescending");
- // We need to remove an existing checked attribute because the unsorted
- // 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");
- }
- },
-
- /**
- * Shows/Hides a tree column.
- * @param element
- * The menuitem element for the column
- */
- showHideColumn: function VM_showHideColumn(element) {
- var column = element.column;
-
- var splitter = column.nextSibling;
- if (splitter && splitter.localName != "splitter")
- splitter = null;
-
- if (element.getAttribute("checked") == "true") {
- column.setAttribute("hidden", "false");
- if (splitter)
- splitter.removeAttribute("hidden");
- }
- else {
- column.setAttribute("hidden", "true");
- if (splitter)
- splitter.setAttribute("hidden", "true");
- }
- },
-
- /**
- * Gets the last column that was sorted.
- * @returns the currently sorted column, null if there is no sorted column.
- */
- _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;
- },
-
- /**
- * 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.
- * @param aDirection
- * The direction to sort - "ascending" or "descending".
- * Can be null - the last direction or descending will be used.
- *
- * If both aColumnID and aDirection are null, the view will be unsorted.
- */
- setSortColumn: function VM_setSortColumn(aColumn, aDirection) {
- var result = document.getElementById("placeContent").getResult();
- if (!aColumn && !aDirection) {
- result.sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_NONE;
- return;
- }
-
- var columnId;
- if (aColumn) {
- columnId = aColumn.getAttribute("anonid")
- if (!aDirection) {
- var sortColumn = this._getSortColumn();
- aDirection = sortColumn ?
- sortColumn.getAttribute("sortDirection") : "descending";
- }
- }
- else {
- var sortColumn = this._getSortColumn();
- columnId = sortColumn ? sortColumn.getAttribute("anonid") : "title";
- }
-
- var sortingMode;
- var sortingAnnotation = "";
- const NHQO = Ci.nsINavHistoryQueryOptions;
- switch (columnId) {
- case "title":
- sortingMode = aDirection == "descending" ?
- NHQO.SORT_BY_TITLE_DESCENDING : NHQO.SORT_BY_TITLE_ASCENDING;
- break;
- case "url":
- sortingMode = aDirection == "descending" ?
- NHQO.SORT_BY_URI_DESCENDING : NHQO.SORT_BY_URI_ASCENDING;
- break;
- case "date":
- sortingMode = aDirection == "descending" ?
- NHQO.SORT_BY_DATE_DESCENDING : NHQO.SORT_BY_DATE_ASCENDING;
- break;
- case "visitCount":
- sortingMode = aDirection == "descending" ?
- NHQO.SORT_BY_VISITCOUNT_DESCENDING : NHQO.SORT_BY_VISITCOUNT_ASCENDING;
- break;
- case "keyword":
- sortingMode = aDirection == "descending" ?
- NHQO.SORT_BY_KEYWORD_DESCENDING : NHQO.SORT_BY_KEYWORD_ASCENDING;
- break;
- case "description":
- sortingAnnotation = DESCRIPTION_ANNO;
- sortingMode = aDirection == "descending" ?
- NHQO.SORT_BY_ANNOTATION_DESCENDING : NHQO.SORT_BY_ANNOTATION_ASCENDING;
- break;
- case "dateAdded":
- sortingMode = aDirection == "descending" ?
- NHQO.SORT_BY_DATEADDED_DESCENDING : NHQO.SORT_BY_DATEADDED_ASCENDING;
- break;
- case "lastModified":
- sortingMode = aDirection == "descending" ?
- NHQO.SORT_BY_LASTMODIFIED_DESCENDING : NHQO.SORT_BY_LASTMODIFIED_ASCENDING;
- break;
- default:
- throw("Invalid Column");
- }
- result.sortingAnnotation = sortingAnnotation;
- result.sortingMode = sortingMode;
- }
- };
-