add: open attachment to magic key command
This commit is contained in:
parent
354430200d
commit
1591c0f2a0
|
|
@ -28,6 +28,10 @@ const editorStrings = {
|
|||
"en-US": "Insert Citation",
|
||||
"zh-CN": "插入引用",
|
||||
},
|
||||
openAttachment: {
|
||||
"en-US": "Open attachment of parent item",
|
||||
"zh-CN": "打开父条目的附件",
|
||||
},
|
||||
copySectionLink: {
|
||||
"en-US": "Copy Section Link",
|
||||
"zh-CN": "复制章节链接",
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ interface MagicKeyOptions {
|
|||
insertTemplate?: () => void;
|
||||
insertLink?: (type: "inbound" | "outbound") => void;
|
||||
copyLink?: (mode: "section" | "line") => void;
|
||||
openAttachment?: () => void;
|
||||
canOpenAttachment?: () => boolean;
|
||||
enable?: boolean;
|
||||
}
|
||||
|
||||
|
|
@ -21,6 +23,7 @@ interface MagicCommand {
|
|||
title?: string;
|
||||
icon?: string;
|
||||
command: (state: EditorState) => void | Transaction;
|
||||
enabled?: (state: EditorState) => boolean;
|
||||
}
|
||||
|
||||
class PluginState {
|
||||
|
|
@ -28,7 +31,7 @@ class PluginState {
|
|||
|
||||
options: MagicKeyOptions;
|
||||
|
||||
commands: MagicCommand[] = [
|
||||
_commands: MagicCommand[] = [
|
||||
{
|
||||
messageId: "insertTemplate",
|
||||
command: (state) => {
|
||||
|
|
@ -53,6 +56,15 @@ class PluginState {
|
|||
getPlugin("citation")?.insertCitation();
|
||||
},
|
||||
},
|
||||
{
|
||||
messageId: "openAttachment",
|
||||
command: (state) => {
|
||||
this.options.openAttachment?.();
|
||||
},
|
||||
enabled: (state) => {
|
||||
return this.options.canOpenAttachment?.() || false;
|
||||
},
|
||||
},
|
||||
{
|
||||
messageId: "copySectionLink",
|
||||
command: (state) => {
|
||||
|
|
@ -166,6 +178,15 @@ class PluginState {
|
|||
},
|
||||
];
|
||||
|
||||
get commands() {
|
||||
return this._commands.filter((command) => {
|
||||
if (command.enabled) {
|
||||
return command.enabled(this.state);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
popup: Popup | null = null;
|
||||
|
||||
selectedCommandIndex = 0;
|
||||
|
|
|
|||
|
|
@ -530,6 +530,26 @@ function initEditorPlugins(editor: Zotero.EditorInstance) {
|
|||
copyLink: (mode: "section" | "line") => {
|
||||
copyNoteLink(editor, mode);
|
||||
},
|
||||
openAttachment: () => {
|
||||
editor._item.parentItem
|
||||
?.getBestAttachment()
|
||||
.then((attachment) => {
|
||||
if (!attachment) {
|
||||
return;
|
||||
}
|
||||
Zotero.getActiveZoteroPane().viewAttachment([attachment.id]);
|
||||
Zotero.Notifier.trigger("open", "file", attachment.id);
|
||||
});
|
||||
},
|
||||
canOpenAttachment: () => {
|
||||
const parentItem = editor._item.parentItem;
|
||||
if (!parentItem) {
|
||||
return false;
|
||||
}
|
||||
return (
|
||||
(editor._item.parentItem as Zotero.Item).numAttachments() > 0
|
||||
);
|
||||
},
|
||||
enable: getPref("editor.useMagicKey") as boolean,
|
||||
},
|
||||
markdownPaste: {
|
||||
|
|
|
|||
Loading…
Reference in New Issue