add: annotation quick note link

This commit is contained in:
xiangyu 2022-05-08 00:39:37 +08:00
parent 2003c12f1b
commit 50cdfe4b27
11 changed files with 87 additions and 39 deletions

View File

@ -53,7 +53,7 @@
<html:div id="outline-tools" height="50" maxheight="50" minheight="50" style="display: flex; flex-flex-direction: row; justify-content: space-between; margin: 0px 30px 0px 30px;">
<div class="tooltip">
<div id="outline-selectknowledge"></div>
<span class="tooltiptext">Select Main Knowledge</span>
<span class="tooltiptext">Select Main Note</span>
</div>
<div class="tooltip">
<div id="outline-switchview"></div>

View File

@ -1,5 +1,5 @@
<!ENTITY zotero.__addonRef__.workspace.title "Knowledge Workspace">
<!ENTITY zotero.__addonRef__.itemmenu.setMainKnowledge.label "Set Main Knowledge">
<!ENTITY zotero.__addonRef__.itemmenu.setMainKnowledge.label "Set Main Note">
<!ENTITY zotero.__addonRef__.export.title "Export Knowledge">
<!ENTITY zotero.__addonRef__.export.file.enable.label "Export to file(MarkDown/HTML/RDF)">
@ -16,9 +16,9 @@
<!ENTITY zotero.__addonRef__.wizard.page3.header "Open Knowledge Workspace">
<!ENTITY zotero.__addonRef__.wizard.page3.description "Click the link above 'My Library' or the home button in the note editor to open or focus the workspace.">
<!ENTITY zotero.__addonRef__.wizard.layout "Knowledge Workspace Layout">
<!ENTITY zotero.__addonRef__.wizard.page4.header "Outline/Main Knowledge/Linked Note Preview">
<!ENTITY zotero.__addonRef__.wizard.page4.description1 "Modify/jump to headings inside main Knowledge with the Outline;">
<!ENTITY zotero.__addonRef__.wizard.page4.description2 "Main Knowledge stores all linked notes. Export to MarkDown/HTML with full text supported;">
<!ENTITY zotero.__addonRef__.wizard.page4.header "Outline/Main Note/Linked Note Preview">
<!ENTITY zotero.__addonRef__.wizard.page4.description1 "Modify/jump to headings inside main Note with the Outline;">
<!ENTITY zotero.__addonRef__.wizard.page4.description2 "Main Note stores all linked notes. Export to MarkDown/HTML with full text supported;">
<!ENTITY zotero.__addonRef__.wizard.page4.description3 "Open and edit linked notes in the preview.">
<!ENTITY zotero.__addonRef__.wizard.link "Add Note Link to Knowledge">
<!ENTITY zotero.__addonRef__.wizard.page5.header "Open note link in Knowledge, and everywhere.">
@ -27,11 +27,11 @@
<!ENTITY zotero.__addonRef__.wizard.setup "Setup Workspace">
<!ENTITY zotero.__addonRef__.wizard.page6.header "Almost there. Setup your workspace before starting.">
<!ENTITY zotero.__addonRef__.wizard.page6.description1 "You can come back later from the knowledge workspace.">
<!ENTITY zotero.__addonRef__.wizard.page6.description2 "WARNING If main knowledge is not set, this addon will not work properly.">
<!ENTITY zotero.__addonRef__.wizard.page6.description2 "WARNING If main Note is not set, this addon will not work properly.">
<!ENTITY zotero.__addonRef__.wizard.setup.enable.label "Enable Setup">
<!ENTITY zotero.__addonRef__.wizard.setup.collectionenable.label "Create a new collection with the name:">
<!ENTITY zotero.__addonRef__.wizard.setup.noteenable.label "Create a new note and use it as the main Knowledge">
<!ENTITY zotero.__addonRef__.wizard.setup.noteenable.label "Create a new note and use it as the main Note">
<!ENTITY zotero.__addonRef__.help.feedback.caption.label "User Guide and Feedback">
<!ENTITY zotero.__addonRef__.help.feedback.label "GitHub">

View File

