From 1c2eb0be756d092caadb0d6d8c601fc284df8c02 Mon Sep 17 00:00:00 2001 From: Logan Ramos Date: Tue, 6 Sep 2022 22:55:28 -0400 Subject: [PATCH] Incremental naming add `disabled` (#160218) --- .../workbench/contrib/files/browser/fileActions.ts | 12 +++++++----- .../contrib/files/browser/files.contribution.ts | 5 +++-- src/vs/workbench/contrib/files/common/files.ts | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/vs/workbench/contrib/files/browser/fileActions.ts b/src/vs/workbench/contrib/files/browser/fileActions.ts index 04839fa2f43fd..9234f83c6f74f 100644 --- a/src/vs/workbench/contrib/files/browser/fileActions.ts +++ b/src/vs/workbench/contrib/files/browser/fileActions.ts @@ -296,7 +296,7 @@ function containsBothDirectoryAndFile(distinctElements: ExplorerItem[]): boolean } -export function findValidPasteFileTarget(explorerService: IExplorerService, targetFolder: ExplorerItem, fileToPaste: { resource: URI; isDirectory?: boolean; allowOverwrite: boolean }, incrementalNaming: 'simple' | 'smart'): URI { +export function findValidPasteFileTarget(explorerService: IExplorerService, targetFolder: ExplorerItem, fileToPaste: { resource: URI; isDirectory?: boolean; allowOverwrite: boolean }, incrementalNaming: 'simple' | 'smart' | 'disabled'): URI { let name = resources.basenameOrAuthority(fileToPaste.resource); let candidate = resources.joinPath(targetFolder.resource, name); @@ -305,7 +305,9 @@ export function findValidPasteFileTarget(explorerService: IExplorerService, targ break; } - name = incrementFileName(name, !!fileToPaste.isDirectory, incrementalNaming); + if (incrementalNaming !== 'disabled') { + name = incrementFileName(name, !!fileToPaste.isDirectory, incrementalNaming); + } candidate = resources.joinPath(targetFolder.resource, name); } @@ -1004,6 +1006,7 @@ export const pasteFileHandler = async (accessor: ServicesAccessor) => { const context = explorerService.getContext(true); const toPaste = resources.distinctParents(await clipboardService.readResources(), r => r); const element = context.length ? context[0] : explorerService.roots[0]; + const incrementalNaming = configurationService.getValue().explorer.incrementalNaming; try { // Check if target is ancestor of pasted folder @@ -1022,8 +1025,7 @@ export const pasteFileHandler = async (accessor: ServicesAccessor) => { target = element.isDirectory ? element : element.parent!; } - const incrementalNaming = configurationService.getValue().explorer.incrementalNaming; - const targetFile = findValidPasteFileTarget(explorerService, target, { resource: fileToPaste, isDirectory: fileToPasteStat.isDirectory, allowOverwrite: pasteShouldMove }, incrementalNaming); + const targetFile = findValidPasteFileTarget(explorerService, target, { resource: fileToPaste, isDirectory: fileToPasteStat.isDirectory, allowOverwrite: pasteShouldMove || incrementalNaming === 'disabled' }, incrementalNaming); return { source: fileToPaste, target: targetFile }; })); @@ -1041,7 +1043,7 @@ export const pasteFileHandler = async (accessor: ServicesAccessor) => { }; await explorerService.applyBulkEdit(resourceFileEdits, options); } else { - const resourceFileEdits = sourceTargetPairs.map(pair => new ResourceFileEdit(pair.source, pair.target, { copy: true })); + const resourceFileEdits = sourceTargetPairs.map(pair => new ResourceFileEdit(pair.source, pair.target, { copy: true, overwrite: incrementalNaming === 'disabled' })); const undoLevel = configurationService.getValue().explorer.confirmUndo; const options = { confirmBeforeUndo: undoLevel === UndoConfirmLevel.Default || undoLevel === UndoConfirmLevel.Verbose, diff --git a/src/vs/workbench/contrib/files/browser/files.contribution.ts b/src/vs/workbench/contrib/files/browser/files.contribution.ts index a975cf5c4a939..062fb218400d2 100644 --- a/src/vs/workbench/contrib/files/browser/files.contribution.ts +++ b/src/vs/workbench/contrib/files/browser/files.contribution.ts @@ -445,10 +445,11 @@ configurationRegistry.registerConfiguration({ }, 'explorer.incrementalNaming': { 'type': 'string', - enum: ['simple', 'smart'], + enum: ['simple', 'smart', 'disabled'], enumDescriptions: [ nls.localize('simple', "Appends the word \"copy\" at the end of the duplicated name potentially followed by a number"), - nls.localize('smart', "Adds a number at the end of the duplicated name. If some number is already part of the name, tries to increase that number") + nls.localize('smart', "Adds a number at the end of the duplicated name. If some number is already part of the name, tries to increase that number"), + nls.localize('disabled', "Disables incremental naming. If two files with the same name exist you will be prompted to overwrite the existing file") ], description: nls.localize('explorer.incrementalNaming', "Controls what naming strategy to use when a giving a new name to a duplicated explorer item on paste."), default: 'simple' diff --git a/src/vs/workbench/contrib/files/common/files.ts b/src/vs/workbench/contrib/files/common/files.ts index b9500df93d9dc..bff6d425a37ea 100644 --- a/src/vs/workbench/contrib/files/common/files.ts +++ b/src/vs/workbench/contrib/files/common/files.ts @@ -99,7 +99,7 @@ export interface IFilesConfiguration extends PlatformIFilesConfiguration, IWorkb colors: boolean; badges: boolean; }; - incrementalNaming: 'simple' | 'smart'; + incrementalNaming: 'simple' | 'smart' | 'disabled'; excludeGitIgnore: boolean; fileNesting: { enabled: boolean;