Skip to content

Commit 426a3e8

Browse files
committed
Adding dra&drop move for file & folders
1 parent ad083e7 commit 426a3e8

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/App.vue

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
@click="onClick"
1111
@change-name="onChangeName"
1212
@delete-node="onDel"
13-
@add-node="onAddNode"
1413
@dragstart="dragCallback"
14+
@drop="drop"
1515
:model="data"
1616
v-bind:default-expanded="false"
1717
>
@@ -29,12 +29,12 @@
2929
<script>
3030
import { VueTreeList, Tree, TreeNode } from 'vue-tree-list'
3131
import { readDir, createDir, writeFile, removeDir, removeFile, renameFile } from '@tauri-apps/api/fs'
32-
import { videoDir, resolve as pathResolve, join as pathJoin } from '@tauri-apps/api/path'
32+
import { videoDir, resolve as pathResolve, join as pathJoin, basename as pathBasename, sep as DS } from '@tauri-apps/api/path'
3333
import { open } from '@tauri-apps/api/dialog'
3434
3535
const getPartialNodePath = (node, accum, override) => {
3636
if (node.parent == null) {
37-
return accum.reverse().join('/')
37+
return accum.reverse().join(DS)
3838
} else {
3939
accum.push(override == null ? node.name : override)
4040
return getPartialNodePath(node.parent, accum)
@@ -62,7 +62,6 @@ const slugify = (text) =>
6262
.replace(/--+/g, '-') + Date.now().toString()
6363
6464
const getNodeObj = (node) => {
65-
console.log(node)
6665
if (node.parent !== null) {
6766
return node.parent.children.filter(function (el) {
6867
return el.name === node.name
@@ -103,6 +102,14 @@ export default {
103102
dragCallback (event) {
104103
console.log(event)
105104
},
105+
async drop (event) {
106+
const originPath = getFullNodePath(event.src)
107+
const nodeFile = await pathBasename(getFullNodePath(event.node)).then(result => result)
108+
const dest = getFullNodePath(event.target)
109+
const origin = await pathJoin(this.rootDir.trim(), originPath.trim(), nodeFile.trim()).then(result => result)
110+
const target = this.rootDir + dest + DS + nodeFile
111+
renameFile(origin, target)
112+
},
106113
async clickUpdateNode () {
107114
await this.updateNode(null, true)
108115
},
@@ -237,7 +244,7 @@ export default {
237244
parent = parent.parent
238245
}
239246
if (parent !== null) {
240-
path = await pathJoin(this.rootDir, getFullNodePath(parent)).then(result => result) + '\\' + value
247+
path = await pathJoin(this.rootDir, getFullNodePath(parent)).then(result => result) + DS + value
241248
}
242249
createDir(path).then((result) => {
243250
this.addDir({ name: value }, parent)

0 commit comments

Comments
 (0)