Skip to content

Commit

Permalink
feat(files): add file check keyboard shortcut
Browse files Browse the repository at this point in the history
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Nov 29, 2024
1 parent 884e18f commit 4c1d47d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
11 changes: 5 additions & 6 deletions apps/files/src/components/FileEntry/FileEntryActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ 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'
import { useActiveStore } from '../../store/active.ts'

export default defineComponent({
name: 'FileEntryActions',
Expand Down Expand Up @@ -138,16 +139,14 @@ export default defineComponent({
setup() {
// The file list is guaranteed to be only shown with active view - thus we can set the `loaded` flag
const { currentView } = useNavigation(true)
const {
directory: currentDir,
fileId: currentFileId,
} = useRouteParameters()
const { directory: currentDir } = useRouteParameters()

const activeStore = useActiveStore()
const filesListWidth = useFileListWidth()
const enabledFileActions = inject<FileAction[]>('enabledFileActions', [])
return {
activeStore,
currentDir,
currentFileId,
currentView,
enabledFileActions,
filesListWidth,
Expand All @@ -163,7 +162,7 @@ export default defineComponent({

computed: {
isActive() {
return String(this.source.fileid) === String(this.currentFileId)
return this.activeStore.active?.source === this.source.source
},

isLoading() {
Expand Down
33 changes: 32 additions & 1 deletion apps/files/src/components/FileEntry/FileEntryCheckbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import { defineComponent } from 'vue'
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js'

import { isDialogOpened } from '../../utils/dialogUtils.ts'
import { useActiveStore } from '../../store/active.ts'
import { useKeyboardStore } from '../../store/keyboard.ts'
import { useSelectionStore } from '../../store/selection.ts'
import logger from '../../logger.ts'
Expand Down Expand Up @@ -60,13 +62,21 @@ export default defineComponent({
setup() {
const selectionStore = useSelectionStore()
const keyboardStore = useKeyboardStore()
const activeStore = useActiveStore()

return {
activeStore,
keyboardStore,
selectionStore,
t,
}
},

computed: {
isActive() {
return this.activeStore.active?.source === this.source.source
},

selectedFiles() {
return this.selectionStore.selected
},
Expand All @@ -91,6 +101,14 @@ export default defineComponent({
},
},

beforeMount() {
document.addEventListener('keydown', this.onKeyDown)
},

beforeDestroy() {
document.removeEventListener('keydown', this.onKeyDown)
},

methods: {
onSelectionChange(selected: boolean) {
const newSelectedIndex = this.index
Expand Down Expand Up @@ -132,7 +150,20 @@ export default defineComponent({
this.selectionStore.reset()
},

t,
onKeyDown(event: KeyboardEvent) {
// Don't react to the event if a dialog is open or the nde is not active
if (isDialogOpened() || !this.isActive) {
return
}

// ctrl+space toggle selection
if (event.key === ' ' && event.ctrlKey) {
event.preventDefault()
event.stopPropagation()
logger.debug('Toggling selection for file', { source: this.source })
this.onSelectionChange(!this.isSelected)
}
},
},
})
</script>

0 comments on commit 4c1d47d

Please sign in to comment.