diff --git a/TemplateDoc.md b/TemplateDoc.md index 30075ed..70f44ba 100644 --- a/TemplateDoc.md +++ b/TemplateDoc.md @@ -6,7 +6,7 @@ Use `Ctrl+F` to look up what you need and make your own template! ## Stages -Some type of templates(Item, Note) support stages. +Some type of templates(Item) support stages. Code wrapped inside the stage will be called at a specific time. @@ -60,9 +60,7 @@ In other type of templates, the default stage is called. ### Note -> beforeloop stage: notes, copyNoteImage, editor, sharedObj(for temporary variables, shared by all stages) -> default stage: noteItem, topItem, link, copyNoteImage, editor, sharedObj -> afterloop stage: notes, copyNoteImage, editor, sharedObj +> Removed after v0.7.15+ ## Formats diff --git a/TemplateUsage.md b/TemplateUsage.md index 98204c7..c1c597f 100644 --- a/TemplateUsage.md +++ b/TemplateUsage.md @@ -23,7 +23,6 @@ Copy The Name & template text to a new template and save it! These templates can have different names. The keyword must be incluede in the template name. - Text: indicate it's a normal template -- Note: indicate it's a note template. Must select notes before inserting - Item: indicate it's an item template. Must select items before inserting ### System Templates @@ -40,21 +39,3 @@ Only the template with specific name will be called. ## Template Examples Welcome to share & contribute your template! See [Templates From Community](https://github.com/windingwind/zotero-better-notes/issues/85) for more templates. - -### [Note] with meta-data - -```js -

Note: ${link}

-${topItem?`

Title: ${topItem.getField('title')}

-

Author: ${topItem.getField('firstCreator')}

-

Date: ${topItem.getField('date')}

`:''} -``` - -### [Item] meta-data - -```js -

Item Meta Data:

-

Title: ${topItem.getField('title')}

-

Author: ${topItem.getField('firstCreator')}

-

Date: ${topItem.getField('date')}

