From 3d9f8a8a0df3410ac7f20819429c08b59d8df4d9 Mon Sep 17 00:00:00 2001 From: windingwind <33902321+windingwind@users.noreply.github.com> Date: Thu, 14 Dec 2023 22:33:10 +0800 Subject: [PATCH] update: registerShortcuts --- package.json | 12 +++---- src/hooks.ts | 7 ++--- src/modules/examples.ts | 70 +++++------------------------------------ 3 files changed, 16 insertions(+), 73 deletions(-) diff --git a/package.json b/package.json index d33f59b..7c50f07 100644 --- a/package.json +++ b/package.json @@ -32,22 +32,22 @@ }, "homepage": "https://github.com/windingwind/zotero-addon-template#readme", "dependencies": { - "zotero-plugin-toolkit": "^2.3.11" + "zotero-plugin-toolkit": "^2.3.15" }, "devDependencies": { "@types/node": "^20.10.4", - "@typescript-eslint/eslint-plugin": "^6.13.2", - "@typescript-eslint/parser": "^6.13.2", + "@typescript-eslint/eslint-plugin": "^6.14.0", + "@typescript-eslint/parser": "^6.14.0", "chokidar": "^3.5.3", "compressing": "^1.10.0", - "esbuild": "^0.19.8", + "esbuild": "^0.19.9", "eslint": "^8.55.0", "eslint-config-prettier": "^9.1.0", - "prettier": "^3.1.0", + "prettier": "^3.1.1", "release-it": "^17.0.1", "replace-in-file": "^7.0.2", "typescript": "^5.3.3", - "zotero-types": "^1.3.7" + "zotero-types": "^1.3.10" }, "eslintConfig": { "env": { diff --git a/src/hooks.ts b/src/hooks.ts index 9b781f3..91b9350 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -30,6 +30,8 @@ async function onStartup() { BasicExampleFactory.registerNotifier(); + KeyExampleFactory.registerShortcuts(); + await onMainWindowLoad(window); } @@ -48,8 +50,6 @@ async function onMainWindowLoad(win: Window): Promise { }) .show(); - KeyExampleFactory.registerShortcuts(); - await Zotero.Promise.delay(1000); popupWin.changeLine({ progress: 30, @@ -151,9 +151,6 @@ function onShortcuts(type: string) { case "smaller": KeyExampleFactory.exampleShortcutSmallerCallback(); break; - case "confliction": - KeyExampleFactory.exampleShortcutConflictingCallback(); - break; default: break; } diff --git a/src/modules/examples.ts b/src/modules/examples.ts index d493760..f69fba7 100644 --- a/src/modules/examples.ts +++ b/src/modules/examples.ts @@ -86,55 +86,17 @@ export class BasicExampleFactory { export class KeyExampleFactory { @example static registerShortcuts() { - const keysetId = `${config.addonRef}-keyset`; - const cmdsetId = `${config.addonRef}-cmdset`; - const cmdSmallerId = `${config.addonRef}-cmd-smaller`; // Register an event key for Alt+L - ztoolkit.Shortcut.register("event", { - id: `${config.addonRef}-key-larger`, - key: "L", - modifiers: "alt", - callback: (keyOptions) => { + ztoolkit.Keyboard.register((ev, keyOptions) => { + ztoolkit.log(ev, keyOptions.keyboard); + if (keyOptions.keyboard.equals("shift,l")) { addon.hooks.onShortcuts("larger"); - }, - }); - // Register an element key using for Alt+S - ztoolkit.Shortcut.register("element", { - id: `${config.addonRef}-key-smaller`, - key: "S", - modifiers: "alt", - xulData: { - document, - command: cmdSmallerId, - _parentId: keysetId, - _commandOptions: { - id: cmdSmallerId, - document, - _parentId: cmdsetId, - oncommand: `Zotero.${config.addonInstance}.hooks.onShortcuts('smaller')`, - }, - }, - }); - // Here we register an conflict key for Alt+S - // just to show how the confliction check works. - // This is something you should avoid in your plugin. - ztoolkit.Shortcut.register("event", { - id: `${config.addonRef}-key-smaller-conflict`, - key: "S", - modifiers: "alt", - callback: (keyOptions) => { - ztoolkit.getGlobal("alert")("Smaller! This is a conflict key."); - }, - }); - // Register an event key to check confliction - ztoolkit.Shortcut.register("event", { - id: `${config.addonRef}-key-check-conflict`, - key: "C", - modifiers: "alt", - callback: (keyOptions) => { - addon.hooks.onShortcuts("confliction"); - }, + } + if (ev.shiftKey && ev.key === "S") { + addon.hooks.onShortcuts("smaller"); + } }); + new ztoolkit.ProgressWindow(config.addonName) .createLine({ text: "Example Shortcuts: Alt+L/S/C", @@ -162,22 +124,6 @@ export class KeyExampleFactory { }) .show(); } - - @example - static exampleShortcutConflictingCallback() { - const conflictingGroups = ztoolkit.Shortcut.checkAllKeyConflicting(); - new ztoolkit.ProgressWindow("Check Key Conflicting") - .createLine({ - text: `${conflictingGroups.length} groups of conflicting keys found. Details are in the debug output/console.`, - }) - .show(-1); - ztoolkit.log( - "Conflicting:", - conflictingGroups, - "All keys:", - ztoolkit.Shortcut.getAll(), - ); - } } export class UIExampleFactory {