2007-12-14 20:22:12 +00: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 20:12:40 +00:00
|
|
|
# Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
2007-12-14 20:22:12 +00: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 *****
|
2006-04-10 19:26:01 +00:00
|
|
|
|
2008-01-30 04:37:41 +00:00
|
|
|
|
|
|
|
var StarUI = {
|
|
|
|
_itemId: -1,
|
|
|
|
uri: null,
|
|
|
|
_batching: false,
|
|
|
|
|
|
|
|
_element: function(aID) {
|
|
|
|
return document.getElementById(aID);
|
|
|
|
},
|
|
|
|
|
2007-08-17 07:22:12 +00:00
|
|
|
// Edit-bookmark panel
|
|
|
|
get panel() {
|
2007-10-31 01:16:46 +00:00
|
|
|
delete this.panel;
|
2008-01-30 04:37:41 +00:00
|
|
|
var element = this._element("editBookmarkPanel");
|
2007-11-11 18:36:52 +00:00
|
|
|
// initially the panel is hidden
|
|
|
|
// to avoid impacting startup / new window performance
|
|
|
|
element.hidden = false;
|
2007-11-17 04:29:07 +00:00
|
|
|
element.addEventListener("popuphidden", this, false);
|
2009-05-15 13:33:59 +00:00
|
|
|
element.addEventListener("keypress", this, false);
|
2007-10-31 01:16:46 +00:00
|
|
|
return this.panel = element;
|
2007-08-17 07:22:12 +00:00
|
|
|
},
|
|
|
|
|
2007-08-30 16:13:33 +00:00
|
|
|
// list of command elements (by id) to disable when the panel is opened
|
|
|
|
_blockedCommands: ["cmd_close", "cmd_closeWindow"],
|
2008-01-30 04:37:41 +00:00
|
|
|
_blockCommands: function SU__blockCommands() {
|
2007-08-30 16:13:33 +00:00
|
|
|
for each(var key in this._blockedCommands) {
|
2008-01-30 04:37:41 +00:00
|
|
|
var elt = this._element(key);
|
2007-12-24 03:03:41 +00:00
|
|
|
// make sure not to permanently disable this item (see bug 409155)
|
|
|
|
if (elt.hasAttribute("wasDisabled"))
|
|
|
|
continue;
|
2007-08-30 16:13:33 +00:00
|
|
|
if (elt.getAttribute("disabled") == "true")
|
|
|
|
elt.setAttribute("wasDisabled", "true");
|
|
|
|
else {
|
|
|
|
elt.setAttribute("wasDisabled", "false");
|
|
|
|
elt.setAttribute("disabled", "true");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-01-30 04:37:41 +00:00
|
|
|
_restoreCommandsState: function SU__restoreCommandsState() {
|
2007-08-30 16:13:33 +00:00
|
|
|
for each(var key in this._blockedCommands) {
|
2008-01-30 04:37:41 +00:00
|
|
|
var elt = this._element(key);
|
2007-08-30 16:13:33 +00:00
|
|
|
if (elt.getAttribute("wasDisabled") != "true")
|
|
|
|
elt.removeAttribute("disabled");
|
|
|
|
elt.removeAttribute("wasDisabled");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2007-08-17 07:22:12 +00:00
|
|
|
// nsIDOMEventListener
|
2008-01-30 04:37:41 +00:00
|
|
|
handleEvent: function SU_handleEvent(aEvent) {
|
2007-08-30 16:13:33 +00:00
|
|
|
switch (aEvent.type) {
|
2007-11-17 04:29:07 +00:00
|
|
|
case "popuphidden":
|
2007-08-30 16:13:33 +00:00
|
|
|
if (aEvent.originalTarget == this.panel) {
|
2008-01-30 04:37:41 +00:00
|
|
|
if (!this._element("editBookmarkPanelContent").hidden)
|
2008-03-14 00:52:21 +00:00
|
|
|
this.quitEditMode();
|
2007-08-30 16:13:33 +00:00
|
|
|
this._restoreCommandsState();
|
2008-01-30 04:37:41 +00:00
|
|
|
this._itemId = -1;
|
|
|
|
this._uri = null;
|
|
|
|
if (this._batching) {
|
2008-03-13 19:25:49 +00:00
|
|
|
PlacesUIUtils.ptm.endBatch();
|
2008-01-30 04:37:41 +00:00
|
|
|
this._batching = false;
|
|
|
|
}
|
2007-08-30 16:13:33 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "keypress":
|
2009-05-15 13:33:59 +00:00
|
|
|
if (aEvent.getPreventDefault()) {
|
|
|
|
// The event has already been consumed inside of the panel.
|
|
|
|
break;
|
2008-03-14 00:52:21 +00:00
|
|
|
}
|
2009-05-15 13:33:59 +00: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") {
|
|
|
|
//XXX Why is this necessary? The getPreventDefault() check should
|
|
|
|
// be enough.
|
|
|
|
break;
|
|
|
|
}
|
2008-01-30 04:37:41 +00:00
|
|
|
this.panel.hidePopup();
|
2009-05-15 13:33:59 +00:00
|
|
|
break;
|
2008-01-30 04:37:41 +00:00
|
|
|
}
|
2007-08-30 16:13:33 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-08-17 07:22:12 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_overlayLoaded: false,
|
|
|
|
_overlayLoading: false,
|
|
|
|
showEditBookmarkPopup:
|
2008-01-30 04:37:41 +00:00
|
|
|
function SU_showEditBookmarkPopup(aItemId, aAnchorElement, aPosition) {
|
2007-08-17 07:22:12 +00: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
var loadObserver = {
|
|
|
|
_self: this,
|
|
|
|
_itemId: aItemId,
|
|
|
|
_anchorElement: aAnchorElement,
|
|
|
|
_position: aPosition,
|
|
|
|
observe: function (aSubject, aTopic, aData) {
|
2008-01-31 21:40:37 +00:00
|
|
|
this._self._overlayLoading = false;
|
|
|
|
this._self._overlayLoaded = true;
|
|
|
|
this._self._doShowEditBookmarkPanel(this._itemId, this._anchorElement,
|
|
|
|
this._position);
|
2007-08-17 07:22:12 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
this._overlayLoading = true;
|
|
|
|
document.loadOverlay("chrome://browser/content/places/editBookmarkOverlay.xul",
|
|
|
|
loadObserver);
|
|
|
|
},
|
|
|
|
|
|
|
|
_doShowEditBookmarkPanel:
|
2008-01-30 06:46:45 +00:00
|
|
|
function SU__doShowEditBookmarkPanel(aItemId, aAnchorElement, aPosition) {
|
2008-12-18 20:12:40 +00:00
|
|
|
if (this.panel.state != "closed")
|
|
|
|
return;
|
|
|
|
|
2008-07-29 23:22:28 +00:00
|
|
|
this._blockCommands(); // un-done in the popuphiding handler
|
|
|
|
|
2009-03-25 22:18:23 +00:00
|
|
|
// Move the header (star, title, possibly a button) into the grid,
|
|
|
|
// so that it aligns nicely with the other items (bug 484022).
|
|
|
|
var rows = this._element("editBookmarkPanelGrid").lastChild;
|
|
|
|
var header = this._element("editBookmarkPanelHeader");
|
|
|
|
rows.insertBefore(header, rows.firstChild);
|
|
|
|
header.hidden = false;
|
|
|
|
|
2008-07-29 23:22:28 +00:00
|
|
|
// 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 22:10:04 +00:00
|
|
|
gNavigatorBundle.getString("editBookmarkPanel.pageBookmarkedTitle") :
|
|
|
|
gNavigatorBundle.getString("editBookmarkPanel.editBookmarkTitle");
|
2008-07-29 23:22:28 +00:00
|
|
|
|
|
|
|
// No description; show the Done, Cancel;
|
|
|
|
// hide the Edit, Undo buttons
|
|
|
|
this._element("editBookmarkPanelDescription").textContent = "";
|
|
|
|
this._element("editBookmarkPanelBottomButtons").hidden = false;
|
|
|
|
this._element("editBookmarkPanelContent").hidden = false;
|
|
|
|
this._element("editBookmarkPanelEditButton").hidden = true;
|
|
|
|
this._element("editBookmarkPanelUndoRemoveButton").hidden = true;
|
|
|
|
|
|
|
|
// 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 19:47:25 +00:00
|
|
|
// The label of the remove button differs if the URI is bookmarked
|
|
|
|
// multiple times.
|
|
|
|
var bookmarks = PlacesUtils.getBookmarksForURI(gBrowser.currentURI);
|
2009-07-13 22:10:04 +00:00
|
|
|
var forms = gNavigatorBundle.getString("editBookmark.removeBookmarks.label");
|
2008-12-11 19:47:25 +00:00
|
|
|
var label = PluralForm.get(bookmarks.length, forms).replace("#1", bookmarks.length);
|
|
|
|
this._element("editBookmarkPanelRemoveButton").label = label;
|
|
|
|
|
2008-07-29 23:22:28 +00:00
|
|
|
// unset the unstarred state, if set
|
|
|
|
this._element("editBookmarkPanelStarIcon").removeAttribute("unstarred");
|
|
|
|
|
|
|
|
this._itemId = aItemId !== undefined ? aItemId : this._itemId;
|
|
|
|
this.beginBatch();
|
|
|
|
|
2008-12-18 20:12:40 +00:00
|
|
|
// Consume dismiss clicks, see bug 400924
|
|
|
|
this.panel.popupBoxObject
|
|
|
|
.setConsumeRollupEvent(Ci.nsIPopupBoxObject.ROLLUP_CONSUME);
|
|
|
|
this.panel.openPopup(aAnchorElement, aPosition, -1, -1);
|
2008-01-30 06:46:45 +00:00
|
|
|
|
|
|
|
gEditItemOverlay.initPanel(this._itemId,
|
2007-09-21 22:57:18 +00:00
|
|
|
{ hiddenRows: ["description", "location",
|
2007-09-22 22:58:35 +00:00
|
|
|
"loadInSidebar", "keyword"] });
|
2007-11-17 13:28:16 +00:00
|
|
|
},
|
|
|
|
|
2008-01-30 06:46:45 +00:00
|
|
|
panelShown:
|
|
|
|
function SU_panelShown(aEvent) {
|
2008-01-30 21:19:39 +00:00
|
|
|
if (aEvent.target == this.panel) {
|
|
|
|
if (!this._element("editBookmarkPanelContent").hidden) {
|
2010-02-25 18:30:09 +00:00
|
|
|
let fieldToFocus = "editBMPanel_" +
|
2009-02-27 01:27:39 +00:00
|
|
|
gPrefService.getCharPref("browser.bookmarks.editDialog.firstEditField");
|
|
|
|
var elt = this._element(fieldToFocus);
|
|
|
|
elt.focus();
|
|
|
|
elt.select();
|
2008-01-30 21:19:39 +00:00
|
|
|
}
|
2009-02-27 01:27:39 +00: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 21:19:39 +00:00
|
|
|
this.panel.focus();
|
2009-02-27 01:27:39 +00:00
|
|
|
}
|
2008-01-30 06:46:45 +00:00
|
|
|
}
|
2006-09-01 00:33:23 +00:00
|
|
|
},
|
|
|
|
|
2008-01-30 06:46:45 +00:00
|
|
|
showPageBookmarkedNotification:
|
|
|
|
function PCH_showPageBookmarkedNotification(aItemId, aAnchorElement, aPosition) {
|
|
|
|
this._blockCommands(); // un-done in the popuphiding handler
|
|
|
|
|
|
|
|
var brandBundle = this._element("bundle_brand");
|
|
|
|
var brandShortName = brandBundle.getString("brandShortName");
|
|
|
|
|
|
|
|
// "Page Bookmarked" title
|
|
|
|
this._element("editBookmarkPanelTitle").value =
|
2009-07-13 22:10:04 +00:00
|
|
|
gNavigatorBundle.getString("editBookmarkPanel.pageBookmarkedTitle");
|
2008-01-30 06:46:45 +00:00
|
|
|
|
|
|
|
// description
|
|
|
|
this._element("editBookmarkPanelDescription").textContent =
|
2009-07-13 22:10:04 +00:00
|
|
|
gNavigatorBundle.getFormattedString("editBookmarkPanel.pageBookmarkedDescription",
|
|
|
|
[brandShortName]);
|
2008-01-30 06:46:45 +00:00
|
|
|
|
|
|
|
// show the "Edit.." button and the Remove Bookmark button, hide the
|
|
|
|
// undo-remove-bookmark button.
|
|
|
|
this._element("editBookmarkPanelEditButton").hidden = false;
|
|
|
|
this._element("editBookmarkPanelRemoveButton").hidden = false;
|
|
|
|
this._element("editBookmarkPanelUndoRemoveButton").hidden = true;
|
|
|
|
|
|
|
|
// unset the unstarred state, if set
|
|
|
|
this._element("editBookmarkPanelStarIcon").removeAttribute("unstarred");
|
|
|
|
|
|
|
|
this._itemId = aItemId !== undefined ? aItemId : this._itemId;
|
|
|
|
if (this.panel.state == "closed") {
|
|
|
|
// Consume dismiss clicks, see bug 400924
|
|
|
|
this.panel.popupBoxObject
|
|
|
|
.setConsumeRollupEvent(Ci.nsIPopupBoxObject.ROLLUP_CONSUME);
|
|
|
|
this.panel.openPopup(aAnchorElement, aPosition, -1, -1);
|
|
|
|
}
|
2008-01-30 21:19:39 +00:00
|
|
|
else
|
|
|
|
this.panel.focus();
|
2008-01-30 06:46:45 +00:00
|
|
|
},
|
|
|
|
|
2008-03-14 00:52:21 +00:00
|
|
|
quitEditMode: function SU_quitEditMode() {
|
|
|
|
this._element("editBookmarkPanelContent").hidden = true;
|
|
|
|
this._element("editBookmarkPanelBottomButtons").hidden = true;
|
|
|
|
gEditItemOverlay.uninitPanel(true);
|
|
|
|
},
|
|
|
|
|
2008-01-30 06:46:45 +00:00
|
|
|
editButtonCommand: function SU_editButtonCommand() {
|
|
|
|
this.showEditBookmarkPopup();
|
|
|
|
},
|
|
|
|
|
|
|
|
cancelButtonOnCommand: function SU_cancelButtonOnCommand() {
|
2008-03-14 00:52:21 +00:00
|
|
|
// The order here is important! We have to hide the panel first, otherwise
|
|
|
|
// changes done as part of Undo may change the panel contents and by
|
|
|
|
// that force it to commit more transactions
|
|
|
|
this.panel.hidePopup();
|
2008-01-30 21:19:39 +00:00
|
|
|
this.endBatch();
|
2008-03-13 19:25:49 +00:00
|
|
|
PlacesUIUtils.ptm.undoTransaction();
|
2008-01-30 06:46:45 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
removeBookmarkButtonCommand: function SU_removeBookmarkButtonCommand() {
|
2008-02-04 18:54:57 +00:00
|
|
|
#ifdef ADVANCED_STARRING_UI
|
2008-01-30 06:46:45 +00:00
|
|
|
// In minimal mode ("page bookmarked" notification), the bookmark
|
|
|
|
// is removed and the panel is hidden immediately. In full edit mode,
|
|
|
|
// a "Bookmark Removed" notification along with an Undo button is
|
|
|
|
// shown
|
|
|
|
if (this._batching) {
|
2008-03-13 19:25:49 +00:00
|
|
|
PlacesUIUtils.ptm.endBatch();
|
|
|
|
PlacesUIUtils.ptm.beginBatch(); // allow undo from within the notification
|
2008-01-30 06:46:45 +00:00
|
|
|
|
|
|
|
// "Bookmark Removed" title (the description field is already empty in
|
|
|
|
// this mode)
|
|
|
|
this._element("editBookmarkPanelTitle").value =
|
2009-07-13 22:10:04 +00:00
|
|
|
gNavigatorBundle.getString("editBookmarkPanel.bookmarkedRemovedTitle");
|
2008-03-14 00:52:21 +00:00
|
|
|
|
|
|
|
// hide the edit panel
|
|
|
|
this.quitEditMode();
|
|
|
|
|
|
|
|
// Hide the remove bookmark button, show the undo-remove-bookmark
|
|
|
|
// button.
|
2008-01-30 06:46:45 +00:00
|
|
|
this._element("editBookmarkPanelUndoRemoveButton").hidden = false;
|
|
|
|
this._element("editBookmarkPanelRemoveButton").hidden = true;
|
|
|
|
this._element("editBookmarkPanelStarIcon").setAttribute("unstarred", "true");
|
2008-01-30 21:19:39 +00:00
|
|
|
this.panel.focus();
|
2008-01-30 06:46:45 +00:00
|
|
|
}
|
2008-02-04 18:54:57 +00:00
|
|
|
#endif
|
2008-01-30 06:46:45 +00:00
|
|
|
|
|
|
|
// cache its uri so we can get the new itemId in the case of undo
|
|
|
|
this._uri = PlacesUtils.bookmarks.getBookmarkURI(this._itemId);
|
|
|
|
|
2008-01-31 18:05:22 +00:00
|
|
|
// remove all bookmarks for the bookmark's url, this also removes
|
|
|
|
// the tags for the url
|
|
|
|
var itemIds = PlacesUtils.getBookmarksForURI(this._uri);
|
|
|
|
for (var i=0; i < itemIds.length; i++) {
|
2008-03-13 19:25:49 +00:00
|
|
|
var txn = PlacesUIUtils.ptm.removeItem(itemIds[i]);
|
|
|
|
PlacesUIUtils.ptm.doTransaction(txn);
|
2008-01-31 18:05:22 +00:00
|
|
|
}
|
2008-01-30 06:46:45 +00:00
|
|
|
|
2008-02-04 18:54:57 +00:00
|
|
|
#ifdef ADVANCED_STARRING_UI
|
2008-01-30 06:46:45 +00:00
|
|
|
// hidePopup resets our itemId, thus we call it only after removing
|
|
|
|
// the bookmark
|
|
|
|
if (!this._batching)
|
2008-02-04 18:54:57 +00:00
|
|
|
#endif
|
2008-01-30 06:46:45 +00:00
|
|
|
this.panel.hidePopup();
|
|
|
|
},
|
|
|
|
|
|
|
|
undoRemoveBookmarkCommand: function SU_undoRemoveBookmarkCommand() {
|
|
|
|
// restore the bookmark by undoing the last transaction and go back
|
|
|
|
// to the edit state
|
2008-01-30 21:19:39 +00:00
|
|
|
this.endBatch();
|
2008-03-13 19:25:49 +00:00
|
|
|
PlacesUIUtils.ptm.undoTransaction();
|
2008-01-30 06:46:45 +00:00
|
|
|
this._itemId = PlacesUtils.getMostRecentBookmarkForURI(this._uri);
|
|
|
|
this.showEditBookmarkPopup();
|
2008-01-30 21:19:39 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
beginBatch: function SU_beginBatch() {
|
|
|
|
if (!this._batching) {
|
2008-03-13 19:25:49 +00:00
|
|
|
PlacesUIUtils.ptm.beginBatch();
|
2008-01-30 21:19:39 +00:00
|
|
|
this._batching = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
endBatch: function SU_endBatch() {
|
|
|
|
if (this._batching) {
|
2008-03-13 19:25:49 +00:00
|
|
|
PlacesUIUtils.ptm.endBatch();
|
2008-01-30 21:19:39 +00:00
|
|
|
this._batching = false;
|
|
|
|
}
|
2008-01-30 06:46:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var PlacesCommandHook = {
|
2007-01-31 03:09:48 +00:00
|
|
|
/**
|
2007-08-28 21:47:43 +00:00
|
|
|
* Adds a bookmark to the page loaded in the given browser.
|
2007-08-17 07:22:12 +00:00
|
|
|
*
|
2007-01-31 03:09:48 +00:00
|
|
|
* @param aBrowser
|
2007-08-28 21:47:43 +00:00
|
|
|
* a <browser> element.
|
|
|
|
* @param [optional] aParent
|
|
|
|
* The folder in which to create a new bookmark if the page loaded in
|
2007-09-17 01:42:15 +00:00
|
|
|
* aBrowser isn't bookmarked yet, defaults to the unfiled root.
|
2007-08-17 07:22:12 +00:00
|
|
|
* @param [optional] aShowEditUI
|
|
|
|
* whether or not to show the edit-bookmark UI for the bookmark item
|
|
|
|
*/
|
2007-11-13 16:30:58 +00:00
|
|
|
bookmarkPage: function PCH_bookmarkPage(aBrowser, aParent, aShowEditUI) {
|
2007-08-17 07:22:12 +00: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 18:41:04 +00:00
|
|
|
var charset;
|
2007-08-17 07:22:12 +00:00
|
|
|
try {
|
2007-12-15 00:24:09 +00:00
|
|
|
title = webNav.document.title || url.spec;
|
2008-03-13 19:25:49 +00:00
|
|
|
description = PlacesUIUtils.getDescriptionFromDocument(webNav.document);
|
2008-04-08 18:41:04 +00:00
|
|
|
charset = webNav.document.characterSet;
|
2007-08-17 07:22:12 +00:00
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
|
2008-01-30 21:19:39 +00: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-20 02:01:53 +00:00
|
|
|
var parent = aParent != undefined ?
|
|
|
|
aParent : PlacesUtils.unfiledBookmarksFolderId;
|
2010-04-18 14:06:01 +00:00
|
|
|
var descAnno = { name: PlacesUIUtils.DESCRIPTION_ANNO, value: description };
|
2008-03-13 19:25:49 +00:00
|
|
|
var txn = PlacesUIUtils.ptm.createItem(uri, parent, -1,
|
|
|
|
title, null, [descAnno]);
|
|
|
|
PlacesUIUtils.ptm.doTransaction(txn);
|
2008-04-08 18:41:04 +00:00
|
|
|
// Set the character-set
|
|
|
|
if (charset)
|
|
|
|
PlacesUtils.history.setCharsetForURI(uri, charset);
|
2008-01-30 04:37:41 +00:00
|
|
|
itemId = PlacesUtils.getMostRecentBookmarkForURI(uri);
|
2007-03-10 00:05:50 +00:00
|
|
|
}
|
2007-08-17 07:22:12 +00:00
|
|
|
|
2008-04-14 01:00:16 +00:00
|
|
|
// Revert the contents of the location bar
|
2008-09-25 11:33:51 +00:00
|
|
|
if (gURLBar)
|
|
|
|
gURLBar.handleRevert();
|
2008-04-14 01:00:16 +00:00
|
|
|
|
2008-01-30 04:37:41 +00: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)) {
|
2008-07-11 20:31:48 +00:00
|
|
|
// Make sure the bookmark properties dialog hangs toward the middle of
|
|
|
|
// the location bar in RTL builds
|
2009-07-29 18:33:53 +00:00
|
|
|
var position = (getComputedStyle(gNavToolbox, "").direction == "rtl") ? 'after_start' : 'after_end';
|
2008-01-30 04:37:41 +00:00
|
|
|
if (aShowEditUI)
|
2008-07-11 20:31:48 +00:00
|
|
|
StarUI.showEditBookmarkPopup(itemId, starIcon, position);
|
2008-02-04 18:54:57 +00:00
|
|
|
#ifdef ADVANCED_STARRING_UI
|
2008-01-30 04:37:41 +00:00
|
|
|
else
|
2008-07-11 20:31:48 +00:00
|
|
|
StarUI.showPageBookmarkedNotification(itemId, starIcon, position);
|
2008-02-04 18:54:57 +00:00
|
|
|
#endif
|
2008-01-30 04:37:41 +00:00
|
|
|
return;
|
2007-11-13 16:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-30 04:37:41 +00:00
|
|
|
|
|
|
|
StarUI.showEditBookmarkPopup(itemId, aBrowser, "overlap");
|
2007-01-31 03:09:48 +00:00
|
|
|
},
|
|
|
|
|
2006-04-10 19:26:01 +00:00
|
|
|
/**
|
|
|
|
* Adds a bookmark to the page loaded in the current tab.
|
|
|
|
*/
|
2007-08-28 21:47:43 +00:00
|
|
|
bookmarkCurrentPage: function PCH_bookmarkCurrentPage(aShowEditUI, aParent) {
|
2009-09-20 10:58:27 +00:00
|
|
|
this.bookmarkPage(gBrowser.selectedBrowser, aParent, aShowEditUI);
|
2006-04-10 19:26:01 +00:00
|
|
|
},
|
2007-01-21 23:31:39 +00:00
|
|
|
|
2007-08-17 07:22:12 +00:00
|
|
|
/**
|
|
|
|
* Adds a bookmark to the page targeted by a link.
|
2007-08-28 21:47:43 +00: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 07:22:12 +00:00
|
|
|
*/
|
2007-08-28 21:47:43 +00:00
|
|
|
bookmarkLink: function PCH_bookmarkLink(aParent, aURL, aTitle) {
|
2008-02-02 00:39:05 +00:00
|
|
|
var linkURI = makeURI(aURL);
|
2007-08-17 07:22:12 +00:00
|
|
|
var itemId = PlacesUtils.getMostRecentBookmarkForURI(linkURI);
|
2008-10-30 17:21:47 +00:00
|
|
|
if (itemId == -1)
|
|
|
|
PlacesUIUtils.showMinimalAddBookmarkUI(linkURI, aTitle);
|
|
|
|
else {
|
|
|
|
PlacesUIUtils.showItemProperties(itemId,
|
|
|
|
PlacesUtils.bookmarks.TYPE_BOOKMARK);
|
2007-08-17 07:22:12 +00:00
|
|
|
}
|
|
|
|
},
|
2007-01-31 03:09:48 +00:00
|
|
|
|
2007-01-21 23:31:39 +00:00
|
|
|
/**
|
|
|
|
* This function returns a list of nsIURI objects characterizing the
|
|
|
|
* tabs currently open in the browser. The URIs will appear in the
|
|
|
|
* list in the order in which their corresponding tabs appeared. However,
|
|
|
|
* only the first instance of each URI will be returned.
|
|
|
|
*
|
|
|
|
* @returns a list of nsIURI objects representing unique locations open
|
|
|
|
*/
|
|
|
|
_getUniqueTabInfo: function BATC__getUniqueTabInfo() {
|
|
|
|
var tabList = [];
|
2009-09-20 10:58:27 +00:00
|
|
|
var seenURIs = {};
|
2007-01-21 23:31:39 +00:00
|
|
|
|
2009-09-20 10:58:27 +00:00
|
|
|
var browsers = gBrowser.browsers;
|
2007-01-21 23:31:39 +00:00
|
|
|
for (var i = 0; i < browsers.length; ++i) {
|
2009-09-20 10:58:27 +00:00
|
|
|
let uri = browsers[i].currentURI;
|
2007-01-21 23:31:39 +00:00
|
|
|
|
|
|
|
// skip redundant entries
|
|
|
|
if (uri.spec in seenURIs)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// add to the set of seen URIs
|
2009-09-20 10:58:27 +00:00
|
|
|
seenURIs[uri.spec] = null;
|
2007-01-21 23:31:39 +00:00
|
|
|
tabList.push(uri);
|
|
|
|
}
|
|
|
|
return tabList;
|
|
|
|
},
|
|
|
|
|
2006-04-10 19:26:01 +00:00
|
|
|
/**
|
|
|
|
* Adds a folder with bookmarks to all of the currently open tabs in this
|
|
|
|
* window.
|
|
|
|
*/
|
|
|
|
bookmarkCurrentPages: function PCH_bookmarkCurrentPages() {
|
2007-01-21 23:31:39 +00:00
|
|
|
var tabURIs = this._getUniqueTabInfo();
|
2008-03-13 19:25:49 +00:00
|
|
|
PlacesUIUtils.showMinimalAddMultiBookmarkUI(tabURIs);
|
2006-04-10 19:26:01 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a Live Bookmark to a feed associated with the current page.
|
2006-08-28 17:24:28 +00:00
|
|
|
* @param url
|
|
|
|
* The nsIURI of the page the feed was attached to
|
|
|
|
* @title title
|
|
|
|
* The title of the feed. Optional.
|
|
|
|
* @subtitle subtitle
|
2007-03-10 00:05:50 +00:00
|
|
|
* A short description of the feed. Optional.
|
2006-04-10 19:26:01 +00:00
|
|
|
*/
|
2006-08-28 17:24:28 +00:00
|
|
|
addLiveBookmark: function PCH_addLiveBookmark(url, feedTitle, feedSubtitle) {
|
2009-07-29 05:55:18 +00:00
|
|
|
var feedURI = makeURI(url);
|
2006-04-10 19:26:01 +00:00
|
|
|
|
2007-03-10 00:05:50 +00:00
|
|
|
var doc = gBrowser.contentDocument;
|
|
|
|
var title = (arguments.length > 1) ? feedTitle : doc.title;
|
2006-08-28 17:24:28 +00:00
|
|
|
|
|
|
|
var description;
|
|
|
|
if (arguments.length > 2)
|
|
|
|
description = feedSubtitle;
|
|
|
|
else
|
2008-03-13 19:25:49 +00:00
|
|
|
description = PlacesUIUtils.getDescriptionFromDocument(doc);
|
2006-04-10 19:26:01 +00:00
|
|
|
|
2007-03-10 00:05:50 +00:00
|
|
|
var toolbarIP =
|
|
|
|
new InsertionPoint(PlacesUtils.bookmarks.toolbarFolder, -1);
|
2008-03-13 19:25:49 +00:00
|
|
|
PlacesUIUtils.showMinimalAddLivemarkUI(feedURI, gBrowser.currentURI,
|
|
|
|
title, description, toolbarIP, true);
|
2006-04-10 19:26:01 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens the Places Organizer.
|
2007-11-26 19:04:23 +00:00
|
|
|
* @param aLeftPaneRoot
|
|
|
|
* The query to select in the organizer window - options
|
|
|
|
* are: History, AllBookmarks, BookmarksMenu, BookmarksToolbar,
|
|
|
|
* UnfiledBookmarks and Tags.
|
2006-04-10 19:26:01 +00:00
|
|
|
*/
|
2007-11-26 19:04:23 +00:00
|
|
|
showPlacesOrganizer: function PCH_showPlacesOrganizer(aLeftPaneRoot) {
|
2010-03-09 07:49:46 +00:00
|
|
|
var organizer = Services.wm.getMostRecentWindow("Places:Organizer");
|
2006-04-10 19:26:01 +00: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 19:04:23 +00:00
|
|
|
"", "chrome,toolbar=yes,dialog=no,resizable", aLeftPaneRoot);
|
2006-04-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-11-26 19:04:23 +00:00
|
|
|
organizer.PlacesOrganizer.selectLeftPaneQuery(aLeftPaneRoot);
|
2006-04-10 19:26:01 +00:00
|
|
|
organizer.focus();
|
|
|
|
}
|
2007-08-22 14:42:37 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
deleteButtonOnCommand: function PCH_deleteButtonCommand() {
|
|
|
|
PlacesUtils.bookmarks.removeItem(gEditItemOverlay.itemId);
|
|
|
|
|
|
|
|
// remove all tags for the associated url
|
|
|
|
PlacesUtils.tagging.untagURI(gEditItemOverlay._uri, null);
|
|
|
|
|
|
|
|
this.panel.hidePopup();
|
2006-04-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-05-05 13:28:04 +00:00
|
|
|
// View for the history menu.
|
|
|
|
function HistoryMenu(aPopupShowingEvent) {
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "_ss",
|
|
|
|
"@mozilla.org/browser/sessionstore;1",
|
|
|
|
"nsISessionStore");
|
|
|
|
PlacesMenu.call(this, aPopupShowingEvent,
|
|
|
|
"place:redirectsMode=2&sort=4&maxResults=10");
|
|
|
|
}
|
2009-07-29 08:49:59 +00:00
|
|
|
|
2010-05-05 13:28:04 +00:00
|
|
|
HistoryMenu.prototype = {
|
|
|
|
__proto__: PlacesMenu.prototype,
|
|
|
|
|
|
|
|
toggleRecentlyClosedTabs: function HM_toggleRecentlyClosedTabs() {
|
2009-06-22 23:00:44 +00:00
|
|
|
// enable/disable the Recently Closed Tabs sub menu
|
|
|
|
var undoPopup = document.getElementById("historyUndoPopup");
|
|
|
|
|
|
|
|
// no restorable tabs, so disable menu
|
2009-07-29 08:49:59 +00:00
|
|
|
if (this._ss.getClosedTabCount(window) == 0)
|
2009-06-22 23:00:44 +00:00
|
|
|
undoPopup.parentNode.setAttribute("disabled", true);
|
|
|
|
else
|
|
|
|
undoPopup.parentNode.removeAttribute("disabled");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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() {
|
|
|
|
var undoPopup = document.getElementById("historyUndoPopup");
|
|
|
|
|
|
|
|
// 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 08:49:59 +00:00
|
|
|
if (this._ss.getClosedTabCount(window) == 0) {
|
2009-06-22 23:00:44 +00:00
|
|
|
undoPopup.parentNode.setAttribute("disabled", true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// enable menu
|
|
|
|
undoPopup.parentNode.removeAttribute("disabled");
|
|
|
|
|
|
|
|
// populate menu
|
2009-07-29 08:49:59 +00:00
|
|
|
var undoItems = eval("(" + this._ss.getClosedTabData(window) + ")");
|
2009-06-22 23:00:44 +00: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 09:17:40 +00:00
|
|
|
m.setAttribute("class", "menuitem-iconic bookmark-item menuitem-with-favicon");
|
2009-06-22 23:00:44 +00:00
|
|
|
m.setAttribute("value", i);
|
|
|
|
m.setAttribute("oncommand", "undoCloseTab(" + i + ");");
|
2009-12-04 09:01:00 +00:00
|
|
|
|
|
|
|
// Set the targetURI attribute so it will be shown in tooltip and statusbar.
|
|
|
|
// SessionStore uses one-based indexes, so we need to normalize them.
|
|
|
|
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 23:00:44 +00:00
|
|
|
m.addEventListener("click", this._undoCloseMiddleClick, false);
|
|
|
|
if (i == 0)
|
|
|
|
m.setAttribute("key", "key_undoCloseTab");
|
|
|
|
undoPopup.appendChild(m);
|
|
|
|
}
|
|
|
|
|
2009-08-12 08:40:26 +00:00
|
|
|
// "Restore All Tabs"
|
2009-06-22 23:00:44 +00:00
|
|
|
var strings = gNavigatorBundle;
|
|
|
|
undoPopup.appendChild(document.createElement("menuseparator"));
|
|
|
|
m = undoPopup.appendChild(document.createElement("menuitem"));
|
2009-08-07 08:43:30 +00:00
|
|
|
m.id = "menu_restoreAllTabs";
|
2009-08-12 08:40:26 +00:00
|
|
|
m.setAttribute("label", strings.getString("menuRestoreAllTabs.label"));
|
|
|
|
m.setAttribute("accesskey", strings.getString("menuRestoreAllTabs.accesskey"));
|
2009-06-22 23:00:44 +00: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
|
|
|
|
let undoPopup = document.getElementById("historyUndoWindowPopup");
|
|
|
|
|
|
|
|
// no restorable windows, so disable menu
|
2009-07-29 08:49:59 +00:00
|
|
|
if (this._ss.getClosedWindowCount() == 0)
|
2009-06-22 23:00:44 +00:00
|
|
|
undoPopup.parentNode.setAttribute("disabled", true);
|
|
|
|
else
|
|
|
|
undoPopup.parentNode.removeAttribute("disabled");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Populate when the history menu is opened
|
|
|
|
*/
|
|
|
|
populateUndoWindowSubmenu: function PHM_populateUndoWindowSubmenu() {
|
|
|
|
let undoPopup = document.getElementById("historyUndoWindowPopup");
|
|
|
|
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 08:49:59 +00:00
|
|
|
if (this._ss.getClosedWindowCount() == 0) {
|
2009-06-22 23:00:44 +00:00
|
|
|
undoPopup.parentNode.setAttribute("disabled", true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// enable menu
|
|
|
|
undoPopup.parentNode.removeAttribute("disabled");
|
|
|
|
|
|
|
|
// populate menu
|
2009-07-29 08:49:59 +00:00
|
|
|
let undoItems = JSON.parse(this._ss.getClosedWindowData());
|
2009-06-22 23:00:44 +00: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 09:17:40 +00:00
|
|
|
m.setAttribute("class", "menuitem-iconic bookmark-item menuitem-with-favicon");
|
2009-06-22 23:00:44 +00:00
|
|
|
m.setAttribute("oncommand", "undoCloseWindow(" + i + ");");
|
2009-12-04 09:01:00 +00:00
|
|
|
|
|
|
|
// Set the targetURI attribute so it will be shown in tooltip and statusbar.
|
|
|
|
// 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 23:00:44 +00: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 08:43:30 +00:00
|
|
|
m.id = "menu_restoreAllWindows";
|
2009-06-22 23:00:44 +00:00
|
|
|
m.setAttribute("label", gNavigatorBundle.getString("menuRestoreAllWindows.label"));
|
|
|
|
m.setAttribute("accesskey", gNavigatorBundle.getString("menuRestoreAllWindows.accesskey"));
|
|
|
|
m.setAttribute("oncommand",
|
|
|
|
"for (var i = 0; i < " + undoItems.length + "; i++) undoCloseWindow();");
|
2009-04-23 06:50:30 +00:00
|
|
|
},
|
|
|
|
|
2010-05-05 13:28:04 +00:00
|
|
|
_onPopupShowing: function HM__onPopupShowing(aEvent) {
|
|
|
|
PlacesMenu.prototype._onPopupShowing.apply(this, arguments);
|
|
|
|
|
2009-06-22 23:00:44 +00:00
|
|
|
// Don't handle events for submenus.
|
|
|
|
if (aEvent.target != aEvent.currentTarget)
|
|
|
|
return;
|
|
|
|
|
2007-02-16 23:37:00 +00:00
|
|
|
this.toggleRecentlyClosedTabs();
|
2009-04-23 06:50:30 +00:00
|
|
|
this.toggleRecentlyClosedWindows();
|
2009-06-15 11:09:40 +00:00
|
|
|
},
|
|
|
|
|
2010-05-05 13:28:04 +00:00
|
|
|
_onCommand: function HM__onCommand(aEvent) {
|
|
|
|
let placesNode = aEvent.target._placesNode;
|
|
|
|
if (placesNode) {
|
|
|
|
PlacesUIUtils.markPageAsTyped(placesNode.uri);
|
|
|
|
openUILink(placesNode.uri, aEvent, false, true);
|
|
|
|
}
|
2006-04-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Functions for handling events in the Bookmarks Toolbar and menu.
|
|
|
|
*/
|
2010-06-24 17:08:43 +00:00
|
|
|
var BookmarksEventHandler = {
|
2006-04-10 19:26:01 +00: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 20:17:14 +00:00
|
|
|
* Left-click is handled in the onCommand function.
|
|
|
|
* When items are middle-clicked (or clicked with modifier), open in tabs.
|
2006-04-10 19:26:01 +00:00
|
|
|
* If the click came through a menu, close the menu.
|
2006-12-30 10:26:23 +00:00
|
|
|
* @param aEvent
|
|
|
|
* DOMEvent for the click
|
2006-04-10 19:26:01 +00:00
|
|
|
*/
|
2010-06-24 17:08:43 +00:00
|
|
|
onClick: function BEH_onClick(aEvent) {
|
2008-03-14 20:17:14 +00: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))
|
2006-04-10 19:26:01 +00:00
|
|
|
return;
|
2006-12-30 10:26:23 +00:00
|
|
|
|
|
|
|
var target = aEvent.originalTarget;
|
2008-03-14 20:17:14 +00:00
|
|
|
// If this event bubbled up from a menu or menuitem, close the menus.
|
2008-03-17 11:38:17 +00:00
|
|
|
// Do this before opening tabs, to avoid hiding the open tabs confirm-dialog.
|
2008-03-14 20:17:14 +00:00
|
|
|
if (target.localName == "menu" || target.localName == "menuitem") {
|
|
|
|
for (node = target.parentNode; node; node = node.parentNode) {
|
2006-04-10 19:26:01 +00:00
|
|
|
if (node.localName == "menupopup")
|
|
|
|
node.hidePopup();
|
2008-03-14 20:17:14 +00:00
|
|
|
else if (node.localName != "menu")
|
|
|
|
break;
|
2006-04-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
}
|
2008-03-17 11:33:16 +00:00
|
|
|
|
2010-05-05 13:28:04 +00:00
|
|
|
if (target._placesNode && PlacesUtils.nodeIsContainer(target._placesNode)) {
|
2008-03-17 11:33:16 +00: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")
|
2010-05-05 13:28:04 +00:00
|
|
|
PlacesUIUtils.openContainerNodeInTabs(target._placesNode, aEvent);
|
2008-03-17 11:33:16 +00:00
|
|
|
}
|
|
|
|
else if (aEvent.button == 1) {
|
|
|
|
// left-clicks with modifier are already served by onCommand
|
|
|
|
this.onCommand(aEvent);
|
|
|
|
}
|
2006-04-10 19:26:01 +00:00
|
|
|
},
|
2007-10-25 02:02:28 +00:00
|
|
|
|
2006-04-10 19:26:01 +00: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.
|
2006-12-30 10:26:23 +00:00
|
|
|
* @param aEvent
|
2006-04-10 19:26:01 +00:00
|
|
|
* DOMEvent for the command
|
|
|
|
*/
|
2010-06-24 17:08:43 +00:00
|
|
|
onCommand: function BEH_onCommand(aEvent) {
|
2006-12-30 10:26:23 +00:00
|
|
|
var target = aEvent.originalTarget;
|
2010-05-05 13:28:04 +00:00
|
|
|
if (target._placesNode)
|
|
|
|
PlacesUIUtils.openNodeWithEvent(target._placesNode, aEvent);
|
2007-01-13 10:18:30 +00:00
|
|
|
},
|
|
|
|
|
2010-06-24 17:08:43 +00:00
|
|
|
fillInBHTooltip: function BEH_fillInBHTooltip(aDocument, aEvent) {
|
2009-09-04 23:36:07 +00:00
|
|
|
var node;
|
|
|
|
var cropped = false;
|
2009-11-14 12:44:17 +00:00
|
|
|
var targetURI;
|
2009-09-04 23:36:07 +00: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 12:43:12 +00:00
|
|
|
if (row.value == -1)
|
|
|
|
return false;
|
2009-09-04 23:36:07 +00:00
|
|
|
node = tree.view.nodeForTreeIndex(row.value);
|
|
|
|
cropped = tbo.isCellCropped(row.value, column.value);
|
|
|
|
}
|
2009-11-14 12:44:17 +00: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 13:28:04 +00:00
|
|
|
if (tooltipNode._placesNode)
|
|
|
|
node = tooltipNode._placesNode;
|
2009-11-14 12:44:17 +00:00
|
|
|
else {
|
|
|
|
// This is a static non-Places node.
|
|
|
|
targetURI = tooltipNode.getAttribute("targetURI");
|
|
|
|
}
|
|
|
|
}
|
2007-01-13 10:18:30 +00:00
|
|
|
|
2009-11-14 12:44:17 +00:00
|
|
|
if (!node && !targetURI)
|
2007-06-12 15:34:02 +00:00
|
|
|
return false;
|
|
|
|
|
2009-11-14 12:44:17 +00:00
|
|
|
// Show node.label as tooltip's title for non-Places nodes.
|
|
|
|
var title = node ? node.title : tooltipNode.label;
|
2009-09-04 23:36:07 +00:00
|
|
|
|
2009-11-14 12:44:17 +00: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 23:36:07 +00:00
|
|
|
|
|
|
|
// Show tooltip for containers only if their title is cropped.
|
|
|
|
if (!cropped && !url)
|
|
|
|
return false;
|
2007-01-13 10:18:30 +00:00
|
|
|
|
2009-09-04 23:36:07 +00:00
|
|
|
var tooltipTitle = aDocument.getElementById("bhtTitleText");
|
|
|
|
tooltipTitle.hidden = (!title || (title == url));
|
2008-10-13 10:19:55 +00:00
|
|
|
if (!tooltipTitle.hidden)
|
2008-09-30 23:36:20 +00:00
|
|
|
tooltipTitle.textContent = title;
|
2007-01-13 10:18:30 +00:00
|
|
|
|
2009-09-04 23:36:07 +00:00
|
|
|
var tooltipUrl = aDocument.getElementById("bhtUrlText");
|
|
|
|
tooltipUrl.hidden = !url;
|
|
|
|
if (!tooltipUrl.hidden)
|
|
|
|
tooltipUrl.value = url;
|
2008-10-13 10:19:55 +00:00
|
|
|
|
2009-09-04 23:36:07 +00:00
|
|
|
// Show tooltip.
|
2007-01-13 10:18:30 +00:00
|
|
|
return true;
|
2006-04-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-09-19 15:47:45 +00:00
|
|
|
|
2010-06-24 17:08:43 +00: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 = {
|
2006-04-10 19:26:01 +00:00
|
|
|
_springLoadDelay: 350, // milliseconds
|
2010-06-24 17:08:43 +00:00
|
|
|
_loadTimer: null,
|
2006-04-10 19:26:01 +00:00
|
|
|
|
|
|
|
/**
|
2010-06-24 17:08:43 +00:00
|
|
|
* Called when the user enters the <menu> element during a drag.
|
2006-04-10 19:26:01 +00:00
|
|
|
* @param event
|
|
|
|
* The DragEnter event that spawned the opening.
|
|
|
|
*/
|
2010-06-24 17:08:43 +00:00
|
|
|
onDragEnter: function PMDH_onDragEnter(event) {
|
|
|
|
// Opening menus in a Places popup is handled by the view itself.
|
|
|
|
if (!this._isStaticContainer(event.target))
|
2006-04-10 19:26:01 +00:00
|
|
|
return;
|
2010-06-24 17:08:43 +00: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();
|
|
|
|
event.stopPropagation();
|
2006-04-10 19:26:01 +00:00
|
|
|
},
|
2010-06-24 17:08:43 +00:00
|
|
|
|
2006-04-10 19:26:01 +00:00
|
|
|
/**
|
2010-06-24 17:08:43 +00:00
|
|
|
* Handles dragleave on the <menu> element.
|
|
|
|
* @returns true if the element is a container element (menu or
|
|
|
|
* menu-toolbarbutton), false otherwise.
|
2006-04-10 19:26:01 +00:00
|
|
|
*/
|
2010-06-24 17:08:43 +00:00
|
|
|
onDragLeave: function PMDH_onDragLeave(event) {
|
|
|
|
// Closing menus in a Places popup is handled by the view itself.
|
|
|
|
if (!this._isStaticContainer(event.target))
|
2006-04-10 19:26:01 +00:00
|
|
|
return;
|
|
|
|
|
2010-06-24 17:08:43 +00:00
|
|
|
if (this._loadTimer) {
|
|
|
|
this._loadTimer.cancel();
|
|
|
|
this._loadTimer = null;
|
2006-04-10 19:26:01 +00:00
|
|
|
}
|
2010-06-24 17:08:43 +00:00
|
|
|
let closeTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
|
|
|
closeTimer.initWithCallback(function() {
|
|
|
|
let node = PlacesControllerDragHelper.currentDropTarget;
|
|
|
|
let inHierarchy = false;
|
|
|
|
while (node && !inHierarchy) {
|
|
|
|
inHierarchy = node == event.target;
|
|
|
|
node = node.parentNode;
|
2006-04-10 19:26:01 +00:00
|
|
|
}
|
2010-06-24 17:08:43 +00: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);
|
2006-04-10 19:26:01 +00:00
|
|
|
},
|
2010-06-24 17:08:43 +00:00
|
|
|
|
2006-04-10 19:26:01 +00:00
|
|
|
/**
|
2010-06-24 17:08:43 +00:00
|
|
|
* Determines if a XUL element represents a static container.
|
2006-04-10 19:26:01 +00:00
|
|
|
* @returns true if the element is a container element (menu or
|
|
|
|
*` menu-toolbarbutton), false otherwise.
|
|
|
|
*/
|
2010-06-24 17:08:43 +00: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;
|
2006-04-10 19:26:01 +00:00
|
|
|
},
|
2010-06-24 17:08:43 +00:00
|
|
|
|
2006-04-10 19:26:01 +00:00
|
|
|
/**
|
2010-06-24 17:08:43 +00:00
|
|
|
* Called when the user drags over the <menu> element.
|
2006-04-10 19:26:01 +00:00
|
|
|
* @param event
|
2010-06-24 17:08:43 +00:00
|
|
|
* The DragOver event.
|
2006-04-10 19:26:01 +00:00
|
|
|
*/
|
2010-06-24 17:08:43 +00: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();
|
2006-04-10 19:26:01 +00:00
|
|
|
},
|
|
|
|
|
2010-06-24 17:08:43 +00: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();
|
|
|
|
}
|
2006-04-10 19:26:01 +00:00
|
|
|
};
|
2007-08-16 01:15:50 +00:00
|
|
|
|
2010-06-24 17:08:43 +00:00
|
|
|
|
2007-08-16 01:15:50 +00:00
|
|
|
var PlacesStarButton = {
|
|
|
|
init: function PSB_init() {
|
2008-12-30 12:44:55 +00:00
|
|
|
try {
|
|
|
|
PlacesUtils.bookmarks.addObserver(this, false);
|
|
|
|
} catch(ex) {
|
|
|
|
Components.utils.reportError("PlacesStarButton.init(): error adding bookmark observer: " + ex);
|
|
|
|
}
|
2007-08-16 01:15:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
uninit: function PSB_uninit() {
|
|
|
|
PlacesUtils.bookmarks.removeObserver(this);
|
|
|
|
},
|
|
|
|
|
2010-06-24 17:08:43 +00:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver]),
|
2007-08-16 01:15:50 +00:00
|
|
|
|
|
|
|
_starred: false,
|
|
|
|
_batching: false,
|
|
|
|
|
|
|
|
updateState: function PSB_updateState() {
|
2007-08-28 21:47:43 +00:00
|
|
|
var starIcon = document.getElementById("star-button");
|
2007-08-17 07:22:12 +00:00
|
|
|
if (!starIcon)
|
|
|
|
return;
|
|
|
|
|
2009-09-20 10:58:27 +00:00
|
|
|
var uri = gBrowser.currentURI;
|
2007-09-07 21:47:21 +00:00
|
|
|
this._starred = uri && (PlacesUtils.getMostRecentBookmarkForURI(uri) != -1 ||
|
|
|
|
PlacesUtils.getMostRecentFolderForFeedURI(uri) != -1);
|
2007-09-21 18:18:34 +00:00
|
|
|
if (this._starred) {
|
2007-08-17 07:22:12 +00:00
|
|
|
starIcon.setAttribute("starred", "true");
|
2009-07-13 22:10:04 +00:00
|
|
|
starIcon.setAttribute("tooltiptext", gNavigatorBundle.getString("starButtonOn.tooltip"));
|
2007-09-21 18:18:34 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-08-17 07:22:12 +00:00
|
|
|
starIcon.removeAttribute("starred");
|
2009-07-13 22:10:04 +00:00
|
|
|
starIcon.setAttribute("tooltiptext", gNavigatorBundle.getString("starButtonOff.tooltip"));
|
2007-09-21 18:18:34 +00:00
|
|
|
}
|
2007-08-16 01:15:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onClick: function PSB_onClick(aEvent) {
|
2007-12-01 21:04:09 +00:00
|
|
|
if (aEvent.button == 0)
|
|
|
|
PlacesCommandHook.bookmarkCurrentPage(this._starred);
|
|
|
|
|
|
|
|
// don't bubble to the textbox so that the address won't be selected
|
|
|
|
aEvent.stopPropagation();
|
2007-08-16 01:15:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// nsINavBookmarkObserver
|
|
|
|
onBeginUpdateBatch: function PSB_onBeginUpdateBatch() {
|
|
|
|
this._batching = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
onEndUpdateBatch: function PSB_onEndUpdateBatch() {
|
|
|
|
this.updateState();
|
|
|
|
this._batching = false;
|
|
|
|
},
|
|
|
|
|
2009-10-01 16:53:26 +00:00
|
|
|
onItemAdded: function PSB_onItemAdded(aItemId, aFolder, aIndex, aItemType) {
|
2007-08-16 01:15:50 +00:00
|
|
|
if (!this._batching && !this._starred)
|
|
|
|
this.updateState();
|
|
|
|
},
|
|
|
|
|
2009-10-01 16:53:26 +00:00
|
|
|
onBeforeItemRemoved: function() {},
|
2009-03-19 19:56:51 +00:00
|
|
|
|
2009-10-01 16:53:26 +00:00
|
|
|
onItemRemoved: function PSB_onItemRemoved(aItemId, aFolder, aIndex,
|
|
|
|
aItemType) {
|
2007-08-16 01:15:50 +00:00
|
|
|
if (!this._batching)
|
|
|
|
this.updateState();
|
|
|
|
},
|
|
|
|
|
|
|
|
onItemChanged: function PSB_onItemChanged(aItemId, aProperty,
|
2009-10-01 16:53:26 +00:00
|
|
|
aIsAnnotationProperty, aNewValue,
|
|
|
|
aLastModified, aItemType) {
|
2007-08-16 01:15:50 +00:00
|
|
|
if (!this._batching && aProperty == "uri")
|
|
|
|
this.updateState();
|
|
|
|
},
|
|
|
|
|
2010-06-24 17:08:43 +00:00
|
|
|
onItemVisited: function() {},
|
|
|
|
onItemMoved: function() {}
|
2007-08-16 01:15:50 +00:00
|
|
|
};
|
2010-05-05 13:28:04 +00:00
|
|
|
|
2010-06-24 17:08:43 +00:00
|
|
|
|
2010-06-24 23:47:10 +00:00
|
|
|
// This object handles the initialization and uninitialization of the bookmarks
|
2010-05-05 13:28:04 +00: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 20:38:05 +00:00
|
|
|
get _viewElt() {
|
|
|
|
return document.getElementById("PlacesToolbar");
|
2010-05-05 13:28:04 +00:00
|
|
|
},
|
|
|
|
|
2010-07-15 20:38:05 +00:00
|
|
|
init: function PTH_init() {
|
2010-07-16 19:03:04 +00: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 20:38:05 +00:00
|
|
|
},
|
2010-05-05 13:28:04 +00:00
|
|
|
|
2010-07-15 20:38:05 +00:00
|
|
|
customizeStart: function PTH_customizeStart() {
|
|
|
|
let viewElt = this._viewElt;
|
|
|
|
if (viewElt && viewElt._placesView)
|
|
|
|
viewElt._placesView.uninit();
|
|
|
|
},
|
2010-05-05 13:28:04 +00:00
|
|
|
|
2010-07-15 20:38:05 +00:00
|
|
|
customizeDone: function PTH_customizeDone() {
|
|
|
|
this.init();
|
2010-05-05 13:28:04 +00:00
|
|
|
}
|
|
|
|
};
|
2010-06-24 17:08:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Handles the bookmarks menu button shown when the main menubar is hidden.
|
|
|
|
let BookmarksMenuButton = {
|
|
|
|
get button() {
|
2010-07-09 19:44:01 +00:00
|
|
|
return document.getElementById("bookmarks-menu-button");
|
2010-06-24 17:08:43 +00:00
|
|
|
},
|
|
|
|
|
2010-07-09 19:44:01 +00:00
|
|
|
get buttonContainer() {
|
|
|
|
return document.getElementById("bookmarks-menu-button-container");
|
2010-06-24 17:08:43 +00: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.
|
|
|
|
},
|
|
|
|
|
|
|
|
_popupInitialized: false,
|
|
|
|
_popupNeedsUpdating: true,
|
|
|
|
onPopupShowing: function BMB_onPopupShowing(event) {
|
|
|
|
if (!this._popupNeedsUpdating)
|
|
|
|
return;
|
|
|
|
this._popupNeedsUpdating = false;
|
|
|
|
|
|
|
|
let viewToolbar = document.getElementById("BMB_viewBookmarksToolbar");
|
|
|
|
if (!this._popupInitialized) {
|
|
|
|
// First popupshowing event, initialize immutable attributes.
|
|
|
|
this._popupInitialized = true;
|
|
|
|
// Update View bookmarks toolbar checkbox menuitem.
|
|
|
|
viewToolbar.setAttribute("toolbarindex",
|
|
|
|
Array.indexOf(gNavToolbox.childNodes,
|
|
|
|
this.personalToolbar));
|
|
|
|
|
|
|
|
// Need to set the label on Unsorted Bookmarks menu.
|
|
|
|
let unsortedBookmarksElt =
|
|
|
|
document.getElementById("BMB_unsortedBookmarksFolderMenu");
|
|
|
|
unsortedBookmarksElt.label =
|
|
|
|
PlacesUtils.getString("UnsortedBookmarksFolderTitle");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update View Bookmarks Toolbar checkbox menuitem.
|
|
|
|
viewToolbar.setAttribute("checked", !this.personalToolbar.collapsed);
|
|
|
|
|
|
|
|
// Hide Bookmarks Toolbar menu if the button is next to the bookmarks
|
|
|
|
// toolbar item, show them otherwise.
|
2010-07-09 19:44:01 +00:00
|
|
|
let button = this.button;
|
|
|
|
document.getElementById("BMB_bookmarksToolbarFolderMenu").collapsed =
|
|
|
|
button && button.parentNode == this.bookmarksToolbarItem;
|
2010-06-24 17:08:43 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
updatePosition: function BMB_updatePosition() {
|
|
|
|
this._popupNeedsUpdating = true;
|
|
|
|
|
2010-07-09 19:44:01 +00: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 17:08:43 +00:00
|
|
|
let bookmarksToolbarItem = this.bookmarksToolbarItem;
|
2010-07-09 19:44:01 +00: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 23:47:10 +00:00
|
|
|
}
|
2010-06-24 17:08:43 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-07-09 19:44:01 +00:00
|
|
|
if (container && button.parentNode != container) {
|
|
|
|
this._uninitView();
|
|
|
|
container.appendChild(button);
|
2010-06-24 23:47:10 +00:00
|
|
|
}
|
2010-06-24 17:08:43 +00:00
|
|
|
}
|
2010-07-09 19:44:01 +00:00
|
|
|
this._updateStyle();
|
2010-06-24 17:08:43 +00:00
|
|
|
},
|
|
|
|
|
2010-07-09 19:44:01 +00: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 23:47:10 +00: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 19:44:01 +00:00
|
|
|
let button = this.button;
|
|
|
|
if (button && button._placesView)
|
|
|
|
button._placesView.uninit();
|
2010-06-24 23:47:10 +00:00
|
|
|
},
|
|
|
|
|
2010-06-24 17:08:43 +00:00
|
|
|
customizeStart: function BMB_customizeStart() {
|
2010-07-09 19:44:01 +00: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 17:08:43 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
customizeDone: function BMB_customizeDone() {
|
|
|
|
this.updatePosition();
|
|
|
|
}
|
|
|
|
};
|