Skip to content

Commit

Permalink
add: share button in template editor
Browse files Browse the repository at this point in the history
  • Loading branch information
windingwind committed Oct 18, 2024
1 parent 235362e commit 4a871a8
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/DISCUSSION_TEMPLATE/note-templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ body:
id: bn_version
attributes:
label: Test on Better Notes version
description: Please provide the Better Notes version you are using here. You can find this in the menu -> Edit -> Settings -> Better Notes.
description: Please provide the Better Notes version you are using here. You can find this in the Settings -> Better Notes.
placeholder: e.g. 1.0.4
validations:
required: true
Expand Down
3 changes: 1 addition & 2 deletions addon/chrome/content/templateEditor.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
<button id="save" data-l10n-id="save"></button>
<button id="delete" data-l10n-id="delete"></button>
<button id="reset" data-l10n-id="reset"></button>
<button id="share" data-l10n-id="share"></button>
<button id="more" data-l10n-id="more"></button>
<button
id="options"
Expand All @@ -165,8 +166,6 @@
></menuitem>
<menuitem id="importNote" data-l10n-id="importNote"></menuitem>
<menuseparator />
<menuitem id="share" data-l10n-id="share"></menuitem>
<menuseparator />
<menuitem id="backup" data-l10n-id="backup"></menuitem>
<menuitem id="restore" data-l10n-id="restore"></menuitem>
<menuseparator />
Expand Down
5 changes: 3 additions & 2 deletions addon/locale/en-US/templateEditor.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ delete =
.label = Delete
reset =
.label = Reset
share =
.label = Share
.tooltiptext = Copy template share code to clipboard
more =
.label = More Templates
.title = Get more templates online
Expand All @@ -36,8 +39,6 @@ importClipboard =
.label = Import template: from template share code in clipboard
importNote =
.label = Import template: from existing note
share =
.label = Copy template share code to clipboard
backup =
.label = Export backup file
restore =
Expand Down
5 changes: 3 additions & 2 deletions addon/locale/it-IT/templateEditor.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ delete =
.label = Elimina
reset =
.label = Ripristina
share =
.label = Share
.tooltiptext = Copia codice di condivisione template negli appunti
more =
.label = Altri Template
.title = Ottieni altri template online
Expand All @@ -36,8 +39,6 @@ importClipboard =
.label = Importa template: da il codice di condivisione template negli appunti
importNote =
.label = Importa template: da nota esistente
share =
.label = Copia codice di condivisione template negli appunti
backup =
.label = Esporta file di backup
restore =
Expand Down
5 changes: 3 additions & 2 deletions addon/locale/ru-RU/templateEditor.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ delete =
.label = Удалить
reset =
.label = Сброс
share =
.label = Share
.tooltiptext = Copy template share code to clipboard
more =
.label = Больше шаблонов
.title = Get more templates online
Expand All @@ -36,8 +39,6 @@ importClipboard =
.label = Import template: from template share code in clipboard
importNote =
.label = Import template: from existing note
share =
.label = Copy template share code to clipboard
backup =
.label = Export backup file
restore =
Expand Down
5 changes: 3 additions & 2 deletions addon/locale/tr-TR/templateEditor.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ delete =
.label = Sil
reset =
.label = Sıfırla
share =
.label = Share
.tooltiptext = Şablon paylaşım kodunu panoya kopyala
more =
.label = Daha Fazla Şablon
.title = Daha Fazla Çevrimiçi Şablon Bul
Expand All @@ -36,8 +39,6 @@ importClipboard =
.label = Şablonu İçe Aktar: panodaki şablon paylaşım kodu ile
importNote =
.label = Şablonu İçe Aktar: var olan bir nottan
share =
.label = Şablon paylaşım kodunu panoya kopyala
backup =
.label = Yedek dosyasını dışa aktar
restore =
Expand Down
5 changes: 3 additions & 2 deletions addon/locale/zh-CN/templateEditor.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ delete =
.label = 删除
reset =
.label = 重置
share =
.label = 分享
.tooltiptext = 复制模板分享代码到剪贴板
more =
.label = 更多模板
Expand All @@ -35,8 +38,6 @@ importClipboard =
.label = 导入笔记模板: 剪贴板中的模板分享代码
importNote =
.label = 导入笔记模板: 从现有笔记
share =
.label = 复制模板分享代码到剪贴板
backup =
.label = 导出模板备份文件
restore =
Expand Down
22 changes: 14 additions & 8 deletions src/modules/template/editorWindow.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import YAML = require("yamljs");
import { config } from "../../../package.json";
import { config, version } from "../../../package.json";
import { showHint } from "../../utils/hint";
import { itemPicker } from "../../utils/itemPicker";
import { getString } from "../../utils/locale";
Expand Down Expand Up @@ -163,6 +163,11 @@ export async function showTemplateEditor() {
?.addEventListener("click", (ev) => {
resetSelectedTemplate();
});
_window.document
.querySelector("#share")
?.addEventListener("click", (ev) => {
shareSelectedTemplate();
});
_window.document
.querySelector("#importClipboard")
?.addEventListener("click", (ev) => {
Expand All @@ -173,11 +178,6 @@ export async function showTemplateEditor() {
?.addEventListener("click", (ev) => {
importNoteTemplate();
});
_window.document
.querySelector("#share")
?.addEventListener("click", (ev) => {
shareSelectedTemplate();
});
_window.document
.querySelector("#backup")
?.addEventListener("click", (ev) => {
Expand Down Expand Up @@ -286,6 +286,7 @@ function updateEditor() {
const saveTemplate = win?.document.getElementById("save") as XUL.Button;
const deleteTemplate = win?.document.getElementById("delete") as XUL.Button;
const resetTemplate = win?.document.getElementById("reset") as XUL.Button;
const shareTemplate = win?.document.getElementById("share") as XUL.Button;
const formats = win?.document.getElementById(
"formats-container",
) as HTMLDivElement;
Expand All @@ -301,6 +302,7 @@ function updateEditor() {
saveTemplate.setAttribute("disabled", "true");
deleteTemplate.setAttribute("disabled", "true");
deleteTemplate.hidden = false;
shareTemplate.setAttribute("disabled", "true");
resetTemplate.hidden = true;
formats.hidden = true;
snippets.hidden = true;
Expand All @@ -323,6 +325,7 @@ function updateEditor() {
editor.hidden = false;
saveTemplate.removeAttribute("disabled");
deleteTemplate.removeAttribute("disabled");
shareTemplate.removeAttribute("disabled");
formats.hidden = false;
snippets.hidden = false;
updateSnippets(
Expand Down Expand Up @@ -620,9 +623,12 @@ function shareSelectedTemplate() {
const content = addon.api.template.getTemplateText(name);
const yaml = `# This template is specifically for importing/sharing, using better
# notes 'import from clipboard': copy the content and
# goto Zotero menu bar, click Edit->New Template from Clipboard.
# goto Zotero menu bar, click Tools->New Template from Clipboard.
# Do not copy-paste this to better notes template editor directly.
name: "${name}"
zoteroVersion: "${Zotero.version}"
pluginVersion: "${version}"
savedAt: "${new Date().toISOString()}"
content: |-
${content
.split("\n")
Expand All @@ -631,7 +637,7 @@ ${content
`;
new ztoolkit.Clipboard().addText(yaml, "text/plain").copy();
showHint(
`Template ${name} is copied to clipboard. To import it, goto Zotero menu bar, click Edit->New Template from Clipboard. `,
`Template ${name} is copied to clipboard. To import it, goto Zotero menu->Tools->New Template from Clipboard. `,
);
}

Expand Down

0 comments on commit 4a871a8

Please sign in to comment.