plugins: add properties in file menu
Massimo Melina committed
Apr 3, 2023 at 11:33 UTC
1192bd0158cd32f17d2384c421199033e8b88e96
6 files changed
+15
-6
dev-plugins.md
+2
-1
@@ -192,7 +192,7 @@ This is a list of available frontend-events, with respective object parameter an
192
- output `Html`
193
- `fileMenu`
194
- add your entries to the menu.
195
- - parameter `{ entry: Entry }`
195
+ - parameter `{ entry: Entry, menu: FileMenuEntry[], props: FileMenuProp[] }`
196
- output `FileMenuEntry | FileMenuEntry[]`
197
```typescript
198
interface FileMenuEntry {
@@ -202,6 +202,7 @@ This is a list of available frontend-events, with respective object parameter an
202
onClick?: () => (Promisable<boolean>) // return false to not close menu dialog
203
//...rest is transfered to <a> element, for example 'target', or 'title'
204
}
205
+ type FileMenuProp = [ReactNode,ReactNode] | ReactElement
206
```
207
## Publish your plug-in
208
frontend/src/BrowseFiles.ts
+9
-2
@@ -4,6 +4,7 @@ import { Link } from 'react-router-dom'
4
import {
5
createElement as h,
6
Fragment,
7
+ isValidElement,
8
memo,
9
useCallback,
10
useEffect,
@@ -224,7 +225,10 @@ const Entry = memo((entry: DirEntry & { midnight: Date, separator?: string }) =>
225
{ label: t`Download`, href: uri + '?dl', icon: 'download' },
226
can_delete && { label: t`Delete`, icon: 'trash', onClick: () => deleteFiles([uri], base) }
227
]
227
- const res = hfsEvent('fileMenu', { entry })
228
+ const props = [
229
+ [t(`Name`), name]
230
+ ]
231
+ const res = hfsEvent('fileMenu', { entry, menu, props })
232
if (res)
233
menu.push(...res.flat())
234
const close = newDialog({
@@ -237,7 +241,10 @@ const Entry = memo((entry: DirEntry & { midnight: Date, separator?: string }) =>
241
const {t} = useI18N()
242
return h(Fragment, {},
243
h('dl', { className: 'file-dialog-properties' },
240
- h('dt', {}, t`Name:`), h('dd', {}, name),
244
+ props.map(prop => isValidElement(prop) ? prop
245
+ : Array.isArray(prop) ? h(Fragment, {}, h('dt', {}, prop[0]), h('dd', {}, prop[1]))
246
+ : null
247
+ )
248
),
249
entry.p && h(Fragment, {}, hIcon('password', { style: { marginRight: '.5em' } }), t(MISSING_PERM)),
250
h('div', { className: 'file-menu' },
frontend/src/index.scss
+1
@@ -388,6 +388,7 @@ button label {
388
.file-dialog-properties {
389
word-break: break-word;
390
line-height: 1.5em;
391
+ & dt { font-weight: bold; }
392
& dd { margin-left: 1.5em; }
393
}
394
.file-menu {
langs/hfs-lang-en.json
+1
-1
@@ -105,7 +105,7 @@
105
"download counter": "download counter",
106
107
"File menu": "File menu",
108
- "Name:": "Name:",
108
+ "Name": "Name",
109
"file_open": "Open",
110
"Download": "Download",
111
"Missing permission": "Missing permission"
langs/hfs-lang-it.json
+1
-1
@@ -99,7 +99,7 @@
99
"download counter": "download conteggiati",
100
101
"File menu": "Menu file",
102
- "Name:": "Nome:",
102
+ "Name": "Nome",
103
"file_open": "Apri",
104
"Download": "Download",
105
"Missing permission": "Permesso mancante"
langs/hfs-lang-ru.json
+1
-1
@@ -104,7 +104,7 @@
104
105
"download counter": "Количество скачиваний",
106
"File menu": "Меню файла",
107
- "Name: {name}": "Имя: {name}",
107
+ "Name": "Имя",
108
"file_open": "Открыть",
109
"Download": "Скачать",
110
"Missing permission": "Отсутствует доступ"