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>
|
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,
|
|
|
|
|
2007-08-17 00:22:12 -07:00
|
|
|
// nsISupports
|
2008-01-29 20:37:41 -08:00
|
|
|
QueryInterface: function SU_QueryInterface(aIID) {
|
2007-08-17 00:22:12 -07:00
|
|
|
if (aIID.equals(Ci.nsIDOMEventListener) ||
|
|
|
|
aIID.equals(Ci.nsISupports))
|
|
|
|
return this;
|
|
|
|
|
|
|
|
throw Cr.NS_NOINTERFACE;
|
|
|
|
},
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-01-29 20:37:41 -08:00
|
|
|
_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
|
|
|
},
|
|
|
|
|
2007-08-30 09:13:33 -07:00
|
|
|
// list of command elements (by id) to disable when the panel is opened
|
|
|
|
_blockedCommands: ["cmd_close", "cmd_closeWindow"],
|
2008-01-29 20:37:41 -08:00
|
|
|
_blockCommands: function SU__blockCommands() {
|
2007-08-30 09:13:33 -07:00
|
|
|
for each(var key in this._blockedCommands) {
|
2008-01-29 20:37:41 -08:00
|
|
|
var elt = this._element(key);
|
2007-12-23 19:03:41 -08:00
|
|
|
// make sure not to permanently disable this item (see bug 409155)
|
|
|
|
if (elt.hasAttribute("wasDisabled"))
|
|
|
|
continue;
|
2007-08-30 09:13:33 -07:00
|
|
|
if (elt.getAttribute("disabled") == "true")
|
|
|
|
elt.setAttribute("wasDisabled", "true");
|
|
|
|
else {
|
|
|
|
elt.setAttribute("wasDisabled", "false");
|
|
|
|
elt.setAttribute("disabled", "true");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-01-29 20:37:41 -08:00
|
|
|
_restoreCommandsState: function SU__restoreCommandsState() {
|
2007-08-30 09:13:33 -07:00
|
|
|
for each(var key in this._blockedCommands) {
|
2008-01-29 20:37:41 -08:00
|
|
|
var elt = this._element(key);
|
2007-08-30 09:13:33 -07:00
|
|
|
if (elt.getAttribute("wasDisabled") != "true")
|
|
|
|
elt.removeAttribute("disabled");
|
|
|
|
elt.removeAttribute("wasDisabled");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
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();
|
2007-08-30 09:13:33 -07:00
|
|
|
this._restoreCommandsState();
|
2008-01-29 20:37:41 -08:00
|
|
|
this._itemId = -1;
|
|
|
|
this._uri = null;
|
|
|
|
if (this._batching) {
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUIUtils.ptm.endBatch();
|
2008-01-29 20:37:41 -08:00
|
|
|
this._batching = false;
|
|
|
|
}
|
2007-08-30 09:13:33 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "keypress":
|
2009-05-15 06:33:59 -07:00
|
|
|
if (aEvent.getPreventDefault()) {
|
|
|
|
// 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") {
|
|
|
|
//XXX Why is this necessary? The getPreventDefault() check should
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
var loadObserver = {
|
|
|
|
_self: this,
|
|
|
|
_itemId: aItemId,
|
|
|
|
_anchorElement: aAnchorElement,
|
|
|
|
_position: aPosition,
|
|
|
|
observe: function (aSubject, aTopic, aData) {
|
2008-01-31 13:40:37 -08:00
|
|
|
this._self._overlayLoading = false;
|
|
|
|
this._self._overlayLoaded = true;
|
|
|
|
this._self._doShowEditBookmarkPanel(this._itemId, this._anchorElement,
|
|
|
|
this._position);
|
2007-08-17 00:22:12 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
this._overlayLoading = true;
|
|
|
|
document.loadOverlay("chrome://browser/content/places/editBookmarkOverlay.xul",
|
|
|
|
loadObserver);
|
|
|
|
},
|
|
|
|
|
|
|
|
_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
|
|
|
|
|
2009-03-25 15:18:23 -07: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 16:22:28 -07: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 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;
|
|
|
|
// 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 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);
|
|
|
|
this.panel.openPopup(aAnchorElement, aPosition, -1, -1);
|
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-01-29 22:46:45 -08: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 15:10:04 -07:00
|
|
|
gNavigatorBundle.getString("editBookmarkPanel.pageBookmarkedTitle");
|
2008-01-29 22:46:45 -08:00
|
|
|
|
|
|
|
// description
|
|
|
|
this._element("editBookmarkPanelDescription").textContent =
|
2009-07-13 15:10:04 -07:00
|
|
|
gNavigatorBundle.getFormattedString("editBookmarkPanel.pageBookmarkedDescription",
|
|
|
|
[brandShortName]);
|
2008-01-29 22:46:45 -08: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 13:19:39 -08:00
|
|
|
else
|
|
|
|
this.panel.focus();
|
2008-01-29 22:46:45 -08: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() {
|
2008-03-13 17:52:21 -07: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 13:19:39 -08:00
|
|
|
this.endBatch();
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUIUtils.ptm.undoTransaction();
|
2008-01-29 22:46:45 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
removeBookmarkButtonCommand: function SU_removeBookmarkButtonCommand() {
|
2008-02-04 10:54:57 -08:00
|
|
|
#ifdef ADVANCED_STARRING_UI
|
2008-01-29 22:46:45 -08: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 12:25:49 -07:00
|
|
|
PlacesUIUtils.ptm.endBatch();
|
|
|
|
PlacesUIUtils.ptm.beginBatch(); // allow undo from within the notification
|
2008-01-29 22:46:45 -08:00
|
|
|
|
|
|
|
// "Bookmark Removed" title (the description field is already empty in
|
|
|
|
// this mode)
|
|
|
|
this._element("editBookmarkPanelTitle").value =
|
2009-07-13 15:10:04 -07:00
|
|
|
gNavigatorBundle.getString("editBookmarkPanel.bookmarkedRemovedTitle");
|
2008-03-13 17:52:21 -07:00
|
|
|
|
|
|
|
// hide the edit panel
|
|
|
|
this.quitEditMode();
|
|
|
|
|
|
|
|
// Hide the remove bookmark button, show the undo-remove-bookmark
|
|
|
|
// button.
|
2008-01-29 22:46:45 -08:00
|
|
|
this._element("editBookmarkPanelUndoRemoveButton").hidden = false;
|
|
|
|
this._element("editBookmarkPanelRemoveButton").hidden = true;
|
|
|
|
this._element("editBookmarkPanelStarIcon").setAttribute("unstarred", "true");
|
2008-01-30 13:19:39 -08:00
|
|
|
this.panel.focus();
|
2008-01-29 22:46:45 -08:00
|
|
|
}
|
2008-02-04 10:54:57 -08:00
|
|
|
#endif
|
2008-01-29 22:46:45 -08: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 10:05:22 -08: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 12:25:49 -07:00
|
|
|
var txn = PlacesUIUtils.ptm.removeItem(itemIds[i]);
|
|
|
|
PlacesUIUtils.ptm.doTransaction(txn);
|
2008-01-31 10:05:22 -08:00
|
|
|
}
|
2008-01-29 22:46:45 -08:00
|
|
|
|
2008-02-04 10:54:57 -08:00
|
|
|
#ifdef ADVANCED_STARRING_UI
|
2008-01-29 22:46:45 -08:00
|
|
|
// hidePopup resets our itemId, thus we call it only after removing
|
|
|
|
// the bookmark
|
|
|
|
if (!this._batching)
|
2008-02-04 10:54:57 -08:00
|
|
|
#endif
|
2008-01-29 22:46:45 -08: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 13:19:39 -08:00
|
|
|
this.endBatch();
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUIUtils.ptm.undoTransaction();
|
2008-01-29 22:46:45 -08:00
|
|
|
this._itemId = PlacesUtils.getMostRecentBookmarkForURI(this._uri);
|
|
|
|
this.showEditBookmarkPopup();
|
2008-01-30 13:19:39 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
beginBatch: function SU_beginBatch() {
|
|
|
|
if (!this._batching) {
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUIUtils.ptm.beginBatch();
|
2008-01-30 13:19:39 -08:00
|
|
|
this._batching = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
endBatch: function SU_endBatch() {
|
|
|
|
if (this._batching) {
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUIUtils.ptm.endBatch();
|
2008-01-30 13:19:39 -08:00
|
|
|
this._batching = false;
|
|
|
|
}
|
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 };
|
2008-03-13 12:25:49 -07:00
|
|
|
var txn = PlacesUIUtils.ptm.createItem(uri, parent, -1,
|
|
|
|
title, null, [descAnno]);
|
|
|
|
PlacesUIUtils.ptm.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)) {
|
2008-07-11 13:31:48 -07:00
|
|
|
// Make sure the bookmark properties dialog hangs toward the middle of
|
|
|
|
// the location bar in RTL builds
|
2009-07-29 11:33:53 -07:00
|
|
|
var position = (getComputedStyle(gNavToolbox, "").direction == "rtl") ? 'after_start' : 'after_end';
|
2008-01-29 20:37:41 -08:00
|
|
|
if (aShowEditUI)
|
2008-07-11 13:31:48 -07:00
|
|
|
StarUI.showEditBookmarkPopup(itemId, starIcon, position);
|
2008-02-04 10:54:57 -08:00
|
|
|
#ifdef ADVANCED_STARRING_UI
|
2008-01-29 20:37:41 -08:00
|
|
|
else
|
2008-07-11 13:31:48 -07:00
|
|
|
StarUI.showPageBookmarkedNotification(itemId, starIcon, position);
|
2008-02-04 10:54:57 -08:00
|
|
|
#endif
|
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);
|
2008-10-30 10:21:47 -07:00
|
|
|
if (itemId == -1)
|
|
|
|
PlacesUIUtils.showMinimalAddBookmarkUI(linkURI, aTitle);
|
|
|
|
else {
|
|
|
|
PlacesUIUtils.showItemProperties(itemId,
|
|
|
|
PlacesUtils.bookmarks.TYPE_BOOKMARK);
|
2007-08-17 00:22:12 -07:00
|
|
|
}
|
|
|
|
},
|
2007-03-22 10:30:00 -07: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 03:58:27 -07:00
|
|
|
var seenURIs = {};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-20 03:58:27 -07:00
|
|
|
var browsers = gBrowser.browsers;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (var i = 0; i < browsers.length; ++i) {
|
2009-09-20 03:58:27 -07:00
|
|
|
let uri = browsers[i].currentURI;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// skip redundant entries
|
|
|
|
if (uri.spec in seenURIs)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// add to the set of seen URIs
|
2009-09-20 03:58:27 -07:00
|
|
|
seenURIs[uri.spec] = null;
|
2007-03-22 10:30:00 -07:00
|
|
|
tabList.push(uri);
|
|
|
|
}
|
|
|
|
return tabList;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a folder with bookmarks to all of the currently open tabs in this
|
|
|
|
* window.
|
|
|
|
*/
|
|
|
|
bookmarkCurrentPages: function PCH_bookmarkCurrentPages() {
|
|
|
|
var tabURIs = this._getUniqueTabInfo();
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUIUtils.showMinimalAddMultiBookmarkUI(tabURIs);
|
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
|
|
|
|
|
|
|
var toolbarIP =
|
|
|
|
new InsertionPoint(PlacesUtils.bookmarks.toolbarFolder, -1);
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUIUtils.showMinimalAddLivemarkUI(feedURI, gBrowser.currentURI,
|
|
|
|
title, description, toolbarIP, true);
|
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();
|
|
|
|
}
|
2007-08-22 07:42:37 -07: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();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-05-05 06:28:04 -07: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 01:49:59 -07:00
|
|
|
|
2010-05-05 06:28:04 -07:00
|
|
|
HistoryMenu.prototype = {
|
|
|
|
__proto__: PlacesMenu.prototype,
|
|
|
|
|
|
|
|
toggleRecentlyClosedTabs: function HM_toggleRecentlyClosedTabs() {
|
2009-06-22 16:00:44 -07:00
|
|
|
// enable/disable the Recently Closed Tabs sub menu
|
|
|
|
var undoPopup = document.getElementById("historyUndoPopup");
|
|
|
|
|
|
|
|
// no restorable tabs, so disable menu
|
2009-07-29 01:49:59 -07:00
|
|
|
if (this._ss.getClosedTabCount(window) == 0)
|
2009-06-22 16:00:44 -07: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 01:49:59 -07:00
|
|
|
if (this._ss.getClosedTabCount(window) == 0) {
|
2009-06-22 16:00:44 -07:00
|
|
|
undoPopup.parentNode.setAttribute("disabled", true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// enable menu
|
|
|
|
undoPopup.parentNode.removeAttribute("disabled");
|
|
|
|
|
|
|
|
// populate menu
|
2009-07-29 01:49:59 -07:00
|
|
|
var undoItems = eval("(" + 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
|
|
|
|
|
|
|
// 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 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"));
|
|
|
|
m.setAttribute("accesskey", strings.getString("menuRestoreAllTabs.accesskey"));
|
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
|
|
|
|
let undoPopup = document.getElementById("historyUndoWindowPopup");
|
|
|
|
|
|
|
|
// no restorable windows, so disable menu
|
2009-07-29 01:49:59 -07:00
|
|
|
if (this._ss.getClosedWindowCount() == 0)
|
2009-06-22 16:00:44 -07: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 01:49:59 -07:00
|
|
|
if (this._ss.getClosedWindowCount() == 0) {
|
2009-06-22 16:00:44 -07:00
|
|
|
undoPopup.parentNode.setAttribute("disabled", true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// enable menu
|
|
|
|
undoPopup.parentNode.removeAttribute("disabled");
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
// 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 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("accesskey", gNavigatorBundle.getString("menuRestoreAllWindows.accesskey"));
|
|
|
|
m.setAttribute("oncommand",
|
|
|
|
"for (var i = 0; i < " + undoItems.length + "; i++) undoCloseWindow();");
|
2009-04-22 23:50:30 -07:00
|
|
|
},
|
|
|
|
|
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;
|
|
|
|
|
2010-05-05 06:28:04 -07:00
|
|
|
let resultNode = this.result.root;
|
2007-03-22 10:30:00 -07:00
|
|
|
resultNode.containerOpen = true;
|
|
|
|
document.getElementById("endHistorySeparator").hidden =
|
|
|
|
resultNode.childCount == 0;
|
|
|
|
|
|
|
|
this.toggleRecentlyClosedTabs();
|
2009-04-22 23:50:30 -07:00
|
|
|
this.toggleRecentlyClosedWindows();
|
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.
|
|
|
|
*/
|
|
|
|
var BookmarksEventHandler = {
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
onClick: function BT_onClick(aEvent) {
|
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();
|
2008-03-14 13:17:14 -07:00
|
|
|
else if (node.localName != "menu")
|
|
|
|
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")
|
2010-05-05 06:28:04 -07:00
|
|
|
PlacesUIUtils.openContainerNodeInTabs(target._placesNode, aEvent);
|
2008-03-17 04:33:16 -07:00
|
|
|
}
|
|
|
|
else if (aEvent.button == 1) {
|
|
|
|
// left-clicks with modifier are already served by onCommand
|
|
|
|
this.onCommand(aEvent);
|
|
|
|
}
|
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
|
|
|
|
*/
|
|
|
|
onCommand: function BM_onCommand(aEvent) {
|
|
|
|
var target = aEvent.originalTarget;
|
2010-05-05 06:28:04 -07:00
|
|
|
if (target._placesNode)
|
|
|
|
PlacesUIUtils.openNodeWithEvent(target._placesNode, aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2009-09-04 16:36:07 -07:00
|
|
|
fillInBHTooltip: function(aDocument, aEvent) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2010-02-23 07:20:36 -08:00
|
|
|
* Drag and Drop handler for the Bookmarks menu in the top level menu bar.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2010-02-23 07:20:36 -08:00
|
|
|
let BookmarksMenuDropHandler = {
|
|
|
|
onDragOver: function BMDH_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();
|
2008-09-19 08:47:45 -07:00
|
|
|
|
2010-02-23 07:20:36 -08:00
|
|
|
event.stopPropagation();
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2008-02-16 22:17:34 -08:00
|
|
|
|
2010-02-23 07:20:36 -08:00
|
|
|
onDrop: function BMDH_onDrop(event) {
|
|
|
|
// Put the item at the end of bookmark menu.
|
|
|
|
let ip = new InsertionPoint(PlacesUtils.bookmarksMenuFolderId,
|
|
|
|
PlacesUtils.bookmarks.DEFAULT_INDEX,
|
2008-09-19 08:47:45 -07:00
|
|
|
Ci.nsITreeView.DROP_ON);
|
2010-02-23 07:20:36 -08:00
|
|
|
PlacesControllerDragHelper.onDrop(ip, event.dataTransfer);
|
|
|
|
event.stopPropagation();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles special drag and drop functionality for menus on the Bookmarks
|
|
|
|
* Toolbar and Bookmarks Menu.
|
|
|
|
*/
|
|
|
|
var PlacesMenuDNDController = {
|
|
|
|
_springLoadDelay: 350, // milliseconds
|
|
|
|
|
|
|
|
/**
|
|
|
|
* All Drag Timers set for the Places UI
|
|
|
|
*/
|
|
|
|
_timers: { },
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the user drags over the Bookmarks top level <menu> element.
|
|
|
|
* @param event
|
|
|
|
* The DragEnter event that spawned the opening.
|
|
|
|
*/
|
|
|
|
onBookmarksMenuDragEnter: function PMDC_onDragEnter(event) {
|
|
|
|
if ("loadTime" in this._timers)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._setDragTimer("loadTime", this._openBookmarksMenu,
|
|
|
|
this._springLoadDelay, [event]);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a timer that will fire during a drag and drop operation.
|
|
|
|
* @param id
|
|
|
|
* The identifier of the timer being set
|
|
|
|
* @param callback
|
|
|
|
* The function to call when the timer "fires"
|
|
|
|
* @param delay
|
|
|
|
* The time to wait before calling the callback function
|
|
|
|
* @param args
|
|
|
|
* An array of arguments to pass to the callback function
|
|
|
|
*/
|
|
|
|
_setDragTimer: function PMDC__setDragTimer(id, callback, delay, args) {
|
|
|
|
if (!this._dragSupported)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Cancel this timer if it's already running.
|
|
|
|
if (id in this._timers)
|
|
|
|
this._timers[id].cancel();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An object implementing nsITimerCallback that calls a user-supplied
|
|
|
|
* method with the specified args in the context of the supplied object.
|
|
|
|
*/
|
|
|
|
function Callback(object, method, args) {
|
|
|
|
this._method = method;
|
|
|
|
this._args = args;
|
|
|
|
this._object = object;
|
|
|
|
}
|
|
|
|
Callback.prototype = {
|
|
|
|
notify: function C_notify(timer) {
|
|
|
|
this._method.apply(this._object, this._args);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
|
|
|
timer.initWithCallback(new Callback(this, callback, args), delay,
|
|
|
|
timer.TYPE_ONE_SHOT);
|
|
|
|
this._timers[id] = timer;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if a XUL element represents a container in the Bookmarks system
|
|
|
|
* @returns true if the element is a container element (menu or
|
|
|
|
*` menu-toolbarbutton), false otherwise.
|
|
|
|
*/
|
|
|
|
_isContainer: function PMDC__isContainer(node) {
|
2008-09-19 08:47:45 -07:00
|
|
|
return node.localName == "menu" ||
|
|
|
|
(node.localName == "toolbarbutton" &&
|
|
|
|
node.getAttribute("type") == "menu");
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens the Bookmarks Menu when it is dragged over. (This is special-cased,
|
|
|
|
* since the toplevel Bookmarks <menu> is not a member of an existing places
|
|
|
|
* container, as folders on the personal toolbar or submenus are.
|
|
|
|
* @param event
|
|
|
|
* The DragEnter event that spawned the opening.
|
|
|
|
*/
|
|
|
|
_openBookmarksMenu: function PMDC__openBookmarksMenu(event) {
|
|
|
|
if ("loadTime" in this._timers)
|
|
|
|
delete this._timers.loadTime;
|
|
|
|
if (event.target.id == "bookmarksMenu") {
|
|
|
|
// If this is the bookmarks menu, tell its menupopup child to show.
|
2008-05-07 03:14:51 -07:00
|
|
|
event.target.lastChild.setAttribute("autoopened", "true");
|
2007-03-22 10:30:00 -07:00
|
|
|
event.target.lastChild.showPopup(event.target.lastChild);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Whether or not drag and drop to menus is supported on this platform
|
|
|
|
// Dragging in menus is disabled on OS X due to various repainting issues.
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
_dragSupported: false
|
|
|
|
#else
|
|
|
|
_dragSupported: true
|
|
|
|
#endif
|
|
|
|
};
|
2007-08-15 18:15:50 -07:00
|
|
|
|
|
|
|
var PlacesStarButton = {
|
|
|
|
init: function PSB_init() {
|
2008-12-30 04:44:55 -08:00
|
|
|
try {
|
|
|
|
PlacesUtils.bookmarks.addObserver(this, false);
|
|
|
|
} catch(ex) {
|
|
|
|
Components.utils.reportError("PlacesStarButton.init(): error adding bookmark observer: " + ex);
|
|
|
|
}
|
2007-08-15 18:15:50 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
uninit: function PSB_uninit() {
|
|
|
|
PlacesUtils.bookmarks.removeObserver(this);
|
|
|
|
},
|
|
|
|
|
|
|
|
QueryInterface: function PSB_QueryInterface(aIID) {
|
2007-08-17 00:22:12 -07:00
|
|
|
if (aIID.equals(Ci.nsINavBookmarkObserver) ||
|
2007-08-15 18:15:50 -07:00
|
|
|
aIID.equals(Ci.nsISupports))
|
|
|
|
return this;
|
|
|
|
|
|
|
|
throw Cr.NS_NOINTERFACE;
|
|
|
|
},
|
|
|
|
|
|
|
|
_starred: false,
|
|
|
|
_batching: false,
|
|
|
|
|
|
|
|
updateState: function PSB_updateState() {
|
2007-08-28 14:47:43 -07:00
|
|
|
var starIcon = document.getElementById("star-button");
|
2007-08-17 00:22:12 -07:00
|
|
|
if (!starIcon)
|
|
|
|
return;
|
|
|
|
|
2009-09-20 03:58:27 -07:00
|
|
|
var uri = gBrowser.currentURI;
|
2007-09-07 14:47:21 -07:00
|
|
|
this._starred = uri && (PlacesUtils.getMostRecentBookmarkForURI(uri) != -1 ||
|
|
|
|
PlacesUtils.getMostRecentFolderForFeedURI(uri) != -1);
|
2007-09-21 11:18:34 -07:00
|
|
|
if (this._starred) {
|
2007-08-17 00:22:12 -07:00
|
|
|
starIcon.setAttribute("starred", "true");
|
2009-07-13 15:10:04 -07:00
|
|
|
starIcon.setAttribute("tooltiptext", gNavigatorBundle.getString("starButtonOn.tooltip"));
|
2007-09-21 11:18:34 -07:00
|
|
|
}
|
|
|
|
else {
|
2007-08-17 00:22:12 -07:00
|
|
|
starIcon.removeAttribute("starred");
|
2009-07-13 15:10:04 -07:00
|
|
|
starIcon.setAttribute("tooltiptext", gNavigatorBundle.getString("starButtonOff.tooltip"));
|
2007-09-21 11:18:34 -07:00
|
|
|
}
|
2007-08-15 18:15:50 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onClick: function PSB_onClick(aEvent) {
|
2007-12-01 13:04:09 -08: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-15 18:15:50 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// nsINavBookmarkObserver
|
|
|
|
onBeginUpdateBatch: function PSB_onBeginUpdateBatch() {
|
|
|
|
this._batching = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
onEndUpdateBatch: function PSB_onEndUpdateBatch() {
|
|
|
|
this.updateState();
|
|
|
|
this._batching = false;
|
|
|
|
},
|
|
|
|
|
2009-10-01 09:53:26 -07:00
|
|
|
onItemAdded: function PSB_onItemAdded(aItemId, aFolder, aIndex, aItemType) {
|
2007-08-15 18:15:50 -07:00
|
|
|
if (!this._batching && !this._starred)
|
|
|
|
this.updateState();
|
|
|
|
},
|
|
|
|
|
2009-10-01 09:53:26 -07:00
|
|
|
onBeforeItemRemoved: function() {},
|
2009-03-19 12:56:51 -07:00
|
|
|
|
2009-10-01 09:53:26 -07:00
|
|
|
onItemRemoved: function PSB_onItemRemoved(aItemId, aFolder, aIndex,
|
|
|
|
aItemType) {
|
2007-08-15 18:15:50 -07:00
|
|
|
if (!this._batching)
|
|
|
|
this.updateState();
|
|
|
|
},
|
|
|
|
|
|
|
|
onItemChanged: function PSB_onItemChanged(aItemId, aProperty,
|
2009-10-01 09:53:26 -07:00
|
|
|
aIsAnnotationProperty, aNewValue,
|
|
|
|
aLastModified, aItemType) {
|
2007-08-15 18:15:50 -07:00
|
|
|
if (!this._batching && aProperty == "uri")
|
|
|
|
this.updateState();
|
|
|
|
},
|
|
|
|
|
|
|
|
onItemVisited: function() { },
|
|
|
|
onItemMoved: function() { }
|
|
|
|
};
|
2010-05-05 06:28:04 -07:00
|
|
|
|
|
|
|
// This object handles the initlization and uninitlization of the bookmarks
|
|
|
|
// toolbar. updateState is called when the browser window is opened and
|
|
|
|
// after closing the toolbar customization dialog.
|
|
|
|
let PlacesToolbarHelper = {
|
|
|
|
_place: "place:folder=TOOLBAR",
|
|
|
|
_cachedElt: null,
|
|
|
|
|
|
|
|
onBrowserWindowClose: function PTH_onBrowserWindowClose() {
|
|
|
|
if (this._cachedElt)
|
|
|
|
this._cachedElt._placesView.uninit();
|
|
|
|
},
|
|
|
|
|
|
|
|
updateState: function PTH_updateState() {
|
|
|
|
let currentElt = document.getElementById("PlacesToolbar");
|
|
|
|
|
|
|
|
// Bail out if the state has not changed.
|
|
|
|
if (currentElt == this._cachedElt)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!this._cachedElt) {
|
|
|
|
// The toolbar has been added.
|
|
|
|
new PlacesToolbar(this._place);
|
|
|
|
this._cachedElt = currentElt;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// The toolbar has been removed.
|
|
|
|
this._cachedElt._placesView.uninit();
|
|
|
|
this._cachedElt = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|