Bug 644461 - Port |
Bug 636924 - Copied livemarks appear as folders in sidebar| to SeaMonkey; (Av2) Just copy it (code + test).
r=iann.
--- a/suite/common/places/browserPlacesViews.js
+++ b/suite/common/places/browserPlacesViews.js
@@ -462,17 +462,17 @@ PlacesViewBase.prototype = {
elt.removeAttribute("image");
else if (icon != elt.getAttribute("image"))
elt.setAttribute("image", icon);
},
nodeAnnotationChanged:
function PVB_nodeAnnotationChanged(aPlacesNode, aAnno) {
// All livemarks have a feedURI, so use it as our indicator.
- if (aAnno == "livemark/feedURI") {
+ if (aAnno == PlacesUtils.LMANNO_FEEDURI) {
let elt = aPlacesNode._DOMElement;
if (!elt)
throw "aPlacesNode must have _DOMElement set";
let menu = elt.parentNode;
if (!menu.hasAttribute("livemark"))
menu.setAttribute("livemark", "true");
@@ -1152,17 +1152,17 @@ PlacesToolbar.prototype = {
// We're notified for the menupopup, not the containing toolbarbutton.
if (elt.localName == "menupopup")
elt = elt.parentNode;
if (elt.parentNode == this._rootElt) {
// Node is on the toolbar.
// All livemarks have a feedURI, so use it as our indicator.
- if (aAnno == "livemark/feedURI")
+ if (aAnno == PlacesUtils.LMANNO_FEEDURI)
elt.setAttribute("livemark", true);
return;
}
PlacesViewBase.prototype.nodeAnnotationChanged.apply(this, arguments);
},
nodeTitleChanged: function PT_nodeTitleChanged(aPlacesNode, aNewTitle) {
--- a/suite/common/places/tests/browser/browser_library_views_liveupdate.js
+++ b/suite/common/places/tests/browser/browser_library_views_liveupdate.js
@@ -76,18 +76,19 @@ function test() {
null);
}
/**
* Adds bookmarks observer, and executes a bunch of bookmarks operations.
*/
function startTest() {
var bs = PlacesUtils.bookmarks;
- // Add bookmarks observer.
+ // Add observers.
bs.addObserver(bookmarksObserver, false);
+ PlacesUtils.annotations.addObserver(bookmarksObserver, false);
var addedBookmarks = [];
// MENU
ok(true, "*** Acting on menu bookmarks");
var id = bs.insertBookmark(bs.bookmarksMenuFolder,
PlacesUtils._uri("http://bm1.mozilla.org/"),
bs.DEFAULT_INDEX,
"bm1");
@@ -106,16 +107,21 @@ function startTest() {
bs.setItemTitle(id, "bmf_edited");
addedBookmarks.push(id);
id = bs.insertBookmark(id,
PlacesUtils._uri("http://bmf1.mozilla.org/"),
bs.DEFAULT_INDEX,
"bmf1");
addedBookmarks.push(id);
bs.moveItem(id, bs.bookmarksMenuFolder, 0);
+ id = PlacesUtils.livemarks.createLivemarkFolderOnly(
+ bs.bookmarksMenuFolder, "bml",
+ PlacesUtils._uri("http://bml.siteuri.mozilla.org/"),
+ PlacesUtils._uri("http://bml.feeduri.mozilla.org/"), bs.DEFAULT_INDEX);
+ addedBookmarks.push(id);
// TOOLBAR
ok(true, "*** Acting on toolbar bookmarks");
bs.insertBookmark(bs.toolbarFolder,
PlacesUtils._uri("http://tb1.mozilla.org/"),
bs.DEFAULT_INDEX,
"tb1");
bs.setItemTitle(id, "tb1_edited");
@@ -134,16 +140,20 @@ function startTest() {
bs.setItemTitle(id, "tbf_edited");
addedBookmarks.push(id);
id = bs.insertBookmark(id,
PlacesUtils._uri("http://tbf1.mozilla.org/"),
bs.DEFAULT_INDEX,
"bmf1");
addedBookmarks.push(id);
bs.moveItem(id, bs.toolbarFolder, 0);
+ id = PlacesUtils.livemarks.createLivemarkFolderOnly(
+ bs.toolbarFolder, "tbl", PlacesUtils._uri("http://tbl.siteuri.mozilla.org/"),
+ PlacesUtils._uri("http://tbl.feeduri.mozilla.org/"), bs.DEFAULT_INDEX);
+ addedBookmarks.push(id);
// UNSORTED
ok(true, "*** Acting on unsorted bookmarks");
id = bs.insertBookmark(bs.unfiledBookmarksFolder,
PlacesUtils._uri("http://ub1.mozilla.org/"),
bs.DEFAULT_INDEX,
"ub1");
bs.setItemTitle(id, "ub1_edited");
@@ -162,28 +172,34 @@ function startTest() {
bs.setItemTitle(id, "ubf_edited");
addedBookmarks.push(id);
id = bs.insertBookmark(id,
PlacesUtils._uri("http://ubf1.mozilla.org/"),
bs.DEFAULT_INDEX,
"ubf1");
addedBookmarks.push(id);
bs.moveItem(id, bs.unfiledBookmarksFolder, 0);
+ id = PlacesUtils.livemarks.createLivemarkFolderOnly(
+ bs.unfiledBookmarksFolder, "bubl",
+ PlacesUtils._uri("http://bubl.siteuri.mozilla.org/"),
+ PlacesUtils._uri("http://bubl.feeduri.mozilla.org/"), bs.DEFAULT_INDEX);
+ addedBookmarks.push(id);
// Remove all added bookmarks.
addedBookmarks.forEach(function (aItem) {
// If we remove an item after its containing folder has been removed,
// this will throw, but we can ignore that.
try {
bs.removeItem(aItem);
} catch (ex) {}
});
- // Remove bookmarks observer.
+ // Remove observers.
bs.removeObserver(bookmarksObserver);
+ PlacesUtils.annotations.removeObserver(bookmarksObserver);
finishTest();
}
/**
* Restores browser state and calls finish.
*/
function finishTest() {
// Close Library window.
@@ -191,22 +207,46 @@ function finishTest() {
finish();
}
/**
* The observer is where magic happens, for every change we do it will look for
* nodes positions in the affected views.
*/
var bookmarksObserver = {
- QueryInterface: function PSB_QueryInterface(aIID) {
- if (aIID.equals(Ci.nsINavBookmarkObserver) ||
- aIID.equals(Ci.nsISupports))
- return this;
- throw Cr.NS_NOINTERFACE;
+ QueryInterface: XPCOMUtils.generateQI([
+ Ci.nsINavBookmarkObserver
+ , Ci.nsIAnnotationObserver
+ ]),
+
+ // nsIAnnotationObserver
+ onItemAnnotationSet: function(aItemId, aAnnotationName) {
+ if (aAnnotationName == PlacesUtils.LMANNO_FEEDURI) {
+ // Check that item is recognized as a livemark.
+ let validator = function(aTreeRowIndex) {
+ let tree = gLibrary.PlacesOrganizer._places;
+ let livemarkAtom = Cc["@mozilla.org/atom-service;1"].
+ getService(Ci.nsIAtomService).
+ getAtom("livemark");
+ let properties = Cc["@mozilla.org/supports-array;1"].
+ createInstance(Ci.nsISupportsArray);
+ tree.view.getCellProperties(aTreeRowIndex,
+ tree.columns.getColumnAt(0),
+ properties);
+ return properties.GetIndexOf(livemarkAtom) != -1;
+ };
+
+ var [node, index, valid] = getNodeForTreeItem(aItemId, gLibrary.PlacesOrganizer._places, validator);
+ isnot(node, null, "Found new Places node in left pane at " + index);
+ ok(valid, "Node is recognized as a livemark");
+ }
},
+ onItemAnnotationRemoved: function() {},
+ onPageAnnotationSet: function() {},
+ onPageAnnotationRemoved: function() {},
// nsINavBookmarkObserver
onItemAdded: function PSB_onItemAdded(aItemId, aFolderId, aIndex, aItemType,
aURI) {
var node = null;
var index = null;
[node, index] = getNodeForTreeItem(aItemId, gLibrary.PlacesOrganizer._places);
// Left pane should not be updated for normal bookmarks or separators.
--- a/suite/common/places/treeView.js
+++ b/suite/common/places/treeView.js
@@ -838,18 +838,22 @@ PlacesTreeView.prototype = {
this._invalidateCellValue(aNode, this.COLUMN_TYPE_TAGS);
},
nodeKeywordChanged: function PTV_nodeKeywordChanged(aNode, aNewKeyword) {
this._invalidateCellValue(aNode, this.COLUMN_TYPE_KEYWORD);
},
nodeAnnotationChanged: function PTV_nodeAnnotationChanged(aNode, aAnno) {
- if (aAnno == PlacesUIUtils.DESCRIPTION_ANNO)
+ if (aAnno == PlacesUIUtils.DESCRIPTION_ANNO) {
this._invalidateCellValue(aNode, this.COLUMN_TYPE_DESCRIPTION);
+ } else if (aAnno == PlacesUtils.LMANNO_FEEDURI) {
+ // The livemark attribute is set as a cell property on the title cell.
+ this._invalidateCellValue(aNode, this.COLUMN_TYPE_TITLE);
+ }
},
nodeDateAddedChanged: function PTV_nodeDateAddedChanged(aNode, aNewValue) {
this._invalidateCellValue(aNode, this.COLUMN_TYPE_DATEADDED);
},
nodeLastModifiedChanged:
function PTV_nodeLastModifiedChanged(aNode, aNewValue) {