add: outline drag&drop
This commit is contained in:
parent
258a076740
commit
71404137ec
|
|
@ -1,8 +1,22 @@
|
||||||
import { AddonBase, EditorMessage } from "./base";
|
import { AddonBase, EditorMessage } from "./base";
|
||||||
|
|
||||||
class AddonEvents extends AddonBase {
|
class AddonEvents extends AddonBase {
|
||||||
|
notifierCallback: object;
|
||||||
constructor(parent: Knowledge4Zotero) {
|
constructor(parent: Knowledge4Zotero) {
|
||||||
super(parent);
|
super(parent);
|
||||||
|
this.notifierCallback = {
|
||||||
|
notify: async (
|
||||||
|
event: string,
|
||||||
|
type: string,
|
||||||
|
ids: Array<string>,
|
||||||
|
extraData: object
|
||||||
|
) => {
|
||||||
|
if (event == "modify") {
|
||||||
|
Zotero.debug("Knowledge4Zotero: main knowledge midified.");
|
||||||
|
this._Addon.views.buildOutline();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async onInit() {
|
public async onInit() {
|
||||||
|
|
@ -10,6 +24,19 @@ class AddonEvents extends AddonBase {
|
||||||
await Zotero.uiReadyPromise;
|
await Zotero.uiReadyPromise;
|
||||||
this._Addon.views.addOpenWorkspaceButton();
|
this._Addon.views.addOpenWorkspaceButton();
|
||||||
this.addEditorInstanceListener();
|
this.addEditorInstanceListener();
|
||||||
|
// Register the callback in Zotero as an item observer
|
||||||
|
let notifierID = Zotero.Notifier.registerObserver(this.notifierCallback, [
|
||||||
|
"item",
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Unregister callback when the window closes (important to avoid a memory leak)
|
||||||
|
window.addEventListener(
|
||||||
|
"unload",
|
||||||
|
function (e) {
|
||||||
|
Zotero.Notifier.unregisterObserver(notifierID);
|
||||||
|
},
|
||||||
|
false
|
||||||
|
);
|
||||||
this.resetState();
|
this.resetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -211,6 +238,34 @@ class AddonEvents extends AddonBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (message.type === "moveOutlineTitle") {
|
||||||
|
/*
|
||||||
|
message.content = {
|
||||||
|
params: {
|
||||||
|
fromID, toID, type: "before" | "after"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
let tree = this._Addon.knowledge.getNoteTree();
|
||||||
|
let fromNode = this._Addon.knowledge.getNoteTreeNodeById(
|
||||||
|
undefined,
|
||||||
|
message.content.params.fromID,
|
||||||
|
tree
|
||||||
|
);
|
||||||
|
let toNode = this._Addon.knowledge.getNoteTreeNodeById(
|
||||||
|
undefined,
|
||||||
|
message.content.params.toID,
|
||||||
|
tree
|
||||||
|
);
|
||||||
|
Zotero.debug(fromNode.model);
|
||||||
|
Zotero.debug(toNode.model);
|
||||||
|
this._Addon.knowledge.moveHeaderLineInNote(
|
||||||
|
undefined,
|
||||||
|
fromNode,
|
||||||
|
toNode,
|
||||||
|
message.content.params.type
|
||||||
|
);
|
||||||
|
this._Addon.views.buildOutline();
|
||||||
} else if (message.type === "closePreview") {
|
} else if (message.type === "closePreview") {
|
||||||
/*
|
/*
|
||||||
message.content = {
|
message.content = {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ const TreeModel = require("./treemodel");
|
||||||
|
|
||||||
class Knowledge extends AddonBase {
|
class Knowledge extends AddonBase {
|
||||||
currentLine: number;
|
currentLine: number;
|
||||||
|
currentVersion: number;
|
||||||
workspaceWindow: Window;
|
workspaceWindow: Window;
|
||||||
constructor(parent: Knowledge4Zotero) {
|
constructor(parent: Knowledge4Zotero) {
|
||||||
super(parent);
|
super(parent);
|
||||||
|
|
@ -35,7 +36,7 @@ class Knowledge extends AddonBase {
|
||||||
this.workspaceWindow = win;
|
this.workspaceWindow = win;
|
||||||
await this.waitWorkspaceReady();
|
await this.waitWorkspaceReady();
|
||||||
this.setWorkspaceNote("main");
|
this.setWorkspaceNote("main");
|
||||||
this._Addon.views.buildOutline(this.getWorkspaceNote());
|
this._Addon.views.buildOutline();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -117,7 +118,7 @@ class Knowledge extends AddonBase {
|
||||||
let containerIndex = noteText.search(/data-schema-version="8">/g);
|
let containerIndex = noteText.search(/data-schema-version="8">/g);
|
||||||
if (containerIndex != -1) {
|
if (containerIndex != -1) {
|
||||||
noteText = noteText.substring(
|
noteText = noteText.substring(
|
||||||
containerIndex + '<div data-schema-version="8">'.length,
|
containerIndex + 'data-schema-version="8">'.length,
|
||||||
noteText.length - "</div>".length
|
noteText.length - "</div>".length
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -296,7 +297,7 @@ class Knowledge extends AddonBase {
|
||||||
this.setLinesToNote(note, newLines);
|
this.setLinesToNote(note, newLines);
|
||||||
}
|
}
|
||||||
|
|
||||||
getNoteTree(note: ZoteroItem): TreeModel.Node<object> {
|
getNoteTree(note: ZoteroItem = undefined): TreeModel.Node<object> {
|
||||||
// See http://jnuno.com/tree-model-js
|
// See http://jnuno.com/tree-model-js
|
||||||
note = note || this.getWorkspaceNote();
|
note = note || this.getWorkspaceNote();
|
||||||
if (!note) {
|
if (!note) {
|
||||||
|
|
@ -444,6 +445,8 @@ class Knowledge extends AddonBase {
|
||||||
|
|
||||||
if (convertNoteLinks) {
|
if (convertNoteLinks) {
|
||||||
let item: ZoteroItem = new Zotero.Item("note");
|
let item: ZoteroItem = new Zotero.Item("note");
|
||||||
|
item.setNote(note.getNote());
|
||||||
|
item.saveTx();
|
||||||
let noteLines = this.getLinesInNote(note);
|
let noteLines = this.getLinesInNote(note);
|
||||||
let newLines = [];
|
let newLines = [];
|
||||||
for (let i in noteLines) {
|
for (let i in noteLines) {
|
||||||
|
|
@ -472,8 +475,7 @@ class Knowledge extends AddonBase {
|
||||||
linkIndex = noteLines[i].search(/zotero:\/\/note\//g);
|
linkIndex = noteLines[i].search(/zotero:\/\/note\//g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
item.setNote(`<div data-schema-version="8">${newLines.join("\n")}</div>`);
|
this.setLinesToNote(item, newLines);
|
||||||
item.saveTx();
|
|
||||||
exporter.items = [item];
|
exporter.items = [item];
|
||||||
await exporter.save();
|
await exporter.save();
|
||||||
await Zotero.Items.erase(item.id);
|
await Zotero.Items.erase(item.id);
|
||||||
|
|
|
||||||
|
|
@ -296,14 +296,15 @@ class AddonViews extends AddonBase {
|
||||||
toNode === null || isDropInsideItem
|
toNode === null || isDropInsideItem
|
||||||
? toItems.length
|
? toItems.length
|
||||||
: this.findIndex(toItems, toNode.itemData.id);
|
: this.findIndex(toItems, toNode.itemData.id);
|
||||||
Zotero.debug(fromNode.itemData);
|
|
||||||
Zotero.debug(toItems[toIndex]);
|
|
||||||
|
|
||||||
this._Addon.events.onEditorEvent(
|
this._Addon.events.onEditorEvent(
|
||||||
new EditorMessage("moveOutlineTitle", {
|
new EditorMessage("moveOutlineTitle", {
|
||||||
params: {
|
params: {
|
||||||
fromID: fromNode.itemData.id,
|
fromID: parseInt(fromNode.itemData.id),
|
||||||
toID: toNode ? toNode.itemData.id : -1,
|
toID: toNode
|
||||||
|
? parseInt(toNode.itemData.id)
|
||||||
|
: toItems[toItems.length - 1].itemData.id,
|
||||||
|
type: toNode ? "before" : "after",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue