diff --git a/addon/chrome/content/syncManager.xhtml b/addon/chrome/content/syncManager.xhtml index 5295cbc..a27c9e8 100644 --- a/addon/chrome/content/syncManager.xhtml +++ b/addon/chrome/content/syncManager.xhtml @@ -32,11 +32,6 @@ "chrome://zotero/content/include.js", this, ); - - Services.scriptloader.loadSubScript( - "resource://zotero/require.js", - this, - ); window.arguments[0]._initPromise.resolve(); }); @@ -47,12 +42,12 @@ padding: 0; margin: 0; height: 100%; - overflow-x: hidden; - overflow-y: auto; + overflow: hidden; word-wrap: break-word; } .viewport { margin: 0 5px 0 5px; + overflow-y: auto; } .viewport-container { padding: 0; @@ -62,6 +57,7 @@ display: flex; flex-direction: row; overflow: hidden; + background: var(--material-background); } .list-viewport { width: 100%; @@ -89,6 +85,7 @@ + diff --git a/addon/locale/en-US/addon.ftl b/addon/locale/en-US/addon.ftl index b54f5e4..030c829 100644 --- a/addon/locale/en-US/addon.ftl +++ b/addon/locale/en-US/addon.ftl @@ -26,11 +26,14 @@ editor-previewImage-title = Preview Image syncManager-noteName = Note Name syncManager-lastSync = Last Sync syncManager-filePath = MarkDown Path +syncManager-detectConfirmInfo = {$total} synced markdown files detected in {$dir} + {$new} new, {$current} will be updated. + Do you want to apply the changes? syncInfo-syncTo = MarkDown Path syncInfo-lastSync = Last Sync syncInfo-sync = Sync -syncInfo-unSync = UnSync +syncInfo-unSync = Unsync syncInfo-reveal = Show in Folder syncInfo-manager = Sync Manager syncInfo-export = Export As... diff --git a/addon/locale/en-US/syncManager.ftl b/addon/locale/en-US/syncManager.ftl index f8ab50f..b3437af 100644 --- a/addon/locale/en-US/syncManager.ftl +++ b/addon/locale/en-US/syncManager.ftl @@ -1,7 +1,13 @@ title = Sync Manager refresh = .label = Refresh + .tooltiptext = Refresh the list of notes sync = .label = Sync + .tooltiptext = Sync the selected notes immediately unSync = - .label = UnSync + .label = Unsync + .tooltiptext = Unsync the selected notes +detect = + .label = Detect... + .tooltiptext = Detect synced notes from folder diff --git a/addon/locale/it-IT/addon.ftl b/addon/locale/it-IT/addon.ftl index f393a93..b084440 100644 --- a/addon/locale/it-IT/addon.ftl +++ b/addon/locale/it-IT/addon.ftl @@ -22,6 +22,9 @@ templateEditor-templateName = Nome template syncManager-noteName = Nome nota syncManager-lastSync = Ultima sincronizzazione syncManager-filePath = Percorso MarkDown +syncManager-detectConfirmInfo = {$total} synced markdown files detected in {$dir} + {$new} new, {$current} will be updated. + Do you want to apply the changes? syncInfo-syncTo = Percorso MarkDown syncInfo-lastSync = Ultima sincronizzazione diff --git a/addon/locale/it-IT/syncManager.ftl b/addon/locale/it-IT/syncManager.ftl index dcdeef9..03f3fa9 100644 --- a/addon/locale/it-IT/syncManager.ftl +++ b/addon/locale/it-IT/syncManager.ftl @@ -1,7 +1,13 @@ title = Manager di sincronizzazione refresh = .label = Aggiorna + .tooltiptext = Refresh the list of notes sync = .label = Sincronizza + .tooltiptext = Sync the selected notes immediately unSync = .label = Interrompi sincronizzazione + .tooltiptext = Unsync the selected notes +detect = + .label = Detect... + .tooltiptext = Detect synced notes from folder diff --git a/addon/locale/ru-RU/addon.ftl b/addon/locale/ru-RU/addon.ftl index 5315109..17a4122 100644 --- a/addon/locale/ru-RU/addon.ftl +++ b/addon/locale/ru-RU/addon.ftl @@ -26,6 +26,9 @@ editor-previewImage-title = Preview Image syncManager-noteName=Имя заметки syncManager-lastSync=Последний Синк syncManager-filePath=MarkDown путь +syncManager-detectConfirmInfo = {$total} synced markdown files detected in {$dir} + {$new} new, {$current} will be updated. + Do you want to apply the changes? syncInfo-syncTo=MarkDown путь syncInfo-lastSync=Последний Синк diff --git a/addon/locale/ru-RU/syncManager.ftl b/addon/locale/ru-RU/syncManager.ftl index 3249504..a285c02 100644 --- a/addon/locale/ru-RU/syncManager.ftl +++ b/addon/locale/ru-RU/syncManager.ftl @@ -1,7 +1,13 @@ title = Синк Менеджер refresh = .label = Обновить + .tooltiptext = Refresh the list of notes sync = .label = Синк + .tooltiptext = Sync the selected notes immediately unSync = .label = ДеСинк + .tooltiptext = Unsync the selected notes +detect = + .label = Detect... + .tooltiptext = Detect synced notes from folder diff --git a/addon/locale/tr-TR/addon.ftl b/addon/locale/tr-TR/addon.ftl index 695ebb9..31c8991 100644 --- a/addon/locale/tr-TR/addon.ftl +++ b/addon/locale/tr-TR/addon.ftl @@ -26,6 +26,9 @@ editor-previewImage-title = Resmi Önizle syncManager-noteName = Not Adı syncManager-lastSync = Son Senkronizasyon syncManager-filePath = MarkDown Yolu +syncManager-detectConfirmInfo = {$total} synced markdown files detected in {$dir} + {$new} new, {$current} will be updated. + Do you want to apply the changes? syncInfo-syncTo = MarkDown Yolu syncInfo-lastSync = Son Senkronizasyon diff --git a/addon/locale/tr-TR/syncManager.ftl b/addon/locale/tr-TR/syncManager.ftl index d32e7d1..9cf1a5f 100644 --- a/addon/locale/tr-TR/syncManager.ftl +++ b/addon/locale/tr-TR/syncManager.ftl @@ -1,7 +1,13 @@ title = Sync Manager refresh = .label = Yenile + .tooltiptext = Refresh the list of notes sync = .label = Senkronize Et + .tooltiptext = Sync the selected notes immediately unSync = .label = Senkronizasyonu Geri Al + .tooltiptext = Unsync the selected notes +detect = + .label = Detect... + .tooltiptext = Detect synced notes from folder diff --git a/addon/locale/zh-CN/addon.ftl b/addon/locale/zh-CN/addon.ftl index f4b69a0..8a86bc4 100644 --- a/addon/locale/zh-CN/addon.ftl +++ b/addon/locale/zh-CN/addon.ftl @@ -26,6 +26,9 @@ editor-previewImage-title = 预览图片 syncManager-noteName=笔记名称 syncManager-lastSync=最近同步 syncManager-filePath=MarkDown路径 +syncManager-detectConfirmInfo = 扫描到{$total}项由本插件同步的markdown文件 (来自{$dir}) + 将要新同步{$new}项, 将要覆盖{$current}项 + 确定应用这些更改吗? syncInfo-syncTo=MarkDown路径 syncInfo-lastSync=最近同步 diff --git a/addon/locale/zh-CN/syncManager.ftl b/addon/locale/zh-CN/syncManager.ftl index 4a6ceab..e057ca9 100644 --- a/addon/locale/zh-CN/syncManager.ftl +++ b/addon/locale/zh-CN/syncManager.ftl @@ -1,7 +1,13 @@ title = 同步管理 refresh = .label = 刷新 + .tooltiptext = 刷新同步笔记列表 sync = .label = 同步 + .tooltiptext = 立刻同步选中的笔记 unSync = .label = 取消同步 + .tooltiptext = 不再同步选中的笔记 +detect = + .label = 扫描... + .tooltiptext = 从文件夹扫描已同步的笔记 diff --git a/src/api.ts b/src/api.ts index 631eb15..64b381f 100644 --- a/src/api.ts +++ b/src/api.ts @@ -28,6 +28,7 @@ import { getMDStatus, getMDStatusFromContent, getMDFileName, + findAllSyncedFiles, } from "./modules/sync/api"; import { runTemplate, @@ -92,6 +93,7 @@ const sync = { getMDStatus, getMDStatusFromContent, getMDFileName, + findAllSyncedFiles, }; const convert = { diff --git a/src/modules/sync/api.ts b/src/modules/sync/api.ts index 4a2d23d..2c5b082 100644 --- a/src/modules/sync/api.ts +++ b/src/modules/sync/api.ts @@ -15,6 +15,7 @@ export { getMDStatus, getMDStatusFromContent, getMDFileName, + findAllSyncedFiles, }; function initSyncList() { @@ -210,3 +211,43 @@ async function getMDFileName(noteId: number, searchDir?: string) { [noteItem], ); } + +async function findAllSyncedFiles(searchDir: string) { + const results: SyncStatus[] = []; + const mdRegex = /\.(md|MD|Md|mD)$/; + await Zotero.File.iterateDirectory( + searchDir, + async (entry: OS.File.Entry) => { + if (entry.isDir) { + const subDirResults = await findAllSyncedFiles(entry.path); + results.push(...subDirResults); + return; + } + if (mdRegex.test(entry.name)) { + const MDStatus = await getMDStatus(entry.path); + if (!MDStatus.meta?.$libraryID || !MDStatus.meta?.$itemKey) { + return; + } + const item = await Zotero.Items.getByLibraryAndKeyAsync( + MDStatus.meta.$libraryID, + MDStatus.meta.$itemKey, + ); + if (!item || !(item as Zotero.Item).isNote()) { + return; + } + results.push({ + path: MDStatus.filedir, + filename: MDStatus.filename, + md5: Zotero.Utilities.Internal.md5(MDStatus.content, false), + noteMd5: Zotero.Utilities.Internal.md5( + (item as Zotero.Item).getNote(), + false, + ), + lastsync: MDStatus.lastmodify.getTime(), + itemID: item.id, + }); + } + }, + ); + return results; +} diff --git a/src/modules/sync/managerWindow.ts b/src/modules/sync/managerWindow.ts index ec32561..c662cb0 100644 --- a/src/modules/sync/managerWindow.ts +++ b/src/modules/sync/managerWindow.ts @@ -110,6 +110,9 @@ export async function showSyncManager() { const unSyncButton = win.document.querySelector( "#unSync", ) as HTMLButtonElement; + const detectButton = win.document.querySelector( + "#detect", + ) as HTMLButtonElement; refreshButton.addEventListener("click", (ev) => { refresh(); }); @@ -127,6 +130,9 @@ export async function showSyncManager() { }); refresh(); }); + detectButton.addEventListener("click", () => { + detectSyncedNotes(); + }); } } @@ -218,5 +224,41 @@ async function unSyncNotes(itemIds: number[]) { for (const itemId of itemIds) { await addon.api.sync.removeSyncNote(itemId); } - refresh(); + await refresh(); +} + +async function detectSyncedNotes() { + const dir = await new addon.data.ztoolkit.FilePicker( + "Select folder to detect", + "folder", + ).open(); + if (!dir) return; + + const statusList = await addon.api.sync.findAllSyncedFiles(dir); + let current = 0; + for (const status of statusList) { + if (addon.api.sync.isSyncNote(status.itemID)) { + current++; + } + } + const total = statusList.length; + const newCount = total - current; + if ( + !addon.data.sync.manager.window?.confirm( + getString("syncManager-detectConfirmInfo", { + args: { + total, + new: newCount, + current, + dir, + }, + }), + ) + ) + return; + for (const status of statusList) { + addon.api.sync.updateSyncStatus(status.itemID, status); + } + await addon.hooks.onSyncing(); + await refresh(); }