update: registerShortcuts

This commit is contained in:
windingwind 2023-12-14 22:33:10 +08:00
parent 032aa74f6e
commit 3d9f8a8a0d
3 changed files with 16 additions and 73 deletions

View File

@ -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": {

View File

@ -30,6 +30,8 @@ async function onStartup() {
BasicExampleFactory.registerNotifier();
KeyExampleFactory.registerShortcuts();
await onMainWindowLoad(window);
}
@ -48,8 +50,6 @@ async function onMainWindowLoad(win: Window): Promise<void> {
})
.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;
}

View File

@ -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 <key> 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 {