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:
parent
4c4d5310da
commit
4a4577ff5a
|
@ -1916,7 +1916,7 @@ var ZoteroPane = new function()
|
||||||
|
|
||||||
var file = attachment.getFile();
|
var file = attachment.getFile();
|
||||||
if (file) {
|
if (file) {
|
||||||
var mimeType = attachment.getAttachmentMimeType();
|
var mimeType = attachment.getAttachmentMIMEType();
|
||||||
// If no MIME type specified, try to detect again (I guess in case
|
// If no MIME type specified, try to detect again (I guess in case
|
||||||
// we've gotten smarter since the file was imported?)
|
// we've gotten smarter since the file was imported?)
|
||||||
if (!mimeType) {
|
if (!mimeType) {
|
||||||
|
|
|
@ -66,6 +66,7 @@ Zotero.Item.prototype._init = function(itemTypeOrID, create) {
|
||||||
this._noteAccessTime = null;
|
this._noteAccessTime = null;
|
||||||
|
|
||||||
this._fileLinkMode = 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'");
|
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;
|
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()){
|
if (!this.isAttachment()){
|
||||||
throw ("getAttachmentMIMEType() can only be called on items of type 'attachment'");
|
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();
|
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());
|
var itemType = Zotero.ItemTypes.getName(this.getType());
|
||||||
if (itemType == 'attachment') {
|
if (itemType == 'attachment') {
|
||||||
var linkMode = this.getAttachmentLinkMode();
|
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) {
|
else if (linkMode == Zotero.Attachments.LINK_MODE_LINKED_FILE) {
|
||||||
itemType = itemType + "-link";
|
itemType += "-link";
|
||||||
}
|
}
|
||||||
else if (linkMode == Zotero.Attachments.LINK_MODE_IMPORTED_URL) {
|
else if (linkMode == Zotero.Attachments.LINK_MODE_IMPORTED_URL) {
|
||||||
itemType = itemType + "-snapshot";
|
itemType += "-snapshot";
|
||||||
}
|
}
|
||||||
else if (linkMode == Zotero.Attachments.LINK_MODE_LINKED_URL) {
|
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-link':
|
||||||
case 'attachment-snapshot':
|
case 'attachment-snapshot':
|
||||||
case 'attachment-web-link':
|
case 'attachment-web-link':
|
||||||
|
case 'attachment-pdf':
|
||||||
case 'artwork':
|
case 'artwork':
|
||||||
case 'audioRecording':
|
case 'audioRecording':
|
||||||
case 'blogPost':
|
case 'blogPost':
|
||||||
|
@ -4287,7 +4302,6 @@ Zotero.ItemTypes = new function(){
|
||||||
case 'tvBroadcast':
|
case 'tvBroadcast':
|
||||||
case 'videoRecording':
|
case 'videoRecording':
|
||||||
case 'webpage':
|
case 'webpage':
|
||||||
|
|
||||||
return "chrome://zotero/skin/treeitem-" + itemType + ".png";
|
return "chrome://zotero/skin/treeitem-" + itemType + ".png";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -464,7 +464,7 @@ Zotero.Fulltext = new function(){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.indexFile(file, i.getAttachmentMimeType(),
|
this.indexFile(file, i.getAttachmentMIMEType(),
|
||||||
i.getAttachmentCharset(), i.getID(), !complete);
|
i.getAttachmentCharset(), i.getID(), !complete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -572,7 +572,7 @@ Zotero.Fulltext = new function(){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var mimeType = i.getAttachmentMimeType();
|
var mimeType = i.getAttachmentMIMEType();
|
||||||
|
|
||||||
if (isCachedMIMEType(mimeType)) {
|
if (isCachedMIMEType(mimeType)) {
|
||||||
var file = _getItemCacheFile(i.getID());
|
var file = _getItemCacheFile(i.getID());
|
||||||
|
@ -659,7 +659,7 @@ Zotero.Fulltext = new function(){
|
||||||
*/
|
*/
|
||||||
function getTotalCharsFromFile(itemID) {
|
function getTotalCharsFromFile(itemID) {
|
||||||
var item = Zotero.Items.get(itemID);
|
var item = Zotero.Items.get(itemID);
|
||||||
switch (item.getAttachmentMimeType()) {
|
switch (item.getAttachmentMIMEType()) {
|
||||||
case 'application/pdf':
|
case 'application/pdf':
|
||||||
var file = Zotero.Attachments.getStorageDirectory(itemID);
|
var file = Zotero.Attachments.getStorageDirectory(itemID);
|
||||||
file.append(this.pdfConverterCacheFile);
|
file.append(this.pdfConverterCacheFile);
|
||||||
|
@ -706,7 +706,7 @@ Zotero.Fulltext = new function(){
|
||||||
throw ('Item ' + itemID + ' is not an attachment in Zotero.Fulltext.getIndexedState()');
|
throw ('Item ' + itemID + ' is not an attachment in Zotero.Fulltext.getIndexedState()');
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (item.getAttachmentMimeType()) {
|
switch (item.getAttachmentMIMEType()) {
|
||||||
// Use pages for PDFs
|
// Use pages for PDFs
|
||||||
case 'application/pdf':
|
case 'application/pdf':
|
||||||
var pages = this.getPages(itemID);
|
var pages = this.getPages(itemID);
|
||||||
|
@ -874,7 +874,7 @@ Zotero.Fulltext = new function(){
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.debug('Clearing full-text cache file for item ' + itemID);
|
Zotero.debug('Clearing full-text cache file for item ' + itemID);
|
||||||
switch (item.getAttachmentMimeType()) {
|
switch (item.getAttachmentMIMEType()) {
|
||||||
case 'application/pdf':
|
case 'application/pdf':
|
||||||
var cacheFile = _getItemCacheFile();
|
var cacheFile = _getItemCacheFile();
|
||||||
if (cacheFile.exists()) {
|
if (cacheFile.exists()) {
|
||||||
|
|
|
@ -1838,7 +1838,7 @@ Zotero.Translate.prototype._exportGetAttachment = function(attachment) {
|
||||||
var linkMode = attachment.getAttachmentLinkMode();
|
var linkMode = attachment.getAttachmentLinkMode();
|
||||||
|
|
||||||
// get mime type
|
// get mime type
|
||||||
attachmentArray.mimeType = attachmentArray.uniqueFields.mimeType = attachment.getAttachmentMimeType();
|
attachmentArray.mimeType = attachmentArray.uniqueFields.mimeType = attachment.getAttachmentMIMEType();
|
||||||
// get charset
|
// get charset
|
||||||
attachmentArray.charset = attachmentArray.uniqueFields.charset = attachment.getAttachmentCharset();
|
attachmentArray.charset = attachmentArray.uniqueFields.charset = attachment.getAttachmentCharset();
|
||||||
|
|
||||||
|
|
BIN
chrome/skin/default/zotero/treeitem-attachment-pdf.png
Normal file
BIN
chrome/skin/default/zotero/treeitem-attachment-pdf.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 531 B |
Loading…
Reference in New Issue
Block a user