Skip to content

Commit

Permalink
feat: duplicate file or directory
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
  • Loading branch information
pedrolamas committed May 7, 2023
1 parent d14fa81 commit 1cf08c1
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/components/widgets/filesystem/FileSystem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
@view="handleFileOpenDialog"
@edit="handleFileOpenDialog"
@rename="handleRenameDialog"
@duplicate="handleDuplicateDialog"
@remove="handleRemove"
@download="handleDownload"
@preheat="handlePreheat"
Expand Down Expand Up @@ -577,8 +578,8 @@ export default class FileSystem extends Mixins(StateMixin, FilesMixin, ServicesM
if (this.disabled) return
const [title, label] = item.type === 'file'
? [this.$t('app.file_system.title.rename_dir'), this.$t('app.file_system.label.dir_name')]
: [this.$t('app.file_system.title.rename_file'), this.$t('app.file_system.label.file_name')]
? [this.$t('app.file_system.title.rename_file'), this.$t('app.file_system.label.file_name')]
: [this.$t('app.file_system.title.rename_dir'), this.$t('app.file_system.label.dir_name')]
this.fileNameDialogState = {
open: true,
Expand All @@ -589,6 +590,22 @@ export default class FileSystem extends Mixins(StateMixin, FilesMixin, ServicesM
}
}
handleDuplicateDialog (item: FileBrowserEntry) {
if (this.disabled) return
const [title, label] = item.type === 'file'
? [this.$t('app.file_system.title.duplicate_file'), this.$t('app.file_system.label.file_name')]
: [this.$t('app.file_system.title.duplicate_dir'), this.$t('app.file_system.label.dir_name')]
this.fileNameDialogState = {
open: true,
title,
label,
value: item.name,
handler: this.handleDuplicate
}
}
handleAddFileDialog () {
if (this.disabled) return
this.fileNameDialogState = {
Expand Down Expand Up @@ -785,6 +802,12 @@ export default class FileSystem extends Mixins(StateMixin, FilesMixin, ServicesM
SocketActions.serverFilesMove(src, dest)
}
handleDuplicate (name: string) {
const src = `${this.currentPath}/${this.fileNameDialogState.value}`
const dest = `${this.currentPath}/${name}`
SocketActions.serverFilesCopy(src, dest)
}
async handleRemove (file: FileBrowserEntry | FileBrowserEntry[]) {
if (this.disabled) return
Expand Down
13 changes: 13 additions & 0 deletions src/components/widgets/filesystem/FileSystemContextMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,19 @@
</v-list-item-content>
</v-list-item>

<v-list-item
v-if="!Array.isArray(file) && !rootProperties.readonly"
link
@click="$emit('duplicate', file)"
>
<v-list-item-icon>
<v-icon>$duplicate</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>{{ $t('app.general.btn.duplicate') }}</v-list-item-title>
</v-list-item-content>
</v-list-item>

<v-list-item
v-if="!rootProperties.readonly || rootProperties.canDelete"
@click="$emit('remove', file)"
Expand Down
1 change: 1 addition & 0 deletions src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ export const Icons = Object.freeze({
printer: mdiPrinter,
download: mdiDownload,
rename: mdiFormTextbox,
duplicate: mdiContentCopy,
delete: mdiDelete,
camera: mdiCamera,
fan: mdiFan,
Expand Down
3 changes: 3 additions & 0 deletions src/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ app:
add_file: Add File
command_palette: Command Palette
download_file: Retrieving file
duplicate_dir: Duplicate Directory
duplicate_file: Duplicate File
go_to_file: Go to file
rename_dir: Rename Directory
rename_file: Rename File
Expand Down Expand Up @@ -152,6 +154,7 @@ app:
create_zip_archive: Create ZIP Archive
delete: Delete
download: Download
duplicate: Duplicate
edit: Edit
exit_layout: Exit layout mode
extrude: Extrude
Expand Down

0 comments on commit 1cf08c1

Please sign in to comment.