2007-12-14 12:22:12 -08:00
|
|
|
# ***** 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 the Places Browser Integration
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is Google Inc.
|
|
|
|
# Portions created by the Initial Developer are Copyright (C) 2006
|
|
|
|
# the Initial Developer. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s):
|
|
|
|
# Ben Goodger <beng@google.com>
|
|
|
|
# Annie Sullivan <annie.sullivan@gmail.com>
|
|
|
|
# Joe Hughes <joe@retrovirus.com>
|
|
|
|
# Asaf Romano <mano@mozilla.com>
|
2008-12-18 12:12:40 -08:00
|
|
|
# Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
2010-11-22 11:34:57 -08:00
|
|
|
# Marco Bonardo <mak77@bonardo.net>
|
2007-12-14 12:22:12 -08: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 *****
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-01-29 20:37:41 -08:00
|
|
|
|
|
|
|
var StarUI = {
|
|
|
|
_itemId: -1,
|
|
|
|
uri: null,
|
|
|
|
_batching: false,
|
|
|
|
|
|
|
|
_element: function(aID) {
|
|
|
|
return document.getElementById(aID);
|
|
|
|
},
|
|
|
|
|
2007-08-17 00:22:12 -07:00
|
|
|
// Edit-bookmark panel
|
|
|
|
get panel() {
|
2007-10-30 18:16:46 -07:00
|
|
|
delete this.panel;
|
2008-01-29 20:37:41 -08:00
|
|
|
var element = this._element("editBookmarkPanel");
|
2007-11-11 10:36:52 -08:00
|
|
|
// initially the panel is hidden
|
|
|
|
// to avoid impacting startup / new window performance
|
|
|
|
element.hidden = false;
|
2007-11-16 20:29:07 -08:00
|
|
|
element.addEventListener("popuphidden", this, false);
|
2009-05-15 06:33:59 -07:00
|
|
|
element.addEventListener("keypress", this, false);
|
2007-10-30 18:16:46 -07:00
|
|
|
return this.panel = element;
|
2007-08-17 00:22:12 -07:00
|
|
|
},
|
|
|
|
|
2010-07-26 16:04:13 -07:00
|
|
|
// Array of command elements to disable when the panel is opened.
|
|
|
|
get _blockedCommands() {
|
|
|
|
delete this._blockedCommands;
|
|
|
|
return this._blockedCommands =
|
|
|
|
["cmd_close", "cmd_closeWindow"].map(function (id) this._element(id), this);
|
|
|
|
},
|
|
|
|
|
2008-01-29 20:37:41 -08:00
|
|
|
_blockCommands: function SU__blockCommands() {
|
2010-07-26 16:04:13 -07:00
|
|
|
this._blockedCommands.forEach(function (elt) {
|
2007-12-23 19:03:41 -08:00
|
|
|
// make sure not to permanently disable this item (see bug 409155)
|
|
|
|
if (elt.hasAttribute("wasDisabled"))
|
2010-07-26 16:04:13 -07:00
|
|
|
return;
|
|
|
|
if (elt.getAttribute("disabled") == "true") {
|
2007-08-30 09:13:33 -07:00
|
|
|
elt.setAttribute("wasDisabled", "true");
|
2010-07-26 16:04:13 -07:00
|
|
|
} else {
|
2007-08-30 09:13:33 -07:00
|
|
|
elt.setAttribute("wasDisabled", "false");
|
|
|
|
elt.setAttribute("disabled", "true");
|
|
|
|
}
|
2010-07-26 16:04:13 -07:00
|
|
|
});
|
2007-08-30 09:13:33 -07:00
|
|
|
},
|
|
|
|
|
2008-01-29 20:37:41 -08:00
|
|
|
_restoreCommandsState: function SU__restoreCommandsState() {
|
2010-07-26 16:04:13 -07:00
|
|
|
this._blockedCommands.forEach(function (elt) {
|
2007-08-30 09:13:33 -07:00
|
|
|
if (elt.getAttribute("wasDisabled") != "true")
|
|
|
|
elt.removeAttribute("disabled");
|
|
|
|
elt.removeAttribute("wasDisabled");
|
2010-07-26 16:04:13 -07:00
|
|
|
});
|
2007-08-30 09:13:33 -07:00
|
|
|
},
|
|
|
|
|
2007-08-17 00:22:12 -07:00
|
|
|
// nsIDOMEventListener
|
2008-01-29 20:37:41 -08:00
|
|
|
handleEvent: function SU_handleEvent(aEvent) {
|
2007-08-30 09:13:33 -07:00
|
|
|
switch (aEvent.type) {
|
2007-11-16 20:29:07 -08:00
|
|
|
case "popuphidden":
|
2007-08-30 09:13:33 -07:00
|
|
|
if (aEvent.originalTarget == this.panel) {
|
2008-01-29 20:37:41 -08:00
|
|
|
if (!this._element("editBookmarkPanelContent").hidden)
|
2008-03-13 17:52:21 -07:00
|
|
|
this.quitEditMode();
|
2010-10-14 01:46:32 -07:00
|
|
|
|
2007-08-30 09:13:33 -07:00
|
|
|
this._restoreCommandsState();
|
2008-01-29 20:37:41 -08:00
|
|
|
this._itemId = -1;
|
|
|
|
if (this._batching) {
|
2012-02-28 15:40:38 -08:00
|
|
|
PlacesUtils.transactionManager.endBatch();
|
2008-01-29 20:37:41 -08:00
|
|
|
this._batching = false;
|
|
|
|
}
|
2010-10-14 01:46:32 -07:00
|
|
|
|
|
|
|
switch (this._actionOnHide) {
|
|
|
|
case "cancel": {
|
2012-02-28 15:40:38 -08:00
|
|
|
PlacesUtils.transactionManager.undoTransaction();
|
2010-10-14 01:46:32 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "remove": {
|
|
|
|
// Remove all bookmarks for the bookmark's url, this also removes
|
|
|
|
// the tags for the url.
|
2012-02-28 15:40:38 -08:00
|
|
|
PlacesUtils.transactionManager.beginBatch();
|
2010-10-14 01:46:32 -07:00
|
|
|
let itemIds = PlacesUtils.getBookmarksForURI(this._uriForRemoval);
|
|
|
|
for (let i = 0; i < itemIds.length; i++) {
|
2012-02-28 15:40:38 -08:00
|
|
|
let txn = new PlacesRemoveItemTransaction(itemIds[i]);
|
|
|
|
PlacesUtils.transactionManager.doTransaction(txn);
|
2010-10-14 01:46:32 -07:00
|
|
|
}
|
2012-02-28 15:40:38 -08:00
|
|
|
PlacesUtils.transactionManager.endBatch();
|
2010-10-14 01:46:32 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this._actionOnHide = "";
|
2007-08-30 09:13:33 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "keypress":
|
2011-12-08 01:21:32 -08:00
|
|
|
if (aEvent.defaultPrevented) {
|
2009-05-15 06:33:59 -07:00
|
|
|
// The event has already been consumed inside of the panel.
|
|
|
|
break;
|
2008-03-13 17:52:21 -07:00
|
|
|
}
|
2009-05-15 06:33:59 -07:00
|
|
|
switch (aEvent.keyCode) {
|
|
|
|
case KeyEvent.DOM_VK_ESCAPE:
|
|
|
|
if (!this._element("editBookmarkPanelContent").hidden)
|
|
|
|
this.cancelButtonOnCommand();
|
|
|
|
break;
|
|
|
|
case KeyEvent.DOM_VK_RETURN:
|
|
|
|
if (aEvent.target.className == "expander-up" ||
|
|
|
|
aEvent.target.className == "expander-down" ||
|
|
|
|
aEvent.target.id == "editBMPanel_newFolderButton") {
|
2011-12-08 01:21:32 -08:00
|
|
|
//XXX Why is this necessary? The defaultPrevented check should
|
2009-05-15 06:33:59 -07:00
|
|
|
// be enough.
|
|
|
|
break;
|
|
|
|
}
|
2008-01-29 20:37:41 -08:00
|
|
|
this.panel.hidePopup();
|
2009-05-15 06:33:59 -07:00
|
|
|
break;
|
2008-01-29 20:37:41 -08:00
|
|
|
}
|
2007-08-30 09:13:33 -07:00
|
|
|
break;
|
|
|
|
}
|
2007-08-17 00:22:12 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_overlayLoaded: false,
|
|
|
|
_overlayLoading: false,
|
|
|
|
showEditBookmarkPopup:
|
2008-01-29 20:37:41 -08:00
|
|
|
function SU_showEditBookmarkPopup(aItemId, aAnchorElement, aPosition) {
|
2007-08-17 00:22:12 -07:00
|
|
|
// Performance: load the overlay the first time the panel is opened
|
|
|
|
// (see bug 392443).
|
|
|
|
if (this._overlayLoading)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this._overlayLoaded) {
|
|
|
|
this._doShowEditBookmarkPanel(aItemId, aAnchorElement, aPosition);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-24 02:11:17 -08:00
|
|
|
this._overlayLoading = true;
|
|
|
|
document.loadOverlay(
|
|
|
|
"chrome://browser/content/places/editBookmarkOverlay.xul",
|
|
|
|
(function (aSubject, aTopic, aData) {
|
2011-03-23 04:38:46 -07:00
|
|
|
//XXX We just caused localstore.rdf to be re-applied (bug 640158)
|
|
|
|
retrieveToolbarIconsizesFromTheme();
|
|
|
|
|
2012-02-24 02:11:17 -08:00
|
|
|
// Move the header (star, title, button) into the grid,
|
|
|
|
// so that it aligns nicely with the other items (bug 484022).
|
|
|
|
let header = this._element("editBookmarkPanelHeader");
|
|
|
|
let rows = this._element("editBookmarkPanelGrid").lastChild;
|
|
|
|
rows.insertBefore(header, rows.firstChild);
|
|
|
|
header.hidden = false;
|
|
|
|
|
|
|
|
this._overlayLoading = false;
|
|
|
|
this._overlayLoaded = true;
|
|
|
|
this._doShowEditBookmarkPanel(aItemId, aAnchorElement, aPosition);
|
|
|
|
}).bind(this)
|
|
|
|
);
|
2007-08-17 00:22:12 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_doShowEditBookmarkPanel:
|
2008-01-29 22:46:45 -08:00
|
|
|
function SU__doShowEditBookmarkPanel(aItemId, aAnchorElement, aPosition) {
|
2008-12-18 12:12:40 -08:00
|
|
|
if (this.panel.state != "closed")
|
|
|
|
return;
|
|
|
|
|
2008-07-29 16:22:28 -07:00
|
|
|
this._blockCommands(); // un-done in the popuphiding handler
|
|
|
|
|
|
|
|
// Set panel title:
|
|
|
|
// if we are batching, i.e. the bookmark has been added now,
|
|
|
|
// then show Page Bookmarked, else if the bookmark did already exist,
|
|
|
|
// we are about editing it, then use Edit This Bookmark.
|
|
|
|
this._element("editBookmarkPanelTitle").value =
|
|
|
|
this._batching ?
|
2009-07-13 15:10:04 -07:00
|
|
|
gNavigatorBundle.getString("editBookmarkPanel.pageBookmarkedTitle") :
|
|
|
|
gNavigatorBundle.getString("editBookmarkPanel.editBookmarkTitle");
|
2008-07-29 16:22:28 -07:00
|
|
|
|
|
|
|
// No description; show the Done, Cancel;
|
|
|
|
this._element("editBookmarkPanelDescription").textContent = "";
|
|
|
|
this._element("editBookmarkPanelBottomButtons").hidden = false;
|
|
|
|
this._element("editBookmarkPanelContent").hidden = false;
|
|
|
|
|
|
|
|
// The remove button is shown only if we're not already batching, i.e.
|
|
|
|
// if the cancel button/ESC does not remove the bookmark.
|
|
|
|
this._element("editBookmarkPanelRemoveButton").hidden = this._batching;
|
|
|
|
|
2008-12-11 11:47:25 -08:00
|
|
|
// The label of the remove button differs if the URI is bookmarked
|
|
|
|
// multiple times.
|
|
|
|
var bookmarks = PlacesUtils.getBookmarksForURI(gBrowser.currentURI);
|
2009-07-13 15:10:04 -07:00
|
|
|
var forms = gNavigatorBundle.getString("editBookmark.removeBookmarks.label");
|
2008-12-11 11:47:25 -08:00
|
|
|
var label = PluralForm.get(bookmarks.length, forms).replace("#1", bookmarks.length);
|
|
|
|
this._element("editBookmarkPanelRemoveButton").label = label;
|
|
|
|
|
2008-07-29 16:22:28 -07:00
|
|
|
// unset the unstarred state, if set
|
|
|
|
this._element("editBookmarkPanelStarIcon").removeAttribute("unstarred");
|
|
|
|
|
|
|
|
this._itemId = aItemId !== undefined ? aItemId : this._itemId;
|
|
|
|
this.beginBatch();
|
|
|
|
|
2008-12-18 12:12:40 -08:00
|
|
|
// Consume dismiss clicks, see bug 400924
|
|
|
|
this.panel.popupBoxObject
|
|
|
|
.setConsumeRollupEvent(Ci.nsIPopupBoxObject.ROLLUP_CONSUME);
|
2010-12-05 14:10:45 -08:00
|
|
|
this.panel.openPopup(aAnchorElement, aPosition);
|
2008-01-29 22:46:45 -08:00
|
|
|
|
|
|
|
gEditItemOverlay.initPanel(this._itemId,
|
2007-09-21 15:57:18 -07:00
|
|
|
{ hiddenRows: ["description", "location",
|
2007-09-22 15:58:35 -07:00
|
|
|
"loadInSidebar", "keyword"] });
|
2007-11-17 05:28:16 -08:00
|
|
|
},
|
|
|
|
|
2008-01-29 22:46:45 -08:00
|
|
|
panelShown:
|
|
|
|
function SU_panelShown(aEvent) {
|
2008-01-30 13:19:39 -08:00
|
|
|
if (aEvent.target == this.panel) {
|
|
|
|
if (!this._element("editBookmarkPanelContent").hidden) {
|
2010-02-25 10:30:09 -08:00
|
|
|
let fieldToFocus = "editBMPanel_" +
|
2009-02-26 17:27:39 -08:00
|
|
|
gPrefService.getCharPref("browser.bookmarks.editDialog.firstEditField");
|
|
|
|
var elt = this._element(fieldToFocus);
|
|
|
|
elt.focus();
|
|
|
|
elt.select();
|
2008-01-30 13:19:39 -08:00
|
|
|
}
|
2009-02-26 17:27:39 -08:00
|
|
|
else {
|
|
|
|
// Note this isn't actually used anymore, we should remove this
|
|
|
|
// once we decide not to bring back the page bookmarked notification
|
2008-01-30 13:19:39 -08:00
|
|
|
this.panel.focus();
|
2009-02-26 17:27:39 -08:00
|
|
|
}
|
2008-01-29 22:46:45 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2008-03-13 17:52:21 -07:00
|
|
|
quitEditMode: function SU_quitEditMode() {
|
|
|
|
this._element("editBookmarkPanelContent").hidden = true;
|
|
|
|
this._element("editBookmarkPanelBottomButtons").hidden = true;
|
|
|
|
gEditItemOverlay.uninitPanel(true);
|
|
|
|
},
|
|
|
|
|
2008-01-29 22:46:45 -08:00
|
|
|
editButtonCommand: function SU_editButtonCommand() {
|
|
|
|
this.showEditBookmarkPopup();
|
|
|
|
},
|
|
|
|
|
|
|
|
cancelButtonOnCommand: function SU_cancelButtonOnCommand() {
|
2010-10-14 01:46:32 -07:00
|
|
|
this._actionOnHide = "cancel";
|
2008-03-13 17:52:21 -07:00
|
|
|
this.panel.hidePopup();
|
2008-01-29 22:46:45 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
removeBookmarkButtonCommand: function SU_removeBookmarkButtonCommand() {
|
2010-10-14 01:46:32 -07:00
|
|
|
this._uriForRemoval = PlacesUtils.bookmarks.getBookmarkURI(this._itemId);
|
|
|
|
this._actionOnHide = "remove";
|
|
|
|
this.panel.hidePopup();
|
2008-01-30 13:19:39 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
beginBatch: function SU_beginBatch() {
|
|
|
|
if (!this._batching) {
|
2012-02-28 15:40:38 -08:00
|
|
|
PlacesUtils.transactionManager.beginBatch();
|
2008-01-30 13:19:39 -08:00
|
|
|
this._batching = true;
|
|
|
|
}
|
2008-01-29 22:46:45 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var PlacesCommandHook = {
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2007-08-28 14:47:43 -07:00
|
|
|
* Adds a bookmark to the page loaded in the given browser.
|
2007-08-17 00:22:12 -07:00
|
|
|
*
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param aBrowser
|
2007-08-28 14:47:43 -07:00
|
|
|
* a <browser> element.
|
|
|
|
* @param [optional] aParent
|
|
|
|
* The folder in which to create a new bookmark if the page loaded in
|
2007-09-16 18:42:15 -07:00
|
|
|
* aBrowser isn't bookmarked yet, defaults to the unfiled root.
|
2007-08-17 00:22:12 -07:00
|
|
|
* @param [optional] aShowEditUI
|
|
|
|
* whether or not to show the edit-bookmark UI for the bookmark item
|
|
|
|
*/
|
2007-11-13 08:30:58 -08:00
|
|
|
bookmarkPage: function PCH_bookmarkPage(aBrowser, aParent, aShowEditUI) {
|
2007-08-17 00:22:12 -07:00
|
|
|
var uri = aBrowser.currentURI;
|
|
|
|
var itemId = PlacesUtils.getMostRecentBookmarkForURI(uri);
|
|
|
|
if (itemId == -1) {
|
|
|
|
// Copied over from addBookmarkForBrowser:
|
|
|
|
// Bug 52536: We obtain the URL and title from the nsIWebNavigation
|
|
|
|
// associated with a <browser/> rather than from a DOMWindow.
|
|
|
|
// This is because when a full page plugin is loaded, there is
|
|
|
|
// no DOMWindow (?) but information about the loaded document
|
|
|
|
// may still be obtained from the webNavigation.
|
|
|
|
var webNav = aBrowser.webNavigation;
|
|
|
|
var url = webNav.currentURI;
|
|
|
|
var title;
|
|
|
|
var description;
|
2008-04-08 11:41:04 -07:00
|
|
|
var charset;
|
2007-08-17 00:22:12 -07:00
|
|
|
try {
|
2007-12-14 16:24:09 -08:00
|
|
|
title = webNav.document.title || url.spec;
|
2008-03-13 12:25:49 -07:00
|
|
|
description = PlacesUIUtils.getDescriptionFromDocument(webNav.document);
|
2008-04-08 11:41:04 -07:00
|
|
|
charset = webNav.document.characterSet;
|
2007-08-17 00:22:12 -07:00
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
|
2008-01-30 13:19:39 -08:00
|
|
|
if (aShowEditUI) {
|
|
|
|
// If we bookmark the page here (i.e. page was not "starred" already)
|
|
|
|
// but open right into the "edit" state, start batching here, so
|
|
|
|
// "Cancel" in that state removes the bookmark.
|
|
|
|
StarUI.beginBatch();
|
|
|
|
}
|
|
|
|
|
2007-11-19 18:01:53 -08:00
|
|
|
var parent = aParent != undefined ?
|
|
|
|
aParent : PlacesUtils.unfiledBookmarksFolderId;
|
2010-04-18 07:06:01 -07:00
|
|
|
var descAnno = { name: PlacesUIUtils.DESCRIPTION_ANNO, value: description };
|
2012-02-28 15:40:38 -08:00
|
|
|
var txn = new PlacesCreateBookmarkTransaction(uri, parent,
|
|
|
|
PlacesUtils.bookmarks.DEFAULT_INDEX,
|
|
|
|
title, null, [descAnno]);
|
|
|
|
PlacesUtils.transactionManager.doTransaction(txn);
|
2008-04-08 11:41:04 -07:00
|
|
|
// Set the character-set
|
|
|
|
if (charset)
|
|
|
|
PlacesUtils.history.setCharsetForURI(uri, charset);
|
2008-01-29 20:37:41 -08:00
|
|
|
itemId = PlacesUtils.getMostRecentBookmarkForURI(uri);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-08-17 00:22:12 -07:00
|
|
|
|
2008-04-13 18:00:16 -07:00
|
|
|
// Revert the contents of the location bar
|
2008-09-25 04:33:51 -07:00
|
|
|
if (gURLBar)
|
|
|
|
gURLBar.handleRevert();
|
2008-04-13 18:00:16 -07:00
|
|
|
|
2008-01-29 20:37:41 -08:00
|
|
|
// dock the panel to the star icon when possible, otherwise dock
|
|
|
|
// it to the content area
|
|
|
|
if (aBrowser.contentWindow == window.content) {
|
|
|
|
var starIcon = aBrowser.ownerDocument.getElementById("star-button");
|
|
|
|
if (starIcon && isElementVisible(starIcon)) {
|
|
|
|
if (aShowEditUI)
|
2011-01-24 03:16:21 -08:00
|
|
|
StarUI.showEditBookmarkPopup(itemId, starIcon, "bottomcenter topright");
|
2008-01-29 20:37:41 -08:00
|
|
|
return;
|
2007-11-13 08:30:58 -08:00
|
|
|
}
|
|
|
|
}
|
2008-01-29 20:37:41 -08:00
|
|
|
|
|
|
|
StarUI.showEditBookmarkPopup(itemId, aBrowser, "overlap");
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a bookmark to the page loaded in the current tab.
|
|
|
|
*/
|
2007-08-28 14:47:43 -07:00
|
|
|
bookmarkCurrentPage: function PCH_bookmarkCurrentPage(aShowEditUI, aParent) {
|
2009-09-20 03:58:27 -07:00
|
|
|
this.bookmarkPage(gBrowser.selectedBrowser, aParent, aShowEditUI);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2007-08-17 00:22:12 -07:00
|
|
|
/**
|
|
|
|
* Adds a bookmark to the page targeted by a link.
|
2007-08-28 14:47:43 -07:00
|
|
|
* @param aParent
|
|
|
|
* The folder in which to create a new bookmark if aURL isn't
|
|
|
|
* bookmarked.
|
|
|
|
* @param aURL (string)
|
|
|
|
* the address of the link target
|
|
|
|
* @param aTitle
|
|
|
|
* The link text
|
2007-08-17 00:22:12 -07:00
|
|
|
*/
|
2007-08-28 14:47:43 -07:00
|
|
|
bookmarkLink: function PCH_bookmarkLink(aParent, aURL, aTitle) {
|
2008-02-01 16:39:05 -08:00
|
|
|
var linkURI = makeURI(aURL);
|
2007-08-17 00:22:12 -07:00
|
|
|
var itemId = PlacesUtils.getMostRecentBookmarkForURI(linkURI);
|
2011-10-27 02:11:43 -07:00
|
|
|
if (itemId == -1) {
|
|
|
|
PlacesUIUtils.showBookmarkDialog({ action: "add"
|
|
|
|
, type: "bookmark"
|
|
|
|
, uri: linkURI
|
|
|
|
, title: aTitle
|
|
|
|
, hiddenRows: [ "description"
|
|
|
|
, "location"
|
|
|
|
, "loadInSidebar"
|
|
|
|
, "keyword" ]
|
2011-11-11 13:39:26 -08:00
|
|
|
}, window);
|
2011-10-27 02:11:43 -07:00
|
|
|
}
|
2008-10-30 10:21:47 -07:00
|
|
|
else {
|
2011-10-27 02:11:43 -07:00
|
|
|
PlacesUIUtils.showBookmarkDialog({ action: "edit"
|
|
|
|
, type: "bookmark"
|
|
|
|
, itemId: itemId
|
2011-11-11 13:39:26 -08:00
|
|
|
}, window);
|
2007-08-17 00:22:12 -07:00
|
|
|
}
|
|
|
|
},
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
2011-01-28 08:46:49 -08:00
|
|
|
* List of nsIURI objects characterizing the tabs currently open in the
|
|
|
|
* browser, modulo pinned tabs. The URIs will be in the order in which their
|
|
|
|
* corresponding tabs appeared and duplicates are discarded.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2011-01-28 08:46:49 -08:00
|
|
|
get uniqueCurrentPages() {
|
|
|
|
let uniquePages = {};
|
|
|
|
let URIs = [];
|
|
|
|
gBrowser.visibleTabs.forEach(function (tab) {
|
|
|
|
let spec = tab.linkedBrowser.currentURI.spec;
|
|
|
|
if (!tab.pinned && !(spec in uniquePages)) {
|
|
|
|
uniquePages[spec] = null;
|
|
|
|
URIs.push(tab.linkedBrowser.currentURI);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return URIs;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a folder with bookmarks to all of the currently open tabs in this
|
|
|
|
* window.
|
|
|
|
*/
|
|
|
|
bookmarkCurrentPages: function PCH_bookmarkCurrentPages() {
|
2011-01-28 08:46:49 -08:00
|
|
|
let pages = this.uniqueCurrentPages;
|
|
|
|
if (pages.length > 1) {
|
2011-10-27 02:11:43 -07:00
|
|
|
PlacesUIUtils.showBookmarkDialog({ action: "add"
|
|
|
|
, type: "folder"
|
|
|
|
, URIList: pages
|
|
|
|
, hiddenRows: [ "description" ]
|
2011-11-11 13:39:26 -08:00
|
|
|
}, window);
|
2011-01-28 08:46:49 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates disabled state for the "Bookmark All Tabs" command.
|
|
|
|
*/
|
|
|
|
updateBookmarkAllTabsCommand:
|
|
|
|
function PCH_updateBookmarkAllTabsCommand() {
|
2011-01-31 12:04:03 -08:00
|
|
|
// There's nothing to do in non-browser windows.
|
|
|
|
if (window.location.href != getBrowserURL())
|
|
|
|
return;
|
|
|
|
|
2011-01-28 08:46:49 -08:00
|
|
|
// Disable "Bookmark All Tabs" if there are less than two
|
|
|
|
// "unique current pages".
|
|
|
|
goSetCommandEnabled("Browser:BookmarkAllTabs",
|
|
|
|
this.uniqueCurrentPages.length >= 2);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a Live Bookmark to a feed associated with the current page.
|
|
|
|
* @param url
|
|
|
|
* The nsIURI of the page the feed was attached to
|
|
|
|
* @title title
|
|
|
|
* The title of the feed. Optional.
|
|
|
|
* @subtitle subtitle
|
|
|
|
* A short description of the feed. Optional.
|
|
|
|
*/
|
|
|
|
addLiveBookmark: function PCH_addLiveBookmark(url, feedTitle, feedSubtitle) {
|
2009-07-28 22:55:18 -07:00
|
|
|
var feedURI = makeURI(url);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
var doc = gBrowser.contentDocument;
|
|
|
|
var title = (arguments.length > 1) ? feedTitle : doc.title;
|
|
|
|
|
|
|
|
var description;
|
|
|
|
if (arguments.length > 2)
|
|
|
|
description = feedSubtitle;
|
|
|
|
else
|
2008-03-13 12:25:49 -07:00
|
|
|
description = PlacesUIUtils.getDescriptionFromDocument(doc);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-27 02:11:43 -07:00
|
|
|
var toolbarIP = new InsertionPoint(PlacesUtils.toolbarFolderId, -1);
|
|
|
|
PlacesUIUtils.showBookmarkDialog({ action: "add"
|
|
|
|
, type: "livemark"
|
|
|
|
, feedURI: feedURI
|
|
|
|
, siteURI: gBrowser.currentURI
|
|
|
|
, title: title
|
|
|
|
, description: description
|
|
|
|
, defaultInsertionPoint: toolbarIP
|
|
|
|
, hiddenRows: [ "feedLocation"
|
|
|
|
, "siteLocation"
|
|
|
|
, "description" ]
|
2011-11-11 13:39:26 -08:00
|
|
|
}, window);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens the Places Organizer.
|
2007-11-26 11:04:23 -08:00
|
|
|
* @param aLeftPaneRoot
|
|
|
|
* The query to select in the organizer window - options
|
|
|
|
* are: History, AllBookmarks, BookmarksMenu, BookmarksToolbar,
|
|
|
|
* UnfiledBookmarks and Tags.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2007-11-26 11:04:23 -08:00
|
|
|
showPlacesOrganizer: function PCH_showPlacesOrganizer(aLeftPaneRoot) {
|
2010-03-08 23:49:46 -08:00
|
|
|
var organizer = Services.wm.getMostRecentWindow("Places:Organizer");
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!organizer) {
|
|
|
|
// No currently open places window, so open one with the specified mode.
|
|
|
|
openDialog("chrome://browser/content/places/places.xul",
|
2007-11-26 11:04:23 -08:00
|
|
|
"", "chrome,toolbar=yes,dialog=no,resizable", aLeftPaneRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2007-11-26 11:04:23 -08:00
|
|
|
organizer.PlacesOrganizer.selectLeftPaneQuery(aLeftPaneRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
organizer.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-05-05 06:28:04 -07:00
|
|
|
// View for the history menu.
|
|
|
|
function HistoryMenu(aPopupShowingEvent) {
|
2011-02-10 05:17:54 -08:00
|
|
|
// Workaround for Bug 610187. The sidebar does not include all the Places
|
|
|
|
// views definitions, and we don't need them there.
|
|
|
|
// Defining the prototype inheritance in the prototype itself would cause
|
|
|
|
// browser.js to halt on "PlacesMenu is not defined" error.
|
|
|
|
this.__proto__.__proto__ = PlacesMenu.prototype;
|
2010-05-05 06:28:04 -07:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "_ss",
|
|
|
|
"@mozilla.org/browser/sessionstore;1",
|
|
|
|
"nsISessionStore");
|
|
|
|
PlacesMenu.call(this, aPopupShowingEvent,
|
2012-04-06 16:17:53 -07:00
|
|
|
"place:sort=4&maxResults=15");
|
2010-05-05 06:28:04 -07:00
|
|
|
}
|
2009-07-29 01:49:59 -07:00
|
|
|
|
2010-05-05 06:28:04 -07:00
|
|
|
HistoryMenu.prototype = {
|
|
|
|
toggleRecentlyClosedTabs: function HM_toggleRecentlyClosedTabs() {
|
2009-06-22 16:00:44 -07:00
|
|
|
// enable/disable the Recently Closed Tabs sub menu
|
2010-08-20 22:14:45 -07:00
|
|
|
var undoMenu = this._rootElt.getElementsByClassName("recentlyClosedTabsMenu")[0];
|
2009-06-22 16:00:44 -07:00
|
|
|
|
|
|
|
// no restorable tabs, so disable menu
|
2009-07-29 01:49:59 -07:00
|
|
|
if (this._ss.getClosedTabCount(window) == 0)
|
2010-08-20 22:14:45 -07:00
|
|
|
undoMenu.setAttribute("disabled", true);
|
2009-06-22 16:00:44 -07:00
|
|
|
else
|
2010-08-20 22:14:45 -07:00
|
|
|
undoMenu.removeAttribute("disabled");
|
2009-06-22 16:00:44 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Re-open a closed tab and put it to the end of the tab strip.
|
|
|
|
* Used for a middle click.
|
|
|
|
* @param aEvent
|
|
|
|
* The event when the user clicks the menu item
|
|
|
|
*/
|
|
|
|
_undoCloseMiddleClick: function PHM__undoCloseMiddleClick(aEvent) {
|
|
|
|
if (aEvent.button != 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
undoCloseTab(aEvent.originalTarget.value);
|
|
|
|
gBrowser.moveTabToEnd();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Populate when the history menu is opened
|
|
|
|
*/
|
|
|
|
populateUndoSubmenu: function PHM_populateUndoSubmenu() {
|
2010-08-20 22:14:45 -07:00
|
|
|
var undoMenu = this._rootElt.getElementsByClassName("recentlyClosedTabsMenu")[0];
|
|
|
|
var undoPopup = undoMenu.firstChild;
|
2009-06-22 16:00:44 -07:00
|
|
|
|
|
|
|
// remove existing menu items
|
|
|
|
while (undoPopup.hasChildNodes())
|
|
|
|
undoPopup.removeChild(undoPopup.firstChild);
|
|
|
|
|
|
|
|
// no restorable tabs, so make sure menu is disabled, and return
|
2009-07-29 01:49:59 -07:00
|
|
|
if (this._ss.getClosedTabCount(window) == 0) {
|
2010-08-20 22:14:45 -07:00
|
|
|
undoMenu.setAttribute("disabled", true);
|
2009-06-22 16:00:44 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// enable menu
|
2010-08-20 22:14:45 -07:00
|
|
|
undoMenu.removeAttribute("disabled");
|
2009-06-22 16:00:44 -07:00
|
|
|
|
|
|
|
// populate menu
|
2012-02-20 20:29:20 -08:00
|
|
|
var undoItems = JSON.parse(this._ss.getClosedTabData(window));
|
2009-06-22 16:00:44 -07:00
|
|
|
for (var i = 0; i < undoItems.length; i++) {
|
|
|
|
var m = document.createElement("menuitem");
|
|
|
|
m.setAttribute("label", undoItems[i].title);
|
|
|
|
if (undoItems[i].image) {
|
|
|
|
let iconURL = undoItems[i].image;
|
|
|
|
// don't initiate a connection just to fetch a favicon (see bug 467828)
|
|
|
|
if (/^https?:/.test(iconURL))
|
|
|
|
iconURL = "moz-anno:favicon:" + iconURL;
|
|
|
|
m.setAttribute("image", iconURL);
|
|
|
|
}
|
2010-03-24 02:17:40 -07:00
|
|
|
m.setAttribute("class", "menuitem-iconic bookmark-item menuitem-with-favicon");
|
2009-06-22 16:00:44 -07:00
|
|
|
m.setAttribute("value", i);
|
|
|
|
m.setAttribute("oncommand", "undoCloseTab(" + i + ");");
|
2009-12-04 01:01:00 -08:00
|
|
|
|
2010-09-15 23:09:27 -07:00
|
|
|
// Set the targetURI attribute so it will be shown in tooltip and trigger
|
|
|
|
// onLinkHovered. SessionStore uses one-based indexes, so we need to
|
|
|
|
// normalize them.
|
2009-12-04 01:01:00 -08:00
|
|
|
let tabData = undoItems[i].state;
|
|
|
|
let activeIndex = (tabData.index || tabData.entries.length) - 1;
|
|
|
|
if (activeIndex >= 0 && tabData.entries[activeIndex])
|
|
|
|
m.setAttribute("targetURI", tabData.entries[activeIndex].url);
|
|
|
|
|
2009-06-22 16:00:44 -07:00
|
|
|
m.addEventListener("click", this._undoCloseMiddleClick, false);
|
|
|
|
if (i == 0)
|
|
|
|
m.setAttribute("key", "key_undoCloseTab");
|
|
|
|
undoPopup.appendChild(m);
|
|
|
|
}
|
|
|
|
|
2009-08-12 01:40:26 -07:00
|
|
|
// "Restore All Tabs"
|
2009-06-22 16:00:44 -07:00
|
|
|
var strings = gNavigatorBundle;
|
|
|
|
undoPopup.appendChild(document.createElement("menuseparator"));
|
|
|
|
m = undoPopup.appendChild(document.createElement("menuitem"));
|
2009-08-07 01:43:30 -07:00
|
|
|
m.id = "menu_restoreAllTabs";
|
2009-08-12 01:40:26 -07:00
|
|
|
m.setAttribute("label", strings.getString("menuRestoreAllTabs.label"));
|
2009-06-22 16:00:44 -07:00
|
|
|
m.addEventListener("command", function() {
|
|
|
|
for (var i = 0; i < undoItems.length; i++)
|
|
|
|
undoCloseTab();
|
|
|
|
}, false);
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleRecentlyClosedWindows: function PHM_toggleRecentlyClosedWindows() {
|
|
|
|
// enable/disable the Recently Closed Windows sub menu
|
2010-08-20 22:14:45 -07:00
|
|
|
var undoMenu = this._rootElt.getElementsByClassName("recentlyClosedWindowsMenu")[0];
|
2009-06-22 16:00:44 -07:00
|
|
|
|
|
|
|
// no restorable windows, so disable menu
|
2009-07-29 01:49:59 -07:00
|
|
|
if (this._ss.getClosedWindowCount() == 0)
|
2010-08-20 22:14:45 -07:00
|
|
|
undoMenu.setAttribute("disabled", true);
|
2009-06-22 16:00:44 -07:00
|
|
|
else
|
2010-08-20 22:14:45 -07:00
|
|
|
undoMenu.removeAttribute("disabled");
|
2009-06-22 16:00:44 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Populate when the history menu is opened
|
|
|
|
*/
|
|
|
|
populateUndoWindowSubmenu: function PHM_populateUndoWindowSubmenu() {
|
2010-08-20 22:14:45 -07:00
|
|
|
let undoMenu = this._rootElt.getElementsByClassName("recentlyClosedWindowsMenu")[0];
|
|
|
|
let undoPopup = undoMenu.firstChild;
|
2009-06-22 16:00:44 -07:00
|
|
|
let menuLabelString = gNavigatorBundle.getString("menuUndoCloseWindowLabel");
|
|
|
|
let menuLabelStringSingleTab =
|
|
|
|
gNavigatorBundle.getString("menuUndoCloseWindowSingleTabLabel");
|
|
|
|
|
|
|
|
// remove existing menu items
|
|
|
|
while (undoPopup.hasChildNodes())
|
|
|
|
undoPopup.removeChild(undoPopup.firstChild);
|
|
|
|
|
|
|
|
// no restorable windows, so make sure menu is disabled, and return
|
2009-07-29 01:49:59 -07:00
|
|
|
if (this._ss.getClosedWindowCount() == 0) {
|
2010-08-20 22:14:45 -07:00
|
|
|
undoMenu.setAttribute("disabled", true);
|
2009-06-22 16:00:44 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// enable menu
|
2010-08-20 22:14:45 -07:00
|
|
|
undoMenu.removeAttribute("disabled");
|
2009-06-22 16:00:44 -07:00
|
|
|
|
|
|
|
// populate menu
|
2009-07-29 01:49:59 -07:00
|
|
|
let undoItems = JSON.parse(this._ss.getClosedWindowData());
|
2009-06-22 16:00:44 -07:00
|
|
|
for (let i = 0; i < undoItems.length; i++) {
|
|
|
|
let undoItem = undoItems[i];
|
|
|
|
let otherTabsCount = undoItem.tabs.length - 1;
|
|
|
|
let label = (otherTabsCount == 0) ? menuLabelStringSingleTab
|
|
|
|
: PluralForm.get(otherTabsCount, menuLabelString);
|
|
|
|
let menuLabel = label.replace("#1", undoItem.title)
|
|
|
|
.replace("#2", otherTabsCount);
|
|
|
|
let m = document.createElement("menuitem");
|
|
|
|
m.setAttribute("label", menuLabel);
|
|
|
|
let selectedTab = undoItem.tabs[undoItem.selected - 1];
|
|
|
|
if (selectedTab.attributes.image) {
|
|
|
|
let iconURL = selectedTab.attributes.image;
|
|
|
|
// don't initiate a connection just to fetch a favicon (see bug 467828)
|
|
|
|
if (/^https?:/.test(iconURL))
|
|
|
|
iconURL = "moz-anno:favicon:" + iconURL;
|
|
|
|
m.setAttribute("image", iconURL);
|
|
|
|
}
|
2010-03-24 02:17:40 -07:00
|
|
|
m.setAttribute("class", "menuitem-iconic bookmark-item menuitem-with-favicon");
|
2009-06-22 16:00:44 -07:00
|
|
|
m.setAttribute("oncommand", "undoCloseWindow(" + i + ");");
|
2009-12-04 01:01:00 -08:00
|
|
|
|
2010-09-15 23:09:27 -07:00
|
|
|
// Set the targetURI attribute so it will be shown in tooltip.
|
2009-12-04 01:01:00 -08:00
|
|
|
// SessionStore uses one-based indexes, so we need to normalize them.
|
|
|
|
let activeIndex = (selectedTab.index || selectedTab.entries.length) - 1;
|
|
|
|
if (activeIndex >= 0 && selectedTab.entries[activeIndex])
|
|
|
|
m.setAttribute("targetURI", selectedTab.entries[activeIndex].url);
|
|
|
|
|
2009-06-22 16:00:44 -07:00
|
|
|
if (i == 0)
|
|
|
|
m.setAttribute("key", "key_undoCloseWindow");
|
|
|
|
undoPopup.appendChild(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
// "Open All in Windows"
|
|
|
|
undoPopup.appendChild(document.createElement("menuseparator"));
|
|
|
|
let m = undoPopup.appendChild(document.createElement("menuitem"));
|
2009-08-07 01:43:30 -07:00
|
|
|
m.id = "menu_restoreAllWindows";
|
2009-06-22 16:00:44 -07:00
|
|
|
m.setAttribute("label", gNavigatorBundle.getString("menuRestoreAllWindows.label"));
|
|
|
|
m.setAttribute("oncommand",
|
|
|
|
"for (var i = 0; i < " + undoItems.length + "; i++) undoCloseWindow();");
|
2009-04-22 23:50:30 -07:00
|
|
|
},
|
|
|
|
|
2010-08-02 16:37:56 -07:00
|
|
|
toggleTabsFromOtherComputers: function PHM_toggleTabsFromOtherComputers() {
|
|
|
|
// This is a no-op if MOZ_SERVICES_SYNC isn't defined
|
|
|
|
#ifdef MOZ_SERVICES_SYNC
|
2011-06-18 01:59:03 -07:00
|
|
|
// Enable/disable the Tabs From Other Computers menu. Some of the menus handled
|
|
|
|
// by HistoryMenu do not have this menuitem.
|
|
|
|
let menuitem = this._rootElt.getElementsByClassName("syncTabsMenuItem")[0];
|
|
|
|
if (!menuitem)
|
|
|
|
return;
|
2010-08-02 16:37:56 -07:00
|
|
|
|
|
|
|
// If Sync isn't configured yet, then don't show the menuitem.
|
2010-09-07 18:37:46 -07:00
|
|
|
if (Weave.Status.checkSetup() == Weave.CLIENT_NOT_CONFIGURED ||
|
2010-08-02 16:37:56 -07:00
|
|
|
Weave.Svc.Prefs.get("firstSync", "") == "notReady") {
|
|
|
|
menuitem.setAttribute("hidden", true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The tabs engine might never be inited (if services.sync.registerEngines
|
|
|
|
// is modified), so make sure we avoid undefined errors.
|
|
|
|
let enabled = Weave.Service.isLoggedIn && Weave.Engines.get("tabs") &&
|
|
|
|
Weave.Engines.get("tabs").enabled;
|
|
|
|
menuitem.setAttribute("disabled", !enabled);
|
|
|
|
menuitem.setAttribute("hidden", false);
|
|
|
|
#endif
|
|
|
|
},
|
|
|
|
|
2010-09-10 10:57:28 -07:00
|
|
|
toggleRestoreLastSession: function PHM_toggleRestoreLastSession() {
|
|
|
|
let restoreItem = this._rootElt.getElementsByClassName("restoreLastSession")[0];
|
|
|
|
|
|
|
|
if (this._ss.canRestoreLastSession)
|
|
|
|
restoreItem.removeAttribute("disabled");
|
|
|
|
else
|
|
|
|
restoreItem.setAttribute("disabled", true);
|
|
|
|
},
|
|
|
|
|
2010-05-05 06:28:04 -07:00
|
|
|
_onPopupShowing: function HM__onPopupShowing(aEvent) {
|
|
|
|
PlacesMenu.prototype._onPopupShowing.apply(this, arguments);
|
|
|
|
|
2009-06-22 16:00:44 -07:00
|
|
|
// Don't handle events for submenus.
|
|
|
|
if (aEvent.target != aEvent.currentTarget)
|
|
|
|
return;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
this.toggleRecentlyClosedTabs();
|
2009-04-22 23:50:30 -07:00
|
|
|
this.toggleRecentlyClosedWindows();
|
2010-08-02 16:37:56 -07:00
|
|
|
this.toggleTabsFromOtherComputers();
|
2010-09-10 10:57:28 -07:00
|
|
|
this.toggleRestoreLastSession();
|
2009-06-15 04:09:40 -07:00
|
|
|
},
|
|
|
|
|
2010-05-05 06:28:04 -07:00
|
|
|
_onCommand: function HM__onCommand(aEvent) {
|
|
|
|
let placesNode = aEvent.target._placesNode;
|
|
|
|
if (placesNode) {
|
|
|
|
PlacesUIUtils.markPageAsTyped(placesNode.uri);
|
|
|
|
openUILink(placesNode.uri, aEvent, false, true);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Functions for handling events in the Bookmarks Toolbar and menu.
|
|
|
|
*/
|
2010-06-24 10:08:43 -07:00
|
|
|
var BookmarksEventHandler = {
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Handler for click event for an item in the bookmarks toolbar or menu.
|
|
|
|
* Menus and submenus from the folder buttons bubble up to this handler.
|
2008-03-14 13:17:14 -07:00
|
|
|
* Left-click is handled in the onCommand function.
|
|
|
|
* When items are middle-clicked (or clicked with modifier), open in tabs.
|
2007-03-22 10:30:00 -07:00
|
|
|
* If the click came through a menu, close the menu.
|
|
|
|
* @param aEvent
|
|
|
|
* DOMEvent for the click
|
2011-01-28 08:46:51 -08:00
|
|
|
* @param aView
|
|
|
|
* The places view which aEvent should be associated with.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2011-01-28 08:46:51 -08:00
|
|
|
onClick: function BEH_onClick(aEvent, aView) {
|
2008-03-14 13:17:14 -07:00
|
|
|
// Only handle middle-click or left-click with modifiers.
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
var modifKey = aEvent.metaKey || aEvent.shiftKey;
|
|
|
|
#else
|
|
|
|
var modifKey = aEvent.ctrlKey || aEvent.shiftKey;
|
|
|
|
#endif
|
|
|
|
if (aEvent.button == 2 || (aEvent.button == 0 && !modifKey))
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
var target = aEvent.originalTarget;
|
2008-03-14 13:17:14 -07:00
|
|
|
// If this event bubbled up from a menu or menuitem, close the menus.
|
2008-03-17 04:38:17 -07:00
|
|
|
// Do this before opening tabs, to avoid hiding the open tabs confirm-dialog.
|
2008-03-14 13:17:14 -07:00
|
|
|
if (target.localName == "menu" || target.localName == "menuitem") {
|
|
|
|
for (node = target.parentNode; node; node = node.parentNode) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (node.localName == "menupopup")
|
|
|
|
node.hidePopup();
|
2011-01-19 19:21:50 -08:00
|
|
|
else if (node.localName != "menu" &&
|
|
|
|
node.localName != "splitmenu" &&
|
|
|
|
node.localName != "hbox" &&
|
|
|
|
node.localName != "vbox" )
|
2008-03-14 13:17:14 -07:00
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2008-03-17 04:33:16 -07:00
|
|
|
|
2010-05-05 06:28:04 -07:00
|
|
|
if (target._placesNode && PlacesUtils.nodeIsContainer(target._placesNode)) {
|
2008-03-17 04:33:16 -07:00
|
|
|
// Don't open the root folder in tabs when the empty area on the toolbar
|
|
|
|
// is middle-clicked or when a non-bookmark item except for Open in Tabs)
|
|
|
|
// in a bookmarks menupopup is middle-clicked.
|
|
|
|
if (target.localName == "menu" || target.localName == "toolbarbutton")
|
2011-01-28 08:46:51 -08:00
|
|
|
PlacesUIUtils.openContainerNodeInTabs(target._placesNode, aEvent, aView);
|
2008-03-17 04:33:16 -07:00
|
|
|
}
|
|
|
|
else if (aEvent.button == 1) {
|
|
|
|
// left-clicks with modifier are already served by onCommand
|
2011-01-28 08:46:51 -08:00
|
|
|
this.onCommand(aEvent, aView);
|
2008-03-17 04:33:16 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-10-24 19:02:28 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Handler for command event for an item in the bookmarks toolbar.
|
|
|
|
* Menus and submenus from the folder buttons bubble up to this handler.
|
|
|
|
* Opens the item.
|
|
|
|
* @param aEvent
|
|
|
|
* DOMEvent for the command
|
2011-01-28 08:46:51 -08:00
|
|
|
* @param aView
|
|
|
|
* The places view which aEvent should be associated with.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2011-01-28 08:46:51 -08:00
|
|
|
onCommand: function BEH_onCommand(aEvent, aView) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var target = aEvent.originalTarget;
|
2010-05-05 06:28:04 -07:00
|
|
|
if (target._placesNode)
|
2011-01-28 08:46:51 -08:00
|
|
|
PlacesUIUtils.openNodeWithEvent(target._placesNode, aEvent, aView);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2010-06-24 10:08:43 -07:00
|
|
|
fillInBHTooltip: function BEH_fillInBHTooltip(aDocument, aEvent) {
|
2009-09-04 16:36:07 -07:00
|
|
|
var node;
|
|
|
|
var cropped = false;
|
2009-11-14 04:44:17 -08:00
|
|
|
var targetURI;
|
2009-09-04 16:36:07 -07:00
|
|
|
|
|
|
|
if (aDocument.tooltipNode.localName == "treechildren") {
|
|
|
|
var tree = aDocument.tooltipNode.parentNode;
|
|
|
|
var row = {}, column = {};
|
|
|
|
var tbo = tree.treeBoxObject;
|
|
|
|
tbo.getCellAt(aEvent.clientX, aEvent.clientY, row, column, {});
|
2009-09-15 05:43:12 -07:00
|
|
|
if (row.value == -1)
|
|
|
|
return false;
|
2009-09-04 16:36:07 -07:00
|
|
|
node = tree.view.nodeForTreeIndex(row.value);
|
|
|
|
cropped = tbo.isCellCropped(row.value, column.value);
|
|
|
|
}
|
2009-11-14 04:44:17 -08:00
|
|
|
else {
|
|
|
|
// Check whether the tooltipNode is a Places node.
|
|
|
|
// In such a case use it, otherwise check for targetURI attribute.
|
|
|
|
var tooltipNode = aDocument.tooltipNode;
|
2010-05-05 06:28:04 -07:00
|
|
|
if (tooltipNode._placesNode)
|
|
|
|
node = tooltipNode._placesNode;
|
2009-11-14 04:44:17 -08:00
|
|
|
else {
|
|
|
|
// This is a static non-Places node.
|
|
|
|
targetURI = tooltipNode.getAttribute("targetURI");
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-11-14 04:44:17 -08:00
|
|
|
if (!node && !targetURI)
|
2007-06-12 08:34:02 -07:00
|
|
|
return false;
|
|
|
|
|
2009-11-14 04:44:17 -08:00
|
|
|
// Show node.label as tooltip's title for non-Places nodes.
|
|
|
|
var title = node ? node.title : tooltipNode.label;
|
2009-09-04 16:36:07 -07:00
|
|
|
|
2009-11-14 04:44:17 -08:00
|
|
|
// Show URL only for Places URI-nodes or nodes with a targetURI attribute.
|
|
|
|
var url;
|
|
|
|
if (targetURI || PlacesUtils.nodeIsURI(node))
|
|
|
|
url = targetURI || node.uri;
|
2009-09-04 16:36:07 -07:00
|
|
|
|
|
|
|
// Show tooltip for containers only if their title is cropped.
|
|
|
|
if (!cropped && !url)
|
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-04 16:36:07 -07:00
|
|
|
var tooltipTitle = aDocument.getElementById("bhtTitleText");
|
|
|
|
tooltipTitle.hidden = (!title || (title == url));
|
2008-10-13 03:19:55 -07:00
|
|
|
if (!tooltipTitle.hidden)
|
2008-09-30 16:36:20 -07:00
|
|
|
tooltipTitle.textContent = title;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-04 16:36:07 -07:00
|
|
|
var tooltipUrl = aDocument.getElementById("bhtUrlText");
|
|
|
|
tooltipUrl.hidden = !url;
|
|
|
|
if (!tooltipUrl.hidden)
|
|
|
|
tooltipUrl.value = url;
|
2008-10-13 03:19:55 -07:00
|
|
|
|
2009-09-04 16:36:07 -07:00
|
|
|
// Show tooltip.
|
2007-03-22 10:30:00 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-09-19 08:47:45 -07:00
|
|
|
|
2010-06-24 10:08:43 -07:00
|
|
|
// Handles special drag and drop functionality for Places menus that are not
|
|
|
|
// part of a Places view (e.g. the bookmarks menu in the menubar).
|
|
|
|
var PlacesMenuDNDHandler = {
|
2007-03-22 10:30:00 -07:00
|
|
|
_springLoadDelay: 350, // milliseconds
|
2010-06-24 10:08:43 -07:00
|
|
|
_loadTimer: null,
|
2011-07-05 18:40:00 -07:00
|
|
|
_closerTimer: null,
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
2010-06-24 10:08:43 -07:00
|
|
|
* Called when the user enters the <menu> element during a drag.
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param event
|
|
|
|
* The DragEnter event that spawned the opening.
|
|
|
|
*/
|
2010-06-24 10:08:43 -07:00
|
|
|
onDragEnter: function PMDH_onDragEnter(event) {
|
|
|
|
// Opening menus in a Places popup is handled by the view itself.
|
|
|
|
if (!this._isStaticContainer(event.target))
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
2010-06-24 10:08:43 -07:00
|
|
|
|
2011-10-26 17:46:58 -07:00
|
|
|
this._loadTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
|
|
|
this._loadTimer.initWithCallback(function() {
|
|
|
|
PlacesMenuDNDHandler._loadTimer = null;
|
|
|
|
event.target.lastChild.setAttribute("autoopened", "true");
|
|
|
|
event.target.lastChild.showPopup(event.target.lastChild);
|
|
|
|
}, this._springLoadDelay, Ci.nsITimer.TYPE_ONE_SHOT);
|
|
|
|
event.preventDefault();
|
2010-06-24 10:08:43 -07:00
|
|
|
event.stopPropagation();
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2010-06-24 10:08:43 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2010-12-03 08:19:55 -08:00
|
|
|
* Handles dragexit on the <menu> element.
|
2010-06-24 10:08:43 -07:00
|
|
|
* @returns true if the element is a container element (menu or
|
|
|
|
* menu-toolbarbutton), false otherwise.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2010-12-03 08:19:55 -08:00
|
|
|
onDragExit: function PMDH_onDragExit(event) {
|
2010-06-24 10:08:43 -07:00
|
|
|
// Closing menus in a Places popup is handled by the view itself.
|
|
|
|
if (!this._isStaticContainer(event.target))
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
|
2010-06-24 10:08:43 -07:00
|
|
|
if (this._loadTimer) {
|
|
|
|
this._loadTimer.cancel();
|
|
|
|
this._loadTimer = null;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-07-05 18:40:00 -07:00
|
|
|
this._closeTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
|
|
|
this._closeTimer.initWithCallback(function() {
|
|
|
|
this._closeTimer = null;
|
2010-06-24 10:08:43 -07:00
|
|
|
let node = PlacesControllerDragHelper.currentDropTarget;
|
|
|
|
let inHierarchy = false;
|
|
|
|
while (node && !inHierarchy) {
|
|
|
|
inHierarchy = node == event.target;
|
|
|
|
node = node.parentNode;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-24 10:08:43 -07:00
|
|
|
if (!inHierarchy && event.target.lastChild &&
|
|
|
|
event.target.lastChild.hasAttribute("autoopened")) {
|
|
|
|
event.target.lastChild.removeAttribute("autoopened");
|
|
|
|
event.target.lastChild.hidePopup();
|
|
|
|
}
|
|
|
|
}, this._springLoadDelay, Ci.nsITimer.TYPE_ONE_SHOT);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2010-06-24 10:08:43 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2010-06-24 10:08:43 -07:00
|
|
|
* Determines if a XUL element represents a static container.
|
2007-03-22 10:30:00 -07:00
|
|
|
* @returns true if the element is a container element (menu or
|
|
|
|
*` menu-toolbarbutton), false otherwise.
|
|
|
|
*/
|
2010-06-24 10:08:43 -07:00
|
|
|
_isStaticContainer: function PMDH__isContainer(node) {
|
|
|
|
let isMenu = node.localName == "menu" ||
|
|
|
|
(node.localName == "toolbarbutton" &&
|
|
|
|
node.getAttribute("type") == "menu");
|
|
|
|
let isStatic = !("_placesNode" in node) && node.lastChild &&
|
|
|
|
node.lastChild.hasAttribute("placespopup") &&
|
|
|
|
!node.parentNode.hasAttribute("placespopup");
|
|
|
|
return isMenu && isStatic;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2010-06-24 10:08:43 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2010-06-24 10:08:43 -07:00
|
|
|
* Called when the user drags over the <menu> element.
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param event
|
2010-06-24 10:08:43 -07:00
|
|
|
* The DragOver event.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2010-06-24 10:08:43 -07:00
|
|
|
onDragOver: function PMDH_onDragOver(event) {
|
|
|
|
let ip = new InsertionPoint(PlacesUtils.bookmarksMenuFolderId,
|
|
|
|
PlacesUtils.bookmarks.DEFAULT_INDEX,
|
|
|
|
Ci.nsITreeView.DROP_ON);
|
|
|
|
if (ip && PlacesControllerDragHelper.canDrop(ip, event.dataTransfer))
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
event.stopPropagation();
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2010-06-24 10:08:43 -07:00
|
|
|
/**
|
|
|
|
* Called when the user drops on the <menu> element.
|
|
|
|
* @param event
|
|
|
|
* The Drop event.
|
|
|
|
*/
|
|
|
|
onDrop: function PMDH_onDrop(event) {
|
|
|
|
// Put the item at the end of bookmark menu.
|
|
|
|
let ip = new InsertionPoint(PlacesUtils.bookmarksMenuFolderId,
|
|
|
|
PlacesUtils.bookmarks.DEFAULT_INDEX,
|
|
|
|
Ci.nsITreeView.DROP_ON);
|
|
|
|
PlacesControllerDragHelper.onDrop(ip, event.dataTransfer);
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
2007-08-15 18:15:50 -07:00
|
|
|
|
2010-06-24 10:08:43 -07:00
|
|
|
|
2007-08-15 18:15:50 -07:00
|
|
|
var PlacesStarButton = {
|
2010-11-29 09:33:26 -08:00
|
|
|
_hasBookmarksObserver: false,
|
2010-11-22 11:34:57 -08:00
|
|
|
uninit: function PSB_uninit()
|
|
|
|
{
|
2010-11-29 09:33:26 -08:00
|
|
|
if (this._hasBookmarksObserver) {
|
2011-10-27 02:11:45 -07:00
|
|
|
PlacesUtils.removeLazyBookmarkObserver(this);
|
2010-11-29 09:33:26 -08:00
|
|
|
}
|
2011-02-15 03:39:21 -08:00
|
|
|
if (this._pendingStmt) {
|
|
|
|
this._pendingStmt.cancel();
|
|
|
|
delete this._pendingStmt;
|
|
|
|
}
|
2007-08-15 18:15:50 -07:00
|
|
|
},
|
|
|
|
|
2010-11-22 11:34:57 -08:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([
|
|
|
|
Ci.nsINavBookmarkObserver
|
|
|
|
]),
|
2007-08-15 18:15:50 -07:00
|
|
|
|
2010-11-22 11:34:57 -08:00
|
|
|
get _starredTooltip()
|
|
|
|
{
|
|
|
|
delete this._starredTooltip;
|
|
|
|
return this._starredTooltip =
|
|
|
|
gNavigatorBundle.getString("starButtonOn.tooltip");
|
|
|
|
},
|
|
|
|
get _unstarredTooltip()
|
|
|
|
{
|
|
|
|
delete this._unstarredTooltip;
|
|
|
|
return this._unstarredTooltip =
|
|
|
|
gNavigatorBundle.getString("starButtonOff.tooltip");
|
|
|
|
},
|
2007-08-15 18:15:50 -07:00
|
|
|
|
2010-11-22 11:34:57 -08:00
|
|
|
updateState: function PSB_updateState()
|
|
|
|
{
|
|
|
|
this._starIcon = document.getElementById("star-button");
|
2010-11-30 02:14:24 -08:00
|
|
|
if (!this._starIcon || (this._uri && gBrowser.currentURI.equals(this._uri))) {
|
2007-08-17 00:22:12 -07:00
|
|
|
return;
|
2007-09-21 11:18:34 -07:00
|
|
|
}
|
2007-08-15 18:15:50 -07:00
|
|
|
|
2010-11-22 11:34:57 -08:00
|
|
|
// Reset tracked values.
|
|
|
|
this._uri = gBrowser.currentURI;
|
|
|
|
this._itemIds = [];
|
2007-12-01 13:04:09 -08:00
|
|
|
|
2011-02-15 03:39:21 -08:00
|
|
|
if (this._pendingStmt) {
|
|
|
|
this._pendingStmt.cancel();
|
|
|
|
delete this._pendingStmt;
|
|
|
|
}
|
2010-11-22 11:34:57 -08:00
|
|
|
|
2010-12-14 09:58:58 -08:00
|
|
|
// We can load about:blank before the actual page, but there is no point in handling that page.
|
2012-01-25 14:43:27 -08:00
|
|
|
if (isBlankPageURL(this._uri.spec)) {
|
2010-12-14 09:58:58 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-15 03:39:21 -08:00
|
|
|
this._pendingStmt = PlacesUtils.asyncGetBookmarkIds(this._uri, function (aItemIds, aURI) {
|
|
|
|
// Safety check that the bookmarked URI equals the tracked one.
|
|
|
|
if (!aURI.equals(this._uri)) {
|
|
|
|
Components.utils.reportError("PlacesStarButton did not receive current URI");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-18 05:54:14 -08:00
|
|
|
// It's possible that onItemAdded gets called before the async statement
|
|
|
|
// calls back. For such an edge case, retain all unique entries from both
|
|
|
|
// arrays.
|
|
|
|
this._itemIds = this._itemIds.filter(
|
|
|
|
function (id) aItemIds.indexOf(id) == -1
|
|
|
|
).concat(aItemIds);
|
2010-11-22 11:34:57 -08:00
|
|
|
this._updateStateInternal();
|
2010-11-29 09:33:26 -08:00
|
|
|
|
|
|
|
// Start observing bookmarks if needed.
|
|
|
|
if (!this._hasBookmarksObserver) {
|
|
|
|
try {
|
2011-10-27 02:11:45 -07:00
|
|
|
PlacesUtils.addLazyBookmarkObserver(this);
|
2010-11-29 09:33:26 -08:00
|
|
|
this._hasBookmarksObserver = true;
|
|
|
|
} catch(ex) {
|
|
|
|
Components.utils.reportError("PlacesStarButton failed adding a bookmarks observer: " + ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-15 03:39:21 -08:00
|
|
|
delete this._pendingStmt;
|
2010-11-22 11:34:57 -08:00
|
|
|
}, this);
|
2007-08-15 18:15:50 -07:00
|
|
|
},
|
|
|
|
|
2010-11-22 11:34:57 -08:00
|
|
|
_updateStateInternal: function PSB__updateStateInternal()
|
|
|
|
{
|
|
|
|
if (!this._starIcon) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-12 19:28:20 -08:00
|
|
|
if (this._itemIds.length > 0) {
|
2010-11-22 11:34:57 -08:00
|
|
|
this._starIcon.setAttribute("starred", "true");
|
|
|
|
this._starIcon.setAttribute("tooltiptext", this._starredTooltip);
|
|
|
|
}
|
2011-01-12 19:28:20 -08:00
|
|
|
else {
|
2010-11-22 11:34:57 -08:00
|
|
|
this._starIcon.removeAttribute("starred");
|
|
|
|
this._starIcon.setAttribute("tooltiptext", this._unstarredTooltip);
|
|
|
|
}
|
2007-08-15 18:15:50 -07:00
|
|
|
},
|
|
|
|
|
2010-11-22 11:34:57 -08:00
|
|
|
onClick: function PSB_onClick(aEvent)
|
|
|
|
{
|
2011-02-15 03:39:21 -08:00
|
|
|
// Ignore clicks on the star while we update its state.
|
|
|
|
if (aEvent.button == 0 && !this._pendingStmt) {
|
2010-11-22 11:34:57 -08:00
|
|
|
PlacesCommandHook.bookmarkCurrentPage(this._itemIds.length > 0);
|
|
|
|
}
|
|
|
|
// Don't bubble to the textbox, to avoid unwanted selection of the address.
|
|
|
|
aEvent.stopPropagation();
|
2007-08-15 18:15:50 -07:00
|
|
|
},
|
2010-10-26 15:20:53 -07:00
|
|
|
|
2010-11-22 11:34:57 -08:00
|
|
|
// nsINavBookmarkObserver
|
|
|
|
onItemAdded:
|
|
|
|
function PSB_onItemAdded(aItemId, aFolder, aIndex, aItemType, aURI)
|
|
|
|
{
|
|
|
|
if (!this._starIcon) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-25 18:07:25 -08:00
|
|
|
if (aURI && aURI.equals(this._uri)) {
|
2010-11-22 11:34:57 -08:00
|
|
|
// If a new bookmark has been added to the tracked uri, register it.
|
|
|
|
if (this._itemIds.indexOf(aItemId) == -1) {
|
|
|
|
this._itemIds.push(aItemId);
|
|
|
|
this._updateStateInternal();
|
|
|
|
}
|
|
|
|
}
|
2007-08-15 18:15:50 -07:00
|
|
|
},
|
|
|
|
|
2010-11-22 11:34:57 -08:00
|
|
|
onItemRemoved:
|
|
|
|
function PSB_onItemRemoved(aItemId, aFolder, aIndex, aItemType)
|
|
|
|
{
|
|
|
|
if (!this._starIcon) {
|
|
|
|
return;
|
|
|
|
}
|
2009-03-19 12:56:51 -07:00
|
|
|
|
2010-11-22 11:34:57 -08:00
|
|
|
let index = this._itemIds.indexOf(aItemId);
|
|
|
|
// If one of the tracked bookmarks has been removed, unregister it.
|
|
|
|
if (index != -1) {
|
|
|
|
this._itemIds.splice(index, 1);
|
|
|
|
this._updateStateInternal();
|
|
|
|
}
|
2007-08-15 18:15:50 -07:00
|
|
|
},
|
|
|
|
|
2010-11-22 11:34:57 -08:00
|
|
|
onItemChanged:
|
|
|
|
function PSB_onItemChanged(aItemId, aProperty, aIsAnnotationProperty,
|
|
|
|
aNewValue, aLastModified, aItemType)
|
|
|
|
{
|
|
|
|
if (!this._starIcon) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aProperty == "uri") {
|
|
|
|
let index = this._itemIds.indexOf(aItemId);
|
|
|
|
// If the changed bookmark was tracked, check if it is now pointing to
|
|
|
|
// a different uri and unregister it.
|
|
|
|
if (index != -1 && aNewValue != this._uri.spec) {
|
|
|
|
this._itemIds.splice(index, 1);
|
|
|
|
this._updateStateInternal();
|
|
|
|
}
|
|
|
|
// If another bookmark is now pointing to the tracked uri, register it.
|
|
|
|
else if (index == -1 && aNewValue == this._uri.spec) {
|
|
|
|
this._itemIds.push(aItemId);
|
|
|
|
this._updateStateInternal();
|
|
|
|
}
|
|
|
|
}
|
2007-08-15 18:15:50 -07:00
|
|
|
},
|
|
|
|
|
2010-11-22 11:34:57 -08:00
|
|
|
onBeginUpdateBatch: function () {},
|
|
|
|
onEndUpdateBatch: function () {},
|
|
|
|
onBeforeItemRemoved: function () {},
|
|
|
|
onItemVisited: function () {},
|
|
|
|
onItemMoved: function () {}
|
2007-08-15 18:15:50 -07:00
|
|
|
};
|
2010-05-05 06:28:04 -07:00
|
|
|
|
2010-06-24 10:08:43 -07:00
|
|
|
|
2010-06-24 16:47:10 -07:00
|
|
|
// This object handles the initialization and uninitialization of the bookmarks
|
2010-05-05 06:28:04 -07:00
|
|
|
// toolbar. updateState is called when the browser window is opened and
|
|
|
|
// after closing the toolbar customization dialog.
|
|
|
|
let PlacesToolbarHelper = {
|
|
|
|
_place: "place:folder=TOOLBAR",
|
|
|
|
|
2010-07-15 13:38:05 -07:00
|
|
|
get _viewElt() {
|
|
|
|
return document.getElementById("PlacesToolbar");
|
2010-05-05 06:28:04 -07:00
|
|
|
},
|
|
|
|
|
2010-07-15 13:38:05 -07:00
|
|
|
init: function PTH_init() {
|
2010-07-16 12:03:04 -07:00
|
|
|
let viewElt = this._viewElt;
|
|
|
|
if (!viewElt || viewElt._placesView)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If the bookmarks toolbar item is hidden because the parent toolbar is
|
|
|
|
// collapsed or hidden (i.e. in a popup), spare the initialization.
|
|
|
|
let toolbar = viewElt.parentNode.parentNode;
|
|
|
|
if (toolbar.collapsed ||
|
|
|
|
getComputedStyle(toolbar, "").display == "none")
|
|
|
|
return;
|
|
|
|
|
|
|
|
new PlacesToolbar(this._place);
|
2010-07-15 13:38:05 -07:00
|
|
|
},
|
2010-05-05 06:28:04 -07:00
|
|
|
|
2010-07-15 13:38:05 -07:00
|
|
|
customizeStart: function PTH_customizeStart() {
|
|
|
|
let viewElt = this._viewElt;
|
|
|
|
if (viewElt && viewElt._placesView)
|
|
|
|
viewElt._placesView.uninit();
|
|
|
|
},
|
2010-05-05 06:28:04 -07:00
|
|
|
|
2010-07-15 13:38:05 -07:00
|
|
|
customizeDone: function PTH_customizeDone() {
|
|
|
|
this.init();
|
2010-05-05 06:28:04 -07:00
|
|
|
}
|
|
|
|
};
|
2010-06-24 10:08:43 -07:00
|
|
|
|
|
|
|
|
|
|
|
// Handles the bookmarks menu button shown when the main menubar is hidden.
|
|
|
|
let BookmarksMenuButton = {
|
|
|
|
get button() {
|
2010-07-09 12:44:01 -07:00
|
|
|
return document.getElementById("bookmarks-menu-button");
|
2010-06-24 10:08:43 -07:00
|
|
|
},
|
|
|
|
|
2010-07-09 12:44:01 -07:00
|
|
|
get buttonContainer() {
|
|
|
|
return document.getElementById("bookmarks-menu-button-container");
|
2010-06-24 10:08:43 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
get personalToolbar() {
|
|
|
|
delete this.personalToolbar;
|
|
|
|
return this.personalToolbar = document.getElementById("PersonalToolbar");
|
|
|
|
},
|
|
|
|
|
|
|
|
get bookmarksToolbarItem() {
|
|
|
|
return document.getElementById("personal-bookmarks");
|
|
|
|
},
|
|
|
|
|
|
|
|
init: function BMB_init() {
|
|
|
|
this.updatePosition();
|
|
|
|
|
|
|
|
// Any other stuff that does not regard the button itself should be
|
|
|
|
// handled in the onPopupShowing handler, so it does not hit Ts.
|
|
|
|
},
|
|
|
|
|
2010-10-06 05:16:05 -07:00
|
|
|
_popupNeedsUpdate: {},
|
2010-06-24 10:08:43 -07:00
|
|
|
onPopupShowing: function BMB_onPopupShowing(event) {
|
2010-10-06 05:16:05 -07:00
|
|
|
// Don't handle events for submenus.
|
|
|
|
if (event.target != event.currentTarget)
|
2010-06-24 10:08:43 -07:00
|
|
|
return;
|
|
|
|
|
2010-10-06 05:16:05 -07:00
|
|
|
let popup = event.target;
|
|
|
|
let needsUpdate = this._popupNeedsUpdate[popup.id];
|
2010-06-24 10:08:43 -07:00
|
|
|
|
2010-10-06 05:16:05 -07:00
|
|
|
// Check if popup contents need to be updated. Note that if needsUpdate is
|
|
|
|
// undefined we have never seen the popup, thus it should be updated.
|
|
|
|
if (needsUpdate === false)
|
|
|
|
return;
|
|
|
|
this._popupNeedsUpdate[popup.id] = false;
|
2010-06-24 10:08:43 -07:00
|
|
|
|
2010-10-06 05:16:05 -07:00
|
|
|
function getPlacesAnonymousElement(aAnonId)
|
|
|
|
document.getAnonymousElementByAttribute(popup.parentNode,
|
|
|
|
"placesanonid",
|
|
|
|
aAnonId);
|
2010-06-24 10:08:43 -07:00
|
|
|
|
2010-10-06 05:16:05 -07:00
|
|
|
let viewToolbarMenuitem = getPlacesAnonymousElement("view-toolbar");
|
|
|
|
if (viewToolbarMenuitem) {
|
|
|
|
// Update View bookmarks toolbar checkbox menuitem.
|
|
|
|
viewToolbarMenuitem.setAttribute("checked",
|
|
|
|
!this.personalToolbar.collapsed);
|
|
|
|
}
|
|
|
|
|
|
|
|
let toolbarMenuitem = getPlacesAnonymousElement("toolbar-autohide");
|
|
|
|
if (toolbarMenuitem) {
|
|
|
|
// If bookmarks items are visible, hide Bookmarks Toolbar menu and the
|
|
|
|
// separator after it.
|
|
|
|
toolbarMenuitem.collapsed = toolbarMenuitem.nextSibling.collapsed =
|
|
|
|
isElementVisible(this.bookmarksToolbarItem);
|
|
|
|
}
|
2010-06-24 10:08:43 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
updatePosition: function BMB_updatePosition() {
|
2010-10-06 05:16:05 -07:00
|
|
|
// Popups will have to be updated when the user customizes the UI, or
|
|
|
|
// changes personal toolbar collapsed status. Both of those location call
|
|
|
|
// updatePosition(), so this is the only point asking for popup updates.
|
|
|
|
for (let popupId in this._popupNeedsUpdate) {
|
|
|
|
this._popupNeedsUpdate[popupId] = true;
|
|
|
|
}
|
2010-06-24 10:08:43 -07:00
|
|
|
|
2010-07-09 12:44:01 -07:00
|
|
|
let button = this.button;
|
|
|
|
if (!button)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If the toolbar containing bookmarks is visible, we want to move the
|
|
|
|
// button to bookmarksToolbarItem.
|
2010-06-24 10:08:43 -07:00
|
|
|
let bookmarksToolbarItem = this.bookmarksToolbarItem;
|
2010-07-09 12:44:01 -07:00
|
|
|
let bookmarksOnVisibleToolbar = bookmarksToolbarItem &&
|
|
|
|
!bookmarksToolbarItem.parentNode.collapsed &&
|
|
|
|
bookmarksToolbarItem.parentNode.getAttribute("autohide") != "true";
|
|
|
|
|
|
|
|
// If the container has been moved by the user to the toolbar containing
|
|
|
|
// bookmarks, we want to preserve the desired position.
|
|
|
|
let container = this.buttonContainer;
|
|
|
|
let containerNearBookmarks = container && bookmarksToolbarItem &&
|
|
|
|
container.parentNode == bookmarksToolbarItem.parentNode;
|
|
|
|
|
|
|
|
if (bookmarksOnVisibleToolbar && !containerNearBookmarks) {
|
|
|
|
if (button.parentNode != bookmarksToolbarItem) {
|
|
|
|
this._uninitView();
|
|
|
|
bookmarksToolbarItem.appendChild(button);
|
2010-06-24 16:47:10 -07:00
|
|
|
}
|
2010-06-24 10:08:43 -07:00
|
|
|
}
|
|
|
|
else {
|
2010-07-09 12:44:01 -07:00
|
|
|
if (container && button.parentNode != container) {
|
|
|
|
this._uninitView();
|
|
|
|
container.appendChild(button);
|
2010-06-24 16:47:10 -07:00
|
|
|
}
|
2010-06-24 10:08:43 -07:00
|
|
|
}
|
2010-07-09 12:44:01 -07:00
|
|
|
this._updateStyle();
|
2010-06-24 10:08:43 -07:00
|
|
|
},
|
|
|
|
|
2010-07-09 12:44:01 -07:00
|
|
|
_updateStyle: function BMB__updateStyle() {
|
|
|
|
let button = this.button;
|
|
|
|
if (!button)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let container = this.buttonContainer;
|
|
|
|
let containerOnPersonalToolbar = container &&
|
|
|
|
(container.parentNode == this.personalToolbar ||
|
|
|
|
container.parentNode.parentNode == this.personalToolbar);
|
|
|
|
|
|
|
|
if (button.parentNode == this.bookmarksToolbarItem ||
|
|
|
|
containerOnPersonalToolbar) {
|
|
|
|
button.classList.add("bookmark-item");
|
|
|
|
button.classList.remove("toolbarbutton-1");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
button.classList.remove("bookmark-item");
|
|
|
|
button.classList.add("toolbarbutton-1");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_uninitView: function BMB__uninitView() {
|
2010-06-24 16:47:10 -07:00
|
|
|
// When an element with a placesView attached is removed and re-inserted,
|
|
|
|
// XBL reapplies the binding causing any kind of issues and possible leaks,
|
|
|
|
// so kill current view and let popupshowing generate a new one.
|
2010-07-09 12:44:01 -07:00
|
|
|
let button = this.button;
|
|
|
|
if (button && button._placesView)
|
|
|
|
button._placesView.uninit();
|
2010-06-24 16:47:10 -07:00
|
|
|
},
|
|
|
|
|
2010-06-24 10:08:43 -07:00
|
|
|
customizeStart: function BMB_customizeStart() {
|
2010-07-09 12:44:01 -07:00
|
|
|
this._uninitView();
|
|
|
|
let button = this.button;
|
|
|
|
let container = this.buttonContainer;
|
|
|
|
if (button && container && button.parentNode != container) {
|
|
|
|
// Move button back to the container, so user can move or remove it.
|
|
|
|
container.appendChild(button);
|
|
|
|
this._updateStyle();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
customizeChange: function BMB_customizeChange() {
|
|
|
|
this._updateStyle();
|
2010-06-24 10:08:43 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
customizeDone: function BMB_customizeDone() {
|
|
|
|
this.updatePosition();
|
|
|
|
}
|
|
|
|
};
|