mirror of
https://github.com/zotero/zotero.git
synced 2026-10-08 03:08:19 +00:00
Set auto attachment title when not renaming (#5748)
This commit is contained in:
parent
cc53bc1699
commit
8b446b7fc5
6 changed files with 15 additions and 18 deletions
|
|
@ -146,7 +146,7 @@ export async function renameFilesFromParent({ userLibrary = true, groupLibrary =
|
|||
// update the title if it matches the old filename
|
||||
const newTitleLC = attachmentItem.getField('title').toLowerCase();
|
||||
if (newTitleLC === oldBaseName.toLowerCase() || newTitleLC === oldFileName.toLowerCase()) {
|
||||
attachmentItem.setAutoAttachmentTitle({ ignoreAutoRenamePrefs: true });
|
||||
attachmentItem.setAutoAttachmentTitle();
|
||||
}
|
||||
|
||||
await attachmentItem.saveTx();
|
||||
|
|
@ -196,7 +196,7 @@ export async function renameFileFromParent(attachmentItem) {
|
|||
|
||||
const newTitleLC = attachmentItem.getField('title').toLowerCase();
|
||||
if (newTitleLC === oldBaseName.toLowerCase() || newTitleLC === oldName.toLowerCase()) {
|
||||
attachmentItem.setAutoAttachmentTitle({ ignoreAutoRenamePrefs: true });
|
||||
attachmentItem.setAutoAttachmentTitle();
|
||||
requiresSave = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4014,7 +4014,7 @@ Zotero.Item.prototype._getDefaultTitleForAttachmentContentType = function () {
|
|||
};
|
||||
|
||||
|
||||
Zotero.Item.prototype.setAutoAttachmentTitle = function ({ ignoreAutoRenamePrefs, forceFirstOfType } = {}) {
|
||||
Zotero.Item.prototype.setAutoAttachmentTitle = function ({ forceFirstOfType } = {}) {
|
||||
if (!this.isAttachment()) {
|
||||
throw new Error("setAutoAttachmentTitle() can only be called on attachment items");
|
||||
}
|
||||
|
|
@ -4030,8 +4030,7 @@ Zotero.Item.prototype.setAutoAttachmentTitle = function ({ ignoreAutoRenamePrefs
|
|||
.every(item => item === this)
|
||||
)
|
||||
: forceFirstOfType;
|
||||
let isBeingRenamed = ignoreAutoRenamePrefs || Zotero.Attachments.shouldAutoRenameAttachment(this);
|
||||
if (isFirstOfType && isBeingRenamed) {
|
||||
if (isFirstOfType) {
|
||||
let defaultTitle = this._getDefaultTitleForAttachmentContentType();
|
||||
if (defaultTitle !== null) {
|
||||
this.setField('title', defaultTitle);
|
||||
|
|
|
|||
|
|
@ -305,7 +305,7 @@ Zotero.RecognizeDocument = new function () {
|
|||
if (result !== true) {
|
||||
throw new Error("Error renaming " + path);
|
||||
}
|
||||
attachment.setAutoAttachmentTitle({ ignoreAutoRenamePrefs: true });
|
||||
attachment.setAutoAttachmentTitle();
|
||||
await attachment.saveTx();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5783,7 +5783,7 @@ var ZoteroPane = new function () {
|
|||
if (result !== true) {
|
||||
throw new Error('Error renaming ' + path);
|
||||
}
|
||||
item.setAutoAttachmentTitle({ ignoreAutoRenamePrefs: true });
|
||||
item.setAutoAttachmentTitle();
|
||||
await item.saveTx();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ describe("Zotero.Attachments", function () {
|
|||
await attachment.eraseTx();
|
||||
});
|
||||
|
||||
it("should set a child item's title to the filename, minus its extension", async function () {
|
||||
it("should set a child item's title based on its type", async function () {
|
||||
let file = getTestDataDirectory();
|
||||
file.append('test.pdf');
|
||||
let parent = await createDataObject('item');
|
||||
|
|
@ -144,7 +144,7 @@ describe("Zotero.Attachments", function () {
|
|||
await attachment.eraseTx();
|
||||
});
|
||||
|
||||
it("should set a child item's title to the filename, minus its extension", async function () {
|
||||
it("should set a child item's title based on its type", async function () {
|
||||
let file = getTestDataDirectory();
|
||||
file.append('test.pdf');
|
||||
let parent = await createDataObject('item');
|
||||
|
|
@ -152,7 +152,7 @@ describe("Zotero.Attachments", function () {
|
|||
file: file,
|
||||
parentItemID: parent.id,
|
||||
});
|
||||
assert.equal(attachment.getField('title'), 'test');
|
||||
assert.equal(attachment.getField('title'), Zotero.getString('file-type-pdf'));
|
||||
await parent.eraseTx();
|
||||
});
|
||||
})
|
||||
|
|
@ -2309,17 +2309,15 @@ describe("Zotero.Attachments", function () {
|
|||
|
||||
var attachment = await importFileAttachment('test.png', {
|
||||
parentItemID: item.id,
|
||||
// Use default setAutoAttachmentTitle() behavior -- the file isn't going to be
|
||||
// renamed because autoRenameFiles.fileTypes doesn't match image/, so the title
|
||||
// becomes the filename minus extension, i.e., "test"
|
||||
title: null
|
||||
// Pretend this was, e.g., a secondary attachment before, and it got titled
|
||||
// after the file basename
|
||||
title: 'test'
|
||||
});
|
||||
assert.equal(attachment.getField('title'), 'test');
|
||||
await renameFileFromParent(attachment);
|
||||
assert.equal(attachment.attachmentFilename, 'Title.png');
|
||||
// After a manual rename, the title becomes the default for this type
|
||||
assert.equal(attachment.getField('title'), Zotero.getString('file-type-image'));
|
||||
|
||||
});
|
||||
|
||||
it("should change attachment title if file basename matches the title", async function () {
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ describe("Document Recognition", function () {
|
|||
assert.lengthOf(addedIDs, 2);
|
||||
var item = Zotero.Items.get(addedIDs[0]);
|
||||
assert.equal(item.getField("title"), "Scaling study of an improved fermion action on quenched lattices");
|
||||
assert.lengthOf(modifiedIDs, 1);
|
||||
assert.lengthOf(modifiedIDs, 2);
|
||||
|
||||
await waitForProgressWindow();
|
||||
|
||||
|
|
@ -139,7 +139,7 @@ describe("Document Recognition", function () {
|
|||
// Item and note
|
||||
assert.lengthOf(addedIDs, 2);
|
||||
var item = Zotero.Items.get(addedIDs[0]);
|
||||
assert.lengthOf(modifiedIDs, 1);
|
||||
assert.lengthOf(modifiedIDs, 2);
|
||||
|
||||
await waitForProgressWindow();
|
||||
|
||||
|
|
@ -167,7 +167,7 @@ describe("Document Recognition", function () {
|
|||
// Item and note
|
||||
assert.lengthOf(addedIDs, 2);
|
||||
var item = Zotero.Items.get(addedIDs[0]);
|
||||
assert.lengthOf(modifiedIDs, 1);
|
||||
assert.lengthOf(modifiedIDs, 2);
|
||||
|
||||
await waitForProgressWindow();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue