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(Editor): store last state of file structure sidebar #2140

Merged
merged 4 commits into from
Feb 9, 2025
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
32 changes: 20 additions & 12 deletions src/components/TheEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<v-icon small class="mr-1">{{ mdiHelp }}</v-icon>
{{ $t('Editor.ConfigReference') }}
</v-btn>
<v-btn v-if="configFileStructure" text tile class="d-none d-md-flex" @click="showFileStructure()">
<v-btn v-if="existsFileStructure" text tile class="d-none d-md-flex" @click="toggleFileStructure">
<v-icon small class="mr-1">{{ mdiFormatListCheckbox }}</v-icon>
{{ $t('Editor.FileStructure') }}
</v-btn>
Expand Down Expand Up @@ -60,9 +60,9 @@
:name="filename"
:file-extension="fileExtension"
class="codemirror"
:class="{ withSidebar: fileStructureSidebar }"
:class="{ withSidebar: existsFileStructure && fileStructureSidebar }"
@lineChange="lineChanges" />
<div v-if="fileStructureSidebar" class="d-none d-md-flex structure-sidebar">
<div v-if="existsFileStructure && fileStructureSidebar" class="d-none d-md-flex structure-sidebar">
<v-treeview
activatable
dense
Expand Down Expand Up @@ -189,7 +189,6 @@ import { ConfigFileSection } from '@/store/files/types'
export default class TheEditor extends Mixins(BaseMixin) {
dialogConfirmChange = false
dialogDevices = false
fileStructureSidebar = true
treeviewItemKeyProp = 'line' as const
structureActive: number[] = []
structureOpen: number[] = []
Expand Down Expand Up @@ -358,10 +357,16 @@ export default class TheEditor extends Mixins(BaseMixin) {
return url
}

get configFileStructure() {
this.fileStructureSidebar = false
get fileStructureSidebar() {
return this.$store.state.gui.editor.fileStructureSidebar
}

set fileStructureSidebar(newVal) {
this.$store.dispatch('gui/saveSetting', { name: 'editor.fileStructureSidebar', value: newVal })
}

if (!['conf', 'cfg'].includes(this.fileExtension)) return null
get configFileStructure(): ConfigFileSection[] {
if (!['conf', 'cfg'].includes(this.fileExtension)) return []

const lines = this.sourcecode.split(/\n/gi)
const regex = /^[^#\S]*?(\[(?<section>.*?)]|(?<name>\w+)\s*?[:=])/gim
Expand Down Expand Up @@ -395,10 +400,17 @@ export default class TheEditor extends Mixins(BaseMixin) {
}
}

if (structure.length > 0) this.fileStructureSidebar = true
return structure
}

get existsFileStructure() {
return this.configFileStructure.length > 0
}

toggleFileStructure() {
this.fileStructureSidebar = !this.fileStructureSidebar
}

cancelDownload() {
this.$store.dispatch('editor/cancelLoad')
}
Expand Down Expand Up @@ -431,10 +443,6 @@ export default class TheEditor extends Mixins(BaseMixin) {
})
}

showFileStructure() {
this.fileStructureSidebar = !this.fileStructureSidebar
}

// Relies on event bubbling to flip the flag before treeview active change is handled
activeChangesItemClick() {
this.structureActiveChangedBySidebar = true
Expand Down
1 change: 1 addition & 0 deletions src/store/gui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export const getDefaultState = (): GuiState => {
confirmUnsavedChanges: true,
klipperRestartMethod: 'FIRMWARE_RESTART',
tabSize: 2,
fileStructureSidebar: true,
},
gcodeViewer: {
extruderColors: ['#E76F51FF', '#F4A261FF', '#E9C46AFF', '#2A9D8FFF', '#264653FF'],
Expand Down
1 change: 1 addition & 0 deletions src/store/gui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface GuiState {
confirmUnsavedChanges: boolean
klipperRestartMethod: 'FIRMWARE_RESTART' | 'RESTART'
tabSize: number
fileStructureSidebar: boolean
}
gcodeViewer: {
extruderColors: string[]
Expand Down