add a bookmarks context menu item for refreshing a microsummary; bug=341555; r=mconnor; a=mconnor for 1.8 branch

This commit is contained in:
myk%mozilla.org 2006-06-19 23:16:27 +00:00
Родитель e71eb0674f
Коммит 41e498b216
7 изменённых файлов: 120 добавлений и 45 удалений

Просмотреть файл

@ -82,6 +82,7 @@
<command id="cmd_bm_newseparator" oncommand="goDoCommand('cmd_bm_newseparator');"/>
<command id="cmd_bm_properties" oncommand="goDoCommand('cmd_bm_properties');"/>
<command id="cmd_bm_refreshlivemark" oncommand="goDoCommand('cmd_bm_refreshlivemark');"/>
<command id="cmd_bm_refreshmicrosummary" oncommand="goDoCommand('cmd_bm_refreshmicrosummary');"/>
<command id="cmd_bm_rename" oncommand="goDoCommand('cmd_bm_rename');"/>
<command id="cmd_bm_moveBookmark" oncommand="goDoCommand('cmd_bm_moveBookmark');"/>
<command id="cmd_bm_sortbyname" oncommand="goDoCommand('cmd_bm_sortbyname');"/>

Просмотреть файл

@ -133,6 +133,10 @@ function initServices()
kIOIID = Components.interfaces.nsIIOService;
IOSVC = Components.classes[kIOContractID].getService(kIOIID);
kMICSUMContractID = "@mozilla.org/microsummary/service;1";
kMICSUMIID = Components.interfaces.nsIMicrosummaryService;
MICSUMSVC = Components.classes[kMICSUMContractID].getService(kMICSUMIID);
gBmProperties = [RDF.GetResource(gNC_NS+"Name"),
RDF.GetResource(gNC_NS+"URL"),
RDF.GetResource(gNC_NS+"ShortcutURL"),
@ -308,6 +312,7 @@ var BookmarksCommand = {
// delete
// ---------------------
// bm_refreshlivemark
// bm_refreshmicrosummary
// bm_sortbyname
// ---------------------
// bm_properties
@ -326,6 +331,10 @@ var BookmarksCommand = {
"delete", "bm_separator",
"bm_sortbyname", "bm_separator",
"bm_properties"];
// If this bookmark has a microsummary, add a command for refreshing it
// right before the "sort by name" (bm_sortbyname) command.
if (MICSUMSVC.hasMicrosummary(aNodeID))
commands.splice(14, 0, "bm_refreshmicrosummary");
break;
case "Folder":
case "PersonalToolbarFolder":
@ -965,6 +974,14 @@ var BookmarksCommand = {
}
},
refreshMicrosummary: function (aSelection)
{
for (var i = 0; i < aSelection.length; i++) {
rsrc = RDF.GetResource(aSelection.item[i].Value);
MICSUMSVC.refreshMicrosummary(rsrc);
}
},
sortByName: function (aSelection)
{
// do the real sorting in a timeout, to make sure that
@ -1090,6 +1107,7 @@ var BookmarksController = {
case "cmd_bm_export":
case "cmd_bm_movebookmark":
case "cmd_bm_refreshlivemark":
case "cmd_bm_refreshmicrosummary":
case "cmd_bm_sortbyname":
isCommandSupported = true;
break;
@ -1199,6 +1217,12 @@ var BookmarksController = {
return false;
}
return length > 0;
case "cmd_bm_refreshmicrosummary":
for (i=0; i<length; ++i) {
if (!MICSUMSVC.hasMicrosummary(aSelection.item[i]))
return false;
}
return length > 0;
case "cmd_bm_sortbyname":
if (length == 1 && (aSelection.type[0] == "Folder" ||
aSelection.type[0] == "Bookmark" ||
@ -1293,6 +1317,9 @@ var BookmarksController = {
case "cmd_bm_refreshlivemark":
BookmarksCommand.refreshLivemark(aSelection);
break;
case "cmd_bm_refreshmicrosummary":
BookmarksCommand.refreshMicrosummary(aSelection);
break;
case "cmd_bm_sortbyname":
BookmarksCommand.sortByName(aSelection);
break;
@ -1308,7 +1335,8 @@ var BookmarksController = {
"cmd_undo", "cmd_redo", "cmd_bm_properties", "cmd_bm_rename",
"cmd_copy", "cmd_paste", "cmd_cut", "cmd_delete",
"cmd_bm_setpersonaltoolbarfolder", "cmd_bm_movebookmark",
"cmd_bm_openfolder", "cmd_bm_managefolder", "cmd_bm_refreshlivemark", "cmd_bm_sortbyname"];
"cmd_bm_openfolder", "cmd_bm_managefolder", "cmd_bm_refreshlivemark",
"cmd_bm_refreshmicrosummary", "cmd_bm_sortbyname"];
for (var i = 0; i < commands.length; ++i) {
var enabled = this.isCommandEnabled(commands[i], aSelection, aTarget);
var commandNode = document.getElementById(commands[i]);

Просмотреть файл

@ -87,6 +87,7 @@
<command id="cmd_bm_setpersonaltoolbarfolder" oncommand="goDoCommand('cmd_bm_setpersonaltoolbarfolder');"/>
<command id="cmd_bm_setnewsearchfolder" oncommand="goDoCommand('cmd_bm_setnewsearchfolder');"/>
<command id="cmd_bm_refreshlivemark" oncommand="goDoCommand('cmd_bm_refreshlivemark');"/>
<command id="cmd_bm_refreshmicrosummary" oncommand="goDoCommand('cmd_bm_refreshmicrosummary');"/>
<command id="cmd_bm_properties" oncommand="goDoCommand('cmd_bm_properties');"/>
<command id="cmd_bm_rename" oncommand="goDoCommand('cmd_bm_rename');"/>
<command id="cmd_bm_import" oncommand="goDoCommand('cmd_bm_import');"/>

Просмотреть файл

@ -57,18 +57,19 @@
<!-- bookmarks & edit commands -->
<commandset id="editMenuCommands"/>
<command id="cmd_bm_open" oncommand="goDoCommand('cmd_bm_open');"/>
<command id="cmd_bm_openinnewwindow" oncommand="goDoCommand('cmd_bm_openinnewwindow');"/>
<command id="cmd_bm_openinnewtab" oncommand="goDoCommand('cmd_bm_openinnewtab');"/>
<command id="cmd_bm_openfolder" oncommand="goDoCommand('cmd_bm_openfolder');"/>
<command id="cmd_bm_managefolder" oncommand="goDoCommand('cmd_bm_managefolder');"/>
<command id="cmd_bm_newfolder" oncommand="goDoCommand('cmd_bm_newfolder');"/>
<command id="cmd_bm_newbookmark" oncommand="goDoCommand('cmd_bm_newbookmark');"/>
<command id="cmd_bm_newseparator" oncommand="goDoCommand('cmd_bm_newseparator');"/>
<command id="cmd_bm_find" oncommand="goDoCommand('cmd_bm_find');"/>
<command id="cmd_bm_properties" oncommand="goDoCommand('cmd_bm_properties');"/>
<command id="cmd_bm_refreshlivemark" oncommand="goDoCommand('cmd_bm_refreshlivemark');"/>
<command id="cmd_bm_sortbyname" oncommand="goDoCommand('cmd_bm_sortbyname');"/>
<command id="cmd_bm_open" oncommand="goDoCommand('cmd_bm_open');"/>
<command id="cmd_bm_openinnewwindow" oncommand="goDoCommand('cmd_bm_openinnewwindow');"/>
<command id="cmd_bm_openinnewtab" oncommand="goDoCommand('cmd_bm_openinnewtab');"/>
<command id="cmd_bm_openfolder" oncommand="goDoCommand('cmd_bm_openfolder');"/>
<command id="cmd_bm_managefolder" oncommand="goDoCommand('cmd_bm_managefolder');"/>
<command id="cmd_bm_newfolder" oncommand="goDoCommand('cmd_bm_newfolder');"/>
<command id="cmd_bm_newbookmark" oncommand="goDoCommand('cmd_bm_newbookmark');"/>
<command id="cmd_bm_newseparator" oncommand="goDoCommand('cmd_bm_newseparator');"/>
<command id="cmd_bm_find" oncommand="goDoCommand('cmd_bm_find');"/>
<command id="cmd_bm_properties" oncommand="goDoCommand('cmd_bm_properties');"/>
<command id="cmd_bm_refreshlivemark" oncommand="goDoCommand('cmd_bm_refreshlivemark');"/>
<command id="cmd_bm_refreshmicrosummary" oncommand="goDoCommand('cmd_bm_refreshmicrosummary');"/>
<command id="cmd_bm_sortbyname" oncommand="goDoCommand('cmd_bm_sortbyname');"/>
<hbox align="center">
<label value="&search.label;" accesskey="&search.accesskey;" control="search-box"/>

Просмотреть файл

@ -250,4 +250,24 @@ interface nsIMicrosummaryService : nsISupports
*/
boolean isMicrosummary(in nsISupports bookmarkID,
in nsIMicrosummary microsummary);
/**
* Refresh a microsummary, updating its value in the datastore and UI.
* If this method can refresh the microsummary instantly, it will.
* Otherwise, it'll asynchronously download the necessary information
* (the generator and/or page) before refreshing the microsummary.
*
* Callers should check the "content" property of the returned microsummary
* object to distinguish between sync and async refreshes. If its value
* is "null", then it's an async refresh, and the caller should register
* itself as an nsIMicrosummaryObserver via nsIMicrosummary.addObserver()
* to find out when the refresh completes.
*
* @param bookmarkID
* the bookmark whose microsummary is being refreshed
*
* @returns the microsummary being refreshed
*
*/
nsIMicrosummary refreshMicrosummary(in nsISupports bookmarkID);
};

Просмотреть файл

@ -263,37 +263,7 @@ MicrosummaryService.prototype = {
this._getField(bookmarkID, FIELD_MICSUM_EXPIRATION) > now)
continue;
// Create and initialize a new Microsummary instance.
var pageURI =
#ifdef MOZ_PLACES
bookmarkID;
#else
this._uri(this._getField(bookmarkID, FIELD_BOOKMARK_URL));
#endif
var generatorURI = this._uri(this._getField(bookmarkID, FIELD_MICSUM_GEN_URI));
var microsummary = new Microsummary(pageURI, generatorURI);
if (this._localGenerators[generatorURI.spec])
microsummary.generator = this._localGenerators[generatorURI.spec];
// A microsummary observer that calls the microsummary service
// to update the datastore when the microsummary finishes loading.
var observer = {
_svc: this,
_bookmarkID: bookmarkID,
onContentLoaded: function(microsummary) {
this._svc._updateMicrosummary(this._bookmarkID, microsummary);
// Prevent reference cycles from leaking memory.
microsummary.removeObserver(this);
this._bookmark = null;
this._svc = null;
}
};
// Register the observer with the microsummary and trigger
// the microsummary to update itself.
microsummary.addObserver(observer);
microsummary.update();
this.refreshMicrosummary(bookmarkID);
}
},
@ -854,8 +824,60 @@ MicrosummaryService.prototype = {
return true;
return false
}
},
/**
* Refresh a microsummary, updating its value in the datastore and UI.
* If this method can refresh the microsummary instantly, it will.
* Otherwise, it'll asynchronously download the necessary information
* (the generator and/or page) before refreshing the microsummary.
*
* Callers should check the "content" property of the returned microsummary
* object to distinguish between sync and async refreshes. If its value
* is "null", then it's an async refresh, and the caller should register
* itself as an nsIMicrosummaryObserver via nsIMicrosummary.addObserver()
* to find out when the refresh completes.
*
* @param bookmarkID
* the bookmark whose microsummary is being refreshed
*
* @returns the microsummary being refreshed
*
*/
refreshMicrosummary: function MSS_refreshMicrosummary(bookmarkID) {
if (!this.hasMicrosummary(bookmarkID))
throw "bookmark " + bookmarkID + " does not have a microsummary";
var pageURI = this._getPageForBookmark(bookmarkID);
var generatorURI = this._uri(this._getField(bookmarkID, FIELD_MICSUM_GEN_URI));
var microsummary = new Microsummary(pageURI, generatorURI);
if (this._localGenerators[generatorURI.spec])
microsummary.generator = this._localGenerators[generatorURI.spec];
// A microsummary observer that calls the microsummary service
// to update the datastore when the microsummary finishes loading.
var observer = {
_svc: this,
_bookmarkID: bookmarkID,
onContentLoaded: function MSS_observer_onContentLoaded(microsummary) {
try {
this._svc._updateMicrosummary(this._bookmarkID, microsummary);
}
finally {
this._svc = null;
this._bookmarkID = null;
microsummary.removeObserver(this);
}
}
};
// Register the observer with the microsummary and trigger the microsummary
// to update itself.
microsummary.addObserver(observer);
microsummary.update();
return microsummary;
}
};

Просмотреть файл

@ -67,6 +67,8 @@ cmd_bm_properties = Properties
cmd_bm_properties_accesskey = r
cmd_bm_refreshlivemark = Reload Live Bookmark
cmd_bm_refreshlivemark_accesskey = L
cmd_bm_refreshmicrosummary = Reload Live Title
cmd_bm_refreshmicrosummary_accesskey = L
cmd_bm_sortbyname = Sort By Name
cmd_bm_sortbyname_accesskey = S