Skip to content

Commit

Permalink
光标在引用处add citation自动转化为多重,不删除原来
Browse files Browse the repository at this point in the history
  • Loading branch information
MuiseDestiny committed Feb 3, 2023
1 parent b789ba5 commit cccd750
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 219 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"homepage": "https://github.com/muisedestiny/zotero-citation#readme",
"dependencies": {
"path": "^0.12.7",
"zotero-plugin-toolkit": "^1.1.2"
"zotero-plugin-toolkit": "^1.1.5"
},
"devDependencies": {
"@types/node": "^18.11.18",
Expand All @@ -48,7 +48,7 @@
"minimist": "^1.2.7",
"release-it": "^15.6.0",
"replace-in-file": "^6.3.5",
"typescript": "^4.9.4",
"zotero-types": "^1.0.6"
"typescript": "^4.9.5",
"zotero-types": "^1.0.7"
}
}
2 changes: 0 additions & 2 deletions src/addon.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import ZoteroToolkit from "E:/Github/zotero-plugin-toolkit/dist/index"
import { ColumnOptions } from "zotero-plugin-toolkit/dist/helpers/virtualizedTable";
import hooks from "./hooks";

class Addon {
Expand All @@ -14,7 +13,6 @@ class Addon {
};
prefs?: {
window: Window;
columns: Array<ColumnOptions>;
rows: Array<{ [dataKey: string]: string }>;
};
};
Expand Down
94 changes: 3 additions & 91 deletions src/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import {
BasicExampleFactory,
HelperExampleFactory,
KeyExampleFactory,
UIExampleFactory,
} from "./modules/examples";
import { config } from "../package.json";
import { getString, initLocale } from "./modules/locale";
import { registerPrefsScripts } from "./modules/preferenceScript";
import Citation from "./modules/citation";
import { citeFromSelectedItems } from "./modules/cite";

Expand All @@ -17,6 +10,7 @@ async function onStartup() {
Zotero.uiReadyPromise,
]);
initLocale();
await Zotero.Promise.delay(3000)
const citation = new Citation()
citation.listener(1000);

Expand Down Expand Up @@ -48,97 +42,15 @@ async function onStartup() {

function onShutdown(): void {
ztoolkit.unregisterAll();
console.log("Prompt unregisterAll")
ztoolkit.Prompt.unregisterAll();
// Remove addon object
addon.data.alive = false;
delete Zotero.ZoteroCitation;
}

/**
* This function is just an example of dispatcher for Notify events.
* Any operations should be placed in a function to keep this funcion clear.
*/
async function onNotify(
event: string,
type: string,
ids: Array<string>,
extraData: { [key: string]: any }
) {
// You can add your code to the corresponding notify type
ztoolkit.log("notify", event, type, ids, extraData);
if (
event == "select" &&
type == "tab" &&
extraData[ids[0]].type == "reader"
) {
BasicExampleFactory.exampleNotifierCallback();
} else {
return;
}
}

/**
* This function is just an example of dispatcher for Preference UI events.
* Any operations should be placed in a function to keep this funcion clear.
* @param type event type
* @param data event data
*/
async function onPrefsEvent(type: string, data: { [key: string]: any }) {
switch (type) {
case "load":
registerPrefsScripts(data.window);
break;
default:
return;
}
}

function onShortcuts(type: string) {
switch (type) {
case "larger":
KeyExampleFactory.exampleShortcutLargerCallback();
break;
case "smaller":
KeyExampleFactory.exampleShortcutSmallerCallback();
break;
case "confliction":
KeyExampleFactory.exampleShortcutConflictionCallback();
break;
default:
break;
}
}

function onDialogEvents(type: string) {
switch (type) {
case "dialogExample":
HelperExampleFactory.dialogExample();
break;
case "clipboardExample":
HelperExampleFactory.clipboardExample();
break;
case "filePickerExample":
HelperExampleFactory.filePickerExample();
break;
case "progressWindowExample":
HelperExampleFactory.progressWindowExample();
break;
case "vtableExample":
HelperExampleFactory.vtableExample();
break;
default:
break;
}
}

// Add your hooks here. For element click, etc.
// Keep in mind hooks only do dispatch. Don't add code that does real jobs in hooks.
// Otherwise the code would be hard to read and maintian.

export default {
onStartup,
onShutdown,
onNotify,
onPrefsEvent,
onShortcuts,
onDialogEvents,
};
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import { BasicTool } from "zotero-plugin-toolkit/dist/basic";
import Addon from "./addon";
import { config } from "../package.json";
Expand Down
Loading

0 comments on commit cccd750

Please sign in to comment.