update: open workspace in tab

This commit is contained in:
xiangyu 2022-06-09 22:23:00 +08:00
parent 769af6188d
commit c1b1703681
13 changed files with 370 additions and 134 deletions

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
**/builds
node_modules
.vscode
package-lock.json
package-lock.json
zotero-cmd.json

View File

@ -34,6 +34,11 @@ https://user-images.githubusercontent.com/33902321/167992626-34adfd97-c2df-48b0-
For new users, a **User Guide** will help you get started quickly and create a user guide note for you. Use it as a playground and explore your own workflow!
### Important Changes
- Since v0.2.0, most of the workspace bottom-left buttons are moved to menu bar.
- Since v0.5.0, workspace will open as a Zotero tab by default. `Menu -> File -> Open in New Window` or press `shift` while clicking the Open Workspace button to use the standalone mode.
Documentation:
[User Guide(EN)](./UserGuide.md) | [用户指引(中文)](./UserGuideCN.md)

View File

@ -1,11 +1,105 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://__addonRef__/skin/overlay.css" type="text/css"?>
<!DOCTYPE overlay SYSTEM "chrome://__addonRef__/locale/overlay.dtd">
<!DOCTYPE window [
<!ENTITY % globalDTD SYSTEM "chrome://global/locale/global.dtd">
%globalDTD;
<!ENTITY % standaloneDTD SYSTEM "chrome://zotero/locale/standalone.dtd">
%standaloneDTD;
<!ENTITY % editMenuOverlayDTD SYSTEM "chrome://zotero/locale/mozilla/editMenuOverlay.dtd">
%editMenuOverlayDTD;
<!ENTITY % zoteroDTD SYSTEM "chrome://zotero/locale/zotero.dtd">
%zoteroDTD;
<!ENTITY % knowledgeDTD SYSTEM "chrome://__addonRef__/locale/overlay.dtd">
%knowledgeDTD;
]>
<overlay id="__addonRef__" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script src="chrome://__addonRef__/content/scripts/index.js" />
<keyset id="mainKeyset">
<key id="key_new_betternotes" class="key-type-betternotes" key="N" modifiers="accel" command="cmd_new_betternotes" />
<key id="key_open_betternotes" class="key-type-betternotes" key="O" modifiers="accel" command="cmd_open_betternotes" />
<key id="key_export_betternotes" class="key-type-betternotes" key="E" modifiers="accel" command="cmd_export_betternotes" />
<key id="key_indent_betternotes" class="key-type-betternotes" keycode="VK_TAB" command="cmd_indent_betternotes" />
<key id="key_unindent_betternotes" class="key-type-betternotes" keycode="VK_TAB" modifiers="shift" command="cmd_unindent_betternotes" />
</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: 'selectMainKnowledge'});" />
<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_editTemplate_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'editTemplate'});" />
<command id="cmd_addheading_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'addHeading'});" />
<command id="cmd_indent_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'indentHeading'});" />
<command id="cmd_unindent_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'unindentHeading'});" />
<command id="cmd_treeview_betternotes" oncommand="Zotero.Knowledge4Zotero.views.switchView(1);" />
<command id="cmd_mindmap_betternotes" oncommand="Zotero.Knowledge4Zotero.views.switchView(2);" />
<command id="cmd_bubblemap_betternotes" oncommand="Zotero.Knowledge4Zotero.views.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'});" />
</commandset>
<popup id="zotero-itemmenu">
<menuseparator />
<menuitem id="zotero-itemmenu-__addonRef__-setMainKnowledge" label="&zotero.__addonRef__.itemmenu.setMainKnowledge.label;" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent.bind(Zotero.Knowledge4Zotero.events)({type: 'setMainKnowledge', content: {params: {itemID: ZoteroPane.getSelectedItems()[0].id}}})" class="menuitem-iconic" style="list-style-image: url('chrome://__addonRef__/skin/favicon.png');" />
</popup>
<menupopup id="menu_FilePopup">
<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>
<menupopup id="menu_EditPopup">
<menuseparator class="menu-type-betternotes" />
<menu id="menu_insertTextTemplate_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.insertTextTemplate;">
<menupopup id="menu_insertTextTemplatePopup_betternotes" onpopupshowing="Zotero.Knowledge4Zotero.views.updateTemplateMenu('Text');" />
</menu>
<menu id="menu_insertNoteTemplate_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.insertNoteTemplate;">
<menupopup id="menu_insertNoteTemplatePopup_betternotes" onpopupshowing="Zotero.Knowledge4Zotero.views.updateTemplateMenu('Note');" />
</menu>
<menu id="menu_insertItemTemplate_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.insertItemTemplate;">
<menupopup id="menu_insertItemTemplatePopup_betternotes" onpopupshowing="Zotero.Knowledge4Zotero.views.updateTemplateMenu('Item');" />
</menu>
<menuitem id="menu_editTemplate_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.editTemplate;" command="cmd_editTemplate_betternotes" />
<menuseparator class="menu-type-betternotes" />
<menuitem id="menu_addheading_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.addheading;" command="cmd_addheading_betternotes" />
<menuitem id="menu_indent_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.indent;" command="cmd_indent_betternotes" key="key_indent_betternotes" />
<menuitem id="menu_unindent_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.unindent;" command="cmd_unindent_betternotes" key="key_unindent_betternotes" />
</menupopup>
<menupopup id="menu_ViewPopup">
<menuseparator class="menu-type-betternotes" />
<menuitem id="menu_treeview_betternotes" class="menu-type-betternotes" type="checkbox" label="&zotero.__addonRef__.workspace.menu.treeview;" command="cmd_treeview_betternotes" />
<menuitem id="menu_mindmap_betternotes" class="menu-type-betternotes" type="checkbox" label="&zotero.__addonRef__.workspace.menu.mindmap;" command="cmd_mindmap_betternotes" />
<menuitem id="menu_bubblemap_betternotes" class="menu-type-betternotes" type="checkbox" label="&zotero.__addonRef__.workspace.menu.bubblemap;" command="cmd_bubblemap_betternotes" />
<menuseparator class="menu-type-betternotes" />
<menu id="note-font-size-menu_betternotes" class="menu-type-betternotes" label="&noteFontSize.label;">
<menupopup oncommand="Zotero.Prefs.set('note.fontSize', event.originalTarget.getAttribute('label'));">
<menuitem label="11" type="checkbox" />
<menuitem label="12" type="checkbox" />
<menuitem label="13" type="checkbox" />
<menuitem label="14" type="checkbox" />
<menuitem label="18" type="checkbox" />
<menuitem label="24" type="checkbox" />
<menuitem label="36" type="checkbox" />
<menuitem label="48" type="checkbox" />
<menuitem label="64" type="checkbox" />
<menuitem label="72" type="checkbox" />
<menuitem label="96" type="checkbox" />
<menuseparator />
<menuitem id="view-menuitem-note-font-size-reset_betternotes" label="&zotero.general.reset;" oncommand="Zotero.Prefs.clear('note.fontSize');" />
</menupopup>
</menu>
</menupopup>
<menupopup id="menu_HelpPopup">
<menuseparator class="menu-type-betternotes" />
<menuitem id="menu_guide_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.guide;" command="cmd_guide_betternotes" />
<menuitem id="menu_about_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.about;" command="cmd_about_betternotes" />
</menupopup>
</overlay>

View File

@ -50,77 +50,72 @@
<command id="cmd_guide" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'openUserGuide'});" />
<command id="cmd_about" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'openAbout'});" />
<toolbox id="navigator-toolbox" class="toolbox-top" mode="icons" defaultmode="icons">
<!-- Menu -->
<toolbar type="menubar" id="toolbar-menubar" class="chromeclass-menubar" customizable="true" defaultset="menubar-items" mode="icons" iconsize="small" defaulticonsize="small" context="toolbar-context-menu">
<toolbaritem id="menubar-items" align="center">
<menubar id="main-menubar" style="border:0px;padding:0px;margin:0px;-moz-appearance:none">
<menu id="fileMenu" label="&fileMenu.label;" accesskey="&fileMenu.accesskey;">
<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>
</menu>
<!-- Menu -->
<menubar id="better-notes-menu">
<menu id="fileMenu" label="&fileMenu.label;" accesskey="&fileMenu.accesskey;">
<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>
</menu>
<menu id="menu_edit" label="&editMenu.label;" accesskey="&editMenu.accesskey;">
<menupopup id="menu_EditPopup">
<!-- <menuitem id="menu_insertNotes" label="&zotero.__addonRef__.workspace.menu.insertNotes;" key="key_insertNotes" accesskey="I" command="cmd_insertNotes" /> -->
<menu id="menu_insertTextTemplate" label="&zotero.__addonRef__.workspace.menu.insertTextTemplate;">
<menupopup id="menu_insertTextTemplatePopup" onpopupshowing="Zotero.Knowledge4Zotero.views.updateTemplateMenu('Text');" />
</menu>
<menu id="menu_insertNoteTemplate" label="&zotero.__addonRef__.workspace.menu.insertNoteTemplate;">
<menupopup id="menu_insertNoteTemplatePopup" onpopupshowing="Zotero.Knowledge4Zotero.views.updateTemplateMenu('Note');" />
</menu>
<menu id="menu_insertItemTemplate" label="&zotero.__addonRef__.workspace.menu.insertItemTemplate;">
<menupopup id="menu_insertItemTemplatePopup" onpopupshowing="Zotero.Knowledge4Zotero.views.updateTemplateMenu('Item');" />
</menu>
<menuitem id="menu_editTemplate" label="&zotero.__addonRef__.workspace.menu.editTemplate;" command="cmd_editTemplate" />
<menuseparator />
<menuitem id="menu_addheading" label="&zotero.__addonRef__.workspace.menu.addheading;" command="cmd_addheading" />
<menuitem id="menu_indent" label="&zotero.__addonRef__.workspace.menu.indent;" command="cmd_indent" key="key_indent" />
<menuitem id="menu_unindent" label="&zotero.__addonRef__.workspace.menu.unindent;" command="cmd_unindent" key="key_unindent" />
</menupopup>
</menu>
<menu id="menu_edit" label="&editMenu.label;" accesskey="&editMenu.accesskey;">
<menupopup id="menu_EditPopup">
<!-- <menuitem id="menu_insertNotes" label="&zotero.__addonRef__.workspace.menu.insertNotes;" key="key_insertNotes" accesskey="I" command="cmd_insertNotes" /> -->
<menu id="menu_insertTextTemplate" label="&zotero.__addonRef__.workspace.menu.insertTextTemplate;">
<menupopup id="menu_insertTextTemplatePopup" onpopupshowing="Zotero.Knowledge4Zotero.views.updateTemplateMenu('Text');" />
</menu>
<menu id="menu_insertNoteTemplate" label="&zotero.__addonRef__.workspace.menu.insertNoteTemplate;">
<menupopup id="menu_insertNoteTemplatePopup" onpopupshowing="Zotero.Knowledge4Zotero.views.updateTemplateMenu('Note');" />
</menu>
<menu id="menu_insertItemTemplate" label="&zotero.__addonRef__.workspace.menu.insertItemTemplate;">
<menupopup id="menu_insertItemTemplatePopup" onpopupshowing="Zotero.Knowledge4Zotero.views.updateTemplateMenu('Item');" />
</menu>
<menuitem id="menu_editTemplate" label="&zotero.__addonRef__.workspace.menu.editTemplate;" command="cmd_editTemplate" />
<menuseparator />
<menuitem id="menu_addheading" label="&zotero.__addonRef__.workspace.menu.addheading;" command="cmd_addheading" />
<menuitem id="menu_indent" label="&zotero.__addonRef__.workspace.menu.indent;" command="cmd_indent" key="key_indent" />
<menuitem id="menu_unindent" label="&zotero.__addonRef__.workspace.menu.unindent;" command="cmd_unindent" key="key_unindent" />
</menupopup>
</menu>
<menu id="view-menu" label="&viewMenu.label;" accesskey="&viewMenu.accesskey;" onpopupshowing="Zotero.Knowledge4Zotero.views.updateViewMenu();">
<menupopup id="menu_ViewPopup">
<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" />
<menuseparator />
<menu id="note-font-size-menu" label="&noteFontSize.label;">
<menupopup oncommand="Zotero.Prefs.set('note.fontSize', event.originalTarget.getAttribute('label'));">
<menuitem label="11" type="checkbox" />
<menuitem label="12" type="checkbox" />
<menuitem label="13" type="checkbox" />
<menuitem label="14" type="checkbox" />
<menuitem label="18" type="checkbox" />
<menuitem label="24" type="checkbox" />
<menuitem label="36" type="checkbox" />
<menuitem label="48" type="checkbox" />
<menuitem label="64" type="checkbox" />
<menuitem label="72" type="checkbox" />
<menuitem label="96" type="checkbox" />
<menuseparator />
<menuitem id="view-menuitem-note-font-size-reset" label="&zotero.general.reset;" oncommand="Zotero.Prefs.clear('note.fontSize');" />
</menupopup>
</menu>
</menupopup>
</menu>
<menu id="view-menu" label="&viewMenu.label;" accesskey="&viewMenu.accesskey;" onpopupshowing="Zotero.Knowledge4Zotero.views.updateViewMenu();">
<menupopup id="menu_ViewPopup">
<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" />
<menuseparator />
<menu id="note-font-size-menu" label="&noteFontSize.label;">
<menupopup oncommand="Zotero.Prefs.set('note.fontSize', event.originalTarget.getAttribute('label'));">
<menuitem label="11" type="checkbox" />
<menuitem label="12" type="checkbox" />
<menuitem label="13" type="checkbox" />
<menuitem label="14" type="checkbox" />
<menuitem label="18" type="checkbox" />
<menuitem label="24" type="checkbox" />
<menuitem label="36" type="checkbox" />
<menuitem label="48" type="checkbox" />
<menuitem label="64" type="checkbox" />
<menuitem label="72" type="checkbox" />
<menuitem label="96" type="checkbox" />
<menuseparator />
<menuitem id="view-menuitem-note-font-size-reset" label="&zotero.general.reset;" oncommand="Zotero.Prefs.clear('note.fontSize');" />
</menupopup>
</menu>
</menupopup>
</menu>
<menu id="helpMenu" label="&helpMenu.label;" accesskey="&helpMenu.accesskey;">
<menupopup id="menu_HelpPopup">
<menuitem id="menu_guide" label="&zotero.__addonRef__.workspace.menu.guide;" command="cmd_guide" />
<menuitem id="menu_about" label="&zotero.__addonRef__.workspace.menu.about;" command="cmd_about" />
</menupopup>
</menu>
</menubar>
<menu id="helpMenu" label="&helpMenu.label;" accesskey="&helpMenu.accesskey;">
<menupopup id="menu_HelpPopup">
<menuitem id="menu_guide" label="&zotero.__addonRef__.workspace.menu.guide;" command="cmd_guide" />
<menuitem id="menu_about" label="&zotero.__addonRef__.workspace.menu.about;" command="cmd_about" />
</menupopup>
</menu>
</menubar>
</toolbaritem>
</toolbar>
</toolbox>
<hbox flex="1">
<vbox id="zotero-knowledge-outline" flex="1" width="330" minwidth="300" style="overflow: hidden;">

View File

@ -8,6 +8,10 @@
"main": "src/index.js",
"scripts": {
"build": "node build.js",
"start": "node start.js",
"stop": "node stop.js",
"prerestart": "npm run build",
"restart": "node restart.js",
"release": "release-it",
"test": "echo \"Error: no test specified\" && exit 1"
},

8
restart.js Normal file
View File

@ -0,0 +1,8 @@
const { execSync } = require("child_process");
const { killZotero, startZotero } = require("./zotero-cmd.json");
try {
execSync(killZotero);
} catch (e) {}
execSync(startZotero);

View File

@ -37,18 +37,55 @@ class AddonEvents extends AddonBase {
new EditorMessage("buildReaderAnnotationButton", {})
);
}
if (event == "add" && type == "tab") {
if (ids[0] === this._Addon.knowledge.workspaceTabId) {
const tabTitle = document
.querySelector(`.tab[data-id=${ids[0]}]`)
.querySelector(".tab-name");
tabTitle.innerHTML = `${this._Addon.views.editorIcon.tabIcon}${tabTitle.innerHTML}`;
}
}
if (event == "select" && type == "tab") {
if (extraData[ids[0]].type == "betternotes") {
let t = 0;
await this._Addon.knowledge.waitWorkspaceReady();
while (
!(await this._Addon.knowledge.getWorkspaceEditorInstance(
"main",
false
)) &&
t < 100
) {
t += 1;
this._Addon.knowledge.setWorkspaceNote();
await Zotero.Promise.delay(100);
}
const _tabCover = document.getElementById("zotero-tab-cover");
const _contextPane = document.getElementById(
"zotero-context-pane"
) as XUL.Element;
const _contextPaneSplitter = document.getElementById(
"zotero-context-splitter"
) as XUL.Element;
const _tabToolbar = document.getElementById("zotero-tab-toolbar");
_contextPaneSplitter.setAttribute("hidden", true);
_contextPane.setAttribute("collapsed", true);
_tabToolbar.hidden = true;
_tabCover.hidden = true;
this._Addon.views.switchKey(false);
} else {
this._Addon.views.switchRealMenuBar(true);
this._Addon.views.switchKey(true);
}
}
},
};
}
public async onInit() {
Zotero.debug("Knowledge4Zotero: init called");
await Zotero.uiReadyPromise;
// Init translator
// await loadTranslator(TRANSLATOR_ID_BETTER_MARKDOWN);
// Init UI
this._Addon.views.addOpenWorkspaceButton();
this._Addon.views.addNewKnowledgeButton();
this.addEditorInstanceListener();
// Register the callback in Zotero as an item observer
let notifierID = Zotero.Notifier.registerObserver(this.notifierCallback, [
@ -60,15 +97,54 @@ class AddonEvents extends AddonBase {
// Unregister callback when the window closes (important to avoid a memory leak)
window.addEventListener(
"unload",
function (e) {
(e) => {
Zotero.Notifier.unregisterObserver(notifierID);
},
false
);
await Zotero.uiReadyPromise;
this._Addon.views.addOpenWorkspaceButton();
this._Addon.views.addNewKnowledgeButton();
if (!Zotero.Prefs.get("Knowledge4Zotero.mainKnowledgeID")) {
this.onEditorEvent(new EditorMessage("openUserGuide", {}));
}
this.resetState();
this.initWorkspaceTab();
this._Addon.views.switchRealMenuBar(true);
this._Addon.views.switchKey(true);
}
private async initWorkspaceTab() {
let state = Zotero.Session.state.windows.find((x) => x.type === "pane");
Zotero.debug("initWorkspaceTab");
Zotero.debug(state);
if (state) {
const noteTab = state.tabs.find((t) => t.type === "betternotes");
Zotero.debug(noteTab);
if (noteTab) {
let t = 0;
while (t < 5) {
t += 1;
try {
await this._Addon.knowledge.openWorkspaceWindow(
"tab",
false,
noteTab.selected
);
break;
} catch (e) {
this._Addon.views.showProgressWindow(
"Recovering Note Workspace Failed",
e
);
}
await Zotero.Promise.delay(1000);
}
}
}
}
public addEditorInstanceListener() {
@ -142,9 +218,16 @@ class AddonEvents extends AddonBase {
);
} else if (message.type === "openWorkspace") {
/*
message.content = {}
message.content = {event?}
*/
await this._Addon.knowledge.openWorkspaceWindow();
if (
message.content.event &&
(message.content.event as unknown as MouseEvent).shiftKey
) {
await this._Addon.knowledge.openWorkspaceWindow("window", true);
} else {
await this._Addon.knowledge.openWorkspaceWindow();
}
} else if (message.type === "openWorkspaceInWindow") {
/*
message.content = {}
@ -159,8 +242,16 @@ class AddonEvents extends AddonBase {
/*
message.content = {}
*/
const currentCollection = ZoteroPane_Local.getSelectedCollection();
if (!currentCollection) {
this._Addon.views.showProgressWindow(
"Better Notes",
"Please select a collection before creating a new main note."
);
return;
}
const res = confirm(
`Will create a new note under collection '${ZoteroPane_Local.getSelectedCollection().getName()}' and set it the main note. Continue?`
`Will create a new note under collection '${currentCollection.getName()}' and set it the main note. Continue?`
);
if (!res) {
return;

View File

@ -32,10 +32,13 @@ class Knowledge extends AddonBase {
async openWorkspaceWindow(
type: "window" | "tab" = "tab",
reopen: boolean = false
reopen: boolean = false,
select: boolean = true
) {
// this._Addon.views.showProgressWindow("Recovering Note", "4");
if (this.getWorkspaceWindow()) {
if (!reopen) {
Zotero.debug("openWorkspaceWindow: reopen");
if (this.workspaceTabId) {
Zotero_Tabs.select(this.workspaceTabId);
} else {
@ -47,6 +50,7 @@ class Knowledge extends AddonBase {
}
}
if (type === "window") {
Zotero.debug("openWorkspaceWindow: as window");
this._Addon.views._initIframe = Zotero.Promise.defer();
let win = window.open(
"chrome://Knowledge4Zotero/content/workspace.xul",
@ -62,17 +66,17 @@ class Knowledge extends AddonBase {
this._Addon.views.switchView(OutlineType.treeView);
this._Addon.views.updateOutline();
} else {
Zotero.debug("openWorkspaceWindow: as tab");
this._Addon.views._initIframe = Zotero.Promise.defer();
// Avoid sidebar show up
Zotero_Tabs.jump(0);
let { id, container } = Zotero_Tabs.add({
type: "library",
title: "Better Notes Workspace",
type: "betternotes",
title: Zotero.locale.includes("zh") ? "工作区" : "Workspace",
index: 1,
data: {
_item: this.getWorkspaceNote(),
},
select: true,
data: {},
select: select,
onClose: undefined,
});
this.workspaceTabId = id;
const _iframe = window.document.createElement("browser");
@ -84,27 +88,17 @@ class Knowledge extends AddonBase {
"chrome://Knowledge4Zotero/content/workspace.xul"
);
container.appendChild(_iframe);
// @ts-ignore
window.addEventListener("DOMContentLoaded", async (event) => {
if (
_iframe &&
// @ts-ignore
_iframe.contentWindow &&
// @ts-ignore
_iframe.contentWindow.document === event.target
) {
// @ts-ignore
this.workspaceWindow = _iframe.contentWindow;
await this.waitWorkspaceReady();
// Need reinit
this.setWorkspaceNote("main");
this.currentLine = -1;
this._Addon.views.initKnowledgeWindow(this.workspaceWindow);
this._Addon.views.switchView(OutlineType.treeView);
this._Addon.views.updateOutline();
}
});
// @ts-ignore
this.workspaceWindow = _iframe.contentWindow;
await this.waitWorkspaceReady();
this._Addon.views.hideMenuBar(this.workspaceWindow.document);
this.currentLine = -1;
this._Addon.views.initKnowledgeWindow(this.workspaceWindow);
this._Addon.views.switchView(OutlineType.treeView);
this._Addon.views.updateOutline();
}
}
@ -141,11 +135,12 @@ class Knowledge extends AddonBase {
}
async getWorkspaceEditorInstance(
type: "main" | "preview" = "main"
type: "main" | "preview" = "main",
wait: boolean = true
): Promise<EditorInstance> {
let noteEditor = (await this.getWorkspaceEditor(type)) as any;
let t = 0;
while (!noteEditor.getCurrentInstance() && t < 500) {
while (wait && !noteEditor.getCurrentInstance() && t < 500) {
t += 1;
await Zotero.Promise.delay(10);
}
@ -749,34 +744,32 @@ class Knowledge extends AddonBase {
[["MarkDown File(*.md)", "*.md"]],
`${newNote.getNoteTitle()}.md`
);
if (!filename) {
return;
}
if (filename) {
this._exportNote = newNote;
this._exportPath =
Zotero.File.pathToFile(filename).parent.path + "/attachments";
// Convert to unix format
this._exportPath = this._exportPath.replace(/\\/g, "/");
this._exportNote = newNote;
this._exportPath =
Zotero.File.pathToFile(filename).parent.path + "/attachments";
// Convert to unix format
this._exportPath = this._exportPath.replace(/\\/g, "/");
Components.utils.import("resource://gre/modules/osfile.jsm");
Components.utils.import("resource://gre/modules/osfile.jsm");
const hasImage = newNote.getNote().includes("<img");
if (hasImage) {
await Zotero.File.createDirectoryIfMissingAsync(
OS.Path.join(...this._exportPath.split(/\//))
);
}
const hasImage = newNote.getNote().includes("<img");
if (hasImage) {
await Zotero.File.createDirectoryIfMissingAsync(
OS.Path.join(...this._exportPath.split(/\//))
const translator = new Zotero.Translate.Export();
translator.setItems([newNote]);
translator.setLocation(Zotero.File.pathToFile(filename));
translator.setTranslator(TRANSLATOR_ID_BETTER_MARKDOWN);
translator.translate();
this._Addon.views.showProgressWindow(
"Better Notes",
`Note Saved to ${filename}`
);
}
const translator = new Zotero.Translate.Export();
translator.setItems([newNote]);
translator.setLocation(Zotero.File.pathToFile(filename));
translator.setTranslator(TRANSLATOR_ID_BETTER_MARKDOWN);
translator.translate();
this._Addon.views.showProgressWindow(
"Better Notes",
`Note Saved to ${filename}`
);
}
if (saveCopy) {
if (!convertNoteLinks) {

View File

@ -26,6 +26,7 @@ class AddonViews extends AddonBase {
export: `<svg t="1651322116327" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="11894" width="24" height="24"><path d="M849.2 599v217H178.5V599c-0.7-23.7-20.1-42.7-44-42.7s-43.3 19-44 42.7v252.5c0 28.9 23.6 52.5 52.5 52.5h741.7c28.9 0 52.5-23.6 52.5-52.5V599c-0.7-23.7-20.1-42.7-44-42.7s-43.3 19-44 42.7z" fill="currentColor" p-id="11895"></path><path d="M482.7 135.4l-164 164c-17.1 17.1-17.1 45.1 0 62.2s45.1 17.1 62.2 0l85.7-85.7v314.8c0 26 21.3 47.2 47.2 47.2 26 0 47.2-21.3 47.2-47.2V276l85.7 85.7c17.1 17.1 45.1 17.1 62.2 0s17.1-45.1 0-62.2l-164-164c-17.1-17.2-45.1-17.2-62.2-0.1z" fill="currentColor" p-id="11896"></path></svg>`,
close: `<svg t="1651331457107" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="12754" width="24" height="24"><path d="M557.311759 513.248864l265.280473-263.904314c12.54369-12.480043 12.607338-32.704421 0.127295-45.248112-12.512727-12.576374-32.704421-12.607338-45.248112-0.127295L512.127295 467.904421 249.088241 204.063755c-12.447359-12.480043-32.704421-12.54369-45.248112-0.063647-12.512727 12.480043-12.54369 32.735385-0.063647 45.280796l262.975407 263.775299-265.151458 263.744335c-12.54369 12.480043-12.607338 32.704421-0.127295 45.248112 6.239161 6.271845 14.463432 9.440452 22.687703 9.440452 8.160624 0 16.319527-3.103239 22.560409-9.311437l265.216826-263.807983 265.440452 266.240344c6.239161 6.271845 14.432469 9.407768 22.65674 9.407768 8.191587 0 16.352211-3.135923 22.591372-9.34412 12.512727-12.480043 12.54369-32.704421 0.063647-45.248112L557.311759 513.248864z" fill="currentColor" p-id="12755"></path></svg>`,
openWorkspaceCollectionView: `<svg t="1651317033804" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2432" width="100%" height="100%"><path d="M874.9 459.4c-18.8 0-34 15.2-34 34v355.7c0 18.6-15.5 33.7-34.5 33.7H181.5c-19 0-34.5-15.1-34.5-33.7V232.3c0-18.6 15.5-33.7 34.5-33.7H541c18.8 0 34-15.2 34-34s-15.2-34-34-34H181.5C125 130.6 79 176.2 79 232.3v616.8c0 56 46 101.7 102.5 101.7h624.9c56.5 0 102.5-45.6 102.5-101.7V493.4c0-18.8-15.2-34-34-34z" fill="currentColor" p-id="2433"></path><path d="M885.5 82.7H657.1c-18.8 0-34 15.2-34 34s15.2 34 34 34h169.7L358.5 619.1c-13.3 13.3-13.3 34.8 0 48.1 6.6 6.6 15.3 10 24 10s17.4-3.3 24-10l470-470v169.7c0 18.8 15.2 34 34 34s34-15.2 34-34V141.5c0.1-32.4-26.4-58.8-59-58.8z" fill="currentColor" p-id="2434"></path></svg>`,
tabIcon: `<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="16" height="16" class="icon icon-bg"><path d="M791.30324 369.7c-5 5-6.2 12.7-2.8 18.9 17.5 31.9 27.4 68.5 27.4 107.4 0 56.2-20.7 107.6-54.9 147-4.5 5.1-5.1 12.6-1.8 18.4l39.2 67.9c3.3 5.7 9.6 8.7 16.1 7.8 6-0.8 12.1-1.2 18.3-1.2 70.1 0.5 128 59.7 127.1 129.7-0.9 69.7-57.4 125.9-127.1 126.4-70.9 0.5-128.9-57.1-128.9-128 0-38.1 16.7-72.3 43.1-95.8l-37-64c-4.2-7.3-13.3-10-20.9-6.4-29.3 14.2-62.3 22.2-97.2 22.2-26.7 0-52.3-4.7-76-13.2-7.3-2.6-15.4 0.3-19.3 7l-24.9 43.1c-3.1 5.4-2.8 12.1 0.8 17.2 15 21.2 23.7 47.1 23.5 75.1-0.7 69.5-57.5 126.2-127 126.8-71.6 0.6-129.8-57.7-129.1-129.4 0.8-69.7 58-126.5 127.8-126.6 12 0 23.7 1.6 34.8 4.7 7 2 14.5-1.1 18.2-7.4l21.7-37.6c3.7-6.4 2.5-14.6-2.9-19.6-33.6-31.2-57.5-72.6-67-119.2-1.5-7.5-8-12.9-15.7-12.9h-92c-6.9 0-13.1 4.5-15.2 11.1C232.80324 590.2 184.70324 627 128.00324 627 57.00324 627-0.49676 569.2 0.00324 498.1 0.40324 427.5 58.60324 370.3 129.20324 371c54.2 0.5 100.4 34.8 118.5 82.8C250.00324 460 256.00324 464 262.60324 464h94.1c7.6 0 14.2-5.3 15.7-12.7 11-54.2 41.5-101.3 84-133.6 6.4-4.9 8.2-13.8 4.2-20.8l-2.2-3.8c-3.5-6-10.3-9-17.1-7.7-8.8 1.8-18 2.7-27.4 2.5-69.5-1-126.9-60.1-126-129.6 0.9-70.3 58.4-126.9 129-126.3 69.3 0.6 126 57 127 126.2 0.4 31.6-10.6 60.7-29.3 83.2-4.3 5.2-5 12.5-1.6 18.3l6.6 11.4c3.6 6.2 10.8 9.3 17.7 7.5 17.5-4.4 35.8-6.7 54.6-6.7 52.3 0 100.4 17.9 138.6 48 6.4 5 15.5 4.5 21.2-1.2l24.2-24.2c4.7-4.7 6-11.8 3.3-17.8-7.3-16.1-11.3-34-11.3-52.8 0-70.7 57.3-128 128-128 70.6 0 128 57.4 128 128 0 70.7-57.3 128-128 128-20.7 0-40.2-4.9-57.5-13.6-6.2-3.1-13.7-2-18.7 2.9l-28.4 28.5z" fill="#ffd400"/></svg>`,
};
this.currentOutline = OutlineType.treeView;
this._initIframe = Zotero.Promise.defer();
@ -37,6 +38,23 @@ class AddonViews extends AddonBase {
return editor;
}
hideMenuBar(_document: Document) {
_document.getElementById("better-notes-menu").hidden = true;
}
switchRealMenuBar(hidden: boolean) {
// We only handle hide. The show will be handled by the ZoteroStandalone.switchMenuType
document
.querySelectorAll(".menu-type-betternotes")
.forEach((el) => ((el as HTMLElement).hidden = hidden));
}
switchKey(disabled: boolean) {
document
.querySelectorAll(".key-type-betternotes")
.forEach((el) => (el as XUL.Element).setAttribute("disabled", disabled));
}
async addEditorKnowledgeToolBar(editorInstances: EditorInstance) {
await editorInstances._initPromise;
@ -318,11 +336,15 @@ class AddonViews extends AddonBase {
const span4 = document.createElement("span");
span4.setAttribute("class", "cell-text");
span4.setAttribute("style", "margin-left: 6px;");
span4.innerHTML = "Open Workspace";
span4.innerHTML = Zotero.locale.includes("zh")
? "打开工作区"
: "Open Workspace";
span1.append(span2, span3, span4);
treeRow.append(span1);
treeRow.addEventListener("click", (e) => {
this._Addon.events.onEditorEvent(new EditorMessage("openWorkspace", {}));
this._Addon.events.onEditorEvent(
new EditorMessage("openWorkspace", { event: e })
);
});
treeRow.addEventListener("mouseover", (e: XULEvent) => {
treeRow.setAttribute(
@ -592,6 +614,11 @@ class AddonViews extends AddonBase {
this.switchView();
});
_window.addEventListener("resize", (e) => this.resizeOutline(_window));
_window.document
.getElementById("outline-splitter")
.addEventListener("mouseup", async (e) => {
this.resizeOutline(_window);
});
}
async messageHandler(e) {

6
start.js Normal file
View File

@ -0,0 +1,6 @@
const { execSync } = require("child_process");
const { exit } = require("process");
const { startZotero } = require("./zotero-cmd.json");
execSync(startZotero);
exit(0);

6
stop.js Normal file
View File

@ -0,0 +1,6 @@
const { execSync } = require("child_process");
const { killZotero } = require("./zotero-cmd.json");
try {
execSync(killZotero);
} catch (e) {}

1
typing/global.d.ts vendored
View File

@ -217,6 +217,7 @@ declare const Zotero_Tabs: {
index: any;
data: object;
select: boolean;
onClose: Function;
});
_tabs: Array<any>;
selectedID: string;

5
zotero-cmd-default.json Normal file
View File

@ -0,0 +1,5 @@
{
"usage": "Copy and rename this file to zotero-cmd.json. Edit the cmd.",
"killZotero": "taskkill /f /im zotero.exe",
"startZotero": "/path/to/zotero.exe --debugger --purgecaches"
}