|
23 | 23 | </div> |
24 | 24 | <file v-for="(file, index) in files" |
25 | 25 | :file="file" |
26 | | - :selected="selected(file)" |
27 | | - :focused="isFocused(file)" |
28 | 26 | :key="file.name" |
29 | 27 | @click.native="selectFile(file, index, $event)" |
30 | 28 | @dblclick.native="changePath(file)"> |
|
36 | 34 | <script> |
37 | 35 | import File from './File.vue' |
38 | 36 | import FileHeader from './FileHeader.vue' |
39 | | - import {Rpc} from '../rpc.js' |
40 | | - import {EventBus} from '../EventBus' |
| 37 | + import { Rpc } from '../rpc.js' |
| 38 | + import { EventBus } from '../EventBus' |
41 | 39 |
|
42 | 40 | export default{ |
43 | 41 | props: ['roots', 'id'], |
44 | 42 | data: () => { |
45 | 43 | return { |
46 | | - files: [], |
47 | 44 | loading: false, |
48 | 45 | eventListener: null, |
49 | 46 | focusedFileIndex: -1 |
50 | 47 | } |
51 | 48 | }, |
52 | 49 | computed: { |
53 | 50 | state () { |
54 | | - return this.$store.state.states[this.id] |
| 51 | + return this.$store.state.views[this.id] |
55 | 52 | }, |
56 | 53 | roots () { |
57 | 54 | return this.$store.state.roots |
58 | 55 | }, |
59 | 56 | selectedRoot () { |
60 | | - return this.$store.state.states[this.id].selectedRoot |
| 57 | + return this.$store.state.views[this.id].selectedRoot |
61 | 58 | }, |
62 | 59 | isSelected () { |
63 | | - return this.$store.state.selectedState === this.id |
| 60 | + return this.$store.state.activeView === this.id |
64 | 61 | }, |
65 | 62 | path () { |
66 | | - return [this.selectedRoot].concat(this.$store.state.states[this.id].path) |
| 63 | + return [this.selectedRoot].concat(this.$store.state.views[this.id].path) |
67 | 64 | }, |
68 | 65 | pathString () { |
69 | | - return this.$store.state.states[this.id].path.reduce((acc, p) => { |
| 66 | + return this.$store.state.views[this.id].path.reduce((acc, p) => { |
70 | 67 | return acc + '/' + p |
71 | 68 | }, '') |
72 | 69 | }, |
73 | | - isViewSelected () { |
74 | | - return this.$store.state.selectedState === this.id |
| 70 | + files () { |
| 71 | + return this.$store.state.views[this.id].files |
75 | 72 | }, |
76 | 73 | focusedFile () { |
77 | | - if (this.files.length) { |
78 | | - return this.files[this.focusedFileIndex] |
79 | | - } |
80 | | - return '' |
| 74 | + return this.files.find(file => file.focused) |
81 | 75 | } |
82 | 76 | }, |
83 | 77 | components: { |
|
93 | 87 | } |
94 | 88 | }, |
95 | 89 | methods: { |
96 | | - selected (file) { |
97 | | - return this.$store.state.states[this.id] && this.$store.state.states[this.id].selectedFiles.includes(file.name) |
98 | | - }, |
99 | | - isFocused (file) { |
100 | | - return this.focusedFile === file |
| 90 | + focusFile (index) { |
| 91 | + this.files.forEach(file => { file.focused = false }) |
| 92 | + this.focusedFileIndex = index |
| 93 | + if (index >= 0) { |
| 94 | + this.files[index].focused = true |
| 95 | + } |
101 | 96 | }, |
102 | 97 | selectFile (file, index, event) { |
103 | 98 | if (event.shiftKey) { |
104 | 99 | let begin = Math.min(this.focusedFileIndex, index) |
105 | 100 | let end = Math.max(this.focusedFileIndex, index) + 1 |
106 | | - let selectedFiles = this.files |
| 101 | + this.files.forEach(file => { file.selected = false }) |
| 102 | + this.files |
107 | 103 | .slice(begin, end) |
108 | | - .map(file => file.name) |
109 | | - this.$store.commit('selectFiles', {stateId: this.id, value: selectedFiles}) |
| 104 | + .forEach(file => { file.selected = true }) |
110 | 105 | return |
111 | 106 | } else if (event.ctrlKey) { |
112 | | - this.$store.commit('selectFile', {stateId: this.id, value: file.name}) |
| 107 | + file.selected = !file.selected |
113 | 108 | } else { |
114 | | - this.$store.commit('selectSingleFile', {stateId: this.id, value: file.name}) |
| 109 | + this.files.forEach(file => { file.selected = false }) |
| 110 | + file.selected = true |
115 | 111 | } |
116 | | - this.focusedFileIndex = index |
| 112 | + this.focusFile(index) |
117 | 113 | }, |
118 | 114 | selectRootFn (e) { |
119 | 115 | this.selectRoot(e.target.value) |
|
126 | 122 | return |
127 | 123 | } |
128 | 124 | this.$store.commit('changePath', {stateId: this.id, value: file.name}) |
129 | | - this.focusedFileIndex = -1 |
| 125 | + this.focusFile(-1) |
130 | 126 | }, |
131 | 127 | changePathToParent () { |
132 | 128 | this.$store.commit('changePathToParent', {stateId: this.id}) |
133 | | - this.focusedFileIndex = -1 |
| 129 | + this.focusFile(-1) |
134 | 130 | }, |
135 | 131 | setPath (index) { |
136 | 132 | this.$store.commit('setPath', {stateId: this.id, value: index}) |
|
149 | 145 | response.result.filter((file) => { |
150 | 146 | return file.type === 'f' |
151 | 147 | }) |
152 | | - ) |
| 148 | + ).map(file => { |
| 149 | + file.selected = false |
| 150 | + file.focused = false |
| 151 | + return file |
| 152 | + }) |
153 | 153 | vm.loading = false |
154 | | - vm.files = files |
| 154 | + this.$store.state.views[this.id].files = files |
155 | 155 | }) |
156 | 156 | } |
157 | 157 | }, |
|
161 | 161 | }) |
162 | 162 | let vm = this |
163 | 163 | this.eventListener = (e) => { |
164 | | - if (!vm.isViewSelected || vm.$store.state.ui.state !== 'browse') { |
| 164 | + if (!vm.isSelected || vm.$store.state.ui.state !== 'browse') { |
165 | 165 | return |
166 | 166 | } |
167 | 167 | switch (e.key) { |
168 | 168 | case 'ArrowUp': |
169 | 169 | if (e.ctrlKey || e.shiftKey) { |
170 | | - vm.$store.commit('selectFile', {stateId: vm.id, value: vm.focusedFile.name}) |
| 170 | + vm.focusedFile.selected = !vm.focusedFile.selected |
171 | 171 | } |
172 | 172 | let hasParentDirectory = vm.path.length > 1 |
173 | 173 | let lowerFileIndex = hasParentDirectory |
174 | 174 | ? -1 |
175 | 175 | : 0 |
176 | | - vm.focusedFileIndex = Math.max(vm.focusedFileIndex - 1, lowerFileIndex) |
| 176 | + vm.focusFile(Math.max(vm.focusedFileIndex - 1, lowerFileIndex)) |
177 | 177 | break |
178 | 178 | case 'ArrowDown': |
179 | 179 | if (e.ctrlKey || e.shiftKey) { |
180 | | - vm.$store.commit('selectFile', {stateId: vm.id, value: vm.focusedFile.name}) |
| 180 | + vm.focusedFile.selected = !vm.focusedFile.selected |
181 | 181 | } |
182 | | - vm.focusedFileIndex = Math.min(vm.focusedFileIndex + 1, vm.files.length - 1) |
| 182 | + vm.focusFile(Math.min(vm.focusedFileIndex + 1, vm.files.length - 1)) |
183 | 183 | break |
184 | 184 | case 'Tab': |
185 | 185 | var newRootSelectionIndex = (vm.roots.indexOf(vm.selectedRoot) + (e.shiftKey ? -1 : 1)) % vm.roots.length |
|
191 | 191 | e.preventDefault() |
192 | 192 | break |
193 | 193 | case ' ': |
194 | | - vm.$store.commit('selectFile', {stateId: vm.id, value: vm.focusedFile.name}) |
| 194 | + vm.focusedFile.selected = !vm.focusedFile.selected |
195 | 195 | break |
196 | 196 | case 'Enter': |
197 | 197 | if (vm.focusedFileIndex === -1) { |
|
0 commit comments