Skip to content

Commit

Permalink
Add Bulk Merge Function
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenglongMa committed Jan 6, 2024
1 parent 4fda48c commit 2fc0b16
Show file tree
Hide file tree
Showing 16 changed files with 418 additions and 52 deletions.
1 change: 1 addition & 0 deletions .idea/zoplicate.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added addon/chrome/content/icons/merge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 61 additions & 25 deletions addon/chrome/content/preferences.xhtml
Original file line number Diff line number Diff line change
@@ -1,33 +1,69 @@
<?xml-stylesheet href="chrome://zoplicate/content/zoteroPane.css"?>

<linkset>
<html:link rel="localization" href="__addonRef__-preferences.ftl" />
<html:link rel="localization" href="__addonRef__-preferences.ftl" />
</linkset>
<vbox id="zotero-prefpane-__addonRef__" onload="Zotero.__addonInstance__.hooks.onPrefsEvent('load', {window})">
<label>

<label>
<html:h1>__addonName__</html:h1>
</label>
<groupbox>
<label>
<html:h2 data-l10n-id="pref-title"></html:h2>
</label>

<label data-l10n-id="pref-default-action-title" />
<!-- `preference="extensions.zotero.__addonRef__.default.action"` also works. -->
<!-- Because __prefsPrefix__ = extensions.zotero.__addonRef__ in package.json-->
<radiogroup
id="zotero-prefpane-__addonRef__-default-action"
preference="__prefsPrefix__.duplicate.default.action"
orient="vertical">
<radio data-l10n-id="pref-default-action-keep-this" value="keep" />
<radio data-l10n-id="pref-default-action-keep-others" value="discard" />
<radio data-l10n-id="pref-default-action-keep-all" value="cancel" />
<radio data-l10n-id="pref-default-action-always-ask" value="ask" />
</radiogroup>
</groupbox>
</label>
<vbox class="pref-section">
<groupbox>
<label>
<html:h1 data-l10n-id="pref-duplicate-detection-title"></html:h1>
</label>

<label>
<html:h2 data-l10n-id="pref-action-title"></html:h2>
</label>

<label data-l10n-id="pref-default-action-description" />
<!-- `preference="extensions.zotero.__addonRef__.default.action"` also works. -->
<!-- Because __prefsPrefix__ = extensions.zotero.__addonRef__ in package.json-->
<radiogroup
id="zotero-prefpane-__addonRef__-default-action"
preference="__prefsPrefix__.duplicate.default.action"
orient="vertical">
<radio data-l10n-id="pref-default-action-keep-this" value="keep" />
<radio data-l10n-id="pref-default-action-keep-others" value="discard" />
<radio data-l10n-id="pref-default-action-keep-all" value="cancel" />
<radio data-l10n-id="pref-default-action-always-ask" value="ask" />
</radiogroup>
</groupbox>
</vbox>


<vbox class="pref-section">
<groupbox>
<label>
<html:h1 data-l10n-id="pref-bulk-merge-title"></html:h1>
</label>
<label>
<html:h2 data-l10n-id="pref-master-item-title"></html:h2>
</label>

<label data-l10n-id="pref-master-item-description" />
<radiogroup
id="zotero-prefpane-__addonRef__-master-item"
preference="__prefsPrefix__.bulk.master.item"
orient="vertical">
<radio data-l10n-id="pref-default-master-item-oldest" value="oldest" />
<radio data-l10n-id="pref-default-master-item-newest" value="newest" />
<radio data-l10n-id="pref-default-master-item-modified" value="modified" />
<radio data-l10n-id="pref-default-master-item-detailed" value="detailed" />
<!-- <radio data-l10n-id="pref-default-master-item-always-ask" value="ask" />-->

</radiogroup>
</groupbox>
</vbox>

<spacer height="20" />
</vbox>


