@@ -301,10 +301,26 @@ function containsBothDirectoryAndFile(distinctElements: ExplorerItem[]): boolean
301
301
}
302
302
303
303
304
- export function findValidPasteFileTarget ( explorerService : IExplorerService , targetFolder : ExplorerItem , fileToPaste : { resource : URI ; isDirectory ?: boolean ; allowOverwrite : boolean } , incrementalNaming : 'simple' | 'smart' | 'disabled' ) : URI {
305
- let name = resources . basenameOrAuthority ( fileToPaste . resource ) ;
304
+ export async function findValidPasteFileTarget (
305
+ explorerService : IExplorerService ,
306
+ fileService : IFileService ,
307
+ dialogService : IDialogService ,
308
+ targetFolder : ExplorerItem ,
309
+ fileToPaste : { resource : URI ; isDirectory ?: boolean ; allowOverwrite : boolean } ,
310
+ incrementalNaming : 'simple' | 'smart' | 'disabled'
311
+ ) : Promise < URI | undefined > {
306
312
313
+ let name = resources . basenameOrAuthority ( fileToPaste . resource ) ;
307
314
let candidate = resources . joinPath ( targetFolder . resource , name ) ;
315
+
316
+ // In the disabled case we must ask if it's ok to overwrite the file if it exists
317
+ if ( incrementalNaming === 'disabled' ) {
318
+ const canOverwrite = await askForOverwrite ( fileService , dialogService , candidate ) ;
319
+ if ( ! canOverwrite ) {
320
+ return ;
321
+ }
322
+ }
323
+
308
324
while ( true && ! fileToPaste . allowOverwrite ) {
309
325
if ( ! explorerService . findClosest ( candidate ) ) {
310
326
break ;
@@ -1064,13 +1080,17 @@ export const pasteFileHandler = async (accessor: ServicesAccessor) => {
1064
1080
target = element . isDirectory ? element : element . parent ! ;
1065
1081
}
1066
1082
1067
- const targetFile = findValidPasteFileTarget ( explorerService , target , { resource : fileToPaste , isDirectory : fileToPasteStat . isDirectory , allowOverwrite : pasteShouldMove || incrementalNaming === 'disabled' } , incrementalNaming ) ;
1068
-
1069
- if ( incrementalNaming === 'disabled' ) {
1070
- const canOverwrite = await askForOverwrite ( fileService , dialogService , targetFile ) ;
1071
- if ( ! canOverwrite ) {
1072
- return ;
1073
- }
1083
+ const targetFile = await findValidPasteFileTarget (
1084
+ explorerService ,
1085
+ fileService ,
1086
+ dialogService ,
1087
+ target ,
1088
+ { resource : fileToPaste , isDirectory : fileToPasteStat . isDirectory , allowOverwrite : pasteShouldMove || incrementalNaming === 'disabled' } ,
1089
+ incrementalNaming
1090
+ ) ;
1091
+
1092
+ if ( ! targetFile ) {
1093
+ return undefined ;
1074
1094
}
1075
1095
1076
1096
return { source : fileToPaste , target : targetFile } ;
@@ -1079,7 +1099,7 @@ export const pasteFileHandler = async (accessor: ServicesAccessor) => {
1079
1099
if ( sourceTargetPairs . length >= 1 ) {
1080
1100
// Move/Copy File
1081
1101
if ( pasteShouldMove ) {
1082
- const resourceFileEdits = sourceTargetPairs . map ( pair => new ResourceFileEdit ( pair . source , pair . target ) ) ;
1102
+ const resourceFileEdits = sourceTargetPairs . map ( pair => new ResourceFileEdit ( pair . source , pair . target , { overwrite : incrementalNaming === 'disabled' } ) ) ;
1083
1103
const options = {
1084
1104
confirmBeforeUndo : configurationService . getValue < IFilesConfiguration > ( ) . explorer . confirmUndo === UndoConfirmLevel . Verbose ,
1085
1105
progressLabel : sourceTargetPairs . length > 1 ? nls . localize ( { key : 'movingBulkEdit' , comment : [ 'Placeholder will be replaced by the number of files being moved' ] } , "Moving {0} files" , sourceTargetPairs . length )
0 commit comments