summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@protonmail.com>2023-05-24 17:20:35 +0200
committernextcloud-command <nextcloud-command@users.noreply.github.com>2023-05-25 06:32:34 +0000
commitadcd4efbcc7b7544d9e54a3316635d06844aa921 (patch)
tree4b2f2e5e11239bc25b00e93b79e8737a922de0e4 /apps
parent16a1ec629fc816e37ff6e19f0b3c72fb8658dd5f (diff)
downloadnextcloud-server-adcd4efbcc7b7544d9e54a3316635d06844aa921.tar.gz
nextcloud-server-adcd4efbcc7b7544d9e54a3316635d06844aa921.zip
fix(files): make open folder a default action
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com> Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
Diffstat (limited to 'apps')
-rw-r--r--apps/files/src/actions/openFolderAction.ts69
-rw-r--r--apps/files/src/components/FileEntry.vue33
-rw-r--r--apps/files/src/main.ts1
3 files changed, 87 insertions, 16 deletions
diff --git a/apps/files/src/actions/openFolderAction.ts b/apps/files/src/actions/openFolderAction.ts
new file mode 100644
index 00000000000..cc2c0825bd4
--- /dev/null
+++ b/apps/files/src/actions/openFolderAction.ts
@@ -0,0 +1,69 @@
+/**
+ * @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @license AGPL-3.0-or-later
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+import { Permission, Node, FileType } from '@nextcloud/files'
+import { translate as t } from '@nextcloud/l10n'
+import Folder from '@mdi/svg/svg/folder.svg?raw'
+
+import type { Navigation } from '../services/Navigation'
+import { join } from 'path'
+import { registerFileAction, FileAction } from '../services/FileAction'
+
+registerFileAction(new FileAction({
+ id: 'open-folder',
+ displayName(files: Node[]) {
+ // Only works on single node
+ const displayName = files[0].attributes.displayName || files[0].basename
+ return t('files', 'Open folder {displayName}', { displayName })
+ },
+ iconSvgInline: () => Folder,
+
+ enabled(nodes: Node[]) {
+ // Only works on single node
+ if (nodes.length !== 1) {
+ return false
+ }
+
+ const node = nodes[0]
+ return node.type === FileType.Folder
+ && (node.permissions & Permission.READ) !== 0
+ },
+
+ async exec(node: Node, view: Navigation, dir: string) {
+ if (!node || node.type !== FileType.Folder) {
+ return false
+ }
+
+ window.OCP.Files.Router.goToRoute(
+ null,
+ null,
+ { dir: join(dir, node.basename) },
+ )
+ return null
+ },
+ async execBatch(nodes: Node[], view: Navigation, dir: string) {
+ return Promise.all(nodes.map(node => this.exec(node, view, dir)))
+ },
+
+ // Main action if enabled, meaning folders only
+ order: -100,
+ default: true,
+}))
diff --git a/apps/files/src/components/FileEntry.vue b/apps/files/src/components/FileEntry.vue
index 8dc067a407d..fd61f5e3623 100644
--- a/apps/files/src/components/FileEntry.vue
+++ b/apps/files/src/components/FileEntry.vue
@@ -33,7 +33,7 @@
<!-- Link to file -->
<td class="files-list__row-name">
- <a ref="name" v-bind="linkTo" @click="execDefaultAction">
+ <a ref="name" v-bind="linkAttrs" @click="execDefaultAction">
<!-- Icon or preview -->
<span class="files-list__row-icon">
<FolderIcon v-if="source.type === 'folder'" />
@@ -261,7 +261,22 @@ export default Vue.extend({
return minOpacity + (1 - minOpacity) * Math.pow((this.source.size / maxOpacitySize), 2)
},
- linkTo() {
+ linkAttrs() {
+ if (this.enabledDefaultActions.length > 0) {
+ const action = this.enabledDefaultActions[0]
+ const displayName = action.displayName([this.source], this.currentView)
+ return {
+ class: ['files-list__row-default-action', 'files-list__row-action-' + action.id],
+ role: 'button',
+ title: displayName,
+ }
+ }
+
+ /**
+ * A folder would never reach this point
+ * as it has open-folder as default action.
+ * Just to be safe, let's handle it.
+ */
if (this.source.type === 'folder') {
const to = { ...this.$route, query: { dir: join(this.dir, this.source.basename) } }
return {
@@ -271,15 +286,6 @@ export default Vue.extend({
}
}
- if (this.enabledDefaultActions.length > 0) {
- const action = this.enabledDefaultActions[0]
- const displayName = action.displayName([this.source], this.currentView)
- return {
- title: displayName,
- role: 'button',
- }
- }
-
return {
href: this.source.source,
// TODO: Use first action title ?
@@ -526,11 +532,6 @@ export default Vue.extend({
}
},
execDefaultAction(event) {
- // Do not execute the default action on the folder, navigate instead
- if (this.source.type === 'folder') {
- return
- }
-
if (this.enabledDefaultActions.length > 0) {
event.preventDefault()
event.stopPropagation()
diff --git a/apps/files/src/main.ts b/apps/files/src/main.ts
index 195357d0e0a..1d96c2f6eaa 100644
--- a/apps/files/src/main.ts
+++ b/apps/files/src/main.ts
@@ -1,6 +1,7 @@
import './templates.js'
import './legacy/filelistSearch.js'
import './actions/deleteAction'
+import './actions/openFolderAction'
import './actions/sidebarAction'
import Vue from 'vue'