Skip to content

Commit

Permalink
fix: outlinePane messageHandler
Browse files Browse the repository at this point in the history
fix: #950
remove: deprecated PreferencePaneManager
  • Loading branch information
windingwind committed Apr 16, 2024
1 parent 2c03a11 commit 2294929
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 23 deletions.
10 changes: 10 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
html2md,
annotations2html,
note2html,
link2params,
} from "./utils/convert";
import { exportNotes } from "./modules/export/api";
import { saveDocx } from "./modules/export/docx";
Expand Down Expand Up @@ -59,10 +60,14 @@ import {
getRangeAtCursor,
move,
replace,
moveHeading,
updateHeadingTextAtLine,
} from "./utils/editor";
import {
addLineToNote,
getNoteTree,
getNoteTreeFlattened,
getNoteTreeNodeById,
getLinesInNote,
} from "./utils/note";
import {
Expand Down Expand Up @@ -92,6 +97,7 @@ const convert = {
note2noteDiff,
note2link,
link2note,
link2params,
link2html,
md2html,
html2md,
Expand Down Expand Up @@ -140,12 +146,16 @@ const editor = {
getPositionAtLine,
getTextBetween,
getTextBetweenLines,
moveHeading,
updateHeadingTextAtLine,
};

const note = {
insert: addLineToNote,
getLinesInNote,
getNoteTree,
getNoteTreeFlattened,
getNoteTreeNodeById,
};

const relation = {
Expand Down
31 changes: 16 additions & 15 deletions src/elements/workspace/outlinePane.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import { FilePickerHelper } from "zotero-plugin-toolkit/dist/helpers/filePicker";
import { config } from "../../../package.json";
import { showHintWithLink } from "../../utils/hint";
import { formatPath } from "../../utils/str";
import { waitUtilAsync } from "../../utils/wait";
import { OutlineType } from "../../utils/workspace";
import { PluginCEBase } from "../base";
import {
getEditorInstance,
moveHeading,
updateHeadingTextAtLine,
} from "../../utils/editor";
import { getNoteLinkParams } from "../../utils/link";
import { getNoteTree, getNoteTreeNodeById } from "../../utils/note";
import { getPref } from "../../utils/prefs";
import { showHintWithLink } from "../../utils/hint";

export class OutlinePane extends PluginCEBase {
_outlineType: OutlineType = OutlineType.empty;
Expand Down Expand Up @@ -296,7 +289,7 @@ export class OutlinePane extends PluginCEBase {
return;
}
case "openNote": {
const linkParams = getNoteLinkParams(ev.data.link);
const linkParams = this._addon.api.convert.link2params(ev.data.link);
if (!linkParams.noteItem) {
return;
}
Expand All @@ -307,11 +300,19 @@ export class OutlinePane extends PluginCEBase {
}
case "moveNode": {
if (!this.item) return;
const tree = getNoteTree(this.item);
const fromNode = getNoteTreeNodeById(this.item, ev.data.fromID, tree);
const toNode = getNoteTreeNodeById(this.item, ev.data.toID, tree);
moveHeading(
getEditorInstance(this.item.id),
const tree = this._addon.api.note.getNoteTree(this.item);
const fromNode = this._addon.api.note.getNoteTreeNodeById(
this.item,
ev.data.fromID,
tree,
);
const toNode = this._addon.api.note.getNoteTreeNodeById(
this.item,
ev.data.toID,
tree,
);
this._addon.api.editor.moveHeading(
this._addon.api.editor.getEditorInstance(this.item.id),
fromNode!,
toNode!,
ev.data.moveType,
Expand All @@ -322,7 +323,7 @@ export class OutlinePane extends PluginCEBase {
if (!this.editor) {
return;
}
updateHeadingTextAtLine(
this._addon.api.editor.updateHeadingTextAtLine(
this.editor,
ev.data.lineIndex,
ev.data.text.replace(/[\r\n]/g, ""),
Expand Down
4 changes: 1 addition & 3 deletions src/modules/preferenceWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ import { config } from "../../package.json";
import { getString } from "../utils/locale";

export function registerPrefsWindow() {
ztoolkit.PreferencePane.register({
Zotero.PreferencePanes.register({
pluginID: config.addonID,
src: rootURI + "chrome/content/preferences.xhtml",
label: getString("pref.title"),
image: `chrome://${config.addonRef}/content/icons/favicon.png`,
extraDTD: [`chrome://${config.addonRef}/locale/overlay.dtd`],
defaultXUL: true,
});
}

Expand Down
5 changes: 5 additions & 0 deletions src/utils/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export {
note2noteDiff,
note2link,
link2note,
link2params,
link2html,
md2html,
html2md,
Expand Down Expand Up @@ -179,6 +180,10 @@ function link2note(link: string) {
return getNoteLinkParams(link).noteItem;
}

function link2params(link: string) {
return getNoteLinkParams(link);
}

async function link2html(
link: string,
options: { noteItem?: Zotero.Item; dryRun?: boolean } = {},
Expand Down
11 changes: 9 additions & 2 deletions src/utils/hint.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { config } from "../../package.json";
import { ProgressWindowHelper } from "zotero-plugin-toolkit/dist/helpers/progressWindow";
import { PROGRESS_TITLE } from "./config";
import { waitUtilAsync } from "./wait";

ProgressWindowHelper.setIconURI(
"default",
`chrome://${config.addonRef}/content/icons/favicon.png`,
);

function showHint(text: string) {
return new ztoolkit.ProgressWindow(PROGRESS_TITLE)
return new ProgressWindowHelper(PROGRESS_TITLE)
.createLine({ text, progress: 100, type: "default" })
.show();
}
Expand All @@ -12,7 +19,7 @@ async function showHintWithLink(
linkText: string,
linkCallback: (ev: MouseEvent) => any,
) {
const progress = new ztoolkit.ProgressWindow(PROGRESS_TITLE)
const progress = new ProgressWindowHelper(PROGRESS_TITLE)
.createLine({ text, progress: 100, type: "default" })
.show(-1);
// Just a placeholder
Expand Down
3 changes: 0 additions & 3 deletions src/utils/ztoolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ function initZToolkit(_ztoolkit: ReturnType<typeof createZToolkit>) {

import { BasicTool, unregister } from "zotero-plugin-toolkit/dist/basic";
import { UITool } from "zotero-plugin-toolkit/dist/tools/ui";
import { PreferencePaneManager } from "zotero-plugin-toolkit/dist/managers/preferencePane";
import { ClipboardHelper } from "zotero-plugin-toolkit/dist/helpers/clipboard";
import { DialogHelper } from "zotero-plugin-toolkit/dist/helpers/dialog";
import { FilePickerHelper } from "zotero-plugin-toolkit/dist/helpers/filePicker";
Expand All @@ -47,7 +46,6 @@ class MyToolkit extends BasicTool {
LibraryTabPanel: LibraryTabPanelManager;
ReaderTabPanel: ReaderTabPanelManager;
Menu: MenuManager;
PreferencePane: PreferencePaneManager;
Clipboard: typeof ClipboardHelper;
FilePicker: typeof FilePickerHelper;
ProgressWindow: typeof ProgressWindowHelper;
Expand All @@ -62,7 +60,6 @@ class MyToolkit extends BasicTool {
this.LibraryTabPanel = new LibraryTabPanelManager(this);
this.ReaderTabPanel = new ReaderTabPanelManager(this);
this.Menu = new MenuManager(this);
this.PreferencePane = new PreferencePaneManager(this);
this.Clipboard = ClipboardHelper;
this.FilePicker = FilePickerHelper;
this.ProgressWindow = ProgressWindowHelper;
Expand Down

0 comments on commit 2294929

Please sign in to comment.