Use PDF icon for imported (but not linked) PDF attachments (whether file or URL)

Also:

- Item.getAttachmentMimeType() -> getAttachmentMIMEType()
- getAttachmentMIMEType() value is now cached
This commit is contained in:
Dan Stillman 2007-09-17 06:11:32 +00:00
parent 4c4d5310da
commit 4a4577ff5a
5 changed files with 31 additions and 17 deletions

View File

@ -1916,7 +1916,7 @@ var ZoteroPane = new function()
var file = attachment.getFile();
if (file) {
var mimeType = attachment.getAttachmentMimeType();
var mimeType = attachment.getAttachmentMIMEType();
// If no MIME type specified, try to detect again (I guess in case
// we've gotten smarter since the file was imported?)
if (!mimeType) {

View File

@ -66,6 +66,7 @@ Zotero.Item.prototype._init = function(itemTypeOrID, create) {
this._noteAccessTime = null;
this._fileLinkMode = null;
this._fileMIMEType = null;
}
@ -1587,7 +1588,7 @@ Zotero.Item.prototype.getAttachmentLinkMode = function(){
throw ("getAttachmentLinkMode() can only be called on items of type 'attachment'");
}
if (this._fileLinkMode !==null && this._fileLinkMode !==false){
if (this._fileLinkMode !== null) {
return this._fileLinkMode;
}
@ -1598,15 +1599,20 @@ Zotero.Item.prototype.getAttachmentLinkMode = function(){
/**
* Get the mime type of an attachment (e.g. text/plain)
* Get the MIME type of an attachment (e.g. 'text/plain')
**/
Zotero.Item.prototype.getAttachmentMimeType = function(){
Zotero.Item.prototype.getAttachmentMIMEType = function(){
if (!this.isAttachment()){
throw ("getAttachmentMIMEType() can only be called on items of type 'attachment'");
}
if (this._fileMIMEType != null) {
return this._fileMIMEType;
}
var sql = "SELECT mimeType FROM itemAttachments WHERE itemID=" + this.getID();
return Zotero.DB.valueQuery(sql);
this._fileMIMEType = Zotero.DB.valueQuery(sql);
return this._fileMIMEType;
}
@ -1984,17 +1990,25 @@ Zotero.Item.prototype.getImageSrc = function() {
var itemType = Zotero.ItemTypes.getName(this.getType());
if (itemType == 'attachment') {
var linkMode = this.getAttachmentLinkMode();
if (linkMode == Zotero.Attachments.LINK_MODE_IMPORTED_FILE) {
itemType = itemType + "-file";
// Quick hack to use PDF icon for imported files and URLs --
// extend to support other document types later
if ((linkMode == Zotero.Attachments.LINK_MODE_IMPORTED_FILE ||
linkMode == Zotero.Attachments.LINK_MODE_IMPORTED_URL) &&
this.getAttachmentMIMEType() == 'application/pdf') {
itemType += '-pdf';
}
else if (linkMode == Zotero.Attachments.LINK_MODE_IMPORTED_FILE) {
itemType += "-file";
}
else if (linkMode == Zotero.Attachments.LINK_MODE_LINKED_FILE) {
itemType = itemType + "-link";
itemType += "-link";
}
else if (linkMode == Zotero.Attachments.LINK_MODE_IMPORTED_URL) {
itemType = itemType + "-snapshot";
itemType += "-snapshot";
}
else if (linkMode == Zotero.Attachments.LINK_MODE_LINKED_URL) {
itemType = itemType + "-web-link";
itemType += "-web-link";
}
}
@ -4262,6 +4276,7 @@ Zotero.ItemTypes = new function(){
case 'attachment-link':
case 'attachment-snapshot':
case 'attachment-web-link':
case 'attachment-pdf':
case 'artwork':
case 'audioRecording':
case 'blogPost':
@ -4287,7 +4302,6 @@ Zotero.ItemTypes = new function(){
case 'tvBroadcast':
case 'videoRecording':
case 'webpage':
return "chrome://zotero/skin/treeitem-" + itemType + ".png";
}

View File

@ -464,7 +464,7 @@ Zotero.Fulltext = new function(){
continue;
}
this.indexFile(file, i.getAttachmentMimeType(),
this.indexFile(file, i.getAttachmentMIMEType(),
i.getAttachmentCharset(), i.getID(), !complete);
}
@ -572,7 +572,7 @@ Zotero.Fulltext = new function(){
continue;
}
var mimeType = i.getAttachmentMimeType();
var mimeType = i.getAttachmentMIMEType();
if (isCachedMIMEType(mimeType)) {
var file = _getItemCacheFile(i.getID());
@ -659,7 +659,7 @@ Zotero.Fulltext = new function(){
*/
function getTotalCharsFromFile(itemID) {
var item = Zotero.Items.get(itemID);
switch (item.getAttachmentMimeType()) {
switch (item.getAttachmentMIMEType()) {
case 'application/pdf':
var file = Zotero.Attachments.getStorageDirectory(itemID);
file.append(this.pdfConverterCacheFile);
@ -706,7 +706,7 @@ Zotero.Fulltext = new function(){
throw ('Item ' + itemID + ' is not an attachment in Zotero.Fulltext.getIndexedState()');
}
switch (item.getAttachmentMimeType()) {
switch (item.getAttachmentMIMEType()) {
// Use pages for PDFs
case 'application/pdf':
var pages = this.getPages(itemID);
@ -874,7 +874,7 @@ Zotero.Fulltext = new function(){
}
Zotero.debug('Clearing full-text cache file for item ' + itemID);
switch (item.getAttachmentMimeType()) {
switch (item.getAttachmentMIMEType()) {
case 'application/pdf':
var cacheFile = _getItemCacheFile();
if (cacheFile.exists()) {

View File

@ -1838,7 +1838,7 @@ Zotero.Translate.prototype._exportGetAttachment = function(attachment) {
var linkMode = attachment.getAttachmentLinkMode();
// get mime type
attachmentArray.mimeType = attachmentArray.uniqueFields.mimeType = attachment.getAttachmentMimeType();
attachmentArray.mimeType = attachmentArray.uniqueFields.mimeType = attachment.getAttachmentMIMEType();
// get charset
attachmentArray.charset = attachmentArray.uniqueFields.charset = attachment.getAttachmentCharset();

Binary file not shown.

After

Width:  |  Height:  |  Size: 531 B