Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion lib/actions/fileAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,37 @@ export enum DefaultType {
HIDDEN = 'hidden',
}

export interface IHotkeyConfig {
/**
* Short, translated, description what this action is doing.
* This will be used as the description next to the hotkey in the shortcuts overview.
*/
description: string

/**
* The key to be pressed.
* @see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
*/
key: string

/**
* If set then the callback is only called when the shift key is (not) pressed.
* When left `undefined` a pressed shift key is ignored (callback is run with and without shift pressed).
*/
shift?: boolean

/**
* Only execute the action if the control key is pressed.
* On Mac devices the command key is used instead.
*/
ctrl?: true

/**
* Only execute the action if the alt key is pressed
*/
alt?: true
}

export interface FileActionData {
/** Unique ID */
id: string
Expand Down Expand Up @@ -41,7 +72,12 @@ export interface FileActionData {
execBatch?: (files: Node[], view: View, dir: string) => Promise<(boolean|null)[]>

/** This action order in the list */
order?: number,
order?: number

/**
* Allows to define a hotkey which will trigger this action for the selected node.
*/
hotkey?: IHotkeyConfig

/**
* Set to true if this action is a destructive action, like "delete".
Expand Down Expand Up @@ -113,6 +149,10 @@ export class FileAction {
return this._action.execBatch
}

get hotkey() {
return this._action.hotkey
}

get order() {
return this._action.order
}
Expand Down Expand Up @@ -190,6 +230,20 @@ export class FileAction {
if ('renderInline' in action && typeof action.renderInline !== 'function') {
throw new Error('Invalid renderInline function')
}

if ('hotkey' in action && action.hotkey !== undefined) {
if (typeof action.hotkey !== 'object') {
throw new Error('Invalid hotkey configuration')
}

if (typeof action.hotkey.key !== 'string' || !action.hotkey.key) {
throw new Error('Missing or invalid hotkey key')
}

if (typeof action.hotkey.description !== 'string' || !action.hotkey.description) {
throw new Error('Missing or invalid hotkey description')
}
}
}

}
Expand Down
2 changes: 1 addition & 1 deletion lib/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

export type { FileActionData } from './fileAction.ts'
export type { FileActionData, IHotkeyConfig } from './fileAction.ts'

export { FileAction, getFileActions, registerFileAction, DefaultType } from './fileAction.ts'
export { getFileListActions, registerFileListAction, FileListAction } from './fileListAction.ts'