refactor: events & views

This commit is contained in:
xiangyu 2022-10-10 13:59:53 +08:00
parent 1b28b0190b
commit 1838904bbe
17 changed files with 214 additions and 74 deletions

View File

@ -25,30 +25,30 @@
</keyset>
<commandset id="mainCommandSet">
<command id="cmd_new_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'createWorkspace'});" />
<command id="cmd_open_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'selectMainNote'});" />
<command id="cmd_open_betternotesWindow" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'openWorkspaceInWindow'});" />
<command id="cmd_export_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'export', content: {editorInstance: {_item: false}}});" />
<command id="cmd_sync_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'sync'});" />
<command id="cmd_new_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'createWorkspace'});" />
<command id="cmd_open_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'selectMainNote'});" />
<command id="cmd_open_betternotesWindow" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'openWorkspaceInWindow'});" />
<command id="cmd_export_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'export', content: {editorInstance: {_item: false}}});" />
<command id="cmd_sync_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'sync'});" />
<command id="cmd_sync_manager_betternotes" oncommand="Zotero.Knowledge4Zotero.SyncListWindow.openSyncList();" />
<command id="cmd_editTemplate_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'editTemplate'});" />
<!-- <command id="cmd_importlink_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'importLink'});" />
<command id="cmd_updatelink_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'updateLink'});" /> -->
<command id="cmd_autoannotation_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'updateAutoAnnotation'});" />
<command id="cmd_convertmd_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'convertMD'});" />
<command id="cmd_convertasciidoc_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'convertAsciiDoc'});" />
<command id="cmd_editTemplate_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'editTemplate'});" />
<!-- <command id="cmd_importlink_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'importLink'});" />
<command id="cmd_updatelink_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'updateLink'});" /> -->
<command id="cmd_autoannotation_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'updateAutoAnnotation'});" />
<command id="cmd_convertmd_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'convertMD'});" />
<command id="cmd_convertasciidoc_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'convertAsciiDoc'});" />
<command id="cmd_treeview_betternotes" oncommand="Zotero.Knowledge4Zotero.WorkspaceOutline.switchView(1);" />
<command id="cmd_mindmap_betternotes" oncommand="Zotero.Knowledge4Zotero.WorkspaceOutline.switchView(2);" />
<command id="cmd_bubblemap_betternotes" oncommand="Zotero.Knowledge4Zotero.WorkspaceOutline.switchView(3);" />
<command id="cmd_guide_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'openUserGuide'});" />
<command id="cmd_about_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'openAbout'});" />
<command id="cmd_guide_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'openUserGuide'});" />
<command id="cmd_about_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'openAbout'});" />
</commandset>
<popup id="zotero-itemmenu">
<menuseparator />
<menuitem id="zotero-itemmenu-__addonRef__-setMainNote" class="menuitem-iconic popup-type-single-note" label="&zotero.__addonRef__.itemmenu.setMainNote.label;" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'setMainNote', content: {params: {itemID: ZoteroPane.getSelectedItems()[0].id}}})" style="list-style-image: url('chrome://__addonRef__/skin/favicon.png');" />
<menuitem id="zotero-itemmenu-__addonRef__-exportNote" class="menuitem-iconic popup-type-single" label="&zotero.__addonRef__.itemmenu.exportNote.label;" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent.bind(Zotero.Knowledge4Zotero.events)({type: 'exportNotes', content: {}})" style="list-style-image: url('chrome://__addonRef__/skin/favicon.png');" />
<menuitem id="zotero-itemmenu-__addonRef__-exportNotes" class="menuitem-iconic popup-type-multiple" label="&zotero.__addonRef__.itemmenu.exportNotes.label;" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent.bind(Zotero.Knowledge4Zotero.events)({type: 'exportNotes', content: {}})" style="list-style-image: url('chrome://__addonRef__/skin/favicon.png');" />
<menuitem id="zotero-itemmenu-__addonRef__-setMainNote" class="menuitem-iconic popup-type-single-note" label="&zotero.__addonRef__.itemmenu.setMainNote.label;" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'setMainNote', content: {params: {itemID: ZoteroPane.getSelectedItems()[0].id}}})" style="list-style-image: url('chrome://__addonRef__/skin/favicon.png');" />
<menuitem id="zotero-itemmenu-__addonRef__-exportNote" class="menuitem-iconic popup-type-single" label="&zotero.__addonRef__.itemmenu.exportNote.label;" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent.bind(Zotero.Knowledge4Zotero.ZoteroEvents)({type: 'exportNotes', content: {}})" style="list-style-image: url('chrome://__addonRef__/skin/favicon.png');" />
<menuitem id="zotero-itemmenu-__addonRef__-exportNotes" class="menuitem-iconic popup-type-multiple" label="&zotero.__addonRef__.itemmenu.exportNotes.label;" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent.bind(Zotero.Knowledge4Zotero.ZoteroEvents)({type: 'exportNotes', content: {}})" style="list-style-image: url('chrome://__addonRef__/skin/favicon.png');" />
</popup>
<menupopup id="menu_FilePopup">
@ -99,9 +99,9 @@
<menuseparator class="menu-betternotes" />
<menu id="menu_ocrsetting_betternotes" class="menu-betternotes" label="&zotero.__addonRef__.workspace.menu.OCRSetting;">
<menupopup id="menu_ocrsettingpopup" onpopupshowing="Zotero.Knowledge4Zotero.ZoteroViews.updateOCRStyleMenu();">
<menuitem id="menu_ocr_bing_betternotes" class="menu-betternotes" label="&zotero.__addonRef__.workspace.menu.OCRBing;" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent.bind(Zotero.Knowledge4Zotero.events)({type: 'setOCREngine', content: {params: {engine: 'bing'}}})" type="checkbox" />
<menuitem id="menu_ocr_mathpix_betternotes" class="menu-betternotes" label="&zotero.__addonRef__.workspace.menu.OCRMathpix;" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent.bind(Zotero.Knowledge4Zotero.events)({type: 'setOCREngine', content: {params: {engine: 'mathpix'}}})" type="checkbox" />
<menuitem id="menu_ocr_xunfei_betternotes" class="menu-betternotes" label="&zotero.__addonRef__.workspace.menu.OCRXunfei;" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent.bind(Zotero.Knowledge4Zotero.events)({type: 'setOCREngine', content: {params: {engine: 'xunfei'}}})" type="checkbox" />
<menuitem id="menu_ocr_bing_betternotes" class="menu-betternotes" label="&zotero.__addonRef__.workspace.menu.OCRBing;" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent.bind(Zotero.Knowledge4Zotero.ZoteroEvents)({type: 'setOCREngine', content: {params: {engine: 'bing'}}})" type="checkbox" />
<menuitem id="menu_ocr_mathpix_betternotes" class="menu-betternotes" label="&zotero.__addonRef__.workspace.menu.OCRMathpix;" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent.bind(Zotero.Knowledge4Zotero.ZoteroEvents)({type: 'setOCREngine', content: {params: {engine: 'mathpix'}}})" type="checkbox" />
<menuitem id="menu_ocr_xunfei_betternotes" class="menu-betternotes" label="&zotero.__addonRef__.workspace.menu.OCRXunfei;" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent.bind(Zotero.Knowledge4Zotero.ZoteroEvents)({type: 'setOCREngine', content: {params: {engine: 'xunfei'}}})" type="checkbox" />
</menupopup>
</menu>
<menuitem id="menu_guide_betternotes menu-betternotes" label="&zotero.__addonRef__.workspace.menu.guide;" command="cmd_guide_betternotes" />

View File

@ -11,7 +11,7 @@
%knowledgeDTD;
]>
<wizard xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" id="knowledge-wizard" windowtype="knowledge-wizard" title="&zotero.__addonRef__.wizard.title;" width="788" height="600" onwizardfinish="Zotero.Knowledge4Zotero.wizard.setup()">
<wizard xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" id="knowledge-wizard" windowtype="knowledge-wizard" title="&zotero.__addonRef__.wizard.title;" width="788" height="600" onwizardfinish="Zotero.Knowledge4Zotero.WizardWindow.setup()">
<script src="chrome://zotero/content/include.js" />
<wizardpage label="&zotero.__addonRef__.wizard.title;">
@ -43,19 +43,19 @@
<description style="white-space: pre-wrap; color: red;">&zotero.__addonRef__.wizard.page6.description2;</description>
<rows>
<row>
<checkbox id="__addonRef__-setup-enable" checked="true" oncommand="Zotero.Knowledge4Zotero.wizard.changeSetup()" />
<checkbox id="__addonRef__-setup-enable" checked="true" oncommand="Zotero.Knowledge4Zotero.WizardWindow.changeSetup()" />
<label value="&zotero.__addonRef__.wizard.setup.enable.label;" />
</row>
<row>
<checkbox id="__addonRef__-setup-collectionenable" checked="true" oncommand="Zotero.Knowledge4Zotero.wizard.updateCollectionSetup()" />
<checkbox id="__addonRef__-setup-collectionenable" checked="true" oncommand="Zotero.Knowledge4Zotero.WizardWindow.updateCollectionSetup()" />
<label value="&zotero.__addonRef__.wizard.setup.collectionenable.label;" />
<textbox id="__addonRef__-setup-collectionname" value="My Notes" oninput="Zotero.Knowledge4Zotero.wizard.updateCollectionSetup()" />
<textbox id="__addonRef__-setup-collectionname" value="My Notes" oninput="Zotero.Knowledge4Zotero.WizardWindow.updateCollectionSetup()" />
</row>
<row>
<checkbox id="__addonRef__-setup-noteenable" checked="true" oncommand="Zotero.Knowledge4Zotero.wizard.updateNoteSetup()" />
<checkbox id="__addonRef__-setup-noteenable" checked="true" oncommand="Zotero.Knowledge4Zotero.WizardWindow.updateNoteSetup()" />
<label value="&zotero.__addonRef__.wizard.setup.noteenable.label;" />
</row>
</rows>
</wizardpage>
<script>Zotero.Knowledge4Zotero.wizard.init(document)</script>
<script>Zotero.Knowledge4Zotero.WizardWindow.init(document)</script>
</wizard>

