diff --git a/__tests__/fileAction.spec.ts b/__tests__/fileAction.spec.ts
index 6052d3a1..f4329e7a 100644
--- a/__tests__/fileAction.spec.ts
+++ b/__tests__/fileAction.spec.ts
@@ -109,6 +109,17 @@ describe('Invalid FileAction creation', () => {
} as any as FileAction)
}).toThrowError('Invalid displayName function')
})
+ test('Invalid title', () => {
+ expect(() => {
+ new FileAction({
+ id: 'test',
+ displayName: () => 'Test',
+ title: 'Test',
+ iconSvgInline: () => '',
+ exec: async () => true,
+ } as any as FileAction)
+ }).toThrowError('Invalid title function')
+ })
test('Invalid iconSvgInline', () => {
expect(() => {
new FileAction({
@@ -203,6 +214,7 @@ describe('FileActions creation', () => {
const action = new FileAction({
id: 'test',
displayName: () => 'Test',
+ title: () => 'Test title',
iconSvgInline: () => '',
exec: async () => true,
execBatch: async () => [true],
@@ -219,6 +231,7 @@ describe('FileActions creation', () => {
expect(action.id).toBe('test')
expect(action.displayName([], {} as any)).toBe('Test')
+ expect(action.title?.([], {} as any)).toBe('Test title')
expect(action.iconSvgInline([], {} as any)).toBe('')
await expect(action.exec({} as any, {} as any, '/')).resolves.toBe(true)
await expect(action.execBatch?.([], {} as any, '/')).resolves.toStrictEqual([true])
diff --git a/lib/fileAction.ts b/lib/fileAction.ts
index 2cc64e7a..06716893 100644
--- a/lib/fileAction.ts
+++ b/lib/fileAction.ts
@@ -34,6 +34,8 @@ interface FileActionData {
id: string
/** Translatable string displayed in the menu */
displayName: (files: Node[], view: View) => string
+ /** Translatable title for of the action */
+ title?: (files: Node[], view: View) => string
/** Svg as inline string. */
iconSvgInline: (files: Node[], view: View) => string
/** Condition wether this action is shown or not */
@@ -93,6 +95,10 @@ export class FileAction {
return this._action.displayName
}
+ get title() {
+ return this._action.title
+ }
+
get iconSvgInline() {
return this._action.iconSvgInline
}
@@ -134,6 +140,10 @@ export class FileAction {
throw new Error('Invalid displayName function')
}
+ if ('title' in action && typeof action.title !== 'function') {
+ throw new Error('Invalid title function')
+ }
+
if (!action.iconSvgInline || typeof action.iconSvgInline !== 'function') {
throw new Error('Invalid iconSvgInline function')
}