You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

viewInFolderAction.ts 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com>
  3. *
  4. * @author John Molakvoæ <skjnldsv@protonmail.com>
  5. *
  6. * @license AGPL-3.0-or-later
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. import { Node, FileType, Permission, View, registerFileAction, FileAction } from '@nextcloud/files'
  23. import { translate as t } from '@nextcloud/l10n'
  24. import FolderMoveSvg from '@mdi/svg/svg/folder-move.svg?raw'
  25. export const action = new FileAction({
  26. id: 'view-in-folder',
  27. displayName() {
  28. return t('files', 'View in folder')
  29. },
  30. iconSvgInline: () => FolderMoveSvg,
  31. enabled(nodes: Node[]) {
  32. // Only works on single node
  33. if (nodes.length !== 1) {
  34. return false
  35. }
  36. const node = nodes[0]
  37. if (!node.isDavRessource) {
  38. return false
  39. }
  40. if (node.permissions === Permission.NONE) {
  41. return false
  42. }
  43. return node.type === FileType.File
  44. },
  45. async exec(node: Node, view: View, dir: string) {
  46. if (!node || node.type !== FileType.File) {
  47. return false
  48. }
  49. window.OCP.Files.Router.goToRoute(
  50. null,
  51. { view: 'files', fileid: node.fileid },
  52. { dir: node.dirname },
  53. )
  54. return null
  55. },
  56. order: 80,
  57. })
  58. registerFileAction(action)