View File

@ -33,25 +33,25 @@
<key id="key_indent" keycode="VK_TAB" command="cmd_indent_betternotes" />
<key id="key_unindent" keycode="VK_TAB" modifiers="shift" command="cmd_unindent_betternotes" />
</keyset>
<command id="cmd_new" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'createWorkspace'});" />
<command id="cmd_open" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'selectMainNote'});" />
<command id="cmd_openWindow" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'openWorkspaceInWindow'});" />
<command id="cmd_export" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'export', content: {editorInstance: {_item: false}}});" />
<command id="cmd_sync_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'sync'});" />
<command id="cmd_new" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'createWorkspace'});" />
<command id="cmd_open" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'selectMainNote'});" />
<command id="cmd_openWindow" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'openWorkspaceInWindow'});" />
<command id="cmd_export" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'export', content: {editorInstance: {_item: false}}});" />
<command id="cmd_sync_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'sync'});" />
<command id="cmd_sync_manager_betternotes" oncommand="Zotero.Knowledge4Zotero.SyncListWindow.openSyncList();" />
<command id="cmd_close" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'closeWorkspace'});" />
<!-- <command id="cmd_insertNotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'insertNotes'});" /> -->
<command id="cmd_editTemplate" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'editTemplate'});" />
<!-- <command id="cmd_importlink_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'importLink'});" />
<command id="cmd_updatelink_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'updateLink'});" /> -->
<command id="cmd_autoannotation_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'updateAutoAnnotation', content: {event: event}});" />
<command id="cmd_convertmd_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'convertMD'});" />
<command id="cmd_convertasciidoc_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'convertAsciiDoc'});" />
<command id="cmd_close" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'closeWorkspace'});" />
<!-- <command id="cmd_insertNotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'insertNotes'});" /> -->
<command id="cmd_editTemplate" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'editTemplate'});" />
<!-- <command id="cmd_importlink_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'importLink'});" />
<command id="cmd_updatelink_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'updateLink'});" /> -->
<command id="cmd_autoannotation_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'updateAutoAnnotation', content: {event: event}});" />
<command id="cmd_convertmd_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'convertMD'});" />
<command id="cmd_convertasciidoc_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'convertAsciiDoc'});" />
<command id="cmd_treeview" oncommand="Zotero.Knowledge4Zotero.WorkspaceOutline.switchView(1);" />
<command id="cmd_mindmap" oncommand="Zotero.Knowledge4Zotero.WorkspaceOutline.switchView(2);" />
<command id="cmd_bubblemap" oncommand="Zotero.Knowledge4Zotero.WorkspaceOutline.switchView(3);" />
<command id="cmd_guide" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'openUserGuide'});" />
<command id="cmd_about" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'openAbout'});" />
<command id="cmd_guide" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'openUserGuide'});" />
<command id="cmd_about" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'openAbout'});" />
<!-- Menu -->
<menubar id="better-notes-menu">

