Skip to content

Commit

Permalink
feat(TreeEditor): new display modes
Browse files Browse the repository at this point in the history
closes #588
  • Loading branch information
solvedDev committed Aug 25, 2022
1 parent 0656b12 commit d5da200
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/components/Editors/TreeEditor/Highlight.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export default {
mixins: [
HighlighterMixin([
'string',
'number',
'variable',
'definition',
'keyword',
Expand Down
20 changes: 17 additions & 3 deletions src/components/Editors/TreeEditor/Tree/CommonTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,22 @@
>
mdi-chevron-right
</v-icon>
<span v-if="tree.parent.type === 'object'">
<span v-if="showArrayIndices || tree.parent.type === 'object'">
<!-- Debugging helper -->
<span v-if="isDevMode">
s: {{ tree.type }} p: {{ tree.parent.type }}
</span>

<span @dblclick="tree.toggleOpen()"> <slot /> </span>:</span
<span @dblclick="tree.toggleOpen()"> <slot /> </span
>{{ hideBracketsWithinTreeEditor ? undefined : ':' }}</span
>
<!-- Spacer to make array objects easier to select -->
<span
v-else-if="!showArrayIndices"
:class="{
'mx-2': pointerDevice !== 'touch',
'mx-6': pointerDevice === 'touch',
}"
v-else
/>

<span class="px-1" @click.stop.prevent="tree.toggleOpen()">
Expand Down Expand Up @@ -110,7 +111,18 @@ export default {
}
},
computed: {
hideBracketsWithinTreeEditor() {
if (!settingsState.editor) return false
return settingsState.editor.hideBracketsWithinTreeEditor || false
},
showArrayIndices() {
if (!settingsState.editor) return false
return settingsState.editor.showArrayIndices || false
},
openingBracket() {
if (this.hideBracketsWithinTreeEditor) return
if (this.tree.isOpen) return brackets[this.tree.type][0]
else if (Object.keys(this.tree.children).length > 0)
return `${brackets[this.tree.type][0]}...${
Expand All @@ -121,6 +133,8 @@ export default {
}`
},
closingBracket() {
if (this.hideBracketsWithinTreeEditor) return
return this.tree.isOpen ? brackets[this.tree.type][1] : undefined
},
},
Expand Down
7 changes: 6 additions & 1 deletion src/components/Editors/TreeEditor/Tree/TreeChildren.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
:treeEditor="treeEditor"
@setActive="$emit('setActive')"
>
<Highlight :value="key" />
<span v-if="tree.type === 'array'" :style="numberDef">{{
key
}}</span>
<Highlight v-else :value="key" />
</component>
</Draggable>
</div>
Expand All @@ -29,9 +32,11 @@ import { pointerDevice } from '/@/utils/pointerDevice.ts'
import Draggable from 'vuedraggable'
import { settingsState } from '/@/components/Windows/Settings/SettingsState.ts'
import { MoveEntry } from '../History/MoveEntry.ts'
import { HighlighterMixin } from '/@/components/Mixins/Highlighter'
export default {
name: 'TreeChildren',
mixins: [HighlighterMixin(['number'])],
components: {
Highlight,
Draggable,
Expand Down
19 changes: 19 additions & 0 deletions src/components/Windows/Settings/setupSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,25 @@ export async function setupSettings(settings: SettingsWindow) {
default: true,
})
)
settings.addControl(
new Toggle({
category: 'editor',
name: 'windows.settings.editor.showArrayIndices.name',
description: 'windows.settings.editor.showArrayIndices.description',
key: 'showArrayIndices',
default: false,
})
)
settings.addControl(
new Toggle({
category: 'editor',
name: 'windows.settings.editor.hideBracketsWithinTreeEditor.name',
description:
'windows.settings.editor.hideBracketsWithinTreeEditor.description',
key: 'hideBracketsWithinTreeEditor',
default: false,
})
)

// Projects
settings.addControl(
Expand Down
8 changes: 8 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,14 @@
"dragAndDropTreeNodes": {
"name": "Drag and Drop Tree Nodes",
"description": "Disable/enable drag & drop for tree nodes inside of bridge.'s tree editor"
},
"showArrayIndices": {
"name": "Show Array Indices",
"description": "Show indices for array elements inside of bridge.'s tree editor"
},
"hideBracketsWithinTreeEditor": {
"name": "Hide Brackets",
"description": "Hide brackets within bridge.'s tree editor"
}
}
},
Expand Down

0 comments on commit d5da200

Please sign in to comment.