Skip to content

Commit

Permalink
add: quicknote template
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangyu committed Jun 10, 2022
1 parent 81ac8b6 commit fc01593
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
4 changes: 2 additions & 2 deletions addon/chrome/content/overlay.xul
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
<menuseparator class="menu-type-betternotes" />
<menuitem id="menu_new_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.new;" key="key_new_betternotes" accesskey="N" command="cmd_new_betternotes" />
<menuitem id="menu_open_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.open;" key="key_open_betternotes" accesskey="O" command="cmd_open_betternotes" />
<menuitem id="menu_openWindow_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.openWindow;" command="cmd_open_betternotesWindow" />
<menuitem id="menu_export_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.export;" key="key_export_betternotes" accesskey="E" command="cmd_export_betternotes" />
</menupopup>

Expand All @@ -73,10 +72,11 @@
</menupopup>

<menupopup id="menu_viewPopup">
<menuitem id="menu_openWindow_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.openWindow;" command="cmd_open_betternotesWindow" />
<menuseparator class="menu-type-betternotes" />
<menuitem id="menu_treeview" class="menu-type-betternotes" type="checkbox" label="&zotero.__addonRef__.workspace.menu.treeview;" command="cmd_treeview_betternotes" />
<menuitem id="menu_mindmap" class="menu-type-betternotes" type="checkbox" label="&zotero.__addonRef__.workspace.menu.mindmap;" command="cmd_mindmap_betternotes" />
<menuitem id="menu_bubblemap" class="menu-type-betternotes" type="checkbox" label="&zotero.__addonRef__.workspace.menu.bubblemap;" command="cmd_bubblemap_betternotes" />
<menuitem id="menu_bubblemap" class="menu-type-betternotes" type="checkbox" label="&zotero.__addonRef__.workspace.menu.bubblemap;" command="cmd_bubblemap_betternotes" />
</menupopup>

<menupopup id="menu_HelpPopup">
Expand Down
3 changes: 2 additions & 1 deletion addon/chrome/content/workspace.xul
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
<menupopup id="menu_FilePopup">
<menuitem id="menu_new" label="&zotero.__addonRef__.workspace.menu.new;" key="key_new" accesskey="N" command="cmd_new" />
<menuitem id="menu_open" label="&zotero.__addonRef__.workspace.menu.open;" key="key_open" accesskey="O" command="cmd_open" />
<menuitem id="menu_openWindow" label="&zotero.__addonRef__.workspace.menu.openWindow;" command="cmd_openWindow" />
<menuitem id="menu_export" label="&zotero.__addonRef__.workspace.menu.export;" key="key_export" accesskey="E" command="cmd_export" />
<menuitem id="menu_close" label="&closeCmd.label;" key="key_close" accesskey="&closeCmd.accesskey;" command="cmd_close" />
</menupopup>
Expand Down Expand Up @@ -84,6 +83,8 @@

