86 this.itemId = aItemId;
88 this.orientation = aOrientation;
90 this.dropNearItemId = aDropNearItemId;
95 return this._index =
val;
99 if (this.dropNearItemId > 0) {
102 var index = PlacesUtils.bookmarks.getItemIndex(this.dropNearItemId);
103 return this.orientation ==
Ci.nsITreeView.DROP_BEFORE ? index : index + 1;
123 isCommandEnabled:
function PC_isCommandEnabled(aCommand) {
130 case "placesCmd_cut":
131 var nodes = this._view.getSelectionNodes();
133 for (var
i = 0;
i < nodes.length;
i++) {
134 if (nodes[
i].itemId == -1)
139 case "placesCmd_delete":
140 return this._hasRemovableSelection(
false);
141 case "placesCmd_deleteDataHost":
142 return this._hasRemovableSelection(
false) &&
144 case "placesCmd_moveBookmarks":
145 return this._hasRemovableSelection(
true);
147 case "placesCmd_copy":
148 return this._view.hasSelection;
150 case "placesCmd_paste":
151 return this._canInsert(
true) && this._isClipboardDataPasteable();
152 case "cmd_selectAll":
153 if (this._view.selType !=
"single") {
154 var rootNode = this._view.getResultNode();
155 if (rootNode.containerOpen && rootNode.childCount > 0)
159 case "placesCmd_open":
160 case "placesCmd_open:window":
161 case "placesCmd_open:tab":
162 var selectedNode = this._view.selectedNode;
163 return selectedNode && PlacesUtils.nodeIsURI(selectedNode);
164 case "placesCmd_new:folder":
165 case "placesCmd_new:livemark":
166 return this._canInsert();
167 case "placesCmd_new:bookmark":
168 return this._canInsert();
169 case "placesCmd_new:separator":
170 return this._canInsert() &&
171 !
asQuery(this._view.getResultNode()).queryOptions.excludeItems &&
172 this._view.getResult().sortingMode ==
173 Ci.nsINavHistoryQueryOptions.SORT_BY_NONE;
174 case "placesCmd_show:info":
175 var selectedNode = this._view.selectedNode;
177 PlacesUtils.getConcreteItemId(selectedNode) != -1 &&
178 !PlacesUtils.nodeIsLivemarkItem(selectedNode))
181 case "placesCmd_reloadMicrosummary":
182 var selectedNode = this._view.selectedNode;
183 return selectedNode && PlacesUtils.nodeIsBookmark(selectedNode) &&
184 PlacesUIUtils.microsummaries.hasMicrosummary(selectedNode.itemId);
185 case "placesCmd_reload":
187 var selectedNode = this._view.selectedNode;
188 return selectedNode && PlacesUtils.nodeIsLivemarkContainer(selectedNode);
189 case "placesCmd_sortBy:name":
190 var selectedNode = this._view.selectedNode;
191 return selectedNode &&
192 PlacesUtils.nodeIsFolder(selectedNode) &&
193 !PlacesUtils.nodeIsReadOnly(selectedNode) &&
194 this._view.getResult().sortingMode ==
195 Ci.nsINavHistoryQueryOptions.SORT_BY_NONE;
196 case "placesCmd_createBookmark":
197 var
node = this._view.selectedNode;
198 return node && PlacesUtils.nodeIsURI(node) && node.itemId == -1;
204 supportsCommand:
function PC_supportsCommand(aCommand) {
214 case "cmd_selectAll":
220 const CMD_PREFIX =
"placesCmd_";
221 return (aCommand.substr(0, CMD_PREFIX.length) == CMD_PREFIX);
224 doCommand:
function PC_doCommand(aCommand) {
233 case "placesCmd_cut":
237 case "placesCmd_copy":
241 case "placesCmd_paste":
245 case "placesCmd_delete":
246 this.
remove(
"Remove Selection");
248 case "placesCmd_deleteDataHost":
250 if (PlacesUtils.nodeIsHost(
this._view.selectedNode)) {
251 var queries = this._view.selectedNode.getQueries({});
252 host = queries[0].domain;
255 host = PlacesUtils._uri(this._view.selectedNode.uri).host;
258 case "cmd_selectAll":
261 case "placesCmd_open":
262 PlacesUIUtils.openNodeIn(this._view.selectedNode,
"current");
264 case "placesCmd_open:window":
267 case "placesCmd_open:tab":
270 case "placesCmd_new:folder":
271 this.newItem(
"folder");
273 case "placesCmd_new:bookmark":
274 this.newItem(
"bookmark");
276 case "placesCmd_new:livemark":
277 this.newItem(
"livemark");
279 case "placesCmd_new:separator":
282 case "placesCmd_show:info":
283 this.showBookmarkPropertiesForSelection();
285 case "placesCmd_moveBookmarks":
286 this.moveSelectedBookmarks();
288 case "placesCmd_reload":
289 this.reloadSelectedLivemark();
291 case "placesCmd_reloadMicrosummary":
292 this.reloadSelectedMicrosummary();
294 case "placesCmd_sortBy:name":
295 this.sortFolderByName();
297 case "placesCmd_createBookmark":
298 var
node = this._view.selectedNode;
299 PlacesUIUtils.showMinimalAddBookmarkUI(PlacesUtils._uri(node.uri), node.title);
304 onEvent:
function PC_onEvent(eventName) { },
319 _hasRemovableSelection:
function PC__hasRemovableSelection(aIsMoveCommand) {
320 var ranges = this._view.getRemovableSelectionRanges();
324 var root = this._view.getResultNode();
326 for (var j = 0; j < ranges.length; j++) {
327 var nodes = ranges[j];
328 for (var
i = 0;
i < nodes.length; ++
i) {
330 if (nodes[
i] == root)
333 if (PlacesUtils.nodeIsFolder(nodes[
i]) &&
346 var parent = nodes[
i].parent || root;
347 if (PlacesUtils.isReadonlyFolder(parent))
358 _canInsert:
function PC__canInsert(isPaste) {
359 var ip = this._view.insertionPoint;
360 return ip !=
null && (isPaste || ip.isTag !=
true);
366 rootNodeIsSelected:
function PC_rootNodeIsSelected() {
367 var nodes = this._view.getSelectionNodes();
368 var root = this._view.getResultNode();
369 for (var
i = 0;
i < nodes.length; ++
i) {
370 if (nodes[
i] == root)
385 _isClipboardDataPasteable:
function PC__isClipboardDataPasteable() {
392 clipboard.hasDataMatchingFlavors(flavors, flavors.length,
393 Ci.nsIClipboard.kGlobalClipboard);
395 return this._view.insertionPoint !=
null;
399 var xferable =
Cc[
"@mozilla.org/widget/transferable;1"].
402 xferable.addDataFlavor(PlacesUtils.TYPE_X_MOZ_URL);
403 xferable.addDataFlavor(PlacesUtils.TYPE_UNICODE);
404 clipboard.getData(xferable,
Ci.nsIClipboard.kGlobalClipboard);
408 var
data = { }, type = { };
409 xferable.getAnyTransferData(type, data, { });
410 data = data.value.QueryInterface(
Ci.nsISupportsString).data;
411 if (type.value != PlacesUtils.TYPE_X_MOZ_URL &&
412 type.value != PlacesUtils.TYPE_UNICODE)
416 var unwrappedNodes = PlacesUtils.unwrapNodes(data, type.value);
417 return this._view.insertionPoint !=
null;
447 _buildSelectionMetadata:
function PC__buildSelectionMetadata() {
449 var root = this._view.getResultNode();
450 var nodes = this._view.getSelectionNodes();
451 if (nodes.length == 0)
454 for (var
i=0;
i < nodes.length;
i++) {
457 var nodeType = node.type;
463 case Ci.nsINavHistoryResultNode.RESULT_TYPE_QUERY:
464 nodeData[
"query"] =
true;
466 switch (
asQuery(node.parent).queryOptions.resultType) {
467 case Ci.nsINavHistoryQueryOptions.RESULTS_AS_SITE_QUERY:
468 nodeData[
"host"] =
true;
470 case Ci.nsINavHistoryQueryOptions.RESULTS_AS_DATE_SITE_QUERY:
471 case Ci.nsINavHistoryQueryOptions.RESULTS_AS_DATE_QUERY:
472 nodeData[
"day"] =
true;
477 case Ci.nsINavHistoryResultNode.RESULT_TYPE_DYNAMIC_CONTAINER:
478 nodeData[
"dynamiccontainer"] =
true;
480 case Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER:
481 case Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER_SHORTCUT:
482 nodeData[
"folder"] =
true;
484 case Ci.nsINavHistoryResultNode.RESULT_TYPE_SEPARATOR:
485 nodeData[
"separator"] =
true;
487 case Ci.nsINavHistoryResultNode.RESULT_TYPE_URI:
488 case Ci.nsINavHistoryResultNode.RESULT_TYPE_VISIT:
489 case Ci.nsINavHistoryResultNode.RESULT_TYPE_FULL_VISIT:
490 nodeData[
"link"] =
true;
491 uri = PlacesUtils._uri(node.uri);
492 if (PlacesUtils.nodeIsBookmark(node)) {
493 nodeData[
"bookmark"] =
true;
494 PlacesUtils.nodeIsTagQuery(node.parent)
496 if (mss.hasMicrosummary(node.itemId))
497 nodeData[
"microsummary"] =
true;
499 var parentNode = node.parent;
501 if (PlacesUtils.nodeIsTagQuery(parentNode))
502 nodeData[
"tagChild"] =
true;
503 else if (PlacesUtils.nodeIsLivemarkContainer(parentNode))
504 nodeData[
"livemarkChild"] =
true;
512 var names = PlacesUtils.annotations.getPageAnnotationNames(uri, {});
513 for (var j = 0; j < names.length; ++j)
514 nodeData[names[j]] =
true;
518 if (node.itemId != -1) {
519 names = PlacesUtils.annotations
520 .getItemAnnotationNames(node.itemId, {});
521 for (j = 0; j < names.length; ++j)
522 nodeData[names[j]] =
true;
524 metadata.push(nodeData);
539 _shouldShowMenuItem:
function PC__shouldShowMenuItem(
aMenuItem, aMetaData) {
540 var selectiontype =
aMenuItem.getAttribute(
"selectiontype");
541 if (selectiontype ==
"multiple" && aMetaData.length == 1)
543 if (selectiontype ==
"single" && aMetaData.length != 1)
546 var forceHideAttr =
aMenuItem.getAttribute(
"forcehideselection");
548 var forceHideRules = forceHideAttr.split(
"|");
549 for (var
i = 0;
i < aMetaData.length; ++
i) {
550 for (var j=0; j < forceHideRules.length; ++j) {
551 if (forceHideRules[j] in aMetaData[
i])
557 var selectionAttr =
aMenuItem.getAttribute(
"selection");
559 if (selectionAttr ==
"any")
562 var showRules = selectionAttr.split(
"|");
563 var anyMatched =
false;
564 function metaDataNodeMatches(metaDataNode, rules) {
565 for (var
i=0;
i < rules.length;
i++) {
566 if (rules[
i] in metaDataNode)
572 for (var
i = 0;
i < aMetaData.length; ++
i) {
573 if (metaDataNodeMatches(aMetaData[
i], showRules))
617 buildContextMenu:
function PC_buildContextMenu(aPopup) {
618 var metadata = this._buildSelectionMetadata();
619 var ip = this._view.insertionPoint;
620 var noIp = !ip || ip.isTag;
622 var separator =
null;
623 var visibleItemsBeforeSep =
false;
624 var anyVisible =
false;
625 for (var
i = 0;
i < aPopup.childNodes.length; ++
i) {
626 var item = aPopup.childNodes[
i];
627 if (item.localName !=
"menuseparator") {
629 var hideIfNoIP = item.getAttribute(
"hideifnoinsertionpoint") ==
"true" &&
630 noIp && !(ip && ip.isTag && item.id ==
"placesContext_paste");
631 var hideIfPB = item.getAttribute(
"hideifprivatebrowsing") ==
"true" &&
633 item.hidden = hideIfNoIP || hideIfPB ||
634 !this._shouldShowMenuItem(item, metadata);
637 visibleItemsBeforeSep =
true;
642 separator.hidden =
false;
653 if (visibleItemsBeforeSep)
657 visibleItemsBeforeSep =
false;
663 var openContainerInTabsItem = document.getElementById(
"placesContext_openContainer:tabs");
664 if (!openContainerInTabsItem.hidden &&
this._view.selectedNode &&
665 PlacesUtils.nodeIsContainer(
this._view.selectedNode)) {
666 openContainerInTabsItem.disabled =
667 !PlacesUtils.hasChildURIs(this._view.selectedNode);
671 var openLinksInTabsItem = document.getElementById(
"placesContext_openLinks:tabs");
672 openLinksInTabsItem.disabled = openLinksInTabsItem.hidden;
682 selectAll:
function PC_selectAll() {
683 this._view.selectAll();
689 showBookmarkPropertiesForSelection:
690 function PC_showBookmarkPropertiesForSelection() {
691 var node = this._view.selectedNode;
695 var itemType = PlacesUtils.nodeIsFolder(node) ||
696 PlacesUtils.nodeIsTagQuery(node) ?
"folder" :
"bookmark";
697 var concreteId = PlacesUtils.getConcreteItemId(node);
698 var isRootItem = PlacesUtils.isRootItem(concreteId);
699 var itemId = node.itemId;
700 if (isRootItem || PlacesUtils.nodeIsTagQuery(node)) {
714 _assertURINotString:
function PC__assertURINotString(
value) {
716 "This method should be passed a URI as a nsIURI object, not as a string.");
722 reloadSelectedLivemark:
function PC_reloadSelectedLivemark() {
723 var selectedNode = this._view.selectedNode;
724 if (selectedNode && PlacesUtils.nodeIsLivemarkContainer(selectedNode))
725 PlacesUtils.livemarks.reloadLivemarkFolder(selectedNode.itemId);
731 reloadSelectedMicrosummary:
function PC_reloadSelectedMicrosummary() {
732 var selectedNode = this._view.selectedNode;
734 if (mss.hasMicrosummary(selectedNode.itemId))
735 mss.refreshMicrosummary(selectedNode.itemId);
741 _confirmOpenTabs:
function(numTabsToOpen) {
742 var
pref =
Cc[
"@mozilla.org/preferences-service;1"].
745 const kWarnOnOpenPref =
"browser.tabs.warnOnOpen";
746 var reallyOpen =
true;
747 if (pref.getBoolPref(kWarnOnOpenPref)) {
748 if (numTabsToOpen >= pref.getIntPref(
"browser.tabs.maxOpenBeforeWarn")) {
753 var warnOnOpen = {
value:
true };
755 var messageKey =
"tabs.openWarningMultipleBranded";
756 var openKey =
"tabs.openButtonMultiple";
757 var
strings = document.getElementById(
"placeBundle");
758 const BRANDING_BUNDLE_URI =
"chrome://branding/locale/brand.properties";
759 var brandShortName =
Cc[
"@mozilla.org/intl/stringbundle;1"].
761 createBundle(BRANDING_BUNDLE_URI).
762 GetStringFromName(
"brandShortName");
764 var buttonPressed = promptService.confirmEx(
window,
767 [numTabsToOpen, brandShortName]),
768 (promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0)
769 + (promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1),
772 PlacesUIUtils.getFormattedString(
"tabs.openWarningPromptMeBranded",
776 reallyOpen = (buttonPressed == 0);
778 if (reallyOpen && !warnOnOpen.value)
779 pref.setBoolPref(kWarnOnOpenPref,
false);
788 openSelectionInTabs:
function PC_openLinksInTabs(aEvent) {
789 var node = this._view.selectedNode;
790 if (node && PlacesUtils.nodeIsContainer(node))
791 PlacesUIUtils.openContainerNodeInTabs(
this._view.selectedNode, aEvent);
793 PlacesUIUtils.openURINodesInTabs(this._view.getSelectionNodes(), aEvent);
802 newItem:
function PC_newItem(aType) {
803 var ip = this._view.insertionPoint;
805 throw Cr.NS_ERROR_NOT_AVAILABLE;
807 var performed =
false;
808 if (aType ==
"bookmark")
809 performed =
PlacesUIUtils.showAddBookmarkUI(null, null, null, ip);
810 else if (aType ==
"livemark")
811 performed =
PlacesUIUtils.showAddLivemarkUI(null, null, null, null, ip);
817 var insertedNodeId = PlacesUtils.bookmarks
818 .getIdForItemAt(ip.itemId, ip.index);
819 this._view.selectItems([insertedNodeId],
false);
828 newFolder:
function PC_newFolder() {
829 var ip = this._view.insertionPoint;
831 throw Cr.NS_ERROR_NOT_AVAILABLE;
833 var performed =
false;
837 var insertedNodeId = PlacesUtils.bookmarks
838 .getIdForItemAt(ip.itemId, ip.index);
839 this._view.selectItems([insertedNodeId],
false);
846 newSeparator:
function PC_newSeparator() {
847 var ip = this._view.insertionPoint;
849 throw Cr.NS_ERROR_NOT_AVAILABLE;
850 var txn =
PlacesUIUtils.ptm.createSeparator(ip.itemId, ip.index);
853 var insertedNodeId = PlacesUtils.bookmarks
854 .getIdForItemAt(ip.itemId, ip.index);
855 this._view.selectItems([insertedNodeId],
false);
861 moveSelectedBookmarks:
function PC_moveBookmarks() {
862 window.openDialog(
"chrome://browser/content/places/moveBookmarks.xul",
864 this._view.getSelectionNodes());
870 sortFolderByName:
function PC_sortFolderByName() {
871 var itemId = PlacesUtils.getConcreteItemId(this._view.selectedNode);
886 _shouldSkipNode:
function PC_shouldSkipNode(node, pastFolders) {
895 function isContainedBy(node, parent) {
896 var cursor = node.parent;
898 if (cursor == parent)
900 cursor = cursor.parent;
905 for (var j = 0; j < pastFolders.length; ++j) {
906 if (isContainedBy(node, pastFolders[j]))
922 _removeRange:
function PC__removeRange(
range, transactions, removedFolders) {
923 NS_ASSERT(transactions instanceof
Array,
"Must pass a transactions array");
927 for (var
i = 0;
i <
range.length; ++
i) {
929 if (this._shouldSkipNode(node, removedFolders))
932 if (PlacesUtils.nodeIsTagQuery(node.parent)) {
935 var tagItemId = PlacesUtils.getConcreteItemId(node.parent);
936 var uri = PlacesUtils._uri(node.uri);
937 transactions.push(
PlacesUIUtils.ptm.untagURI(uri, [tagItemId]));
939 else if (PlacesUtils.nodeIsTagQuery(node) && node.parent &&
940 PlacesUtils.nodeIsQuery(node.parent) &&
941 asQuery(node.parent).queryOptions.resultType ==
942 Ci.nsINavHistoryQueryOptions.RESULTS_AS_TAG_QUERY) {
947 var
tag = node.title;
948 var URIs = PlacesUtils.tagging.getURIsForTag(tag);
949 for (var j = 0; j < URIs.length; j++)
950 transactions.push(
PlacesUIUtils.ptm.untagURI(URIs[j], [tag]));
952 else if (PlacesUtils.nodeIsURI(node) &&
953 PlacesUtils.nodeIsQuery(node.parent) &&
954 asQuery(node.parent).queryOptions.queryType ==
955 Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY) {
957 var
bhist = PlacesUtils.history.QueryInterface(
Ci.nsIBrowserHistory);
958 bhist.removePage(PlacesUtils._uri(node.uri));
961 else if (node.itemId == -1 &&
962 PlacesUtils.nodeIsQuery(node) &&
963 asQuery(node).queryOptions.queryType ==
964 Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY) {
968 this._removeHistoryContainer(node);
973 if (PlacesUtils.nodeIsFolder(node)) {
976 removedFolders.push(node);
978 transactions.push(
PlacesUIUtils.ptm.removeItem(node.itemId));
988 _removeRowsFromBookmarks:
function PC__removeRowsFromBookmarks(txnName) {
989 var ranges = this._view.getRemovableSelectionRanges();
990 var transactions = [];
991 var removedFolders = [];
993 for (var
i = 0;
i < ranges.length;
i++)
994 this._removeRange(ranges[
i], transactions, removedFolders);
996 if (transactions.length > 0) {
997 var txn =
PlacesUIUtils.ptm.aggregateTransactions(txnName, transactions);
1005 _removeRowsFromHistory:
function PC__removeRowsFromHistory() {
1008 var nodes = this._view.getSelectionNodes();
1010 var bhist = PlacesUtils.history.QueryInterface(
Ci.nsIBrowserHistory);
1011 var root = this._view.getResultNode();
1013 for (var i = 0; i < nodes.length; ++
i) {
1014 var node = nodes[
i];
1015 if (PlacesUtils.nodeIsURI(node)) {
1016 var uri = PlacesUtils._uri(node.uri);
1018 if (URIs.indexOf(uri) < 0) {
1022 else if (PlacesUtils.nodeIsQuery(node) &&
1023 asQuery(node).queryOptions.queryType ==
1024 Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY)
1025 this._removeHistoryContainer(node);
1036 bhist.removePages(URIslice, URIslice.length,
1043 for (var i = 0; i < URIs.length; ++
i)
1044 bhist.removePage(URIs[i]);
1053 _removeHistoryContainer:
function PC_removeHistoryContainer(aContainerNode) {
1054 var bhist = PlacesUtils.history.QueryInterface(
Ci.nsIBrowserHistory);
1055 if (PlacesUtils.nodeIsHost(aContainerNode)) {
1057 bhist.removePagesFromHost(aContainerNode.title,
true);
1059 else if (PlacesUtils.nodeIsDay(aContainerNode)) {
1061 var query = aContainerNode.getQueries({})[0];
1062 var beginTime = query.beginTime;
1063 var endTime = query.endTime;
1064 NS_ASSERT(query && beginTime && endTime,
1065 "A valid date container query should exist!");
1070 bhist.removePagesByTimeframe(beginTime+1, endTime);
1080 remove:
function PC_remove(aTxnName) {
1081 if (!this._hasRemovableSelection(
false))
1084 NS_ASSERT(aTxnName !== undefined,
"Must supply Transaction Name");
1086 var root = this._view.getResultNode();
1088 if (PlacesUtils.nodeIsFolder(root))
1089 this._removeRowsFromBookmarks(aTxnName);
1090 else if (PlacesUtils.nodeIsQuery(root)) {
1091 var queryType =
asQuery(root).queryOptions.queryType;
1092 if (queryType ==
Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS)
1093 this._removeRowsFromBookmarks(aTxnName);
1094 else if (queryType ==
Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY)
1095 this._removeRowsFromHistory();
1097 NS_ASSERT(
false,
"implement support for QUERY_TYPE_UNIFIED");
1109 setDataTransfer:
function PC_setDataTransfer(aEvent) {
1110 var dt = aEvent.dataTransfer;
1111 var doCopy = [
"copyLink",
"copy",
"link"].indexOf(dt.effectAllowed) != -1;
1113 var result = this._view.getResult();
1114 var oldViewer = result.viewer;
1116 result.viewer =
null;
1117 var nodes = this._view.getDraggableSelection();
1119 for (var i = 0; i < nodes.length; ++
i) {
1120 var node = nodes[
i];
1122 function addData(type, index, overrideURI) {
1123 var wrapNode = PlacesUtils.wrapNode(node, type, overrideURI, doCopy);
1124 dt.mozSetDataAt(type, wrapNode, index);
1127 function addURIData(index, overrideURI) {
1128 addData(PlacesUtils.TYPE_X_MOZ_URL, index, overrideURI);
1129 addData(PlacesUtils.TYPE_UNICODE, index, overrideURI);
1130 addData(PlacesUtils.TYPE_HTML, index, overrideURI);
1135 addData(PlacesUtils.TYPE_X_MOZ_PLACE, i);
1138 if (PlacesUtils.nodeIsLivemarkContainer(node))
1139 addURIData(i, PlacesUtils.livemarks.getFeedURI(node.itemId).spec);
1146 result.viewer = oldViewer;
1153 copy:
function PC_copy() {
1154 var result = this._view.getResult();
1155 var oldViewer = result.viewer;
1157 result.viewer =
null;
1158 var nodes = this._view.getSelectionNodes();
1160 var xferable =
Cc[
"@mozilla.org/widget/transferable;1"].
1162 var foundFolder =
false, foundLink =
false;
1163 var copiedFolders = [];
1164 var placeString, mozURLString, htmlString, unicodeString;
1165 placeString = mozURLString = htmlString = unicodeString =
"";
1167 for (var i = 0; i < nodes.length; ++
i) {
1168 var node = nodes[
i];
1169 if (this._shouldSkipNode(node, copiedFolders))
1171 if (PlacesUtils.nodeIsFolder(node))
1172 copiedFolders.push(node);
1174 function generateChunk(type, overrideURI) {
1175 var suffix = i < (nodes.length - 1) ?
NEWLINE :
"";
1176 var uri = overrideURI;
1178 if (PlacesUtils.nodeIsLivemarkContainer(node))
1179 uri = PlacesUtils.livemarks.getFeedURI(node.itemId).spec
1181 mozURLString += (PlacesUtils.wrapNode(node, PlacesUtils.TYPE_X_MOZ_URL,
1183 unicodeString += (PlacesUtils.wrapNode(node, PlacesUtils.TYPE_UNICODE,
1185 htmlString += (PlacesUtils.wrapNode(node, PlacesUtils.TYPE_HTML,
1188 var placeSuffix = i < (nodes.length - 1) ?
"," :
"";
1190 return PlacesUtils.wrapNode(node, type, overrideURI, resolveShortcuts) + placeSuffix;
1194 placeString += generateChunk(PlacesUtils.TYPE_X_MOZ_PLACE);
1197 function addData(type, data) {
1198 xferable.addDataFlavor(type);
1199 xferable.setTransferData(type,
PlacesUIUtils._wrapString(data), data.length * 2);
1204 addData(PlacesUtils.TYPE_X_MOZ_PLACE, placeString);
1206 addData(PlacesUtils.TYPE_X_MOZ_URL, mozURLString);
1208 addData(PlacesUtils.TYPE_UNICODE, unicodeString);
1210 addData(PlacesUtils.TYPE_HTML, htmlString);
1212 if (placeString || unicodeString || htmlString || mozURLString) {
1213 PlacesUIUtils.clipboard.setData(xferable, null,
Ci.nsIClipboard.kGlobalClipboard);
1218 result.viewer = oldViewer;
1225 cut:
function PC_cut() {
1227 this.
remove(
"Cut Selection");
1233 paste:
function PC_paste() {
1248 function makeXferable(
types) {
1250 Cc[
"@mozilla.org/widget/transferable;1"].
1252 for (var i = 0; i <
types.length; ++
i)
1253 xferable.addDataFlavor(
types[i]);
1259 var ip = this._view.insertionPoint;
1261 throw Cr.NS_ERROR_NOT_AVAILABLE;
1269 function getTransactions(
types) {
1270 var xferable = makeXferable(
types);
1271 clipboard.getData(xferable,
Ci.nsIClipboard.kGlobalClipboard);
1273 var data = { }, type = { };
1275 xferable.getAnyTransferData(type, data, { });
1276 data = data.value.QueryInterface(
Ci.nsISupportsString).data;
1277 var items = PlacesUtils.unwrapNodes(data, type.value);
1278 var transactions = [];
1279 var index = ip.index;
1280 for (var i = 0; i < items.length; ++
i) {
1283 var uri = PlacesUtils._uri(items[i].uri);
1291 index = ip.index +
i;
1293 ip.itemId, index,
true);
1295 transactions.push(txn);
1297 return transactions;
1311 var transactions = getTransactions([PlacesUtils.TYPE_X_MOZ_PLACE,
1312 PlacesUtils.TYPE_X_MOZ_URL,
1313 PlacesUtils.TYPE_UNICODE]);
1314 var txn =
PlacesUIUtils.ptm.aggregateTransactions(
"Paste", transactions);
1318 var insertedNodeIds = [];
1319 for (var i = 0; i < transactions.length; ++
i)
1320 insertedNodeIds.push(PlacesUtils.bookmarks
1321 .getIdForItemAt(ip.itemId, ip.index + i));
1322 if (insertedNodeIds.length > 0)
1323 this._view.selectItems(insertedNodeIds,
false);
1337 currentDropTarget:
null,
1345 currentDataTransfer:
null,
1356 draggingOverChildNode:
function PCDH_draggingOverChildNode(node) {
1357 var currentNode = this.currentDropTarget;
1358 while (currentNode) {
1359 if (currentNode == node)
1361 currentNode = currentNode.parentNode;
1369 getSession:
function PCDH__getSession() {
1370 var dragService =
Cc[
"@mozilla.org/widget/dragservice;1"].
1372 return dragService.getCurrentSession();
1380 getFirstValidFlavor:
function PCDH_getFirstValidFlavor(aFlavors) {
1381 for (var i = 0; i < aFlavors.length; i++) {
1382 if (this.GENERIC_VIEW_DROP_TYPES.indexOf(aFlavors[i]) != -1)
1394 canDrop:
function PCDH_canDrop(ip) {
1395 var dt = this.currentDataTransfer;
1396 var dropCount = dt.mozItemCount;
1399 for (var i = 0; i < dropCount; i++) {
1400 var flavor = this.getFirstValidFlavor(dt.mozTypesAt(i));
1404 var data = dt.mozGetDataAt(flavor, i);
1420 var dragged = PlacesUtils.unwrapNodes(data, flavor)[0];
1426 if (ip.isTag && ip.orientation ==
Ci.nsITreeView.DROP_ON &&
1427 dragged.type != PlacesUtils.TYPE_X_MOZ_URL &&
1428 (dragged.type != PlacesUtils.TYPE_X_MOZ_PLACE ||
1429 /^place:/.test(dragged.uri)))
1434 if (dragged.type == PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER ||
1435 /^place:/.test(dragged.uri)) {
1436 var parentId = ip.itemId;
1437 while (parentId != PlacesUtils.placesRootId) {
1438 if (dragged.concreteId == parentId || dragged.id == parentId)
1440 parentId = PlacesUtils.bookmarks.getFolderIdForItem(parentId);
1456 function PCDH_canMoveNode(aNode) {
1461 var parentId = PlacesUtils.getConcreteItemId(aNode.parent);
1462 var concreteId = PlacesUtils.getConcreteItemId(aNode);
1465 if (PlacesUtils.nodeIsTagQuery(aNode.parent))
1469 if (PlacesUtils.nodeIsReadOnly(aNode.parent))
1473 if (PlacesUtils.nodeIsContainer(aNode) &&
1474 !this.canMoveContainer(aNode.itemId, parentId))
1490 function PCDH_canMoveContainer(aId, aParentId) {
1495 const ROOTS = [PlacesUtils.placesRootId, PlacesUtils.bookmarksMenuFolderId,
1496 PlacesUtils.tagsFolderId, PlacesUtils.unfiledBookmarksFolderId,
1497 PlacesUtils.toolbarFolderId];
1498 if (ROOTS.indexOf(aId) != -1)
1502 if (aParentId == null || aParentId == -1)
1503 aParentId = PlacesUtils.bookmarks.getFolderIdForItem(aId);
1505 if (PlacesUtils.bookmarks.getFolderReadonly(aParentId))
1516 onDrop:
function PCDH_onDrop(insertionPoint) {
1517 var dt = this.currentDataTransfer;
1518 var doCopy = [
"copy",
"link"].indexOf(dt.dropEffect) != -1;
1520 var transactions = [];
1521 var dropCount = dt.mozItemCount;
1523 for (var i = 0; i < dropCount; ++
i) {
1524 var flavor = this.getFirstValidFlavor(dt.mozTypesAt(i));
1528 var data = dt.mozGetDataAt(flavor, i);
1532 unwrapped = PlacesUtils.unwrapNodes(data, flavor)[0];
1534 else if (data instanceof XULElement && data.localName ==
"tab" &&
1535 data.ownerDocument.defaultView instanceof ChromeWindow) {
1536 var uri = data.linkedBrowser.currentURI;
1537 var spec = uri ? uri.spec :
"about:blank";
1538 var title = data.label;
1539 unwrapped = { uri: spec,
1541 type: PlacesUtils.TYPE_X_MOZ_URL};
1544 throw(
"bogus data was passed as a tab")
1546 var index = insertionPoint.index;
1551 var dragginUp = insertionPoint.itemId == unwrapped.parent &&
1552 index < PlacesUtils.bookmarks.getItemIndex(unwrapped.id);
1553 if (index != -1 && dragginUp)
1554 index+= movedCount++;
1557 if (insertionPoint.isTag &&
1558 insertionPoint.orientation ==
Ci.nsITreeView.DROP_ON) {
1559 var uri = PlacesUtils._uri(unwrapped.uri);
1560 var tagItemId = insertionPoint.itemId;
1561 transactions.push(
PlacesUIUtils.ptm.tagURI(uri,[tagItemId]));
1565 flavor, insertionPoint.itemId,
1570 var txn =
PlacesUIUtils.ptm.aggregateTransactions(
"DropItems", transactions);
1579 disallowInsertion:
function(aContainer) {
1580 NS_ASSERT(aContainer,
"empty container");
1582 if (PlacesUtils.nodeIsTagQuery(aContainer))
1585 return (!PlacesUtils.nodeIsFolder(aContainer) ||
1586 PlacesUtils.nodeIsReadOnly(aContainer));
1589 placesFlavors: [PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER,
1590 PlacesUtils.TYPE_X_MOZ_PLACE_SEPARATOR,
1591 PlacesUtils.TYPE_X_MOZ_PLACE],
1594 GENERIC_VIEW_DROP_TYPES: [PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER,
1595 PlacesUtils.TYPE_X_MOZ_PLACE_SEPARATOR,
1596 PlacesUtils.TYPE_X_MOZ_PLACE,
1597 PlacesUtils.TYPE_X_MOZ_URL,
1599 PlacesUtils.TYPE_UNICODE],
1605 delete this.flavourSet;
1606 var flavourSet =
new FlavourSet();
1607 var acceptedDropFlavours = this.GENERIC_VIEW_DROP_TYPES;
1608 acceptedDropFlavours.forEach(flavourSet.appendFlavour, flavourSet);
1609 return this.flavourSet = flavourSet;
1616 if (!placesController)
1619 function updatePlacesCommand(aCommand) {
1620 goSetCommandEnabled(aCommand, placesController.isCommandEnabled(aCommand));
1623 updatePlacesCommand(
"placesCmd_open");
1624 updatePlacesCommand(
"placesCmd_open:window");
1625 updatePlacesCommand(
"placesCmd_open:tab");
1626 updatePlacesCommand(
"placesCmd_new:folder");
1627 updatePlacesCommand(
"placesCmd_new:bookmark");
1628 updatePlacesCommand(
"placesCmd_new:livemark");
1629 updatePlacesCommand(
"placesCmd_new:separator");
1630 updatePlacesCommand(
"placesCmd_show:info");
1631 updatePlacesCommand(
"placesCmd_moveBookmarks");
1632 updatePlacesCommand(
"placesCmd_reload");
1633 updatePlacesCommand(
"placesCmd_reloadMicrosummary");
1634 updatePlacesCommand(
"placesCmd_sortBy:name");
1635 updatePlacesCommand(
"placesCmd_cut");
1636 updatePlacesCommand(
"placesCmd_copy");
1637 updatePlacesCommand(
"placesCmd_paste");
1638 updatePlacesCommand(
"placesCmd_delete");
1643 var placesController =
top.document.commandDispatcher
1644 .getControllerForCommand(aCommand);
1645 if (!placesController) {
1648 var
element = document.popupNode;
1650 var isContextMenuShown = (
"_contextMenuShown" in
element) && element._contextMenuShown;
1652 if ((element.localName ==
"menupopup" || element.localName ==
"hbox") &&
1653 isContextMenuShown) {
1654 placesController = element.controllers.getControllerForCommand(aCommand);
1657 element = element.parentNode;
1661 return placesController;
1667 if (controller && controller.isCommandEnabled(aCommand))
1668 controller.doCommand(aCommand);
function doGetPlacesControllerForCommand(aCommand)
const RELOAD_ACTION_REMOVE
const REMOVE_PAGES_MAX_SINGLEREMOVES
getService(Ci.sbIFaceplateManager)
function goUpdatePlacesCommands()
const ORGANIZER_SUBSCRIPTIONS_QUERY
const REMOVE_PAGES_CHUNKLEN
const RELOAD_ACTION_NOTHING
function goDoPlacesCommand(aCommand)
function PlacesController(aView)
const RELOAD_ACTION_INSERT
this _dialogInput val(dateText)
const ORGANIZER_ROOT_BOOKMARKS
function NS_ASSERT(cond, msg)
_setFaviconForWebReader aMenuItem
var PlacesControllerDragHelper
dataSBGenres SBProperties tag
function InsertionPoint(aItemId, aIndex, aOrientation, aIsTag, aDropNearItemId)
_getSelectedPageStyle s i