From e7ee112527da9c212b78a6b864298694f7a15d66 Mon Sep 17 00:00:00 2001 From: hyliang96 Date: Mon, 9 Dec 2019 17:12:06 +0800 Subject: [PATCH] fix bug: subfolder duplicates in renamed attachment's name when set disable_renaming=true (#200) --- chrome/content/zotfile/zotfile.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/chrome/content/zotfile/zotfile.js b/chrome/content/zotfile/zotfile.js index 41dcc5b1..f5aef6f2 100644 --- a/chrome/content/zotfile/zotfile.js +++ b/chrome/content/zotfile/zotfile.js @@ -99,7 +99,7 @@ Zotero.ZotFile = new function() { } // set to pdf.js if poppler is not supported if(!this.pdfAnnotations.popplerExtractorSupported) this.setPref('pdfExtraction.UsePDFJS', true); - + }.bind(this)); } // Register callbacks in Zotero as item observers @@ -109,7 +109,7 @@ Zotero.ZotFile = new function() { window.addEventListener('unload', function(e) { Zotero.Notifier.unregisterObserver(Zotero.ZotFile.notifierID); Zotero.ZotFile.notifierID = null; - }, false); + }, false); // Load zotero.js first Components.classes["@mozilla.org/moz/jssubscript-loader;1"] .getService(Components.interfaces.mozIJSSubScriptLoader) @@ -162,7 +162,7 @@ Zotero.ZotFile = new function() { * @param {string} pref Name of preference in 'extensions.zotfile' branch * @param {string|int|bool} value Value of preference */ - this.setPref = function(pref, value) { + this.setPref = function(pref, value) { Zotero.Prefs.set('extensions.zotfile.' + pref, value, true); }; @@ -295,7 +295,7 @@ Zotero.ZotFile = new function() { errors.lines.push(this.ZFgetString('error.unknown')); errors.txt = this.ZFgetString('error.clickToCopy'); // prepare error message for clipboard - + var errors_str = this.messages_fatalError.map(function(e) { if (typeof e == 'object') Zotero.logError(e); return typeof e == 'object' ? this.format_error(e) : e; @@ -371,7 +371,7 @@ Zotero.ZotFile = new function() { return(button); - }; + }; this.addUserInput = function(filename, original_filename){ var default_str = this.getPref('userInput_Default'); @@ -495,13 +495,13 @@ Zotero.ZotFile = new function() { Zotero.debug("Attachment file not found in moveLinkedAttachmentFile()", 2); return false; } - + try { var origName = OS.Path.basename(origPath); var origModDate = (yield OS.File.stat(origPath)).lastModificationDate; - + filename = Zotero.File.getValidFileName(filename); - + var destPath = OS.Path.join(location, filename); var destName = OS.Path.basename(destPath); @@ -510,7 +510,7 @@ Zotero.ZotFile = new function() { Zotero.debug("Filename has not changed"); return true; } - + destPath = yield this.moveFile(origPath, destPath); yield att.relinkAttachmentFile(destPath); return true; @@ -883,12 +883,12 @@ Zotero.ZotFile = new function() { att_note = att.getNote(), att_tags = att.getTags(), att_relations = att.getRelations(); - if (!path) throw('Zotero.ZotFile.renameAttachment(): Attachment file does not exists.'); + if (!path) throw('Zotero.ZotFile.renameAttachment(): Attachment file does not exists.'); // only proceed if linked or imported attachment if(!att.isImportedAttachment() && !linkmode == Zotero.Attachments.LINK_MODE_LINKED_FILE) return att; // get filename and location - var filename = rename ? this.getFilename(item, att.attachmentFilename) : att.attachmentFilename, + var filename = rename ? this.getFilename(item, OS.Path.basename(att.attachmentFilename)) : OS.Path.basename(att.attachmentFilename), location = this.getLocation(folder, item, subfolder); // (a) linked to imported attachment if (imported && linkmode == Zotero.Attachments.LINK_MODE_LINKED_FILE) { @@ -991,10 +991,10 @@ Zotero.ZotFile = new function() { var atts = Zotero.Items.get(this.getSelectedAttachments()) .filter(this.checkFileType); // confirm renaming - if (this.getPref('confirmation_batch_ask') && atts.length >= this.getPref('confirmation_batch')) + if (this.getPref('confirmation_batch_ask') && atts.length >= this.getPref('confirmation_batch')) if(!confirm(this.ZFgetString('renaming.moveRename', [atts.length]))) return; - // show infoWindow + // show infoWindow var progressWin = this.progressWindow(this.ZFgetString('renaming.renamed')), description = atts.length == 0; // rename attachments