-``` diff --git a/addon/chrome/content/overlay.xul b/addon/chrome/content/overlay.xul index 8afa9d6..a7a37bd 100644 --- a/addon/chrome/content/overlay.xul +++ b/addon/chrome/content/overlay.xul @@ -65,9 +65,6 @@ - - - diff --git a/addon/chrome/content/workspace.xul b/addon/chrome/content/workspace.xul index 54e4c76..4a3f73b 100644 --- a/addon/chrome/content/workspace.xul +++ b/addon/chrome/content/workspace.xul @@ -72,9 +72,6 @@ - - - diff --git a/src/editor/editorViews.ts b/src/editor/editorViews.ts index cf69b4f..0f107ff 100644 --- a/src/editor/editorViews.ts +++ b/src/editor/editorViews.ts @@ -982,26 +982,6 @@ class EditorViews extends AddonBase { }, ], }, - { - tag: "menu", - id: "menupopup-insertNoteTemplate", - checkExistanceParent: instance._popup, - ignoreIfExists: true, - attributes: [["label", "Insert Template (Note)"]], - subElementOptions: [ - { - tag: "menupopup", - id: `menu_insert${instance._item.id}NoteTemplatePopup`, - ignoreIfExists: true, - attributes: [ - [ - "onpopupshowing", - `Zotero.Knowledge4Zotero.ZoteroViews.updateTemplateMenu('Note', Zotero.Knowledge4Zotero.EditorController.activeEditor._popup.ownerDocument, '${instance._item.id}');`, - ], - ], - }, - ], - }, { tag: "menu", id: "menupopup-insertItemTemplate", diff --git a/src/zotero/events.ts b/src/zotero/events.ts index da0e656..f88bc15 100644 --- a/src/zotero/events.ts +++ b/src/zotero/events.ts @@ -841,9 +841,7 @@ class ZoteroEvents extends AddonBase { ) as Zotero.Item; const ids = await this._Addon.ZoteroViews.openSelectItemsWindow(); - const items = (Zotero.Items.get(ids) as Zotero.Item[]).filter( - (item: Zotero.Item) => item.isRegularItem() - ); + const items = Zotero.Items.get(ids) as Zotero.Item[]; if (items.length === 0) { return; } @@ -890,9 +888,9 @@ class ZoteroEvents extends AddonBase { topItem, itemNotes, copyNoteImage, editor */ - const itemNotes: Zotero.Item[] = Zotero.Items.get( - topItem.getNotes() - ) as Zotero.Item[]; + const itemNotes: Zotero.Item[] = topItem.isNote() + ? [] + : (Zotero.Items.get(topItem.getNotes()) as Zotero.Item[]); renderredTemplate = await this._Addon.TemplateController.renderTemplateAsync( @@ -923,132 +921,6 @@ class ZoteroEvents extends AddonBase { newLines.push("

"); } - if (newLines) { - const html = newLines.join("\n"); - if (!targetItem) { - console.log(html); - - new CopyHelper() - .addText(html, "text/html") - .addText(this._Addon.NoteParse.parseHTMLToMD(html), "text/unicode") - .copy(); - progressWindow.changeHeadline("Template Copied"); - } else { - const forceMetadata = toCopyImage.length > 0; - console.log(toCopyImage); - await this._Addon.NoteUtils.addLineToNote( - targetItem, - html, - -1, - forceMetadata - ); - await Zotero.DB.executeTransaction(async () => { - for (const subNote of toCopyImage) { - await Zotero.Notes.copyEmbeddedImages(subNote, targetItem); - } - }); - progressWindow.changeHeadline("Running Template Finished"); - } - } else { - progressWindow.changeHeadline("Running Template Failed"); - } - progressWindow.startCloseTimer(5000); - } else if (message.type === "insertNoteUsingTemplate") { - /* - message.content = { - params: {templateName} - } - */ - const targetItem = Zotero.Items.get( - message.content.params.targetItemId - ) as Zotero.Item; - const ids = await this._Addon.ZoteroViews.openSelectItemsWindow(); - const notes = (Zotero.Items.get(ids) as Zotero.Item[]).filter( - (item: Zotero.Item) => item.isNote() - ); - if (notes.length === 0) { - return; - } - const progressWindow = this._Addon.ZoteroViews.showProgressWindow( - "Running Template", - message.content.params.templateName, - "default", - -1 - ); - const newLines: string[] = []; - newLines.push("

"); - - const toCopyImage: Zotero.Item[] = []; - - const copyNoteImage = (noteItem: Zotero.Item) => { - toCopyImage.push(noteItem); - }; - - const editor = - await this._Addon.WorkspaceWindow.getWorkspaceEditorInstance( - "main", - false - ); - const sharedObj = {}; - - let renderredTemplate = - await this._Addon.TemplateController.renderTemplateAsync( - message.content.params.templateName, - "notes, copyNoteImage, editor, sharedObj", - [notes, copyNoteImage, editor, sharedObj], - true, - "beforeloop" - ); - - if (renderredTemplate) { - newLines.push(renderredTemplate); - newLines.push("

"); - } - - for (const noteItem of notes) { - /* - Available variables: - noteItem, topItem, link, copyNoteImage, editor - */ - let topItem = noteItem.parentItem; - while (topItem && !topItem.isRegularItem()) { - topItem = topItem.parentItem; - } - const linkURL = this._Addon.NoteUtils.getNoteLink(noteItem); - const linkText = noteItem.getNoteTitle().trim(); - const link = `

${ - linkText ? linkText : linkURL - }

`; - - renderredTemplate = - await this._Addon.TemplateController.renderTemplateAsync( - message.content.params.templateName, - "noteItem, topItem, link, copyNoteImage, editor, sharedObj", - [noteItem, topItem, link, copyNoteImage, editor, sharedObj], - true, - "default" - ); - - if (renderredTemplate) { - newLines.push(renderredTemplate); - newLines.push("

"); - } - } - - renderredTemplate = - await this._Addon.TemplateController.renderTemplateAsync( - message.content.params.templateName, - "notes, copyNoteImage, editor, sharedObj", - [notes, copyNoteImage, editor, sharedObj], - true, - "afterloop" - ); - - if (renderredTemplate) { - newLines.push(renderredTemplate); - newLines.push("

"); - } - if (newLines) { const html = newLines.join("\n"); if (!targetItem) {