Skip to content

Commit

Permalink
feat(files): add delete, rename and sidebar keyboard shortcut
Browse files Browse the repository at this point in the history
Signed-off-by: skjnldsv <[email protected]>
  • Loading branch information
skjnldsv committed Nov 27, 2024
1 parent 80b76dc commit e38303a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
11 changes: 9 additions & 2 deletions apps/files/src/actions/deleteAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import { askConfirmation, canDisconnectOnly, canUnshareOnly, deleteNode, display

const queue = new PQueue({ concurrency: 5 })

export const ACTION_DELETE = 'delete'

export const action = new FileAction({
id: 'delete',
id: ACTION_DELETE,
displayName,
iconSvgInline: (nodes: Node[]) => {
if (canUnshareOnly(nodes)) {
Expand All @@ -41,8 +43,13 @@ export const action = new FileAction({
try {
let confirm = true

// Trick to detect if the action was called from a keyboard event
const callStack = new Error().stack || ''
const isCalledFromEventListener = callStack.toLocaleLowerCase().includes('keydown')

debugger
// If trashbin is disabled, we need to ask for confirmation
if (!isTrashbinEnabled()) {
if (!isTrashbinEnabled() || isCalledFromEventListener) {
confirm = await askConfirmation([node], view)
}

Expand Down
4 changes: 2 additions & 2 deletions apps/files/src/actions/renameAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { Permission, type Node, FileAction, View } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import PencilSvg from '@mdi/svg/svg/pencil.svg?raw'

export const ACTION_DETAILS = 'details'
export const ACTION_RENAME = 'rename'

export const action = new FileAction({
id: 'rename',
id: ACTION_RENAME,
displayName: () => t('files', 'Rename'),
iconSvgInline: () => PencilSvg,

Expand Down
5 changes: 5 additions & 0 deletions apps/files/src/actions/sidebarAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export const action = new FileAction({

async exec(node: Node, view: View, dir: string) {
try {
// If the sidebar is already open for the current file, do nothing
if (window.OCA.Files.Sidebar.file === node.path) {
logger.debug('Sidebar already open for this file', { node })
return null
}
// Open sidebar and set active tab to sharing by default
window.OCA.Files.Sidebar.setActiveTab('sharing')

Expand Down
25 changes: 25 additions & 0 deletions apps/files/src/components/FileEntry/FileEntryActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ import { useFileListWidth } from '../../composables/useFileListWidth.ts'
import { useNavigation } from '../../composables/useNavigation'
import { useRouteParameters } from '../../composables/useRouteParameters.ts'
import logger from '../../logger.ts'
import { ACTION_DETAILS } from '../../actions/sidebarAction.ts'
import { ACTION_RENAME } from '../../actions/renameAction.ts'
import { ACTION_DELETE } from '../../actions/deleteAction.ts'

export default defineComponent({
name: 'FileEntryActions',
Expand Down Expand Up @@ -354,6 +357,28 @@ export default defineComponent({
event.stopPropagation()
this.openedMenu = true
}

// d opens the sidebar
if (event.key === 'd') {
event.preventDefault()
event.stopPropagation()
this.onActionClick(this.enabledFileActions.find(action => action.id === ACTION_DETAILS)!)
}

// F2 renames the file
if (event.key === 'F2') {
event.preventDefault()
event.stopPropagation()
this.onActionClick(this.enabledFileActions.find(action => action.id === ACTION_RENAME)!)
}

// Delete key deletes the file with confirmation
if (event.key === 'Delete') {
event.preventDefault()
event.stopPropagation()
this.onActionClick(this.enabledFileActions.find(action => action.id === ACTION_DELETE)!)
}

},
},
})
Expand Down

0 comments on commit e38303a

Please sign in to comment.