@ -1,7 +1,7 @@
<!ENTITY zotero.__addonRef__.workspace.title "Knowledge工作区">
<!ENTITY zotero.__addonRef__.itemmenu.setMainKnowledge.label "设置为主Knowledge">
<!ENTITY zotero.__addonRef__.itemmenu.setMainKnowledge.label "设置为主笔记">
<!ENTITY zotero.__addonRef__.export.title "导出Knowledge">
<!ENTITY zotero.__addonRef__.export.title "导出笔记">
<!ENTITY zotero.__addonRef__.export.file.enable.label "导出为文件(MarkDown/HTML/RDF)">
<!ENTITY zotero.__addonRef__.export.note.enable.label "导出到新笔记">
<!ENTITY zotero.__addonRef__.export.copy.enable.label "导出到剪贴板">
@ -16,22 +16,22 @@
<!ENTITY zotero.__addonRef__.wizard.page3.header "打开Knowledge工作区">
<!ENTITY zotero.__addonRef__.wizard.page3.description "单击“我的文库”上方链接或笔记编辑器中的“主页”按钮,来打开或聚焦工作区。">
<!ENTITY zotero.__addonRef__.wizard.layout "Knowledge 工作区布局">
<!ENTITY zotero.__addonRef__.wizard.page4.header "大纲/主Knowledge/链接笔记预览">
<!ENTITY zotero.__addonRef__.wizard.page4.description1 "用大纲修改/跳转主 Knowledge 的标题;">
<!ENTITY zotero.__addonRef__.wizard.page4.description2 "主Knowledge存储所有链接的笔记。支持导出包含链接全文的MarkDown/HTML">
<!ENTITY zotero.__addonRef__.wizard.page4.header "大纲/主笔记/链接笔记预览">
<!ENTITY zotero.__addonRef__.wizard.page4.description1 "用大纲修改/跳转主笔记的标题;">
<!ENTITY zotero.__addonRef__.wizard.page4.description2 "主笔记存储所有链接的笔记。支持导出包含链接全文的MarkDown/HTML">
<!ENTITY zotero.__addonRef__.wizard.page4.description3 "在预览中打开并编辑链接的笔记。">
<!ENTITY zotero.__addonRef__.wizard.link "添加笔记链接到 Knowledge">
<!ENTITY zotero.__addonRef__.wizard.page5.header "在Knowledge, 以及任何地方打开笔记链接。">
<!ENTITY zotero.__addonRef__.wizard.page5.description1 "单击按钮,在主Knowledge中当前行插入当前笔记的链接,或选择位置以插入链接。">
<!ENTITY zotero.__addonRef__.wizard.link "添加笔记链接到笔记">
<!ENTITY zotero.__addonRef__.wizard.page5.header "在工作区, 以及任何地方打开笔记链接。">
<!ENTITY zotero.__addonRef__.wizard.page5.description1 "单击按钮,在主笔记中当前行插入当前笔记的链接,或选择位置以插入链接。">
<!ENTITY zotero.__addonRef__.wizard.page5.description2 "通过笔记链接,甚至可以从其他应用程序跳转到笔记!">
<!ENTITY zotero.__addonRef__.wizard.setup "配置工作区">
<!ENTITY zotero.__addonRef__.wizard.page6.header "即将完成。在开始之前,请设置工作区。">
<!ENTITY zotero.__addonRef__.wizard.page6.description1 "您可以稍后从Knowledge工作区返回配置指引。">
<!ENTITY zotero.__addonRef__.wizard.page6.description2 "警告:如果未设置主Knowledge,此插件将无法正常工作。">
<!ENTITY zotero.__addonRef__.wizard.page6.description1 "您可以稍后从工作区返回配置指引。">
<!ENTITY zotero.__addonRef__.wizard.page6.description2 "警告:如果未设置主笔记,此插件将无法正常工作。">
<!ENTITY zotero.__addonRef__.wizard.setup.enable.label "启用工作区配置">
<!ENTITY zotero.__addonRef__.wizard.setup.collectionenable.label "用这个名字创建新的工作区分类文件夹:">
<!ENTITY zotero.__addonRef__.wizard.setup.noteenable.label "创建一个新的笔记,并将其设为主Knowledge">
<!ENTITY zotero.__addonRef__.wizard.setup.noteenable.label "创建一个新的笔记,并将其设为主笔记">
<!ENTITY zotero.__addonRef__.help.feedback.caption.label "User Guide and Feedback">
<!ENTITY zotero.__addonRef__.help.feedback.label "GitHub">

Binary file not shown.

Before

