Skip to content

Commit

Permalink
Reformat file.
Browse files Browse the repository at this point in the history
  • Loading branch information
CF3B5 committed Jul 14, 2024
1 parent 4cacf92 commit a2b1391
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 70 deletions.
107 changes: 52 additions & 55 deletions src/components/TheEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@
</v-btn>
</template>
<v-card-text class="pa-0">
<div v-if="fileStructureSidebar"
class="d-none d-md-flex float-right structure-sidebar cm-editor ͼo">
<div v-if="fileStructureSidebar" class="d-none d-md-flex float-right structure-sidebar cm-editor ͼo">
<div class="cm-scroller" style="width: 100%;">
<v-treeview
activatable
Expand Down Expand Up @@ -98,23 +97,23 @@
v-model="sourcecode"
:name="filename"
:file-extension="fileExtension"
@lineChange="lineChanges"/>
@lineChange="lineChanges" />
</div>
</v-card-text>
</panel>
</v-dialog>
<v-snackbar v-model="loaderBool" :timeout="-1" :value="true" fixed right bottom>
<div>
{{ snackbarHeadline }}
<br/>
<br />
<strong>{{ filename }}</strong>
</div>
<template v-if="loaderProgress.total > 0">
<span class="mr-1">
({{ formatFilesize(loaderProgress.loaded) }}/{{ formatFilesize(loaderProgress.total) }})
</span>
{{ Math.round((100 * loaderProgress.loaded) / loaderProgress.total) }} % @ {{ loaderProgress.speed }}/s
<br/>
<br />
<v-progress-linear
class="mt-2"
:value="(100 * loaderProgress.loaded) / loaderProgress.total"></v-progress-linear>
Expand Down Expand Up @@ -148,7 +147,7 @@
</v-row>
</v-card-text>
<v-card-actions>
<v-spacer/>
<v-spacer />
<v-btn text @click="discardChanges">
{{ $t('Editor.DontSave') }}
</v-btn>
Expand All @@ -163,7 +162,7 @@
</v-card-actions>
</panel>
</v-dialog>
<devices-dialog :show-dialog="dialogDevices" @close="dialogDevices = false"/>
<devices-dialog :show-dialog="dialogDevices" @close="dialogDevices = false" />
</div>
</template>

