Skip to content

Commit 6aaf830

Browse files
authored
Fix some cases of incremental naming disabled (microsoft#165253)
1 parent db1c4d4 commit 6aaf830

File tree

2 files changed

+46
-12
lines changed

2 files changed

+46
-12
lines changed

src/vs/workbench/contrib/files/browser/fileActions.ts

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,26 @@ function containsBothDirectoryAndFile(distinctElements: ExplorerItem[]): boolean
301301
}
302302

303303

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> {
306312

313+
let name = resources.basenameOrAuthority(fileToPaste.resource);
307314
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+
308324
while (true && !fileToPaste.allowOverwrite) {
309325
if (!explorerService.findClosest(candidate)) {
310326
break;
@@ -1064,13 +1080,17 @@ export const pasteFileHandler = async (accessor: ServicesAccessor) => {
10641080
target = element.isDirectory ? element : element.parent!;
10651081
}
10661082

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;
10741094
}
10751095

10761096
return { source: fileToPaste, target: targetFile };
@@ -1079,7 +1099,7 @@ export const pasteFileHandler = async (accessor: ServicesAccessor) => {
10791099
if (sourceTargetPairs.length >= 1) {
10801100
// Move/Copy File
10811101
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' }));
10831103
const options = {
10841104
confirmBeforeUndo: configurationService.getValue<IFilesConfiguration>().explorer.confirmUndo === UndoConfirmLevel.Verbose,
10851105
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)

src/vs/workbench/contrib/files/browser/views/explorerViewer.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,8 +1276,22 @@ export class FileDragAndDrop implements ITreeDragAndDrop<ExplorerItem> {
12761276

12771277
// Reuse duplicate action when user copies
12781278
const explorerConfig = this.configurationService.getValue<IFilesConfiguration>().explorer;
1279-
const resourceFileEdits = sources.map(({ resource, isDirectory }) =>
1280-
(new ResourceFileEdit(resource, findValidPasteFileTarget(this.explorerService, target, { resource, isDirectory, allowOverwrite: false }, explorerConfig.incrementalNaming), { copy: true })));
1279+
const resourceFileEdits: ResourceFileEdit[] = [];
1280+
for (const { resource, isDirectory } of sources) {
1281+
const allowOverwrite = explorerConfig.incrementalNaming === 'disabled';
1282+
const newResource = await findValidPasteFileTarget(this.explorerService,
1283+
this.fileService,
1284+
this.dialogService,
1285+
target,
1286+
{ resource, isDirectory, allowOverwrite },
1287+
explorerConfig.incrementalNaming
1288+
);
1289+
if (!newResource) {
1290+
continue;
1291+
}
1292+
const resourceEdit = new ResourceFileEdit(resource, newResource, { copy: true, overwrite: allowOverwrite });
1293+
resourceFileEdits.push(resourceEdit);
1294+
}
12811295
const labelSufix = getFileOrFolderLabelSufix(sources);
12821296
await this.explorerService.applyBulkEdit(resourceFileEdits, {
12831297
confirmBeforeUndo: explorerConfig.confirmUndo === UndoConfirmLevel.Default || explorerConfig.confirmUndo === UndoConfirmLevel.Verbose,

0 commit comments

Comments
 (0)