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

feat: add function to duplicate gcode files #1321

Merged
merged 2 commits into from
May 6, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions src/components/panels/GcodefilesPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@
<v-icon class="mr-1">{{ mdiRenameBox }}</v-icon>
{{ $t('Files.Rename') }}
</v-list-item>
<v-list-item v-if="!contextMenu.item.isDirectory" @click="duplicateFile(contextMenu.item)">
<v-icon class="mr-1">{{ mdiContentCopy }}</v-icon>
{{ $t('Files.Duplicate') }}
</v-list-item>
<v-list-item v-if="!contextMenu.item.isDirectory" class="red--text" @click="removeFile">
<v-icon class="mr-1" color="error">{{ mdiDelete }}</v-icon>
{{ $t('Files.Delete') }}
Expand Down Expand Up @@ -432,6 +436,35 @@
</v-card-actions>
</panel>
</v-dialog>
<v-dialog v-model="dialogDuplicateFile.show" :max-width="400">
<panel
:title="$t('Files.DuplicateFile').toString()"
card-class="gcode-files-duplicate-file-dialog"
:margin-bottom="false">
<template #buttons>
<v-btn icon tile @click="dialogDuplicateFile.show = false">
<v-icon>{{ mdiCloseThick }}</v-icon>
</v-btn>
</template>
<v-card-text>
<v-text-field
ref="inputFieldDuplicateFile"
v-model="dialogDuplicateFile.newName"
:label="$t('Files.Name').toString()"
required
:rules="nameInputRules"
@update:error="(bool) => (isInvalidName = bool)"
@keyup.enter="duplicateFileAction"></v-text-field>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="" text @click="dialogDuplicateFile.show = false">{{ $t('Files.Cancel') }}</v-btn>
<v-btn :disabled="isInvalidName" color="primary" text @click="duplicateFileAction">
{{ $t('Files.Duplicate') }}
</v-btn>
</v-card-actions>
</panel>
</v-dialog>
<v-dialog v-model="dialogRenameDirectory.show" max-width="400">
<panel
:title="$t('Files.RenameDirectory').toString()"
Expand Down Expand Up @@ -586,6 +619,7 @@ import {
mdiUpload,
mdiVideo3d,
mdiFileDocumentEditOutline,
mdiContentCopy,
} from '@mdi/js'
import StartPrintDialog from '@/components/dialogs/StartPrintDialog.vue'
import ControlMixin from '@/components/mixins/control'
Expand Down Expand Up @@ -636,6 +670,7 @@ interface tableColumnSetting {
export default class GcodefilesPanel extends Mixins(BaseMixin, ControlMixin) {
mdiChevronDown = mdiChevronDown
mdiChevronUp = mdiChevronUp
mdiContentCopy = mdiContentCopy
mdiFile = mdiFile
mdiFileDocumentMultipleOutline = mdiFileDocumentMultipleOutline
mdiMagnify = mdiMagnify
Expand Down Expand Up @@ -665,6 +700,7 @@ export default class GcodefilesPanel extends Mixins(BaseMixin, ControlMixin) {
declare $refs: {
fileUpload: HTMLInputElement
inputFieldRenameFile: HTMLInputElement
inputFieldDuplicateFile: HTMLInputElement
inputFieldCreateDirectory: HTMLInputElement
inputFieldRenameDirectory: HTMLInputElement
}
Expand Down Expand Up @@ -722,6 +758,12 @@ export default class GcodefilesPanel extends Mixins(BaseMixin, ControlMixin) {
item: { ...this.contextMenu.item },
}

private dialogDuplicateFile: dialogRenameObject = {
show: false,
newName: '',
item: { ...this.contextMenu.item },
}

private dialogRenameDirectory: dialogRenameObject = {
show: false,
newName: '',
Expand Down Expand Up @@ -1284,6 +1326,24 @@ export default class GcodefilesPanel extends Mixins(BaseMixin, ControlMixin) {
)
}

duplicateFile(item: FileStateGcodefile) {
this.dialogDuplicateFile.item = item
this.dialogDuplicateFile.newName = item.filename
this.dialogDuplicateFile.show = true

setTimeout(() => {
this.$refs.inputFieldDuplicateFile?.focus()
}, 200)
}

duplicateFileAction() {
this.dialogDuplicateFile.show = false
this.$socket.emit('server.files.copy', {
source: 'gcodes' + this.currentPath + '/' + this.dialogDuplicateFile.item.filename,
dest: 'gcodes' + this.currentPath + '/' + this.dialogDuplicateFile.newName,
})
}

renameDirectory(item: FileStateGcodefile) {
this.dialogRenameDirectory.item = item
this.dialogRenameDirectory.newName = item.filename
Expand Down
66 changes: 66 additions & 0 deletions src/components/panels/Machine/ConfigFilesPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@
<v-icon class="mr-1">{{ mdiRenameBox }}</v-icon>
{{ $t('Machine.ConfigFilesPanel.Rename') }}
</v-list-item>
<v-list-item v-if="!contextMenu.item.isDirectory" @click="duplicateFile(contextMenu.item)">
<v-icon class="mr-1">{{ mdiContentCopy }}</v-icon>
{{ $t('Machine.ConfigFilesPanel.Duplicate') }}
</v-list-item>
<v-list-item
v-if="contextMenu.item.isDirectory && contextMenu.item.permissions.includes('w')"
@click="renameDirectory(contextMenu.item)">
Expand Down Expand Up @@ -323,6 +327,37 @@
</v-card-actions>
</panel>
</v-dialog>
<v-dialog v-model="dialogDuplicateFile.show" max-width="400">
<panel
:title="$t('Machine.ConfigFilesPanel.DuplicateFile').toString()"
card-class="maschine-configfiles-duplicate-file-dialog"
:margin-bottom="false">
<template #buttons>
<v-btn icon tile @click="dialogDuplicateFile.show = false">
<v-icon>{{ mdiCloseThick }}</v-icon>
</v-btn>
</template>
<v-card-text>
<v-text-field
ref="inputDialoDuplicateFileName"
v-model="dialogDuplicateFile.newName"
:label="$t('Machine.ConfigFilesPanel.Name')"
required
:rules="nameInputRules"
@update:error="(bool) => (isInvalidName = bool)"
@keyup.enter="duplicateFileAction" />
</v-card-text>
<v-card-actions>
<v-spacer />
<v-btn color="" text @click="dialogDuplicateFile.show = false">
{{ $t('Machine.ConfigFilesPanel.Cancel') }}
</v-btn>
<v-btn :disabled="isInvalidName" color="primary" text @click="duplicateFileAction">
{{ $t('Machine.ConfigFilesPanel.Duplicate') }}
</v-btn>
</v-card-actions>
</panel>
</v-dialog>
<v-dialog v-model="dialogCreateDirectory.show" max-width="400">
<panel
:title="$t('Machine.ConfigFilesPanel.CreateDirectory').toString()"
Expand Down Expand Up @@ -484,6 +519,7 @@ import {
mdiDelete,
mdiCloseThick,
mdiLockOutline,
mdiContentCopy,
} from '@mdi/js'

interface contextMenu {
Expand Down Expand Up @@ -550,6 +586,7 @@ export default class ConfigFilesPanel extends Mixins(BaseMixin) {
mdiDelete = mdiDelete
mdiCloseThick = mdiCloseThick
mdiLockOutline = mdiLockOutline
mdiContentCopy = mdiContentCopy

sortFiles = sortFiles
formatFilesize = formatFilesize
Expand All @@ -558,6 +595,7 @@ export default class ConfigFilesPanel extends Mixins(BaseMixin) {
fileUpload: HTMLInputElement
inputDialogCreateFileName: HTMLInputElement
inputDialogRenameFileName: HTMLInputElement
inputDialogDuplicateFileName: HTMLInputElement
inputDialogCreateDirectoryName: HTMLInputElement
inputDialogRenameDirectoryName: HTMLInputElement
}
Expand Down Expand Up @@ -598,6 +636,16 @@ export default class ConfigFilesPanel extends Mixins(BaseMixin) {
modified: new Date(),
},
}
private dialogDuplicateFile: dialogRenameObject = {
show: false,
newName: '',
item: {
isDirectory: false,
filename: '',
permissions: '',
modified: new Date(),
},
}
private dialogCreateDirectory = {
show: false,
name: '',
Expand Down Expand Up @@ -1086,6 +1134,24 @@ export default class ConfigFilesPanel extends Mixins(BaseMixin) {
)
}

duplicateFile(item: FileStateFile) {
this.dialogDuplicateFile.item = item
this.dialogDuplicateFile.newName = item.filename
this.dialogDuplicateFile.show = true

setTimeout(() => {
this.$refs.inputDialogDuplicateFileName?.focus()
}, 200)
}

duplicateFileAction() {
this.dialogDuplicateFile.show = false
this.$socket.emit('server.files.copy', {
source: (this.absolutePath + '/' + this.dialogDuplicateFile.item.filename).slice(1),
dest: (this.absolutePath + '/' + this.dialogDuplicateFile.newName).slice(1),
})
}

removeFile() {
this.$socket.emit(
'server.files.delete_file',
Expand Down
4 changes: 4 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@
"DeleteDirectoryQuestion": "Do you really want to delete the \"{name}\" directory with all its contents?",
"DeleteSelectedQuestion": "Do you really want to delete {count} selected files?",
"Download": "Download",
"Duplicate": "Duplicate",
"DuplicateFile": "Duplicate File",
"EditFile": "Edit File",
"Empty": "Empty",
"ExtruderTemp": "Extruder Temp.",
Expand Down Expand Up @@ -399,6 +401,8 @@
"DeleteDirectoryQuestion": "Delete directory \"{name}\" and all its contents?",
"DeleteSelectedQuestion": "Delete {count} selected elements?",
"Download": "Download",
"Duplicate": "Duplicate",
"DuplicateFile": "Duplicate File",
"EditFile": "Edit file",
"Empty": "Empty",
"Files": "Files",
Expand Down