Skip to content

Commit

Permalink
增加HX自定义数据集,修复快捷键失效
Browse files Browse the repository at this point in the history
  • Loading branch information
redleafnew committed Oct 1, 2024
1 parent 5d6f022 commit f931a03
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 100 deletions.
4 changes: 1 addition & 3 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ async function onStartup() {
BasicExampleFactory.registerPrefs();

BasicExampleFactory.registerNotifier();

KeyExampleFactory.registerShortcuts();
await Promise.all(
Zotero.getMainWindows().map((win) => onMainWindowLoad(win)),
);
}

async function onMainWindowLoad(win: Window) {
KeyExampleFactory.registerShortcuts(win);

UIExampleFactory.registerRightClickMenuItem(); // 右键菜单
// UIExampleFactory.registerRightClickMenuPopup(); // 右键弹出菜单
UIExampleFactory.registerWindowMenuWithSeprator();
Expand Down
117 changes: 20 additions & 97 deletions src/modules/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export class KeyExampleFactory {
}
if (HX) {
var HXLevel: any = await KeyExampleFactory.getCustomIFs(
item,
item,
HXJourID,
);
}
Expand Down Expand Up @@ -1159,11 +1159,11 @@ export class KeyExampleFactory {
}
// 注册快捷键
@example
static registerShortcuts(win?: Window) {
if (!win) {
win = Zotero.getMainWindow();
}
ztoolkit.Keyboard.unregisterAll();
static registerShortcuts() {
// if (!win) {
// win = Zotero.getMainWindow();
// }
// ztoolkit.Keyboard.unregisterAll();
// const keysetId = `${config.addonRef}-keyset`;
// const cmdsetId = `${config.addonRef}-cmdset`;
// const cmdSmallerId = `${config.addonRef}-cmd-smaller`;
Expand Down Expand Up @@ -1210,112 +1210,35 @@ export class KeyExampleFactory {
HelperExampleFactory.chPubTitleCase();
});
}

ztoolkit.log(`${getString("dataDir")} ${Zotero.DataDirectory.dir}`)
Zotero.debug('数据目录是:'+ `${getString("dataDir")} ${Zotero.DataDirectory.dir}`)
// 显示数据目录
if (ifDataDir) {
ztoolkit.Keyboard.register((event, { keyboard }) => {
if (!keyboard?.equals(`alt,${keyDataDir}`)) {
return;
}

// HelperExampleFactory.progressWindow(`${ifPubTitleCase}${keyPubTitleCase}`, 'success')
// addon.hooks.onShortcuts("larger");
// HelperExampleFactory.progressWindow(`${ifPubTitleCase} ${keyPubTitleCase} `, 'success');
HelperExampleFactory.progressWindow(
ztoolkit.Keyboard.register((ev, keyOptions ) => {
ztoolkit.log(ev, keyOptions.keyboard);
if (keyOptions.keyboard?.equals(`alt,${keyDataDir}`)) {
HelperExampleFactory.progressWindow(
`${getString("dataDir")} ${Zotero.DataDirectory.dir}`,
"success",
);
}
});
}

// Register an event key for Alt+P 配置目录
if (ifProfileDir) {
ztoolkit.Keyboard.register((event, { keyboard }) => {
if (!keyboard?.equals(`alt,${keyProfileDir}`)) {
return;
}
// addon.hooks.onShortcuts("larger");
HelperExampleFactory.progressWindow(
ztoolkit.Keyboard.register((ev, keyOptions ) => {
ztoolkit.log(ev, keyOptions.keyboard);
if (keyOptions.keyboard?.equals(`alt,${keyProfileDir}`)) {
HelperExampleFactory.progressWindow(
`${getString("proDir")} ${Zotero.Profile.dir}`,
"success",
);
});
}
});
}
}

// 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");
},
});
*/
/*
new ztoolkit.ProgressWindow(config.addonName)
.createLine({
text: "Example Shortcuts: Alt+L/S/C",
type: "success",
})
.show();
*/
}

/*
@example
static exampleShortcutLargerCallback() {
new ztoolkit.ProgressWindow(config.addonName)
.createLine({
text: "Larger!",
type: "default",
})
.show();
}
@example
static exampleShortcutSmallerCallback() {
new ztoolkit.ProgressWindow(config.addonName)
.createLine({
text: "Smaller!",
type: "default",
})
.show();
}
*/
@example
static exampleShortcutConflictionCallback() {
return;
Expand Down

0 comments on commit f931a03

Please sign in to comment.