Expand Down Expand Up @@ -220,87 +219,87 @@ export default class TheEditor extends Mixins(BaseMixin) {
editor: Codemirror
}
get changed () {
get changed() {
return this.$store.state.editor.changed ?? false
}
get changedOutput () {
get changedOutput() {
return this.changed ? '*' : ''
}
get show () {
get show() {
return this.$store.state.editor.bool ?? false
}
get filepath (): string {
get filepath(): string {
return this.$store.state.editor.filepath ?? ''
}
get filename (): string {
get filename(): string {
return this.$store.state.editor.filename ?? ''
}
get filenameWithoutExtension (): string {
get filenameWithoutExtension(): string {
if (this.filename.lastIndexOf('.')) return this.filename.slice(0, this.filename.lastIndexOf('.'))
return this.filename
}
get fileExtension () {
get fileExtension() {
if (this.filename.lastIndexOf('.')) return this.filename.slice(this.filename.lastIndexOf('.') + 1)
return ''
}
get fileroot () {
get fileroot() {
return this.$store.state.editor.fileroot ?? 'gcodes'
}
get permissions (): string {
get permissions(): string {
return this.$store.state.editor.permissions ?? 'r'
}
get isWriteable () {
get isWriteable() {
return this.permissions.includes('w')
}
get sourcecode () {
get sourcecode() {
return this.$store.state.editor.sourcecode ?? ''
}
set sourcecode (newVal) {
set sourcecode(newVal) {
this.$store.dispatch('editor/updateSourcecode', newVal)
}
get loaderBool () {
get loaderBool() {
return this.$store.state.editor.loaderBool ?? false
}
get loaderProgress () {
get loaderProgress() {
return this.$store.state.editor.loaderProgress ?? {}
}
get snackbarHeadline () {
get snackbarHeadline() {
let directionUppercase = this.$t('Editor.Downloading')
if (this.loaderProgress.direction) directionUppercase = capitalize(this.loaderProgress.direction)
return this.$t(`Editor.${ directionUppercase }`)
return this.$t(`Editor.${directionUppercase}`)
}
get availableServices () {
get availableServices() {
return this.$store.state.server.system_info?.available_services ?? []
}
get restartServiceName () {
get restartServiceName() {
if (!this.isWriteable) return null
if ([ 'printing', 'paused' ].includes(this.printer_state)) return null
if (['printing', 'paused'].includes(this.printer_state)) return null
// check for generic services <service>.conf (like moonraker.conf, crowsnest.conf, sonar.conf)
if (this.availableServices.includes(this.filenameWithoutExtension) && this.fileExtension === 'conf')
return this.filenameWithoutExtension
// old webcam service DEPRECATED
if (this.filename.startsWith('webcam') && [ 'conf', 'txt' ].includes(this.fileExtension)) return 'webcamd'
if (this.filename.startsWith('webcam') && ['conf', 'txt'].includes(this.fileExtension)) return 'webcamd'
// check for mooncord config files
if (this.filename.startsWith('mooncord') && this.fileExtension === 'json') return 'mooncord'
Expand All @@ -314,50 +313,50 @@ export default class TheEditor extends Mixins(BaseMixin) {
return null
}
get restartServiceNameExists () {
get restartServiceNameExists() {
// hide the button, if there is no service found
if (this.restartServiceName === null) return false
// klipper and moonraker uses specific api calls instead of generic service restart
if ([ 'klipper', 'moonraker' ].includes(this.restartServiceName)) return true
if (['klipper', 'moonraker'].includes(this.restartServiceName)) return true
return this.availableServices.includes(this.restartServiceName)
}
get confirmUnsavedChanges () {
get confirmUnsavedChanges() {
return this.$store.state.gui.editor.confirmUnsavedChanges ?? false
}
get escToClose () {
get escToClose() {
return this.$store.state.gui.editor.escToClose ?? false
}
get title () {
const title = this.filepath ? `${ this.filepath }/${ this.filename }` : this.filename
get title() {
const title = this.filepath ? `${this.filepath}/${this.filename}` : this.filename
if (!this.isWriteable) return `${ title } (${ this.$t('Editor.FileReadOnly') })`
if (!this.isWriteable) return `${title} (${this.$t('Editor.FileReadOnly')})`
return `${ title } ${ this.changedOutput }`
return `${title} ${this.changedOutput}`
}
get currentLanguage () {
get currentLanguage() {
return this.$store.state.gui.general.language
}
get klipperConfigReference (): string {
get klipperConfigReference(): string {
const currentLanguage = this.currentLanguage
const translations = availableKlipperConfigReferenceTranslations
let url = 'https://www.klipper3d.org/Config_Reference.html'
if (translations.includes(currentLanguage)) {
url = `https://www.klipper3d.org/${ currentLanguage }/Config_Reference.html`
url = `https://www.klipper3d.org/${currentLanguage}/Config_Reference.html`
}
return url
}
get configFileStructure () {
if ([ 'conf', 'cfg' ].includes(this.fileExtension)) {
get configFileStructure() {
if (['conf', 'cfg'].includes(this.fileExtension)) {
const sourcecode = this.sourcecode
const lines = sourcecode.split(/\n/gi)
const regex = /^[^#\S]*?(\[(?<section>.*?)]|(?<name>\w+)\s*?[:=])/gim
Expand All @@ -366,7 +365,7 @@ export default class TheEditor extends Mixins(BaseMixin) {
let structure: ConfigFileSection[] = []
for (let i = 0; i < lines.length; i++) {
const line = lines[i]
const matches = [ ...line.matchAll(regex) ]
const matches = [...line.matchAll(regex)]
if (matches.length > 0) {
const match = matches[0]
if (match['groups']['section']) {
Expand Down Expand Up @@ -394,30 +393,30 @@ export default class TheEditor extends Mixins(BaseMixin) {
return null
}
cancelDownload () {
cancelDownload() {
this.$store.dispatch('editor/cancelLoad')
}
escClose () {
escClose() {
if (this.escToClose) this.close()
}
close () {
close() {
if (this.confirmUnsavedChanges) this.promptUnsavedChanges()
else this.$store.dispatch('editor/close')
}
discardChanges () {
discardChanges() {
this.dialogConfirmChange = false
this.$store.dispatch('editor/close')
}
promptUnsavedChanges () {
promptUnsavedChanges() {
if (!this.changed || !this.isWriteable) this.$store.dispatch('editor/close')
else this.dialogConfirmChange = true
}
save (restartServiceName: string | null = null) {
save(restartServiceName: string | null = null) {
this.dialogConfirmChange = false
this.$store.dispatch('editor/saveFile', {
Expand All @@ -426,22 +425,22 @@ export default class TheEditor extends Mixins(BaseMixin) {
})
}
showFileStructure () {
showFileStructure() {
this.fileStructureSidebar = !this.fileStructureSidebar
}
activeChanges (key: any) {
activeChanges(key: any) {
this.$refs.editor.gotoLine(key)
}
lineChanges (line: number) {
lineChanges(line: number) {
this.configFileStructure?.map((item) => {
if (item.line == line) {
this.structureActive = [ line ]
this.structureActive = [line]
} else {
item.children?.map((child) => {
if (child.line == line) {
this.structureActive = [ line ]
this.structureActive = [line]
if (!this.structureOpen.includes(item.line)) this.structureOpen.push(item.line)
}
})
Expand All @@ -450,7 +449,7 @@ export default class TheEditor extends Mixins(BaseMixin) {
}
@Watch('changed')
changedChanged (newVal: boolean) {
changedChanged(newVal: boolean) {
if (!this.confirmUnsavedChanges) return
if (newVal) {
Expand Down Expand Up @@ -515,11 +514,9 @@ export default class TheEditor extends Mixins(BaseMixin) {
.structure {
margin-right: 300px
}
.structure-sidebar {
width: 300px;
overflow-y: auto;
}
}
</style>
Loading

0 comments on commit a2b1391

Please sign in to comment.