3
3
4
4
import * as path from "path" ;
5
5
import * as fse from "fs-extra" ;
6
- import { commands , DataTransfer , DataTransferItem , TreeDragAndDropController , Uri , window , workspace , WorkspaceEdit } from "vscode" ;
7
- import { Commands } from "../commands" ;
6
+ import { DataTransfer , DataTransferItem , TreeDragAndDropController , Uri , window , workspace , WorkspaceEdit } from "vscode" ;
8
7
import { Explorer } from "../constants" ;
9
8
import { BaseSymbolNode } from "./baseSymbolNode" ;
10
9
import { ContainerNode , ContainerType } from "./containerNode" ;
@@ -136,7 +135,7 @@ export class DragAndDropController implements TreeDragAndDropController<Explorer
136
135
this . addReferencedLibraries ( [ source ?. uri ! ] ) ;
137
136
} else if ( target instanceof PackageRootNode || target instanceof PackageNode
138
137
|| target instanceof FolderNode ) {
139
- await this . move ( source ! , target ) ;
138
+ await this . move ( Uri . parse ( source ! . uri ! ) , Uri . parse ( target . uri ! ) ) ;
140
139
}
141
140
}
142
141
@@ -159,7 +158,9 @@ export class DragAndDropController implements TreeDragAndDropController<Explorer
159
158
this . addReferencedLibraries ( uris ) ;
160
159
} else if ( target instanceof PackageRootNode || target instanceof PackageNode
161
160
|| target instanceof FolderNode ) {
162
- // TODO: copy the resources to other nodes
161
+ for ( const uri of uris ) {
162
+ await this . copy ( Uri . parse ( uri ) , Uri . parse ( target . uri ! ) ) ;
163
+ }
163
164
}
164
165
}
165
166
@@ -240,9 +241,7 @@ export class DragAndDropController implements TreeDragAndDropController<Explorer
240
241
/**
241
242
* Trigger a workspace edit that move the source node into the target node.
242
243
*/
243
- private async move ( source : DataNode , target : DataNode ) : Promise < void > {
244
- const sourceUri = Uri . parse ( source . uri ! ) ;
245
- const targetUri = Uri . parse ( target . uri ! ) ;
244
+ private async move ( sourceUri : Uri , targetUri : Uri ) : Promise < void > {
246
245
if ( sourceUri === targetUri ) {
247
246
return ;
248
247
}
@@ -258,7 +257,20 @@ export class DragAndDropController implements TreeDragAndDropController<Explorer
258
257
const edit = new WorkspaceEdit ( ) ;
259
258
edit . renameFile ( sourceUri , Uri . file ( newPath ) , { overwrite : true } ) ;
260
259
await workspace . applyEdit ( edit ) ;
261
- commands . executeCommand ( Commands . VIEW_PACKAGE_REFRESH , /* debounce = */ true ) ;
260
+ }
261
+ }
262
+
263
+ /**
264
+ * Copy the file from source uri to the target uri.
265
+ */
266
+ private async copy ( sourceUri : Uri , targetUri : Uri ) : Promise < void > {
267
+ if ( sourceUri === targetUri ) {
268
+ return ;
269
+ }
270
+
271
+ const newPath = path . join ( targetUri . fsPath , path . basename ( sourceUri . fsPath ) ) ;
272
+ if ( await this . confirmOverwrite ( newPath ) ) {
273
+ await workspace . fs . copy ( sourceUri , Uri . file ( newPath ) , { overwrite : true } ) ;
262
274
}
263
275
}
264
276
0 commit comments