2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Places Command Controller.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Google Inc.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2005
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Ben Goodger <beng@google.com>
|
|
|
|
* Myk Melez <myk@mozilla.org>
|
|
|
|
* Asaf Romano <mano@mozilla.com>
|
2008-09-19 08:47:45 -07:00
|
|
|
* Marco Bonardo <mak77@bonardo.net>
|
2007-03-22 10:30:00 -07: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 16:43:56 -07:00
|
|
|
// XXXmano: we should move most/all of these constants to PlacesUtils
|
2008-03-15 12:39:04 -07:00
|
|
|
const ORGANIZER_ROOT_BOOKMARKS = "place:folder=BOOKMARKS_MENU&excludeItems=1&queryType=1";
|
2007-04-09 17:30:52 -07:00
|
|
|
const ORGANIZER_SUBSCRIPTIONS_QUERY = "place:annotation=livemark%2FfeedURI";
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// No change to the view, preserve current selection
|
|
|
|
const RELOAD_ACTION_NOTHING = 0;
|
|
|
|
// Inserting items new to the view, select the inserted rows
|
|
|
|
const RELOAD_ACTION_INSERT = 1;
|
|
|
|
// Removing items from the view, select the first item after the last selected
|
|
|
|
const RELOAD_ACTION_REMOVE = 2;
|
|
|
|
// Moving items within a view, don't treat the dropped items as additional
|
|
|
|
// rows.
|
|
|
|
const RELOAD_ACTION_MOVE = 3;
|
|
|
|
|
2008-01-31 19:03:14 -08:00
|
|
|
// when removing a bunch of pages we split them in chunks to avoid passing
|
|
|
|
// a too big array to RemovePages
|
|
|
|
// 300 is the best choice with an history of about 150000 visits
|
|
|
|
// smaller chunks could cause a Slow Script warning with a huge history
|
|
|
|
const REMOVE_PAGES_CHUNKLEN = 300;
|
|
|
|
// if we are removing less than this pages we will remove them one by one
|
|
|
|
// since it will be reflected faster on the UI
|
|
|
|
// 10 is a good compromise, since allows the user to delete a little amount of
|
|
|
|
// urls for privacy reasons, but does not cause heavy disk access
|
|
|
|
const REMOVE_PAGES_MAX_SINGLEREMOVES = 10;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Represents an insertion point within a container where we can insert
|
|
|
|
* items.
|
2007-05-14 14:56:38 -07:00
|
|
|
* @param aItemId
|
|
|
|
* The identifier of the parent container
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param aIndex
|
|
|
|
* The index within the container where we should insert
|
|
|
|
* @param aOrientation
|
|
|
|
* The orientation of the insertion. NOTE: the adjustments to the
|
|
|
|
* insertion point to accommodate the orientation should be done by
|
|
|
|
* the person who constructs the IP, not the user. The orientation
|
|
|
|
* is provided for informational purposes only!
|
2008-04-11 09:22:01 -07:00
|
|
|
* @param [optional] aIsTag
|
|
|
|
* Indicates if parent container is a tag
|
2008-04-25 16:44:10 -07:00
|
|
|
* @param [optional] aDropNearItemId
|
|
|
|
* When defined we will calculate index based on this itemId
|
2007-03-22 10:30:00 -07:00
|
|
|
* @constructor
|
|
|
|
*/
|
2008-04-25 16:44:10 -07:00
|
|
|
function InsertionPoint(aItemId, aIndex, aOrientation, aIsTag,
|
|
|
|
aDropNearItemId) {
|
2007-05-14 14:56:38 -07:00
|
|
|
this.itemId = aItemId;
|
2008-04-25 16:44:10 -07:00
|
|
|
this._index = aIndex;
|
2007-03-22 10:30:00 -07:00
|
|
|
this.orientation = aOrientation;
|
2008-04-11 09:22:01 -07:00
|
|
|
this.isTag = aIsTag;
|
2008-04-25 16:44:10 -07:00
|
|
|
this.dropNearItemId = aDropNearItemId;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-04-25 16:44:10 -07:00
|
|
|
|
|
|
|
InsertionPoint.prototype = {
|
|
|
|
set index(val) {
|
|
|
|
return this._index = val;
|
|
|
|
},
|
|
|
|
|
|
|
|
get index() {
|
|
|
|
if (this.dropNearItemId > 0) {
|
|
|
|
// If dropNearItemId is set up we must calculate the real index of
|
|
|
|
// the item near which we will drop.
|
|
|
|
var index = PlacesUtils.bookmarks.getItemIndex(this.dropNearItemId);
|
|
|
|
return this.orientation == Ci.nsITreeView.DROP_BEFORE ? index : index + 1;
|
|
|
|
}
|
|
|
|
return this._index;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Places Controller
|
|
|
|
*/
|
|
|
|
|
|
|
|
function PlacesController(aView) {
|
|
|
|
this._view = aView;
|
|
|
|
}
|
|
|
|
|
2007-09-19 01:13:20 -07:00
|
|
|
PlacesController.prototype = {
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2007-09-19 01:13:20 -07:00
|
|
|
* The places view.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
_view: null,
|
|
|
|
|
|
|
|
isCommandEnabled: function PC_isCommandEnabled(aCommand) {
|
|
|
|
switch (aCommand) {
|
|
|
|
case "cmd_undo":
|
2008-03-13 12:25:49 -07:00
|
|
|
return PlacesUIUtils.ptm.numberOfUndoItems > 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
case "cmd_redo":
|
2008-03-13 12:25:49 -07:00
|
|
|
return PlacesUIUtils.ptm.numberOfRedoItems > 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
case "cmd_cut":
|
2009-06-10 11:00:30 -07:00
|
|
|
case "placesCmd_cut":
|
2009-04-24 06:11:01 -07:00
|
|
|
var nodes = this._view.getSelectionNodes();
|
|
|
|
// If selection includes history nodes there's no reason to allow cut.
|
|
|
|
for (var i = 0; i < nodes.length; i++) {
|
|
|
|
if (nodes[i].itemId == -1)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Otherwise fallback to cmd_delete check.
|
2007-03-22 10:30:00 -07:00
|
|
|
case "cmd_delete":
|
2009-06-10 11:00:30 -07:00
|
|
|
case "placesCmd_delete":
|
2007-05-29 17:29:54 -07:00
|
|
|
return this._hasRemovableSelection(false);
|
2008-11-05 00:24:22 -08:00
|
|
|
case "placesCmd_deleteDataHost":
|
2009-04-03 11:55:37 -07:00
|
|
|
return this._hasRemovableSelection(false) &&
|
|
|
|
!PlacesUIUtils.privateBrowsing.privateBrowsingEnabled;
|
2007-03-22 10:30:00 -07:00
|
|
|
case "placesCmd_moveBookmarks":
|
2007-05-29 17:29:54 -07:00
|
|
|
return this._hasRemovableSelection(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
case "cmd_copy":
|
2009-06-10 11:00:30 -07:00
|
|
|
case "placesCmd_copy":
|
2007-03-22 16:43:56 -07:00
|
|
|
return this._view.hasSelection;
|
2007-03-22 10:30:00 -07:00
|
|
|
case "cmd_paste":
|
2009-06-10 11:00:30 -07:00
|
|
|
case "placesCmd_paste":
|
2009-03-27 07:31:17 -07:00
|
|
|
return this._canInsert(true) && this._isClipboardDataPasteable();
|
2007-03-22 10:30:00 -07:00
|
|
|
case "cmd_selectAll":
|
|
|
|
if (this._view.selType != "single") {
|
|
|
|
var result = this._view.getResult();
|
|
|
|
if (result) {
|
|
|
|
var container = asContainer(result.root);
|
|
|
|
if (container.childCount > 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
case "placesCmd_open":
|
|
|
|
case "placesCmd_open:window":
|
|
|
|
case "placesCmd_open:tab":
|
2008-02-25 13:45:22 -08:00
|
|
|
var selectedNode = this._view.selectedNode;
|
|
|
|
return selectedNode && PlacesUtils.nodeIsURI(selectedNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
case "placesCmd_new:folder":
|
|
|
|
case "placesCmd_new:livemark":
|
2008-01-29 12:04:43 -08:00
|
|
|
return this._canInsert();
|
2007-03-22 10:30:00 -07:00
|
|
|
case "placesCmd_new:bookmark":
|
2008-01-29 12:04:43 -08:00
|
|
|
return this._canInsert();
|
2007-03-22 10:30:00 -07:00
|
|
|
case "placesCmd_new:separator":
|
2007-03-22 16:43:56 -07:00
|
|
|
return this._canInsert() &&
|
2007-06-18 21:19:39 -07:00
|
|
|
!asQuery(this._view.getResult().root).queryOptions.excludeItems &&
|
|
|
|
this._view.getResult().sortingMode ==
|
|
|
|
Ci.nsINavHistoryQueryOptions.SORT_BY_NONE;
|
2007-03-22 10:30:00 -07:00
|
|
|
case "placesCmd_show:info":
|
2008-02-25 13:45:22 -08:00
|
|
|
var selectedNode = this._view.selectedNode;
|
2009-03-18 07:23:56 -07:00
|
|
|
if (selectedNode &&
|
|
|
|
PlacesUtils.getConcreteItemId(selectedNode) != -1 &&
|
|
|
|
!PlacesUtils.nodeIsLivemarkItem(selectedNode))
|
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
return false;
|
2007-05-31 17:39:09 -07:00
|
|
|
case "placesCmd_reloadMicrosummary":
|
2008-02-25 13:45:22 -08:00
|
|
|
var selectedNode = this._view.selectedNode;
|
|
|
|
return selectedNode && PlacesUtils.nodeIsBookmark(selectedNode) &&
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUIUtils.microsummaries.hasMicrosummary(selectedNode.itemId);
|
2007-03-22 10:30:00 -07:00
|
|
|
case "placesCmd_reload":
|
2008-02-25 13:45:22 -08:00
|
|
|
// Livemark containers
|
|
|
|
var selectedNode = this._view.selectedNode;
|
|
|
|
return selectedNode && PlacesUtils.nodeIsLivemarkContainer(selectedNode);
|
2007-05-11 12:06:57 -07:00
|
|
|
case "placesCmd_sortBy:name":
|
|
|
|
var selectedNode = this._view.selectedNode;
|
|
|
|
return selectedNode &&
|
|
|
|
PlacesUtils.nodeIsFolder(selectedNode) &&
|
2007-07-01 05:23:38 -07:00
|
|
|
!PlacesUtils.nodeIsReadOnly(selectedNode) &&
|
|
|
|
this._view.getResult().sortingMode ==
|
|
|
|
Ci.nsINavHistoryQueryOptions.SORT_BY_NONE;
|
2009-05-11 02:06:06 -07:00
|
|
|
case "placesCmd_createBookmark":
|
|
|
|
var node = this._view.selectedNode;
|
|
|
|
return node && PlacesUtils.nodeIsURI(node) && node.itemId == -1;
|
2007-03-22 10:30:00 -07:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
supportsCommand: function PC_supportsCommand(aCommand) {
|
|
|
|
//LOG("supportsCommand: " + command);
|
|
|
|
// Non-Places specific commands that we also support
|
|
|
|
switch (aCommand) {
|
|
|
|
case "cmd_undo":
|
|
|
|
case "cmd_redo":
|
|
|
|
case "cmd_cut":
|
|
|
|
case "cmd_copy":
|
|
|
|
case "cmd_paste":
|
|
|
|
case "cmd_delete":
|
|
|
|
case "cmd_selectAll":
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// All other Places Commands are prefixed with "placesCmd_" ... this
|
|
|
|
// filters out other commands that we do _not_ support (see 329587).
|
|
|
|
const CMD_PREFIX = "placesCmd_";
|
|
|
|
return (aCommand.substr(0, CMD_PREFIX.length) == CMD_PREFIX);
|
|
|
|
},
|
|
|
|
|
|
|
|
doCommand: function PC_doCommand(aCommand) {
|
|
|
|
switch (aCommand) {
|
|
|
|
case "cmd_undo":
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUIUtils.ptm.undoTransaction();
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case "cmd_redo":
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUIUtils.ptm.redoTransaction();
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case "cmd_cut":
|
2009-06-10 11:00:30 -07:00
|
|
|
case "placesCmd_cut":
|
2007-03-22 10:30:00 -07:00
|
|
|
this.cut();
|
|
|
|
break;
|
|
|
|
case "cmd_copy":
|
2009-06-10 11:00:30 -07:00
|
|
|
case "placesCmd_copy":
|
2007-03-22 10:30:00 -07:00
|
|
|
this.copy();
|
|
|
|
break;
|
|
|
|
case "cmd_paste":
|
2009-06-10 11:00:30 -07:00
|
|
|
case "placesCmd_paste":
|
2007-03-22 10:30:00 -07:00
|
|
|
this.paste();
|
|
|
|
break;
|
|
|
|
case "cmd_delete":
|
2009-06-10 11:00:30 -07:00
|
|
|
case "placesCmd_delete":
|
2007-03-22 10:30:00 -07:00
|
|
|
this.remove("Remove Selection");
|
|
|
|
break;
|
2008-11-05 00:24:22 -08:00
|
|
|
case "placesCmd_deleteDataHost":
|
2009-05-11 02:06:12 -07:00
|
|
|
var host;
|
|
|
|
if (PlacesUtils.nodeIsHost(this._view.selectedNode)) {
|
|
|
|
var queries = this._view.selectedNode.getQueries({});
|
|
|
|
host = queries[0].domain;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
host = PlacesUtils._uri(this._view.selectedNode.uri).host;
|
|
|
|
PlacesUIUtils.privateBrowsing.removeDataFromDomain(host);
|
2008-11-05 00:24:22 -08:00
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
case "cmd_selectAll":
|
|
|
|
this.selectAll();
|
|
|
|
break;
|
|
|
|
case "placesCmd_open":
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUIUtils.openNodeIn(this._view.selectedNode, "current");
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case "placesCmd_open:window":
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUIUtils.openNodeIn(this._view.selectedNode, "window");
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case "placesCmd_open:tab":
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUIUtils.openNodeIn(this._view.selectedNode, "tab");
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case "placesCmd_new:folder":
|
|
|
|
this.newItem("folder");
|
|
|
|
break;
|
|
|
|
case "placesCmd_new:bookmark":
|
|
|
|
this.newItem("bookmark");
|
|
|
|
break;
|
|
|
|
case "placesCmd_new:livemark":
|
|
|
|
this.newItem("livemark");
|
|
|
|
break;
|
|
|
|
case "placesCmd_new:separator":
|
|
|
|
this.newSeparator();
|
|
|
|
break;
|
|
|
|
case "placesCmd_show:info":
|
|
|
|
this.showBookmarkPropertiesForSelection();
|
|
|
|
break;
|
|
|
|
case "placesCmd_moveBookmarks":
|
|
|
|
this.moveSelectedBookmarks();
|
|
|
|
break;
|
|
|
|
case "placesCmd_reload":
|
2007-11-19 18:01:53 -08:00
|
|
|
this.reloadSelectedLivemark();
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2007-05-31 17:39:09 -07:00
|
|
|
case "placesCmd_reloadMicrosummary":
|
|
|
|
this.reloadSelectedMicrosummary();
|
|
|
|
break;
|
2007-05-11 12:06:57 -07:00
|
|
|
case "placesCmd_sortBy:name":
|
|
|
|
this.sortFolderByName();
|
|
|
|
break;
|
2009-05-11 02:06:06 -07:00
|
|
|
case "placesCmd_createBookmark":
|
|
|
|
var node = this._view.selectedNode;
|
|
|
|
PlacesUIUtils.showMinimalAddBookmarkUI(PlacesUtils._uri(node.uri), node.title);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onEvent: function PC_onEvent(eventName) { },
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether or not the selection can be removed, either by the
|
|
|
|
* delete or cut operations based on whether or not any of its contents
|
|
|
|
* are non-removable. We don't need to worry about recursion here since it
|
|
|
|
* is a policy decision that a removable item not be placed inside a non-
|
2007-05-29 17:29:54 -07:00
|
|
|
* removable item.
|
|
|
|
* @param aIsMoveCommand
|
2008-04-25 14:36:40 -07:00
|
|
|
* True if the command for which this method is called only moves the
|
2007-05-29 17:29:54 -07:00
|
|
|
* selected items to another container, false otherwise.
|
2008-04-25 14:36:40 -07:00
|
|
|
* @returns true if all nodes in the selection can be removed,
|
2007-03-22 10:30:00 -07:00
|
|
|
* false otherwise.
|
|
|
|
*/
|
2007-05-29 17:29:54 -07:00
|
|
|
_hasRemovableSelection: function PC__hasRemovableSelection(aIsMoveCommand) {
|
2008-12-13 01:57:30 -08:00
|
|
|
var ranges = this._view.getRemovableSelectionRanges();
|
|
|
|
if (!ranges.length)
|
|
|
|
return false;
|
|
|
|
|
2007-03-25 14:56:52 -07:00
|
|
|
var root = this._view.getResultNode();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-13 01:57:30 -08:00
|
|
|
for (var j = 0; j < ranges.length; j++) {
|
|
|
|
var nodes = ranges[j];
|
|
|
|
for (var i = 0; i < nodes.length; ++i) {
|
|
|
|
// Disallow removing the view's root node
|
|
|
|
if (nodes[i] == root)
|
|
|
|
return false;
|
2007-03-25 14:56:52 -07:00
|
|
|
|
2008-12-13 01:57:30 -08:00
|
|
|
if (PlacesUtils.nodeIsFolder(nodes[i]) &&
|
|
|
|
!PlacesControllerDragHelper.canMoveNode(nodes[i]))
|
|
|
|
return false;
|
2007-03-25 14:56:52 -07:00
|
|
|
|
2008-12-13 01:57:30 -08:00
|
|
|
// We don't call nodeIsReadOnly here, because nodeIsReadOnly means that
|
|
|
|
// a node has children that cannot be edited, reordered or removed. Here,
|
|
|
|
// we don't care if a node's children can't be reordered or edited, just
|
|
|
|
// that they're removable. All history results have removable children
|
|
|
|
// (based on the principle that any URL in the history table should be
|
|
|
|
// removable), but some special bookmark folders may have non-removable
|
|
|
|
// children, e.g. live bookmark folder children. It doesn't make sense
|
|
|
|
// to delete a child of a live bookmark folder, since when the folder
|
|
|
|
// refreshes, the child will return.
|
|
|
|
var parent = nodes[i].parent || root;
|
|
|
|
if (PlacesUtils.isReadonlyFolder(parent))
|
|
|
|
return false;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-12-13 01:57:30 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines whether or not nodes can be inserted relative to the selection.
|
|
|
|
*/
|
2009-03-27 07:31:17 -07:00
|
|
|
_canInsert: function PC__canInsert(isPaste) {
|
2008-04-11 09:22:01 -07:00
|
|
|
var ip = this._view.insertionPoint;
|
2009-03-27 07:31:17 -07:00
|
|
|
return ip != null && (isPaste || ip.isTag != true);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines whether or not the root node for the view is selected
|
|
|
|
*/
|
|
|
|
rootNodeIsSelected: function PC_rootNodeIsSelected() {
|
2008-02-25 13:45:22 -08:00
|
|
|
var nodes = this._view.getSelectionNodes();
|
|
|
|
var root = this._view.getResultNode();
|
|
|
|
for (var i = 0; i < nodes.length; ++i) {
|
|
|
|
if (nodes[i] == root)
|
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-02-25 13:45:22 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return false;
|
|
|
|
},
|
2007-09-19 01:13:20 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Looks at the data on the clipboard to see if it is paste-able.
|
|
|
|
* Paste-able data is:
|
|
|
|
* - in a format that the view can receive
|
2007-08-11 09:08:52 -07:00
|
|
|
* @returns true if: - clipboard data is of a TYPE_X_MOZ_PLACE_* flavor,
|
|
|
|
- clipboard data is of type TEXT_UNICODE and
|
|
|
|
is a valid URI.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2007-08-11 09:08:52 -07:00
|
|
|
_isClipboardDataPasteable: function PC__isClipboardDataPasteable() {
|
|
|
|
// if the clipboard contains TYPE_X_MOZ_PLACE_* data, it is definitely
|
|
|
|
// pasteable, with no need to unwrap all the nodes.
|
2007-09-19 01:13:20 -07:00
|
|
|
|
2008-09-19 08:47:45 -07:00
|
|
|
var flavors = PlacesControllerDragHelper.placesFlavors;
|
2008-03-13 12:25:49 -07:00
|
|
|
var clipboard = PlacesUIUtils.clipboard;
|
2007-09-19 01:13:20 -07:00
|
|
|
var hasPlacesData =
|
2007-11-20 11:06:30 -08:00
|
|
|
clipboard.hasDataMatchingFlavors(flavors, flavors.length,
|
2007-09-19 01:13:20 -07:00
|
|
|
Ci.nsIClipboard.kGlobalClipboard);
|
2007-08-11 09:08:52 -07:00
|
|
|
if (hasPlacesData)
|
|
|
|
return this._view.insertionPoint != null;
|
2007-09-19 01:13:20 -07:00
|
|
|
|
2007-08-11 09:08:52 -07:00
|
|
|
// if the clipboard doesn't have TYPE_X_MOZ_PLACE_* data, we also allow
|
|
|
|
// pasting of valid "text/unicode" and "text/x-moz-url" data
|
|
|
|
var xferable = Cc["@mozilla.org/widget/transferable;1"].
|
2007-09-19 01:13:20 -07:00
|
|
|
createInstance(Ci.nsITransferable);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-11 09:08:52 -07:00
|
|
|
xferable.addDataFlavor(PlacesUtils.TYPE_X_MOZ_URL);
|
|
|
|
xferable.addDataFlavor(PlacesUtils.TYPE_UNICODE);
|
2007-03-22 10:30:00 -07:00
|
|
|
clipboard.getData(xferable, Ci.nsIClipboard.kGlobalClipboard);
|
2007-09-19 01:13:20 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
try {
|
2007-08-11 09:08:52 -07:00
|
|
|
// getAnyTransferData will throw if no data is available.
|
2007-03-22 10:30:00 -07:00
|
|
|
var data = { }, type = { };
|
|
|
|
xferable.getAnyTransferData(type, data, { });
|
|
|
|
data = data.value.QueryInterface(Ci.nsISupportsString).data;
|
2007-08-11 09:08:52 -07:00
|
|
|
if (type.value != PlacesUtils.TYPE_X_MOZ_URL &&
|
|
|
|
type.value != PlacesUtils.TYPE_UNICODE)
|
2007-03-22 10:30:00 -07:00
|
|
|
return false;
|
|
|
|
|
2007-08-11 09:08:52 -07:00
|
|
|
// unwrapNodes() will throw if the data blob is malformed.
|
2007-07-13 17:25:26 -07:00
|
|
|
var unwrappedNodes = PlacesUtils.unwrapNodes(data, type.value);
|
|
|
|
return this._view.insertionPoint != null;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2007-08-11 09:08:52 -07:00
|
|
|
// getAnyTransferData or unwrapNodes failed
|
2007-03-22 10:30:00 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gathers information about the selected nodes according to the following
|
|
|
|
* rules:
|
|
|
|
* "link" node is a URI
|
|
|
|
* "bookmark" node is a bookamrk
|
2007-08-27 17:35:55 -07:00
|
|
|
* "livemarkChild" node is a child of a livemark
|
2008-04-21 02:20:16 -07:00
|
|
|
* "tagChild" node is a child of a tag
|
2007-03-22 10:30:00 -07:00
|
|
|
* "folder" node is a folder
|
|
|
|
* "query" node is a query
|
2007-08-02 15:52:21 -07:00
|
|
|
* "dynamiccontainer" node is a dynamic container
|
2007-03-22 10:30:00 -07:00
|
|
|
* "separator" node is a separator line
|
|
|
|
* "host" node is a host
|
2008-04-20 19:32:43 -07:00
|
|
|
*
|
2007-03-22 10:30:00 -07:00
|
|
|
* @returns an array of objects corresponding the selected nodes. Each
|
|
|
|
* object has each of the properties above set if its corresponding
|
|
|
|
* node matches the rule. In addition, the annotations names for each
|
|
|
|
* node are set on its corresponding object as properties.
|
|
|
|
* Notes:
|
|
|
|
* 1) This can be slow, so don't call it anywhere performance critical!
|
|
|
|
* 2) A single-object array corresponding the root node is returned if
|
|
|
|
* there's no selection.
|
|
|
|
*/
|
|
|
|
_buildSelectionMetadata: function PC__buildSelectionMetadata() {
|
|
|
|
var metadata = [];
|
|
|
|
var root = this._view.getResult().root;
|
2008-02-25 13:45:22 -08:00
|
|
|
var nodes = this._view.getSelectionNodes();
|
|
|
|
if (nodes.length == 0)
|
|
|
|
nodes.push(root); // See the second note above
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
for (var i=0; i < nodes.length; i++) {
|
|
|
|
var nodeData = {};
|
|
|
|
var node = nodes[i];
|
|
|
|
var nodeType = node.type;
|
|
|
|
var uri = null;
|
|
|
|
|
|
|
|
// We don't use the nodeIs* methods here to avoid going through the type
|
|
|
|
// property way too often
|
|
|
|
switch(nodeType) {
|
|
|
|
case Ci.nsINavHistoryResultNode.RESULT_TYPE_QUERY:
|
|
|
|
nodeData["query"] = true;
|
2008-02-26 20:48:51 -08:00
|
|
|
if (node.parent) {
|
|
|
|
switch (asQuery(node.parent).queryOptions.resultType) {
|
|
|
|
case Ci.nsINavHistoryQueryOptions.RESULTS_AS_SITE_QUERY:
|
|
|
|
nodeData["host"] = true;
|
|
|
|
break;
|
|
|
|
case Ci.nsINavHistoryQueryOptions.RESULTS_AS_DATE_SITE_QUERY:
|
|
|
|
case Ci.nsINavHistoryQueryOptions.RESULTS_AS_DATE_QUERY:
|
|
|
|
nodeData["day"] = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2007-08-02 15:52:21 -07:00
|
|
|
case Ci.nsINavHistoryResultNode.RESULT_TYPE_DYNAMIC_CONTAINER:
|
|
|
|
nodeData["dynamiccontainer"] = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER:
|
2008-01-25 11:01:18 -08:00
|
|
|
case Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER_SHORTCUT:
|
2007-03-22 10:30:00 -07:00
|
|
|
nodeData["folder"] = true;
|
|
|
|
break;
|
|
|
|
case Ci.nsINavHistoryResultNode.RESULT_TYPE_SEPARATOR:
|
|
|
|
nodeData["separator"] = true;
|
|
|
|
break;
|
|
|
|
case Ci.nsINavHistoryResultNode.RESULT_TYPE_URI:
|
|
|
|
case Ci.nsINavHistoryResultNode.RESULT_TYPE_VISIT:
|
|
|
|
case Ci.nsINavHistoryResultNode.RESULT_TYPE_FULL_VISIT:
|
|
|
|
nodeData["link"] = true;
|
|
|
|
uri = PlacesUtils._uri(node.uri);
|
2007-05-31 17:39:09 -07:00
|
|
|
if (PlacesUtils.nodeIsBookmark(node)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nodeData["bookmark"] = true;
|
2008-04-20 19:32:43 -07:00
|
|
|
PlacesUtils.nodeIsTagQuery(node.parent)
|
2008-03-13 12:25:49 -07:00
|
|
|
var mss = PlacesUIUtils.microsummaries;
|
2007-05-31 17:39:09 -07:00
|
|
|
if (mss.hasMicrosummary(node.itemId))
|
|
|
|
nodeData["microsummary"] = true;
|
2008-04-20 19:32:43 -07:00
|
|
|
|
|
|
|
var parentNode = node.parent;
|
|
|
|
if (parentNode) {
|
|
|
|
if (PlacesUtils.nodeIsTagQuery(parentNode))
|
|
|
|
nodeData["tagChild"] = true;
|
|
|
|
else if (PlacesUtils.nodeIsLivemarkContainer(parentNode))
|
|
|
|
nodeData["livemarkChild"] = true;
|
|
|
|
}
|
2007-05-31 17:39:09 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// annotations
|
|
|
|
if (uri) {
|
|
|
|
var names = PlacesUtils.annotations.getPageAnnotationNames(uri, {});
|
|
|
|
for (var j = 0; j < names.length; ++j)
|
2007-04-27 09:37:09 -07:00
|
|
|
nodeData[names[j]] = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-11-19 18:01:53 -08:00
|
|
|
|
|
|
|
// For items also include the item-specific annotations
|
|
|
|
if (node.itemId != -1) {
|
|
|
|
names = PlacesUtils.annotations
|
|
|
|
.getItemAnnotationNames(node.itemId, {});
|
|
|
|
for (j = 0; j < names.length; ++j)
|
|
|
|
nodeData[names[j]] = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
metadata.push(nodeData);
|
|
|
|
}
|
|
|
|
|
|
|
|
return metadata;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if a context-menu item should be shown
|
|
|
|
* @param aMenuItem
|
|
|
|
* the context menu item
|
|
|
|
* @param aMetaData
|
|
|
|
* meta data about the selection
|
|
|
|
* @returns true if the conditions (see buildContextMenu) are satisfied
|
|
|
|
* and the item can be displayed, false otherwise.
|
|
|
|
*/
|
|
|
|
_shouldShowMenuItem: function PC__shouldShowMenuItem(aMenuItem, aMetaData) {
|
|
|
|
var selectiontype = aMenuItem.getAttribute("selectiontype");
|
|
|
|
if (selectiontype == "multiple" && aMetaData.length == 1)
|
|
|
|
return false;
|
|
|
|
if (selectiontype == "single" && aMetaData.length != 1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
var forceHideRules = aMenuItem.getAttribute("forcehideselection").split("|");
|
|
|
|
for (var i = 0; i < aMetaData.length; ++i) {
|
|
|
|
for (var j=0; j < forceHideRules.length; ++j) {
|
|
|
|
if (forceHideRules[j] in aMetaData[i])
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-20 19:32:43 -07:00
|
|
|
var selectionAttr = aMenuItem.getAttribute("selection");
|
|
|
|
if (selectionAttr) {
|
|
|
|
if (selectionAttr == "any")
|
|
|
|
return true;
|
|
|
|
|
|
|
|
var showRules = selectionAttr.split("|");
|
2007-03-22 10:30:00 -07:00
|
|
|
var anyMatched = false;
|
|
|
|
function metaDataNodeMatches(metaDataNode, rules) {
|
|
|
|
for (var i=0; i < rules.length; i++) {
|
|
|
|
if (rules[i] in metaDataNode)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (var i = 0; i < aMetaData.length; ++i) {
|
|
|
|
if (metaDataNodeMatches(aMetaData[i], showRules))
|
|
|
|
anyMatched = true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return anyMatched;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !aMenuItem.hidden;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Detects information (meta-data rules) about the current selection in the
|
|
|
|
* view (see _buildSelectionMetadata) and sets the visibility state for each
|
|
|
|
* of the menu-items in the given popup with the following rules applied:
|
|
|
|
* 1) The "selectiontype" attribute may be set on a menu-item to "single"
|
|
|
|
* if the menu-item should be visible only if there is a single node
|
|
|
|
* selected, or to "multiple" if the menu-item should be visible only if
|
|
|
|
* multiple nodes are selected. If the attribute is not set or if it is
|
|
|
|
* set to an invalid value, the menu-item may be visible for both types of
|
|
|
|
* selection.
|
|
|
|
* 2) The "selection" attribute may be set on a menu-item to the various
|
|
|
|
* meta-data rules for which it may be visible. The rules should be
|
|
|
|
* separated with the | character.
|
|
|
|
* 3) A menu-item may be visible only if at least one of the rules set in
|
|
|
|
* its selection attribute apply to each of the selected nodes in the
|
|
|
|
* view.
|
|
|
|
* 4) The "forcehideselection" attribute may be set on a menu-item to rules
|
|
|
|
* for which it should be hidden. This attribute takes priority over the
|
|
|
|
* selection attribute. A menu-item would be hidden if at least one of the
|
|
|
|
* given rules apply to one of the selected nodes. The rules should be
|
|
|
|
* separated with the | character.
|
2009-02-28 04:00:05 -08:00
|
|
|
* 5) The "hideifnoinsertionpoint" attribute may be set on a menu-item to
|
2008-04-20 19:32:43 -07:00
|
|
|
* true if it should be hidden when there's no insertion point
|
|
|
|
* 6) The visibility state of a menu-item is unchanged if none of these
|
2007-03-22 10:30:00 -07:00
|
|
|
* attribute are set.
|
2008-04-20 19:32:43 -07:00
|
|
|
* 7) These attributes should not be set on separators for which the
|
2007-03-22 10:30:00 -07:00
|
|
|
* visibility state is "auto-detected."
|
2009-04-03 11:55:37 -07:00
|
|
|
* 8) The "hideifprivatebrowsing" attribute may be set on a menu-item to
|
|
|
|
* true if it should be hidden inside the private browsing mode
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param aPopup
|
|
|
|
* The menupopup to build children into.
|
|
|
|
* @return true if at least one item is visible, false otherwise.
|
|
|
|
*/
|
|
|
|
buildContextMenu: function PC_buildContextMenu(aPopup) {
|
|
|
|
var metadata = this._buildSelectionMetadata();
|
2008-04-20 19:32:43 -07:00
|
|
|
var ip = this._view.insertionPoint;
|
|
|
|
var noIp = !ip || ip.isTag;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
var separator = null;
|
|
|
|
var visibleItemsBeforeSep = false;
|
|
|
|
var anyVisible = false;
|
|
|
|
for (var i = 0; i < aPopup.childNodes.length; ++i) {
|
|
|
|
var item = aPopup.childNodes[i];
|
|
|
|
if (item.localName != "menuseparator") {
|
2009-03-27 07:31:17 -07:00
|
|
|
// We allow pasting into tag containers, so special case that.
|
2009-04-03 11:55:37 -07:00
|
|
|
var hideIfNoIP = item.getAttribute("hideifnoinsertionpoint") == "true" &&
|
|
|
|
noIp && !(ip && ip.isTag && item.id == "placesContext_paste");
|
|
|
|
var hideIfPB = item.getAttribute("hideifprivatebrowsing") == "true" &&
|
|
|
|
PlacesUIUtils.privateBrowsing.privateBrowsingEnabled;
|
|
|
|
item.hidden = hideIfNoIP || hideIfPB ||
|
2008-04-20 19:32:43 -07:00
|
|
|
!this._shouldShowMenuItem(item, metadata);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!item.hidden) {
|
|
|
|
visibleItemsBeforeSep = true;
|
|
|
|
anyVisible = true;
|
|
|
|
|
|
|
|
// Show the separator above the menu-item if any
|
|
|
|
if (separator) {
|
|
|
|
separator.hidden = false;
|
|
|
|
separator = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // menuseparator
|
|
|
|
// Initially hide it. It will be unhidden if there will be at least one
|
|
|
|
// visible menu-item above and below it.
|
|
|
|
item.hidden = true;
|
|
|
|
|
|
|
|
// We won't show the separator at all if no items are visible above it
|
|
|
|
if (visibleItemsBeforeSep)
|
|
|
|
separator = item;
|
|
|
|
|
|
|
|
// New separator, count again:
|
|
|
|
visibleItemsBeforeSep = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-02 12:03:24 -07:00
|
|
|
// Set Open Folder/Links In Tabs items enabled state if they're visible
|
|
|
|
if (anyVisible) {
|
|
|
|
var openContainerInTabsItem = document.getElementById("placesContext_openContainer:tabs");
|
2007-09-21 15:48:23 -07:00
|
|
|
if (!openContainerInTabsItem.hidden && this._view.selectedNode &&
|
|
|
|
PlacesUtils.nodeIsContainer(this._view.selectedNode)) {
|
2007-09-02 12:03:24 -07:00
|
|
|
openContainerInTabsItem.disabled =
|
2008-03-14 13:17:14 -07:00
|
|
|
!PlacesUtils.hasChildURIs(this._view.selectedNode);
|
2007-09-02 12:03:24 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// see selectiontype rule in the overlay
|
|
|
|
var openLinksInTabsItem = document.getElementById("placesContext_openLinks:tabs");
|
|
|
|
openLinksInTabsItem.disabled = openLinksInTabsItem.hidden;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return anyVisible;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Select all links in the current view.
|
|
|
|
*/
|
|
|
|
selectAll: function PC_selectAll() {
|
|
|
|
this._view.selectAll();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens the bookmark properties for the selected URI Node.
|
|
|
|
*/
|
|
|
|
showBookmarkPropertiesForSelection:
|
|
|
|
function PC_showBookmarkPropertiesForSelection() {
|
|
|
|
var node = this._view.selectedNode;
|
|
|
|
if (!node)
|
|
|
|
return;
|
|
|
|
|
2009-03-18 07:23:56 -07:00
|
|
|
var itemType = PlacesUtils.nodeIsFolder(node) ||
|
|
|
|
PlacesUtils.nodeIsTagQuery(node) ? "folder" : "bookmark";
|
|
|
|
var concreteId = PlacesUtils.getConcreteItemId(node);
|
|
|
|
var isRootItem = PlacesUtils.isRootItem(concreteId);
|
|
|
|
var itemId = node.itemId;
|
|
|
|
if (isRootItem || PlacesUtils.nodeIsTagQuery(node)) {
|
|
|
|
// If this is a root or the Tags query we use the concrete itemId to catch
|
|
|
|
// the correct title for the node.
|
|
|
|
itemId = concreteId;
|
|
|
|
}
|
|
|
|
|
|
|
|
PlacesUIUtils.showItemProperties(itemId, itemType,
|
|
|
|
isRootItem /* read only */);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method can be run on a URI parameter to ensure that it didn't
|
|
|
|
* receive a string instead of an nsIURI object.
|
|
|
|
*/
|
|
|
|
_assertURINotString: function PC__assertURINotString(value) {
|
|
|
|
NS_ASSERT((typeof(value) == "object") && !(value instanceof String),
|
|
|
|
"This method should be passed a URI as a nsIURI object, not as a string.");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2007-11-19 18:01:53 -08:00
|
|
|
* Reloads the selected livemark if any.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2007-11-19 18:01:53 -08:00
|
|
|
reloadSelectedLivemark: function PC_reloadSelectedLivemark() {
|
2008-02-25 13:45:22 -08:00
|
|
|
var selectedNode = this._view.selectedNode;
|
|
|
|
if (selectedNode && PlacesUtils.nodeIsLivemarkContainer(selectedNode))
|
|
|
|
PlacesUtils.livemarks.reloadLivemarkFolder(selectedNode.itemId);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2007-05-31 17:39:09 -07:00
|
|
|
/**
|
|
|
|
* Reload the microsummary associated with the selection
|
|
|
|
*/
|
|
|
|
reloadSelectedMicrosummary: function PC_reloadSelectedMicrosummary() {
|
|
|
|
var selectedNode = this._view.selectedNode;
|
2008-03-13 12:25:49 -07:00
|
|
|
var mss = PlacesUIUtils.microsummaries;
|
2007-05-31 17:39:09 -07:00
|
|
|
if (mss.hasMicrosummary(selectedNode.itemId))
|
|
|
|
mss.refreshMicrosummary(selectedNode.itemId);
|
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Gives the user a chance to cancel loading lots of tabs at once
|
|
|
|
*/
|
|
|
|
_confirmOpenTabs: function(numTabsToOpen) {
|
|
|
|
var pref = Cc["@mozilla.org/preferences-service;1"].
|
|
|
|
getService(Ci.nsIPrefBranch);
|
|
|
|
|
|
|
|
const kWarnOnOpenPref = "browser.tabs.warnOnOpen";
|
|
|
|
var reallyOpen = true;
|
|
|
|
if (pref.getBoolPref(kWarnOnOpenPref)) {
|
|
|
|
if (numTabsToOpen >= pref.getIntPref("browser.tabs.maxOpenBeforeWarn")) {
|
|
|
|
var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"].
|
|
|
|
getService(Ci.nsIPromptService);
|
|
|
|
|
|
|
|
// default to true: if it were false, we wouldn't get this far
|
|
|
|
var warnOnOpen = { value: true };
|
|
|
|
|
|
|
|
var messageKey = "tabs.openWarningMultipleBranded";
|
|
|
|
var openKey = "tabs.openButtonMultiple";
|
|
|
|
var strings = document.getElementById("placeBundle");
|
|
|
|
const BRANDING_BUNDLE_URI = "chrome://branding/locale/brand.properties";
|
|
|
|
var brandShortName = Cc["@mozilla.org/intl/stringbundle;1"].
|
|
|
|
getService(Ci.nsIStringBundleService).
|
|
|
|
createBundle(BRANDING_BUNDLE_URI).
|
|
|
|
GetStringFromName("brandShortName");
|
|
|
|
|
|
|
|
var buttonPressed = promptService.confirmEx(window,
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUIUtils.getString("tabs.openWarningTitle"),
|
|
|
|
PlacesUIUtils.getFormattedString(messageKey,
|
2007-03-22 10:30:00 -07:00
|
|
|
[numTabsToOpen, brandShortName]),
|
|
|
|
(promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0)
|
|
|
|
+ (promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1),
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUIUtils.getString(openKey),
|
2007-03-22 10:30:00 -07:00
|
|
|
null, null,
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUIUtils.getFormattedString("tabs.openWarningPromptMeBranded",
|
2007-03-22 10:30:00 -07:00
|
|
|
[brandShortName]),
|
|
|
|
warnOnOpen);
|
|
|
|
|
|
|
|
reallyOpen = (buttonPressed == 0);
|
|
|
|
// don't set the pref unless they press OK and it's false
|
|
|
|
if (reallyOpen && !warnOnOpen.value)
|
|
|
|
pref.setBoolPref(kWarnOnOpenPref, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return reallyOpen;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens the links in the selected folder, or the selected links in new tabs.
|
|
|
|
*/
|
2007-09-02 12:03:24 -07:00
|
|
|
openSelectionInTabs: function PC_openLinksInTabs(aEvent) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var node = this._view.selectedNode;
|
2008-02-25 13:45:22 -08:00
|
|
|
if (node && PlacesUtils.nodeIsContainer(node))
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUIUtils.openContainerNodeInTabs(this._view.selectedNode, aEvent);
|
2007-09-02 12:03:24 -07:00
|
|
|
else
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUIUtils.openURINodesInTabs(this._view.getSelectionNodes(), aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the Add Bookmark UI for the current insertion point.
|
|
|
|
*
|
|
|
|
* @param aType
|
|
|
|
* the type of the new item (bookmark/livemark/folder)
|
|
|
|
*/
|
|
|
|
newItem: function PC_newItem(aType) {
|
|
|
|
var ip = this._view.insertionPoint;
|
|
|
|
if (!ip)
|
|
|
|
throw Cr.NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
var performed = false;
|
|
|
|
if (aType == "bookmark")
|
2008-03-13 12:25:49 -07:00
|
|
|
performed = PlacesUIUtils.showAddBookmarkUI(null, null, null, ip);
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (aType == "livemark")
|
2008-03-13 12:25:49 -07:00
|
|
|
performed = PlacesUIUtils.showAddLivemarkUI(null, null, null, null, ip);
|
2007-03-22 10:30:00 -07:00
|
|
|
else // folder
|
2008-03-13 12:25:49 -07:00
|
|
|
performed = PlacesUIUtils.showAddFolderUI(null, ip);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-02-06 13:05:23 -08:00
|
|
|
if (performed) {
|
|
|
|
// select the new item
|
|
|
|
var insertedNodeId = PlacesUtils.bookmarks
|
|
|
|
.getIdForItemAt(ip.itemId, ip.index);
|
2008-07-08 02:33:17 -07:00
|
|
|
this._view.selectItems([insertedNodeId], false);
|
2008-02-06 13:05:23 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new Bookmark folder somewhere. Prompts the user for the name
|
|
|
|
* of the folder.
|
|
|
|
*/
|
|
|
|
newFolder: function PC_newFolder() {
|
|
|
|
var ip = this._view.insertionPoint;
|
|
|
|
if (!ip)
|
|
|
|
throw Cr.NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
2008-02-06 13:05:23 -08:00
|
|
|
var performed = false;
|
2008-03-13 12:25:49 -07:00
|
|
|
performed = PlacesUIUtils.showAddFolderUI(null, ip);
|
2008-02-06 13:05:23 -08:00
|
|
|
if (performed) {
|
|
|
|
// select the new item
|
|
|
|
var insertedNodeId = PlacesUtils.bookmarks
|
|
|
|
.getIdForItemAt(ip.itemId, ip.index);
|
2008-07-08 02:33:17 -07:00
|
|
|
this._view.selectItems([insertedNodeId], false);
|
2008-02-06 13:05:23 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new Bookmark separator somewhere.
|
|
|
|
*/
|
|
|
|
newSeparator: function PC_newSeparator() {
|
|
|
|
var ip = this._view.insertionPoint;
|
|
|
|
if (!ip)
|
|
|
|
throw Cr.NS_ERROR_NOT_AVAILABLE;
|
2008-03-13 12:25:49 -07:00
|
|
|
var txn = PlacesUIUtils.ptm.createSeparator(ip.itemId, ip.index);
|
|
|
|
PlacesUIUtils.ptm.doTransaction(txn);
|
2008-02-06 13:05:23 -08:00
|
|
|
// select the new item
|
|
|
|
var insertedNodeId = PlacesUtils.bookmarks
|
|
|
|
.getIdForItemAt(ip.itemId, ip.index);
|
2008-07-08 02:33:17 -07:00
|
|
|
this._view.selectItems([insertedNodeId], false);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens a dialog for moving the selected nodes.
|
|
|
|
*/
|
|
|
|
moveSelectedBookmarks: function PC_moveBookmarks() {
|
|
|
|
window.openDialog("chrome://browser/content/places/moveBookmarks.xul",
|
|
|
|
"", "chrome, modal",
|
2007-12-02 12:08:23 -08:00
|
|
|
this._view.getSelectionNodes());
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2007-05-11 12:06:57 -07:00
|
|
|
/**
|
|
|
|
* Sort the selected folder by name
|
|
|
|
*/
|
|
|
|
sortFolderByName: function PC_sortFolderByName() {
|
2008-02-10 14:51:57 -08:00
|
|
|
var itemId = PlacesUtils.getConcreteItemId(this._view.selectedNode);
|
2008-03-13 12:25:49 -07:00
|
|
|
var txn = PlacesUIUtils.ptm.sortFolderByName(itemId);
|
|
|
|
PlacesUIUtils.ptm.doTransaction(txn);
|
2007-05-11 12:06:57 -07:00
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2007-07-13 17:25:26 -07:00
|
|
|
* Walk the list of folders we're removing in this delete operation, and
|
|
|
|
* see if the selected node specified is already implicitly being removed
|
|
|
|
* because it is a child of that folder.
|
|
|
|
* @param node
|
|
|
|
* Node to check for containment.
|
|
|
|
* @param pastFolders
|
|
|
|
* List of folders the calling function has already traversed
|
|
|
|
* @returns true if the node should be skipped, false otherwise.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2007-07-13 17:25:26 -07:00
|
|
|
_shouldSkipNode: function PC_shouldSkipNode(node, pastFolders) {
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Determines if a node is contained by another node within a resultset.
|
|
|
|
* @param node
|
|
|
|
* The node to check for containment for
|
|
|
|
* @param parent
|
|
|
|
* The parent container to check for containment in
|
|
|
|
* @returns true if node is a member of parent's children, false otherwise.
|
|
|
|
*/
|
|
|
|
function isContainedBy(node, parent) {
|
|
|
|
var cursor = node.parent;
|
|
|
|
while (cursor) {
|
|
|
|
if (cursor == parent)
|
|
|
|
return true;
|
|
|
|
cursor = cursor.parent;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2007-07-13 17:25:26 -07:00
|
|
|
|
|
|
|
for (var j = 0; j < pastFolders.length; ++j) {
|
|
|
|
if (isContainedBy(node, pastFolders[j]))
|
2007-03-22 10:30:00 -07:00
|
|
|
return true;
|
|
|
|
}
|
2007-07-13 17:25:26 -07:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a set of transactions for the removal of a range of items.
|
|
|
|
* A range is an array of adjacent nodes in a view.
|
2007-07-15 02:44:50 -07:00
|
|
|
* @param [in] range
|
2007-07-13 17:25:26 -07:00
|
|
|
* An array of nodes to remove. Should all be adjacent.
|
2007-07-15 02:44:50 -07:00
|
|
|
* @param [out] transactions
|
2007-07-13 17:25:26 -07:00
|
|
|
* An array of transactions.
|
2008-09-11 07:16:54 -07:00
|
|
|
* @param [optional] removedFolders
|
|
|
|
* An array of folder nodes that have already been removed.
|
2007-07-13 17:25:26 -07:00
|
|
|
*/
|
2008-09-11 07:16:54 -07:00
|
|
|
_removeRange: function PC__removeRange(range, transactions, removedFolders) {
|
2007-07-13 17:25:26 -07:00
|
|
|
NS_ASSERT(transactions instanceof Array, "Must pass a transactions array");
|
2008-09-11 07:16:54 -07:00
|
|
|
if (!removedFolders)
|
|
|
|
removedFolders = [];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
for (var i = 0; i < range.length; ++i) {
|
|
|
|
var node = range[i];
|
2007-07-13 17:25:26 -07:00
|
|
|
if (this._shouldSkipNode(node, removedFolders))
|
2007-03-22 10:30:00 -07:00
|
|
|
continue;
|
|
|
|
|
2009-04-30 09:52:49 -07:00
|
|
|
if (PlacesUtils.nodeIsTagQuery(node.parent)) {
|
2009-04-24 06:11:01 -07:00
|
|
|
// This is a uri node inside a tag container. It needs a special
|
|
|
|
// untag transaction.
|
2008-10-17 03:06:53 -07:00
|
|
|
var tagItemId = PlacesUtils.getConcreteItemId(node.parent);
|
2008-04-15 10:17:34 -07:00
|
|
|
var uri = PlacesUtils._uri(node.uri);
|
|
|
|
transactions.push(PlacesUIUtils.ptm.untagURI(uri, [tagItemId]));
|
2008-04-11 09:22:01 -07:00
|
|
|
}
|
2008-10-17 03:06:53 -07:00
|
|
|
else if (PlacesUtils.nodeIsTagQuery(node) && node.parent &&
|
|
|
|
PlacesUtils.nodeIsQuery(node.parent) &&
|
|
|
|
asQuery(node.parent).queryOptions.resultType ==
|
|
|
|
Ci.nsINavHistoryQueryOptions.RESULTS_AS_TAG_QUERY) {
|
2009-04-24 06:11:01 -07:00
|
|
|
// This is a tag container.
|
2008-10-17 03:06:53 -07:00
|
|
|
// Untag all URIs tagged with this tag only if the tag container is
|
|
|
|
// child of the "Tags" query in the library, in all other places we
|
|
|
|
// must only remove the query node.
|
|
|
|
var tag = node.title;
|
|
|
|
var URIs = PlacesUtils.tagging.getURIsForTag(tag);
|
|
|
|
for (var j = 0; j < URIs.length; j++)
|
|
|
|
transactions.push(PlacesUIUtils.ptm.untagURI(URIs[j], [tag]));
|
|
|
|
}
|
2009-04-24 06:11:01 -07:00
|
|
|
else if (PlacesUtils.nodeIsURI(node) &&
|
|
|
|
PlacesUtils.nodeIsQuery(node.parent) &&
|
2008-04-17 19:01:30 -07:00
|
|
|
asQuery(node.parent).queryOptions.queryType ==
|
2009-04-24 06:11:01 -07:00
|
|
|
Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY) {
|
|
|
|
// This is a uri node inside an history query.
|
2008-04-17 19:01:30 -07:00
|
|
|
var bhist = PlacesUtils.history.QueryInterface(Ci.nsIBrowserHistory);
|
|
|
|
bhist.removePage(PlacesUtils._uri(node.uri));
|
2009-04-24 06:11:01 -07:00
|
|
|
// History deletes are not undoable, so we don't have a transaction.
|
|
|
|
}
|
2009-04-30 09:52:49 -07:00
|
|
|
else if (node.itemId == -1 &&
|
|
|
|
PlacesUtils.nodeIsQuery(node) &&
|
2009-04-24 06:11:01 -07:00
|
|
|
asQuery(node).queryOptions.queryType ==
|
|
|
|
Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY) {
|
2009-04-30 09:52:49 -07:00
|
|
|
// This is a dynamically generated history query, like queries
|
|
|
|
// grouped by site, time or both. Dynamically generated queries don't
|
|
|
|
// have an itemId even if they are descendants of a bookmark.
|
2009-04-24 06:11:01 -07:00
|
|
|
this._removeHistoryContainer(node);
|
|
|
|
// History deletes are not undoable, so we don't have a transaction.
|
2008-04-17 19:01:30 -07:00
|
|
|
}
|
2009-04-30 09:52:49 -07:00
|
|
|
else {
|
|
|
|
// This is a common bookmark item.
|
|
|
|
if (PlacesUtils.nodeIsFolder(node)) {
|
|
|
|
// If this is a folder we add it to our array of folders, used
|
|
|
|
// to skip nodes that are children of an already removed folder.
|
|
|
|
removedFolders.push(node);
|
|
|
|
}
|
|
|
|
transactions.push(PlacesUIUtils.ptm.removeItem(node.itemId));
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the set of selected ranges from bookmarks.
|
|
|
|
* @param txnName
|
|
|
|
* See |remove|.
|
|
|
|
*/
|
|
|
|
_removeRowsFromBookmarks: function PC__removeRowsFromBookmarks(txnName) {
|
|
|
|
var ranges = this._view.getRemovableSelectionRanges();
|
|
|
|
var transactions = [];
|
2008-09-11 07:16:54 -07:00
|
|
|
var removedFolders = [];
|
|
|
|
|
|
|
|
for (var i = 0; i < ranges.length; i++)
|
|
|
|
this._removeRange(ranges[i], transactions, removedFolders);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (transactions.length > 0) {
|
2008-03-13 12:25:49 -07:00
|
|
|
var txn = PlacesUIUtils.ptm.aggregateTransactions(txnName, transactions);
|
|
|
|
PlacesUIUtils.ptm.doTransaction(txn);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2008-01-31 19:03:14 -08:00
|
|
|
* Removes the set of selected ranges from history.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
_removeRowsFromHistory: function PC__removeRowsFromHistory() {
|
|
|
|
// Other containers are history queries, just delete from history
|
|
|
|
// history deletes are not undoable.
|
|
|
|
var nodes = this._view.getSelectionNodes();
|
2008-01-31 19:03:14 -08:00
|
|
|
var URIs = [];
|
|
|
|
var bhist = PlacesUtils.history.QueryInterface(Ci.nsIBrowserHistory);
|
|
|
|
var resultView = this._view.getResultView();
|
2008-02-22 03:46:29 -08:00
|
|
|
var root = this._view.getResultNode();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
for (var i = 0; i < nodes.length; ++i) {
|
|
|
|
var node = nodes[i];
|
2009-04-24 06:11:01 -07:00
|
|
|
if (PlacesUtils.nodeIsURI(node)) {
|
2008-01-31 19:03:14 -08:00
|
|
|
var uri = PlacesUtils._uri(node.uri);
|
|
|
|
// avoid trying to delete the same url twice
|
|
|
|
if (URIs.indexOf(uri) < 0) {
|
|
|
|
URIs.push(uri);
|
|
|
|
}
|
|
|
|
}
|
2009-04-24 06:11:01 -07:00
|
|
|
else if (PlacesUtils.nodeIsQuery(node) &&
|
|
|
|
asQuery(node).queryOptions.queryType ==
|
|
|
|
Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY)
|
|
|
|
this._removeHistoryContainer(node);
|
2008-01-31 19:03:14 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// if we have to delete a lot of urls RemovePage will be slow, it's better
|
|
|
|
// to delete them in bunch and rebuild the full treeView
|
|
|
|
if (URIs.length > REMOVE_PAGES_MAX_SINGLEREMOVES) {
|
|
|
|
// do removal in chunks to avoid passing a too big array to removePages
|
|
|
|
for (var i = 0; i < URIs.length; i += REMOVE_PAGES_CHUNKLEN) {
|
2008-12-06 03:26:41 -08:00
|
|
|
var URIslice = URIs.slice(i, i + REMOVE_PAGES_CHUNKLEN);
|
|
|
|
// set DoBatchNotify (third param) only on the last chunk, so we update
|
|
|
|
// the treeView when we are done.
|
2008-01-31 19:03:14 -08:00
|
|
|
bhist.removePages(URIslice, URIslice.length,
|
|
|
|
(i + REMOVE_PAGES_CHUNKLEN) >= URIs.length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// if we have to delete fewer urls, removepage will allow us to avoid
|
|
|
|
// rebuilding the full treeView
|
|
|
|
for (var i = 0; i < URIs.length; ++i)
|
|
|
|
bhist.removePage(URIs[i]);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-04-24 06:11:01 -07:00
|
|
|
/**
|
|
|
|
* Removes history visits for an history container node.
|
|
|
|
* @param [in] aContainerNode
|
|
|
|
* The container node to remove.
|
|
|
|
*/
|
|
|
|
_removeHistoryContainer: function PC_removeHistoryContainer(aContainerNode) {
|
|
|
|
var bhist = PlacesUtils.history.QueryInterface(Ci.nsIBrowserHistory);
|
|
|
|
if (PlacesUtils.nodeIsHost(aContainerNode)) {
|
|
|
|
// Site container.
|
|
|
|
bhist.removePagesFromHost(aContainerNode.title, true);
|
|
|
|
}
|
|
|
|
else if (PlacesUtils.nodeIsDay(aContainerNode)) {
|
|
|
|
// Day container.
|
|
|
|
var query = aContainerNode.getQueries({})[0];
|
|
|
|
var beginTime = query.beginTime;
|
|
|
|
var endTime = query.endTime;
|
|
|
|
NS_ASSERT(query && beginTime && endTime,
|
|
|
|
"A valid date container query should exist!");
|
|
|
|
// We want to exclude beginTime from the removal because
|
|
|
|
// removePagesByTimeframe includes both extremes, while date containers
|
|
|
|
// exclude the lower extreme. So, if we would not exclude it, we would
|
|
|
|
// end up removing more history than requested.
|
|
|
|
bhist.removePagesByTimeframe(beginTime+1, endTime);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Removes the selection
|
|
|
|
* @param aTxnName
|
|
|
|
* A name for the transaction if this is being performed
|
|
|
|
* as part of another operation.
|
|
|
|
*/
|
|
|
|
remove: function PC_remove(aTxnName) {
|
2008-05-02 08:39:45 -07:00
|
|
|
if (!this._hasRemovableSelection(false))
|
|
|
|
return;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERT(aTxnName !== undefined, "Must supply Transaction Name");
|
|
|
|
|
2007-06-19 09:25:11 -07:00
|
|
|
var root = this._view.getResult().root;
|
|
|
|
|
|
|
|
if (PlacesUtils.nodeIsFolder(root))
|
2007-03-22 10:30:00 -07:00
|
|
|
this._removeRowsFromBookmarks(aTxnName);
|
2007-06-19 09:25:11 -07:00
|
|
|
else if (PlacesUtils.nodeIsQuery(root)) {
|
|
|
|
var queryType = asQuery(root).queryOptions.queryType;
|
|
|
|
if (queryType == Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS)
|
|
|
|
this._removeRowsFromBookmarks(aTxnName);
|
|
|
|
else if (queryType == Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY)
|
|
|
|
this._removeRowsFromHistory();
|
|
|
|
else
|
|
|
|
NS_ASSERT(false, "implement support for QUERY_TYPE_UNIFIED");
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
else
|
2007-06-19 09:25:11 -07:00
|
|
|
NS_ASSERT(false, "unexpected root");
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2008-09-19 08:47:45 -07:00
|
|
|
* Fills a DataTransfer object with the content of the selection that can be
|
|
|
|
* dropped elsewhere.
|
|
|
|
* @param aEvent
|
|
|
|
* The dragstart event.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-09-19 08:47:45 -07:00
|
|
|
setDataTransfer: function PC_setDataTransfer(aEvent) {
|
|
|
|
var dt = aEvent.dataTransfer;
|
|
|
|
var doCopy = dt.effectAllowed == "copyLink" || dt.effectAllowed == "copy";
|
|
|
|
|
2007-10-24 19:02:28 -07:00
|
|
|
var result = this._view.getResult();
|
|
|
|
var oldViewer = result.viewer;
|
|
|
|
try {
|
|
|
|
result.viewer = null;
|
2009-02-28 04:00:05 -08:00
|
|
|
var nodes = this._view.getDraggableSelection();
|
2008-02-25 13:45:22 -08:00
|
|
|
|
2007-10-24 19:02:28 -07:00
|
|
|
for (var i = 0; i < nodes.length; ++i) {
|
|
|
|
var node = nodes[i];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-19 08:47:45 -07:00
|
|
|
function addData(type, index, overrideURI) {
|
|
|
|
var wrapNode = PlacesUtils.wrapNode(node, type, overrideURI, doCopy);
|
|
|
|
dt.mozSetDataAt(type, wrapNode, index);
|
2007-10-24 19:02:28 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-19 08:47:45 -07:00
|
|
|
function addURIData(index, overrideURI) {
|
|
|
|
addData(PlacesUtils.TYPE_X_MOZ_URL, index, overrideURI);
|
|
|
|
addData(PlacesUtils.TYPE_UNICODE, index, overrideURI);
|
|
|
|
addData(PlacesUtils.TYPE_HTML, index, overrideURI);
|
2007-10-24 19:02:28 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-10-24 19:02:28 -07:00
|
|
|
// This order is _important_! It controls how this and other
|
|
|
|
// applications select data to be inserted based on type.
|
2008-09-19 08:47:45 -07:00
|
|
|
addData(PlacesUtils.TYPE_X_MOZ_PLACE, i);
|
|
|
|
|
|
|
|
// Drop the feed uri for livemark containers
|
2007-10-24 19:02:28 -07:00
|
|
|
if (PlacesUtils.nodeIsLivemarkContainer(node))
|
2008-09-19 08:47:45 -07:00
|
|
|
addURIData(i, PlacesUtils.livemarks.getFeedURI(node.itemId).spec);
|
|
|
|
else if (node.uri)
|
|
|
|
addURIData(i);
|
2007-10-24 19:02:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
finally {
|
|
|
|
if (oldViewer)
|
|
|
|
result.viewer = oldViewer;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy Bookmarks and Folders to the clipboard
|
|
|
|
*/
|
|
|
|
copy: function PC_copy() {
|
2007-10-24 19:02:28 -07:00
|
|
|
var result = this._view.getResult();
|
|
|
|
var oldViewer = result.viewer;
|
|
|
|
try {
|
|
|
|
result.viewer = null;
|
2008-02-25 13:45:22 -08:00
|
|
|
var nodes = this._view.getSelectionNodes();
|
2007-10-24 19:02:28 -07:00
|
|
|
|
|
|
|
var xferable = Cc["@mozilla.org/widget/transferable;1"].
|
|
|
|
createInstance(Ci.nsITransferable);
|
|
|
|
var foundFolder = false, foundLink = false;
|
|
|
|
var copiedFolders = [];
|
2009-04-18 05:12:01 -07:00
|
|
|
var placeString, mozURLString, htmlString, unicodeString;
|
|
|
|
placeString = mozURLString = htmlString = unicodeString = "";
|
2008-02-25 13:45:22 -08:00
|
|
|
|
2007-10-24 19:02:28 -07:00
|
|
|
for (var i = 0; i < nodes.length; ++i) {
|
|
|
|
var node = nodes[i];
|
|
|
|
if (this._shouldSkipNode(node, copiedFolders))
|
|
|
|
continue;
|
|
|
|
if (PlacesUtils.nodeIsFolder(node))
|
|
|
|
copiedFolders.push(node);
|
2007-07-13 17:25:26 -07:00
|
|
|
|
2007-10-24 19:02:28 -07:00
|
|
|
function generateChunk(type, overrideURI) {
|
|
|
|
var suffix = i < (nodes.length - 1) ? NEWLINE : "";
|
|
|
|
var uri = overrideURI;
|
2007-07-13 17:25:26 -07:00
|
|
|
|
2007-10-24 19:02:28 -07:00
|
|
|
if (PlacesUtils.nodeIsLivemarkContainer(node))
|
|
|
|
uri = PlacesUtils.livemarks.getFeedURI(node.itemId).spec
|
|
|
|
|
|
|
|
mozURLString += (PlacesUtils.wrapNode(node, PlacesUtils.TYPE_X_MOZ_URL,
|
|
|
|
uri) + suffix);
|
|
|
|
unicodeString += (PlacesUtils.wrapNode(node, PlacesUtils.TYPE_UNICODE,
|
|
|
|
uri) + suffix);
|
|
|
|
htmlString += (PlacesUtils.wrapNode(node, PlacesUtils.TYPE_HTML,
|
|
|
|
uri) + suffix);
|
2008-02-25 13:45:22 -08:00
|
|
|
|
2007-10-24 19:02:28 -07:00
|
|
|
var placeSuffix = i < (nodes.length - 1) ? "," : "";
|
2008-09-19 08:47:45 -07:00
|
|
|
var resolveShortcuts = !PlacesControllerDragHelper.canMoveNode(node);
|
2008-04-25 14:36:40 -07:00
|
|
|
return PlacesUtils.wrapNode(node, type, overrideURI, resolveShortcuts) + placeSuffix;
|
2007-10-24 19:02:28 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-10-24 19:02:28 -07:00
|
|
|
// all items wrapped as TYPE_X_MOZ_PLACE
|
|
|
|
placeString += generateChunk(PlacesUtils.TYPE_X_MOZ_PLACE);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-10-24 19:02:28 -07:00
|
|
|
function addData(type, data) {
|
|
|
|
xferable.addDataFlavor(type);
|
2008-03-13 12:25:49 -07:00
|
|
|
xferable.setTransferData(type, PlacesUIUtils._wrapString(data), data.length * 2);
|
2007-10-24 19:02:28 -07:00
|
|
|
}
|
|
|
|
// This order is _important_! It controls how this and other applications
|
|
|
|
// select data to be inserted based on type.
|
|
|
|
if (placeString)
|
|
|
|
addData(PlacesUtils.TYPE_X_MOZ_PLACE, placeString);
|
|
|
|
if (mozURLString)
|
|
|
|
addData(PlacesUtils.TYPE_X_MOZ_URL, mozURLString);
|
|
|
|
if (unicodeString)
|
|
|
|
addData(PlacesUtils.TYPE_UNICODE, unicodeString);
|
|
|
|
if (htmlString)
|
|
|
|
addData(PlacesUtils.TYPE_HTML, htmlString);
|
|
|
|
|
|
|
|
if (placeString || unicodeString || htmlString || mozURLString) {
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUIUtils.clipboard.setData(xferable, null, Ci.nsIClipboard.kGlobalClipboard);
|
2007-10-24 19:02:28 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-10-24 19:02:28 -07:00
|
|
|
finally {
|
|
|
|
if (oldViewer)
|
|
|
|
result.viewer = oldViewer;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cut Bookmarks and Folders to the clipboard
|
|
|
|
*/
|
|
|
|
cut: function PC_cut() {
|
|
|
|
this.copy();
|
|
|
|
this.remove("Cut Selection");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Paste Bookmarks and Folders from the clipboard
|
|
|
|
*/
|
|
|
|
paste: function PC_paste() {
|
|
|
|
// Strategy:
|
|
|
|
//
|
|
|
|
// There can be data of various types (folder, separator, link) on the
|
|
|
|
// clipboard. We need to get all of that data and build edit transactions
|
|
|
|
// for them. This means asking the clipboard once for each type and
|
|
|
|
// aggregating the results.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs a transferable that can receive data of specific types.
|
|
|
|
* @param types
|
|
|
|
* The types of data the transferable can hold, in order of
|
|
|
|
* preference.
|
|
|
|
* @returns The transferable.
|
|
|
|
*/
|
|
|
|
function makeXferable(types) {
|
|
|
|
var xferable =
|
|
|
|
Cc["@mozilla.org/widget/transferable;1"].
|
|
|
|
createInstance(Ci.nsITransferable);
|
|
|
|
for (var i = 0; i < types.length; ++i)
|
|
|
|
xferable.addDataFlavor(types[i]);
|
|
|
|
return xferable;
|
|
|
|
}
|
|
|
|
|
2008-03-13 12:25:49 -07:00
|
|
|
var clipboard = PlacesUIUtils.clipboard;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
var ip = this._view.insertionPoint;
|
|
|
|
if (!ip)
|
|
|
|
throw Cr.NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a list of transactions to perform the paste of specific types.
|
|
|
|
* @param types
|
|
|
|
* The types of data to form paste transactions for
|
|
|
|
* @returns An array of transactions that perform the paste.
|
|
|
|
*/
|
|
|
|
function getTransactions(types) {
|
|
|
|
var xferable = makeXferable(types);
|
|
|
|
clipboard.getData(xferable, Ci.nsIClipboard.kGlobalClipboard);
|
|
|
|
|
|
|
|
var data = { }, type = { };
|
|
|
|
try {
|
|
|
|
xferable.getAnyTransferData(type, data, { });
|
|
|
|
data = data.value.QueryInterface(Ci.nsISupportsString).data;
|
|
|
|
var items = PlacesUtils.unwrapNodes(data, type.value);
|
|
|
|
var transactions = [];
|
2007-07-13 17:25:26 -07:00
|
|
|
var index = ip.index;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (var i = 0; i < items.length; ++i) {
|
2009-03-27 07:31:17 -07:00
|
|
|
var txn;
|
|
|
|
if (ip.isTag) {
|
|
|
|
var uri = PlacesUtils._uri(items[i].uri);
|
|
|
|
txn = PlacesUIUtils.ptm.tagURI(uri, [ip.itemId]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// adjusted to make sure that items are given the correct index
|
|
|
|
// transactions insert differently if index == -1
|
|
|
|
// transaction will enqueue the item.
|
|
|
|
if (ip.index > -1)
|
|
|
|
index = ip.index + i;
|
|
|
|
txn = PlacesUIUtils.makeTransaction(items[i], type.value,
|
|
|
|
ip.itemId, index, true);
|
|
|
|
}
|
|
|
|
transactions.push(txn);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return transactions;
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
// getAnyTransferData will throw if there is no data of the specified
|
|
|
|
// type on the clipboard.
|
|
|
|
// unwrapNodes will throw if the data that is present is malformed in
|
|
|
|
// some way.
|
2007-07-18 14:39:23 -07:00
|
|
|
// In either case, don't fail horribly, just return no data.
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get transactions to paste any folders, separators or links that might
|
|
|
|
// be on the clipboard, aggregate them and execute them.
|
2007-07-13 17:25:26 -07:00
|
|
|
var transactions = getTransactions([PlacesUtils.TYPE_X_MOZ_PLACE,
|
|
|
|
PlacesUtils.TYPE_X_MOZ_URL,
|
|
|
|
PlacesUtils.TYPE_UNICODE]);
|
2008-03-13 12:25:49 -07:00
|
|
|
var txn = PlacesUIUtils.ptm.aggregateTransactions("Paste", transactions);
|
|
|
|
PlacesUIUtils.ptm.doTransaction(txn);
|
2008-02-06 13:05:23 -08:00
|
|
|
|
|
|
|
// select the pasted items, they should be consecutive
|
|
|
|
var insertedNodeIds = [];
|
|
|
|
for (var i = 0; i < transactions.length; ++i)
|
|
|
|
insertedNodeIds.push(PlacesUtils.bookmarks
|
|
|
|
.getIdForItemAt(ip.itemId, ip.index + i));
|
|
|
|
if (insertedNodeIds.length > 0)
|
2008-07-08 02:33:17 -07:00
|
|
|
this._view.selectItems(insertedNodeIds, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles drag and drop operations for views. Note that this is view agnostic!
|
|
|
|
* You should not use PlacesController._view within these methods, since
|
|
|
|
* the view that the item(s) have been dropped on was not necessarily active.
|
|
|
|
* Drop functions are passed the view that is being dropped on.
|
|
|
|
*/
|
|
|
|
var PlacesControllerDragHelper = {
|
2008-09-19 08:47:45 -07:00
|
|
|
/**
|
|
|
|
* DOM Element currently being dragged over
|
|
|
|
*/
|
|
|
|
currentDropTarget: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Current nsIDOMDataTransfer
|
|
|
|
* We need to cache this because we don't have access to the event in the
|
|
|
|
* treeView's canDrop or drop methods, and session.dataTransfer would not be
|
|
|
|
* filled for drag and drop from external sources (eg. the OS).
|
|
|
|
*/
|
|
|
|
currentDataTransfer: null,
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if the mouse is currently being dragged over a child node of
|
|
|
|
* this menu. This is necessary so that the menu doesn't close while the
|
|
|
|
* mouse is dragging over one of its submenus
|
|
|
|
* @param node
|
|
|
|
* The container node
|
|
|
|
* @returns true if the user is dragging over a node within the hierarchy of
|
|
|
|
* the container, false otherwise.
|
|
|
|
*/
|
|
|
|
draggingOverChildNode: function PCDH_draggingOverChildNode(node) {
|
|
|
|
var currentNode = this.currentDropTarget;
|
|
|
|
while (currentNode) {
|
|
|
|
if (currentNode == node)
|
|
|
|
return true;
|
|
|
|
currentNode = currentNode.parentNode;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns The current active drag session. Returns null if there is none.
|
|
|
|
*/
|
2008-04-19 14:01:19 -07:00
|
|
|
getSession: function PCDH__getSession() {
|
2007-03-22 10:30:00 -07:00
|
|
|
var dragService = Cc["@mozilla.org/widget/dragservice;1"].
|
|
|
|
getService(Ci.nsIDragService);
|
|
|
|
return dragService.getCurrentSession();
|
|
|
|
},
|
|
|
|
|
2008-09-19 08:47:45 -07:00
|
|
|
/**
|
|
|
|
* Extract the first accepted flavor from a flavors array.
|
|
|
|
* @param aFlavors
|
|
|
|
* The flavors array.
|
|
|
|
*/
|
|
|
|
getFirstValidFlavor: function PCDH_getFirstValidFlavor(aFlavors) {
|
|
|
|
for (var i = 0; i < aFlavors.length; i++) {
|
|
|
|
if (this.GENERIC_VIEW_DROP_TYPES.indexOf(aFlavors[i]) != -1)
|
|
|
|
return aFlavors[i];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Determines whether or not the data currently being dragged can be dropped
|
2008-02-16 22:17:34 -08:00
|
|
|
* on a places view.
|
2008-03-14 12:37:37 -07:00
|
|
|
* @param ip
|
|
|
|
* The insertion point where the items should be dropped
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-03-14 12:37:37 -07:00
|
|
|
canDrop: function PCDH_canDrop(ip) {
|
2008-09-19 08:47:45 -07:00
|
|
|
var dt = this.currentDataTransfer;
|
|
|
|
var dropCount = dt.mozItemCount;
|
2008-03-14 12:37:37 -07:00
|
|
|
|
2008-09-19 08:47:45 -07:00
|
|
|
// Check every dragged item
|
|
|
|
for (var i = 0; i < dropCount; i++) {
|
|
|
|
var flavor = this.getFirstValidFlavor(dt.mozTypesAt(i));
|
|
|
|
if (!flavor)
|
|
|
|
return false;
|
2008-03-14 12:37:37 -07:00
|
|
|
|
2008-09-19 08:47:45 -07:00
|
|
|
var data = dt.mozGetDataAt(flavor, i);
|
2008-03-14 12:37:37 -07:00
|
|
|
|
2009-02-19 04:00:05 -08:00
|
|
|
// urls can be dropped on any insertionpoint
|
|
|
|
// XXXmano: // Remember: this method is called for each dragover event!
|
|
|
|
// Thus we shouldn't use unwrapNodes here at all if possible.
|
|
|
|
// I think it would be OK to accept bogus data here (e.g. text which was
|
|
|
|
// somehow wrapped as TAB_DROP_TYPE, this is not in our control, and
|
|
|
|
// will just case the actual drop to be a no-op), and only rule out valid
|
|
|
|
// expected cases, which are either unsupported flavors, or items which
|
|
|
|
// cannot be dropped in the current insertionpoint. The last case will
|
|
|
|
// likely force us to use unwrapNodes for the private data types of
|
|
|
|
// places.
|
|
|
|
if (flavor == TAB_DROP_TYPE)
|
|
|
|
continue;
|
|
|
|
|
2008-09-19 08:47:45 -07:00
|
|
|
try {
|
|
|
|
var dragged = PlacesUtils.unwrapNodes(data, flavor)[0];
|
|
|
|
} catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
2008-04-15 10:17:34 -07:00
|
|
|
|
|
|
|
// Only bookmarks and urls can be dropped into tag containers
|
2008-09-19 08:47:45 -07:00
|
|
|
if (ip.isTag && ip.orientation == Ci.nsITreeView.DROP_ON &&
|
|
|
|
dragged.type != PlacesUtils.TYPE_X_MOZ_URL &&
|
|
|
|
(dragged.type != PlacesUtils.TYPE_X_MOZ_PLACE ||
|
|
|
|
/^place:/.test(dragged.uri)))
|
2008-04-15 10:17:34 -07:00
|
|
|
return false;
|
|
|
|
|
2008-03-14 12:37:37 -07:00
|
|
|
// The following loop disallows the dropping of a folder on itself or
|
|
|
|
// on any of its descendants.
|
|
|
|
if (dragged.type == PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER ||
|
|
|
|
/^place:/.test(dragged.uri)) {
|
|
|
|
var parentId = ip.itemId;
|
|
|
|
while (parentId != PlacesUtils.placesRootId) {
|
|
|
|
if (dragged.concreteId == parentId || dragged.id == parentId)
|
|
|
|
return false;
|
|
|
|
parentId = PlacesUtils.bookmarks.getFolderIdForItem(parentId);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2008-03-14 12:37:37 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2009-02-19 04:00:05 -08:00
|
|
|
|
2008-04-25 14:36:40 -07:00
|
|
|
/**
|
2008-09-19 08:47:45 -07:00
|
|
|
* Determines if a node can be moved.
|
2008-04-25 14:36:40 -07:00
|
|
|
*
|
|
|
|
* @param aNode
|
2008-09-19 08:47:45 -07:00
|
|
|
* A nsINavHistoryResultNode node.
|
|
|
|
* @returns True if the node can be moved, false otherwise.
|
2008-04-25 14:36:40 -07:00
|
|
|
*/
|
2008-09-19 08:47:45 -07:00
|
|
|
canMoveNode:
|
|
|
|
function PCDH_canMoveNode(aNode) {
|
2008-04-25 14:36:40 -07:00
|
|
|
// can't move query root
|
|
|
|
if (!aNode.parent)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
var parentId = PlacesUtils.getConcreteItemId(aNode.parent);
|
|
|
|
var concreteId = PlacesUtils.getConcreteItemId(aNode);
|
|
|
|
|
2008-09-19 08:47:45 -07:00
|
|
|
// can't move children of tag containers
|
|
|
|
if (PlacesUtils.nodeIsTagQuery(aNode.parent))
|
2008-04-25 14:36:40 -07:00
|
|
|
return false;
|
|
|
|
|
2008-09-19 08:47:45 -07:00
|
|
|
// can't move children of read-only containers
|
2008-04-25 14:36:40 -07:00
|
|
|
if (PlacesUtils.nodeIsReadOnly(aNode.parent))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// check for special folders, etc
|
2008-09-19 08:47:45 -07:00
|
|
|
if (PlacesUtils.nodeIsContainer(aNode) &&
|
2008-09-19 15:20:08 -07:00
|
|
|
!this.canMoveContainer(aNode.itemId, parentId))
|
2008-04-25 14:36:40 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if a container node can be moved.
|
|
|
|
*
|
|
|
|
* @param aId
|
|
|
|
* A bookmark folder id.
|
|
|
|
* @param [optional] aParentId
|
|
|
|
* The parent id of the folder.
|
|
|
|
* @returns True if the container can be moved to the target.
|
|
|
|
*/
|
|
|
|
canMoveContainer:
|
|
|
|
function PCDH_canMoveContainer(aId, aParentId) {
|
|
|
|
if (aId == -1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Disallow moving of roots and special folders
|
|
|
|
const ROOTS = [PlacesUtils.placesRootId, PlacesUtils.bookmarksMenuFolderId,
|
|
|
|
PlacesUtils.tagsFolderId, PlacesUtils.unfiledBookmarksFolderId,
|
|
|
|
PlacesUtils.toolbarFolderId];
|
|
|
|
if (ROOTS.indexOf(aId) != -1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Get parent id if necessary
|
|
|
|
if (aParentId == null || aParentId == -1)
|
|
|
|
aParentId = PlacesUtils.bookmarks.getFolderIdForItem(aId);
|
|
|
|
|
2008-09-19 08:47:45 -07:00
|
|
|
if (PlacesUtils.bookmarks.getFolderReadonly(aParentId))
|
2008-04-25 14:36:40 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Handles the drop of one or more items onto a view.
|
|
|
|
* @param insertionPoint
|
|
|
|
* The insertion point where the items should be dropped
|
|
|
|
*/
|
2008-01-29 12:04:43 -08:00
|
|
|
onDrop: function PCDH_onDrop(insertionPoint) {
|
2008-09-19 08:47:45 -07:00
|
|
|
var dt = this.currentDataTransfer;
|
|
|
|
var doCopy = dt.dropEffect == "copy";
|
2007-10-24 19:02:28 -07:00
|
|
|
|
2008-09-19 08:47:45 -07:00
|
|
|
var transactions = [];
|
|
|
|
var dropCount = dt.mozItemCount;
|
2007-08-02 22:52:05 -07:00
|
|
|
var movedCount = 0;
|
|
|
|
for (var i = 0; i < dropCount; ++i) {
|
2008-09-19 08:47:45 -07:00
|
|
|
var flavor = this.getFirstValidFlavor(dt.mozTypesAt(i));
|
|
|
|
if (!flavor)
|
|
|
|
return false;
|
2007-10-24 19:02:28 -07:00
|
|
|
|
2008-09-19 08:47:45 -07:00
|
|
|
var data = dt.mozGetDataAt(flavor, i);
|
2009-02-19 04:00:05 -08:00
|
|
|
var unwrapped;
|
|
|
|
if (flavor != TAB_DROP_TYPE) {
|
|
|
|
// There's only ever one in the D&D case.
|
|
|
|
unwrapped = PlacesUtils.unwrapNodes(data, flavor)[0];
|
|
|
|
}
|
|
|
|
else if (data instanceof XULElement && data.localName == "tab" &&
|
|
|
|
data.ownerDocument.defaultView instanceof ChromeWindow) {
|
|
|
|
var uri = data.linkedBrowser.currentURI;
|
|
|
|
var spec = uri ? uri.spec : "about:blank";
|
|
|
|
var title = data.label;
|
|
|
|
unwrapped = { uri: spec,
|
|
|
|
title: data.label,
|
|
|
|
type: PlacesUtils.TYPE_X_MOZ_URL};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
throw("bogus data was passed as a tab")
|
2008-04-25 14:36:40 -07:00
|
|
|
|
2007-08-02 22:52:05 -07:00
|
|
|
var index = insertionPoint.index;
|
2007-10-24 19:02:28 -07:00
|
|
|
|
2007-08-02 22:52:05 -07:00
|
|
|
// Adjust insertion index to prevent reversal of dragged items. When you
|
|
|
|
// drag multiple elts upward: need to increment index or each successive
|
|
|
|
// elt will be inserted at the same index, each above the previous.
|
2008-09-19 08:47:45 -07:00
|
|
|
var dragginUp = insertionPoint.itemId == unwrapped.parent &&
|
|
|
|
index < PlacesUtils.bookmarks.getItemIndex(unwrapped.id);
|
|
|
|
if (index != -1 && dragginUp)
|
|
|
|
index+= movedCount++;
|
2007-10-24 19:02:28 -07:00
|
|
|
|
2008-04-11 09:22:01 -07:00
|
|
|
// if dragging over a tag container we should tag the item
|
2008-09-19 08:47:45 -07:00
|
|
|
if (insertionPoint.isTag &&
|
|
|
|
insertionPoint.orientation == Ci.nsITreeView.DROP_ON) {
|
2008-04-11 09:22:01 -07:00
|
|
|
var uri = PlacesUtils._uri(unwrapped.uri);
|
|
|
|
var tagItemId = insertionPoint.itemId;
|
|
|
|
transactions.push(PlacesUIUtils.ptm.tagURI(uri,[tagItemId]));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
transactions.push(PlacesUIUtils.makeTransaction(unwrapped,
|
2008-09-19 08:47:45 -07:00
|
|
|
flavor, insertionPoint.itemId,
|
|
|
|
index, doCopy));
|
2008-04-11 09:22:01 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-03-13 12:25:49 -07:00
|
|
|
var txn = PlacesUIUtils.ptm.aggregateTransactions("DropItems", transactions);
|
|
|
|
PlacesUIUtils.ptm.doTransaction(txn);
|
2008-09-19 08:47:45 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if we can insert into a container.
|
|
|
|
* @param aContainer
|
|
|
|
* The container were we are want to drop
|
|
|
|
*/
|
|
|
|
disallowInsertion: function(aContainer) {
|
|
|
|
NS_ASSERT(aContainer, "empty container");
|
|
|
|
// allow dropping into Tag containers
|
|
|
|
if (PlacesUtils.nodeIsTagQuery(aContainer))
|
|
|
|
return false;
|
|
|
|
// Disallow insertion of items under readonly folders
|
|
|
|
return (!PlacesUtils.nodeIsFolder(aContainer) ||
|
|
|
|
PlacesUtils.nodeIsReadOnly(aContainer));
|
|
|
|
},
|
|
|
|
|
|
|
|
placesFlavors: [PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER,
|
|
|
|
PlacesUtils.TYPE_X_MOZ_PLACE_SEPARATOR,
|
|
|
|
PlacesUtils.TYPE_X_MOZ_PLACE],
|
|
|
|
|
2009-02-19 04:00:05 -08:00
|
|
|
// The order matters.
|
2008-09-19 08:47:45 -07:00
|
|
|
GENERIC_VIEW_DROP_TYPES: [PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER,
|
|
|
|
PlacesUtils.TYPE_X_MOZ_PLACE_SEPARATOR,
|
|
|
|
PlacesUtils.TYPE_X_MOZ_PLACE,
|
|
|
|
PlacesUtils.TYPE_X_MOZ_URL,
|
2009-02-19 04:00:05 -08:00
|
|
|
TAB_DROP_TYPE,
|
2008-09-19 08:47:45 -07:00
|
|
|
PlacesUtils.TYPE_UNICODE],
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns our flavourSet
|
|
|
|
*/
|
|
|
|
get flavourSet() {
|
|
|
|
delete this.flavourSet;
|
|
|
|
var flavourSet = new FlavourSet();
|
|
|
|
var acceptedDropFlavours = this.GENERIC_VIEW_DROP_TYPES;
|
|
|
|
acceptedDropFlavours.forEach(flavourSet.appendFlavour, flavourSet);
|
|
|
|
return this.flavourSet = flavourSet;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function goUpdatePlacesCommands() {
|
2009-06-10 11:00:30 -07:00
|
|
|
// Get the controller for one of the places commands.
|
|
|
|
var placesController = doGetPlacesControllerForCommand("placesCmd_open");
|
|
|
|
if (!placesController)
|
|
|
|
return;
|
2007-09-19 01:13:20 -07:00
|
|
|
|
|
|
|
function updatePlacesCommand(aCommand) {
|
2009-06-10 11:00:30 -07:00
|
|
|
goSetCommandEnabled(aCommand, placesController.isCommandEnabled(aCommand));
|
2007-09-19 01:13:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
updatePlacesCommand("placesCmd_open");
|
|
|
|
updatePlacesCommand("placesCmd_open:window");
|
|
|
|
updatePlacesCommand("placesCmd_open:tab");
|
|
|
|
updatePlacesCommand("placesCmd_new:folder");
|
|
|
|
updatePlacesCommand("placesCmd_new:bookmark");
|
|
|
|
updatePlacesCommand("placesCmd_new:livemark");
|
|
|
|
updatePlacesCommand("placesCmd_new:separator");
|
|
|
|
updatePlacesCommand("placesCmd_show:info");
|
|
|
|
updatePlacesCommand("placesCmd_moveBookmarks");
|
|
|
|
updatePlacesCommand("placesCmd_reload");
|
|
|
|
updatePlacesCommand("placesCmd_reloadMicrosummary");
|
|
|
|
updatePlacesCommand("placesCmd_sortBy:name");
|
2009-06-10 11:00:30 -07:00
|
|
|
updatePlacesCommand("placesCmd_cut");
|
|
|
|
updatePlacesCommand("placesCmd_copy");
|
|
|
|
updatePlacesCommand("placesCmd_paste");
|
|
|
|
updatePlacesCommand("placesCmd_delete");
|
|
|
|
}
|
|
|
|
|
|
|
|
function doGetPlacesControllerForCommand(aCommand)
|
|
|
|
{
|
|
|
|
var placesController = top.document.commandDispatcher
|
|
|
|
.getControllerForCommand(aCommand);
|
|
|
|
if (!placesController) {
|
|
|
|
// If building commands for a context menu, look for an element in the
|
|
|
|
// current popup.
|
|
|
|
var element = document.popupNode;
|
|
|
|
while (element) {
|
|
|
|
var isContextMenuShown = ("_contextMenuShown" in element) && element._contextMenuShown;
|
|
|
|
// Check for the parent menupopup or the hbox used for toolbars
|
|
|
|
if ((element.localName == "menupopup" || element.localName == "hbox") &&
|
|
|
|
isContextMenuShown) {
|
|
|
|
placesController = element.controllers.getControllerForCommand(aCommand);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
element = element.parentNode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return placesController;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-06-10 11:00:30 -07:00
|
|
|
|
|
|
|
function goDoPlacesCommand(aCommand)
|
|
|
|
{
|
|
|
|
var controller = doGetPlacesControllerForCommand(aCommand);
|
|
|
|
if (controller && controller.isCommandEnabled(aCommand))
|
|
|
|
controller.doCommand(aCommand);
|
|
|
|
}
|
|
|
|
|