From 7a6f3f9f5e8123abc83f6e40f73e84be9aa1496b Mon Sep 17 00:00:00 2001
From: windingwind <33902321+windingwind@users.noreply.github.com>
Date: Wed, 10 Jul 2024 10:28:18 +0800
Subject: [PATCH] chore: update prefs window
add: links in prefs window
fix: prefs window search shows all sections
---
addon/chrome/content/preferences.xhtml | 224 +++++++++++++------------
addon/locale/en-US/preferences.ftl | 2 +
addon/locale/it-IT/preferences.ftl | 2 +
addon/locale/ru-RU/preferences.ftl | 2 +
addon/locale/tr-TR/preferences.ftl | 2 +
addon/locale/zh-CN/preferences.ftl | 2 +
src/addon.ts | 2 -
src/modules/preferenceWindow.ts | 123 --------------
src/modules/sync/managerWindow.ts | 2 +-
src/modules/template/editorWindow.ts | 2 +-
10 files changed, 132 insertions(+), 231 deletions(-)
diff --git a/addon/chrome/content/preferences.xhtml b/addon/chrome/content/preferences.xhtml
index a1abd73..acfdca2 100644
--- a/addon/chrome/content/preferences.xhtml
+++ b/addon/chrome/content/preferences.xhtml
@@ -1,111 +1,127 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
diff --git a/addon/locale/en-US/preferences.ftl b/addon/locale/en-US/preferences.ftl
index 170fc55..e249330 100644
--- a/addon/locale/en-US/preferences.ftl
+++ b/addon/locale/en-US/preferences.ftl
@@ -26,5 +26,7 @@ template-editor =
annotation-title = PDF Annotation
annotation-autoAnnotation =
.label = Automatically add new annotations to workspace note
+
+about-title = About
help =
.value = { $name } VERSION { $version } Build { $time }
\ No newline at end of file
diff --git a/addon/locale/it-IT/preferences.ftl b/addon/locale/it-IT/preferences.ftl
index 4b9161a..0f59155 100644
--- a/addon/locale/it-IT/preferences.ftl
+++ b/addon/locale/it-IT/preferences.ftl
@@ -26,5 +26,7 @@ template-editor =
annotation-title = Annotazione PDF
annotation-autoAnnotation =
.label = Aggiungi automaticamente le nuove annotazioni alla nota di lavoro
+
+about-title = About
help =
.value = { $name } VERSION { $version } Build { $time }
diff --git a/addon/locale/ru-RU/preferences.ftl b/addon/locale/ru-RU/preferences.ftl
index d29cdfa..23aee3d 100644
--- a/addon/locale/ru-RU/preferences.ftl
+++ b/addon/locale/ru-RU/preferences.ftl
@@ -26,5 +26,7 @@ template-editor =
annotation-title = PDF Аннотация
annotation-autoAnnotation =
.label = Автодобавлять новые аннотации к заметкам раб.пространства
+
+about-title = About
help =
.value = { $name } VERSION { $version } Build { $time }
\ No newline at end of file
diff --git a/addon/locale/tr-TR/preferences.ftl b/addon/locale/tr-TR/preferences.ftl
index ee7a98b..e9a78ae 100644
--- a/addon/locale/tr-TR/preferences.ftl
+++ b/addon/locale/tr-TR/preferences.ftl
@@ -26,5 +26,7 @@ template-editor =
annotation-title = PDF Dipnotları
annotation-autoAnnotation =
.label = Çalışma alanı notuna otomatik olarak yeni dipnotlar ekle
+
+about-title = About
help =
.value = { $name } Versiyon { $version } İnşa { $time }
\ No newline at end of file
diff --git a/addon/locale/zh-CN/preferences.ftl b/addon/locale/zh-CN/preferences.ftl
index 75818d4..2a1fbc6 100644
--- a/addon/locale/zh-CN/preferences.ftl
+++ b/addon/locale/zh-CN/preferences.ftl
@@ -26,5 +26,7 @@ template-editor =
annotation-title = PDF批注
annotation-autoAnnotation =
.label = 自动添加新批注到工作区笔记
+
+about-title = 关于
help =
.value = { $name } 版本 { $version } 构建 { $time }
\ No newline at end of file
diff --git a/src/addon.ts b/src/addon.ts
index 0156e41..bf1b896 100644
--- a/src/addon.ts
+++ b/src/addon.ts
@@ -25,8 +25,6 @@ class Addon {
};
prefs?: {
window: Window;
- columns: Array;
- rows: Array<{ [dataKey: string]: string }>;
};
export: {
pdf: { promise?: _ZoteroTypes.PromiseObject };
diff --git a/src/modules/preferenceWindow.ts b/src/modules/preferenceWindow.ts
index 33be9c2..d674c1f 100644
--- a/src/modules/preferenceWindow.ts
+++ b/src/modules/preferenceWindow.ts
@@ -16,131 +16,8 @@ export function registerPrefsScripts(_window: Window) {
if (!addon.data.prefs) {
addon.data.prefs = {
window: _window,
- columns: [
- {
- dataKey: "title",
- label: "prefs.table.title",
- fixedWidth: true,
- width: 100,
- },
- {
- dataKey: "detail",
- label: "prefs.table.detail",
- },
- ],
- rows: [
- {
- title: "Orange",
- detail: "It's juicy",
- },
- {
- title: "Banana",
- detail: "It's sweet",
- },
- {
- title: "Apple",
- detail: "I mean the fruit APPLE",
- },
- ],
};
} else {
addon.data.prefs.window = _window;
}
- updatePrefsUI();
- bindPrefEvents();
-}
-
-async function updatePrefsUI() {
- // You can initialize some UI elements on prefs window
- // with addon.data.prefs.window.document
- // Or bind some events to the elements
- if (!addon.data.prefs?.window) {
- return;
- }
- const renderLock = ztoolkit.getGlobal("Zotero").Promise.defer();
- const tableHelper = new ztoolkit.VirtualizedTable(addon.data.prefs.window)
- .setContainerId(`${config.addonRef}-table-container`)
- .setProp({
- id: `${config.addonRef}-prefs-table`,
- // Do not use setLocale, as it modifies the Zotero.Intl.strings
- // Set locales directly to columns
- columns: addon.data.prefs?.columns.map((column) =>
- Object.assign(column, {
- label: getString(column.label) || column.label,
- }),
- ),
- showHeader: true,
- multiSelect: true,
- staticColumns: true,
- disableFontSizeScaling: true,
- })
- .setProp("getRowCount", () => addon.data.prefs?.rows.length || 0)
- .setProp(
- "getRowData",
- (index) =>
- addon.data.prefs?.rows[index] || {
- title: "no data",
- detail: "no data",
- },
- )
- // Show a progress window when selection changes
- .setProp("onSelectionChange", (selection) => {
- new ztoolkit.ProgressWindow(config.addonName)
- .createLine({
- text: `Selected line: ${addon.data.prefs?.rows
- .filter((v, i) => selection.isSelected(i))
- .map((row) => row.title)
- .join(",")}`,
- progress: 100,
- })
- .show();
- })
- // When pressing delete, delete selected line and refresh table.
- // Returning false to prevent default event.
- .setProp("onKeyDown", (event: KeyboardEvent) => {
- if (event.key == "Delete" || (Zotero.isMac && event.key == "Backspace")) {
- addon.data.prefs!.rows =
- addon.data.prefs?.rows.filter(
- (v, i) => !tableHelper.treeInstance.selection.isSelected(i),
- ) || [];
- tableHelper.render();
- return false;
- }
- return true;
- })
- // For find-as-you-type
- .setProp(
- "getRowString",
- (index) => addon.data.prefs?.rows[index].title || "",
- )
- // Render the table.
- .render(-1, () => {
- renderLock.resolve();
- });
- await renderLock.promise;
- ztoolkit.log("Preference table rendered!");
-}
-
-function bindPrefEvents() {
- addon.data
- .prefs!.window.document.querySelector(
- `#zotero-prefpane-${config.addonRef}-enable`,
- )
- ?.addEventListener("command", (e) => {
- ztoolkit.log(e);
- addon.data.prefs!.window.alert(
- `Successfully changed to ${(e.target as XUL.Checkbox).checked}!`,
- );
- });
-
- addon.data
- .prefs!.window.document.querySelector(
- `#zotero-prefpane-${config.addonRef}-input`,
- )
- ?.addEventListener("change", (e) => {
- ztoolkit.log(e);
- addon.data.prefs!.window.alert(
- `Successfully changed to ${(e.target as HTMLInputElement).value}!`,
- );
- });
}
diff --git a/src/modules/sync/managerWindow.ts b/src/modules/sync/managerWindow.ts
index d25456a..63faa83 100644
--- a/src/modules/sync/managerWindow.ts
+++ b/src/modules/sync/managerWindow.ts
@@ -95,7 +95,7 @@ export async function showSyncManager() {
})
.setProp(
"getRowString",
- (index) => addon.data.prefs?.rows[index].title || "",
+ (index) => addon.data.sync.manager?.data[index].noteName || "",
)
.setProp("onColumnSort", (columnIndex, ascending) => {
addon.data.sync.manager.columnIndex = columnIndex;
diff --git a/src/modules/template/editorWindow.ts b/src/modules/template/editorWindow.ts
index a8a3e49..e316a4b 100644
--- a/src/modules/template/editorWindow.ts
+++ b/src/modules/template/editorWindow.ts
@@ -68,7 +68,7 @@ export async function showTemplateEditor() {
})
.setProp(
"getRowString",
- (index) => addon.data.prefs?.rows[index].title || "",
+ (index) => addon.data.template.editor.templates[index] || "",
)
.render();
_window.document