зеркало из https://github.com/mozilla/pjs.git
Bug 370959 - places frontend code cleanup. r=sspitzer.
This commit is contained in:
Родитель
7f917d232a
Коммит
e9a784ec55
|
@ -1960,9 +1960,7 @@ function getShortcutOrURI(aURL, aPostDataRef)
|
|||
try {
|
||||
var shortcutURL = null;
|
||||
#ifdef MOZ_PLACES_BOOKMARKS
|
||||
var bookmarkService = Components.classes["@mozilla.org/browser/nav-bookmarks-service;1"]
|
||||
.getService(nsCI.nsINavBookmarksService);
|
||||
var shortcutURI = bookmarkService.getURIForKeyword(aURL);
|
||||
var shortcutURI = PlacesUtils.bookmarks.getURIForKeyword(aURL);
|
||||
if (shortcutURI)
|
||||
shortcutURL = shortcutURI.spec;
|
||||
#else
|
||||
|
|
|
@ -82,32 +82,24 @@ const NEWLINE = "\r\n";
|
|||
// batching (rather than letting them do incremental drawing).
|
||||
const MIN_TRANSACTIONS_FOR_BATCH = 5;
|
||||
|
||||
function STACK(args) {
|
||||
var temp = arguments.callee.caller;
|
||||
while (temp) {
|
||||
LOG("NAME: " + temp.name + "\n");
|
||||
temp = temp.arguments.callee.caller;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an insertion point within a container where we can insert
|
||||
* items.
|
||||
* @param folderId
|
||||
* @param aFolderId
|
||||
* The folderId of the parent container
|
||||
* @param index
|
||||
* @param aIndex
|
||||
* The index within the container where we should insert
|
||||
* @param orientation
|
||||
* @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!
|
||||
* @constructor
|
||||
*/
|
||||
function InsertionPoint(folderId, index, orientation) {
|
||||
this.folderId = folderId;
|
||||
this.index = index;
|
||||
this.orientation = orientation;
|
||||
function InsertionPoint(aFolderId, aIndex, aOrientation) {
|
||||
this.folderId = aFolderId;
|
||||
this.index = aIndex;
|
||||
this.orientation = aOrientation;
|
||||
}
|
||||
InsertionPoint.prototype.toString = function IP_toString() {
|
||||
return "[object InsertionPoint(folder:" + this.folderId + ",index:" + this.index + ",orientation:" + this.orientation + ")]";
|
||||
|
@ -160,9 +152,6 @@ var ViewConfigurator = {
|
|||
if (rules) {
|
||||
view.peerDropTypes = rules.peerDropTypes;
|
||||
view.childDropTypes = rules.childDropTypes;
|
||||
view.excludeItems = rules.excludeItems;
|
||||
view.excludeQueries = rules.excludeQueries;
|
||||
view.expandQueries = rules.expandQueries;
|
||||
view.peerDropIndex = rules.peerDropIndex;
|
||||
}
|
||||
}
|
||||
|
@ -182,8 +171,8 @@ PlacesController.prototype = {
|
|||
*/
|
||||
_view: null,
|
||||
|
||||
isCommandEnabled: function PC_isCommandEnabled(command) {
|
||||
switch (command) {
|
||||
isCommandEnabled: function PC_isCommandEnabled(aCommand) {
|
||||
switch (aCommand) {
|
||||
case "cmd_undo":
|
||||
return PlacesUtils.tm.numberOfUndoItems > 0;
|
||||
case "cmd_redo":
|
||||
|
@ -263,16 +252,12 @@ PlacesController.prototype = {
|
|||
case "placesCmd_show:info":
|
||||
if (this._view.hasSingleSelection) {
|
||||
var selectedNode = this._view.selectedNode;
|
||||
if (PlacesUtils.nodeIsBookmark(selectedNode)) {
|
||||
var uri = PlacesUtils._uri(selectedNode.uri);
|
||||
if (!PlacesUtils.annotations
|
||||
.hasAnnotation(uri, "livemark/bookmarkFeedURI"))
|
||||
return true;
|
||||
}
|
||||
else if (PlacesUtils.nodeIsFolder(selectedNode)) {
|
||||
if (!this._selectionOverlapsSystemArea())
|
||||
return true;
|
||||
}
|
||||
if (PlacesUtils.nodeIsBookmark(selectedNode) &&
|
||||
!PlacesUtils.nodeIsLivemarkItem(selectedNode))
|
||||
return true;
|
||||
else if (PlacesUtils.nodeIsFolder(selectedNode) &&
|
||||
!this._selectionOverlapsSystemArea())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case "placesCmd_reload":
|
||||
|
@ -290,12 +275,9 @@ PlacesController.prototype = {
|
|||
|
||||
// children of a live bookmark (legacy bookmarks UI doesn't support
|
||||
// this)
|
||||
if (PlacesUtils.nodeIsURI(selectedNode)) {
|
||||
var uri = PlacesUtils._uri(selectedNode.uri);
|
||||
if (PlacesUtils.annotations
|
||||
.hasAnnotation(uri, "livemark/bookmarkFeedURI"))
|
||||
return true;
|
||||
}
|
||||
if (PlacesUtils.nodeIsURI() &&
|
||||
PlacesUtils.nodeIsLivemarkItem(selectedNode))
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
|
@ -384,26 +366,8 @@ PlacesController.prototype = {
|
|||
}
|
||||
},
|
||||
|
||||
onEvent: function PC_onEvent(eventName) {
|
||||
//LOG("onEvent: " + eventName);
|
||||
},
|
||||
onEvent: function PC_onEvent(eventName) { },
|
||||
|
||||
/**
|
||||
* Updates the enabled state of a command element.
|
||||
* @param commandId
|
||||
* The id of the command element to update
|
||||
* @param enabled
|
||||
* Whether or not the command element should be enabled.
|
||||
*/
|
||||
_setEnabled: function PC__setEnabled(commandId, enabled) {
|
||||
var command = document.getElementById(commandId);
|
||||
// Prevents excessive setAttributes
|
||||
var disabled = command.hasAttribute("disabled");
|
||||
if (enabled && disabled)
|
||||
command.removeAttribute("disabled");
|
||||
else if (!enabled && !disabled)
|
||||
command.setAttribute("disabled", "true");
|
||||
},
|
||||
|
||||
/**
|
||||
* Determine whether or not the selection can be removed, either by the
|
||||
|
@ -432,11 +396,8 @@ PlacesController.prototype = {
|
|||
// 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.
|
||||
if (PlacesUtils.nodeIsFolder(parent)) {
|
||||
var readOnly = PlacesUtils.bookmarks.getFolderReadonly(asFolder(parent).folderId);
|
||||
if (readOnly)
|
||||
return false;
|
||||
}
|
||||
if (PlacesUtils.isReadonlyFolder(parent))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
@ -517,7 +478,7 @@ PlacesController.prototype = {
|
|||
return true;
|
||||
},
|
||||
|
||||
#ifdef MOZ_PLACES_BOOKMARKS
|
||||
#ifdef BROKEN_SORT_CODE
|
||||
/**
|
||||
* Updates commands for persistent sorting
|
||||
* @param inSysArea
|
||||
|
@ -582,18 +543,6 @@ PlacesController.prototype = {
|
|||
},
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Determines if the active view can support inserting items of a certain type.
|
||||
*/
|
||||
_viewSupportsInsertingType: function PC__viewSupportsInsertingType(type) {
|
||||
var types = this._view.peerDropTypes;
|
||||
for (var i = 0; i < types.length; ++i) {
|
||||
if (types[i] == type.value)
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Looks at the data on the clipboard to see if it is paste-able.
|
||||
* Paste-able data is:
|
||||
|
@ -621,7 +570,7 @@ PlacesController.prototype = {
|
|||
var data = { }, type = { };
|
||||
xferable.getAnyTransferData(type, data, { });
|
||||
data = data.value.QueryInterface(Ci.nsISupportsString).data;
|
||||
if (!this._viewSupportsInsertingType(type.value))
|
||||
if (this._view.peerDropTypes.indexOf(type.value) == -1)
|
||||
return false;
|
||||
|
||||
// unwrapNodes will throw if the data blob is malformed.
|
||||
|
@ -752,7 +701,7 @@ PlacesController.prototype = {
|
|||
// aren't reorderable can have items removed from them, e.g. a history
|
||||
// list.
|
||||
if (!PlacesUtils.nodeIsReadOnly(node) &&
|
||||
!PlacesUtils.folderIsReadonly(node.parent || root))
|
||||
!PlacesUtils.isReadonlyFolder(node.parent || root))
|
||||
nodeData["mutable"] = true;
|
||||
|
||||
// annotations
|
||||
|
@ -761,6 +710,7 @@ PlacesController.prototype = {
|
|||
for (var j = 0; j < names.length; ++j)
|
||||
nodeData[names[i]] = true;
|
||||
}
|
||||
#ifdef EXTENDED_LIVEBOOKMARKS_UI
|
||||
else if (nodeType == Ci.nsINavHistoryResultNode.RESULT_TYPE_QUERY) {
|
||||
// Various queries might live in the left-hand side of the organizer
|
||||
// window. If this one happens to have collected all the livemark feeds,
|
||||
|
@ -773,6 +723,7 @@ PlacesController.prototype = {
|
|||
if (uri.spec == ORGANIZER_SUBSCRIPTIONS_QUERY)
|
||||
nodeData["allLivemarks"] = true;
|
||||
}
|
||||
#endif
|
||||
metadata.push(nodeData);
|
||||
}
|
||||
|
||||
|
@ -788,7 +739,7 @@ PlacesController.prototype = {
|
|||
* @returns true if the conditions (see buildContextMenu) are satisfied
|
||||
* and the item can be displayed, false otherwise.
|
||||
*/
|
||||
_shouldShowMenuItem: function(aMenuItem, aMetaData) {
|
||||
_shouldShowMenuItem: function PC__shouldShowMenuItem(aMenuItem, aMetaData) {
|
||||
var selectiontype = aMenuItem.getAttribute("selectiontype");
|
||||
if (selectiontype == "multiple" && aMetaData.length == 1)
|
||||
return false;
|
||||
|
@ -896,7 +847,7 @@ PlacesController.prototype = {
|
|||
/**
|
||||
* Select all links in the current view.
|
||||
*/
|
||||
selectAll: function() {
|
||||
selectAll: function PC_selectAll() {
|
||||
this._view.selectAll();
|
||||
},
|
||||
|
||||
|
@ -967,11 +918,8 @@ PlacesController.prototype = {
|
|||
folder = asFolder(selectedNode);
|
||||
}
|
||||
#ifdef EXTENDED_LIVEBOOKMARKS_UI
|
||||
else if (PlacesUtils.nodeIsURI(selectedNode)) {
|
||||
var uri = PlacesUtils._uri(selectedNode.uri);
|
||||
var isLivemarkItem =
|
||||
PlacesUtils.annotations.hasAnnotation(uri, "livemark/bookmarkFeedURI");
|
||||
if (isLivemarkItem)
|
||||
else if (PlacesUtils.nodeIsURI()) {
|
||||
if (PlacesUtils.nodeIsLivemarkItem(selectedNode))
|
||||
folder = asFolder(selectedNode.parent);
|
||||
}
|
||||
#endif
|
||||
|
@ -1134,23 +1082,20 @@ PlacesController.prototype = {
|
|||
* of the folder.
|
||||
*/
|
||||
newFolder: function PC_newFolder() {
|
||||
var view = this._view;
|
||||
|
||||
view.saveSelection(view.SAVE_SELECTION_INSERT);
|
||||
var ps =
|
||||
Cc["@mozilla.org/embedcomp/prompt-service;1"].
|
||||
getService(Ci.nsIPromptService);
|
||||
this._view.saveSelection(this._view.SAVE_SELECTION_INSERT);
|
||||
var ps = Cc["@mozilla.org/embedcomp/prompt-service;1"].
|
||||
getService(Ci.nsIPromptService);
|
||||
var title = PlacesUtils.getString("newFolderTitle");
|
||||
var text = PlacesUtils.getString("newFolderMessage");
|
||||
var value = { value: PlacesUtils.getString("newFolderDefault") };
|
||||
if (ps.prompt(window, title, text, value, null, { })) {
|
||||
var ip = view.insertionPoint;
|
||||
var ip = this._view.insertionPoint;
|
||||
if (!ip)
|
||||
throw Cr.NS_ERROR_NOT_AVAILABLE;
|
||||
var txn = new PlacesCreateFolderTransaction(value.value, ip.folderId,
|
||||
ip.index);
|
||||
PlacesUtils.tm.doTransaction(txn);
|
||||
view.restoreSelection();
|
||||
this._view.restoreSelection();
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -1281,19 +1226,19 @@ PlacesController.prototype = {
|
|||
|
||||
/**
|
||||
* Removes the selection
|
||||
* @param txnName
|
||||
* @param aTxnName
|
||||
* A name for the transaction if this is being performed
|
||||
* as part of another operation.
|
||||
*/
|
||||
remove: function PC_remove(txnName) {
|
||||
NS_ASSERT(txnName !== undefined, "Must supply Transaction Name");
|
||||
remove: function PC_remove(aTxnName) {
|
||||
NS_ASSERT(aTxnName !== undefined, "Must supply Transaction Name");
|
||||
this._view.saveSelection(this._view.SAVE_SELECTION_REMOVE);
|
||||
|
||||
// Delete the selected rows. Do this by walking the selection backward, so
|
||||
// that when undo is performed they are re-inserted in the correct order.
|
||||
var type = this._view.getResult().root.type;
|
||||
if (PlacesUtils.nodeIsFolder(this._view.getResult().root))
|
||||
this._removeRowsFromBookmarks(txnName);
|
||||
this._removeRowsFromBookmarks(aTxnName);
|
||||
else
|
||||
this._removeRowsFromHistory();
|
||||
|
||||
|
@ -1360,7 +1305,7 @@ PlacesController.prototype = {
|
|||
/**
|
||||
* Copy Bookmarks and Folders to the clipboard
|
||||
*/
|
||||
copy: function() {
|
||||
copy: function PC_copy() {
|
||||
var nodes = this._view.getCopyableSelection();
|
||||
|
||||
var xferable =
|
||||
|
@ -1428,7 +1373,7 @@ PlacesController.prototype = {
|
|||
/**
|
||||
* Cut Bookmarks and Folders to the clipboard
|
||||
*/
|
||||
cut: function() {
|
||||
cut: function PC_cut() {
|
||||
this.copy();
|
||||
this.remove("Cut Selection");
|
||||
},
|
||||
|
|
|
@ -239,13 +239,7 @@
|
|||
if (PlacesUtils.nodeIsLivemarkContainer(child)) {
|
||||
element.setAttribute("livemark", "true");
|
||||
var folder = asFolder(child).folderId;
|
||||
var bms =
|
||||
Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
var lms =
|
||||
Cc["@mozilla.org/browser/livemark-service;2"].
|
||||
getService(Ci.nsILivemarkService);
|
||||
var siteURI = lms.getSiteURI(folder);
|
||||
var siteURI = PlacesUtils.livemarks.getSiteURI(folder);
|
||||
if (siteURI) {
|
||||
element.setAttribute("siteURI", siteURI.spec);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* -*- 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
|
||||
*
|
||||
|
@ -110,10 +110,11 @@ var PlacesOrganizer = {
|
|||
searchModifiers.hidden = type == this.HEADER_TYPE_SHOWING;
|
||||
},
|
||||
|
||||
onPlaceURIKeypress: function PO_onPlaceURIKeypress(event) {
|
||||
if (event.keyCode == 13)
|
||||
onPlaceURIKeypress: function PO_onPlaceURIKeypress(aEvent) {
|
||||
var keyCode = aEvent.keyCode;
|
||||
if (keyCode == KeyEvent.DOM_VK_RETURN)
|
||||
this.loadPlaceURI();
|
||||
else if (event.keyCode == 27) {
|
||||
else if (keyCode == KeyEvent.DOM_VK_ESCAPE) {
|
||||
event.target.value = "";
|
||||
this.onPlaceSelected(true);
|
||||
}
|
||||
|
@ -213,22 +214,23 @@ var PlacesOrganizer = {
|
|||
* Handle clicks on the tree. If the user middle clicks on a URL, load that
|
||||
* URL according to rules. Single clicks or modified clicks do not result in
|
||||
* any special action, since they're related to selection.
|
||||
* @param event
|
||||
* @param aEvent
|
||||
* The mouse event.
|
||||
*/
|
||||
onTreeClick: function PO_onTreeClicked(event) {
|
||||
var currentView = event.currentTarget;
|
||||
onTreeClick: function PO_onTreeClicked(aEvent) {
|
||||
var currentView = aEvent.currentTarget;
|
||||
var controller = currentView.controller;
|
||||
|
||||
// If the user clicked on a tree column header, update the sorting
|
||||
// preferences to reflect their choices.
|
||||
if (event.target.localName == "treecol") {
|
||||
// XXXmano: should be done in tree.xml
|
||||
if (aEvent.target.localName == "treecol") {
|
||||
OptionsFilter.update(this._content.getResult());
|
||||
return;
|
||||
}
|
||||
if (currentView.hasSingleSelection && event.button == 1) {
|
||||
if (currentView.hasSingleSelection && aEvent.button == 1) {
|
||||
if (PlacesUtils.nodeIsURI(currentView.selectedNode))
|
||||
controller.openSelectedNodeWithEvent(event);
|
||||
controller.openSelectedNodeWithEvent(aEvent);
|
||||
else if (PlacesUtils.nodeIsContainer(currentView.selectedNode)) {
|
||||
// The command execution function will take care of seeing the
|
||||
// selection is a folder/container and loading its contents in
|
||||
|
@ -258,20 +260,17 @@ var PlacesOrganizer = {
|
|||
/**
|
||||
* Allows simple exporting of bookmarks.
|
||||
*/
|
||||
exportBookmarks: function PO_export() {
|
||||
exportBookmarks: function PO_exportBookmarks() {
|
||||
var fp = Cc["@mozilla.org/filepicker;1"].
|
||||
createInstance(Ci.nsIFilePicker);
|
||||
createInstance(Ci.nsIFilePicker);
|
||||
fp.init(window, "", Ci.nsIFilePicker.modeSave);
|
||||
fp.appendFilters(Ci.nsIFilePicker.filterHTML);
|
||||
fp.defaultString = "bookmarks.html";
|
||||
if (fp.show() != Ci.nsIFilePicker.returnCancel) {
|
||||
var bms = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
bms.exportBookmarksHTML(fp.file);
|
||||
}
|
||||
if (fp.show() != Ci.nsIFilePicker.returnCancel)
|
||||
PlacesUtils.exportBookmarksHTML(fp.file);
|
||||
},
|
||||
|
||||
updateStatusBarForView: function G_updateStatusBarForView(aView) {
|
||||
updateStatusBarForView: function PO_updateStatusBarForView(aView) {
|
||||
var statusText = "";
|
||||
var selectedNode = aView.selectedNode;
|
||||
if (selectedNode) {
|
||||
|
@ -477,7 +476,7 @@ var PlacesQueryBuilder = {
|
|||
};
|
||||
|
||||
this._dateService = Cc["@mozilla.org/intl/scriptabledateformat;1"].
|
||||
getService(Ci.nsIScriptableDateFormat);
|
||||
getService(Ci.nsIScriptableDateFormat);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -1353,4 +1352,3 @@ var Groupers = {
|
|||
}
|
||||
};
|
||||
|
||||
#include ../../../../toolkit/content/debug.js
|
||||
|
|
|
@ -645,9 +645,6 @@
|
|||
// Items that are "static" - i.e. above the user-configurable area
|
||||
// of the view - can not be moved.
|
||||
var nodes = this.getSelectionNodes();
|
||||
var bms =
|
||||
Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
for (var i = 0; i < nodes.length; ++i) {
|
||||
var node = nodes[i];
|
||||
|
||||
|
|
|
@ -319,13 +319,26 @@ var PlacesUtils = {
|
|||
"@mozilla.org/browser/livemark-service;2");
|
||||
},
|
||||
|
||||
/**
|
||||
* Determines whether a ResultNode is a live-bookmark item
|
||||
* @param aNode
|
||||
* A NavHistory Result Node
|
||||
* @returns true if the node is a livemark container item
|
||||
*/
|
||||
nodeIsLivemarkItem: function PU_nodeIsLivemarkItem(aNode) {
|
||||
NS_ASSERT(aNode, "null node");
|
||||
|
||||
return this.annotations.hasAnnotation(this._uri(aNode.uri),
|
||||
"livemark/bookmarkFeedURI");
|
||||
},
|
||||
|
||||
/**
|
||||
* Determines whether or not a node is a readonly folder.
|
||||
* @param aNode
|
||||
* The node to test.
|
||||
* @returns true if the node is a readonly folder.
|
||||
*/
|
||||
folderIsReadonly: function(aNode) {
|
||||
isReadonlyFolder: function(aNode) {
|
||||
NS_ASSERT(aNode, "null node");
|
||||
|
||||
return this.nodeIsFolder(aNode) &&
|
||||
|
|
Загрузка…
Ссылка в новой задаче