Closes #564, use zotero:// protocol handler to load snapshots

Fixes #1056, Annotation icons aren't displayed

May be some glitches loading attachments this way, but it seems to work, and it fixes the annotation icons (though they're now misaligned).

Can use zotero://snapshot/ instead of zotero://annotation/ if people think it'd be better.
This commit is contained in:
Dan Stillman 2008-07-08 03:14:01 +00:00
parent 051cf0fbe1
commit ea95f69021
2 changed files with 73 additions and 10 deletions

View File

@ -1995,13 +1995,15 @@ var ZoteroPane = new function()
var isNative = Zotero.MIME.hasNativeHandler(mimeType, ext);
var internal = Zotero.MIME.hasInternalHandler(mimeType, ext);
var fileURL = attachment.getLocalFileURL();
if (isNative ||
(internal && !Zotero.Prefs.get('launchNonNativeFiles'))) {
this.loadURI(fileURL, event, { attachmentID: itemID});
var url = 'zotero://attachment/' + itemID + '/';
this.loadURI(url, event, { attachmentID: itemID});
}
else {
var fileURL = attachment.getLocalFileURL();
// Some platforms don't have nsILocalFile.launch, so we just load it and
// let the Firefox external helper app window handle it
try {

View File

@ -619,10 +619,73 @@ function ChromeExtensionHandler() {
};
/*
zotero://attachment/[id]/
*/
var AttachmentExtension = new function() {
this.newChannel = newChannel;
function newChannel(uri) {
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var Zotero = Components.classes["@zotero.org/Zotero;1"]
.getService(Components.interfaces.nsISupports)
.wrappedJSObject;
try {
var errorMsg;
var [id, fileName] = uri.path.substr(1).split('/');
if (parseInt(id) != id) {
return _errorChannel("Attachment id not an integer");
}
var item = Zotero.Items.get(id);
if (!item) {
return _errorChannel("Item not found");
}
var file = item.getFile();
if (!file) {
return _errorChannel("File not found");
}
if (fileName) {
file = file.parent;
file.append(fileName);
if (!file.exists()) {
return _errorChannel("File not found");
}
}
var ph = Components.classes["@mozilla.org/network/protocol;1?name=file"].
createInstance(Components.interfaces.nsIFileProtocolHandler);
fileURI = ph.newFileURI(file);
var channel = ioService.newChannelFromURI(fileURI);
return channel;
}
catch (e) {
Zotero.debug(e);
throw (e);
}
}
function _errorChannel(msg) {
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var uriStr = 'data:text/plain,' + encodeURIComponent(msg);
var dataURI = ioService.newURI(uriStr, null, null);
var channel = ioService.newChannelFromURI(dataURI);
return channel;
}
};
/*
zotero://select/type/id
*/
var SelectExtension = new function(){
this.newChannel = newChannel;
@ -660,19 +723,17 @@ function ChromeExtensionHandler() {
var ReportExtensionSpec = ZOTERO_SCHEME + "://report"
ReportExtensionSpec = ReportExtensionSpec.toLowerCase();
this._extensions[ReportExtensionSpec] = ReportExtension;
var TimelineExtensionSpec = ZOTERO_SCHEME + "://timeline"
TimelineExtensionSpec = TimelineExtensionSpec.toLowerCase();
this._extensions[TimelineExtensionSpec] = TimelineExtension;
var AttachmentExtensionSpec = ZOTERO_SCHEME + "://attachment"
this._extensions[AttachmentExtensionSpec] = AttachmentExtension;
var SelectExtensionSpec = ZOTERO_SCHEME + "://select"
SelectExtensionSpec = SelectExtensionSpec.toLowerCase();
this._extensions[SelectExtensionSpec] = SelectExtension;
}