diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index 9d61f0f3e0..59d9139efa 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -2239,7 +2239,7 @@ Zotero.Attachments = new function () { * based on the metadata of the specified item and a format string * * (Optional) |formatString| specifies the format string -- otherwise - * the 'attachmentRenameFormatString' pref is used + * the 'attachmentRenameTemplate' pref is used * * @param {Zotero.Item} item * @param {String} formatString @@ -2250,7 +2250,7 @@ Zotero.Attachments = new function () { } if (!formatString) { - formatString = Zotero.Prefs.get('attachmentRenameFormatString'); + formatString = Zotero.Prefs.get('attachmentRenameTemplate'); } const getSlicedCreatorsOfType = (creatorType, slice) => { diff --git a/chrome/content/zotero/xpcom/prefs.js b/chrome/content/zotero/xpcom/prefs.js index 48a93e3646..563cc44615 100644 --- a/chrome/content/zotero/xpcom/prefs.js +++ b/chrome/content/zotero/xpcom/prefs.js @@ -47,7 +47,7 @@ Zotero.Prefs = new function() { if (!fromVersion) { fromVersion = 0; } - var toVersion = 8; + var toVersion = 9; if (fromVersion < toVersion) { for (var i = fromVersion + 1; i <= toVersion; i++) { switch (i) { @@ -107,14 +107,29 @@ Zotero.Prefs = new function() { case 7: this.clear('layers.acceleration.disabled', true); break; + // Convert "attachment rename format string" from old format (e.g. {%c - }{%y - }{%t{50}}) // to a new format that uses the template engine - case 8: + case 9: if (this.prefHasUserValue('attachmentRenameFormatString')) { - this.set('attachmentRenameFormatString', this.convertLegacyAttachmentRenameFormatString( - this.get('attachmentRenameFormatString') || '' - )); + let oldVal = this.get('attachmentRenameFormatString'); + let newVal; + if (oldVal) { + if (oldVal.includes('{%')) { + newVal = this.convertLegacyAttachmentRenameFormatString(oldVal); + } + // User already modified new template from the Z7 beta before we + // renamed this pref, so just transfer over + else { + newVal = oldVal; + } + } + if (newVal) { + this.set('attachmentRenameTemplate', newVal); + } + this.clear('attachmentRenameFormatString'); } + break; } } this.set('prefVersion', toVersion); diff --git a/defaults/preferences/zotero.js b/defaults/preferences/zotero.js index 9ddf295f00..8e7a6f279f 100644 --- a/defaults/preferences/zotero.js +++ b/defaults/preferences/zotero.js @@ -36,7 +36,7 @@ pref("extensions.zotero.autoRecognizeFiles", true); pref("extensions.zotero.autoRenameFiles", true); pref("extensions.zotero.autoRenameFiles.linked", false); pref("extensions.zotero.autoRenameFiles.fileTypes", "application/pdf"); -pref("extensions.zotero.attachmentRenameFormatString", "{{ firstCreator suffix=\" - \" }}{{ year suffix=\" - \" }}{{ title truncate=\"100\" }}"); +pref("extensions.zotero.attachmentRenameTemplate", "{{ firstCreator suffix=\" - \" }}{{ year suffix=\" - \" }}{{ title truncate=\"100\" }}"); pref("extensions.zotero.capitalizeTitles", false); pref("extensions.zotero.launchNonNativeFiles", false); pref("extensions.zotero.sortNotesChronologically", false); diff --git a/test/tests/attachmentsTest.js b/test/tests/attachmentsTest.js index f10864ef37..03d0de974b 100644 --- a/test/tests/attachmentsTest.js +++ b/test/tests/attachmentsTest.js @@ -1551,7 +1551,7 @@ describe("Zotero.Attachments", function() { ); }); - it("should convert formatString attachmentRenameFormatString to use template syntax", function () { + it("should convert old attachmentRenameFormatString to use new attachmentRenameTemplate syntax", function () { assert.equal( Zotero.Prefs.convertLegacyAttachmentRenameFormatString('{%c - }{%y - }{%t{50}}'), '{{ firstCreator suffix=" - " }}{{ year suffix=" - " }}{{ title truncate="50" }}'