better workaround for problem that Live Title bookmark not listed in the main bookmark menu until Firefox is restarted

bug=348248
r=mconnor
This commit is contained in:
myk%mozilla.org 2007-01-14 05:38:27 +00:00
parent 6f42150dcf
commit 8fbd2c1672

View File

@ -739,6 +739,11 @@ MicrosummaryService.prototype = {
_setField: function MSS__setField(bookmarkID, fieldName, fieldValue) {
var bookmarkResource = bookmarkID.QueryInterface(Ci.nsIRDFResource);
// If we're changing the bookmark title, force the bookmark trees
// to rebuild, since they don't seem to be rebuilding on their own.
if (fieldName == FIELD_GENERATED_TITLE)
this._bmds.beginUpdateBatch();
if (this._hasField(bookmarkID, fieldName)) {
var oldValue = this._getField(bookmarkID, fieldName);
this._bmds.Change(bookmarkResource,
@ -753,15 +758,18 @@ MicrosummaryService.prototype = {
true);
}
// If we're setting a field that could affect this bookmark's label,
// then force all bookmark trees to rebuild from scratch.
if (fieldName == FIELD_MICSUM_GEN_URI || fieldName == FIELD_GENERATED_TITLE)
this._forceBookmarkTreesRebuild();
if (fieldName == FIELD_GENERATED_TITLE)
this._bmds.endUpdateBatch();
},
_clearField: function MSS__clearField(bookmarkID, fieldName) {
var bookmarkResource = bookmarkID.QueryInterface(Ci.nsIRDFResource);
// If we're changing the bookmark title, force the bookmark trees
// to rebuild, since they don't seem to be rebuilding on their own.
if (fieldName == FIELD_GENERATED_TITLE)
this._bmds.beginUpdateBatch();
var node = this._bmds.GetTarget(bookmarkResource,
this._resource(fieldName),
true);
@ -771,10 +779,8 @@ MicrosummaryService.prototype = {
node);
}
// If we're clearing a field that could affect this bookmark's label,
// then force all bookmark trees to rebuild from scratch.
if (fieldName == FIELD_MICSUM_GEN_URI || fieldName == FIELD_GENERATED_TITLE)
this._forceBookmarkTreesRebuild();
if (fieldName == FIELD_GENERATED_TITLE)
this._bmds.endUpdateBatch();
},
_hasField: function MSS__hasField(bookmarkID, fieldName) {
@ -786,49 +792,6 @@ MicrosummaryService.prototype = {
return node ? true : false;
},
/**
* Oy vey, a hack! Force the bookmark trees to rebuild, since they don't
* seem to be able to do it correctly on their own right after we twiddle
* something microsummaryish (but they rebuild fine otherwise, incorporating
* all the microsummary changes upon next full rebuild, f.e. if you open
* a new window or shut down and restart your browser).
*
*/
_forceBookmarkTreesRebuild: function MSS__forceBookmarkTreesRebuild() {
var mediator = Cc["@mozilla.org/appshell/window-mediator;1"].
getService(Ci.nsIWindowMediator);
var windows = mediator.getEnumerator("navigator:browser");
while (windows.hasMoreElements()) {
var win = windows.getNext();
// rebuild the bookmarks toolbar
var bookmarksToolbar = win.document.getElementById("bookmarks-ptf");
if (bookmarksToolbar)
bookmarksToolbar.builder.rebuild();
// rebuild the bookmarks sidebar
var sidebar = win.document.getElementById("sidebar");
// sidebar.docShell is null if the sidebar isn't showing, in which case
// sidebar.contentWindow will throw an exception (because it assumes
// the existence of sidebar.docShell), so we have to check for .docShell
// before we check for .contentWindow.
if (sidebar && sidebar.docShell && sidebar.contentWindow &&
sidebar.contentWindow.location ==
"chrome://browser/content/bookmarks/bookmarksPanel.xul") {
var treeElement = sidebar.contentDocument.getElementById("bookmarks-view");
treeElement.tree.builder.rebuild();
}
}
windows = mediator.getEnumerator("bookmarks:manager");
while (windows.hasMoreElements()) {
win = windows.getNext();
// rebuild the Bookmarks Manager's view
treeElement = win.document.getElementById("bookmarks-view");
treeElement.tree.builder.rebuild();
}
},
/**
* Get the URI of the page to which a given bookmark refers.
*