Skip to content

Commit

Permalink
feat: make context menus selection aware
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <[email protected]>
  • Loading branch information
pedrolamas committed Mar 6, 2023
1 parent 07e3eb1 commit 58e9033
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 22 deletions.
16 changes: 14 additions & 2 deletions src/components/widgets/filesystem/FileSystem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,17 @@ export default class FileSystem extends Mixins(StateMixin, FilesMixin, ServicesM
} else if (item.dirname === '..') {
return
}
} else if (
}
if (
this.selected.length !== 0 &&
!this.selected.some(x => x.name === item.name)
) {
return
}
if (
item.type === 'file' &&
e.type === 'click' && (
this.$store.state.config.uiSettings.editor.autoEditExtensions.includes(`.${item.extension}`) ||
this.currentRoot === 'timelapse'
Expand All @@ -565,7 +575,9 @@ export default class FileSystem extends Mixins(StateMixin, FilesMixin, ServicesM
// Open the context menu
this.contextMenuState.x = e.clientX
this.contextMenuState.y = e.clientY
this.contextMenuState.file = item
this.contextMenuState.file = this.selected.length > 1
? this.selected
: item
this.$nextTick(() => {
this.contextMenuState.open = true
})
Expand Down
36 changes: 26 additions & 10 deletions src/components/widgets/filesystem/FileSystemContextMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<v-list-item-title>{{ $t('app.general.btn.print') }}</v-list-item-title>
</v-list-item>
<v-list-item
v-if="canPrint && supportsJobQueue"
v-if="canAddToQueue"
link
@click="$emit('enqueue', file)"
>
Expand All @@ -53,7 +53,7 @@
<v-list-item-title>{{ $t('app.general.btn.preheat') }}</v-list-item-title>
</v-list-item>
<v-list-item
v-if="file.type !== 'directory' && rootProperties.canEdit"
v-if="!Array.isArray(file) && file.type !== 'directory' && rootProperties.canEdit"
link
@click="$emit('edit', file)"
>
Expand All @@ -63,7 +63,7 @@
<v-list-item-title>{{ $t('app.general.btn.edit') }}</v-list-item-title>
</v-list-item>
<v-list-item
v-if="file.type !== 'directory' && rootProperties.canView"
v-if="!Array.isArray(file) && file.type !== 'directory' && rootProperties.canView"
link
@click="$emit('view', file)"
>
Expand Down Expand Up @@ -93,7 +93,7 @@
<v-list-item-title>{{ $t('app.general.btn.create_zip_archive') }}</v-list-item-title>
</v-list-item>
<v-list-item
v-if="file.type !== 'directory'"
v-if="!Array.isArray(file) && file.type !== 'directory'"
link
@click="$emit('download', file)"
>
Expand All @@ -103,7 +103,7 @@
<v-list-item-title>{{ $t('app.general.btn.download') }}</v-list-item-title>
</v-list-item>
<v-list-item
v-if="!rootProperties.readonly"
v-if="!Array.isArray(file) && !rootProperties.readonly"
link
@click="$emit('rename', file)"
>
Expand Down Expand Up @@ -162,8 +162,8 @@ export default class FileSystemContextMenu extends Mixins(StateMixin, FilesMixin
@Prop({ type: String, required: true })
readonly root!: string
@Prop({ type: Object, required: true })
readonly file!: FileBrowserEntry
@Prop({ type: [Object, Array], required: true })
readonly file!: FileBrowserEntry | FileBrowserEntry[]
@Prop({ type: Number, required: true })
readonly positionX!: number
Expand All @@ -177,6 +177,7 @@ export default class FileSystemContextMenu extends Mixins(StateMixin, FilesMixin
get canPrint () {
return (
!Array.isArray(this.file) &&
this.file.type !== 'directory' &&
this.rootProperties.accepts.includes('.' + this.file.extension) &&
this.rootProperties.canPrint
Expand All @@ -185,6 +186,7 @@ export default class FileSystemContextMenu extends Mixins(StateMixin, FilesMixin
get canPreheat () {
return (
!Array.isArray(this.file) &&
'first_layer_extr_temp' in this.file &&
'first_layer_bed_temp' in this.file
)
Expand All @@ -200,6 +202,7 @@ export default class FileSystemContextMenu extends Mixins(StateMixin, FilesMixin
get canPreviewGcode () {
return (
!Array.isArray(this.file) &&
this.file.type === 'file' &&
this.file.extension === 'gcode' &&
this.root === 'gcodes'
Expand All @@ -208,14 +211,27 @@ export default class FileSystemContextMenu extends Mixins(StateMixin, FilesMixin
get canCreateZip () {
return (
(this.file.type !== 'file' || this.file.extension !== 'zip') &&
(
Array.isArray(this.file) ||
this.file.type !== 'file' ||
this.file.extension !== 'zip'
) &&
!this.rootProperties.readonly &&
this.$store.getters['server/getIsMinApiVersion']('1.1.0')
)
}
get supportsJobQueue (): boolean {
return this.$store.getters['server/componentSupport']('job_queue')
get canAddToQueue () {
const files = Array.isArray(this.file) ? this.file : [this.file]
return (
files.some(x =>
x.type !== 'directory' &&
this.rootProperties.accepts.includes('.' + x.extension) &&
this.rootProperties.canPrint
) &&
this.$store.getters['server/componentSupport']('job_queue')
)
}
}
</script>
31 changes: 23 additions & 8 deletions src/components/widgets/job-queue/JobQueue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,30 @@ export default class JobQueue extends Vue {
}
handleRowClick (item: QueuedJob, e: MouseEvent) {
if (!this.contextMenuState.open) {
// Open the context menu
this.contextMenuState.x = e.clientX
this.contextMenuState.y = e.clientY
this.contextMenuState.job = item
this.$nextTick(() => {
this.contextMenuState.open = true
})
if (this.contextMenuState.open) {
this.contextMenuState.open = false
if (e.type !== 'contextmenu') {
return
}
}
if (
this.selected.length !== 0 &&
!this.selected.some(x => x.filename === item.filename)
) {
return
}
// Open the context menu
this.contextMenuState.x = e.clientX
this.contextMenuState.y = e.clientY
this.contextMenuState.job = this.selected.length > 1
? this.selected
: item
this.$nextTick(() => {
this.contextMenuState.open = true
})
}
async handleRemoveAll () {
Expand Down
4 changes: 2 additions & 2 deletions src/components/widgets/job-queue/JobQueueContextMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class JobQueueContextMenu extends Vue {
@Prop({ type: Number, required: true })
readonly positionY!: number
@Prop({ type: Object, required: true })
readonly job!: QueuedJob
@Prop({ type: [Object, Array], required: true })
readonly job!: QueuedJob | QueuedJob[]
}
</script>

0 comments on commit 58e9033

Please sign in to comment.