diff --git a/addon/locale/en-US/addon.ftl b/addon/locale/en-US/addon.ftl index 358c1f2..b54f5e4 100644 --- a/addon/locale/en-US/addon.ftl +++ b/addon/locale/en-US/addon.ftl @@ -77,3 +77,4 @@ alert-notValidCollectionError = Please select a valid collection. alert-notValidParentItemError = No valid parent item. alert-syncImportedNotes = Keep imported notes in sync with MarkDown files? alert-linkCreator-emptyNote = Cannot create link from/to an empty note. +alert-templateEditor-shouldImport = Seems like you are trying to directly save a note template share code. Do you want to import it as a template? diff --git a/addon/locale/it-IT/addon.ftl b/addon/locale/it-IT/addon.ftl index ffb9c9f..f393a93 100644 --- a/addon/locale/it-IT/addon.ftl +++ b/addon/locale/it-IT/addon.ftl @@ -73,3 +73,4 @@ alert-notValidCollectionError = Si prega di scegliere una collezione valida. alert-notValidParentItemError = Nessun elemento genitore valido. alert-syncImportedNotes = Si desidera sincronizzare le note importate con i file markdown? alert-linkCreator-emptyNote = Cannot create link from/to an empty note. +alert-templateEditor-shouldImport = Sembra che tu stia cercando di salvare direttamente un codice di condivisione di un template di nota. Vuoi importarlo come template? \ No newline at end of file diff --git a/addon/locale/ru-RU/addon.ftl b/addon/locale/ru-RU/addon.ftl index 1cbddf9..5315109 100644 --- a/addon/locale/ru-RU/addon.ftl +++ b/addon/locale/ru-RU/addon.ftl @@ -77,3 +77,4 @@ alert-notValidCollectionError=Выберите валидную коллекци alert-notValidParentItemError=Нет валидного родительского элемента. alert-syncImportedNotes = Синхронизировать импортированные заметки с файлами MarkDown? alert-linkCreator-emptyNote = Cannot create link from/to an empty note. +alert-templateEditor-shouldImport = Вы пытаетесь сохранить код шаблона заметки. Хотите импортировать его как шаблон? diff --git a/addon/locale/tr-TR/addon.ftl b/addon/locale/tr-TR/addon.ftl index a1d3c6e..695ebb9 100644 --- a/addon/locale/tr-TR/addon.ftl +++ b/addon/locale/tr-TR/addon.ftl @@ -77,3 +77,4 @@ alert-notValidCollectionError = Lütfen geçerli bir koleksiyon seçin. alert-notValidParentItemError = Geçerli üst öge yok. alert-syncImportedNotes = İçe aktarılmış notları Markdown dosyalarıyla senkron tutmak ister misiniz? alert-linkCreator-emptyNote = Cannot create link from/to an empty note. +alert-templateEditor-shouldImport = Şablon kodunu doğrudan kaydetmeye çalışıyorsunuz gibi görünüyor. Şablon olarak içe aktarmak ister misiniz? \ No newline at end of file diff --git a/addon/locale/zh-CN/addon.ftl b/addon/locale/zh-CN/addon.ftl index fd9b458..f4b69a0 100644 --- a/addon/locale/zh-CN/addon.ftl +++ b/addon/locale/zh-CN/addon.ftl @@ -77,3 +77,4 @@ alert-notValidCollectionError=请选择一个有效的分类。 alert-notValidParentItemError=无效的父条目。 alert-syncImportedNotes = 保持导入的笔记与 MarkDown 文件同步? alert-linkCreator-emptyNote = 无法从/向空笔记创建链接。 +alert-templateEditor-shouldImport = 似乎您正在尝试直接保存一个笔记模板分享代码。您想要将其导入为模板吗? diff --git a/src/modules/template/controller.ts b/src/modules/template/controller.ts index 6348c98..136f349 100644 --- a/src/modules/template/controller.ts +++ b/src/modules/template/controller.ts @@ -75,17 +75,19 @@ function removeTemplate( } } -function importTemplateFromClipboard() { - const templateText = Zotero.Utilities.Internal.getClipboard("text/plain"); - if (!templateText) { +function importTemplateFromClipboard(text?: string) { + if (!text) { + text = Zotero.Utilities.Internal.getClipboard("text/plain") || ""; + } + if (!text) { return; } let template: Record; try { - template = YAML.parse(templateText); + template = YAML.parse(text); } catch (e) { try { - template = JSON.parse(templateText); + template = JSON.parse(text); } catch (e) { template = { name: "", text: "" }; } diff --git a/src/modules/template/editorWindow.ts b/src/modules/template/editorWindow.ts index 24b9042..4ac31e4 100644 --- a/src/modules/template/editorWindow.ts +++ b/src/modules/template/editorWindow.ts @@ -269,8 +269,23 @@ function saveSelectedTemplate() { const template = { name: header.value, - text: addon.data.template.editor.editor.getValue(), + text: addon.data.template.editor.editor.getValue() as string, }; + if ( + template.text.includes( + "# This template is specifically for importing/sharing", + ) + ) { + const useImport = addon.data.template.editor.window?.confirm( + getString("alert-templateEditor-shouldImport"), + ); + if (useImport) { + addon.hooks.onImportTemplateFromClipboard(template.text); + refresh(); + return; + } + } + addon.api.template.setTemplate(template); if (name !== template.name) { addon.api.template.removeTemplate(name); diff --git a/zotero-plugin.config.ts b/zotero-plugin.config.ts index b45ddf3..5b1e5ee 100644 --- a/zotero-plugin.config.ts +++ b/zotero-plugin.config.ts @@ -58,6 +58,7 @@ export default defineConfig({ release: { bumpp: { execute: "npm run build", + all: true, }, },