Width:  |  Height:  |  Size: 680 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 573 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -132,7 +132,17 @@ class AddonEvents extends AddonBase {
/*
message.content = {}
*/
const res = confirm(
`Will create a new note under collection '${ZoteroPane_Local.getSelectedCollection().getName()}' and set it the main note. Continue?`
);
if (!res) {
return;
}
const header = prompt("Enter new note header:");
const noteID = await ZoteroPane_Local.newNote();
Zotero.Items.get(noteID).setNote(
`<div data-schema-version="8"><h1>${header}</h1>\n</div>`
);
await this.onEditorEvent(
new EditorMessage("setMainKnowledge", {
params: { itemID: noteID },
@ -199,7 +209,7 @@ class AddonEvents extends AddonBase {
if (itemID === mainKnowledgeID) {
this._Addon.views.showProgressWindow(
"Knowledge",
"Already a main Knowledge."
"Already a main Note."
);
return;
} else if (!item.isNote()) {
@ -223,7 +233,7 @@ class AddonEvents extends AddonBase {
await this._Addon.knowledge.setWorkspaceNote("main");
this._Addon.views.showProgressWindow(
"Knowledge",
`Set main Knowledge to: ${item.getNoteTitle()}`
`Set main Note to: ${item.getNoteTitle()}`
);
}
} else if (message.type === "addNoteInstance") {
@ -247,9 +257,7 @@ class AddonEvents extends AddonBase {
message.content.editorInstance,
"knowledge-start",
isMainKnowledge ? "isMainKnowledge" : "notMainKnowledge",
isMainKnowledge
? "Edit the main knowledge in Workspace"
: "Open Workspace",
isMainKnowledge ? "Edit the main Note in Workspace" : "Open Workspace",
"openWorkspace",
"start"
);
@ -257,7 +265,7 @@ class AddonEvents extends AddonBase {
message.content.editorInstance,
"knowledge-addlink",
"addToKnowledge",
"Add Note Link to Knowledge Workspace",
"Add link of current note to the main note",
"addToKnowledge",
"middle"
);
@ -328,8 +336,8 @@ class AddonEvents extends AddonBase {
);
middle.innerHTML = "";
const header = _window.document.createElement("div");
header.setAttribute("title", "This is a Main Knowledge");
header.innerHTML = "Main Knowledge";
header.setAttribute("title", "This is a Main Note");
header.innerHTML = "Main Note";
header.setAttribute("style", "font-size: medium");
middle.append(header);
} else {
@ -612,6 +620,18 @@ class AddonEvents extends AddonBase {
const annotations = message.content.params.annotations;
const annotationItem: ZoteroItem = message.content.params.annotationItem;
const text = annotationItem.annotationComment;
let link = text.substring(text.search(/zotero:\/\/note\//g));
link = link.substring(0, link.search('"'));
if (link) {
const note = (await this._Addon.knowledge.getNoteFromLink(link)).item;
if (note && note.id) {
Zotero.debug(note);
ZoteroPane.openNoteWindow(note.id);
return;
}
}
const note: ZoteroItem = new Zotero.Item("note");
note.parentID = Zotero.Items.get(
annotations[0].attachmentItemID
@ -622,6 +642,17 @@ class AddonEvents extends AddonBase {
);
}
await note.saveTx();
let libraryID = note.libraryID;
let library = Zotero.Libraries.get(libraryID);
let groupID: string;
if (library.libraryType === "user") {
groupID = "u";
} else if (library.libraryType === "group") {
groupID = `${library.id}`;
}
let noteKey = note.key;
annotationItem.annotationComment = `${annotationItem.annotationComment}\nnote link: "zotero://note/${groupID}/${noteKey}/"`;
await annotationItem.saveTx();
ZoteroPane.openNoteWindow(note.id);
let t = 0;
while (t < 100 && !ZoteroPane.findNoteWindow(note.id)) {

View File

@ -320,8 +320,8 @@ class Knowledge extends AddonBase {
let linkText = linkedNote.getNoteTitle().trim();
this.addSubLineToNote(
targetNote,
`<a href="zotero://note/${groupID}/${noteKey}" rel="noopener noreferrer nofollow">${
linkText ? linkText : `zotero://note/${groupID}/${noteKey}`
`<a href="zotero://note/${groupID}/${noteKey}/" rel="noopener noreferrer nofollow">${
linkText ? linkText : `zotero://note/${groupID}/${noteKey}/`
}</a>`,
lineIndex,
true

View File

@ -202,20 +202,23 @@ class AddonViews extends AddonBase {
addNewKnowledgeButton() {
// Top toolbar button
let addNoteButton = document.getElementById("zotero-tb-note-add");
let button = document.createElement("toolbarbutton");
let addNoteItem = document
.getElementById("zotero-tb-note-add")
.getElementsByTagName("menuitem")[1];
let button = document.createElement("menuitem");
button.setAttribute("id", "zotero-tb-knowledge-openwindow");
button.setAttribute("tooltiptext", "Create new Knowledge Workspace");
button.setAttribute("label", "New Main Note");
button.addEventListener("click", (e) => {
this._Addon.events.onEditorEvent(
new EditorMessage("createWorkspace", {})
);
});
button.setAttribute("class", "menuitem-iconic");
button.setAttribute(
"style",
"list-style-image: url('chrome://Knowledge4Zotero/skin/knowledge@0.5x.png');"
"list-style-image: url('chrome://Knowledge4Zotero/skin/favicon.png');"
);
addNoteButton.after(button);
addNoteItem.after(button);
}
addOpenWorkspaceButton() {
@ -224,7 +227,7 @@ class AddonViews extends AddonBase {
treeRow.setAttribute("class", "row");
treeRow.setAttribute(
"style",
"height: 22px; margin: 0 0 22px 0; padding: 0 6px 0 6px;"
"height: 22px; margin: 0 0 0 0; padding: 0 6px 0 6px;"
);
const span1 = document.createElement("span");
span1.setAttribute("class", "cell label primary");
@ -235,7 +238,7 @@ class AddonViews extends AddonBase {
span3.setAttribute("class", "icon icon-bg cell-icon");
span3.setAttribute(
"style",
"background-image:url(chrome://Knowledge4Zotero/skin/knowledge.png)"
"background-image:url(chrome://Knowledge4Zotero/skin/favicon.png)"
);
const span4 = document.createElement("span");
span4.setAttribute("class", "cell-text");
@ -249,13 +252,25 @@ class AddonViews extends AddonBase {
treeRow.addEventListener("mouseover", (e: XULEvent) => {
treeRow.setAttribute(
"style",
"height: 22px; margin: 0 0 22px 0; padding: 0 6px 0 6px; background-color: grey;"
"height: 22px; margin: 0 0 0 0; padding: 0 6px 0 6px; background-color: grey;"
);
});
treeRow.addEventListener("mouseleave", (e: XULEvent) => {
treeRow.setAttribute(
"style",
"height: 22px; margin: 0 0 22px 0; padding: 0 6px 0 6px;"
"height: 22px; margin: 0 0 0 0; padding: 0 6px 0 6px;"
);
});
treeRow.addEventListener("mousedown", (e: XULEvent) => {
treeRow.setAttribute(
"style",
"height: 22px; margin: 0 0 0 0; padding: 0 6px 0 6px; color: #FFFFFF;"
);
});
treeRow.addEventListener("mouseup", (e: XULEvent) => {
treeRow.setAttribute(
"style",
"height: 22px; margin: 0 0 0 0; padding: 0 6px 0 6px;"
);
});
document
@ -446,7 +461,7 @@ class AddonViews extends AddonBase {
*/
async buildOutline(note: ZoteroItem) {
Zotero.debug(this.currentOutline)
Zotero.debug(this.currentOutline);
if (this.currentOutline === OutlineType.treeView) {
this._Addon.knowledge.currentNodeID = -1;
let treeList = this._Addon.knowledge.getNoteTreeAsList(note, true, false);

4
typing/global.d.ts vendored
View File

@ -147,7 +147,8 @@ declare const ZoteroPane: {
};
declare const ZoteroPane_Local: {
newNote: () => Promise<number>;
getSelectedCollection: () => ZoteroCollection;
newNote: (popup?, parentKey?, text?, citeURI?) => Promise<number>;
};
declare const Zotero_File_Interface: {
@ -155,6 +156,7 @@ declare const Zotero_File_Interface: {
};
declare class ZoteroCollection {
getName: () => string;
getChildItems: (arg1: boolean, arg2: boolean) => Array<ZoteroItem>;
}