Skip to content

Commit

Permalink
fixup! 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 4c9ce95 commit 0d8313d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion apps/files/src/actions/deleteAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ export const action = new FileAction({
let confirm = true

// Trick to detect if the action was called from a keyboard event
// we need to make sure the method calling have its named containing 'keydown'
// here we use `onKeydown` method from the FileEntryActions component
const callStack = new Error().stack || ''
const isCalledFromEventListener = callStack.toLocaleLowerCase().includes('keydown')

debugger
// If trashbin is disabled, we need to ask for confirmation
if (!isTrashbinEnabled() || isCalledFromEventListener) {
confirm = await askConfirmation([node], view)
Expand Down
4 changes: 3 additions & 1 deletion apps/files/src/actions/favoriteAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const shouldFavorite = (nodes: Node[]): boolean => {
return nodes.some(node => node.attributes.favorite !== 1)
}

export const ACTION_FAVORITE = 'favorite'

export const favoriteNode = async (node: Node, view: View, willFavorite: boolean): Promise<boolean> => {
try {
// TODO: migrate to webdav tags plugin
Expand Down Expand Up @@ -59,7 +61,7 @@ export const favoriteNode = async (node: Node, view: View, willFavorite: boolean
}

export const action = new FileAction({
id: 'favorite',
id: ACTION_FAVORITE,
displayName(nodes: Node[]) {
return shouldFavorite(nodes)
? t('files', 'Add to favorites')
Expand Down
8 changes: 8 additions & 0 deletions apps/files/src/components/FileEntry/FileEntryActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ 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'
import { ACTION_FAVORITE } from '../../actions/favoriteAction.ts'

export default defineComponent({
name: 'FileEntryActions',
Expand Down Expand Up @@ -379,6 +380,13 @@ export default defineComponent({
this.onActionClick(this.enabledFileActions.find(action => action.id === ACTION_DELETE)!)
}

// s toggle favorite
if (event.key === 's') {
event.preventDefault()
event.stopPropagation()
this.onActionClick(this.enabledFileActions.find(action => action.id === ACTION_FAVORITE)!)
}

},
},
})
Expand Down

0 comments on commit 0d8313d

Please sign in to comment.