Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger default action when open file initial state is set #41648

Merged
merged 1 commit into from
Nov 22, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 23 additions & 2 deletions apps/files/src/components/FilesListVirtual.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ import type { PropType } from 'vue'
import type { UserConfig } from '../types.ts'
import { Fragment } from 'vue-frag'
import { getFileListHeaders, Folder, View, Permission } from '@nextcloud/files'
artonge marked this conversation as resolved.
Show resolved Hide resolved
import { getFileListHeaders, Folder, View, Permission, getFileActions } from '@nextcloud/files'
import { showError } from '@nextcloud/dialogs'
import { loadState } from '@nextcloud/initial-state'
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
import Vue from 'vue'
Expand Down Expand Up @@ -217,6 +218,8 @@ export default Vue.extend({
this.scrollToFile(this.fileId)
this.openSidebarForFile(this.fileId)
this.handleOpenFile()
artonge marked this conversation as resolved.
Show resolved Hide resolved
},
methods: {
Expand All @@ -234,7 +237,7 @@ export default Vue.extend({
}
},
scrollToFile(fileId: number, warn = true) {
scrollToFile(fileId: number|null, warn = true) {
if (fileId) {
const index = this.nodes.findIndex(node => node.fileid === fileId)
if (warn && index === -1 && fileId !== this.currentFolder.fileid) {
Expand All @@ -244,6 +247,24 @@ export default Vue.extend({
}
},
handleOpenFile() {
const openFileInfo = loadState('files', 'openFileInfo', {}) as ({ id?: number })
if (openFileInfo === undefined) {
return
}
const node = this.nodes.find(n => n.fileid === openFileInfo.id) as NcNode
if (node === undefined) {
return
}
logger.debug('Opening file ' + node.path, { node })
getFileActions()
.filter(action => !action.enabled || action.enabled([node], this.currentView))
.sort((a, b) => (a.order || 0) - (b.order || 0))
.filter(action => !!action?.default)[0].exec(node, this.currentView, this.currentFolder.path)
},
getFileId(node) {
return node.fileid
},
Expand Down
4 changes: 2 additions & 2 deletions dist/files-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-main.js.map

Large diffs are not rendered by default.