<spacer height="20" flex="1" />
<vbox>
<html:label
data-l10n-id="pref-help"
data-l10n-args='{"time": "__buildTime__","name": "__addonName__","version":"__buildVersion__"}'></html:label>
<html:label
data-l10n-id="pref-help"
data-l10n-args='{"time": "__buildTime__","name": "__addonName__","version":"__buildVersion__"}'></html:label>
</vbox>
5 changes: 5 additions & 0 deletions addon/chrome/content/zoteroPane.css
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
/* Put your custom css style here */
/* Headers in subsections */
.pref-section {
margin-top: 16px;
border-top: 1px solid lightgray;
}
13 changes: 13 additions & 0 deletions addon/locale/en-US/addon.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,16 @@ du-dialog-button-cancel = Cancel
## Messages
du-progress-text = Processing Duplicates...
du-progress-done = All duplicates have been processed.
duplicate-panel-message = Or
bulk-merge-title = Bulk Merge All Duplicate Items
bulk-merge-message = This will merge all duplicate items in your library. Are you sure you want to continue?
bulk-merge-sub-message = - Master Item Preference: [{ $masterItem }]
bulk-merge-sub-message-2 = - You can change the preference in Edit > Settings > Zoplicate.
bulk-merge-master-item-oldest = Earliest Added
bulk-merge-master-item-newest = Latest Added
bulk-merge-master-item-modified = Latest Modified
bulk-merge-master-item-detailed = Most Detailed
bulk-merge-popup-prepare = Preparing...
bulk-merge-popup-process = Processing: { $item }
21 changes: 19 additions & 2 deletions addon/locale/en-US/preferences.ftl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pref-title = Default Preferences
pref-default-action-title = Default action to process duplicate items
pref-duplicate-detection-title = Duplicate Detection
pref-action-title = Action Preferences
pref-default-action-description = Default action to process duplicate items
pref-default-action-keep-this =
.label = [Keep This]: Save the last imported item and delete the rest
Expand All @@ -10,4 +12,19 @@ pref-default-action-keep-all =
pref-default-action-always-ask =
.label = [Always Ask]: Ask for action every time
pref-bulk-merge-title = Bulk Merge
pref-master-item-title = Master Item Preferences
pref-master-item-description = Choose the version of duplicate items to use as the master item
pref-default-master-item-oldest =
.label = [Earliest Added]: The oldest item according to the added date
pref-default-master-item-newest =
.label = [Latest Added]: The latest item according to the added date
pref-default-master-item-modified =
.label = [Latest Modified]: The latest item according to the modified date
pref-default-master-item-detailed =
.label = [Most Detailed]: The item with the most fields filled
pref-default-master-item-always-ask =
.label = [Always Ask]: Ask for master item every time
pref-help = { $name } Build { $version } { $time }
13 changes: 13 additions & 0 deletions addon/locale/zh-CN/addon.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,16 @@ du-dialog-button-cancel = 取消
## Messages
du-progress-text = 正在处理重复条目...
du-progress-done = 所有重复条目已处理完成。
duplicate-panel-message = 或者
bulk-merge-title = 批量合并所有重复条目
bulk-merge-message = 这将合并您库中的所有重复条目。您确定要继续吗?
bulk-merge-sub-message = - 主条目设置为: [{ $masterItem }]
bulk-merge-sub-message-2 = - 您可在 编辑 > 设置 > Zoplicate 中更改该设置。
bulk-merge-master-item-oldest = 最早添加的
bulk-merge-master-item-newest = 最新添加的
bulk-merge-master-item-modified = 最近修改的
bulk-merge-master-item-detailed = 最详细的
bulk-merge-popup-prepare = 准备中...
bulk-merge-popup-process = 正在处理: { $item }
21 changes: 19 additions & 2 deletions addon/locale/zh-CN/preferences.ftl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pref-title = 默认设置
pref-default-action-title = 处理重复条目的默认操作
pref-duplicate-detection-title = 重复条目监测
pref-action-title = 默认操作设置
pref-default-action-description = 处理重复条目的默认操作
pref-default-action-keep-this =
.label = [保留最新的]: 保留新导入条目,删除库中原有的
Expand All @@ -10,4 +12,19 @@ pref-default-action-keep-all =
pref-default-action-always-ask =
.label = [始终询问]: 每次都询问我该如何处理
pref-bulk-merge-title = 批量合并
pref-master-item-title = 主条目设置
pref-master-item-description = 选择作为主条目的条目版本
pref-default-master-item-oldest =
.label = [最早添加的]: 根据添加日期选择最早的条目
pref-default-master-item-newest =
.label = [最新添加的]: 根据添加日期选择最新的条目
pref-default-master-item-modified =
.label = [最近修改的]: 根据修改日期选择最近的条目
pref-default-master-item-detailed =
.label = [最详细的]: 选择字段内容最详细的条目
pref-default-master-item-always-ask =
.label = [始终询问]: 每次都询问我该如何选择主条目
pref-help = { $name } Build { $version } { $time }
1 change: 1 addition & 0 deletions addon/prefs.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/* eslint-disable no-undef */
pref("__prefsPrefix__.duplicate.default.action", "ask");
pref("__prefsPrefix__.bulk.master.item", "oldest");
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zoplicate",
"version": "1.1.0",
"version": "2.0.0",
"description": "Detect and manage duplicate items in Zotero.",
"config": {
"addonName": "Zoplicate",
Expand Down Expand Up @@ -42,7 +42,7 @@
},
"homepage": "https://chenglongma.com/zoplicate/",
"dependencies": {
"zotero-plugin-toolkit": "^2.3.6"
"zotero-plugin-toolkit": "^2.3.16"
},
"devDependencies": {
"@types/node": "^20.6.0",
Expand Down
8 changes: 7 additions & 1 deletion src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { getString, initLocale } from "./utils/locale";
import { registerPrefs, registerPrefsScripts } from "./modules/preferenceScript";
import { createZToolkit } from "./utils/ztoolkit";
import { Notifier } from "./modules/notifier";
import { registerStyleSheet } from "./utils/window";
import { registerUIElements } from "./modules/ui";

async function onStartup() {
await Promise.all([Zotero.initializationPromise, Zotero.unlockPromise, Zotero.uiReadyPromise]);
Expand All @@ -18,6 +20,8 @@ async function onStartup() {
async function onMainWindowLoad(win: Window): Promise<void> {
// Create ztoolkit for every window
addon.data.ztoolkit = createZToolkit();
registerStyleSheet();
registerUIElements(win);
}

async function onMainWindowUnload(win: Window): Promise<void> {
Expand All @@ -36,10 +40,12 @@ function onShutdown(): void {
/**
* This function is just an example of dispatcher for Notify events.
* Any operations should be placed in a function to keep this function clear.
*
* Refer to: https://github.com/zotero/zotero/blob/main/chrome/content/zotero/xpcom/notifier.js
*/
async function onNotify(event: string, type: string, ids: Array<string | number>, extraData: { [key: string]: any }) {
// You can add your code to the corresponding notify type
ztoolkit.log("notify", event, type, ids, extraData);
// ztoolkit.log("notify", event, type, ids, extraData);
if (event == "add" && type == "item") {
await Notifier.whenAddItems(ids as number[]);
}
Expand Down
Loading

0 comments on commit 2fc0b16

Please sign in to comment.