diff --git a/addon/locale/zh-CN/preferences.ftl b/addon/locale/zh-CN/preferences.ftl index 18b10a2..f918aeb 100644 --- a/addon/locale/zh-CN/preferences.ftl +++ b/addon/locale/zh-CN/preferences.ftl @@ -6,8 +6,8 @@ source-title = 源路径 source-intro = <附加新文件> 会从该目录检索最近添加的文件并附加到 Zotero 条目/分类下。 attach-title = 附加类型 -attach-intro = 若使用 Zotero 官方或 WebDAV 同步,请选择 <作为副本>;若使用第三方官方同步,如坚果云、OneDrive等,请选择 <作为链接> 并认真配置 <靶路径>,文件将会被移动到靶路径下后作为链接类型附件导入 Zotero。 -attach-type-start = 附加文件 +attach-intro = 若使用 Zotero 官方或 WebDAV 同步,请选择作为 <副本>;若使用第三方官方同步,如坚果云、OneDrive等,请选择作为 <链接> 并认真配置 <靶路径>,文件将会被移动到靶路径下后作为链接类型附件导入 Zotero。 +attach-type-start = 附加文件作为 attach-type-end = 到 Zotero 的条目/分类下 importing = .label = 副本 diff --git a/addon/prefs.js b/addon/prefs.js index 2f5d11d..8497571 100644 --- a/addon/prefs.js +++ b/addon/prefs.js @@ -1,10 +1,9 @@ /* eslint-disable no-undef */ pref("__prefsPrefix__.enable", true); pref("__prefsPrefix__.attachType", "linking"); -pref("__prefsPrefix__.subfolderFormat", `{{collection}}/{{year}}`); +pref("__prefsPrefix__.subfolderFormat", `{{collection}}`); pref("__prefsPrefix__.sourceDir", ""); pref("__prefsPrefix__.destDir", ""); pref("__prefsPrefix__.autoMove", true); -pref("__prefsPrefix__.move", "linking"); pref("__prefsPrefix__.fileTypes", "pdf,doc,docx,txt,rtf,djvu,epub"); pref("__prefsPrefix__.autoRemoveEmptyFolder", false); diff --git a/package.json b/package.json index a9fbcdb..556b64e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zotero-attanger", - "version": "1.0.8", + "version": "1.0.9", "description": "Attanger for Zotero", "config": { "addonName": "Zotero Attanger", @@ -132,4 +132,4 @@ "after:release": "echo Successfully released ${name} v${version} to ${repo.repository}." } } -} +} \ No newline at end of file diff --git a/src/modules/menu.ts b/src/modules/menu.ts index eed5bfe..ab4d0ae 100644 --- a/src/modules/menu.ts +++ b/src/modules/menu.ts @@ -154,7 +154,8 @@ export default class Menu { commandListener: async (ev) => { for (const item of getAttachmentItems()) { try { - await renameFile(item); + const attItem = await renameFile(item); + attItem && showAttachmentItem(attItem) } catch (e) { ztoolkit.log(e); } @@ -168,7 +169,8 @@ export default class Menu { commandListener: async (ev) => { for (const item of getAttachmentItems()) { try { - await moveFile(item); + const attItem = await moveFile(item); + attItem && showAttachmentItem(attItem) } catch (e) { ztoolkit.log(e); } @@ -352,8 +354,7 @@ async function renameFile(attItem: Zotero.Item) { attItem.setField("title", newName); await attItem.saveTx(); } - // window.alert("newName: " + newName) - return newName; + return attItem; } /** @@ -378,7 +379,6 @@ export async function moveFile(attItem: Zotero.Item) { } } // 2. 中间路径 - // const folderSep = Zotero.isWin ? "\\" : "/"; let subfolder = ""; const subfolderFormat = getPref("subfolderFormat") as string; // Zotero.Attachments.getFileBaseNameFromItem 补充不支持的变量 @@ -433,7 +433,8 @@ export async function moveFile(attItem: Zotero.Item) { if (sourcePath !== destPath) { try { await OS.File.move(sourcePath, destPath); - } catch { + } catch (e) { + ztoolkit.log(e) return await moveFile(attItem); } } @@ -443,10 +444,32 @@ export async function moveFile(attItem: Zotero.Item) { parentItemID: attItem.topLevelItem.id, collections: undefined, }; - await attItem.eraseTx(); - attItem = await Zotero.Attachments.linkFromFile(options); - removeEmptyFolder(OS.Path.dirname(sourcePath)); - return attItem; + const newAttItem = await Zotero.Attachments.linkFromFile(options); + window.setTimeout(async () => { + // 迁移标注 + ztoolkit.log("迁移标注") + await Zotero.DB.executeTransaction(async function () { + await Zotero.Items.moveChildItems(attItem, newAttItem); + }); + // 迁移相关 + ztoolkit.log("迁移相关") + await Zotero.Relations.copyObjectSubjectRelations(attItem, newAttItem); + // 迁移索引 + ztoolkit.log("迁移索引") + await Zotero.DB.executeTransaction(async function () { + await Zotero.Fulltext.transferItemIndex(attItem, newAttItem); + }); + // 迁移标签 + ztoolkit.log("迁移标签") + newAttItem.setTags(attItem.getTags()) + // 迁移PDF笔记 + ztoolkit.log("迁移PDF笔记") + newAttItem.setNote(attItem.getNote()) + await newAttItem.saveTx() + removeEmptyFolder(OS.Path.dirname(sourcePath)); + await attItem.eraseTx(); + }) + return newAttItem; } async function attachNewFile(options: { @@ -524,8 +547,8 @@ function getCollectionPathsOfItem(item: Zotero.Item) { } return OS.Path.normalize( getCollectionPath(collection.parentID) + - addon.data.folderSep + - collection.name, + addon.data.folderSep + + collection.name, ) as string; }; try {