Skip to content

Commit

Permalink
使用新的快捷键注册函数,无须重启即可生效
Browse files Browse the repository at this point in the history
  • Loading branch information
redleafnew committed Mar 17, 2024
1 parent 1aa2a45 commit 27090f9
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 97 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@

`Zotero.Prefs.set('extensions.zotero.delitemwithatt.key.del.abs', 'Z', true); // 修改删除摘要默认快捷键,修改Z为预设置的快捷字母`

修改后**重启**Zotero生效。

2. 根据条目标题语言将所选条目语言字段设置为`en-US``zh-CN`

3. 将附件导出。
Expand Down
2 changes: 1 addition & 1 deletion addon/locale/en-US/addon.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ delete-extra =
}
delete-abstract =
{$count ->
[one]Are you sure you want to empty the abstract of the item?Are you sure you want to empty the extra of the item?
[one]Are you sure you want to empty the abstract of the item? Are you sure you want to empty the extra of the item?
*[other] Are you sure you want to empty the abstracts of the {$count} selected items?
}
# delete-abstract-sig = Are you sure you want to empty the abstract of the item?
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "delitemwithatt",
"version": "0.3.0",
"version": "0.3.1",
"description": "Delete item(s) with attachment(s)",
"config": {
"addonName": "Del Item With Attachment",
Expand Down
5 changes: 3 additions & 2 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from "./modules/examples";
import { config } from "../package.json";
import { getString, initLocale } from "./utils/locale";
import { registerShortcuts } from "./modules/shortcuts";


async function onStartup() {
Expand All @@ -30,8 +31,8 @@ async function onStartup() {
})
.show();

KeyExampleFactory.registerShortcuts();

// KeyExampleFactory.registerShortcuts();
registerShortcuts(); //新的注册快捷键
await Zotero.Promise.delay(1000);
popupWin.changeLine({
progress: 30,
Expand Down
180 changes: 90 additions & 90 deletions src/modules/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,96 +156,96 @@ export class BasicExampleFactory {
export class KeyExampleFactory {

// modifiers逗号分隔,shift就是shift,ctrl跨平台是accel
@example
static registerShortcuts() {

// 修改后重启生效
// 删除条目和附件默认快捷键:Alt+I
var key_del_item_att = getPref('key.del.item.att') == undefined ? 'I' : getPref('key.del.item.att');
// 删除附件默认快捷键.Alt+A
var key_del_att = getPref('key.del.att') == undefined ? 'A' : getPref('key.del.att');
//仅删除快照默认快捷键 Alt+S
var key_del_snap = getPref('key.del.snap') == undefined ? 'S' : getPref('key.del.snap');
// 仅删除笔记默认快捷键.Alt+N
var key_del_note = getPref('key.del.note') == undefined ? 'N' : getPref('key.del.note');
// 仅删除其它默认快捷键.Alt+X
var key_del_extra = getPref('key.del.extra') == undefined ? 'X' : getPref('key.del.extra');
// 仅删除摘要默认快捷键.Alt+Z
var key_del_abs = getPref('key.del.abs') == undefined ? 'Z' : getPref('key.del.abs');



// 删除条目和附件快捷键:Alt+I
ztoolkit.Shortcut.register("event", {
id: `${config.addonRef}-key-del-item-att`,
key: key_del_item_att as string,
modifiers: "alt",
callback: (keyOptions) => {
HelperExampleFactory.delItemAtt();
},
});

// 删除附件快捷键.Alt+A
ztoolkit.Shortcut.register("event", {
id: `${config.addonRef}-key-del-att`,
key: key_del_att as string,
modifiers: "alt",
callback: (keyOptions) => {

HelperExampleFactory.delAtt();
},
});

//仅删除快照快捷键 Alt+S
ztoolkit.Shortcut.register("event", {
id: `${config.addonRef}-key-del-snap`,
key: key_del_snap as string,
modifiers: "alt",
callback: (keyOptions) => {
HelperExampleFactory.delSnap();
},
});

//删除笔记快捷键Alt+N
ztoolkit.Shortcut.register("event", {
id: `${config.addonRef}-key-del-note`,
key: key_del_note as string,
modifiers: "alt",
callback: (keyOptions) => {
HelperExampleFactory.delNote();
},
});

// 删除其它要快捷键 Alt+X
ztoolkit.Shortcut.register("event", {
id: `${config.addonRef}-key-del-extra`,
key: key_del_extra as string,
modifiers: "alt",
callback: (keyOptions) => {
HelperExampleFactory.delExtra();
},
});

// 删除摘要快捷键Alt+Z
ztoolkit.Shortcut.register("event", {
id: `${config.addonRef}-key-del-abs`,
key: key_del_abs as string,
modifiers: "alt",
callback: (keyOptions) => {
HelperExampleFactory.delAbstract();
},
});

//删除摘要快捷键Alt+Z
// ztoolkit.Shortcut.register("event", {
// id: `${config.addonRef}-key-del-abs`,
// key: "U",
// modifiers: "alt",
// callback: (keyOptions) => {
// // HelperExampleFactory.OSnow();
// },
// });
}
// @example
// static registerShortcuts() {

// // 修改后重启生效
// // 删除条目和附件默认快捷键:Alt+I
// var key_del_item_att = getPref('key.del.item.att') == undefined ? 'I' : getPref('key.del.item.att');
// // 删除附件默认快捷键.Alt+A
// var key_del_att = getPref('key.del.att') == undefined ? 'A' : getPref('key.del.att');
// //仅删除快照默认快捷键 Alt+S
// var key_del_snap = getPref('key.del.snap') == undefined ? 'S' : getPref('key.del.snap');
// // 仅删除笔记默认快捷键.Alt+N
// var key_del_note = getPref('key.del.note') == undefined ? 'N' : getPref('key.del.note');
// // 仅删除其它默认快捷键.Alt+X
// var key_del_extra = getPref('key.del.extra') == undefined ? 'X' : getPref('key.del.extra');
// // 仅删除摘要默认快捷键.Alt+Z
// var key_del_abs = getPref('key.del.abs') == undefined ? 'Z' : getPref('key.del.abs');



// // 删除条目和附件快捷键:Alt+I
// ztoolkit.Shortcut.register("event", {
// id: `${config.addonRef}-key-del-item-att`,
// key: key_del_item_att as string,
// modifiers: "alt",
// callback: (keyOptions) => {
// HelperExampleFactory.delItemAtt();
// },
// });

// // 删除附件快捷键.Alt+A
// ztoolkit.Shortcut.register("event", {
// id: `${config.addonRef}-key-del-att`,
// key: key_del_att as string,
// modifiers: "alt",
// callback: (keyOptions) => {

// HelperExampleFactory.delAtt();
// },
// });

// //仅删除快照快捷键 Alt+S
// ztoolkit.Shortcut.register("event", {
// id: `${config.addonRef}-key-del-snap`,
// key: key_del_snap as string,
// modifiers: "alt",
// callback: (keyOptions) => {
// HelperExampleFactory.delSnap();
// },
// });

// //删除笔记快捷键Alt+N
// ztoolkit.Shortcut.register("event", {
// id: `${config.addonRef}-key-del-note`,
// key: key_del_note as string,
// modifiers: "alt",
// callback: (keyOptions) => {
// HelperExampleFactory.delNote();
// },
// });

// // 删除其它要快捷键 Alt+X
// ztoolkit.Shortcut.register("event", {
// id: `${config.addonRef}-key-del-extra`,
// key: key_del_extra as string,
// modifiers: "alt",
// callback: (keyOptions) => {
// HelperExampleFactory.delExtra();
// },
// });

// // 删除摘要快捷键Alt+Z
// ztoolkit.Shortcut.register("event", {
// id: `${config.addonRef}-key-del-abs`,
// key: key_del_abs as string,
// modifiers: "alt",
// callback: (keyOptions) => {
// HelperExampleFactory.delAbstract();
// },
// });

// //删除摘要快捷键Alt+Z
// // ztoolkit.Shortcut.register("event", {
// // id: `${config.addonRef}-key-del-abs`,
// // key: "U",
// // modifiers: "alt",
// // callback: (keyOptions) => {
// // // HelperExampleFactory.OSnow();
// // },
// // });
// }

}

Expand Down
64 changes: 64 additions & 0 deletions src/modules/shortcuts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { HelperExampleFactory } from "./examples";
import { getPref } from "../utils/prefs";
export function registerShortcuts() {
ztoolkit.Keyboard.register((ev, data) => {
// 删除条目和附件默认快捷键:Alt+I
var key_del_item_att = getPref('key.del.item.att') == undefined ? 'I' : getPref('key.del.item.att');
// 删除附件默认快捷键.Alt+A
var key_del_att = getPref('key.del.att') == undefined ? 'A' : getPref('key.del.att');
//仅删除快照默认快捷键 Alt+S
var key_del_snap = getPref('key.del.snap') == undefined ? 'S' : getPref('key.del.snap');
// 仅删除笔记默认快捷键.Alt+N
var key_del_note = getPref('key.del.note') == undefined ? 'N' : getPref('key.del.note');
// 仅删除其它默认快捷键.Alt+X
var key_del_extra = getPref('key.del.extra') == undefined ? 'X' : getPref('key.del.extra');
// 仅删除摘要默认快捷键.Alt+Z
var key_del_abs = getPref('key.del.abs') == undefined ? 'Z' : getPref('key.del.abs');

if (data.type === "keyup" && data.keyboard) {
// 删除条目和附件默认快捷键: Alt+I
if (data.keyboard.equals(`alt,${key_del_item_att}`)) {
HelperExampleFactory.delItemAtt();
//Zotero.debug("clt+K pressed")
}
// 删除附件默认快捷键.Alt+A
if (data.keyboard.equals(`alt,${key_del_att}`)) {
HelperExampleFactory.delAtt();
//Zotero.debug("clt+K pressed")
}
//仅删除快照默认快捷键 Alt+S
if (data.keyboard.equals(`alt,${key_del_snap}`)) {
HelperExampleFactory.delSnap();
//Zotero.debug("clt+K pressed")
}
// 仅删除笔记默认快捷键.Alt+N
if (data.keyboard.equals(`alt,${key_del_note}`)) {
HelperExampleFactory.delNote();
//Zotero.debug("clt+K pressed")
}
// 删除其它
if (data.keyboard.equals(`alt,${key_del_extra}`)) {
HelperExampleFactory.delExtra();
//Zotero.debug("clt+K pressed")
}
// 仅删除摘要默认快捷键.Alt+Z
if (data.keyboard.equals(`alt,${key_del_abs}`)) {
HelperExampleFactory.delAbstract();
//Zotero.debug("clt+K pressed")
}
}
});
// // if (data.type === "keydown") {
// // if (ev.key === "Alt") {
// // addon.data.translate.concatKey = true;
// // }
// // }
// // if (data.type === "keyup") {
// // if (ev.key === "Alt") {
// // addon.data.translate.concatKey = false;
// // }
// // }
// });


}
2 changes: 1 addition & 1 deletion update.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
},
{
"version": "0.3.0",
"version": "0.3.1",
"update_link": "https://github.com/redleafnew/delitemwithatt/releases/latest/download/delitemwithatt.xpi",
"applications": {
"zotero": {
Expand Down

0 comments on commit 27090f9

Please sign in to comment.