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>
|
|
|
|
#
|
|
|
|
# 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);
|
2007-10-30 18:16:46 -07:00
|
|
|
element.addEventListener("keypress", this, true);
|
|
|
|
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)
|
|
|
|
gEditItemOverlay.uninitPanel(true);
|
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) {
|
|
|
|
PlacesUtils.ptm.endBatch();
|
|
|
|
this._batching = false;
|
|
|
|
}
|
2007-08-30 09:13:33 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "keypress":
|
2008-01-29 20:37:41 -08:00
|
|
|
if (aEvent.keyCode == KeyEvent.DOM_VK_ESCAPE) {
|
|
|
|
// In edit mode, the ESC key is mapped to the cancel button
|
|
|
|
if (!this._element("editBookmarkPanelContent").hidden)
|
|
|
|
this.cancelButtonOnCommand();
|
|
|
|
else // otherwise we just hide the panel
|
|
|
|
this.panel.hidePopup();
|
|
|
|
}
|
|
|
|
else if (aEvent.keyCode == KeyEvent.DOM_VK_RETURN)
|
2008-01-23 15:49:10 -08:00
|
|
|
this.panel.hidePopup(); // hide the panel
|
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) {
|
|
|
|
// scripts within the overlay are compiled after this is called :(
|
|
|
|
setTimeout(function(aSelf) {
|
|
|
|
aSelf._self._overlayLoading = false;
|
|
|
|
aSelf._self._overlayLoaded = true;
|
|
|
|
aSelf._self._doShowEditBookmarkPanel(aItemId, aSelf._anchorElement,
|
|
|
|
aSelf._position);
|
|
|
|
}, 0, this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
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) {
|
2007-08-30 09:13:33 -07:00
|
|
|
this._blockCommands(); // un-done in the popuphiding handler
|
2007-10-30 18:16:46 -07:00
|
|
|
|
2008-01-29 22:46:45 -08:00
|
|
|
var bundle = this._element("bundle_browser");
|
2007-08-17 00:22:12 -07:00
|
|
|
|
2008-01-29 22:46:45 -08:00
|
|
|
// "Page Bookmarked" title
|
|
|
|
this._element("editBookmarkPanelTitle").value =
|
|
|
|
bundle.getString("editBookmarkPanel.pageBookmarkedTitle");
|
|
|
|
|
2008-01-30 13:19:39 -08:00
|
|
|
// No description; show the Done, Cancel;
|
|
|
|
// hide the Edit, Undo buttons
|
2008-01-29 22:46:45 -08:00
|
|
|
this._element("editBookmarkPanelDescription").textContent = "";
|
|
|
|
this._element("editBookmarkPanelBottomButtons").hidden = false;
|
|
|
|
this._element("editBookmarkPanelContent").hidden = false;
|
|
|
|
this._element("editBookmarkPanelEditButton").hidden = true;
|
|
|
|
this._element("editBookmarkPanelUndoRemoveButton").hidden = true;
|
|
|
|
|
2008-01-30 13:19:39 -08:00
|
|
|
// 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-01-29 22:46:45 -08:00
|
|
|
// unset the unstarred state, if set
|
|
|
|
this._element("editBookmarkPanelStarIcon").removeAttribute("unstarred");
|
|
|
|
|
|
|
|
this._itemId = aItemId !== undefined ? aItemId : this._itemId;
|
2008-01-30 13:19:39 -08:00
|
|
|
this.beginBatch();
|
2008-01-29 22:46:45 -08:00
|
|
|
|
|
|
|
// XXXmano hack: We push a no-op transaction on the stack so it's always
|
|
|
|
// safe for the Cancel button to call undoTransaction after endBatch.
|
|
|
|
// Otherwise, if no changes were done in the edit-item panel, the last
|
|
|
|
// transaction on the undo stack may be the initial createItem transaction,
|
|
|
|
// or worse, the batched editing of some other item.
|
|
|
|
PlacesUtils.ptm.doTransaction({ doTransaction: function() { },
|
|
|
|
undoTransaction: function() { },
|
|
|
|
redoTransaction: function() { },
|
|
|
|
isTransient: false,
|
|
|
|
merge: function() { return false; } });
|
|
|
|
|
|
|
|
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 {
|
|
|
|
var namePicker = this._element("editBMPanel_namePicker");
|
|
|
|
namePicker.focus();
|
|
|
|
namePicker.editor.selectAll();
|
|
|
|
}
|
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) {
|
|
|
|
var namePicker = this._element("editBMPanel_namePicker");
|
|
|
|
namePicker.focus();
|
|
|
|
namePicker.editor.selectAll();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
this.panel.focus();
|
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 bundle = this._element("bundle_browser");
|
|
|
|
var brandBundle = this._element("bundle_brand");
|
|
|
|
var brandShortName = brandBundle.getString("brandShortName");
|
|
|
|
|
|
|
|
// "Page Bookmarked" title
|
|
|
|
this._element("editBookmarkPanelTitle").value =
|
|
|
|
bundle.getString("editBookmarkPanel.pageBookmarkedTitle");
|
|
|
|
|
|
|
|
// description
|
|
|
|
this._element("editBookmarkPanelDescription").textContent =
|
|
|
|
bundle.getFormattedString("editBookmarkPanel.pageBookmarkedDescription",
|
|
|
|
[brandShortName]);
|
|
|
|
|
|
|
|
// hide the edit panel and the buttons below to it (Cancel, Done)
|
|
|
|
this._element("editBookmarkPanelContent").hidden = true;
|
|
|
|
this._element("editBookmarkPanelBottomButtons").hidden = true;
|
|
|
|
|
|
|
|
// 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
|
|
|
},
|
|
|
|
|
|
|
|
editButtonCommand: function SU_editButtonCommand() {
|
|
|
|
this.showEditBookmarkPopup();
|
|
|
|
},
|
|
|
|
|
|
|
|
cancelButtonOnCommand: function SU_cancelButtonOnCommand() {
|
2008-01-30 13:19:39 -08:00
|
|
|
this.endBatch();
|
2008-01-29 22:46:45 -08:00
|
|
|
PlacesUtils.ptm.undoTransaction();
|
|
|
|
this.panel.hidePopup();
|
|
|
|
},
|
|
|
|
|
|
|
|
removeBookmarkButtonCommand: function SU_removeBookmarkButtonCommand() {
|
|
|
|
// 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) {
|
|
|
|
PlacesUtils.ptm.endBatch();
|
|
|
|
PlacesUtils.ptm.beginBatch(); // allow undo from within the notification
|
|
|
|
var bundle = this._element("bundle_browser");
|
|
|
|
|
|
|
|
// "Bookmark Removed" title (the description field is already empty in
|
|
|
|
// this mode)
|
|
|
|
this._element("editBookmarkPanelTitle").value =
|
|
|
|
bundle.getString("editBookmarkPanel.bookmarkedRemovedTitle");
|
|
|
|
// hide the edit fields, the buttons below to and the remove bookmark
|
|
|
|
// button. Show the undo-remove-bookmark button.
|
|
|
|
this._element("editBookmarkPanelContent").hidden = true;
|
|
|
|
this._element("editBookmarkPanelBottomButtons").hidden = true;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// 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++) {
|
|
|
|
var txn = PlacesUtils.ptm.removeItem(itemIds[i]);
|
|
|
|
PlacesUtils.ptm.doTransaction(txn);
|
|
|
|
}
|
2008-01-29 22:46:45 -08:00
|
|
|
|
|
|
|
// hidePopup resets our itemId, thus we call it only after removing
|
|
|
|
// the bookmark
|
|
|
|
if (!this._batching)
|
|
|
|
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-01-29 22:46:45 -08:00
|
|
|
PlacesUtils.ptm.undoTransaction();
|
|
|
|
this._itemId = PlacesUtils.getMostRecentBookmarkForURI(this._uri);
|
|
|
|
this.showEditBookmarkPopup();
|
2008-01-30 13:19:39 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
beginBatch: function SU_beginBatch() {
|
|
|
|
if (!this._batching) {
|
|
|
|
PlacesUtils.ptm.beginBatch();
|
|
|
|
this._batching = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
endBatch: function SU_endBatch() {
|
|
|
|
if (this._batching) {
|
|
|
|
PlacesUtils.ptm.endBatch();
|
|
|
|
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;
|
|
|
|
try {
|
2007-12-14 16:24:09 -08:00
|
|
|
title = webNav.document.title || url.spec;
|
2007-08-17 00:22:12 -07:00
|
|
|
description = PlacesUtils.getDescriptionFromDocument(webNav.document);
|
|
|
|
}
|
|
|
|
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;
|
2007-08-17 00:22:12 -07:00
|
|
|
var descAnno = { name: DESCRIPTION_ANNO, value: description };
|
2007-08-28 14:47:43 -07:00
|
|
|
var txn = PlacesUtils.ptm.createItem(uri, parent, -1,
|
2007-08-17 00:22:12 -07:00
|
|
|
title, null, [descAnno]);
|
2007-12-02 12:08:23 -08:00
|
|
|
PlacesUtils.ptm.doTransaction(txn);
|
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-01-29 20:37:41 -08:00
|
|
|
// dock the panel to the star icon when possible, otherwise dock
|
|
|
|
// it to the content area
|
|
|
|
if (aBrowser.contentWindow == window.content) {
|
|
|
|
var starIcon = aBrowser.ownerDocument.getElementById("star-button");
|
|
|
|
if (starIcon && isElementVisible(starIcon)) {
|
|
|
|
if (aShowEditUI)
|
|
|
|
StarUI.showEditBookmarkPopup(itemId, starIcon, "after_end");
|
|
|
|
else
|
|
|
|
StarUI.showPageBookmarkedNotification(itemId, starIcon, "after_end");
|
|
|
|
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) {
|
2007-11-13 08:30:58 -08:00
|
|
|
this.bookmarkPage(getBrowser().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) {
|
|
|
|
var linkURI = IO.newURI(aURL)
|
2007-08-17 00:22:12 -07:00
|
|
|
var itemId = PlacesUtils.getMostRecentBookmarkForURI(linkURI);
|
|
|
|
if (itemId == -1) {
|
2007-08-28 14:47:43 -07:00
|
|
|
var txn = PlacesUtils.ptm.createItem(linkURI, aParent, -1, aTitle);
|
2007-12-14 10:04:38 -08:00
|
|
|
PlacesUtils.ptm.doTransaction(txn);
|
2007-08-17 00:22:12 -07:00
|
|
|
itemId = PlacesUtils.getMostRecentBookmarkForURI(linkURI);
|
2008-01-30 13:19:39 -08:00
|
|
|
StarUI.beginBatch();
|
2007-08-17 00:22:12 -07:00
|
|
|
}
|
|
|
|
|
2008-01-30 13:19:39 -08:00
|
|
|
StarUI.showEditBookmarkPopup(itemId, getBrowser(), "overlap");
|
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 = [];
|
|
|
|
var seenURIs = [];
|
|
|
|
|
|
|
|
var browsers = getBrowser().browsers;
|
|
|
|
for (var i = 0; i < browsers.length; ++i) {
|
|
|
|
var webNav = browsers[i].webNavigation;
|
|
|
|
var uri = webNav.currentURI;
|
|
|
|
|
|
|
|
// skip redundant entries
|
|
|
|
if (uri.spec in seenURIs)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// add to the set of seen URIs
|
|
|
|
seenURIs[uri.spec] = true;
|
|
|
|
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();
|
2007-03-26 17:52:59 -07:00
|
|
|
PlacesUtils.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) {
|
|
|
|
var ios =
|
|
|
|
Cc["@mozilla.org/network/io-service;1"].
|
|
|
|
getService(Ci.nsIIOService);
|
|
|
|
var feedURI = ios.newURI(url, null, null);
|
|
|
|
|
|
|
|
var doc = gBrowser.contentDocument;
|
|
|
|
var title = (arguments.length > 1) ? feedTitle : doc.title;
|
|
|
|
|
|
|
|
var description;
|
|
|
|
if (arguments.length > 2)
|
|
|
|
description = feedSubtitle;
|
|
|
|
else
|
|
|
|
description = PlacesUtils.getDescriptionFromDocument(doc);
|
|
|
|
|
|
|
|
var toolbarIP =
|
|
|
|
new InsertionPoint(PlacesUtils.bookmarks.toolbarFolder, -1);
|
2007-03-26 17:52:59 -07:00
|
|
|
PlacesUtils.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) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
|
|
|
|
getService(Ci.nsIWindowMediator);
|
|
|
|
var organizer = wm.getMostRecentWindow("Places:Organizer");
|
|
|
|
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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Functions for the history menu.
|
|
|
|
var HistoryMenu = {
|
|
|
|
/**
|
|
|
|
* popupshowing handler for the history menu.
|
|
|
|
* @param aMenuPopup
|
|
|
|
* XULNode for the history menupopup
|
|
|
|
*/
|
2007-06-15 10:00:08 -07:00
|
|
|
onPopupShowing: function PHM_onPopupShowing(aMenuPopup) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var resultNode = aMenuPopup.getResultNode();
|
|
|
|
var wasOpen = resultNode.containerOpen;
|
|
|
|
resultNode.containerOpen = true;
|
|
|
|
document.getElementById("endHistorySeparator").hidden =
|
|
|
|
resultNode.childCount == 0;
|
|
|
|
|
|
|
|
if (!wasOpen)
|
|
|
|
resultNode.containerOpen = false;
|
|
|
|
|
|
|
|
// HistoryMenu.toggleRecentlyClosedTabs is defined in browser.js
|
|
|
|
this.toggleRecentlyClosedTabs();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
* Only handle middle-click; left-click is handled in the onCommand function.
|
|
|
|
* When items are middle-clicked, open them in tabs.
|
|
|
|
* If the click came through a menu, close the menu.
|
|
|
|
* @param aEvent
|
|
|
|
* DOMEvent for the click
|
|
|
|
*/
|
|
|
|
onClick: function BT_onClick(aEvent) {
|
|
|
|
// Only handle middle-clicks.
|
|
|
|
if (aEvent.button != 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var target = aEvent.originalTarget;
|
|
|
|
var view = PlacesUtils.getViewForNode(target);
|
|
|
|
if (PlacesUtils.nodeIsFolder(view.selectedNode)) {
|
|
|
|
// Don't open the root folder in tabs when the empty area on the toolbar
|
2007-09-02 12:03:24 -07:00
|
|
|
// is middle-clicked or when a non-bookmark item except for Open in Tabs)
|
|
|
|
// in a bookmarks menupopup is middle-clicked.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!view.controller.rootNodeIsSelected())
|
2007-09-02 12:03:24 -07:00
|
|
|
view.controller.openSelectionInTabs(aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
this.onCommand(aEvent);
|
|
|
|
|
|
|
|
// If this event bubbled up from a menu or menuitem,
|
|
|
|
// close the menus.
|
|
|
|
if (target.localName == "menu" ||
|
|
|
|
target.localName == "menuitem") {
|
|
|
|
var node = target.parentNode;
|
|
|
|
while (node &&
|
|
|
|
(node.localName == "menu" ||
|
|
|
|
node.localName == "menupopup")) {
|
|
|
|
if (node.localName == "menupopup")
|
|
|
|
node.hidePopup();
|
2007-10-24 19:02:28 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
node = node.parentNode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// The event target we get if someone middle clicks on a bookmark in the
|
|
|
|
// bookmarks toolbar overflow menu is different from if they click on a
|
|
|
|
// bookmark in a folder or in the bookmarks menu; handle this case
|
|
|
|
// separately.
|
|
|
|
var bookmarksBar = document.getElementById("bookmarksBarContent");
|
|
|
|
if (bookmarksBar._chevron.getAttribute("open") == "true")
|
2007-10-24 19:02:28 -07:00
|
|
|
bookmarksBar._chevron.firstChild.hidePopup();
|
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;
|
2007-10-24 19:02:28 -07:00
|
|
|
if (target.node) {
|
2007-03-22 10:30:00 -07:00
|
|
|
PlacesUtils.getViewForNode(target)
|
|
|
|
.controller
|
|
|
|
.openSelectedNodeWithEvent(aEvent);
|
2007-10-24 19:02:28 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for popupshowing event for an item in bookmarks toolbar or menu.
|
|
|
|
* If the item isn't the main bookmarks menu, add an "Open All in Tabs"
|
|
|
|
* menuitem to the bottom of the popup.
|
|
|
|
* @param event
|
|
|
|
* DOMEvent for popupshowing
|
|
|
|
*/
|
|
|
|
onPopupShowing: function BM_onPopupShowing(event) {
|
2007-06-05 16:26:26 -07:00
|
|
|
var target = event.originalTarget;
|
|
|
|
if (target.localName == "menupopup" &&
|
|
|
|
target.id != "bookmarksMenuPopup" &&
|
|
|
|
target.getAttribute("anonid") != "chevronPopup") {
|
2007-06-15 18:53:06 -07:00
|
|
|
// Add the "Open All in Tabs" menuitem if there are
|
|
|
|
// at least two menuitems with places result nodes.
|
|
|
|
// Add the "Open (Feed Name)" menuitem if it's a livemark with a siteURI.
|
2007-03-22 10:30:00 -07:00
|
|
|
var numNodes = 0;
|
|
|
|
var hasMultipleEntries = false;
|
|
|
|
var currentChild = target.firstChild;
|
2007-06-15 18:53:06 -07:00
|
|
|
while (currentChild) {
|
|
|
|
if (currentChild.localName == "menuitem" && currentChild.node)
|
2007-03-22 10:30:00 -07:00
|
|
|
numNodes++;
|
2007-06-15 18:53:06 -07:00
|
|
|
|
|
|
|
// If the menuitem already exists, do nothing.
|
|
|
|
if (currentChild.getAttribute("openInTabs") == "true")
|
|
|
|
return;
|
|
|
|
if (currentChild.hasAttribute("siteURI"))
|
|
|
|
return;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
currentChild = currentChild.nextSibling;
|
|
|
|
}
|
|
|
|
if (numNodes > 1)
|
|
|
|
hasMultipleEntries = true;
|
2007-06-15 18:53:06 -07:00
|
|
|
|
2007-10-24 19:02:28 -07:00
|
|
|
var itemId = target._resultNode.itemId;
|
|
|
|
var siteURIString = "";
|
|
|
|
if (itemId != -1 && PlacesUtils.livemarks.isLivemark(itemId)) {
|
|
|
|
var siteURI = PlacesUtils.livemarks.getSiteURI(itemId);
|
|
|
|
if (siteURI)
|
|
|
|
siteURIString = siteURI.spec;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-10-24 19:02:28 -07:00
|
|
|
if (hasMultipleEntries || siteURIString) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var separator = document.createElement("menuseparator");
|
|
|
|
target.appendChild(separator);
|
|
|
|
|
2007-10-24 19:02:28 -07:00
|
|
|
if (siteURIString) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var openHomePage = document.createElement("menuitem");
|
2007-10-24 19:02:28 -07:00
|
|
|
openHomePage.setAttribute("siteURI", siteURIString);
|
|
|
|
openHomePage.setAttribute("oncommand",
|
2007-12-16 13:52:45 -08:00
|
|
|
"openUILink(this.getAttribute('siteURI'), event);");
|
2007-12-16 13:53:40 -08:00
|
|
|
// If a user middle-clicks this item we serve the oncommand event
|
2007-12-16 13:52:45 -08:00
|
|
|
// We are using checkForMiddleClick because of Bug 246720
|
|
|
|
// Note: stopPropagation is needed to avoid serving middle-click
|
|
|
|
// with BT_onClick that would open all items in tabs
|
|
|
|
openHomePage.setAttribute("onclick",
|
|
|
|
"checkForMiddleClick(this, event); event.stopPropagation();");
|
|
|
|
openHomePage.setAttribute("label",
|
|
|
|
PlacesUtils.getFormattedString("menuOpenLivemarkOrigin.label",
|
|
|
|
[target.parentNode.getAttribute("label")]));
|
2007-03-22 10:30:00 -07:00
|
|
|
target.appendChild(openHomePage);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasMultipleEntries) {
|
|
|
|
var openInTabs = document.createElement("menuitem");
|
|
|
|
openInTabs.setAttribute("openInTabs", "true");
|
2007-09-02 12:03:24 -07:00
|
|
|
openInTabs.setAttribute("oncommand",
|
2007-10-24 19:02:28 -07:00
|
|
|
"PlacesUtils.openContainerNodeInTabs(this.parentNode._resultNode, event);");
|
2007-03-22 10:30:00 -07:00
|
|
|
openInTabs.setAttribute("label",
|
|
|
|
gNavigatorBundle.getString("menuOpenAllInTabs.label"));
|
|
|
|
target.appendChild(openInTabs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
fillInBTTooltip: function(aTipElement) {
|
|
|
|
// Fx2XP: Don't show tooltips for bookmarks under sub-folders
|
|
|
|
if (aTipElement.localName != "toolbarbutton")
|
|
|
|
return false;
|
|
|
|
|
2007-06-12 08:34:02 -07:00
|
|
|
// Fx2XP: Only show tooltips for URL items
|
|
|
|
if (!PlacesUtils.nodeIsURI(aTipElement.node))
|
|
|
|
return false;
|
|
|
|
|
2007-05-30 09:17:34 -07:00
|
|
|
var url = aTipElement.node.uri;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!url)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
var tooltipUrl = document.getElementById("btUrlText");
|
|
|
|
tooltipUrl.value = url;
|
|
|
|
|
|
|
|
var title = aTipElement.label;
|
|
|
|
var tooltipTitle = document.getElementById("btTitleText");
|
|
|
|
if (title && title != url) {
|
|
|
|
tooltipTitle.hidden = false;
|
|
|
|
tooltipTitle.value = title;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
tooltipTitle.hidden = true;
|
|
|
|
|
|
|
|
// show tooltip
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Drag and Drop handling specifically for the Bookmarks Menu item in the
|
|
|
|
* top level menu bar
|
|
|
|
*/
|
|
|
|
var BookmarksMenuDropHandler = {
|
|
|
|
/**
|
|
|
|
* Need to tell the session to update the state of the cursor as we drag
|
|
|
|
* over the Bookmarks Menu to show the "can drop" state vs. the "no drop"
|
|
|
|
* state.
|
|
|
|
*/
|
|
|
|
onDragOver: function BMDH_onDragOver(event, flavor, session) {
|
|
|
|
session.canDrop = this.canDrop(event, session);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Advertises the set of data types that can be dropped on the Bookmarks
|
|
|
|
* Menu
|
|
|
|
* @returns a FlavourSet object per nsDragAndDrop parlance.
|
|
|
|
*/
|
|
|
|
getSupportedFlavours: function BMDH_getSupportedFlavours() {
|
|
|
|
var flavorSet = new FlavourSet();
|
|
|
|
var view = document.getElementById("bookmarksMenuPopup");
|
2008-01-29 12:04:43 -08:00
|
|
|
var types = PlacesUtils.GENERIC_VIEW_DROP_TYPES
|
|
|
|
for (var i = 0; i < types.length; ++i)
|
|
|
|
flavorSet.appendFlavour(types[i]);
|
2007-03-22 10:30:00 -07:00
|
|
|
return flavorSet;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether or not the user can drop on the Bookmarks Menu.
|
|
|
|
* @param event
|
|
|
|
* A dragover event
|
|
|
|
* @param session
|
|
|
|
* The active DragSession
|
|
|
|
* @returns true if the user can drop onto the Bookmarks Menu item, false
|
|
|
|
* otherwise.
|
|
|
|
*/
|
|
|
|
canDrop: function BMDH_canDrop(event, session) {
|
|
|
|
var view = document.getElementById("bookmarksMenuPopup");
|
|
|
|
return PlacesControllerDragHelper.canDrop(view, -1);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the user drops onto the top level Bookmarks Menu item.
|
|
|
|
* @param event
|
|
|
|
* A drop event
|
|
|
|
* @param data
|
|
|
|
* Data that was dropped
|
|
|
|
* @param session
|
|
|
|
* The active DragSession
|
|
|
|
*/
|
|
|
|
onDrop: function BMDH_onDrop(event, data, session) {
|
|
|
|
var view = document.getElementById("bookmarksMenuPopup");
|
2008-01-09 09:00:15 -08:00
|
|
|
// Put the item at the end of bookmark menu
|
|
|
|
var ip = new InsertionPoint(PlacesUtils.bookmarksMenuFolderId, -1);
|
2008-01-29 12:04:43 -08:00
|
|
|
PlacesControllerDragHelper.onDrop(view, ip);
|
2007-03-22 10:30:00 -07:00
|
|
|
view._rebuild();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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]);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When the user drags out of the Bookmarks Menu or Toolbar, set a timer to
|
|
|
|
* manually close the popup chain that was dragged out of. We need to do this
|
|
|
|
* since the global popup dismissal listener does not handle multiple extant
|
|
|
|
* popup chains well. See bug 332845 for more information.
|
|
|
|
*/
|
|
|
|
onDragExit: function PMDC_onDragExit(event) {
|
|
|
|
// Ensure that we don't set multiple timers if there's one already set.
|
|
|
|
if ("closeTime" in this._timers)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._setDragTimer("closeTime", this._closePopups,
|
|
|
|
this._springLoadDelay, [event.target]);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
|
|
|
return node.localName == "menu" ||
|
|
|
|
node.localName == "toolbarbutton" && node.getAttribute("type") == "menu";
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close all pieces of toplevel menu UI in the browser window. Called in
|
|
|
|
* circumstances where there may be multiple chains of menupopups, e.g.
|
|
|
|
* during drag and drop operations between menus, and in context menu-on-
|
|
|
|
* menu situations.
|
|
|
|
*/
|
|
|
|
_closePopups: function PMDC__closePopups(target) {
|
|
|
|
if (PlacesControllerDragHelper.draggingOverChildNode(target))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ("closeTime" in this._timers)
|
|
|
|
delete this._timers.closeTime;
|
|
|
|
|
|
|
|
// Close the bookmarks menu
|
|
|
|
var bookmarksMenu = document.getElementById("bookmarksMenu");
|
2007-10-24 19:02:28 -07:00
|
|
|
bookmarksMenu.firstChild.hidePopup();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
var bookmarksBar = document.getElementById("bookmarksBarContent");
|
|
|
|
if (bookmarksBar) {
|
|
|
|
// Close the overflow chevron menu and all its children
|
2007-10-24 19:02:28 -07:00
|
|
|
bookmarksBar._chevron.firstChild.hidePopup();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Close all popups on the bookmarks toolbar
|
|
|
|
var toolbarItems = bookmarksBar.childNodes;
|
|
|
|
for (var i = 0; i < toolbarItems.length; ++i) {
|
|
|
|
var item = toolbarItems[i]
|
|
|
|
if (this._isContainer(item))
|
2007-10-24 19:02:28 -07:00
|
|
|
item.firstChild.hidePopup();
|
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.
|
|
|
|
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() {
|
|
|
|
PlacesUtils.bookmarks.addObserver(this, false);
|
|
|
|
},
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2007-09-21 11:18:34 -07:00
|
|
|
var browserBundle = document.getElementById("bundle_browser");
|
2007-08-15 18:15:50 -07:00
|
|
|
var uri = getBrowser().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");
|
2007-09-21 11:18:34 -07:00
|
|
|
starIcon.setAttribute("tooltiptext", browserBundle.getString("starButtonOn.tooltip"));
|
|
|
|
}
|
|
|
|
else {
|
2007-08-17 00:22:12 -07:00
|
|
|
starIcon.removeAttribute("starred");
|
2007-09-21 11:18:34 -07:00
|
|
|
starIcon.setAttribute("tooltiptext", browserBundle.getString("starButtonOff.tooltip"));
|
|
|
|
}
|
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;
|
|
|
|
},
|
|
|
|
|
|
|
|
onItemAdded: function PSB_onItemAdded(aItemId, aFolder, aIndex) {
|
|
|
|
if (!this._batching && !this._starred)
|
|
|
|
this.updateState();
|
|
|
|
},
|
|
|
|
|
|
|
|
onItemRemoved: function PSB_onItemRemoved(aItemId, aFolder, aIndex) {
|
|
|
|
if (!this._batching)
|
|
|
|
this.updateState();
|
|
|
|
},
|
|
|
|
|
|
|
|
onItemChanged: function PSB_onItemChanged(aItemId, aProperty,
|
|
|
|
aIsAnnotationProperty, aValue) {
|
|
|
|
if (!this._batching && aProperty == "uri")
|
|
|
|
this.updateState();
|
|
|
|
},
|
|
|
|
|
|
|
|
onItemVisited: function() { },
|
|
|
|
onItemMoved: function() { }
|
|
|
|
};
|
2007-12-04 17:56:55 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Various migration tasks.
|
|
|
|
*/
|
|
|
|
function placesMigrationTasks() {
|
|
|
|
// bug 398914 - move all post-data annotations from URIs to bookmarks
|
|
|
|
// XXX - REMOVE ME FOR BETA 3 (bug 391419)
|
|
|
|
if (gPrefService.getBoolPref("browser.places.migratePostDataAnnotations")) {
|
|
|
|
const annosvc = PlacesUtils.annotations;
|
|
|
|
const bmsvc = PlacesUtils.bookmarks;
|
|
|
|
const oldPostDataAnno = "URIProperties/POSTData";
|
|
|
|
var pages = annosvc.getPagesWithAnnotation(oldPostDataAnno, {});
|
|
|
|
for (let i = 0; i < pages.length; i++) {
|
|
|
|
try {
|
|
|
|
let uri = pages[i];
|
|
|
|
var postData = annosvc.getPageAnnotation(uri, oldPostDataAnno);
|
|
|
|
// We can't know which URI+keyword combo this postdata was for, but
|
|
|
|
// it's very likely that if this URI is bookmarked and has a keyword
|
|
|
|
// *and* the URI has postdata, then this bookmark was using the
|
|
|
|
// postdata. Propagate the annotation to all bookmarks for this URI
|
|
|
|
// just to be safe.
|
|
|
|
let bookmarks = bmsvc.getBookmarkIdsForURI(uri, {});
|
|
|
|
for (let i = 0; i < bookmarks.length; i++) {
|
|
|
|
var keyword = bmsvc.getKeywordForBookmark(bookmarks[i]);
|
|
|
|
if (keyword)
|
|
|
|
annosvc.setItemAnnotation(bookmarks[i], POST_DATA_ANNO, postData, 0, annosvc.EXPIRE_NEVER);
|
|
|
|
}
|
|
|
|
// Remove the old annotation.
|
|
|
|
annosvc.removePageAnnotation(uri, oldPostDataAnno);
|
|
|
|
} catch(ex) {}
|
|
|
|
}
|
|
|
|
gPrefService.setBoolPref("browser.places.migratePostDataAnnotations", false);
|
|
|
|
}
|
|
|
|
}
|