View File

@ -2,10 +2,10 @@
* This file defines the plugin's structure.
*/
import AddonEvents from "./zotero/events";
import ZoteroEvents from "./zotero/events";
import ZoteroViews from "./zotero/views";
import ReaderViews from "./reader/annotationButton";
import AddonWizard from "./wizard";
import ReaderViews from "./reader/readerViews";
import WizardWindow from "./wizard/wizardWindow";
import { TemplateController, TemplateAPI } from "./template/templateController";
import SyncInfoWindow from "./sync/syncInfoWindow";
import SyncListWindow from "./sync/syncListWindow";
@ -13,16 +13,16 @@ import SyncController from "./sync/syncController";
import WorkspaceWindow from "./workspace/workspaceWindow";
import WorkspaceOutline from "./workspace/workspaceOutline";
import WorkspaceMenu from "./workspace/workspaceMenu";
import NoteUtils from "./editor/noteUtils";
import NoteParse from "./editor/noteParse";
import NoteExportWindow from "./editor/noteExportWindow";
import NoteExport from "./editor/noteExportController";
import EditorViews from "./editor/editorUI";
import NoteUtils from "./note/noteUtils";
import NoteParse from "./note/noteParse";
import NoteExportWindow from "./note/noteExportWindow";
import NoteExport from "./note/noteExportController";
import EditorViews from "./editor/editorViews";
import EditorController from "./editor/editorController";
import TemplateWindow from "./template/templateWindow";
class Knowledge4Zotero {
public events: AddonEvents;
public ZoteroEvents: ZoteroEvents;
// Zotero UI
public ZoteroViews: ZoteroViews;
// Reader UI
@ -32,7 +32,7 @@ class Knowledge4Zotero {
public WorkspaceWindow: WorkspaceWindow;
public WorkspaceMenu: WorkspaceMenu;
// First-run wizard
public wizard: AddonWizard;
public WizardWindow: WizardWindow;
// Sync tools
public SyncInfoWindow: SyncInfoWindow;
public SyncListWindow: SyncListWindow;
@ -51,7 +51,7 @@ class Knowledge4Zotero {
public EditorController: EditorController;
constructor() {
this.events = new AddonEvents(this);
this.ZoteroEvents = new ZoteroEvents(this);
this.ZoteroViews = new ZoteroViews(this);
this.ReaderViews = new ReaderViews(this);
this.WorkspaceOutline = new WorkspaceOutline(this);
@ -59,7 +59,7 @@ class Knowledge4Zotero {
this.WorkspaceMenu = new WorkspaceMenu(this);
this.EditorViews = new EditorViews(this);
this.EditorController = new EditorController(this);
this.wizard = new AddonWizard(this);
this.WizardWindow = new WizardWindow(this);
this.SyncInfoWindow = new SyncInfoWindow(this);
this.SyncListWindow = new SyncListWindow(this);
this.SyncController = new SyncController(this);

View File

@ -261,7 +261,7 @@ class EditorViews extends AddonBase {
}
addCitationButton.addEventListener("click", async (e) => {
this._Addon.events.onEditorEvent(
this._Addon.ZoteroEvents.onEditorEvent(
new EditorMessage("insertCitation", {
params: {
noteItem: noteItem,
@ -549,7 +549,7 @@ class EditorViews extends AddonBase {
message.type = e.target.getAttribute("eventType");
message.content.event = e as XUL.XULEvent;
message.content.editorInstance = editorInstances;
this._Addon.events.onEditorEvent(message);
this._Addon.ZoteroEvents.onEditorEvent(message);
});
return dropdown;
}
@ -594,7 +594,7 @@ class EditorViews extends AddonBase {
message.type = e.target.getAttribute("eventType");
message.content.event = e as XUL.XULEvent;
message.content.editorInstance = editorInstances;
this._Addon.events.onEditorEvent(message);
this._Addon.ZoteroEvents.onEditorEvent(message);
e.stopPropagation();
popup.remove();
});
@ -661,7 +661,7 @@ class EditorViews extends AddonBase {
const newLineString = newLines.join("\n");
const notifyFlag: ZoteroPromise = Zotero.Promise.defer();
const notifierName = "insertLinkWait";
this._Addon.events.addNotifyListener(
this._Addon.ZoteroEvents.addNotifyListener(
notifierName,
(
event: string,
@ -675,7 +675,7 @@ class EditorViews extends AddonBase {
ids.includes(targetNote.id)
) {
notifyFlag.resolve();
this._Addon.events.removeNotifyListener(notifierName);
this._Addon.ZoteroEvents.removeNotifyListener(notifierName);
}
}
);

View File

@ -9,7 +9,7 @@ Zotero.Knowledge4Zotero = new Knowledge4Zotero();
window.addEventListener(
"load",
async function (e) {
Zotero.Knowledge4Zotero.events.onInit();
Zotero.Knowledge4Zotero.ZoteroEvents.onInit();
},
false
);

140
src/note/noteController.ts Normal file
View File

@ -0,0 +1,140 @@
/*
* This file realizes note tools.
*/
import Knowledge4Zotero from "../addon";
import AddonBase from "../module";
class NoteController extends AddonBase {
public currentLine: any;
constructor(parent: Knowledge4Zotero) {
super(parent);
this.currentLine = [];
}
async getNoteFromLink(uri: string) {
const params = this._Addon.NoteParse.parseParamsFromLink(uri);
if (!params.libraryID) {
return {
item: false,
infoText: "Library does not exist or access denied.",
};
}
Zotero.debug(params);
let item = await Zotero.Items.getByLibraryAndKeyAsync(
params.libraryID,
params.noteKey
);
if (!item || !item.isNote()) {
return {
item: false,
args: params,
infoText: "Note does not exist or is not a note.",
};
}
return {
item: item,
args: params,
infoText: "OK",
};
}
public async onSelectionChange(editor: Zotero.EditorInstance) {
// Update current line index
const _window = editor._iframeWindow;
const selection = _window.document.getSelection();
if (!selection || !selection.focusNode) {
return;
}
const realElement = selection.focusNode.parentElement;
let focusNode = selection.focusNode as XUL.Element;
if (!focusNode || !realElement) {
return;
}
function getChildIndex(node) {
return Array.prototype.indexOf.call(node.parentNode.childNodes, node);
}
// Make sure this is a direct child node of editor
try {
while (
focusNode.parentElement &&
(!focusNode.parentElement.className ||
focusNode.parentElement.className.indexOf("primary-editor") === -1)
) {
focusNode = focusNode.parentNode as XUL.Element;
}
} catch (e) {
return;
}
if (!focusNode.parentElement) {
return;
}
let currentLineIndex = getChildIndex(focusNode);
// Parse list
const diveTagNames = ["OL", "UL", "LI"];
// Find list elements before current line
const listElements = Array.prototype.filter.call(
Array.prototype.slice.call(
focusNode.parentElement.childNodes,
0,
currentLineIndex
),
(e) => diveTagNames.includes(e.tagName)
);
for (const e of listElements) {
currentLineIndex += this._Addon.NoteParse.parseListElements(e).length - 1;
}
// Find list index if current line is inside a list
if (diveTagNames.includes(focusNode.tagName)) {
const eleList = this._Addon.NoteParse.parseListElements(focusNode);
for (const i in eleList) {
if (realElement.parentElement === eleList[i]) {
currentLineIndex += Number(i);
break;
}
}
}
Zotero.debug(`Knowledge4Zotero: line ${currentLineIndex} selected.`);
console.log(currentLineIndex);
Zotero.debug(
`Current Element: ${focusNode.outerHTML}; Real Element: ${realElement.outerHTML}`
);
this.currentLine[editor._item.id] = currentLineIndex;
if (realElement.tagName === "A") {
let link = (realElement as HTMLLinkElement).href;
let linkedNote = (await this.getNoteFromLink(link)).item;
if (linkedNote) {
let t = 0;
let linkPopup = _window.document.querySelector(".link-popup");
while (
!(
linkPopup &&
(linkPopup.querySelector("a") as unknown as HTMLLinkElement)
.href === link
) &&
t < 100
) {
t += 1;
linkPopup = _window.document.querySelector(".link-popup");
await Zotero.Promise.delay(30);
}
await this._Addon.EditorViews.updateEditorPopupButtons(editor, link);
} else {
await this._Addon.EditorViews.updateEditorPopupButtons(
editor,
undefined
);
}
}
}
}
export default NoteController;

View File

@ -117,7 +117,7 @@ class ReaderViews extends AddonBase {
if (link) {
const note = (await this._Addon.NoteUtils.getNoteFromLink(link)).item;
if (note && note.id) {
await this._Addon.events.onEditorEvent(
await this._Addon.ZoteroEvents.onEditorEvent(
new EditorMessage("onNoteLink", {
params: {
item: note,

View File

@ -2,11 +2,11 @@
* This file contains the first-run wizard window code.
*/
import Knowledge4Zotero from "./addon";
import { EditorMessage } from "./utils";
import AddonBase from "./module";
import Knowledge4Zotero from "../addon";
import { EditorMessage } from "../utils";
import AddonBase from "../module";
class AddonWizard extends AddonBase {
class WizardWindow extends AddonBase {
enableSetup: boolean;
enableCollection: boolean;
collectionName: string;
@ -275,7 +275,7 @@ class AddonWizard extends AddonBase {
(Zotero.Items.get(noteID) as Zotero.Item).setNote(
Zotero.locale === "zh-CN" ? this.templateCN : this.template
);
await this._Addon.events.onEditorEvent(
await this._Addon.ZoteroEvents.onEditorEvent(
new EditorMessage("setMainNote", {
params: { itemID: noteID, enableConfirm: false, enableOpen: true },
})
@ -285,4 +285,4 @@ class AddonWizard extends AddonBase {
}
}
export default AddonWizard;
export default WizardWindow;

View File

@ -166,20 +166,20 @@ class WorkspaceWindow extends AddonBase {
} else if (e.data.type === "getMindMapData") {
this._Addon.WorkspaceOutline.updateOutline();
} else if (e.data.type === "jumpNode") {
this._Addon.events.onEditorEvent(
this._Addon.ZoteroEvents.onEditorEvent(
new EditorMessage("jumpNode", {
params: e.data,
})
);
} else if (e.data.type === "jumpNote") {
Zotero.debug(e.data);
this._Addon.events.onEditorEvent(
this._Addon.ZoteroEvents.onEditorEvent(
new EditorMessage("onNoteLink", {
params: await this._Addon.NoteUtils.getNoteFromLink(e.data.link),
})
);
} else if (e.data.type === "moveNode") {
this._Addon.events.onEditorEvent(
this._Addon.ZoteroEvents.onEditorEvent(
new EditorMessage("moveNode", {
params: e.data,
})

View File

@ -6,7 +6,7 @@ import Knowledge4Zotero from "../addon";
import { CopyHelper, EditorMessage } from "../utils";
import AddonBase from "../module";
class AddonEvents extends AddonBase {
class ZoteroEvents extends AddonBase {
notifierCallback: any;
notifierCbkDict: any;
constructor(parent: Knowledge4Zotero) {
@ -233,7 +233,7 @@ class AddonEvents extends AddonBase {
params: await this._Addon.NoteUtils.getNoteFromLink(uri.spec),
},
};
await this._Addon.events.onEditorEvent(message);
await this._Addon.ZoteroEvents.onEditorEvent(message);
},
newChannel: function (uri: any) {
this.doAction(uri);
@ -1403,4 +1403,4 @@ class AddonEvents extends AddonBase {
}
}
export default AddonEvents;
export default ZoteroEvents;

View File

@ -72,7 +72,7 @@ class ZoteroViews extends AddonBase {
button.setAttribute("id", "zotero-tb-knowledge-openwindow");
button.setAttribute("label", "New Main Note");
button.addEventListener("click", (e) => {
this._Addon.events.onEditorEvent(
this._Addon.ZoteroEvents.onEditorEvent(
new EditorMessage("createWorkspace", {})
);
});
@ -112,7 +112,7 @@ class ZoteroViews extends AddonBase {
span1.append(span2, span3, span4);
treeRow.append(span1);
treeRow.addEventListener("click", (e) => {
this._Addon.events.onEditorEvent(
this._Addon.ZoteroEvents.onEditorEvent(
new EditorMessage("openWorkspace", { event: e })
);
});
@ -182,7 +182,7 @@ class ZoteroViews extends AddonBase {
menuitem.setAttribute(
"oncommand",
`
Zotero.Knowledge4Zotero.events.onEditorEvent({
Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({
type: "insert${type}UsingTemplate",
content: {
params: { templateName: "${template.name}", copy: ${copyMode} },