chore: add saving confirmation for template import code
This commit is contained in:
parent
d1f7fb8f8a
commit
993cb7a58d
|
|
@ -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?
|
||||
|
|
|
|||
|
|
@ -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?
|
||||
|
|
@ -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 = Вы пытаетесь сохранить код шаблона заметки. Хотите импортировать его как шаблон?
|
||||
|
|
|
|||
|
|
@ -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?
|
||||
|
|
@ -77,3 +77,4 @@ alert-notValidCollectionError=请选择一个有效的分类。
|
|||
alert-notValidParentItemError=无效的父条目。
|
||||
alert-syncImportedNotes = 保持导入的笔记与 MarkDown 文件同步?
|
||||
alert-linkCreator-emptyNote = 无法从/向空笔记创建链接。
|
||||
alert-templateEditor-shouldImport = 似乎您正在尝试直接保存一个笔记模板分享代码。您想要将其导入为模板吗?
|
||||
|
|
|
|||
|
|
@ -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<string, string>;
|
||||
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: "" };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ export default defineConfig({
|
|||
release: {
|
||||
bumpp: {
|
||||
execute: "npm run build",
|
||||
all: true,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue