@@ -13,6 +13,37 @@ export enum DefaultType {
1313 HIDDEN = 'hidden' ,
1414}
1515
16+ export interface IHotkeyConfig {
17+ /**
18+ * Short, translated, description what this action is doing.
19+ * This will be used as the description next to the hotkey in the shortcuts overview.
20+ */
21+ description : string
22+
23+ /**
24+ * The key to be pressed.
25+ * @see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
26+ */
27+ key : string
28+
29+ /**
30+ * If set then the callback is only called when the shift key is (not) pressed.
31+ * When left `undefined` a pressed shift key is ignored (callback is run with and without shift pressed).
32+ */
33+ shift ?: boolean
34+
35+ /**
36+ * Only execute the action if the control key is pressed.
37+ * On Mac devices the command key is used instead.
38+ */
39+ ctrl ?: true
40+
41+ /**
42+ * Only execute the action if the alt key is pressed
43+ */
44+ alt ?: true
45+ }
46+
1647export interface FileActionData {
1748 /** Unique ID */
1849 id : string
@@ -41,7 +72,12 @@ export interface FileActionData {
4172 execBatch ?: ( files : Node [ ] , view : View , dir : string ) => Promise < ( boolean | null ) [ ] >
4273
4374 /** This action order in the list */
44- order ?: number ,
75+ order ?: number
76+
77+ /**
78+ * Allows to define a hotkey which will trigger this action for the selected node.
79+ */
80+ hotkey ?: IHotkeyConfig
4581
4682 /**
4783 * Set to true if this action is a destructive action, like "delete".
@@ -113,6 +149,10 @@ export class FileAction {
113149 return this . _action . execBatch
114150 }
115151
152+ get hotkey ( ) {
153+ return this . _action . hotkey
154+ }
155+
116156 get order ( ) {
117157 return this . _action . order
118158 }
@@ -190,6 +230,20 @@ export class FileAction {
190230 if ( 'renderInline' in action && typeof action . renderInline !== 'function' ) {
191231 throw new Error ( 'Invalid renderInline function' )
192232 }
233+
234+ if ( 'hotkey' in action && action . hotkey !== undefined ) {
235+ if ( typeof action . hotkey !== 'object' ) {
236+ throw new Error ( 'Invalid hotkey configuration' )
237+ }
238+
239+ if ( typeof action . hotkey . key !== 'string' || ! action . hotkey . key ) {
240+ throw new Error ( 'Missing or invalid hotkey key' )
241+ }
242+
243+ if ( typeof action . hotkey . description !== 'string' || ! action . hotkey . description ) {
244+ throw new Error ( 'Missing or invalid hotkey description' )
245+ }
246+ }
193247 }
194248
195249}
0 commit comments