diff --git a/chrome/content/zotero/import/mendeley/mendeleyImport.js b/chrome/content/zotero/import/mendeley/mendeleyImport.js index 5d78ff81ea..8d693ee6fe 100644 --- a/chrome/content/zotero/import/mendeley/mendeleyImport.js +++ b/chrome/content/zotero/import/mendeley/mendeleyImport.js @@ -111,6 +111,11 @@ Zotero_Import_Mendeley.prototype.translate = async function (options = {}) { let docURLs = urls.get(document.id); let docFiles = files.get(document.id); + // If there's a single PDF file, use "PDF" for the attachment title + if (docFiles && docFiles.length == 1 && docFiles[0].fileURL.endsWith('.pdf')) { + docFiles[0].title = 'PDF'; + } + // If there's a single PDF file and a single PDF URL and the file exists, make an // imported_url attachment instead of separate file and linked_url attachments if (docURLs && docFiles) { @@ -124,7 +129,6 @@ Zotero_Import_Mendeley.prototype.translate = async function (options = {}) { if (x.fileURL.endsWith('.pdf')) { x.title = 'PDF'; x.url = pdfURLs[0]; - x.contentType = 'application/pdf'; } }); // Remove PDF URL from URLs array @@ -988,7 +992,8 @@ Zotero_Import_Mendeley.prototype._saveFilesAndAnnotations = async function (file let options = { libraryID, parentItemID, - file: realPath + file: realPath, + title: file.title }; // If we're not set to link files or file is in Mendeley downloads folder, import it if (!this._linkFiles || this._isDownloadedFile(path)) { diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index 4b2e2e0202..c8e7d7b393 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -42,6 +42,7 @@ Zotero.Attachments = new function(){ * @param {nsIFile|String} [options.file] - File to add * @param {Integer} [options.libraryID] * @param {Integer[]|String[]} [options.parentItemID] - Parent item to add item to + * @param {String} [options.title] * @param {Integer[]} [options.collections] - Collection keys or ids to add new item to * @param {String} [options.fileBaseName] * @param {String} [options.contentType] @@ -57,6 +58,7 @@ Zotero.Attachments = new function(){ var path = file.path; var leafName = file.leafName; var parentItemID = options.parentItemID; + var title = options.title; var collections = options.collections; var fileBaseName = options.fileBaseName; var contentType = options.contentType; @@ -91,7 +93,7 @@ Zotero.Attachments = new function(){ else if (libraryID) { attachmentItem.libraryID = libraryID; } - attachmentItem.setField('title', newName); + attachmentItem.setField('title', title != undefined ? title : newName); attachmentItem.parentID = parentItemID; attachmentItem.attachmentLinkMode = this.LINK_MODE_IMPORTED_FILE; if (collections) { @@ -151,6 +153,7 @@ Zotero.Attachments = new function(){ /** * @param {nsIFile|String} options.file - File to add * @param {Integer[]|String[]} [options.parentItemID] - Parent item to add item to + * @param {String} [options.title] * @param {Integer[]} [options.collections] - Collection keys or ids to add new item to * @param {String} [options.contentType] - Content type * @param {String} [options.charset] - Character set @@ -162,6 +165,7 @@ Zotero.Attachments = new function(){ var file = Zotero.File.pathToFile(options.file); var parentItemID = options.parentItemID; + var title = options.title; var collections = options.collections; var contentType = options.contentType || (yield Zotero.MIME.getMIMETypeFromFile(file)); var charset = options.charset; @@ -171,10 +175,9 @@ Zotero.Attachments = new function(){ throw new Error("parentItemID and collections cannot both be provided"); } - var title = file.leafName; var item = yield _addToDB({ file, - title, + title: title != undefined ? title : file.leafName, linkMode: this.LINK_MODE_LINKED_FILE, contentType, charset,