<menu id="view-menu" label="&viewMenu.label;" accesskey="&viewMenu.accesskey;" onpopupshowing="Zotero.Knowledge4Zotero.views.updateViewMenu();">
<menupopup id="menu_ViewPopup">
<menuitem id="menu_openWindow" label="&zotero.__addonRef__.workspace.menu.openWindow;" command="cmd_openWindow" />
<menuseparator />
<menuitem id="menu_treeview" type="checkbox" label="&zotero.__addonRef__.workspace.menu.treeview;" command="cmd_treeview" />
<menuitem id="menu_mindmap" type="checkbox" label="&zotero.__addonRef__.workspace.menu.mindmap;" command="cmd_mindmap" />
<menuitem id="menu_bubblemap" type="checkbox" label="&zotero.__addonRef__.workspace.menu.bubblemap;" command="cmd_bubblemap" />
Expand Down
2 changes: 1 addition & 1 deletion addon/chrome/locale/en-US/overlay.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!ENTITY zotero.__addonRef__.workspace.menu.new "Create New Main Note">
<!ENTITY zotero.__addonRef__.workspace.menu.open "Open Main Note...">
<!ENTITY zotero.__addonRef__.workspace.menu.openWindow "Open in New Window">
<!ENTITY zotero.__addonRef__.workspace.menu.openWindow "Open Workspace in Standalone Window">
<!ENTITY zotero.__addonRef__.workspace.menu.export "Export Main Note...">
<!ENTITY zotero.__addonRef__.workspace.menu.insertNotes "Insert Notes...">
<!ENTITY zotero.__addonRef__.workspace.menu.insertTextTemplate "Insert Template">
Expand Down
2 changes: 1 addition & 1 deletion addon/chrome/locale/zh-CN/overlay.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!ENTITY zotero.__addonRef__.workspace.menu.new "创建新主笔记">
<!ENTITY zotero.__addonRef__.workspace.menu.open "打开主笔记...">
<!ENTITY zotero.__addonRef__.workspace.menu.openWindow "在新窗口中打开">
<!ENTITY zotero.__addonRef__.workspace.menu.openWindow "在独立窗口中打开工作区">
<!ENTITY zotero.__addonRef__.workspace.menu.export "导出主笔记...">
<!ENTITY zotero.__addonRef__.workspace.menu.insertNotes "插入多条笔记...">
<!ENTITY zotero.__addonRef__.workspace.menu.insertTextTemplate "插入模板">
Expand Down
25 changes: 17 additions & 8 deletions src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1247,21 +1247,25 @@ class AddonEvents extends AddonBase {
note.parentID = Zotero.Items.get(
annotations[0].attachmentItemID
).parentID;
if (annotationItem.annotationComment) {
note.setNote(
`<div data-schema-version="8"><p>${annotationItem.annotationComment}</p>\n</div>`
);

let _newLine: string = "";
const templateText = this._Addon.template.getTemplateText("[QuickNote]");
try {
_newLine = new Function(
"annotationItem, topItem",
"return `" + templateText + "`"
)(annotationItem, annotationItem.parentItem.parentItem);
} catch (e) {
alert(e);
}
note.setNote(`<div data-schema-version="8">${_newLine}\n</div>`);

const tags = annotationItem.getTags();
for (const tag of tags) {
note.addTag(tag.tag, tag.type);
}
await note.saveTx();

annotationItem.annotationComment = `${
annotationItem.annotationComment ? annotationItem.annotationComment : ""
}\nnote link: "${this._Addon.knowledge.getNoteLink(note)}"`;
await annotationItem.saveTx();
ZoteroPane.openNoteWindow(note.id);
let t = 0;
while (t < 100 && !ZoteroPane.findNoteWindow(note.id)) {
Expand All @@ -1283,6 +1287,11 @@ class AddonEvents extends AddonBase {
const editorInstance = noteEditor.getCurrentInstance();
editorInstance.focus();
await editorInstance.insertAnnotations(annotations);

annotationItem.annotationComment = `${
annotationItem.annotationComment ? annotationItem.annotationComment : ""
}\nnote link: "${this._Addon.knowledge.getNoteLink(note)}"`;
await annotationItem.saveTx();
} else {
Zotero.debug(`Knowledge4Zotero: message not handled.`);
}
Expand Down
5 changes: 5 additions & 0 deletions src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class AddonTemplate extends AddonBase {
text: '<blockquote>\n<p><strong>Linked Note:</strong></p>\n${subNoteLines.join("")}\n</blockquote>',
disabled: false,
},
{
name: "[QuickNote]",
text: '<p>${annotationItem.annotationComment ? annotationItem.annotationComment : `<span style="background-color: ${annotationItem.annotationColor ? annotationItem.annotationColor : "#ffd400"}">Annotation</span>`}</p>',
disabled: false,
},
{
name: "[Item] item-notes with metadata",
text: '<h1>${topItem.getField("title")}</h1>\n<h2 style="color:red; background-color: #efe3da;">💡 Meta Data</h2>\n<table>\n <tr>\n <th style="background-color:#dbeedd;">\n <p style="text-align: right">Title </p>\n </th>\n <td style="background-color:#dbeedd;">\n ${topItem.getField(\'title\')}\n </td>\n </tr>\n <tr>\n <th style="background-color:#f3faf4;">\n <p style="text-align: right">Journal </p>\n </th>\n <td style="background-color:#f3faf4;">\n ${topItem.getField(\'publicationTitle\')}\n </td>\n </tr>\n <tr>\n <th style="background-color:#dbeedd;">\n <p style="text-align: right">1<sup>st</sup> Author </p>\n </th>\n <td style="background-color:#dbeedd;">\n ${topItem.getField(\'firstCreator\')}\n </td>\n </tr>\n <tr>\n <th style="background-color:#f3faf4;">\n <p style="text-align: right">Authors </p>\n </th>\n <td style="background-color:#f3faf4;">\n ${topItem.getCreators().map((v)=>v.firstName+" "+v.lastName).join("; ")}\n </td>\n </tr>\n <tr>\n <th style="background-color:#dbeedd;">\n <p style="text-align: right">Pub. date </p>\n </th>\n <td style="background-color:#dbeedd;">\n ${topItem.getField(\'date\')}\n </td>\n </tr>\n <tr>\n <th style="background-color:#f3faf4;">\n <p style="text-align: right">DOI </p>\n </th>\n <td style="background-color:#f3faf4;">\n <a href="https://doi.org/${topItem.getField(\'DOI\')}">${topItem.getField(\'DOI\')}</a>\n </td>\n </tr>\n <tr>\n <th style="background-color:#dbeedd;">\n <p style="text-align: right">Archive </p>\n </th>\n <td style="background-color:#dbeedd;">\n ${topItem.getField(\'archive\')}\n </td>\n </tr>\n <tr>\n <th style="background-color:#f3faf4;">\n <p style="text-align: right">Archive Location </p>\n </th>\n <td style="background-color:#f3faf4;">\n ${topItem.getField(\'archiveLocation\')}\n </td>\n </tr>\n <tr>\n <th style="background-color:#dbeedd;">\n <p style="text-align: right">Call No. </p>\n </th>\n <td style="background-color:#dbeedd;">\n ${topItem.getField(\'callNumber\')}\n </td>\n </tr>\n</table>\n${itemNotes.map((noteItem)=>{\nconst noteLine = `<h2 style="color:red; background-color: #efe3da;">📜 Note: <a href="${Zotero.Knowledge4Zotero.knowledge.getNoteLink(noteItem)}" rel="noopener noreferrer nofollow">${noteItem.key}</a></h2>\n<blockquote>\n ${noteItem.getNote()}\n <p style="background-color: pink;"><strong>Merge Date: </strong> ${new Date().toISOString().substr(0,10)+" "+ new Date().toTimeString()}</p>\n</blockquote>\n<p style="color:red; background-color: #efe3da;"><strong>📝 Comments</strong></p>\n<blockquote>\n <p>Make your comments</p>\n <p></p>\n</blockquote>`;\ncopyNoteImage(noteItem);\nreturn noteLine;\n}).join("\\n")}\n',
Expand Down

0 comments on commit fc01593

Please sign in to comment.