attachmentRenameFormatStringattachmentRenameTemplate (#3249)

This commit is contained in:
Dan Stillman 2023-08-04 05:58:15 -04:00 committed by GitHub
parent e44e3edef9
commit 9b0ce9558c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 9 deletions

View file

@ -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) => {

View file

@ -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);

View file

@ -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);

View file

@ -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" }}'